@@ -2,8 +2,9 @@ use crate::interner::{ChalkFnAbi, ChalkIr};
2
2
use chalk_ir:: cast:: { Cast , Caster } ;
3
3
use chalk_ir:: interner:: { HasInterner , Interner } ;
4
4
use chalk_ir:: {
5
- self , AdtId , AssocTypeId , BoundVar , ClausePriority , ClosureId , DebruijnIndex , FnDefId , ImplId ,
6
- OpaqueTyId , QuantifiedWhereClauses , Substitution , ToGenericArg , TraitId , TyKind , VariableKinds ,
5
+ self , AdtId , AssocTypeId , BoundVar , ClausePriority , ClosureId , DebruijnIndex , FnDefId ,
6
+ ForeignDefId , ImplId , OpaqueTyId , QuantifiedWhereClauses , Substitution , ToGenericArg , TraitId ,
7
+ TyKind , VariableKinds ,
7
8
} ;
8
9
use chalk_parse:: ast:: * ;
9
10
use chalk_solve:: rust_ir:: {
@@ -33,6 +34,7 @@ type OpaqueTyKinds = BTreeMap<chalk_ir::OpaqueTyId<ChalkIr>, TypeKind>;
33
34
type AssociatedTyLookups = BTreeMap < ( chalk_ir:: TraitId < ChalkIr > , Ident ) , AssociatedTyLookup > ;
34
35
type AssociatedTyValueIds =
35
36
BTreeMap < ( chalk_ir:: ImplId < ChalkIr > , Ident ) , AssociatedTyValueId < ChalkIr > > ;
37
+ type ForeignIds = BTreeMap < Ident , chalk_ir:: ForeignDefId < ChalkIr > > ;
36
38
37
39
type ParameterMap = BTreeMap < Ident , chalk_ir:: WithKind < ChalkIr , BoundVar > > ;
38
40
@@ -53,6 +55,7 @@ struct Env<'k> {
53
55
opaque_ty_kinds : & ' k OpaqueTyKinds ,
54
56
associated_ty_lookups : & ' k AssociatedTyLookups ,
55
57
auto_traits : & ' k AutoTraits ,
58
+ foreign_ty_ids : & ' k ForeignIds ,
56
59
/// GenericArg identifiers are used as keys, therefore
57
60
/// all identifiers in an environment must be unique (no shadowing).
58
61
parameter_map : ParameterMap ,
@@ -177,6 +180,16 @@ impl<'k> Env<'k> {
177
180
. cast ( interner) ,
178
181
) ;
179
182
}
183
+
184
+ if let Some ( id) = self . foreign_ty_ids . get ( & name. str ) {
185
+ return Ok ( chalk_ir:: TyData :: Apply ( chalk_ir:: ApplicationTy {
186
+ name : chalk_ir:: TypeName :: Foreign ( * id) ,
187
+ substitution : chalk_ir:: Substitution :: empty ( interner) ,
188
+ } )
189
+ . intern ( interner)
190
+ . cast ( interner) ) ;
191
+ }
192
+
180
193
if let Some ( _) = self . trait_ids . get ( & name. str ) {
181
194
return Err ( RustIrError :: NotStruct ( name. clone ( ) ) ) ;
182
195
}
@@ -408,6 +421,7 @@ impl LowerProgram for Program {
408
421
}
409
422
Item :: Impl ( _) => continue ,
410
423
Item :: Clause ( _) => continue ,
424
+ Item :: Foreign ( _) => continue ,
411
425
} ;
412
426
}
413
427
@@ -425,6 +439,8 @@ impl LowerProgram for Program {
425
439
let mut opaque_ty_data = BTreeMap :: new ( ) ;
426
440
let mut hidden_opaque_types = BTreeMap :: new ( ) ;
427
441
let mut custom_clauses = Vec :: new ( ) ;
442
+ let mut foreign_ty_ids = BTreeMap :: new ( ) ;
443
+
428
444
for ( item, & raw_id) in self . items . iter ( ) . zip ( & raw_ids) {
429
445
let empty_env = Env {
430
446
adt_ids : & adt_ids,
@@ -441,6 +457,7 @@ impl LowerProgram for Program {
441
457
associated_ty_lookups : & associated_ty_lookups,
442
458
parameter_map : BTreeMap :: new ( ) ,
443
459
auto_traits : & auto_traits,
460
+ foreign_ty_ids : & foreign_ty_ids,
444
461
} ;
445
462
446
463
match * item {
@@ -638,6 +655,9 @@ impl LowerProgram for Program {
638
655
) ;
639
656
}
640
657
}
658
+ Item :: Foreign ( ForeignDefn ( ref ident) ) => {
659
+ foreign_ty_ids. insert ( ident. str . clone ( ) , ForeignDefId ( raw_id) ) ;
660
+ }
641
661
}
642
662
}
643
663
@@ -667,6 +687,7 @@ impl LowerProgram for Program {
667
687
hidden_opaque_types,
668
688
custom_clauses,
669
689
object_safe_traits,
690
+ foreign_ty_ids,
670
691
} ;
671
692
672
693
Ok ( program)
@@ -2016,6 +2037,7 @@ impl LowerGoal<LoweredProgram> for Goal {
2016
2037
trait_kinds : & program. trait_kinds ,
2017
2038
opaque_ty_kinds : & program. opaque_ty_kinds ,
2018
2039
associated_ty_lookups : & associated_ty_lookups,
2040
+ foreign_ty_ids : & program. foreign_ty_ids ,
2019
2041
parameter_map : BTreeMap :: new ( ) ,
2020
2042
auto_traits : & auto_traits,
2021
2043
} ;
0 commit comments