Skip to content

Commit 813066c

Browse files
authored
Rollup merge of #77554 - varkor:mangle-int-char, r=eddyb
Support signed integers and `char` in v0 mangling Likely we want more tests, to check the output is correct too: however, I wasn't sure what kind of test we needed, so I just added one similar to that added in #77452 for now. r? @eddyb
2 parents 6245b95 + 878c97e commit 813066c

File tree

9 files changed

+227
-13
lines changed

9 files changed

+227
-13
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -3276,9 +3276,9 @@ dependencies = [
32763276

32773277
[[package]]
32783278
name = "rustc-demangle"
3279-
version = "0.1.16"
3279+
version = "0.1.18"
32803280
source = "registry+https://github.com/rust-lang/crates.io-index"
3281-
checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
3281+
checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232"
32823282
dependencies = [
32833283
"compiler_builtins",
32843284
"rustc-std-workspace-core",

compiler/rustc_codegen_llvm/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ measureme = "0.7.1"
1515
snap = "1"
1616
tracing = "0.1"
1717
rustc_middle = { path = "../rustc_middle" }
18-
rustc-demangle = "0.1"
18+
rustc-demangle = "0.1.18"
1919
rustc_attr = { path = "../rustc_attr" }
2020
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
2121
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_symbol_mangling/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ doctest = false
1010
[dependencies]
1111
tracing = "0.1"
1212
punycode = "0.4.0"
13-
rustc-demangle = "0.1.16"
13+
rustc-demangle = "0.1.18"
1414

1515
rustc_ast = { path = "../rustc_ast" }
1616
rustc_span = { path = "../rustc_span" }

compiler/rustc_symbol_mangling/src/v0.rs

+22-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
44
use rustc_hir as hir;
55
use rustc_hir::def_id::{CrateNum, DefId};
66
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
7+
use rustc_middle::mir::interpret::sign_extend;
78
use rustc_middle::ty::print::{Print, Printer};
89
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
910
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
@@ -527,17 +528,31 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
527528
}
528529
let start = self.out.len();
529530

530-
match ct.ty.kind() {
531-
ty::Uint(_) => {}
532-
ty::Bool => {}
531+
let mut neg = false;
532+
let val = match ct.ty.kind() {
533+
ty::Uint(_) | ty::Bool | ty::Char => {
534+
ct.try_eval_bits(self.tcx, ty::ParamEnv::reveal_all(), ct.ty)
535+
}
536+
ty::Int(_) => {
537+
let param_env = ty::ParamEnv::reveal_all();
538+
ct.try_eval_bits(self.tcx, param_env, ct.ty).and_then(|b| {
539+
let sz = self.tcx.layout_of(param_env.and(ct.ty)).ok()?.size;
540+
let val = sign_extend(b, sz) as i128;
541+
if val < 0 {
542+
neg = true;
543+
}
544+
Some(val.wrapping_abs() as u128)
545+
})
546+
}
533547
_ => {
534548
bug!("symbol_names: unsupported constant of type `{}` ({:?})", ct.ty, ct);
535549
}
536-
}
537-
self = ct.ty.print(self)?;
550+
};
538551

539-
if let Some(bits) = ct.try_eval_bits(self.tcx, ty::ParamEnv::reveal_all(), ct.ty) {
540-
let _ = write!(self.out, "{:x}_", bits);
552+
if let Some(bits) = val {
553+
// We only print the type if the const can be evaluated.
554+
self = ct.ty.print(self)?;
555+
let _ = write!(self.out, "{}{:x}_", if neg { "n" } else { "" }, bits);
541556
} else {
542557
// NOTE(eddyb) despite having the path, we need to
543558
// encode a placeholder, as the path could refer

library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ hashbrown = { version = "0.9.0", default-features = false, features = ['rustc-de
2424

2525
# Dependencies of the `backtrace` crate
2626
addr2line = { version = "0.13.0", optional = true, default-features = false }
27-
rustc-demangle = { version = "0.1.4", features = ['rustc-dep-of-std'] }
27+
rustc-demangle = { version = "0.1.18", features = ['rustc-dep-of-std'] }
2828
miniz_oxide = { version = "0.4.0", optional = true, default-features = false }
2929
[dependencies.object]
3030
version = "0.20"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// build-fail
2+
// compile-flags: -Z symbol-mangling-version=v0
3+
4+
#![feature(min_const_generics, rustc_attrs)]
5+
6+
pub struct Unsigned<const F: u8>;
7+
8+
#[rustc_symbol_name]
9+
//~^ ERROR symbol-name(_RMCs4fqI2P2rA04_25const_generics_demanglingINtB0_8UnsignedKhb_E)
10+
//~| ERROR demangling(<const_generics_demangling[317d481089b8c8fe]::Unsigned<11: u8>>)
11+
//~| ERROR demangling-alt(<const_generics_demangling::Unsigned<11>>)
12+
impl Unsigned<11> {}
13+
14+
pub struct Signed<const F: i16>;
15+
16+
#[rustc_symbol_name]
17+
//~^ ERROR symbol-name(_RMs_Cs4fqI2P2rA04_25const_generics_demanglingINtB2_6SignedKsn98_E)
18+
//~| ERROR demangling(<const_generics_demangling[317d481089b8c8fe]::Signed<-152: i16>>)
19+
//~| ERROR demangling-alt(<const_generics_demangling::Signed<-152>>)
20+
impl Signed<-152> {}
21+
22+
pub struct Bool<const F: bool>;
23+
24+
#[rustc_symbol_name]
25+
//~^ ERROR symbol-name(_RMs0_Cs4fqI2P2rA04_25const_generics_demanglingINtB3_4BoolKb1_E)
26+
//~| ERROR demangling(<const_generics_demangling[317d481089b8c8fe]::Bool<true: bool>>)
27+
//~| ERROR demangling-alt(<const_generics_demangling::Bool<true>>)
28+
impl Bool<true> {}
29+
30+
pub struct Char<const F: char>;
31+
32+
#[rustc_symbol_name]
33+
//~^ ERROR symbol-name(_RMs1_Cs4fqI2P2rA04_25const_generics_demanglingINtB3_4CharKc2202_E)
34+
//~| ERROR demangling(<const_generics_demangling[317d481089b8c8fe]::Char<'∂': char>>)
35+
//~| ERROR demangling-alt(<const_generics_demangling::Char<'∂'>>)
36+
impl Char<'∂'> {}
37+
38+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
error: symbol-name(_RMCs4fqI2P2rA04_25const_generics_demanglingINtB0_8UnsignedKhb_E)
2+
--> $DIR/const-generics-demangling.rs:8:1
3+
|
4+
LL | #[rustc_symbol_name]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
7+
error: demangling(<const_generics_demangling[317d481089b8c8fe]::Unsigned<11: u8>>)
8+
--> $DIR/const-generics-demangling.rs:8:1
9+
|
10+
LL | #[rustc_symbol_name]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: demangling-alt(<const_generics_demangling::Unsigned<11>>)
14+
--> $DIR/const-generics-demangling.rs:8:1
15+
|
16+
LL | #[rustc_symbol_name]
17+
| ^^^^^^^^^^^^^^^^^^^^
18+
19+
error: symbol-name(_RMs_Cs4fqI2P2rA04_25const_generics_demanglingINtB2_6SignedKsn98_E)
20+
--> $DIR/const-generics-demangling.rs:16:1
21+
|
22+
LL | #[rustc_symbol_name]
23+
| ^^^^^^^^^^^^^^^^^^^^
24+
25+
error: demangling(<const_generics_demangling[317d481089b8c8fe]::Signed<-152: i16>>)
26+
--> $DIR/const-generics-demangling.rs:16:1
27+
|
28+
LL | #[rustc_symbol_name]
29+
| ^^^^^^^^^^^^^^^^^^^^
30+
31+
error: demangling-alt(<const_generics_demangling::Signed<-152>>)
32+
--> $DIR/const-generics-demangling.rs:16:1
33+
|
34+
LL | #[rustc_symbol_name]
35+
| ^^^^^^^^^^^^^^^^^^^^
36+
37+
error: symbol-name(_RMs0_Cs4fqI2P2rA04_25const_generics_demanglingINtB3_4BoolKb1_E)
38+
--> $DIR/const-generics-demangling.rs:24:1
39+
|
40+
LL | #[rustc_symbol_name]
41+
| ^^^^^^^^^^^^^^^^^^^^
42+
43+
error: demangling(<const_generics_demangling[317d481089b8c8fe]::Bool<true: bool>>)
44+
--> $DIR/const-generics-demangling.rs:24:1
45+
|
46+
LL | #[rustc_symbol_name]
47+
| ^^^^^^^^^^^^^^^^^^^^
48+
49+
error: demangling-alt(<const_generics_demangling::Bool<true>>)
50+
--> $DIR/const-generics-demangling.rs:24:1
51+
|
52+
LL | #[rustc_symbol_name]
53+
| ^^^^^^^^^^^^^^^^^^^^
54+
55+
error: symbol-name(_RMs1_Cs4fqI2P2rA04_25const_generics_demanglingINtB3_4CharKc2202_E)
56+
--> $DIR/const-generics-demangling.rs:32:1
57+
|
58+
LL | #[rustc_symbol_name]
59+
| ^^^^^^^^^^^^^^^^^^^^
60+
61+
error: demangling(<const_generics_demangling[317d481089b8c8fe]::Char<'∂': char>>)
62+
--> $DIR/const-generics-demangling.rs:32:1
63+
|
64+
LL | #[rustc_symbol_name]
65+
| ^^^^^^^^^^^^^^^^^^^^
66+
67+
error: demangling-alt(<const_generics_demangling::Char<'∂'>>)
68+
--> $DIR/const-generics-demangling.rs:32:1
69+
|
70+
LL | #[rustc_symbol_name]
71+
| ^^^^^^^^^^^^^^^^^^^^
72+
73+
error: aborting due to 12 previous errors
74+
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// check-pass
2+
// revisions: legacy v0
3+
//[legacy]compile-flags: -Z symbol-mangling-version=legacy --crate-type=lib
4+
//[v0]compile-flags: -Z symbol-mangling-version=v0 --crate-type=lib
5+
6+
#![feature(min_const_generics)]
7+
8+
// `char`
9+
pub struct Char<const F: char>;
10+
11+
impl Char<'A'> {
12+
pub fn foo() {}
13+
}
14+
15+
impl<const F: char> Char<F> {
16+
pub fn bar() {}
17+
}
18+
19+
// `i8`
20+
pub struct I8<const F: i8>;
21+
22+
impl I8<{std::i8::MIN}> {
23+
pub fn foo() {}
24+
}
25+
26+
impl I8<{std::i8::MAX}> {
27+
pub fn foo() {}
28+
}
29+
30+
impl<const F: i8> I8<F> {
31+
pub fn bar() {}
32+
}
33+
34+
// `i16`
35+
pub struct I16<const F: i16>;
36+
37+
impl I16<{std::i16::MIN}> {
38+
pub fn foo() {}
39+
}
40+
41+
impl<const F: i16> I16<F> {
42+
pub fn bar() {}
43+
}
44+
45+
// `i32`
46+
pub struct I32<const F: i32>;
47+
48+
impl I32<{std::i32::MIN}> {
49+
pub fn foo() {}
50+
}
51+
52+
impl<const F: i32> I32<F> {
53+
pub fn bar() {}
54+
}
55+
56+
// `i64`
57+
pub struct I64<const F: i64>;
58+
59+
impl I64<{std::i64::MIN}> {
60+
pub fn foo() {}
61+
}
62+
63+
impl<const F: i64> I64<F> {
64+
pub fn bar() {}
65+
}
66+
67+
// `i128`
68+
pub struct I128<const F: i128>;
69+
70+
impl I128<{std::i128::MIN}> {
71+
pub fn foo() {}
72+
}
73+
74+
impl<const F: i128> I128<F> {
75+
pub fn bar() {}
76+
}
77+
78+
// `isize`
79+
pub struct ISize<const F: isize>;
80+
81+
impl ISize<3> {
82+
pub fn foo() {}
83+
}
84+
85+
impl<const F: isize> ISize<F> {
86+
pub fn bar() {}
87+
}

src/tools/rust-demangler/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2018"
66

77
[dependencies]
88
regex = "1.0"
9-
rustc-demangle = "0.1"
9+
rustc-demangle = "0.1.17"
1010

1111
[[bin]]
1212
name = "rust-demangler"

0 commit comments

Comments
 (0)