rmeta/query cache: don't write string values of preinterned symbols
This commit is contained in:
parent
0016356f2b
commit
f6329485a8
5 changed files with 51 additions and 22 deletions
|
@ -631,6 +631,10 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for Symbol {
|
||||||
|
|
||||||
sym
|
sym
|
||||||
}
|
}
|
||||||
|
SYMBOL_PREINTERNED => {
|
||||||
|
let symbol_index = d.read_u32();
|
||||||
|
Symbol::new_from_decoded(symbol_index)
|
||||||
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -317,6 +317,12 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for Span {
|
||||||
|
|
||||||
impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for Symbol {
|
impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for Symbol {
|
||||||
fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) {
|
fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) {
|
||||||
|
// if symbol preinterned, emit tag and symbol index
|
||||||
|
if self.is_preinterned() {
|
||||||
|
s.opaque.emit_u8(SYMBOL_PREINTERNED);
|
||||||
|
s.opaque.emit_u32(self.as_u32());
|
||||||
|
} else {
|
||||||
|
// otherwise write it as string or as offset to it
|
||||||
match s.symbol_table.entry(*self) {
|
match s.symbol_table.entry(*self) {
|
||||||
Entry::Vacant(o) => {
|
Entry::Vacant(o) => {
|
||||||
s.opaque.emit_u8(SYMBOL_STR);
|
s.opaque.emit_u8(SYMBOL_STR);
|
||||||
|
@ -332,6 +338,7 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for Symbol {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> TyEncoder for EncodeContext<'a, 'tcx> {
|
impl<'a, 'tcx> TyEncoder for EncodeContext<'a, 'tcx> {
|
||||||
const CLEAR_CROSS_CRATE: bool = true;
|
const CLEAR_CROSS_CRATE: bool = true;
|
||||||
|
|
|
@ -448,6 +448,7 @@ const TAG_PARTIAL_SPAN: u8 = 2;
|
||||||
// Tags for encoding Symbol's
|
// Tags for encoding Symbol's
|
||||||
const SYMBOL_STR: u8 = 0;
|
const SYMBOL_STR: u8 = 0;
|
||||||
const SYMBOL_OFFSET: u8 = 1;
|
const SYMBOL_OFFSET: u8 = 1;
|
||||||
|
const SYMBOL_PREINTERNED: u8 = 2;
|
||||||
|
|
||||||
pub fn provide(providers: &mut Providers) {
|
pub fn provide(providers: &mut Providers) {
|
||||||
encoder::provide(providers);
|
encoder::provide(providers);
|
||||||
|
|
|
@ -42,6 +42,7 @@ const TAG_EXPN_DATA: u8 = 1;
|
||||||
// Tags for encoding Symbol's
|
// Tags for encoding Symbol's
|
||||||
const SYMBOL_STR: u8 = 0;
|
const SYMBOL_STR: u8 = 0;
|
||||||
const SYMBOL_OFFSET: u8 = 1;
|
const SYMBOL_OFFSET: u8 = 1;
|
||||||
|
const SYMBOL_PREINTERNED: u8 = 2;
|
||||||
|
|
||||||
/// Provides an interface to incremental compilation data cached from the
|
/// Provides an interface to incremental compilation data cached from the
|
||||||
/// previous compilation session. This data will eventually include the results
|
/// previous compilation session. This data will eventually include the results
|
||||||
|
@ -745,6 +746,10 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for Symbol {
|
||||||
|
|
||||||
sym
|
sym
|
||||||
}
|
}
|
||||||
|
SYMBOL_PREINTERNED => {
|
||||||
|
let symbol_index = d.read_u32();
|
||||||
|
Symbol::new_from_decoded(symbol_index)
|
||||||
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -939,6 +944,12 @@ impl<'a, 'tcx> Encodable<CacheEncoder<'a, 'tcx>> for Span {
|
||||||
// copy&paste impl from rustc_metadata
|
// copy&paste impl from rustc_metadata
|
||||||
impl<'a, 'tcx> Encodable<CacheEncoder<'a, 'tcx>> for Symbol {
|
impl<'a, 'tcx> Encodable<CacheEncoder<'a, 'tcx>> for Symbol {
|
||||||
fn encode(&self, s: &mut CacheEncoder<'a, 'tcx>) {
|
fn encode(&self, s: &mut CacheEncoder<'a, 'tcx>) {
|
||||||
|
// if symbol preinterned, emit tag and symbol index
|
||||||
|
if self.is_preinterned() {
|
||||||
|
s.encoder.emit_u8(SYMBOL_PREINTERNED);
|
||||||
|
s.encoder.emit_u32(self.as_u32());
|
||||||
|
} else {
|
||||||
|
// otherwise write it as string or as offset to it
|
||||||
match s.symbol_table.entry(*self) {
|
match s.symbol_table.entry(*self) {
|
||||||
Entry::Vacant(o) => {
|
Entry::Vacant(o) => {
|
||||||
s.encoder.emit_u8(SYMBOL_STR);
|
s.encoder.emit_u8(SYMBOL_STR);
|
||||||
|
@ -954,6 +965,7 @@ impl<'a, 'tcx> Encodable<CacheEncoder<'a, 'tcx>> for Symbol {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> TyEncoder for CacheEncoder<'a, 'tcx> {
|
impl<'a, 'tcx> TyEncoder for CacheEncoder<'a, 'tcx> {
|
||||||
type I = TyCtxt<'tcx>;
|
type I = TyCtxt<'tcx>;
|
||||||
|
|
|
@ -1803,6 +1803,11 @@ impl Symbol {
|
||||||
Symbol(SymbolIndex::from_u32(n))
|
Symbol(SymbolIndex::from_u32(n))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// for use in Decoder only
|
||||||
|
pub fn new_from_decoded(n: u32) -> Self {
|
||||||
|
Self::new(n)
|
||||||
|
}
|
||||||
|
|
||||||
/// Maps a string to its interned representation.
|
/// Maps a string to its interned representation.
|
||||||
pub fn intern(string: &str) -> Self {
|
pub fn intern(string: &str) -> Self {
|
||||||
with_session_globals(|session_globals| session_globals.symbol_interner.intern(string))
|
with_session_globals(|session_globals| session_globals.symbol_interner.intern(string))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue