Skip to content

Commit 7c2ab8d

Browse files
committed
Measure upper limit for performance of 32 bit Span
1 parent 34d862b commit 7c2ab8d

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

src/bootstrap/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ impl<'a> Builder<'a> {
438438
doc::EditionGuide,
439439
),
440440
Kind::Dist => describe!(
441-
dist::Docs,
442-
dist::RustcDocs,
441+
// dist::Docs,
442+
// dist::RustcDocs,
443443
dist::Mingw,
444444
dist::Rustc,
445445
dist::DebuggerScripts,

src/librustc_data_structures/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ impl<T> Once<T> {
517517
}
518518

519519
#[derive(Debug)]
520-
pub struct Lock<T>(InnerLock<T>);
520+
pub struct Lock<T>(pub InnerLock<T>);
521521

522522
impl<T> Lock<T> {
523523
#[inline(always)]

src/libsyntax/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ pub fn with_globals<F, R>(f: F) -> R
9898
{
9999
let globals = Globals::new();
100100
GLOBALS.set(&globals, || {
101-
syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
101+
syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, unsafe {
102+
syntax_pos::SPAN_INTERNER_BACKDOOR =
103+
globals.syntax_pos_globals.span_interner.0.as_ptr();
104+
f
105+
})
102106
})
103107
}
104108

src/libsyntax_pos/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#![feature(rustc_attrs)]
1919
#![feature(specialization)]
2020
#![feature(step_trait)]
21+
#![feature(stmt_expr_attributes)]
2122

2223
use serialize::{Encodable, Decodable, Encoder, Decoder};
2324

@@ -29,7 +30,7 @@ pub mod hygiene;
2930
pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnFormat, CompilerDesugaringKind};
3031

3132
mod span_encoding;
32-
pub use span_encoding::{Span, DUMMY_SP};
33+
pub use span_encoding::{Span, DUMMY_SP, SPAN_INTERNER_BACKDOOR};
3334

3435
pub mod symbol;
3536

@@ -48,7 +49,7 @@ use std::path::PathBuf;
4849

4950
pub struct Globals {
5051
symbol_interner: Lock<symbol::Interner>,
51-
span_interner: Lock<span_encoding::SpanInterner>,
52+
pub span_interner: Lock<span_encoding::SpanInterner>,
5253
hygiene_data: Lock<hygiene::HygieneData>,
5354
}
5455

src/libsyntax_pos/span_encoding.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
// The encoding format for inline spans were obtained by optimizing over crates in rustc/libstd.
55
// See https://internals.rust-lang.org/t/rfc-compiler-refactoring-spans/1357/28
66

7-
use crate::GLOBALS;
87
use crate::{BytePos, SpanData};
98
use crate::hygiene::SyntaxContext;
109

1110
use rustc_data_structures::fx::FxHashMap;
12-
use std::hash::{Hash, Hasher};
1311

1412
/// A compressed span.
1513
/// Contains either fields of `SpanData` inline if they are small, or index into span interner.
@@ -74,7 +72,7 @@ fn encode(sd: &SpanData) -> Span {
7472
(base << INLINE_OFFSETS[BASE_INDEX]) | (len << INLINE_OFFSETS[LEN_INDEX]) |
7573
(ctxt << INLINE_OFFSETS[CTXT_INDEX]) | TAG_INLINE
7674
} else {
77-
let index = with_span_interner(|interner| interner.intern(sd));
75+
let index = unsafe { (*SPAN_INTERNER_BACKDOOR).intern(sd) };
7876
(index << INTERNED_INDEX_OFFSET) | TAG_INTERNED
7977
};
8078
Span(val)
@@ -96,7 +94,7 @@ fn decode(span: Span) -> SpanData {
9694
extract(INLINE_OFFSETS[CTXT_INDEX], INLINE_SIZES[CTXT_INDEX]),
9795
)} else {
9896
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) };
10098
};
10199
SpanData { lo: BytePos(base), hi: BytePos(base + len), ctxt: SyntaxContext::from_u32(ctxt) }
102100
}
@@ -125,8 +123,4 @@ impl SpanInterner {
125123
}
126124
}
127125

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

Comments
 (0)