Skip to content

Commit 65a6eb6

Browse files
committed
Add proper name mangling for pattern types
1 parent eec6bd9 commit 65a6eb6

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-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: 11 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
@@ -1139,6 +1141,7 @@ The following is a summary of all of the productions of the symbol grammar.
11391141
> &nbsp;&nbsp; | *[mut-ptr-type]* \
11401142
> &nbsp;&nbsp; | *[fn-type]* \
11411143
> &nbsp;&nbsp; | *[dyn-trait-type]* \
1144+
> &nbsp;&nbsp; | *[pattern-type]* \
11421145
> &nbsp;&nbsp; | *[path]* \
11431146
> &nbsp;&nbsp; | *[backref]*
11441147
>
@@ -1152,6 +1155,14 @@ The following is a summary of all of the productions of the symbol grammar.
11521155
> [mut-ptr-type] → `O` *[type]* \
11531156
> [fn-type] → `F` *[fn-sig]* \
11541157
> [dyn-trait-type] → `D` *[dyn-bounds]* *[lifetime]*
1158+
> [pattern-type] → `W` *[pattern-kind]*
1159+
>
1160+
> [pattern-kind] → \
1161+
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *[range-pattern-kind]* \
1162+
> &nbsp;&nbsp; *[or-pattern-kind]* \
1163+
>
1164+
> [range-pattern-kind] -> `R` *[const]* *[const]* \
1165+
> [or-pattern-kind] -> `O` *[pattern-kind]* `E` \
11551166
>
11561167
> [namespace] → *[lower]* | *[upper]*
11571168
>

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)