@@ -691,28 +691,30 @@ Mangled names conform to the following grammar:
691
691
| "D" <dyn-bounds> <lifetime> // dyn Trait<Assoc = X> + Send + 'a
692
692
| <backref>
693
693
694
- <basic-type> = "a" // i8
694
+ <basic-type> = <int-type>
695
695
| "b" // bool
696
696
| "c" // char
697
697
| "d" // f64
698
698
| "e" // str
699
699
| "f" // f32
700
- | "h" // u8
701
- | "i" // isize
702
- | "j" // usize
703
- | "l" // i32
704
- | "m" // u32
705
- | "n" // i128
706
- | "o" // u128
707
- | "s" // i16
708
- | "t" // u16
709
700
| "u" // ()
710
701
| "v" // ...
711
- | "x" // i64
712
- | "y" // u64
713
702
| "z" // !
714
703
| "p" // placeholder (e.g. for generic params), shown as _
715
704
705
+ <int-type> = "a" // i8
706
+ | "h" // u8
707
+ | "i" // isize
708
+ | "j" // usize
709
+ | "l" // i32
710
+ | "m" // u32
711
+ | "n" // i128
712
+ | "o" // u128
713
+ | "s" // i16
714
+ | "t" // u16
715
+ | "x" // i64
716
+ | "y" // u64
717
+
716
718
// If the "U" is present then the function is `unsafe`.
717
719
// The return type is always present, but demanglers can
718
720
// choose to omit the ` -> ()` by special-casing "u".
@@ -724,16 +726,40 @@ Mangled names conform to the following grammar:
724
726
<dyn-bounds> = [<binder>] {<dyn-trait>} "E"
725
727
<dyn-trait> = <path> {<dyn-trait-assoc-binding>}
726
728
<dyn-trait-assoc-binding> = "p" <undisambiguated-identifier> <type>
727
- <const> = <type> <const-data>
728
- | "p" // placeholder, shown as _
729
+
730
+ // Constants are encoded structurally, as a tree of array/tuple/ADT constructors,
731
+ // with integer(-like) leaves, not using the constant's memory representation.
732
+ // See the comments on <const-int> & <const-str> for more details on leaf encoding.
733
+ <const> = <int-type> <const-int>
734
+ | "b" <const-int> // false, true
735
+ | "c" <const-int> // '...'
736
+ | "e" <const-str> // "..."
737
+ | "R" <const> // &value
738
+ | "Q" <const> // &mut value
739
+ | "A" {<const>} "E" // [a, b, c, ...]
740
+ | "T" {<const>} "E" // (a, b, c, ...)
741
+ | "V" <path> <const-fields> // named struct/variant
742
+ | "p" // placeholder, shown as _
729
743
| <backref>
730
744
731
- // The encoding of a constant depends on its type. Integers use their value,
732
- // in base 16 (0-9a-f), not their memory representation. Negative integer
733
- // values are preceded with "n". The bool value false is encoded as `0_`, true
734
- // value as `1_`. The char constants are encoded using their Unicode scalar
735
- // value.
736
- <const-data> = ["n"] {<hex-digit>} "_"
745
+ <const-fields> = "U" // X
746
+ | "T" {<const>} "E" // X(a, b, c, ...)
747
+ | "S" {<identifier> <const>} "E" // X { field: value, ... }
748
+
749
+ // An integer(-like) constant's numeric value is encoded in base 16 (0-9a-f),
750
+ // with negative integer values being preceded with "n".
751
+ // For other types, the numeric value is the same one used for `as` casts, i.e.:
752
+ // * `bool`: 0 for `false` (encoded as `0_`), 1 for `true` (encoded as `1_`)
753
+ // * `char`: the Unicode scalar value
754
+ <const-int> = ["n"] {<hex-digit>} "_"
755
+
756
+ // `str` constants are encoded as their (UTF-8) byte sequence, where each byte
757
+ // always uses two hex nibbles.
758
+ // Because the constant has `str` type, and not `&str`, demangling should make
759
+ // that clear by e.g. demangling `616263_` as `*"abc"` (instead of `"abc"`).
760
+ // In order to have constants of type `&str` demangle as a plain string literal
761
+ // (i.e. without `&*`), demanglers can special-case `Re...` constants.
762
+ <const-str> = {<hex-digit> <hex-digit>} "_"
737
763
738
764
// <base-62-number> uses 0-9-a-z-A-Z as digits, i.e. 'a' is decimal 10 and
739
765
// 'Z' is decimal 61.
@@ -1156,3 +1182,4 @@ pub static QUUX: u32 = {
1156
1182
- Make ` <binder> ` optional in ` <fn-sig> ` and ` <dyn-bounds> ` productions.
1157
1183
- Extend ` <const-data> ` to include ` bool ` values, ` char ` values, and negative integer values.
1158
1184
- Remove type from constant placeholders.
1185
+ - Extend ` <const> ` to include ` str ` and structural constants
0 commit comments