@@ -31,90 +31,63 @@ fn fn_sig_for_fn_abi<'tcx>(
31
31
tcx : TyCtxt < ' tcx > ,
32
32
instance : ty:: Instance < ' tcx > ,
33
33
param_env : ty:: ParamEnv < ' 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, param_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 ( tcx. param_env ( def_id) , fn_sig)
60
59
} )
61
60
. instantiate ( tcx, args) ,
62
- _ => unreachable ! ( ) ,
63
- } ;
61
+ ) ;
64
62
65
63
if let ty:: InstanceKind :: VTableShim ( ..) = instance. def {
66
- // Modify `fn(self, ...)` to `fn(self: *mut Self, ...)`.
67
- sig = sig. map_bound ( |mut sig| {
68
- let mut inputs_and_output = sig. inputs_and_output . to_vec ( ) ;
69
- inputs_and_output[ 0 ] = Ty :: new_mut_ptr ( tcx, inputs_and_output[ 0 ] ) ;
70
- sig. inputs_and_output = tcx. mk_type_list ( & inputs_and_output) ;
71
- sig
72
- } ) ;
64
+ let mut inputs_and_output = sig. inputs_and_output . to_vec ( ) ;
65
+ inputs_and_output[ 0 ] = Ty :: new_mut_ptr ( tcx, inputs_and_output[ 0 ] ) ;
66
+ sig. inputs_and_output = tcx. mk_type_list ( & inputs_and_output) ;
73
67
}
68
+
74
69
sig
75
70
}
76
71
ty:: Closure ( def_id, args) => {
77
- let sig = args. as_closure ( ) . sig ( ) ;
78
-
79
- let bound_vars =
80
- tcx. mk_bound_variable_kinds_from_iter ( sig. bound_vars ( ) . iter ( ) . chain ( iter:: once (
81
- ty:: BoundVariableKind :: Region ( ty:: BoundRegionKind :: ClosureEnv ) ,
82
- ) ) ) ;
83
- let br = ty:: BoundRegion {
84
- var : ty:: BoundVar :: from_usize ( bound_vars. len ( ) - 1 ) ,
85
- kind : ty:: BoundRegionKind :: ClosureEnv ,
86
- } ;
87
- let env_region = ty:: Region :: new_bound ( tcx, ty:: INNERMOST , br) ;
72
+ let sig = tcx. instantiate_bound_regions_with_erased ( args. as_closure ( ) . sig ( ) ) ;
88
73
let env_ty = tcx. closure_env_ty (
89
74
Ty :: new_closure ( tcx, def_id, args) ,
90
75
args. as_closure ( ) . kind ( ) ,
91
- env_region ,
76
+ tcx . lifetimes . re_erased ,
92
77
) ;
93
78
94
- let sig = sig. skip_binder ( ) ;
95
- ty:: Binder :: bind_with_vars (
96
- tcx. mk_fn_sig (
97
- iter:: once ( env_ty) . chain ( sig. inputs ( ) . iter ( ) . cloned ( ) ) ,
98
- sig. output ( ) ,
99
- sig. c_variadic ,
100
- sig. safety ,
101
- sig. abi ,
102
- ) ,
103
- bound_vars,
79
+ tcx. mk_fn_sig (
80
+ iter:: once ( env_ty) . chain ( sig. inputs ( ) . iter ( ) . cloned ( ) ) ,
81
+ sig. output ( ) ,
82
+ sig. c_variadic ,
83
+ sig. safety ,
84
+ sig. abi ,
104
85
)
105
86
}
106
87
ty:: CoroutineClosure ( def_id, args) => {
107
88
let coroutine_ty = Ty :: new_coroutine_closure ( tcx, def_id, args) ;
108
89
let sig = args. as_coroutine_closure ( ) . coroutine_closure_sig ( ) ;
109
- let bound_vars =
110
- tcx. mk_bound_variable_kinds_from_iter ( sig. bound_vars ( ) . iter ( ) . chain ( iter:: once (
111
- ty:: BoundVariableKind :: Region ( ty:: BoundRegionKind :: ClosureEnv ) ,
112
- ) ) ) ;
113
- let br = ty:: BoundRegion {
114
- var : ty:: BoundVar :: from_usize ( bound_vars. len ( ) - 1 ) ,
115
- kind : ty:: BoundRegionKind :: ClosureEnv ,
116
- } ;
117
- let env_region = ty:: Region :: new_bound ( tcx, ty:: INNERMOST , br) ;
90
+
118
91
// When this `CoroutineClosure` comes from a `ConstructCoroutineInClosureShim`,
119
92
// make sure we respect the `target_kind` in that shim.
120
93
// FIXME(async_closures): This shouldn't be needed, and we should be populating
@@ -135,42 +108,32 @@ fn fn_sig_for_fn_abi<'tcx>(
135
108
coroutine_ty
136
109
}
137
110
} else {
138
- tcx. closure_env_ty ( coroutine_ty, coroutine_kind, env_region )
111
+ tcx. closure_env_ty ( coroutine_ty, coroutine_kind, tcx . lifetimes . re_erased )
139
112
} ;
140
113
141
- let sig = sig. skip_binder ( ) ;
142
- ty:: Binder :: bind_with_vars (
143
- tcx. mk_fn_sig (
144
- iter:: once ( env_ty) . chain ( [ sig. tupled_inputs_ty ] ) ,
145
- sig. to_coroutine_given_kind_and_upvars (
146
- tcx,
147
- args. as_coroutine_closure ( ) . parent_args ( ) ,
148
- tcx. coroutine_for_closure ( def_id) ,
149
- coroutine_kind,
150
- env_region,
151
- args. as_coroutine_closure ( ) . tupled_upvars_ty ( ) ,
152
- args. as_coroutine_closure ( ) . coroutine_captures_by_ref_ty ( ) ,
153
- ) ,
154
- sig. c_variadic ,
155
- sig. safety ,
156
- sig. abi ,
114
+ let sig = tcx. instantiate_bound_regions_with_erased ( sig) ;
115
+
116
+ tcx. mk_fn_sig (
117
+ iter:: once ( env_ty) . chain ( [ sig. tupled_inputs_ty ] ) ,
118
+ sig. to_coroutine_given_kind_and_upvars (
119
+ tcx,
120
+ args. as_coroutine_closure ( ) . parent_args ( ) ,
121
+ tcx. coroutine_for_closure ( def_id) ,
122
+ coroutine_kind,
123
+ tcx. lifetimes . re_erased ,
124
+ args. as_coroutine_closure ( ) . tupled_upvars_ty ( ) ,
125
+ args. as_coroutine_closure ( ) . coroutine_captures_by_ref_ty ( ) ,
157
126
) ,
158
- bound_vars,
127
+ sig. c_variadic ,
128
+ sig. safety ,
129
+ sig. abi ,
159
130
)
160
131
}
161
132
ty:: Coroutine ( did, args) => {
162
133
let coroutine_kind = tcx. coroutine_kind ( did) . unwrap ( ) ;
163
134
let sig = args. as_coroutine ( ) . sig ( ) ;
164
135
165
- let bound_vars = tcx. mk_bound_variable_kinds_from_iter ( iter:: once (
166
- ty:: BoundVariableKind :: Region ( ty:: BoundRegionKind :: ClosureEnv ) ,
167
- ) ) ;
168
- let br = ty:: BoundRegion {
169
- var : ty:: BoundVar :: from_usize ( bound_vars. len ( ) - 1 ) ,
170
- kind : ty:: BoundRegionKind :: ClosureEnv ,
171
- } ;
172
-
173
- let env_ty = Ty :: new_mut_ref ( tcx, ty:: Region :: new_bound ( tcx, ty:: INNERMOST , br) , ty) ;
136
+ let env_ty = Ty :: new_mut_ref ( tcx, tcx. lifetimes . re_erased , ty) ;
174
137
175
138
let pin_did = tcx. require_lang_item ( LangItem :: Pin , None ) ;
176
139
let pin_adt_ref = tcx. adt_def ( pin_did) ;
@@ -265,7 +228,7 @@ fn fn_sig_for_fn_abi<'tcx>(
265
228
}
266
229
} ;
267
230
268
- let fn_sig = if let Some ( resume_ty) = resume_ty {
231
+ if let Some ( resume_ty) = resume_ty {
269
232
tcx. mk_fn_sig (
270
233
[ env_ty, resume_ty] ,
271
234
ret_ty,
@@ -282,8 +245,7 @@ fn fn_sig_for_fn_abi<'tcx>(
282
245
hir:: Safety :: Safe ,
283
246
rustc_abi:: ExternAbi :: Rust ,
284
247
)
285
- } ;
286
- ty:: Binder :: bind_with_vars ( fn_sig, bound_vars)
248
+ }
287
249
}
288
250
_ => bug ! ( "unexpected type {:?} in Instance::fn_sig" , ty) ,
289
251
}
@@ -334,7 +296,14 @@ fn fn_abi_of_fn_ptr<'tcx>(
334
296
let ( param_env, ( sig, extra_args) ) = query. into_parts ( ) ;
335
297
336
298
let cx = LayoutCx :: new ( tcx, param_env) ;
337
- fn_abi_new_uncached ( & cx, sig, extra_args, None , None , false )
299
+ fn_abi_new_uncached (
300
+ & cx,
301
+ tcx. instantiate_bound_regions_with_erased ( sig) ,
302
+ extra_args,
303
+ None ,
304
+ None ,
305
+ false ,
306
+ )
338
307
}
339
308
340
309
fn fn_abi_of_instance < ' tcx > (
@@ -565,15 +534,16 @@ fn fn_abi_sanity_check<'tcx>(
565
534
#[ tracing:: instrument( level = "debug" , skip( cx, caller_location, fn_def_id, force_thin_self_ptr) ) ]
566
535
fn fn_abi_new_uncached < ' tcx > (
567
536
cx : & LayoutCx < ' tcx > ,
568
- sig : ty:: PolyFnSig < ' tcx > ,
537
+ sig : ty:: FnSig < ' tcx > ,
569
538
extra_args : & [ Ty < ' tcx > ] ,
570
539
caller_location : Option < Ty < ' tcx > > ,
571
540
fn_def_id : Option < DefId > ,
572
541
// FIXME(eddyb) replace this with something typed, like an `enum`.
573
542
force_thin_self_ptr : bool ,
574
543
) -> Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , & ' tcx FnAbiError < ' tcx > > {
575
544
let tcx = cx. tcx ( ) ;
576
- let sig = tcx. normalize_erasing_late_bound_regions ( cx. param_env , sig) ;
545
+ // FIXME: is this needed?
546
+ let sig = tcx. normalize_erasing_regions ( cx. param_env , sig) ;
577
547
578
548
let conv = conv_from_spec_abi ( cx. tcx ( ) , sig. abi , sig. c_variadic ) ;
579
549
0 commit comments