Auto merge of #49200 - oli-obk:extern_static_metadata, r=michaelwoerister
Encode/decode extern statics in metadata and incremental cache fixes #49153 cc @abonander r? @michaelwoerister incremental ICE
This commit is contained in:
commit
c19264fa83
4 changed files with 38 additions and 3 deletions
|
@ -156,6 +156,8 @@ impl ::rustc_serialize::UseSpecializedDecodable for AllocId {}
|
||||||
|
|
||||||
pub const ALLOC_DISCRIMINANT: usize = 0;
|
pub const ALLOC_DISCRIMINANT: usize = 0;
|
||||||
pub const FN_DISCRIMINANT: usize = 1;
|
pub const FN_DISCRIMINANT: usize = 1;
|
||||||
|
pub const EXTERN_STATIC_DISCRIMINANT: usize = 2;
|
||||||
|
pub const SHORTHAND_START: usize = 3;
|
||||||
|
|
||||||
pub fn specialized_encode_alloc_id<
|
pub fn specialized_encode_alloc_id<
|
||||||
'a, 'tcx,
|
'a, 'tcx,
|
||||||
|
@ -173,6 +175,7 @@ pub fn specialized_encode_alloc_id<
|
||||||
trace!("encoding {:?} with {:#?}", alloc_id, alloc);
|
trace!("encoding {:?} with {:#?}", alloc_id, alloc);
|
||||||
ALLOC_DISCRIMINANT.encode(encoder)?;
|
ALLOC_DISCRIMINANT.encode(encoder)?;
|
||||||
alloc.encode(encoder)?;
|
alloc.encode(encoder)?;
|
||||||
|
// encode whether this allocation is the root allocation of a static
|
||||||
tcx.interpret_interner
|
tcx.interpret_interner
|
||||||
.get_corresponding_static_def_id(alloc_id)
|
.get_corresponding_static_def_id(alloc_id)
|
||||||
.encode(encoder)?;
|
.encode(encoder)?;
|
||||||
|
@ -180,6 +183,10 @@ pub fn specialized_encode_alloc_id<
|
||||||
trace!("encoding {:?} with {:#?}", alloc_id, fn_instance);
|
trace!("encoding {:?} with {:#?}", alloc_id, fn_instance);
|
||||||
FN_DISCRIMINANT.encode(encoder)?;
|
FN_DISCRIMINANT.encode(encoder)?;
|
||||||
fn_instance.encode(encoder)?;
|
fn_instance.encode(encoder)?;
|
||||||
|
} else if let Some(did) = tcx.interpret_interner.get_corresponding_static_def_id(alloc_id) {
|
||||||
|
// extern "C" statics don't have allocations, just encode its def_id
|
||||||
|
EXTERN_STATIC_DISCRIMINANT.encode(encoder)?;
|
||||||
|
did.encode(encoder)?;
|
||||||
} else {
|
} else {
|
||||||
bug!("alloc id without corresponding allocation: {}", alloc_id);
|
bug!("alloc id without corresponding allocation: {}", alloc_id);
|
||||||
}
|
}
|
||||||
|
@ -225,6 +232,13 @@ pub fn specialized_decode_alloc_id<
|
||||||
cache(decoder, pos, id);
|
cache(decoder, pos, id);
|
||||||
Ok(id)
|
Ok(id)
|
||||||
},
|
},
|
||||||
|
EXTERN_STATIC_DISCRIMINANT => {
|
||||||
|
trace!("creating extern static alloc id at {}", pos);
|
||||||
|
let did = DefId::decode(decoder)?;
|
||||||
|
let alloc_id = tcx.interpret_interner.reserve();
|
||||||
|
tcx.interpret_interner.cache(did, alloc_id);
|
||||||
|
Ok(alloc_id)
|
||||||
|
},
|
||||||
shorthand => {
|
shorthand => {
|
||||||
trace!("loading shorthand {}", shorthand);
|
trace!("loading shorthand {}", shorthand);
|
||||||
short(decoder, shorthand)
|
short(decoder, shorthand)
|
||||||
|
|
|
@ -820,7 +820,7 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<interpret::AllocId> for CacheEncoder<
|
||||||
// of the metadata file, because that would end up making our indices
|
// of the metadata file, because that would end up making our indices
|
||||||
// not special. It is essentially impossible for that to happen,
|
// not special. It is essentially impossible for that to happen,
|
||||||
// but let's make sure
|
// but let's make sure
|
||||||
assert!(pos != interpret::ALLOC_DISCRIMINANT && pos != interpret::FN_DISCRIMINANT);
|
assert!(pos >= interpret::SHORTHAND_START);
|
||||||
entry.insert(pos);
|
entry.insert(pos);
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
|
|
@ -203,9 +203,9 @@ impl<'a, 'tcx> SpecializedEncoder<interpret::AllocId> for EncodeContext<'a, 'tcx
|
||||||
Entry::Occupied(entry) => Some(entry.get().clone()),
|
Entry::Occupied(entry) => Some(entry.get().clone()),
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
// ensure that we don't place any AllocIds at the very beginning
|
// ensure that we don't place any AllocIds at the very beginning
|
||||||
// of the metadata file, because that would end up making our 0 and 1 indices
|
// of the metadata file, because that would end up making our indices
|
||||||
// not special. This is essentially impossible, but let's make sure
|
// not special. This is essentially impossible, but let's make sure
|
||||||
assert!(pos != 0 && pos != 1);
|
assert!(pos >= interpret::SHORTHAND_START);
|
||||||
entry.insert(pos);
|
entry.insert(pos);
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
|
21
src/test/incremental/extern_static/issue-49153.rs
Normal file
21
src/test/incremental/extern_static/issue-49153.rs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// https://github.com/rust-lang/rust/issues/49153
|
||||||
|
|
||||||
|
// revisions:rpass1 rpass2
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
pub static __ImageBase: u8;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub static FOO: &'static u8 = unsafe { &__ImageBase };
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue