4
4
// The encoding format for inline spans were obtained by optimizing over crates in rustc/libstd.
5
5
// See https://internals.rust-lang.org/t/rfc-compiler-refactoring-spans/1357/28
6
6
7
- use crate :: GLOBALS ;
8
7
use crate :: { BytePos , SpanData } ;
9
8
use crate :: hygiene:: SyntaxContext ;
10
9
11
10
use rustc_data_structures:: fx:: FxHashMap ;
12
- use std:: hash:: { Hash , Hasher } ;
13
11
14
12
/// A compressed span.
15
13
/// Contains either fields of `SpanData` inline if they are small, or index into span interner.
@@ -74,7 +72,7 @@ fn encode(sd: &SpanData) -> Span {
74
72
( base << INLINE_OFFSETS [ BASE_INDEX ] ) | ( len << INLINE_OFFSETS [ LEN_INDEX ] ) |
75
73
( ctxt << INLINE_OFFSETS [ CTXT_INDEX ] ) | TAG_INLINE
76
74
} else {
77
- let index = with_span_interner ( |interner| interner . intern ( sd) ) ;
75
+ let index = unsafe { ( * SPAN_INTERNER_BACKDOOR ) . intern ( sd) } ;
78
76
( index << INTERNED_INDEX_OFFSET ) | TAG_INTERNED
79
77
} ;
80
78
Span ( val)
@@ -96,7 +94,7 @@ fn decode(span: Span) -> SpanData {
96
94
extract ( INLINE_OFFSETS [ CTXT_INDEX ] , INLINE_SIZES [ CTXT_INDEX ] ) ,
97
95
) } else {
98
96
let index = extract ( INTERNED_INDEX_OFFSET , INTERNED_INDEX_SIZE ) ;
99
- return with_span_interner ( |interner| * interner . get ( index) ) ;
97
+ return unsafe { * ( * SPAN_INTERNER_BACKDOOR ) . get ( index) } ;
100
98
} ;
101
99
SpanData { lo : BytePos ( base) , hi : BytePos ( base + len) , ctxt : SyntaxContext :: from_u32 ( ctxt) }
102
100
}
@@ -125,8 +123,4 @@ impl SpanInterner {
125
123
}
126
124
}
127
125
128
- // If an interner exists, return it. Otherwise, prepare a fresh one.
129
- #[ inline]
130
- fn with_span_interner < T , F : FnOnce ( & mut SpanInterner ) -> T > ( f : F ) -> T {
131
- GLOBALS . with ( |globals| f ( & mut * globals. span_interner . lock ( ) ) )
132
- }
126
+ pub static mut SPAN_INTERNER_BACKDOOR : * mut SpanInterner = std:: ptr:: null_mut ( ) ;
0 commit comments