@@ -31,93 +31,66 @@ fn fn_sig_for_fn_abi<'tcx>(
31
31
tcx : TyCtxt < ' tcx > ,
32
32
instance : ty:: Instance < ' tcx > ,
33
33
typing_env : ty:: TypingEnv < ' tcx > ,
34
- ) -> ty:: PolyFnSig < ' tcx > {
34
+ ) -> ty:: FnSig < ' tcx > {
35
35
if let InstanceKind :: ThreadLocalShim ( ..) = instance. def {
36
- return ty :: Binder :: dummy ( tcx. mk_fn_sig (
36
+ return tcx. mk_fn_sig (
37
37
[ ] ,
38
38
tcx. thread_local_ptr_ty ( instance. def_id ( ) ) ,
39
39
false ,
40
40
hir:: Safety :: Safe ,
41
41
rustc_abi:: ExternAbi :: Unadjusted ,
42
- ) ) ;
42
+ ) ;
43
43
}
44
44
45
45
let ty = instance. ty ( tcx, typing_env) ;
46
46
match * ty. kind ( ) {
47
- ty:: FnDef ( .. ) => {
47
+ ty:: FnDef ( def_id , args ) => {
48
48
// HACK(davidtwco,eddyb): This is a workaround for polymorphization considering
49
49
// parameters unused if they show up in the signature, but not in the `mir::Body`
50
50
// (i.e. due to being inside a projection that got normalized, see
51
51
// `tests/ui/polymorphization/normalized_sig_types.rs`), and codegen not keeping
52
52
// track of a polymorphization `ParamEnv` to allow normalizing later.
53
53
//
54
54
// We normalize the `fn_sig` again after instantiating at a later point.
55
- let mut sig = match * ty. kind ( ) {
56
- ty:: FnDef ( def_id, args) => tcx
57
- . fn_sig ( def_id)
55
+ let mut sig = tcx. instantiate_bound_regions_with_erased (
56
+ tcx. fn_sig ( def_id)
58
57
. map_bound ( |fn_sig| {
59
58
tcx. normalize_erasing_regions (
60
59
ty:: TypingEnv :: non_body_analysis ( tcx, def_id) ,
61
60
fn_sig,
62
61
)
63
62
} )
64
63
. instantiate ( tcx, args) ,
65
- _ => unreachable ! ( ) ,
66
- } ;
64
+ ) ;
67
65
68
66
if let ty:: InstanceKind :: VTableShim ( ..) = instance. def {
69
- // Modify `fn(self, ...)` to `fn(self: *mut Self, ...)`.
70
- sig = sig. map_bound ( |mut sig| {
71
- let mut inputs_and_output = sig. inputs_and_output . to_vec ( ) ;
72
- inputs_and_output[ 0 ] = Ty :: new_mut_ptr ( tcx, inputs_and_output[ 0 ] ) ;
73
- sig. inputs_and_output = tcx. mk_type_list ( & inputs_and_output) ;
74
- sig
75
- } ) ;
67
+ let mut inputs_and_output = sig. inputs_and_output . to_vec ( ) ;
68
+ inputs_and_output[ 0 ] = Ty :: new_mut_ptr ( tcx, inputs_and_output[ 0 ] ) ;
69
+ sig. inputs_and_output = tcx. mk_type_list ( & inputs_and_output) ;
76
70
}
71
+
77
72
sig
78
73
}
79
74
ty:: Closure ( def_id, args) => {
80
- let sig = args. as_closure ( ) . sig ( ) ;
81
-
82
- let bound_vars =
83
- tcx. mk_bound_variable_kinds_from_iter ( sig. bound_vars ( ) . iter ( ) . chain ( iter:: once (
84
- ty:: BoundVariableKind :: Region ( ty:: BoundRegionKind :: ClosureEnv ) ,
85
- ) ) ) ;
86
- let br = ty:: BoundRegion {
87
- var : ty:: BoundVar :: from_usize ( bound_vars. len ( ) - 1 ) ,
88
- kind : ty:: BoundRegionKind :: ClosureEnv ,
89
- } ;
90
- let env_region = ty:: Region :: new_bound ( tcx, ty:: INNERMOST , br) ;
75
+ let sig = tcx. instantiate_bound_regions_with_erased ( args. as_closure ( ) . sig ( ) ) ;
91
76
let env_ty = tcx. closure_env_ty (
92
77
Ty :: new_closure ( tcx, def_id, args) ,
93
78
args. as_closure ( ) . kind ( ) ,
94
- env_region ,
79
+ tcx . lifetimes . re_erased ,
95
80
) ;
96
81
97
- let sig = sig. skip_binder ( ) ;
98
- ty:: Binder :: bind_with_vars (
99
- tcx. mk_fn_sig (
100
- iter:: once ( env_ty) . chain ( sig. inputs ( ) . iter ( ) . cloned ( ) ) ,
101
- sig. output ( ) ,
102
- sig. c_variadic ,
103
- sig. safety ,
104
- sig. abi ,
105
- ) ,
106
- bound_vars,
82
+ tcx. mk_fn_sig (
83
+ iter:: once ( env_ty) . chain ( sig. inputs ( ) . iter ( ) . cloned ( ) ) ,
84
+ sig. output ( ) ,
85
+ sig. c_variadic ,
86
+ sig. safety ,
87
+ sig. abi ,
107
88
)
108
89
}
109
90
ty:: CoroutineClosure ( def_id, args) => {
110
91
let coroutine_ty = Ty :: new_coroutine_closure ( tcx, def_id, args) ;
111
92
let sig = args. as_coroutine_closure ( ) . coroutine_closure_sig ( ) ;
112
- let bound_vars =
113
- tcx. mk_bound_variable_kinds_from_iter ( sig. bound_vars ( ) . iter ( ) . chain ( iter:: once (
114
- ty:: BoundVariableKind :: Region ( ty:: BoundRegionKind :: ClosureEnv ) ,
115
- ) ) ) ;
116
- let br = ty:: BoundRegion {
117
- var : ty:: BoundVar :: from_usize ( bound_vars. len ( ) - 1 ) ,
118
- kind : ty:: BoundRegionKind :: ClosureEnv ,
119
- } ;
120
- let env_region = ty:: Region :: new_bound ( tcx, ty:: INNERMOST , br) ;
93
+
121
94
// When this `CoroutineClosure` comes from a `ConstructCoroutineInClosureShim`,
122
95
// make sure we respect the `target_kind` in that shim.
123
96
// FIXME(async_closures): This shouldn't be needed, and we should be populating
@@ -138,42 +111,32 @@ fn fn_sig_for_fn_abi<'tcx>(
138
111
coroutine_ty
139
112
}
140
113
} else {
141
- tcx. closure_env_ty ( coroutine_ty, coroutine_kind, env_region )
114
+ tcx. closure_env_ty ( coroutine_ty, coroutine_kind, tcx . lifetimes . re_erased )
142
115
} ;
143
116
144
- let sig = sig. skip_binder ( ) ;
145
- ty:: Binder :: bind_with_vars (
146
- tcx. mk_fn_sig (
147
- iter:: once ( env_ty) . chain ( [ sig. tupled_inputs_ty ] ) ,
148
- sig. to_coroutine_given_kind_and_upvars (
149
- tcx,
150
- args. as_coroutine_closure ( ) . parent_args ( ) ,
151
- tcx. coroutine_for_closure ( def_id) ,
152
- coroutine_kind,
153
- env_region,
154
- args. as_coroutine_closure ( ) . tupled_upvars_ty ( ) ,
155
- args. as_coroutine_closure ( ) . coroutine_captures_by_ref_ty ( ) ,
156
- ) ,
157
- sig. c_variadic ,
158
- sig. safety ,
159
- sig. abi ,
117
+ let sig = tcx. instantiate_bound_regions_with_erased ( sig) ;
118
+
119
+ tcx. mk_fn_sig (
120
+ iter:: once ( env_ty) . chain ( [ sig. tupled_inputs_ty ] ) ,
121
+ sig. to_coroutine_given_kind_and_upvars (
122
+ tcx,
123
+ args. as_coroutine_closure ( ) . parent_args ( ) ,
124
+ tcx. coroutine_for_closure ( def_id) ,
125
+ coroutine_kind,
126
+ tcx. lifetimes . re_erased ,
127
+ args. as_coroutine_closure ( ) . tupled_upvars_ty ( ) ,
128
+ args. as_coroutine_closure ( ) . coroutine_captures_by_ref_ty ( ) ,
160
129
) ,
161
- bound_vars,
130
+ sig. c_variadic ,
131
+ sig. safety ,
132
+ sig. abi ,
162
133
)
163
134
}
164
135
ty:: Coroutine ( did, args) => {
165
136
let coroutine_kind = tcx. coroutine_kind ( did) . unwrap ( ) ;
166
137
let sig = args. as_coroutine ( ) . sig ( ) ;
167
138
168
- let bound_vars = tcx. mk_bound_variable_kinds_from_iter ( iter:: once (
169
- ty:: BoundVariableKind :: Region ( ty:: BoundRegionKind :: ClosureEnv ) ,
170
- ) ) ;
171
- let br = ty:: BoundRegion {
172
- var : ty:: BoundVar :: from_usize ( bound_vars. len ( ) - 1 ) ,
173
- kind : ty:: BoundRegionKind :: ClosureEnv ,
174
- } ;
175
-
176
- let env_ty = Ty :: new_mut_ref ( tcx, ty:: Region :: new_bound ( tcx, ty:: INNERMOST , br) , ty) ;
139
+ let env_ty = Ty :: new_mut_ref ( tcx, tcx. lifetimes . re_erased , ty) ;
177
140
178
141
let pin_did = tcx. require_lang_item ( LangItem :: Pin , None ) ;
179
142
let pin_adt_ref = tcx. adt_def ( pin_did) ;
@@ -268,7 +231,7 @@ fn fn_sig_for_fn_abi<'tcx>(
268
231
}
269
232
} ;
270
233
271
- let fn_sig = if let Some ( resume_ty) = resume_ty {
234
+ if let Some ( resume_ty) = resume_ty {
272
235
tcx. mk_fn_sig (
273
236
[ env_ty, resume_ty] ,
274
237
ret_ty,
@@ -285,8 +248,7 @@ fn fn_sig_for_fn_abi<'tcx>(
285
248
hir:: Safety :: Safe ,
286
249
rustc_abi:: ExternAbi :: Rust ,
287
250
)
288
- } ;
289
- ty:: Binder :: bind_with_vars ( fn_sig, bound_vars)
251
+ }
290
252
}
291
253
_ => bug ! ( "unexpected type {:?} in Instance::fn_sig" , ty) ,
292
254
}
@@ -335,8 +297,16 @@ fn fn_abi_of_fn_ptr<'tcx>(
335
297
query : ty:: PseudoCanonicalInput < ' tcx , ( ty:: PolyFnSig < ' tcx > , & ' tcx ty:: List < Ty < ' tcx > > ) > ,
336
298
) -> Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , & ' tcx FnAbiError < ' tcx > > {
337
299
let ty:: PseudoCanonicalInput { typing_env, value : ( sig, extra_args) } = query;
300
+
338
301
let cx = LayoutCx :: new ( tcx, typing_env) ;
339
- fn_abi_new_uncached ( & cx, sig, extra_args, None , None , false )
302
+ fn_abi_new_uncached (
303
+ & cx,
304
+ tcx. instantiate_bound_regions_with_erased ( sig) ,
305
+ extra_args,
306
+ None ,
307
+ None ,
308
+ false ,
309
+ )
340
310
}
341
311
342
312
fn fn_abi_of_instance < ' tcx > (
@@ -567,15 +537,15 @@ fn fn_abi_sanity_check<'tcx>(
567
537
#[ tracing:: instrument( level = "debug" , skip( cx, caller_location, fn_def_id, force_thin_self_ptr) ) ]
568
538
fn fn_abi_new_uncached < ' tcx > (
569
539
cx : & LayoutCx < ' tcx > ,
570
- sig : ty:: PolyFnSig < ' tcx > ,
540
+ sig : ty:: FnSig < ' tcx > ,
571
541
extra_args : & [ Ty < ' tcx > ] ,
572
542
caller_location : Option < Ty < ' tcx > > ,
573
543
fn_def_id : Option < DefId > ,
574
544
// FIXME(eddyb) replace this with something typed, like an `enum`.
575
545
force_thin_self_ptr : bool ,
576
546
) -> Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , & ' tcx FnAbiError < ' tcx > > {
577
547
let tcx = cx. tcx ( ) ;
578
- let sig = tcx. normalize_erasing_late_bound_regions ( cx. typing_env , sig) ;
548
+ let sig = tcx. normalize_erasing_regions ( cx. typing_env , sig) ;
579
549
580
550
let conv = conv_from_spec_abi ( cx. tcx ( ) , sig. abi , sig. c_variadic ) ;
581
551
0 commit comments