diff options
| author | bors <bors@rust-lang.org> | 2018-03-21 01:06:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-03-21 01:06:16 +0000 |
| commit | c19264fa835a1eca86de4fd2e86a87b3919e57cf (patch) | |
| tree | 2a768000004d96f6ebc687949ed795212c68f458 | |
| parent | 10420536ec95b05603b20e6ef769b44ed8c1ea8e (diff) | |
| parent | 13bfbe1394732163c7130dd57e6b0a86e147c7e8 (diff) | |
| download | rust-c19264fa835a1eca86de4fd2e86a87b3919e57cf.tar.gz rust-c19264fa835a1eca86de4fd2e86a87b3919e57cf.zip | |
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
| -rw-r--r-- | src/librustc/mir/interpret/mod.rs | 14 | ||||
| -rw-r--r-- | src/librustc/ty/maps/on_disk_cache.rs | 2 | ||||
| -rw-r--r-- | src/librustc_metadata/encoder.rs | 4 | ||||
| -rw-r--r-- | src/test/incremental/extern_static/issue-49153.rs | 21 |
4 files changed, 38 insertions, 3 deletions
diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 04ffb9af29e..e242ec4985a 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -156,6 +156,8 @@ impl ::rustc_serialize::UseSpecializedDecodable for AllocId {} pub const ALLOC_DISCRIMINANT: usize = 0; 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< 'a, 'tcx, @@ -173,6 +175,7 @@ pub fn specialized_encode_alloc_id< trace!("encoding {:?} with {:#?}", alloc_id, alloc); ALLOC_DISCRIMINANT.encode(encoder)?; alloc.encode(encoder)?; + // encode whether this allocation is the root allocation of a static tcx.interpret_interner .get_corresponding_static_def_id(alloc_id) .encode(encoder)?; @@ -180,6 +183,10 @@ pub fn specialized_encode_alloc_id< trace!("encoding {:?} with {:#?}", alloc_id, fn_instance); FN_DISCRIMINANT.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 { bug!("alloc id without corresponding allocation: {}", alloc_id); } @@ -225,6 +232,13 @@ pub fn specialized_decode_alloc_id< cache(decoder, pos, 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 => { trace!("loading shorthand {}", shorthand); short(decoder, shorthand) diff --git a/src/librustc/ty/maps/on_disk_cache.rs b/src/librustc/ty/maps/on_disk_cache.rs index 04437a1c9e2..c103d6e015a 100644 --- a/src/librustc/ty/maps/on_disk_cache.rs +++ b/src/librustc/ty/maps/on_disk_cache.rs @@ -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 // not special. It is essentially impossible for that to happen, // but let's make sure - assert!(pos != interpret::ALLOC_DISCRIMINANT && pos != interpret::FN_DISCRIMINANT); + assert!(pos >= interpret::SHORTHAND_START); entry.insert(pos); None }, diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 0da23c2caf4..6b3453f2c99 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -203,9 +203,9 @@ impl<'a, 'tcx> SpecializedEncoder<interpret::AllocId> for EncodeContext<'a, 'tcx Entry::Occupied(entry) => Some(entry.get().clone()), Entry::Vacant(entry) => { // 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 - assert!(pos != 0 && pos != 1); + assert!(pos >= interpret::SHORTHAND_START); entry.insert(pos); None }, diff --git a/src/test/incremental/extern_static/issue-49153.rs b/src/test/incremental/extern_static/issue-49153.rs new file mode 100644 index 00000000000..e0538e09c64 --- /dev/null +++ b/src/test/incremental/extern_static/issue-49153.rs @@ -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() {} |
