From 6b52603a49187e8ec1712bab2a7c0b87108fa89c Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 5 Oct 2020 00:28:05 +0100 Subject: [PATCH 1/5] Support signed integers and `char` in v0 mangling --- compiler/rustc_symbol_mangling/src/v0.rs | 26 +++++-- src/test/ui/symbol-names/const-generics.rs | 87 ++++++++++++++++++++++ 2 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 src/test/ui/symbol-names/const-generics.rs diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 16d0b86903e..8c6ed7bd140 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -4,6 +4,7 @@ use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData}; +use rustc_middle::mir::interpret::sign_extend; use rustc_middle::ty::print::{Print, Printer}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable}; @@ -527,17 +528,30 @@ fn print_const(mut self, ct: &'tcx ty::Const<'tcx>) -> Result {} - ty::Bool => {} + let mut neg = false; + let val = match ct.ty.kind() { + ty::Uint(_) | ty::Bool | ty::Char => { + ct.try_eval_bits(self.tcx, ty::ParamEnv::reveal_all(), ct.ty) + } + ty::Int(_) => { + let param_env = ty::ParamEnv::reveal_all(); + ct.try_eval_bits(self.tcx, param_env, ct.ty).and_then(|b| { + let sz = self.tcx.layout_of(param_env.and(ct.ty)).ok()?.size; + let val = sign_extend(b, sz) as i128; + if val < 0 { + neg = true; + } + Some(val.wrapping_abs() as u128) + }) + } _ => { bug!("symbol_names: unsupported constant of type `{}` ({:?})", ct.ty, ct); } - } + }; self = ct.ty.print(self)?; - if let Some(bits) = ct.try_eval_bits(self.tcx, ty::ParamEnv::reveal_all(), ct.ty) { - let _ = write!(self.out, "{:x}_", bits); + if let Some(bits) = val { + let _ = write!(self.out, "{}{:x}_", if neg { "n" } else { "" }, bits); } else { // NOTE(eddyb) despite having the path, we need to // encode a placeholder, as the path could refer diff --git a/src/test/ui/symbol-names/const-generics.rs b/src/test/ui/symbol-names/const-generics.rs new file mode 100644 index 00000000000..ad87000228d --- /dev/null +++ b/src/test/ui/symbol-names/const-generics.rs @@ -0,0 +1,87 @@ +// check-pass +// revisions: legacy v0 +//[legacy]compile-flags: -Z symbol-mangling-version=legacy --crate-type=lib + //[v0]compile-flags: -Z symbol-mangling-version=v0 --crate-type=lib + + #![feature(min_const_generics)] + + // `char` + pub struct Char; + + impl Char<'A'> { + pub fn foo() {} + } + + impl Char { + pub fn bar() {} + } + + // `i8` + pub struct I8; + + impl I8<{std::i8::MIN}> { + pub fn foo() {} + } + + impl I8<{std::i8::MAX}> { + pub fn foo() {} + } + + impl I8 { + pub fn bar() {} + } + + // `i16` + pub struct I16; + + impl I16<{std::i16::MIN}> { + pub fn foo() {} + } + + impl I16 { + pub fn bar() {} + } + + // `i32` + pub struct I32; + + impl I32<{std::i32::MIN}> { + pub fn foo() {} + } + + impl I32 { + pub fn bar() {} + } + + // `i64` + pub struct I64; + + impl I64<{std::i64::MIN}> { + pub fn foo() {} + } + + impl I64 { + pub fn bar() {} + } + + // `i128` + pub struct I128; + + impl I128<{std::i128::MIN}> { + pub fn foo() {} + } + + impl I128 { + pub fn bar() {} + } + + // `isize` + pub struct ISize; + + impl ISize<3> { + pub fn foo() {} + } + + impl ISize { + pub fn bar() {} + } From 37c00c41f82e50c3b3ca43326faa6ccb909fb2b5 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 7 Oct 2020 19:31:23 +0100 Subject: [PATCH 2/5] Do not print type for placeholder values --- compiler/rustc_symbol_mangling/src/v0.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 8c6ed7bd140..7833385cbc9 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -548,9 +548,10 @@ fn print_const(mut self, ct: &'tcx ty::Const<'tcx>) -> Result Date: Wed, 7 Oct 2020 20:52:02 +0100 Subject: [PATCH 3/5] Update rustc-demangle --- Cargo.lock | 4 ++-- compiler/rustc_codegen_llvm/Cargo.toml | 2 +- compiler/rustc_symbol_mangling/Cargo.toml | 2 +- library/std/Cargo.toml | 2 +- src/tools/rust-demangler/Cargo.toml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0d2170a9927..f6483e7e3db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3276,9 +3276,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +checksum = "b2610b7f643d18c87dff3b489950269617e6601a51f1f05aa5daefee36f64f0b" dependencies = [ "compiler_builtins", "rustc-std-workspace-core", diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index 04792b334d5..3856582dc34 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -15,7 +15,7 @@ measureme = "0.7.1" snap = "1" tracing = "0.1" rustc_middle = { path = "../rustc_middle" } -rustc-demangle = "0.1" +rustc-demangle = "0.1.17" rustc_attr = { path = "../rustc_attr" } rustc_codegen_ssa = { path = "../rustc_codegen_ssa" } rustc_data_structures = { path = "../rustc_data_structures" } diff --git a/compiler/rustc_symbol_mangling/Cargo.toml b/compiler/rustc_symbol_mangling/Cargo.toml index c0dacd24c38..8956366a263 100644 --- a/compiler/rustc_symbol_mangling/Cargo.toml +++ b/compiler/rustc_symbol_mangling/Cargo.toml @@ -10,7 +10,7 @@ doctest = false [dependencies] tracing = "0.1" punycode = "0.4.0" -rustc-demangle = "0.1.16" +rustc-demangle = "0.1.17" rustc_ast = { path = "../rustc_ast" } rustc_span = { path = "../rustc_span" } diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index c08828bc0cd..edd6c0f2046 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -24,7 +24,7 @@ hashbrown = { version = "0.9.0", default-features = false, features = ['rustc-de # Dependencies of the `backtrace` crate addr2line = { version = "0.13.0", optional = true, default-features = false } -rustc-demangle = { version = "0.1.4", features = ['rustc-dep-of-std'] } +rustc-demangle = { version = "0.1.17", features = ['rustc-dep-of-std'] } miniz_oxide = { version = "0.4.0", optional = true, default-features = false } [dependencies.object] version = "0.20" diff --git a/src/tools/rust-demangler/Cargo.toml b/src/tools/rust-demangler/Cargo.toml index c978bbe20e8..ac684a3c47e 100644 --- a/src/tools/rust-demangler/Cargo.toml +++ b/src/tools/rust-demangler/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] regex = "1.0" -rustc-demangle = "0.1" +rustc-demangle = "0.1.17" [[bin]] name = "rust-demangler" From a797801532359d8019eb89e75e509028327b9763 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 7 Oct 2020 21:17:07 +0100 Subject: [PATCH 4/5] Add test for const generics demangling --- .../symbol-names/const-generics-demangling.rs | 38 ++++++++++ .../const-generics-demangling.stderr | 74 +++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 src/test/ui/symbol-names/const-generics-demangling.rs create mode 100644 src/test/ui/symbol-names/const-generics-demangling.stderr diff --git a/src/test/ui/symbol-names/const-generics-demangling.rs b/src/test/ui/symbol-names/const-generics-demangling.rs new file mode 100644 index 00000000000..e002124059f --- /dev/null +++ b/src/test/ui/symbol-names/const-generics-demangling.rs @@ -0,0 +1,38 @@ +// build-fail +// compile-flags: -Z symbol-mangling-version=v0 + +#![feature(min_const_generics, rustc_attrs)] + +pub struct Unsigned; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMCs4fqI2P2rA04_25const_generics_demanglingINtB0_8UnsignedKhb_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl Unsigned<11> {} + +pub struct Signed; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs_Cs4fqI2P2rA04_25const_generics_demanglingINtB2_6SignedKsn98_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl Signed<-152> {} + +pub struct Bool; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs0_Cs4fqI2P2rA04_25const_generics_demanglingINtB3_4BoolKb1_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl Bool {} + +pub struct Char; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs1_Cs4fqI2P2rA04_25const_generics_demanglingINtB3_4CharKc2202_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl Char<'∂'> {} + +fn main() {} diff --git a/src/test/ui/symbol-names/const-generics-demangling.stderr b/src/test/ui/symbol-names/const-generics-demangling.stderr new file mode 100644 index 00000000000..022b3188373 --- /dev/null +++ b/src/test/ui/symbol-names/const-generics-demangling.stderr @@ -0,0 +1,74 @@ +error: symbol-name(_RMCs4fqI2P2rA04_25const_generics_demanglingINtB0_8UnsignedKhb_E) + --> $DIR/const-generics-demangling.rs:8:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-demangling.rs:8:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-demangling.rs:8:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs_Cs4fqI2P2rA04_25const_generics_demanglingINtB2_6SignedKsn98_E) + --> $DIR/const-generics-demangling.rs:16:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-demangling.rs:16:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-demangling.rs:16:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs0_Cs4fqI2P2rA04_25const_generics_demanglingINtB3_4BoolKb1_E) + --> $DIR/const-generics-demangling.rs:24:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-demangling.rs:24:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-demangling.rs:24:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs1_Cs4fqI2P2rA04_25const_generics_demanglingINtB3_4CharKc2202_E) + --> $DIR/const-generics-demangling.rs:32:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-demangling.rs:32:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-demangling.rs:32:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 12 previous errors + From 878c97e70c01d588c5a96d04f02b1c9298e94ecc Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 21 Oct 2020 21:11:11 +0100 Subject: [PATCH 5/5] Update to rustc-demangle 0.1.18 --- Cargo.lock | 4 ++-- compiler/rustc_codegen_llvm/Cargo.toml | 2 +- compiler/rustc_symbol_mangling/Cargo.toml | 2 +- library/std/Cargo.toml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f6483e7e3db..a3c4d2493ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3276,9 +3276,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2610b7f643d18c87dff3b489950269617e6601a51f1f05aa5daefee36f64f0b" +checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" dependencies = [ "compiler_builtins", "rustc-std-workspace-core", diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index 3856582dc34..586b9d08374 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -15,7 +15,7 @@ measureme = "0.7.1" snap = "1" tracing = "0.1" rustc_middle = { path = "../rustc_middle" } -rustc-demangle = "0.1.17" +rustc-demangle = "0.1.18" rustc_attr = { path = "../rustc_attr" } rustc_codegen_ssa = { path = "../rustc_codegen_ssa" } rustc_data_structures = { path = "../rustc_data_structures" } diff --git a/compiler/rustc_symbol_mangling/Cargo.toml b/compiler/rustc_symbol_mangling/Cargo.toml index 8956366a263..3df5f161319 100644 --- a/compiler/rustc_symbol_mangling/Cargo.toml +++ b/compiler/rustc_symbol_mangling/Cargo.toml @@ -10,7 +10,7 @@ doctest = false [dependencies] tracing = "0.1" punycode = "0.4.0" -rustc-demangle = "0.1.17" +rustc-demangle = "0.1.18" rustc_ast = { path = "../rustc_ast" } rustc_span = { path = "../rustc_span" } diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index edd6c0f2046..47b59d4a677 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -24,7 +24,7 @@ hashbrown = { version = "0.9.0", default-features = false, features = ['rustc-de # Dependencies of the `backtrace` crate addr2line = { version = "0.13.0", optional = true, default-features = false } -rustc-demangle = { version = "0.1.17", features = ['rustc-dep-of-std'] } +rustc-demangle = { version = "0.1.18", features = ['rustc-dep-of-std'] } miniz_oxide = { version = "0.4.0", optional = true, default-features = false } [dependencies.object] version = "0.20"