Skip to content

Commit ade9164

Browse files
committed
Add misc fixes + beginning of an attempt to make scalars WellFormed
1 parent 7662478 commit ade9164

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

chalk-integration/src/lowering.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::{Identifier as Ident, RawId, TypeKind, TypeSort};
2121
type StructIds = BTreeMap<Ident, chalk_ir::StructId<ChalkIr>>;
2222
type TraitIds = BTreeMap<Ident, chalk_ir::TraitId<ChalkIr>>;
2323
type OpaqueTyIds = BTreeMap<Ident, chalk_ir::OpaqueTyId<ChalkIr>>;
24+
type ScalarIds = BTreeMap<chalk_ir::Scalar, RawId>;
2425
type StructKinds = BTreeMap<chalk_ir::StructId<ChalkIr>, TypeKind>;
2526
type TraitKinds = BTreeMap<chalk_ir::TraitId<ChalkIr>, TypeKind>;
2627
type AssociatedTyLookups = BTreeMap<(chalk_ir::TraitId<ChalkIr>, Ident), AssociatedTyLookup>;
@@ -38,6 +39,7 @@ struct Env<'k> {
3839
trait_kinds: &'k TraitKinds,
3940
opaque_ty_ids: &'k OpaqueTyIds,
4041
associated_ty_lookups: &'k AssociatedTyLookups,
42+
scalar_ty_ids: &'k ScalarIds,
4143
/// Parameter identifiers are used as keys, therefore
4244
/// all identifiers in an environment must be unique (no shadowing).
4345
parameter_map: ParameterMap,
@@ -200,6 +202,11 @@ impl LowerProgram for Program {
200202
// based just on its position:
201203
let raw_ids: Vec<_> = self.items.iter().map(|_| next_item_id()).collect();
202204

205+
// Create ids for built-in scalar types
206+
let mut scalar_ty_ids = BTreeMap::new();
207+
// debug code do not merge
208+
scalar_ty_ids.insert(chalk_ir::Scalar::Bool, next_item_id());
209+
203210
// Create ids for associated type declarations and values
204211
let mut associated_ty_lookups = BTreeMap::new();
205212
let mut associated_ty_value_ids = BTreeMap::new();
@@ -276,6 +283,7 @@ impl LowerProgram for Program {
276283
trait_ids: &trait_ids,
277284
trait_kinds: &trait_kinds,
278285
opaque_ty_ids: &opaque_ty_ids,
286+
scalar_ty_ids: &scalar_ty_ids,
279287
associated_ty_lookups: &associated_ty_lookups,
280288
parameter_map: BTreeMap::new(),
281289
};
@@ -437,6 +445,8 @@ impl LowerProgram for Program {
437445
let program = LoweredProgram {
438446
struct_ids,
439447
trait_ids,
448+
// hmm
449+
scalar_ids: scalar_ty_ids,
440450
struct_kinds,
441451
trait_kinds,
442452
struct_data,
@@ -1396,6 +1406,7 @@ impl LowerGoal<LoweredProgram> for Goal {
13961406
struct_ids: &program.struct_ids,
13971407
trait_ids: &program.trait_ids,
13981408
opaque_ty_ids: &program.opaque_ty_ids,
1409+
scalar_ty_ids: &program.scalar_ids,
13991410
struct_kinds: &program.struct_kinds,
14001411
trait_kinds: &program.trait_kinds,
14011412
associated_ty_lookups: &associated_ty_lookups,

chalk-integration/src/program.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::{Identifier, TypeKind};
22
use chalk_ir::could_match::CouldMatch;
33
use chalk_ir::debug::Angle;
4-
use chalk_ir::interner::ChalkIr;
4+
use chalk_ir::interner::{ChalkIr, RawId};
55
use chalk_ir::tls;
66
use chalk_ir::{
77
debug::SeparatorTraitRef, AliasTy, ApplicationTy, AssocTypeId, Goal, Goals, ImplId, Lifetime,
88
OpaqueTy, OpaqueTyId, Parameter, ProgramClause, ProgramClauseImplication, ProgramClauses,
9-
ProjectionTy, StructId, Substitution, TraitId, Ty, TypeName,
9+
ProjectionTy, Scalar, StructId, Substitution, TraitId, Ty, TypeName,
1010
};
1111
use chalk_rust_ir::{
1212
AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId, ImplDatum, ImplType, OpaqueTyDatum,
@@ -29,6 +29,9 @@ pub struct Program {
2929
/// From trait name to item-id. Used during lowering only.
3030
pub trait_ids: BTreeMap<Identifier, TraitId<ChalkIr>>,
3131

32+
/// From scalar to raw-id. Used during lowering only.
33+
pub scalar_ids: BTreeMap<Scalar, RawId>,
34+
3235
/// For each trait:
3336
pub trait_kinds: BTreeMap<TraitId<ChalkIr>, TypeKind>,
3437

chalk-solve/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ pub trait RustIrDatabase<I: Interner>: Debug {
8787
/// Returns id of a trait lang item, if found
8888
fn well_known_trait_id(&self, well_known_trait: WellKnownTrait) -> Option<TraitId<I>>;
8989

90+
/// Returns id of a built-in scalar value, if found
91+
//fn scalar_id(&self, well_known_trait: WellKnownTrait) -> Option<Id<I>>;
92+
9093
fn interner(&self) -> &I;
9194
}
9295

libstd.chalk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ trait Clone { }
1010
trait Copy where Self: Clone { }
1111
trait Sized { }
1212

13-
struct i32 { }
1413
impl Copy for i32 { }
1514
impl Clone for i32 { }
1615
impl Sized for i32 { }
1716

18-
struct u32 { }
1917
impl Copy for u32 { }
2018
impl Clone for u32 { }
2119
impl Sized for u32 { }

tests/test/scalars.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,27 @@ fn scalar_trait_impl() {
112112

113113
}
114114
}
115+
116+
#[test]
117+
fn scalars_are_well_formed() {
118+
test! {
119+
program { }
120+
121+
goal { WellFormed(i8) } yields { "Unique" }
122+
goal { WellFormed(i16) } yields { "Unique" }
123+
goal { WellFormed(i32) } yields { "Unique" }
124+
goal { WellFormed(i64) } yields { "Unique" }
125+
goal { WellFormed(i128) } yields { "Unique" }
126+
goal { WellFormed(isize) } yields { "Unique" }
127+
goal { WellFormed(u8) } yields { "Unique" }
128+
goal { WellFormed(u16) } yields { "Unique" }
129+
goal { WellFormed(u32) } yields { "Unique" }
130+
goal { WellFormed(u64) } yields { "Unique" }
131+
goal { WellFormed(u128) } yields { "Unique" }
132+
goal { WellFormed(usize) } yields { "Unique" }
133+
goal { WellFormed(f32) } yields { "Unique" }
134+
goal { WellFormed(f64) } yields { "Unique" }
135+
goal { WellFormed(bool) } yields { "Unique" }
136+
goal { WellFormed(char) } yields { "Unique" }
137+
}
138+
}

0 commit comments

Comments
 (0)