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 9 pull requests #83240

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
1825810
Vec::dedup optimization
Soveu Feb 16, 2021
c114894
Vec::dedup optimization - panic gracefully
Soveu Feb 17, 2021
e292e6e
Stabilize `peekable_peek_mut`
lukaslueg Feb 9, 2021
2abab1f
Vec::dedup optimization - add tests
Soveu Mar 15, 2021
afdbc9e
Vec::dedup optimization - finishing polishes
Soveu Mar 15, 2021
d6a7c1d
Extend `proc_macro_back_compat` lint to `procedural-masquerade`
Aaron1011 Mar 15, 2021
2285f11
Vec::dedup optimization - add test for panic
Soveu Mar 15, 2021
96d6f22
Merge branch 'master' into dedup
Soveu Mar 15, 2021
1796cc0
Make source-based code coverage compatible with MIR inlining
tmiasko Mar 13, 2021
5a9538a
Functions inlined into reachable functions are reachable
tmiasko Mar 13, 2021
ad8f9af
Remove inline-instrument-coverage-fail.rs test case
tmiasko Mar 13, 2021
4b6cc0c
Add support for compile-flags in coverage tests
tmiasko Mar 15, 2021
0d84e0b
Add test case for -Zinline-mir & -Zinstrument-coverage
tmiasko Mar 16, 2021
bd2737f
ci/docker: Add SDK/NDK level 21 to android docker for 32bit platforms
kinnison Mar 16, 2021
b0092bc
Vec::dedup optimization - add benches
Soveu Mar 16, 2021
5bd50ef
Simplify C compilation for Fortanix-SGX target
Mar 16, 2021
e3031fe
Allow registering tool lints with `register_tool`
jyn514 Mar 16, 2021
f414c33
Display error details when a `mmap` call fails
JohnTitor Mar 17, 2021
7dc654c
Update library/core/src/iter/traits/iterator.rs
lukaslueg Mar 17, 2021
8af15db
Update library/core/src/iter/traits/iterator.rs
lukaslueg Mar 17, 2021
ee98c6f
Don't show HTML diff if tidy isn't installed for rustdoc tests
GuillaumeGomez Mar 17, 2021
03abd47
Rollup merge of #81938 - lukaslueg:stab_peek_mut, r=KodrAus,JohnTitor
Dylan-DPC Mar 17, 2021
af0424e
Rollup merge of #82191 - Soveu:dedup, r=nagisa
Dylan-DPC Mar 17, 2021
9a852f9
Rollup merge of #83080 - tmiasko:inline-coverage, r=wesleywiser
Dylan-DPC Mar 17, 2021
243b275
Rollup merge of #83168 - Aaron1011:lint-procedural-masquerade, r=petr…
Dylan-DPC Mar 17, 2021
2472e15
Rollup merge of #83192 - kinnison:add-android-21, r=Mark-Simulacrum
Dylan-DPC Mar 17, 2021
dbd1df1
Rollup merge of #83204 - jethrogb:jb/sgx-c-build, r=joshtriplett,raou…
Dylan-DPC Mar 17, 2021
86faabe
Rollup merge of #83216 - jyn514:register-tool, r=petrochenkov
Dylan-DPC Mar 17, 2021
af9ed1d
Rollup merge of #83223 - JohnTitor:display-err-from-mmap, r=joshtriplett
Dylan-DPC Mar 17, 2021
423fc34
Rollup merge of #83228 - GuillaumeGomez:no-diff-if-no-tidy, r=jyn514
Dylan-DPC Mar 17, 2021
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
4 changes: 0 additions & 4 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ impl MarkedAttrs {
}
}

pub fn is_known_lint_tool(m_item: Ident) -> bool {
[sym::clippy, sym::rustc, sym::rustdoc].contains(&m_item.name)
}

impl NestedMetaItem {
/// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem`.
pub fn meta_item(&self) -> Option<&MetaItem> {
Expand Down
27 changes: 0 additions & 27 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,33 +784,6 @@ impl Nonterminal {
NtTT(tt) => tt.span(),
}
}

/// This nonterminal looks like some specific enums from
/// `proc-macro-hack` and `procedural-masquerade` crates.
/// We need to maintain some special pretty-printing behavior for them due to incorrect
/// asserts in old versions of those crates and their wide use in the ecosystem.
/// See issue #73345 for more details.
/// FIXME(#73933): Remove this eventually.
pub fn pretty_printing_compatibility_hack(&self) -> bool {
let item = match self {
NtItem(item) => item,
NtStmt(stmt) => match &stmt.kind {
ast::StmtKind::Item(item) => item,
_ => return false,
},
_ => return false,
};

let name = item.ident.name;
if name == sym::ProceduralMasqueradeDummyType || name == sym::ProcMacroHack {
if let ast::ItemKind::Enum(enum_def, _) = &item.kind {
if let [variant] = &*enum_def.variants {
return variant.ident.name == sym::Input;
}
}
}
false
}
}

impl PartialEq for Nonterminal {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ fn save_function_record(
///
/// 1. The file name of an "Unreachable" function must match the file name of the existing
/// codegenned (covered) function to which the unreachable code regions will be added.
/// 2. The function to which the unreachable code regions will be added must not be a genaric
/// 2. The function to which the unreachable code regions will be added must not be a generic
/// function (must not have type parameters) because the coverage tools will get confused
/// if the codegenned function has more than one instantiation and additional `CodeRegion`s
/// attached to only one of those instantiations.
Expand Down Expand Up @@ -284,7 +284,7 @@ fn add_unreachable_coverage<'tcx>(
let all_def_ids: DefIdSet =
tcx.mir_keys(LOCAL_CRATE).iter().map(|local_def_id| local_def_id.to_def_id()).collect();

let (codegenned_def_ids, _) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
let codegenned_def_ids = tcx.codegened_and_inlined_items(LOCAL_CRATE);

let mut unreachable_def_ids_by_file: FxHashMap<Symbol, Vec<DefId>> = FxHashMap::default();
for &non_codegenned_def_id in all_def_ids.difference(codegenned_def_ids) {
Expand Down
21 changes: 16 additions & 5 deletions compiler/rustc_codegen_ssa/src/coverageinfo/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_middle::mir::coverage::{
use rustc_middle::ty::Instance;
use rustc_middle::ty::TyCtxt;

#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct Expression {
lhs: ExpressionOperandId,
op: Op,
Expand Down Expand Up @@ -64,7 +64,9 @@ impl<'tcx> FunctionCoverage<'tcx> {

/// Adds a code region to be counted by an injected counter intrinsic.
pub fn add_counter(&mut self, id: CounterValueReference, region: CodeRegion) {
self.counters[id].replace(region).expect_none("add_counter called with duplicate `id`");
if let Some(previous_region) = self.counters[id].replace(region.clone()) {
assert_eq!(previous_region, region, "add_counter: code region for id changed");
}
}

/// Both counters and "counter expressions" (or simply, "expressions") can be operands in other
Expand Down Expand Up @@ -94,9 +96,18 @@ impl<'tcx> FunctionCoverage<'tcx> {
expression_id, lhs, op, rhs, region
);
let expression_index = self.expression_index(u32::from(expression_id));
self.expressions[expression_index]
.replace(Expression { lhs, op, rhs, region })
.expect_none("add_counter_expression called with duplicate `id_descending_from_max`");
if let Some(previous_expression) = self.expressions[expression_index].replace(Expression {
lhs,
op,
rhs,
region: region.clone(),
}) {
assert_eq!(
previous_expression,
Expression { lhs, op, rhs, region },
"add_counter_expression: expression for id changed"
);
}
}

/// Add a region that will be marked as "unreachable", with a constant "zero counter".
Expand Down
25 changes: 18 additions & 7 deletions compiler/rustc_codegen_ssa/src/mir/coverageinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,38 @@ use crate::traits::*;

use rustc_middle::mir::coverage::*;
use rustc_middle::mir::Coverage;
use rustc_middle::mir::SourceScope;

use super::FunctionCx;

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
pub fn codegen_coverage(&self, bx: &mut Bx, coverage: Coverage) {
pub fn codegen_coverage(&self, bx: &mut Bx, coverage: Coverage, scope: SourceScope) {
// Determine the instance that coverage data was originally generated for.
let scope_data = &self.mir.source_scopes[scope];
let instance = if let Some((inlined_instance, _)) = scope_data.inlined {
self.monomorphize(inlined_instance)
} else if let Some(inlined_scope) = scope_data.inlined_parent_scope {
self.monomorphize(self.mir.source_scopes[inlined_scope].inlined.unwrap().0)
} else {
self.instance
};

let Coverage { kind, code_region } = coverage;
match kind {
CoverageKind::Counter { function_source_hash, id } => {
if bx.set_function_source_hash(self.instance, function_source_hash) {
if bx.set_function_source_hash(instance, function_source_hash) {
// If `set_function_source_hash()` returned true, the coverage map is enabled,
// so continue adding the counter.
if let Some(code_region) = code_region {
// Note: Some counters do not have code regions, but may still be referenced
// from expressions. In that case, don't add the counter to the coverage map,
// but do inject the counter intrinsic.
bx.add_coverage_counter(self.instance, id, code_region);
bx.add_coverage_counter(instance, id, code_region);
}

let coverageinfo = bx.tcx().coverageinfo(self.instance.def_id());
let coverageinfo = bx.tcx().coverageinfo(instance.def_id());

let fn_name = bx.create_pgo_func_name_var(self.instance);
let fn_name = bx.create_pgo_func_name_var(instance);
let hash = bx.const_u64(function_source_hash);
let num_counters = bx.const_u32(coverageinfo.num_counters);
let index = bx.const_u32(u32::from(id));
Expand All @@ -34,11 +45,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
}
CoverageKind::Expression { id, lhs, op, rhs } => {
bx.add_coverage_counter_expression(self.instance, id, lhs, op, rhs, code_region);
bx.add_coverage_counter_expression(instance, id, lhs, op, rhs, code_region);
}
CoverageKind::Unreachable => {
bx.add_coverage_unreachable(
self.instance,
instance,
code_region.expect("unreachable regions always have code regions"),
);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/mir/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx
}
mir::StatementKind::Coverage(box ref coverage) => {
self.codegen_coverage(&mut bx, coverage.clone());
self.codegen_coverage(&mut bx, coverage.clone(), statement.source_info.scope);
bx
}
mir::StatementKind::CopyNonOverlapping(box mir::CopyNonOverlapping {
Expand Down
40 changes: 40 additions & 0 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use rustc_attr::{self as attr, Deprecation, Stability};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::{self, Lrc};
use rustc_errors::{DiagnosticBuilder, ErrorReported};
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
use rustc_lint_defs::BuiltinLintDiagnostics;
use rustc_parse::{self, nt_to_tokenstream, parser, MACRO_ARGUMENTS};
use rustc_session::{parse::ParseSess, Limit, Session};
use rustc_span::def_id::DefId;
Expand Down Expand Up @@ -1241,3 +1243,41 @@ pub fn get_exprs_from_tts(
}
Some(es)
}

/// This nonterminal looks like some specific enums from
/// `proc-macro-hack` and `procedural-masquerade` crates.
/// We need to maintain some special pretty-printing behavior for them due to incorrect
/// asserts in old versions of those crates and their wide use in the ecosystem.
/// See issue #73345 for more details.
/// FIXME(#73933): Remove this eventually.
pub(crate) fn pretty_printing_compatibility_hack(nt: &Nonterminal, sess: &ParseSess) -> bool {
let item = match nt {
Nonterminal::NtItem(item) => item,
Nonterminal::NtStmt(stmt) => match &stmt.kind {
ast::StmtKind::Item(item) => item,
_ => return false,
},
_ => return false,
};

let name = item.ident.name;
if name == sym::ProceduralMasqueradeDummyType {
if let ast::ItemKind::Enum(enum_def, _) = &item.kind {
if let [variant] = &*enum_def.variants {
if variant.ident.name == sym::Input {
sess.buffer_lint_with_diagnostic(
&PROC_MACRO_BACK_COMPAT,
item.ident.span,
ast::CRATE_NODE_ID,
"using `procedural-masquerade` crate",
BuiltinLintDiagnostics::ProcMacroBackCompat(
"The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. \
Versions of this crate below 0.1.7 will eventually stop compiling.".to_string())
);
return true;
}
}
}
}
false
}
3 changes: 2 additions & 1 deletion compiler/rustc_expand/src/proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ impl MultiItemModifier for ProcMacroDerive {
}
_ => unreachable!(),
};
let input = if item.pretty_printing_compatibility_hack() {
let input = if crate::base::pretty_printing_compatibility_hack(&item, &ecx.sess.parse_sess)
{
TokenTree::token(token::Interpolated(Lrc::new(item)), DUMMY_SP).into()
} else {
nt_to_tokenstream(&item, &ecx.sess.parse_sess, CanSynthesizeMissingTokens::Yes)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl FromInternal<(TreeAndSpacing, &'_ ParseSess, &'_ mut Vec<Self>)>
delimiter: Delimiter::None,
stream,
span: DelimSpan::from_single(span),
flatten: nt.pretty_printing_compatibility_hack(),
flatten: crate::base::pretty_printing_compatibility_hack(&nt, sess),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ impl<'a> EarlyContext<'a> {
sess,
krate,
lint_store,
builder: LintLevelsBuilder::new(sess, warn_about_weird_lints, lint_store),
builder: LintLevelsBuilder::new(sess, warn_about_weird_lints, lint_store, &krate.attrs),
buffered,
}
}
Expand Down
46 changes: 37 additions & 9 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::context::{CheckLintNameResult, LintStore};
use crate::late::unerased_lint_store;
use rustc_ast as ast;
use rustc_ast::attr;
use rustc_ast::unwrap_or;
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::{intravisit, HirId};
use rustc_middle::hir::map::Map;
use rustc_middle::lint::LevelAndSource;
Expand All @@ -32,7 +31,8 @@ use std::cmp;
fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> LintLevelMap {
assert_eq!(cnum, LOCAL_CRATE);
let store = unerased_lint_store(tcx);
let levels = LintLevelsBuilder::new(tcx.sess, false, &store);
let crate_attrs = tcx.get_attrs(DefId { krate: cnum, index: CRATE_DEF_INDEX });
let levels = LintLevelsBuilder::new(tcx.sess, false, &store, crate_attrs);
let mut builder = LintLevelMapBuilder { levels, tcx, store };
let krate = tcx.hir().krate();

Expand All @@ -56,6 +56,7 @@ pub struct LintLevelsBuilder<'s> {
cur: u32,
warn_about_weird_lints: bool,
store: &'s LintStore,
crate_attrs: &'s [ast::Attribute],
}

pub struct BuilderPush {
Expand All @@ -64,14 +65,20 @@ pub struct BuilderPush {
}

impl<'s> LintLevelsBuilder<'s> {
pub fn new(sess: &'s Session, warn_about_weird_lints: bool, store: &'s LintStore) -> Self {
pub fn new(
sess: &'s Session,
warn_about_weird_lints: bool,
store: &'s LintStore,
crate_attrs: &'s [ast::Attribute],
) -> Self {
let mut builder = LintLevelsBuilder {
sess,
sets: LintLevelSets::new(),
cur: 0,
id_to_set: Default::default(),
warn_about_weird_lints,
store,
crate_attrs,
};
builder.process_command_line(sess, store);
assert_eq!(builder.sets.list.len(), 1);
Expand Down Expand Up @@ -304,15 +311,22 @@ impl<'s> LintLevelsBuilder<'s> {
};
let tool_name = if meta_item.path.segments.len() > 1 {
let tool_ident = meta_item.path.segments[0].ident;
if !attr::is_known_lint_tool(tool_ident) {
struct_span_err!(
if !is_known_lint_tool(tool_ident.name, sess, &self.crate_attrs) {
let mut err = struct_span_err!(
sess,
tool_ident.span,
E0710,
"an unknown tool name found in scoped lint: `{}`",
"unknown tool name `{}` found in scoped lint: `{}`",
tool_ident.name,
pprust::path_to_string(&meta_item.path),
)
.emit();
);
if sess.is_nightly_build() {
err.help(&format!(
"add `#![register_tool({})]` to the crate root",
tool_ident.name
));
}
err.emit();
continue;
}

Expand Down Expand Up @@ -559,6 +573,20 @@ impl<'s> LintLevelsBuilder<'s> {
}
}

fn is_known_lint_tool(m_item: Symbol, sess: &Session, attrs: &[ast::Attribute]) -> bool {
if [sym::clippy, sym::rustc, sym::rustdoc].contains(&m_item) {
return true;
}
// Look for registered tools
// NOTE: does no error handling; error handling is done by rustc_resolve.
sess.filter_by_name(attrs, sym::register_tool)
.filter_map(|attr| attr.meta_item_list())
.flat_map(std::convert::identity)
.filter_map(|nested_meta| nested_meta.ident())
.map(|ident| ident.name)
.any(|name| name == m_item)
}

struct LintLevelMapBuilder<'a, 'tcx> {
levels: LintLevelsBuilder<'tcx>,
tcx: TyCtxt<'tcx>,
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,14 @@ rustc_queries! {
query is_codegened_item(def_id: DefId) -> bool {
desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
}

/// All items participating in code generation together with items inlined into them.
query codegened_and_inlined_items(_: CrateNum)
-> &'tcx DefIdSet {
eval_always
desc { "codegened_and_inlined_items" }
}

query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
desc { "codegen_unit" }
}
Expand Down
Loading