Skip to content

Commit

Permalink
Auto merge of #66356 - JohnTitor:rollup-1mh7jsr, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 13 pull requests

Successful merges:

 - #65932 (download .tar.xz if python3 is used)
 - #66074 ([mir-opt] Turn on the `ConstProp` pass by default)
 - #66094 (Fix documentation for `Iterator::count()`.)
 - #66166 (rename cfg(rustdoc) into cfg(doc))
 - #66227 (docs: Fix link to BufWriter::flush)
 - #66292 (add Result::map_or)
 - #66297 (Add a callback that allows compiler consumers to override queries.)
 - #66317 (Use a relative bindir for rustdoc to find rustc)
 - #66330 (Improve non-exhaustiveness handling in usefulness checking)
 - #66331 (Add some tests for fixed ICEs)
 - #66334 (Move Session fields to CrateStore)
 - #66335 (Move self-profile infrastructure to data structures)
 - #66337 (Remove dead code for encoding/decoding lint IDs)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Nov 13, 2019
2 parents 374ad1b + 6302a35 commit 688a74b
Show file tree
Hide file tree
Showing 57 changed files with 665 additions and 332 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3120,7 +3120,6 @@ dependencies = [
"graphviz",
"jobserver",
"log",
"measureme",
"num_cpus",
"parking_lot 0.9.0",
"polonius-engine",
Expand Down Expand Up @@ -3470,6 +3469,7 @@ dependencies = [
name = "rustc_data_structures"
version = "0.0.0"
dependencies = [
"bitflags",
"cfg-if",
"crossbeam-utils 0.6.5",
"ena",
Expand All @@ -3478,6 +3478,7 @@ dependencies = [
"jobserver",
"lazy_static 1.3.0",
"log",
"measureme",
"parking_lot 0.9.0",
"rustc-hash",
"rustc-rayon 0.3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/bin/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {
let mut dylib_path = bootstrap::util::dylib_path();
dylib_path.insert(0, PathBuf::from(libdir.clone()));

//FIXME(misdreavus): once stdsimd uses cfg(rustdoc) instead of cfg(dox), remove the `--cfg dox`
//FIXME(misdreavus): once stdsimd uses cfg(doc) instead of cfg(dox), remove the `--cfg dox`
//arguments here
let mut cmd = Command::new(rustdoc);
cmd.args(&args)
Expand Down
43 changes: 29 additions & 14 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def verify(path, sha_path, verbose):
return verified


def unpack(tarball, dst, verbose=False, match=None):
def unpack(tarball, tarball_suffix, dst, verbose=False, match=None):
"""Unpack the given tarball file"""
print("extracting", tarball)
fname = os.path.basename(tarball).replace(".tar.gz", "")
fname = os.path.basename(tarball).replace(tarball_suffix, "")
with contextlib.closing(tarfile.open(tarball)) as tar:
for member in tar.getnames():
if "/" not in member:
Expand Down Expand Up @@ -331,6 +331,7 @@ def __init__(self):
self.use_vendored_sources = ''
self.verbose = False


def download_stage0(self):
"""Fetch the build system for Rust, written in Rust
Expand All @@ -344,18 +345,30 @@ def download_stage0(self):
rustc_channel = self.rustc_channel
cargo_channel = self.cargo_channel

def support_xz():
try:
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
temp_path = temp_file.name
with tarfile.open(temp_path, "w:xz") as tar:
pass
return True
except tarfile.CompressionError:
return False

if self.rustc().startswith(self.bin_root()) and \
(not os.path.exists(self.rustc()) or
self.program_out_of_date(self.rustc_stamp())):
if os.path.exists(self.bin_root()):
shutil.rmtree(self.bin_root())
filename = "rust-std-{}-{}.tar.gz".format(
rustc_channel, self.build)
tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz'
filename = "rust-std-{}-{}{}".format(
rustc_channel, self.build, tarball_suffix)
pattern = "rust-std-{}".format(self.build)
self._download_stage0_helper(filename, pattern)
self._download_stage0_helper(filename, pattern, tarball_suffix)

filename = "rustc-{}-{}.tar.gz".format(rustc_channel, self.build)
self._download_stage0_helper(filename, "rustc")
filename = "rustc-{}-{}{}".format(rustc_channel, self.build,
tarball_suffix)
self._download_stage0_helper(filename, "rustc", tarball_suffix)
self.fix_executable("{}/bin/rustc".format(self.bin_root()))
self.fix_executable("{}/bin/rustdoc".format(self.bin_root()))
with output(self.rustc_stamp()) as rust_stamp:
Expand All @@ -365,20 +378,22 @@ def download_stage0(self):
# libraries/binaries that are included in rust-std with
# the system MinGW ones.
if "pc-windows-gnu" in self.build:
filename = "rust-mingw-{}-{}.tar.gz".format(
rustc_channel, self.build)
self._download_stage0_helper(filename, "rust-mingw")
filename = "rust-mingw-{}-{}{}".format(
rustc_channel, self.build, tarball_suffix)
self._download_stage0_helper(filename, "rust-mingw", tarball_suffix)

if self.cargo().startswith(self.bin_root()) and \
(not os.path.exists(self.cargo()) or
self.program_out_of_date(self.cargo_stamp())):
filename = "cargo-{}-{}.tar.gz".format(cargo_channel, self.build)
self._download_stage0_helper(filename, "cargo")
tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz'
filename = "cargo-{}-{}{}".format(cargo_channel, self.build,
tarball_suffix)
self._download_stage0_helper(filename, "cargo", tarball_suffix)
self.fix_executable("{}/bin/cargo".format(self.bin_root()))
with output(self.cargo_stamp()) as cargo_stamp:
cargo_stamp.write(self.date)

def _download_stage0_helper(self, filename, pattern):
def _download_stage0_helper(self, filename, pattern, tarball_suffix):
cache_dst = os.path.join(self.build_dir, "cache")
rustc_cache = os.path.join(cache_dst, self.date)
if not os.path.exists(rustc_cache):
Expand All @@ -388,7 +403,7 @@ def _download_stage0_helper(self, filename, pattern):
tarball = os.path.join(rustc_cache, filename)
if not os.path.exists(tarball):
get("{}/{}".format(url, filename), tarball, verbose=self.verbose)
unpack(tarball, self.bin_root(), match=pattern, verbose=self.verbose)
unpack(tarball, tarball_suffix, self.bin_root(), match=pattern, verbose=self.verbose)

@staticmethod
def fix_executable(fname):
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,8 @@ impl<'a> Builder<'a> {
cargo.arg("--frozen");
}

cargo.env("RUSTC_INSTALL_BINDIR", &self.config.bindir);
// Try to use a sysroot-relative bindir, in case it was configured absolutely.
cargo.env("RUSTC_INSTALL_BINDIR", self.config.bindir_relative());

self.ci_env.force_coloring_in_ci(&mut cargo);

Expand Down
14 changes: 14 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,20 @@ impl Config {
config
}

/// Try to find the relative path of `bindir`, otherwise return it in full.
pub fn bindir_relative(&self) -> &Path {
let bindir = &self.bindir;
if bindir.is_absolute() {
// Try to make it relative to the prefix.
if let Some(prefix) = &self.prefix {
if let Ok(stripped) = bindir.strip_prefix(prefix) {
return stripped;
}
}
}
bindir
}

/// Try to find the relative path of `libdir`.
pub fn libdir_relative(&self) -> Option<&Path> {
let libdir = self.libdir.as_ref()?;
Expand Down
8 changes: 4 additions & 4 deletions src/doc/rustdoc/src/unstable-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,24 @@ item, it will be accompanied by a banner explaining that the item is only availa
platforms.

For Rustdoc to document an item, it needs to see it, regardless of what platform it's currently
running on. To aid this, Rustdoc sets the flag `#[cfg(rustdoc)]` when running on your crate.
running on. To aid this, Rustdoc sets the flag `#[cfg(doc)]` when running on your crate.
Combining this with the target platform of a given item allows it to appear when building your crate
normally on that platform, as well as when building documentation anywhere.

For example, `#[cfg(any(windows, rustdoc))]` will preserve the item either on Windows or during the
For example, `#[cfg(any(windows, doc))]` will preserve the item either on Windows or during the
documentation process. Then, adding a new attribute `#[doc(cfg(windows))]` will tell Rustdoc that
the item is supposed to be used on Windows. For example:

```rust
#![feature(doc_cfg)]

/// Token struct that can only be used on Windows.
#[cfg(any(windows, rustdoc))]
#[cfg(any(windows, doc))]
#[doc(cfg(windows))]
pub struct WindowsToken;

/// Token struct that can only be used on Unix.
#[cfg(any(unix, rustdoc))]
#[cfg(any(unix, doc))]
#[doc(cfg(unix))]
pub struct UnixToken;
```
Expand Down
4 changes: 2 additions & 2 deletions src/doc/unstable-book/src/language-features/doc-cfg.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This attribute has two effects:
2. The item's doc-tests will only run on the specific platform.

In addition to allowing the use of the `#[doc(cfg)]` attribute, this feature enables the use of a
special conditional compilation flag, `#[cfg(rustdoc)]`, set whenever building documentation on your
special conditional compilation flag, `#[cfg(doc)]`, set whenever building documentation on your
crate.

This feature was introduced as part of PR [#43348] to allow the platform-specific parts of the
Expand All @@ -22,7 +22,7 @@ standard library be documented.
```rust
#![feature(doc_cfg)]

#[cfg(any(windows, rustdoc))]
#[cfg(any(windows, doc))]
#[doc(cfg(windows))]
/// The application's icon in the notification area (a.k.a. system tray).
///
Expand Down
7 changes: 4 additions & 3 deletions src/libcore/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,13 @@ pub trait Iterator {

/// Consumes the iterator, counting the number of iterations and returning it.
///
/// This method will evaluate the iterator until its [`next`] returns
/// [`None`]. Once [`None`] is encountered, `count()` returns the number of
/// times it called [`next`].
/// This method will call [`next`] repeatedly until [`None`] is encountered,
/// returning the number of times it saw [`Some`]. Note that [`next`] has to be
/// called at least once even if the iterator does not have any elements.
///
/// [`next`]: #tymethod.next
/// [`None`]: ../../std/option/enum.Option.html#variant.None
/// [`Some`]: ../../std/option/enum.Option.html#variant.Some
///
/// # Overflow Behavior
///
Expand Down
22 changes: 22 additions & 0 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,28 @@ impl<T, E> Result<T, E> {
}
}

/// Applies a function to the contained value (if any),
/// or returns the provided default (if not).
///
/// # Examples
///
/// ```
/// #![feature(result_map_or)]
/// let x: Result<_, &str> = Ok("foo");
/// assert_eq!(x.map_or(42, |v| v.len()), 3);
///
/// let x: Result<&str, _> = Err("bar");
/// assert_eq!(x.map_or(42, |v| v.len()), 42);
/// ```
#[inline]
#[unstable(feature = "result_map_or", issue = "66293")]
pub fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U {
match self {
Ok(t) => f(t),
Err(_) => default,
}
}

/// Maps a `Result<T, E>` to `U` by applying a function to a
/// contained [`Ok`] value, or a fallback function to a
/// contained [`Err`] value.
Expand Down
1 change: 0 additions & 1 deletion src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ byteorder = { version = "1.3" }
chalk-engine = { version = "0.9.0", default-features=false }
rustc_fs_util = { path = "../librustc_fs_util" }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
measureme = "0.4"
1 change: 0 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ pub mod util {
pub mod captures;
pub mod common;
pub mod nodemap;
pub mod profiling;
pub mod bug;
}

Expand Down
27 changes: 1 addition & 26 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use crate::util::common::time;
use errors::DiagnosticBuilder;
use std::slice;
use rustc_data_structures::sync::{self, ParallelIterator, join, par_iter};
use rustc_serialize::{Decoder, Decodable, Encoder, Encodable};
use syntax::ast;
use syntax::util::lev_distance::find_best_match_for_name;
use syntax::visit as ast_visit;
Expand Down Expand Up @@ -71,7 +70,7 @@ pub struct LintStore {

/// Lints that are buffered up early on in the `Session` before the
/// `LintLevels` is calculated
#[derive(PartialEq, RustcEncodable, RustcDecodable, Debug)]
#[derive(PartialEq, Debug)]
pub struct BufferedEarlyLint {
pub lint_id: LintId,
pub ast_id: ast::NodeId,
Expand Down Expand Up @@ -1574,27 +1573,3 @@ pub fn check_ast_crate<T: EarlyLintPass>(
}
}
}

impl Encodable for LintId {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_str(&self.lint.name.to_lowercase())
}
}

impl Decodable for LintId {
#[inline]
fn decode<D: Decoder>(d: &mut D) -> Result<LintId, D::Error> {
let s = d.read_str()?;
ty::tls::with(|tcx| {
match tcx.lint_store.find_lints(&s) {
Ok(ids) => {
if ids.len() != 0 {
panic!("invalid lint-id `{}`", s);
}
Ok(ids[0])
}
Err(_) => panic!("invalid lint-id `{}`", s),
}
})
}
}
3 changes: 3 additions & 0 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::path::{Path, PathBuf};
use syntax::ast;
use syntax::symbol::Symbol;
use syntax_pos::Span;
use syntax::expand::allocator::AllocatorKind;
use rustc_target::spec::Target;
use rustc_data_structures::sync::{self, MetadataRef};
use rustc_macros::HashStable;
Expand Down Expand Up @@ -227,6 +228,8 @@ pub trait CrateStore {
// utility functions
fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata;
fn metadata_encoding_version(&self) -> &[u8];
fn injected_panic_runtime(&self) -> Option<CrateNum>;
fn allocator_kind(&self) -> Option<AllocatorKind>;
}

pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
Expand Down
13 changes: 1 addition & 12 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub use self::code_stats::{DataTypeKind, SizeKind, FieldInfo, VariantInfo};
use self::code_stats::CodeStats;

use crate::dep_graph::cgu_reuse_tracker::CguReuseTracker;
use crate::hir::def_id::CrateNum;
use rustc_data_structures::fingerprint::Fingerprint;

use crate::lint;
Expand All @@ -22,18 +21,17 @@ use errors::emitter::{Emitter, EmitterWriter};
use errors::emitter::HumanReadableErrorType;
use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
use syntax::edition::Edition;
use syntax::expand::allocator::AllocatorKind;
use syntax::feature_gate::{self, AttributeType};
use syntax::json::JsonEmitter;
use syntax::source_map;
use syntax::sess::{ParseSess, ProcessCfgMod};
use syntax::symbol::Symbol;
use syntax_pos::{MultiSpan, Span};
use crate::util::profiling::{SelfProfiler, SelfProfilerRef};

use rustc_target::spec::{PanicStrategy, RelroLevel, Target, TargetTriple};
use rustc_data_structures::flock;
use rustc_data_structures::jobserver;
use rustc_data_structures::profiling::{SelfProfiler, SelfProfilerRef};
use ::jobserver::Client;

use std;
Expand Down Expand Up @@ -102,12 +100,6 @@ pub struct Session {
/// The maximum number of stackframes allowed in const eval.
pub const_eval_stack_frame_limit: usize,

/// The `metadata::creader` module may inject an allocator/`panic_runtime`
/// dependency if it didn't already find one, and this tracks what was
/// injected.
pub allocator_kind: Once<Option<AllocatorKind>>,
pub injected_panic_runtime: Once<Option<CrateNum>>,

/// Map from imported macro spans (which consist of
/// the localized span for the macro body) to the
/// macro name and definition span in the source crate.
Expand Down Expand Up @@ -1099,7 +1091,6 @@ fn build_session_(
);
match profiler {
Ok(profiler) => {
crate::ty::query::QueryName::register_with_profiler(&profiler);
Some(Arc::new(profiler))
},
Err(e) => {
Expand Down Expand Up @@ -1182,8 +1173,6 @@ fn build_session_(
recursion_limit: Once::new(),
type_length_limit: Once::new(),
const_eval_stack_frame_limit: 100,
allocator_kind: Once::new(),
injected_panic_runtime: Once::new(),
imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())),
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
cgu_reuse_tracker,
Expand Down
Loading

0 comments on commit 688a74b

Please sign in to comment.