Skip to content

Commit 38a6660

Browse files
authored
Unrolled build for #142401
Rollup merge of #142401 - oli-obk:pattern-mango, r=petrochenkov Add proper name mangling for pattern types requires adding demangler support first rust-lang/rustc-demangle#81 needed for #136006 (comment) as otherwise we will have symbol collisions
2 parents eabf390 + 739e899 commit 38a6660

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

compiler/rustc_symbol_mangling/src/v0.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,16 @@ impl<'tcx> V0SymbolMangler<'tcx> {
262262
fn print_pat(&mut self, pat: ty::Pattern<'tcx>) -> Result<(), std::fmt::Error> {
263263
Ok(match *pat {
264264
ty::PatternKind::Range { start, end } => {
265-
let consts = [start, end];
266-
for ct in consts {
267-
Ty::new_array_with_const_len(self.tcx, self.tcx.types.unit, ct).print(self)?;
268-
}
265+
self.push("R");
266+
self.print_const(start)?;
267+
self.print_const(end)?;
269268
}
270269
ty::PatternKind::Or(patterns) => {
270+
self.push("O");
271271
for pat in patterns {
272272
self.print_pat(pat)?;
273273
}
274+
self.push("E");
274275
}
275276
})
276277
}
@@ -498,12 +499,9 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> {
498499
}
499500

500501
ty::Pat(ty, pat) => {
501-
// HACK: Represent as tuple until we have something better.
502-
// HACK: constants are used in arrays, even if the types don't match.
503-
self.push("T");
502+
self.push("W");
504503
ty.print(self)?;
505504
self.print_pat(pat)?;
506-
self.push("E");
507505
}
508506

509507
ty::Array(ty, len) => {

src/doc/rustc/src/symbol-mangling/v0.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ A *placeholder* may occur in circumstances where a type or const value is not re
710710
[mut-ptr-type]: #mut-ptr-type
711711
[fn-type]: #fn-type
712712
[dyn-trait-type]: #dyn-trait-type
713+
[pattern-type]: #pattern-type
713714
714715
> type → \
715716
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *[basic-type]* \
@@ -722,6 +723,7 @@ A *placeholder* may occur in circumstances where a type or const value is not re
722723
> &nbsp;&nbsp; | *[mut-ptr-type]* \
723724
> &nbsp;&nbsp; | *[fn-type]* \
724725
> &nbsp;&nbsp; | *[dyn-trait-type]* \
726+
> &nbsp;&nbsp; | *[pattern-type]* \
725727
> &nbsp;&nbsp; | *[path]* \
726728
> &nbsp;&nbsp; | *[backref]*
727729
@@ -830,6 +832,23 @@ Remaining primitives are encoded as a crate production, e.g. `C4f128`.
830832
[fn-sig]: #fn-sig
831833
[abi]: #abi
832834
835+
* `W` — A [pattern-type][pattern-tpye] `u32 is 0..100`.
836+
> <span id="pattern-type">pattern-type</span> → `W` *[pattern-kind]*
837+
>
838+
> <span id="pattern-kind">pattern-kind</span> → \
839+
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *[range-pattern-kind]* \
840+
> &nbsp;&nbsp; *[or-pattern-kind]*
841+
>
842+
> <span id="range-pattern-kind">range-pattern-kind</span> → `R` *[const]* *[const]*
843+
>
844+
> <span id="or-pattern-kind">or-pattern-kind</span> → `O` *[pattern-kind]* `E`
845+
846+
While or patterns can be nested in theory, in practice this does not happen and they are instead flattened.
847+
848+
Range patterns have a start and end constant that are both included in the range.
849+
The end must be larger than the start (there can be no wraparound). To emulate wraparound,
850+
you need to use an or pattern of the two ranges to the upper limit and from the lower limit.
851+
833852
* `D` — A [trait object][reference-trait-object] `dyn Trait<Assoc=X> + Send + 'a`.
834853
835854
> <span id="dyn-trait-type">dyn-trait-type</span> → `D` *[dyn-bounds]* *[lifetime]*
@@ -1139,6 +1158,7 @@ The following is a summary of all of the productions of the symbol grammar.
11391158
> &nbsp;&nbsp; | *[mut-ptr-type]* \
11401159
> &nbsp;&nbsp; | *[fn-type]* \
11411160
> &nbsp;&nbsp; | *[dyn-trait-type]* \
1161+
> &nbsp;&nbsp; | *[pattern-type]* \
11421162
> &nbsp;&nbsp; | *[path]* \
11431163
> &nbsp;&nbsp; | *[backref]*
11441164
>
@@ -1152,6 +1172,14 @@ The following is a summary of all of the productions of the symbol grammar.
11521172
> [mut-ptr-type] → `O` *[type]* \
11531173
> [fn-type] → `F` *[fn-sig]* \
11541174
> [dyn-trait-type] → `D` *[dyn-bounds]* *[lifetime]*
1175+
> [pattern-type] → `W` *[pattern-kind]*
1176+
>
1177+
> [pattern-kind] → \
1178+
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *[range-pattern-kind]* \
1179+
> &nbsp;&nbsp; *[or-pattern-kind]*
1180+
>
1181+
> [range-pattern-kind] -> `R` *[const]* *[const]* \
1182+
> [or-pattern-kind] -> `O` *[pattern-kind]* `E` \
11551183
>
11561184
> [namespace] → *[lower]* | *[upper]*
11571185
>

tests/codegen-llvm/pattern_type_symbols.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn bar() {
1616
// CHECK: call pattern_type_symbols::foo::<u32>
1717
// CHECK: call void @_RINvC[[CRATE_IDENT:[a-zA-Z0-9]{12}]]_20pattern_type_symbols3foomEB2_
1818
foo::<u32>();
19-
// CHECK: call pattern_type_symbols::foo::<(u32, [(); 0], [(); 999999999])>
20-
// CHECK: call void @_RINvC[[CRATE_IDENT]]_20pattern_type_symbols3fooTmAum0_Aum3b9ac9ff_EEB2_
19+
// CHECK: call pattern_type_symbols::foo::<u32 is 0..=999999999>
20+
// CHECK: call void @_RINvC[[CRATE_IDENT]]_20pattern_type_symbols3fooWmRm0_m3b9ac9ff_EB2_
2121
foo::<NanoU32>();
2222
}

0 commit comments

Comments
 (0)