@@ -608,10 +608,13 @@ trait LowerDomainGoal {
608
608
609
609
impl LowerDomainGoal for DomainGoal {
610
610
fn lower ( & self , env : & Env ) -> LowerResult < Vec < chalk_ir:: DomainGoal < ChalkIr > > > {
611
+ let interner = env. interner ( ) ;
611
612
let goals = match self {
612
- DomainGoal :: Holds { where_clause } => {
613
- where_clause. lower ( env) ?. into_iter ( ) . casted ( ) . collect ( )
614
- }
613
+ DomainGoal :: Holds { where_clause } => where_clause
614
+ . lower ( env) ?
615
+ . into_iter ( )
616
+ . casted ( interner)
617
+ . collect ( ) ,
615
618
DomainGoal :: Normalize { alias, ty } => {
616
619
vec ! [ chalk_ir:: DomainGoal :: Normalize ( chalk_ir:: Normalize {
617
620
alias: alias. lower( env) ?,
@@ -655,18 +658,21 @@ trait LowerLeafGoal {
655
658
656
659
impl LowerLeafGoal for LeafGoal {
657
660
fn lower ( & self , env : & Env ) -> LowerResult < chalk_ir:: Goal < ChalkIr > > {
661
+ let interner = env. interner ( ) ;
658
662
Ok ( match self {
659
- LeafGoal :: DomainGoal { goal } => goal. lower ( env) ?. into_iter ( ) . casted ( ) . collect ( ) ,
663
+ LeafGoal :: DomainGoal { goal } => {
664
+ chalk_ir:: Goal :: all ( interner, goal. lower ( env) ?. into_iter ( ) . casted ( interner) )
665
+ }
660
666
LeafGoal :: UnifyTys { a, b } => chalk_ir:: EqGoal {
661
- a : a. lower ( env) ?. cast ( ) ,
662
- b : b. lower ( env) ?. cast ( ) ,
667
+ a : a. lower ( env) ?. cast ( interner ) ,
668
+ b : b. lower ( env) ?. cast ( interner ) ,
663
669
}
664
- . cast :: < chalk_ir:: Goal < ChalkIr > > ( ) ,
670
+ . cast :: < chalk_ir:: Goal < ChalkIr > > ( interner ) ,
665
671
LeafGoal :: UnifyLifetimes { ref a, ref b } => chalk_ir:: EqGoal {
666
- a : a. lower ( env) ?. cast ( ) ,
667
- b : b. lower ( env) ?. cast ( ) ,
672
+ a : a. lower ( env) ?. cast ( interner ) ,
673
+ b : b. lower ( env) ?. cast ( interner ) ,
668
674
}
669
- . cast :: < chalk_ir:: Goal < ChalkIr > > ( ) ,
675
+ . cast :: < chalk_ir:: Goal < ChalkIr > > ( interner ) ,
670
676
} )
671
677
}
672
678
}
@@ -718,14 +724,15 @@ trait LowerTraitRef {
718
724
719
725
impl LowerTraitRef for TraitRef {
720
726
fn lower ( & self , env : & Env ) -> LowerResult < chalk_ir:: TraitRef < ChalkIr > > {
727
+ let interner = env. interner ( ) ;
721
728
let without_self = TraitBound {
722
729
trait_name : self . trait_name ,
723
730
args_no_self : self . args . iter ( ) . cloned ( ) . skip ( 1 ) . collect ( ) ,
724
731
}
725
732
. lower ( env) ?;
726
733
727
734
let self_parameter = self . args [ 0 ] . lower ( env) ?;
728
- Ok ( without_self. as_trait_ref ( self_parameter. assert_ty_ref ( ) . clone ( ) ) )
735
+ Ok ( without_self. as_trait_ref ( interner , self_parameter. assert_ty_ref ( ) . clone ( ) ) )
729
736
}
730
737
}
731
738
@@ -910,6 +917,7 @@ impl LowerAliasTy for AliasTy {
910
917
ref name,
911
918
ref args,
912
919
} = * self ;
920
+ let interner = env. interner ( ) ;
913
921
let chalk_ir:: TraitRef {
914
922
trait_id,
915
923
substitution : trait_substitution,
@@ -945,7 +953,7 @@ impl LowerAliasTy for AliasTy {
945
953
946
954
Ok ( chalk_ir:: AliasTy {
947
955
associated_ty_id : lookup. id ,
948
- substitution : chalk_ir:: Substitution :: from ( args) ,
956
+ substitution : chalk_ir:: Substitution :: from ( interner , args) ,
949
957
} )
950
958
}
951
959
}
@@ -956,6 +964,7 @@ trait LowerTy {
956
964
957
965
impl LowerTy for Ty {
958
966
fn lower ( & self , env : & Env ) -> LowerResult < chalk_ir:: Ty < ChalkIr > > {
967
+ let interner = env. interner ( ) ;
959
968
match * self {
960
969
Ty :: Id { name } => match env. lookup_type ( name) ? {
961
970
TypeLookup :: Struct ( id) => {
@@ -969,14 +978,12 @@ impl LowerTy for Ty {
969
978
} else {
970
979
Ok ( chalk_ir:: TyData :: Apply ( chalk_ir:: ApplicationTy {
971
980
name : chalk_ir:: TypeName :: Struct ( id) ,
972
- substitution : chalk_ir:: Substitution :: empty ( ) ,
981
+ substitution : chalk_ir:: Substitution :: empty ( interner ) ,
973
982
} )
974
- . intern ( env . interner ( ) ) )
983
+ . intern ( interner) )
975
984
}
976
985
}
977
- TypeLookup :: Parameter ( d) => {
978
- Ok ( chalk_ir:: TyData :: BoundVar ( d) . intern ( env. interner ( ) ) )
979
- }
986
+ TypeLookup :: Parameter ( d) => Ok ( chalk_ir:: TyData :: BoundVar ( d) . intern ( interner) ) ,
980
987
} ,
981
988
982
989
Ty :: Dyn { ref bounds } => Ok ( chalk_ir:: TyData :: Dyn ( chalk_ir:: DynTy {
@@ -989,15 +996,15 @@ impl LowerTy for Ty {
989
996
. iter ( )
990
997
. flat_map ( |qil| {
991
998
qil. into_where_clauses (
992
- env . interner ( ) ,
993
- chalk_ir:: TyData :: BoundVar ( 0 ) . intern ( env . interner ( ) ) ,
999
+ interner,
1000
+ chalk_ir:: TyData :: BoundVar ( 0 ) . intern ( interner) ,
994
1001
)
995
1002
} )
996
1003
. collect ( ) )
997
1004
} ,
998
1005
) ?,
999
1006
} )
1000
- . intern ( env . interner ( ) ) ) ,
1007
+ . intern ( interner) ) ,
1001
1008
1002
1009
Ty :: Apply { name, ref args } => {
1003
1010
let id = match env. lookup_type ( name) ? {
@@ -1014,8 +1021,10 @@ impl LowerTy for Ty {
1014
1021
} ) ?;
1015
1022
}
1016
1023
1017
- let substitution =
1018
- chalk_ir:: Substitution :: from_fallible ( args. iter ( ) . map ( |t| Ok ( t. lower ( env) ?) ) ) ?;
1024
+ let substitution = chalk_ir:: Substitution :: from_fallible (
1025
+ interner,
1026
+ args. iter ( ) . map ( |t| Ok ( t. lower ( env) ?) ) ,
1027
+ ) ?;
1019
1028
1020
1029
for ( param, arg) in k. binders . binders . iter ( ) . zip ( args. iter ( ) ) {
1021
1030
if param. kind ( ) != arg. kind ( ) {
@@ -1031,11 +1040,11 @@ impl LowerTy for Ty {
1031
1040
name : chalk_ir:: TypeName :: Struct ( id) ,
1032
1041
substitution : substitution,
1033
1042
} )
1034
- . intern ( env . interner ( ) ) )
1043
+ . intern ( interner) )
1035
1044
}
1036
1045
1037
1046
Ty :: Alias { ref alias } => {
1038
- Ok ( chalk_ir:: TyData :: Alias ( alias. lower ( env) ?) . intern ( env . interner ( ) ) )
1047
+ Ok ( chalk_ir:: TyData :: Alias ( alias. lower ( env) ?) . intern ( interner) )
1039
1048
}
1040
1049
1041
1050
Ty :: ForAll {
@@ -1050,9 +1059,9 @@ impl LowerTy for Ty {
1050
1059
1051
1060
let function = chalk_ir:: Fn {
1052
1061
num_binders : lifetime_names. len ( ) ,
1053
- parameters : vec ! [ ty. lower( & quantified_env) ?. cast( ) ] ,
1062
+ parameters : vec ! [ ty. lower( & quantified_env) ?. cast( interner ) ] ,
1054
1063
} ;
1055
- Ok ( chalk_ir:: TyData :: Function ( function) . intern ( env . interner ( ) ) )
1064
+ Ok ( chalk_ir:: TyData :: Function ( function) . intern ( interner) )
1056
1065
}
1057
1066
}
1058
1067
}
@@ -1064,9 +1073,10 @@ trait LowerParameter {
1064
1073
1065
1074
impl LowerParameter for Parameter {
1066
1075
fn lower ( & self , env : & Env ) -> LowerResult < chalk_ir:: Parameter < ChalkIr > > {
1076
+ let interner = env. interner ( ) ;
1067
1077
match * self {
1068
- Parameter :: Ty ( ref t) => Ok ( t. lower ( env) ?. cast ( ) ) ,
1069
- Parameter :: Lifetime ( ref l) => Ok ( l. lower ( env) ?. cast ( ) ) ,
1078
+ Parameter :: Ty ( ref t) => Ok ( t. lower ( env) ?. cast ( interner ) ) ,
1079
+ Parameter :: Lifetime ( ref l) => Ok ( l. lower ( env) ?. cast ( interner ) ) ,
1070
1080
}
1071
1081
}
1072
1082
}
@@ -1077,10 +1087,11 @@ trait LowerLifetime {
1077
1087
1078
1088
impl LowerLifetime for Lifetime {
1079
1089
fn lower ( & self , env : & Env ) -> LowerResult < chalk_ir:: Lifetime < ChalkIr > > {
1090
+ let interner = env. interner ( ) ;
1080
1091
match * self {
1081
1092
Lifetime :: Id { name } => match env. lookup_lifetime ( name) ? {
1082
1093
LifetimeLookup :: Parameter ( d) => {
1083
- Ok ( chalk_ir:: LifetimeData :: BoundVar ( d) . intern ( env . interner ( ) ) )
1094
+ Ok ( chalk_ir:: LifetimeData :: BoundVar ( d) . intern ( interner) )
1084
1095
}
1085
1096
} ,
1086
1097
}
@@ -1150,10 +1161,12 @@ trait LowerClause {
1150
1161
1151
1162
impl LowerClause for Clause {
1152
1163
fn lower_clause ( & self , env : & Env ) -> LowerResult < Vec < chalk_ir:: ProgramClause < ChalkIr > > > {
1164
+ let interner = env. interner ( ) ;
1153
1165
let implications = env. in_binders ( self . all_parameters ( ) , |env| {
1154
1166
let consequences: Vec < chalk_ir:: DomainGoal < ChalkIr > > = self . consequence . lower ( env) ?;
1155
1167
1156
1168
let conditions = chalk_ir:: Goals :: from_fallible (
1169
+ interner,
1157
1170
// Subtle: in the SLG solver, we pop conditions from R to
1158
1171
// L. To preserve the expected order (L to R), we must
1159
1172
// therefore reverse.
@@ -1269,6 +1282,7 @@ impl LowerGoal<LoweredProgram> for Goal {
1269
1282
1270
1283
impl < ' k > LowerGoal < Env < ' k > > for Goal {
1271
1284
fn lower ( & self , env : & Env < ' k > ) -> LowerResult < chalk_ir:: Goal < ChalkIr > > {
1285
+ let interner = env. interner ( ) ;
1272
1286
match self {
1273
1287
Goal :: ForAll ( ids, g) => g. lower_quantified ( env, chalk_ir:: QuantifierKind :: ForAll , ids) ,
1274
1288
Goal :: Exists ( ids, g) => g. lower_quantified ( env, chalk_ir:: QuantifierKind :: Exists , ids) ,
@@ -1280,18 +1294,19 @@ impl<'k> LowerGoal<Env<'k>> for Goal {
1280
1294
let where_clauses: LowerResult < Vec < _ > > = hyp
1281
1295
. into_iter ( )
1282
1296
. flat_map ( |h| h. lower_clause ( env) . apply_result ( ) )
1283
- . map ( |result| result. map ( |h| h. into_from_env_clause ( ) ) )
1297
+ . map ( |result| result. map ( |h| h. into_from_env_clause ( interner ) ) )
1284
1298
. collect ( ) ;
1285
1299
Ok ( chalk_ir:: GoalData :: Implies ( where_clauses?, g. lower ( env) ?) . intern ( ) )
1286
1300
}
1287
1301
Goal :: And ( g1, g2s) => {
1288
1302
let goals = chalk_ir:: Goals :: from_fallible (
1303
+ interner,
1289
1304
Some ( g1) . into_iter ( ) . chain ( g2s) . map ( |g| g. lower ( env) ) ,
1290
1305
) ?;
1291
1306
Ok ( chalk_ir:: GoalData :: All ( goals) . intern ( ) )
1292
1307
}
1293
1308
Goal :: Not ( g) => Ok ( chalk_ir:: GoalData :: Not ( g. lower ( env) ?) . intern ( ) ) ,
1294
- Goal :: Compatible ( g) => Ok ( g. lower ( env) ?. compatible ( env . interner ( ) ) ) ,
1309
+ Goal :: Compatible ( g) => Ok ( g. lower ( env) ?. compatible ( interner) ) ,
1295
1310
Goal :: Leaf ( leaf) => {
1296
1311
// A where clause can lower to multiple leaf goals; wrap these in Goal::And.
1297
1312
Ok ( leaf. lower ( env) ?)
0 commit comments