@@ -83,88 +83,31 @@ impl<'i, I: Interner> GoalBuilder<'i, I> {
83
83
& mut self ,
84
84
binders : & Binders < B > ,
85
85
passthru : P ,
86
- body : fn ( & mut Self , Substitution < I > , B :: Result , P :: Result ) -> G ,
86
+ body : fn ( & mut Self , Substitution < I > , & B , P :: Result ) -> G ,
87
87
) -> Goal < I >
88
88
where
89
89
B : Fold < I > + HasInterner < Interner = I > ,
90
90
P : Fold < I > ,
91
91
B :: Result : std:: fmt:: Debug ,
92
92
G : CastTo < Goal < I > > ,
93
93
{
94
- self . partially_quantified ( QuantifierKind :: ForAll , binders, & [ ] , passthru, body)
94
+ self . quantified ( QuantifierKind :: ForAll , binders, passthru, body)
95
95
}
96
96
97
97
/// Like [`GoalBuilder::forall`], but for a `exists<Q0..Qn> { G }` goal.
98
98
pub ( crate ) fn exists < G , B , P > (
99
99
& mut self ,
100
100
binders : & Binders < B > ,
101
101
passthru : P ,
102
- body : fn ( & mut Self , Substitution < I > , B :: Result , P :: Result ) -> G ,
102
+ body : fn ( & mut Self , Substitution < I > , & B , P :: Result ) -> G ,
103
103
) -> Goal < I >
104
104
where
105
105
B : Fold < I > + HasInterner < Interner = I > ,
106
106
P : Fold < I > ,
107
107
B :: Result : std:: fmt:: Debug ,
108
108
G : CastTo < Goal < I > > ,
109
109
{
110
- self . partially_quantified ( QuantifierKind :: Exists , binders, & [ ] , passthru, body)
111
- }
112
-
113
- /// Like `[GoalBuilder::forall`], except that it also takes
114
- /// a (partial) substitution `S0..Sm` that provides some
115
- /// suffix of the values for the bound value `<P0..Pn> V`.
116
- ///
117
- /// The resulting goal will be `forall<Q0..Q(n-m)> { G }`,
118
- /// and the resulting substitution for the bound value `V`
119
- /// will be `[Q0, .., Q(n-m), S0, .., Sm]`.
120
- ///
121
- /// This is useful for associated items within traits and impls:
122
- /// the binders on such items contain both the binders from the trait
123
- /// and impl as well as from the associated item itself. Here, the
124
- /// "partial substitution" would be the values from the trait/impl.
125
- pub ( crate ) fn partially_forall < G , B , P > (
126
- & mut self ,
127
- binders : & Binders < B > ,
128
- partial_substitution : & Substitution < I > ,
129
- passthru : P ,
130
- body : fn ( & mut Self , Substitution < I > , B :: Result , P :: Result ) -> G ,
131
- ) -> Goal < I >
132
- where
133
- B : Fold < I > + HasInterner < Interner = I > ,
134
- P : Fold < I > ,
135
- B :: Result : std:: fmt:: Debug ,
136
- G : CastTo < Goal < I > > ,
137
- {
138
- self . partially_quantified (
139
- QuantifierKind :: ForAll ,
140
- binders,
141
- partial_substitution. parameters ( self . interner ( ) ) ,
142
- passthru,
143
- body,
144
- )
145
- }
146
-
147
- /// Like [`GoalBuilder::partially_forall`], but for a `exists` goal.
148
- pub ( crate ) fn partially_exists < G , B , P > (
149
- & mut self ,
150
- binders : & Binders < B > ,
151
- partial_substitution : & Substitution < I > ,
152
- passthru : P ,
153
- body : fn ( & mut Self , Substitution < I > , B :: Result , P :: Result ) -> G ,
154
- ) -> Goal < I >
155
- where
156
- B : Fold < I > + HasInterner < Interner = I > ,
157
- P : Fold < I > ,
158
- B :: Result : std:: fmt:: Debug ,
159
- G : CastTo < Goal < I > > ,
160
- {
161
- self . partially_quantified (
162
- QuantifierKind :: Exists ,
163
- binders,
164
- partial_substitution. parameters ( self . interner ( ) ) ,
165
- passthru,
166
- body,
167
- )
110
+ self . quantified ( QuantifierKind :: Exists , binders, passthru, body)
168
111
}
169
112
170
113
/// A combined helper functon for the various methods
@@ -174,13 +117,12 @@ impl<'i, I: Interner> GoalBuilder<'i, I> {
174
117
/// * [`GoalBuilder::partially_forall`]
175
118
///
176
119
/// for details.
177
- pub ( crate ) fn partially_quantified < G , B , P > (
120
+ pub ( crate ) fn quantified < G , B , P > (
178
121
& mut self ,
179
122
quantifier_kind : QuantifierKind ,
180
123
binders : & Binders < B > ,
181
- partial_substitution : & [ Parameter < I > ] ,
182
124
passthru : P ,
183
- body : fn ( & mut Self , Substitution < I > , B :: Result , P :: Result ) -> G ,
125
+ body : fn ( & mut Self , Substitution < I > , & B , P :: Result ) -> G ,
184
126
) -> Goal < I >
185
127
where
186
128
B : Fold < I > + HasInterner < Interner = I > ,
@@ -189,30 +131,19 @@ impl<'i, I: Interner> GoalBuilder<'i, I> {
189
131
G : CastTo < Goal < I > > ,
190
132
{
191
133
let interner = self . interner ( ) ;
192
- assert ! ( binders. binders. len( ) >= partial_substitution. len( ) ) ;
193
- let split_point = binders. binders . len ( ) - partial_substitution. len ( ) ;
194
- let ( quantified_binders, _) = binders. binders . split_at ( split_point) ;
195
- let combined_values: Substitution < I > = Substitution :: from (
196
- interner,
197
- quantified_binders
198
- . iter ( )
199
- . zip ( 0 ..)
200
- . map ( |p| p. to_parameter ( interner) )
201
- . chain (
202
- // Note that the values from the partial substitution must be shifted
203
- // in by one to account for the new binder we are introducing.
204
- partial_substitution. iter ( ) . map ( |p| p. shifted_in ( interner) ) ,
205
- ) ,
206
- ) ;
207
- let bound_goal = {
208
- let bound_value = binders. substitute ( interner, & combined_values) ;
134
+ let bound_goal = binders. map_ref ( |bound_value| {
135
+ let substitution: Substitution < I > = Substitution :: from (
136
+ interner,
137
+ binders
138
+ . binders
139
+ . iter ( )
140
+ . zip ( 0 ..)
141
+ . map ( |p| p. to_parameter ( interner) ) ,
142
+ ) ;
209
143
let passthru_shifted = passthru. shifted_in ( self . interner ( ) ) ;
210
- let result = body ( self , combined_values, bound_value, passthru_shifted) ;
211
- Binders {
212
- binders : quantified_binders. to_vec ( ) ,
213
- value : result. cast ( self . interner ( ) ) ,
214
- }
215
- } ;
144
+ let result = body ( self , substitution, bound_value, passthru_shifted) ;
145
+ result. cast ( self . interner ( ) )
146
+ } ) ;
216
147
GoalData :: Quantified ( quantifier_kind, bound_goal) . intern ( self . interner ( ) )
217
148
}
218
149
}
0 commit comments