eebf6743d8
With this commit, metadata encoding and decoding can make use of thread-local encoding and decoding contexts. These allow implementers of `serialize::Encodable` and `Decodable` to access information and datastructures that would otherwise not be available to them. For example, we can automatically translate def-id and span information during decoding because the decoding context knows which crate the data is decoded from. Or it allows to make `ty::Ty` decodable because the context has access to the `ty::ctxt` that is needed for creating `ty::Ty` instances. Some notes: - `tls::with_encoding_context()` and `tls::with_decoding_context()` (as opposed to their unsafe versions) try to prevent the TLS data getting out-of-sync by making sure that the encoder/decoder passed in is actually the same as the one stored in the context. This should prevent accidentally reading from the wrong decoder. - There are no real tests in this PR. I had a unit tests for some of the core aspects of the TLS implementation but it was kind of brittle, a lot of code for mocking `ty::ctxt`, `crate_metadata`, etc and did actually test not so much. The code will soon be tested by the first incremental compilation auto-tests that rely on MIR being properly serialized. However, if people think that some tests should be added before this can land, I'll try to provide some that make sense. r? @nikomatsakis
62 lines
1.6 KiB
Rust
62 lines
1.6 KiB
Rust
// Copyright 2015 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.
|
|
|
|
#![cfg_attr(stage0, feature(custom_attribute))]
|
|
#![crate_name = "rustc_metadata"]
|
|
#![unstable(feature = "rustc_private", issue = "27812")]
|
|
#![cfg_attr(stage0, staged_api)]
|
|
#![crate_type = "dylib"]
|
|
#![crate_type = "rlib"]
|
|
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
|
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
|
html_root_url = "https://doc.rust-lang.org/nightly/")]
|
|
|
|
#![feature(box_patterns)]
|
|
#![feature(enumset)]
|
|
#![feature(quote)]
|
|
#![feature(rustc_diagnostic_macros)]
|
|
#![feature(rustc_private)]
|
|
#![feature(staged_api)]
|
|
#![feature(time2)]
|
|
|
|
#[macro_use] extern crate log;
|
|
#[macro_use] extern crate syntax;
|
|
#[macro_use] #[no_link] extern crate rustc_bitflags;
|
|
|
|
extern crate flate;
|
|
extern crate rbml;
|
|
extern crate serialize;
|
|
|
|
extern crate rustc;
|
|
extern crate rustc_back;
|
|
extern crate rustc_front;
|
|
extern crate rustc_llvm;
|
|
|
|
pub use rustc::middle;
|
|
|
|
#[macro_use]
|
|
mod macros;
|
|
|
|
pub mod diagnostics;
|
|
|
|
pub mod astencode;
|
|
pub mod common;
|
|
pub mod tyencode;
|
|
pub mod tydecode;
|
|
pub mod encoder;
|
|
pub mod decoder;
|
|
pub mod creader;
|
|
pub mod csearch;
|
|
pub mod cstore;
|
|
pub mod index;
|
|
pub mod loader;
|
|
pub mod macro_import;
|
|
pub mod tls_context;
|