File tree 5 files changed +31
-6
lines changed
test/codegen-units/polymorphization
5 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,8 @@ impl FlagComputation {
196
196
}
197
197
198
198
& ty:: FnDef ( _, substs) => {
199
+ self . add_flags ( TypeFlags :: MAY_POLYMORPHIZE ) ;
200
+
199
201
self . add_substs ( substs) ;
200
202
}
201
203
Original file line number Diff line number Diff line change @@ -150,7 +150,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
150
150
self . has_type_flags ( TypeFlags :: STILL_FURTHER_SPECIALIZABLE )
151
151
}
152
152
153
- /// Does this value contain closures or generators such that it may require
153
+ /// Does this value contain closures, generators or functions such that it may require
154
154
/// polymorphization?
155
155
fn may_polymorphize ( & self ) -> bool {
156
156
self . has_type_flags ( TypeFlags :: MAY_POLYMORPHIZE )
Original file line number Diff line number Diff line change @@ -512,6 +512,14 @@ fn polymorphize<'tcx>(
512
512
self . tcx . mk_closure ( def_id, polymorphized_substs)
513
513
}
514
514
}
515
+ ty:: FnDef ( def_id, substs) => {
516
+ let polymorphized_substs = polymorphize ( self . tcx , def_id, substs) ;
517
+ if substs == polymorphized_substs {
518
+ ty
519
+ } else {
520
+ self . tcx . mk_fn_def ( def_id, polymorphized_substs)
521
+ }
522
+ }
515
523
ty:: Generator ( def_id, substs, movability) => {
516
524
let polymorphized_substs = polymorphize ( self . tcx , def_id, substs) ;
517
525
if substs == polymorphized_substs {
Original file line number Diff line number Diff line change @@ -576,7 +576,7 @@ bitflags! {
576
576
/// replaced later, in a way that would change the results of `impl` specialization?
577
577
const STILL_FURTHER_SPECIALIZABLE = 1 << 17 ;
578
578
579
- /// Does this value contain closures or generators such that it may require
579
+ /// Does this value contain closures, generators or functions such that it may require
580
580
/// polymorphization?
581
581
const MAY_POLYMORPHIZE = 1 << 18 ;
582
582
}
Original file line number Diff line number Diff line change 3
3
4
4
#![ crate_type = "rlib" ]
5
5
6
- // Test that only one copy of `Iter::map` is generated.
6
+ // Test that only one copy of `Iter::map` and `iter::repeat` are generated.
7
+
8
+ fn unused < T > ( ) -> u64 {
9
+ 42
10
+ }
7
11
8
12
fn foo < T > ( ) {
9
13
let x = [ 1 , 2 , 3 , std:: mem:: size_of :: < T > ( ) ] ;
10
14
x. iter ( ) . map ( |_| ( ) ) ;
11
15
}
12
16
17
+ //~ MONO_ITEM fn core::iter[0]::adapters[0]::{{impl}}[29]::new[0]<core::slice[0]::Iter[0]<usize>, pr_75255::foo[0]::{{closure}}[0]<T>> @@ pr_75255-cgu.0[External]
18
+ //~ MONO_ITEM fn core::iter[0]::traits[0]::iterator[0]::Iterator[0]::map[0]<core::slice[0]::Iter[0]<usize>, (), pr_75255::foo[0]::{{closure}}[0]<T>> @@ pr_75255-cgu.1[Internal]
19
+
20
+ fn bar < T > ( ) {
21
+ std:: iter:: repeat ( unused :: < T > ) ;
22
+ }
23
+
24
+ //~ MONO_ITEM fn core::iter[0]::sources[0]::repeat[0]<fn() -> u64> @@ pr_75255-cgu.1[Internal]
25
+
13
26
pub fn dispatch ( ) {
14
27
foo :: < String > ( ) ;
15
28
foo :: < Vec < String > > ( ) ;
16
- }
17
29
18
- //~ MONO_ITEM fn core::iter[0]::adapters[0]::{{impl}}[29]::new[0]<core::slice[0]::Iter[0]<usize>, pr_75255::foo[0]::{{closure}}[0]<T>> @@ pr_75255-cgu.0[External]
19
- //~ MONO_ITEM fn core::iter[0]::traits[0]::iterator[0]::Iterator[0]::map[0]<core::slice[0]::Iter[0]<usize>, (), pr_75255::foo[0]::{{closure}}[0]<T>> @@ pr_75255-cgu.1[Internal]
30
+ bar :: < String > ( ) ;
31
+ bar :: < Vec < String > > ( ) ;
32
+ }
20
33
21
34
// These are all the items that aren't relevant to the test.
22
35
//~ MONO_ITEM fn core::mem[0]::size_of[0]<alloc::string[0]::String[0]> @@ pr_75255-cgu.1[Internal]
@@ -35,3 +48,5 @@ pub fn dispatch() {
35
48
//~ MONO_ITEM fn pr_75255::dispatch[0] @@ pr_75255-cgu.1[External]
36
49
//~ MONO_ITEM fn pr_75255::foo[0]<alloc::string[0]::String[0]> @@ pr_75255-cgu.1[Internal]
37
50
//~ MONO_ITEM fn pr_75255::foo[0]<alloc::vec[0]::Vec[0]<alloc::string[0]::String[0]>> @@ pr_75255-cgu.1[Internal]
51
+ //~ MONO_ITEM fn pr_75255::bar[0]<alloc::string[0]::String[0]> @@ pr_75255-cgu.1[Internal]
52
+ //~ MONO_ITEM fn pr_75255::bar[0]<alloc::vec[0]::Vec[0]<alloc::string[0]::String[0]>> @@ pr_75255-cgu.1[Internal]
You can’t perform that action at this time.
0 commit comments