@@ -803,17 +803,6 @@ impl Ident {
803
803
Ident :: new ( self . name , self . span . modern_and_legacy ( ) )
804
804
}
805
805
806
- /// Transforms an underscore identifier into one with the same name, but
807
- /// gensymed. Leaves non-underscore identifiers unchanged.
808
- pub fn gensym_if_underscore ( self ) -> Ident {
809
- if self . name == kw:: Underscore {
810
- let name = with_interner ( |interner| interner. gensymed ( self . name ) ) ;
811
- Ident :: new ( name, self . span )
812
- } else {
813
- self
814
- }
815
- }
816
-
817
806
/// If the name of this ident is "_", then return a new unique identifier.
818
807
/// Otherwise returns `self` unmodified
819
808
#[ inline]
@@ -830,8 +819,7 @@ impl Ident {
830
819
self . name . as_str ( )
831
820
}
832
821
833
- /// Convert the name to an `InternedString`. This is a slowish operation
834
- /// because it requires locking the symbol interner.
822
+ /// Convert the name to an `InternedString`.
835
823
pub fn as_interned_str ( self ) -> InternedString {
836
824
self . name . as_interned_str ( )
837
825
}
@@ -886,26 +874,9 @@ impl UseSpecializedDecodable for Ident {
886
874
}
887
875
}
888
876
889
- /// A symbol is an interned or gensymed string. A gensym is a symbol that is
890
- /// never equal to any other symbol.
891
- ///
892
- /// Conceptually, a gensym can be thought of as a normal symbol with an
893
- /// invisible unique suffix. Gensyms are useful when creating new identifiers
894
- /// that must not match any existing identifiers, e.g. during macro expansion
895
- /// and syntax desugaring. Because gensyms should always be identifiers, all
896
- /// gensym operations are on `Ident` rather than `Symbol`. (Indeed, in the
897
- /// future the gensym-ness may be moved from `Symbol` to hygiene data.)
877
+ /// An interned string.
898
878
///
899
- /// Examples:
900
- /// ```
901
- /// assert_eq!(Ident::from_str("_"), Ident::from_str("_"))
902
- /// assert_ne!(Ident::from_str("_").gensym_if_underscore(), Ident::from_str("_"))
903
- /// assert_ne!(
904
- /// Ident::from_str("_").gensym_if_underscore(),
905
- /// Ident::from_str("_").gensym_if_underscore(),
906
- /// )
907
- /// ```
908
- /// Internally, a symbol is implemented as an index, and all operations
879
+ /// Internally, a `Symbol` is implemented as an index, and all operations
909
880
/// (including hashing, equality, and ordering) operate on that index. The use
910
881
/// of `newtype_index!` means that `Option<Symbol>` only takes up 4 bytes,
911
882
/// because `newtype_index!` reserves the last 256 values for tagging purposes.
@@ -956,12 +927,9 @@ impl Symbol {
956
927
} )
957
928
}
958
929
959
- /// Convert to an `InternedString`. This is a slowish operation because it
960
- /// requires locking the symbol interner.
930
+ /// Convert to an `InternedString`.
961
931
pub fn as_interned_str ( self ) -> InternedString {
962
- with_interner ( |interner| InternedString {
963
- symbol : interner. interned ( self )
964
- } )
932
+ InternedString { symbol : self }
965
933
}
966
934
967
935
pub fn as_u32 ( self ) -> u32 {
@@ -971,12 +939,7 @@ impl Symbol {
971
939
972
940
impl fmt:: Debug for Symbol {
973
941
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
974
- let is_gensymed = with_interner ( |interner| interner. is_gensymed ( * self ) ) ;
975
- if is_gensymed {
976
- write ! ( f, "{}({:?})" , self , self . 0 )
977
- } else {
978
- write ! ( f, "{}" , self )
979
- }
942
+ fmt:: Display :: fmt ( self , f)
980
943
}
981
944
}
982
945
@@ -999,15 +962,11 @@ impl Decodable for Symbol {
999
962
}
1000
963
1001
964
// The `&'static str`s in this type actually point into the arena.
1002
- //
1003
- // Note that normal symbols are indexed upward from 0, and gensyms are indexed
1004
- // downward from SymbolIndex::MAX_AS_U32.
1005
965
#[ derive( Default ) ]
1006
966
pub struct Interner {
1007
967
arena : DroplessArena ,
1008
968
names : FxHashMap < & ' static str , Symbol > ,
1009
969
strings : Vec < & ' static str > ,
1010
- gensyms : Vec < Symbol > ,
1011
970
}
1012
971
1013
972
impl Interner {
@@ -1040,34 +999,10 @@ impl Interner {
1040
999
self . names . insert ( string, name) ;
1041
1000
name
1042
1001
}
1043
-
1044
- fn interned ( & self , symbol : Symbol ) -> Symbol {
1045
- if ( symbol. 0 . as_usize ( ) ) < self . strings . len ( ) {
1046
- symbol
1047
- } else {
1048
- self . gensyms [ ( SymbolIndex :: MAX_AS_U32 - symbol. 0 . as_u32 ( ) ) as usize ]
1049
- }
1050
- }
1051
-
1052
- fn gensymed ( & mut self , symbol : Symbol ) -> Symbol {
1053
- self . gensyms . push ( symbol) ;
1054
- Symbol :: new ( SymbolIndex :: MAX_AS_U32 - self . gensyms . len ( ) as u32 + 1 )
1055
- }
1056
-
1057
- fn is_gensymed ( & mut self , symbol : Symbol ) -> bool {
1058
- symbol. 0 . as_usize ( ) >= self . strings . len ( )
1059
- }
1060
-
1061
1002
// Get the symbol as a string. `Symbol::as_str()` should be used in
1062
1003
// preference to this function.
1063
1004
pub fn get ( & self , symbol : Symbol ) -> & str {
1064
- match self . strings . get ( symbol. 0 . as_usize ( ) ) {
1065
- Some ( string) => string,
1066
- None => {
1067
- let symbol = self . gensyms [ ( SymbolIndex :: MAX_AS_U32 - symbol. 0 . as_u32 ( ) ) as usize ] ;
1068
- self . strings [ symbol. 0 . as_usize ( ) ]
1069
- }
1070
- }
1005
+ self . strings [ symbol. 0 . as_usize ( ) ]
1071
1006
}
1072
1007
}
1073
1008
@@ -1252,19 +1187,12 @@ impl fmt::Display for LocalInternedString {
1252
1187
}
1253
1188
}
1254
1189
1255
- /// An alternative to `Symbol` that is focused on string contents. It has two
1256
- /// main differences to `Symbol`.
1190
+ /// An alternative to `Symbol` that is focused on string contents.
1257
1191
///
1258
- /// First, its implementations of `Hash`, `PartialOrd` and `Ord` work with the
1192
+ /// Its implementations of `Hash`, `PartialOrd` and `Ord` work with the
1259
1193
/// string chars rather than the symbol integer. This is useful when hash
1260
1194
/// stability is required across compile sessions, or a guaranteed sort
1261
1195
/// ordering is required.
1262
- ///
1263
- /// Second, gensym-ness is irrelevant. E.g.:
1264
- /// ```
1265
- /// assert_ne!(Symbol::gensym("x"), Symbol::gensym("x"))
1266
- /// assert_eq!(Symbol::gensym("x").as_interned_str(), Symbol::gensym("x").as_interned_str())
1267
- /// ```
1268
1196
#[ derive( Clone , Copy , PartialEq , Eq ) ]
1269
1197
pub struct InternedString {
1270
1198
symbol : Symbol ,
0 commit comments