Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #59942

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
442bef7
compiletest normalization: preserve non-JSON lines such as ICEs
RalfJung Apr 7, 2019
0c45546
fix tests
RalfJung Apr 7, 2019
83dcc96
fix output test for backtrace-debuginfo.rs
RalfJung Apr 7, 2019
be83bd5
normalize flags and rustc version in ICE repro
RalfJung Apr 7, 2019
126ac9e
Add test with current behaviour.
davidtwco Apr 7, 2019
724ca05
Exclude profiler-generated symbols from MSVC __imp_-symbol workaround.
michaelwoerister Apr 9, 2019
3a35b7e
normalize away spurious error
RalfJung Apr 9, 2019
8861232
some more tests need normalization
RalfJung Apr 9, 2019
7b1df42
Clean up handling of -Zpgo-gen commandline option.
michaelwoerister Apr 10, 2019
d84907b
Suggest macro import from crate root.
davidtwco Apr 7, 2019
d589cf9
Handle renamed imports.
davidtwco Apr 7, 2019
7c95540
Handle edge cases.
davidtwco Apr 7, 2019
137ffa1
Improve robustness of nested check.
davidtwco Apr 11, 2019
5158063
Switch to multipart suggestions.
davidtwco Apr 11, 2019
633fc9e
Revert PR #59401 to fix issue #59652 (a stable-to-beta regression).
pnkfelix Apr 12, 2019
796e6e3
Don't generate empty json variables
GuillaumeGomez Apr 11, 2019
4f28431
Apply resource-suffix to search-index and source-files scripts as well
GuillaumeGomez Apr 7, 2019
7e62052
Use a proc macro to declare preallocated symbols
Zoxc Apr 3, 2019
0e26063
Make check_name generic
Zoxc Apr 5, 2019
9c63475
Ensure the symbols are pure strings
Zoxc Apr 9, 2019
856c8a0
Move modules outside the proc macro
Zoxc Apr 9, 2019
b5f246a
Use colon for keyword defs
Zoxc Apr 9, 2019
520f58a
Rollup merge of #59655 - Zoxc:symbols, r=petrochenkov
Centril Apr 13, 2019
1d8905a
Rollup merge of #59769 - RalfJung:compiletest-normalization, r=alexcr…
Centril Apr 13, 2019
93cfaab
Rollup merge of #59776 - GuillaumeGomez:apply-resource-suffix, r=Quie…
Centril Apr 13, 2019
ae90d8d
Rollup merge of #59784 - davidtwco:issue-59764, r=estebank
Centril Apr 13, 2019
dbe8ea0
Rollup merge of #59812 - michaelwoerister:profile-gen-msvc-imp, r=ale…
Centril Apr 13, 2019
09dee29
Rollup merge of #59874 - michaelwoerister:pgo-updates-1, r=cramertj
Centril Apr 13, 2019
5518a19
Rollup merge of #59890 - GuillaumeGomez:empty-json-variables, r=Quiet…
Centril Apr 13, 2019
6319184
Rollup merge of #59911 - pnkfelix:revert-pr-59401-to-fix-emit-stack-s…
Centril Apr 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3385,6 +3385,7 @@ dependencies = [
"arena 0.0.0",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_data_structures 0.0.0",
"rustc_macros 0.1.0",
"scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serialize 0.0.0",
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down
27 changes: 0 additions & 27 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,33 +187,6 @@ fn main() {
cmd.arg("-C").arg(format!("debug-assertions={}", debug_assertions));
}

// Build all crates in the `std` facade with `-Z emit-stack-sizes` to add stack usage
// information.
//
// When you use this `-Z` flag with Cargo you get stack usage information on all crates
// compiled from source, and when you are using LTO you also get information on pre-compiled
// crates like `core` and `std`, even if they were not compiled with `-Z emit-stack-sizes`.
// However, there's an exception: `compiler_builtins`. This crate is special and doesn't
// participate in LTO because it's always linked as a separate object file. For this reason
// it's impossible to get stack usage information about `compiler-builtins` using
// `RUSTFLAGS` + Cargo, or `cargo rustc`.
//
// To make the stack usage information of all crates under the `std` facade available to
// Cargo based stack usage analysis tools, in both LTO and non-LTO mode, we compile them
// with the `-Z emit-stack-sizes` flag. The `RUSTC_EMIT_STACK_SIZES` var helps us apply this
// flag only to the crates in the `std` facade. The `-Z` flag is known to currently work
// with targets that produce ELF files so we limit its use flag to those targets.
//
// NOTE(japaric) if this ever causes problem with an LLVM upgrade or any PR feel free to
// remove it or comment it out
if env::var_os("RUSTC_EMIT_STACK_SIZES").is_some()
&& (target.contains("-linux-")
|| target.contains("-none-eabi")
|| target.ends_with("-none-elf"))
{
cmd.arg("-Zemit-stack-sizes");
}

if let Ok(s) = env::var("RUSTC_CODEGEN_UNITS") {
cmd.arg("-C").arg(format!("codegen-units={}", s));
}
Expand Down
4 changes: 0 additions & 4 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ impl Step for Std {
let _folder = builder.fold_output(|| format!("stage{}-std", compiler.stage));
builder.info(&format!("Building stage{} std artifacts ({} -> {})", compiler.stage,
&compiler.host, target));
// compile with `-Z emit-stack-sizes`; see bootstrap/src/rustc.rs for more details
cargo.env("RUSTC_EMIT_STACK_SIZES", "1");
run_cargo(builder,
&mut cargo,
&libstd_stamp(builder, compiler, target),
Expand Down Expand Up @@ -397,8 +395,6 @@ impl Step for Test {
let _folder = builder.fold_output(|| format!("stage{}-test", compiler.stage));
builder.info(&format!("Building stage{} test artifacts ({} -> {})", compiler.stage,
&compiler.host, target));
// compile with `-Z emit-stack-sizes`; see bootstrap/src/rustc.rs for more details
cargo.env("RUSTC_EMIT_STACK_SIZES", "1");
run_cargo(builder,
&mut cargo,
&libtest_stamp(builder, compiler, target),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/lib_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::ty::TyCtxt;
use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
use syntax::symbol::Symbol;
use syntax::ast::{Attribute, MetaItem, MetaItemKind};
use syntax_pos::Span;
use syntax_pos::{Span, symbols};
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
use rustc_macros::HashStable;
use errors::DiagnosticId;
Expand Down Expand Up @@ -51,12 +51,12 @@ impl<'a, 'tcx> LibFeatureCollector<'a, 'tcx> {
}

fn extract(&self, attr: &Attribute) -> Option<(Symbol, Option<Symbol>, Span)> {
let stab_attrs = vec!["stable", "unstable", "rustc_const_unstable"];
let stab_attrs = [symbols::stable, symbols::unstable, symbols::rustc_const_unstable];

// Find a stability attribute (i.e., `#[stable (..)]`, `#[unstable (..)]`,
// `#[rustc_const_unstable (..)]`).
if let Some(stab_attr) = stab_attrs.iter().find(|stab_attr| {
attr.check_name(stab_attr)
attr.check_name(**stab_attr)
}) {
let meta_item = attr.meta();
if let Some(MetaItem { node: MetaItemKind::List(ref metas), .. }) = meta_item {
Expand Down
38 changes: 32 additions & 6 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ impl LinkerPluginLto {
}
}

#[derive(Clone, PartialEq, Hash)]
pub enum PgoGenerate {
Enabled(Option<PathBuf>),
Disabled,
}

impl PgoGenerate {
pub fn enabled(&self) -> bool {
match *self {
PgoGenerate::Enabled(_) => true,
PgoGenerate::Disabled => false,
}
}
}

#[derive(Clone, Copy, PartialEq, Hash)]
pub enum DebugInfo {
None,
Expand Down Expand Up @@ -826,13 +841,15 @@ macro_rules! options {
pub const parse_linker_plugin_lto: Option<&str> =
Some("either a boolean (`yes`, `no`, `on`, `off`, etc), \
or the path to the linker plugin");
pub const parse_pgo_generate: Option<&str> =
Some("an optional path to the profiling data output directory");
pub const parse_merge_functions: Option<&str> =
Some("one of: `disabled`, `trampolines`, or `aliases`");
}

#[allow(dead_code)]
mod $mod_set {
use super::{$struct_name, Passes, Sanitizer, LtoCli, LinkerPluginLto};
use super::{$struct_name, Passes, Sanitizer, LtoCli, LinkerPluginLto, PgoGenerate};
use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel};
use std::path::PathBuf;
use std::str::FromStr;
Expand Down Expand Up @@ -1087,6 +1104,14 @@ macro_rules! options {
true
}

fn parse_pgo_generate(slot: &mut PgoGenerate, v: Option<&str>) -> bool {
*slot = match v {
None => PgoGenerate::Enabled(None),
Some(path) => PgoGenerate::Enabled(Some(PathBuf::from(path))),
};
true
}

fn parse_merge_functions(slot: &mut Option<MergeFunctions>, v: Option<&str>) -> bool {
match v.and_then(|s| MergeFunctions::from_str(s).ok()) {
Some(mergefunc) => *slot = Some(mergefunc),
Expand Down Expand Up @@ -1363,7 +1388,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"extra arguments to prepend to the linker invocation (space separated)"),
profile: bool = (false, parse_bool, [TRACKED],
"insert profiling code"),
pgo_gen: Option<String> = (None, parse_opt_string, [TRACKED],
pgo_gen: PgoGenerate = (PgoGenerate::Disabled, parse_pgo_generate, [TRACKED],
"Generate PGO profile data, to a given file, or to the default location if it's empty."),
pgo_use: String = (String::new(), parse_string, [TRACKED],
"Use PGO profile data from the given profile file."),
Expand Down Expand Up @@ -1980,7 +2005,7 @@ pub fn build_session_options_and_crate_config(
);
}

if debugging_opts.pgo_gen.is_some() && !debugging_opts.pgo_use.is_empty() {
if debugging_opts.pgo_gen.enabled() && !debugging_opts.pgo_use.is_empty() {
early_error(
error_format,
"options `-Z pgo-gen` and `-Z pgo-use` are exclusive",
Expand Down Expand Up @@ -2490,7 +2515,7 @@ mod dep_tracking {
use std::path::PathBuf;
use std::collections::hash_map::DefaultHasher;
use super::{CrateType, DebugInfo, ErrorOutputType, OptLevel, OutputTypes,
Passes, Sanitizer, LtoCli, LinkerPluginLto};
Passes, Sanitizer, LtoCli, LinkerPluginLto, PgoGenerate};
use syntax::feature_gate::UnstableFeatures;
use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel, TargetTriple};
use syntax::edition::Edition;
Expand Down Expand Up @@ -2558,6 +2583,7 @@ mod dep_tracking {
impl_dep_tracking_hash_via_hash!(TargetTriple);
impl_dep_tracking_hash_via_hash!(Edition);
impl_dep_tracking_hash_via_hash!(LinkerPluginLto);
impl_dep_tracking_hash_via_hash!(PgoGenerate);

impl_dep_tracking_hash_for_sortable_vec_of!(String);
impl_dep_tracking_hash_for_sortable_vec_of!(PathBuf);
Expand Down Expand Up @@ -2625,7 +2651,7 @@ mod tests {
build_session_options_and_crate_config,
to_crate_config
};
use crate::session::config::{LtoCli, LinkerPluginLto};
use crate::session::config::{LtoCli, LinkerPluginLto, PgoGenerate};
use crate::session::build_session;
use crate::session::search_paths::SearchPath;
use std::collections::{BTreeMap, BTreeSet};
Expand Down Expand Up @@ -3124,7 +3150,7 @@ mod tests {
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());

opts = reference.clone();
opts.debugging_opts.pgo_gen = Some(String::from("abc"));
opts.debugging_opts.pgo_gen = PgoGenerate::Enabled(None);
assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash());

opts = reference.clone();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
}

// probestack doesn't play nice either with pgo-gen.
if cx.sess().opts.debugging_opts.pgo_gen.is_some() {
if cx.sess().opts.debugging_opts.pgo_gen.enabled() {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ fn link_args(cmd: &mut dyn Linker,
cmd.build_static_executable();
}

if sess.opts.debugging_opts.pgo_gen.is_some() {
if sess.opts.debugging_opts.pgo_gen.enabled() {
cmd.pgo_gen();
}

Expand Down
40 changes: 33 additions & 7 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::LlvmCodegenBackend;
use rustc::hir::def_id::LOCAL_CRATE;
use rustc_codegen_ssa::back::write::{CodegenContext, ModuleConfig, run_assembler};
use rustc_codegen_ssa::traits::*;
use rustc::session::config::{self, OutputType, Passes, Lto};
use rustc::session::config::{self, OutputType, Passes, Lto, PgoGenerate};
use rustc::session::Session;
use rustc::ty::TyCtxt;
use rustc_codegen_ssa::{ModuleCodegen, CompiledModule};
Expand All @@ -25,7 +25,7 @@ use errors::{Handler, FatalError};
use std::ffi::{CString, CStr};
use std::fs;
use std::io::{self, Write};
use std::path::Path;
use std::path::{Path, PathBuf};
use std::str;
use std::sync::Arc;
use std::slice;
Expand Down Expand Up @@ -706,10 +706,20 @@ pub unsafe fn with_llvm_pmb(llmod: &llvm::Module,
.unwrap_or(llvm::CodeGenOptSizeNone);
let inline_threshold = config.inline_threshold;

let pgo_gen_path = config.pgo_gen.as_ref().map(|s| {
let s = if s.is_empty() { "default_%m.profraw" } else { s };
CString::new(s.as_bytes()).unwrap()
});
let pgo_gen_path = match config.pgo_gen {
PgoGenerate::Enabled(ref opt_dir_path) => {
let path = if let Some(dir_path) = opt_dir_path {
dir_path.join("default_%m.profraw")
} else {
PathBuf::from("default_%m.profraw")
};

Some(CString::new(format!("{}", path.display())).unwrap())
}
PgoGenerate::Disabled => {
None
}
};

let pgo_use_path = if config.pgo_use.is_empty() {
None
Expand Down Expand Up @@ -793,21 +803,31 @@ fn create_msvc_imps(
} else {
"\x01__imp_"
};

unsafe {
let i8p_ty = Type::i8p_llcx(llcx);
let globals = base::iter_globals(llmod)
.filter(|&val| {
llvm::LLVMRustGetLinkage(val) == llvm::Linkage::ExternalLinkage &&
llvm::LLVMIsDeclaration(val) == 0
})
.map(move |val| {
.filter_map(|val| {
// Exclude some symbols that we know are not Rust symbols.
let name = CStr::from_ptr(llvm::LLVMGetValueName(val));
if ignored(name.to_bytes()) {
None
} else {
Some((val, name))
}
})
.map(move |(val, name)| {
let mut imp_name = prefix.as_bytes().to_vec();
imp_name.extend(name.to_bytes());
let imp_name = CString::new(imp_name).unwrap();
(imp_name, val)
})
.collect::<Vec<_>>();

for (imp_name, val) in globals {
let imp = llvm::LLVMAddGlobal(llmod,
i8p_ty,
Expand All @@ -816,4 +836,10 @@ fn create_msvc_imps(
llvm::LLVMRustSetLinkage(imp, llvm::Linkage::ExternalLinkage);
}
}

// Use this function to exclude certain symbols from `__imp` generation.
fn ignored(symbol_name: &[u8]) -> bool {
// These are symbols generated by LLVM's profiling instrumentation
symbol_name.starts_with(b"__llvm_profile_")
}
}
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
}

if tcx.sess.opts.debugging_opts.pgo_gen.is_some() {
if tcx.sess.opts.debugging_opts.pgo_gen.enabled() {
// These are weak symbols that point to the profile version and the
// profile name, which need to be treated as exported so LTO doesn't nix
// them.
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use rustc_incremental::{copy_cgu_workproducts_to_incr_comp_cache_dir,
use rustc::dep_graph::{WorkProduct, WorkProductId, WorkProductFileKind};
use rustc::dep_graph::cgu_reuse_tracker::CguReuseTracker;
use rustc::middle::cstore::EncodedMetadata;
use rustc::session::config::{self, OutputFilenames, OutputType, Passes, Sanitizer, Lto};
use rustc::session::config::{self, OutputFilenames, OutputType, Passes, Lto,
Sanitizer, PgoGenerate};
use rustc::session::Session;
use rustc::util::nodemap::FxHashMap;
use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
Expand Down Expand Up @@ -55,7 +56,7 @@ pub struct ModuleConfig {
/// Some(level) to optimize binary size, or None to not affect program size.
pub opt_size: Option<config::OptLevel>,

pub pgo_gen: Option<String>,
pub pgo_gen: PgoGenerate,
pub pgo_use: String,

// Flags indicating which outputs to produce.
Expand Down Expand Up @@ -93,7 +94,7 @@ impl ModuleConfig {
opt_level: None,
opt_size: None,

pgo_gen: None,
pgo_gen: PgoGenerate::Disabled,
pgo_use: String::new(),

emit_no_opt_bc: false,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ impl<'a, 'tcx> FindAllAttrs<'a, 'tcx> {

fn is_active_attr(&mut self, attr: &Attribute) -> bool {
for attr_name in &self.attr_names {
if attr.check_name(attr_name) && check_config(self.tcx, attr) {
if attr.check_name(*attr_name) && check_config(self.tcx, attr) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {

let plugin_attributes = cx.sess().plugin_attributes.borrow_mut();
for &(ref name, ty) in plugin_attributes.iter() {
if ty == AttributeType::Whitelisted && attr.check_name(&name) {
if ty == AttributeType::Whitelisted && attr.check_name(&**name) {
debug!("{:?} (plugin attr) is whitelisted with ty {:?}", name, ty);
break;
}
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ use proc_macro::TokenStream;

mod hash_stable;
mod query;
mod symbols;

#[proc_macro]
pub fn rustc_queries(input: TokenStream) -> TokenStream {
query::rustc_queries(input)
}

#[proc_macro]
pub fn symbols(input: TokenStream) -> TokenStream {
symbols::symbols(input)
}

decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive);
Loading