Skip to content

Commit

Permalink
Rollup merge of rust-lang#41847 - alexcrichton:less-unstable-annotati…
Browse files Browse the repository at this point in the history
…ons, r=eddyb

rustc: Add a new `-Z force-unstable-if-unmarked` flag

This commit adds a new `-Z` flag to the compiler for use when bootstrapping the
compiler itself. We want to be able to use crates.io crates, but we also want
the usage of such crates to be as ergonomic as possible! To that end compiler
crates are a little tricky in that the crates.io crates are not annotated as
unstable, nor do they expect to pull in unstable dependencies.

To cover all these situations it's intended that the compiler will forever now
bootstrap with `-Z force-unstable-if-unmarked`. This flags serves a dual purpose
of forcing crates.io crates to themselves be unstable while also allowing them
to use other "unstable" crates.io crates. This should mean that adding a
dependency to compiler no longer requires upstream modification with
unstable/staged_api attributes for inclusion!
  • Loading branch information
Mark-Simulacrum authored May 12, 2017
2 parents 9f8ea35 + ab54f4b commit 2398241
Show file tree
Hide file tree
Showing 43 changed files with 201 additions and 140 deletions.
13 changes: 13 additions & 0 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ fn main() {
// do that we pass a weird flag to the compiler to get it to do
// so. Note that this is definitely a hack, and we should likely
// flesh out rpath support more fully in the future.
//
// FIXME: remove condition after next stage0
if stage != "0" {
cmd.arg("-Z").arg("osx-rpath-install-name");
}
Expand All @@ -218,6 +220,17 @@ fn main() {
cmd.arg("-Z").arg("unstable-options");
cmd.arg("-C").arg("target-feature=+crt-static");
}

// Force all crates compiled by this compiler to (a) be unstable and (b)
// allow the `rustc_private` feature to link to other unstable crates
// also in the sysroot.
//
// FIXME: remove condition after next stage0
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
if stage != "0" {
cmd.arg("-Z").arg("force-unstable-if-unmarked");
}
}
}

if verbose > 1 {
Expand Down
7 changes: 5 additions & 2 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ impl Build {
// compiled with debuginfo.
if mode != Mode::Tool {
cargo.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string())
.env("RUSTC_DEBUGINFO_LINES", self.config.rust_debuginfo_lines.to_string());
.env("RUSTC_DEBUGINFO_LINES", self.config.rust_debuginfo_lines.to_string())
.env("RUSTC_FORCE_UNSTABLE", "1");
}

// Enable usage of unstable features
Expand Down Expand Up @@ -524,7 +525,9 @@ impl Build {
// the comipiler, libs, and tests are stable and we don't want to make
// their deps unstable (since this would break the first invariant
// above).
if mode != Mode::Tool {
//
// FIXME: remove this after next stage0
if mode != Mode::Tool && stage == 0 {
cargo.env("RUSTBUILD_UNSTABLE", "1");
}

Expand Down
4 changes: 2 additions & 2 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! objects of a single type.

#![crate_name = "arena"]
#![unstable(feature = "rustc_private", issue = "27812")]
#![cfg_attr(stage0, unstable(feature = "rustc_private", issue = "27812"))]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
Expand All @@ -32,7 +32,7 @@
#![feature(core_intrinsics)]
#![feature(dropck_eyepatch)]
#![feature(generic_param_attrs)]
#![feature(staged_api)]
#![cfg_attr(stage0, feature(staged_api))]
#![cfg_attr(test, feature(test))]

#![allow(deprecated)]
Expand Down
4 changes: 2 additions & 2 deletions src/libflate/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! [mz]: https://code.google.com/p/miniz/

#![crate_name = "flate"]
#![unstable(feature = "rustc_private", issue = "27812")]
#![cfg_attr(stage0, unstable(feature = "rustc_private", issue = "27812"))]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
Expand All @@ -25,7 +25,7 @@
#![deny(warnings)]

#![feature(libc)]
#![feature(staged_api)]
#![cfg_attr(stage0, feature(staged_api))]
#![feature(unique)]
#![cfg_attr(test, feature(rand))]

Expand Down
4 changes: 2 additions & 2 deletions src/libfmt_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! generated instead.

#![crate_name = "fmt_macros"]
#![unstable(feature = "rustc_private", issue = "27812")]
#![cfg_attr(stage0, unstable(feature = "rustc_private", issue = "27812"))]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
Expand All @@ -25,7 +25,7 @@
test(attr(deny(warnings))))]
#![deny(warnings)]

#![feature(staged_api)]
#![cfg_attr(stage0, feature(staged_api))]
#![feature(unicode)]

pub use self::Piece::*;
Expand Down
6 changes: 3 additions & 3 deletions src/libgetopts/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
//! ```

#![crate_name = "getopts"]
#![unstable(feature = "rustc_private",
#![cfg_attr(stage0, unstable(feature = "rustc_private",
reason = "use the crates.io `getopts` library instead",
issue = "27812")]
issue = "27812"))]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
Expand All @@ -91,7 +91,7 @@

#![deny(missing_docs)]
#![deny(warnings)]
#![feature(staged_api)]
#![cfg_attr(stage0, feature(staged_api))]

use self::Name::*;
use self::HasArg::*;
Expand Down
4 changes: 2 additions & 2 deletions src/libgraphviz/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@
//! * [DOT language](http://www.graphviz.org/doc/info/lang.html)

#![crate_name = "graphviz"]
#![unstable(feature = "rustc_private", issue = "27812")]
#![feature(staged_api)]
#![cfg_attr(stage0, unstable(feature = "rustc_private", issue = "27812"))]
#![cfg_attr(stage0, feature(staged_api))]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
Expand Down
6 changes: 3 additions & 3 deletions src/libproc_macro_plugin/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
//! }
//! ```
#![crate_name = "proc_macro_plugin"]
#![unstable(feature = "rustc_private", issue = "27812")]
#![cfg_attr(stage0, unstable(feature = "rustc_private", issue = "27812"))]
#![feature(plugin_registrar)]
#![crate_type = "dylib"]
#![crate_type = "rlib"]
Expand All @@ -81,9 +81,9 @@
html_root_url = "https://doc.rust-lang.org/nightly/")]
#![deny(warnings)]

#![feature(staged_api)]
#![cfg_attr(stage0, feature(staged_api))]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#![cfg_attr(stage0, feature(rustc_private))]

extern crate rustc_plugin;
extern crate syntax;
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
//! This API is completely unstable and subject to change.

#![crate_name = "rustc"]
#![unstable(feature = "rustc_private", issue = "27812")]
#![crate_type = "dylib"]
#![crate_type = "rlib"]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
Expand All @@ -36,15 +35,17 @@
#![feature(nonzero)]
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#![feature(slice_patterns)]
#![feature(specialization)]
#![feature(staged_api)]
#![feature(unboxed_closures)]
#![feature(discriminant_value)]
#![feature(sort_unstable)]
#![feature(trace_macros)]

#![cfg_attr(stage0, unstable(feature = "rustc_private", issue = "27812"))]
#![cfg_attr(stage0, feature(rustc_private))]
#![cfg_attr(stage0, feature(staged_api))]

#![recursion_limit="128"]

extern crate arena;
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ pub trait CrateStore {
fn export_macros(&self, cnum: CrateNum);
fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>;
fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>;
fn is_staged_api(&self, cnum: CrateNum) -> bool;
fn is_allocator(&self, cnum: CrateNum) -> bool;
fn is_panic_runtime(&self, cnum: CrateNum) -> bool;
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool;
Expand Down Expand Up @@ -356,7 +355,6 @@ impl CrateStore for DummyCrateStore {
{ bug!("lang_items") }
fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>
{ bug!("missing_lang_items") }
fn is_staged_api(&self, cnum: CrateNum) -> bool { bug!("is_staged_api") }
fn dep_kind(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
fn export_macros(&self, cnum: CrateNum) { bug!("export_macros") }
fn is_allocator(&self, cnum: CrateNum) -> bool { bug!("is_allocator") }
Expand Down
81 changes: 58 additions & 23 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

pub use self::StabilityLevel::*;

use hir::map as hir_map;
use lint;
use hir::def::Def;
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, DefIndex, LOCAL_CRATE};
use ty::{self, TyCtxt};
use middle::privacy::AccessLevels;
use session::Session;
use syntax::symbol::Symbol;
use syntax_pos::{Span, DUMMY_SP};
use syntax::ast;
Expand Down Expand Up @@ -123,7 +123,7 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
item_sp: Span, kind: AnnotationKind, visit_children: F)
where F: FnOnce(&mut Self)
{
if self.index.staged_api[&LOCAL_CRATE] && self.tcx.sess.features.borrow().staged_api {
if self.index.staged_api[&LOCAL_CRATE] {
debug!("annotate(id = {:?}, attrs = {:?})", id, attrs);
if let Some(..) = attr::find_deprecation(self.tcx.sess.diagnostic(), attrs, item_sp) {
self.tcx.sess.span_err(item_sp, "`#[deprecated]` cannot be used in staged api, \
Expand Down Expand Up @@ -390,20 +390,36 @@ impl<'a, 'tcx> Index<'tcx> {
parent_depr: None,
in_trait_impl: false,
};

// If the `-Z force-unstable-if-unmarked` flag is passed then we provide
// a parent stability annotation which indicates that this is private
// with the `rustc_private` feature. This is intended for use when
// compiling librustc crates themselves so we can leverage crates.io
// while maintaining the invariant that all sysroot crates are unstable
// by default and are unable to be used.
if tcx.sess.opts.debugging_opts.force_unstable_if_unmarked {
let reason = "this crate is being loaded from the sysroot, and \
unstable location; did you mean to load this crate \
from crates.io via `Cargo.toml` instead?";
let stability = tcx.intern_stability(Stability {
level: attr::StabilityLevel::Unstable {
reason: Some(Symbol::intern(reason)),
issue: 27812,
},
feature: Symbol::intern("rustc_private"),
rustc_depr: None,
});
annotator.parent_stab = Some(stability);
}

annotator.annotate(ast::CRATE_NODE_ID, &krate.attrs, krate.span, AnnotationKind::Required,
|v| intravisit::walk_crate(v, krate));
}

pub fn new(hir_map: &hir_map::Map) -> Index<'tcx> {
let krate = hir_map.krate();

let mut is_staged_api = false;
for attr in &krate.attrs {
if attr.path == "stable" || attr.path == "unstable" {
is_staged_api = true;
break
}
}
pub fn new(sess: &Session) -> Index<'tcx> {
let is_staged_api =
sess.opts.debugging_opts.force_unstable_if_unmarked ||
sess.features.borrow().staged_api;

let mut staged_api = FxHashMap();
staged_api.insert(LOCAL_CRATE, is_staged_api);
Expand Down Expand Up @@ -496,8 +512,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
}

let is_staged_api = *self.stability.borrow_mut().staged_api.entry(def_id.krate)
.or_insert_with(|| self.sess.cstore.is_staged_api(def_id.krate));
let is_staged_api = self.lookup_stability(DefId {
index: CRATE_DEF_INDEX,
..def_id
}).is_some();
if !is_staged_api {
return;
}
Expand Down Expand Up @@ -530,15 +548,32 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

match stability {
Some(&Stability { level: attr::Unstable {ref reason, issue}, ref feature, .. }) => {
if !self.stability.borrow().active_features.contains(feature) {
let msg = match *reason {
Some(ref r) => format!("use of unstable library feature '{}': {}",
feature.as_str(), &r),
None => format!("use of unstable library feature '{}'", &feature)
};
emit_feature_err(&self.sess.parse_sess, &feature.as_str(), span,
GateIssue::Library(Some(issue)), &msg);
if self.stability.borrow().active_features.contains(feature) {
return
}

// When we're compiling the compiler itself we may pull in
// crates from crates.io, but those crates may depend on other
// crates also pulled in from crates.io. We want to ideally be
// able to compile everything without requiring upstream
// modifications, so in the case that this looks like a
// rustc_private crate (e.g. a compiler crate) and we also have
// the `-Z force-unstable-if-unmarked` flag present (we're
// compiling a compiler crate), then let this missing feature
// annotation slide.
if *feature == "rustc_private" && issue == 27812 {
if self.sess.opts.debugging_opts.force_unstable_if_unmarked {
return
}
}

let msg = match *reason {
Some(ref r) => format!("use of unstable library feature '{}': {}",
feature.as_str(), &r),
None => format!("use of unstable library feature '{}'", &feature)
};
emit_feature_err(&self.sess.parse_sess, &feature.as_str(), span,
GateIssue::Library(Some(issue)), &msg);
}
Some(_) => {
// Stable APIs are always ok to call and deprecated APIs are
Expand Down Expand Up @@ -658,7 +693,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {

let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);

if tcx.stability.borrow().staged_api[&LOCAL_CRATE] && tcx.sess.features.borrow().staged_api {
if tcx.stability.borrow().staged_api[&LOCAL_CRATE] {
let krate = tcx.hir.krate();
let mut missing = MissingStabilityAnnotations {
tcx: tcx,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"add a source pattern to the file path remapping config"),
remap_path_prefix_to: Vec<String> = (vec![], parse_string_push, [TRACKED],
"add a mapping target to the file path remapping config"),
force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
"force all crates to be `rustc_private` unstable"),
}

pub fn default_lib_output() -> CrateType {
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_back/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
//! build speedups.

#![crate_name = "rustc_back"]
#![unstable(feature = "rustc_private", issue = "27812")]
#![crate_type = "dylib"]
#![crate_type = "rlib"]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
Expand All @@ -34,10 +33,12 @@
#![feature(const_fn)]
#![feature(libc)]
#![feature(rand)]
#![feature(rustc_private)]
#![feature(staged_api)]
#![cfg_attr(test, feature(rand))]

#![cfg_attr(stage0, unstable(feature = "rustc_private", issue = "27812"))]
#![cfg_attr(stage0, feature(rustc_private))]
#![cfg_attr(stage0, feature(staged_api))]

extern crate syntax;
extern crate libc;
extern crate serialize;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_bitflags/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

#![crate_name = "rustc_bitflags"]
#![feature(associated_consts)]
#![feature(staged_api)]
#![crate_type = "rlib"]
#![no_std]
#![unstable(feature = "rustc_private", issue = "27812")]
#![deny(warnings)]
#![cfg_attr(stage0, unstable(feature = "rustc_private", issue = "27812"))]
#![cfg_attr(stage0, feature(staged_api))]

//! A typesafe bitmask flag generator.

Expand Down
Loading

0 comments on commit 2398241

Please sign in to comment.