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 11 pull requests #83247

Merged
merged 36 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 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
12c6a12
Emit error when trying to use assembler syntax directives in `asm!`
asquared31415 Feb 18, 2021
39dcd01
Take into account target default syntax
asquared31415 Feb 20, 2021
68f41b8
Add more links between hash and btree collections
jyn514 Feb 23, 2021
05ae666
Move default inline asm dialect to Session
asquared31415 Mar 8, 2021
4b13b81
Test x86 and arm outputs
asquared31415 Mar 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
a7491d9
fix whitespace
jyn514 Mar 17, 2021
ee98c6f
Don't show HTML diff if tidy isn't installed for rustdoc tests
GuillaumeGomez Mar 17, 2021
9a3e23f
riscvgc-unknown-none-elf use lp64d ABI
Mar 17, 2021
90797ef
Rollup merge of #82191 - Soveu:dedup, r=nagisa
Dylan-DPC Mar 17, 2021
16f6583
Rollup merge of #82270 - asquared31415:asm-syntax-directive-errors, r…
Dylan-DPC Mar 17, 2021
c99200f
Rollup merge of #82434 - jyn514:hash, r=JohnTitor
Dylan-DPC Mar 17, 2021
b688b69
Rollup merge of #83080 - tmiasko:inline-coverage, r=wesleywiser
Dylan-DPC Mar 17, 2021
7cd7dee
Rollup merge of #83168 - Aaron1011:lint-procedural-masquerade, r=petr…
Dylan-DPC Mar 17, 2021
1e23ab5
Rollup merge of #83192 - kinnison:add-android-21, r=Mark-Simulacrum
Dylan-DPC Mar 17, 2021
201893f
Rollup merge of #83204 - jethrogb:jb/sgx-c-build, r=joshtriplett,raou…
Dylan-DPC Mar 17, 2021
bcb9226
Rollup merge of #83216 - jyn514:register-tool, r=petrochenkov
Dylan-DPC Mar 17, 2021
0340045
Rollup merge of #83223 - JohnTitor:display-err-from-mmap, r=joshtriplett
Dylan-DPC Mar 17, 2021
22a9582
Rollup merge of #83228 - GuillaumeGomez:no-diff-if-no-tidy, r=jyn514
Dylan-DPC Mar 17, 2021
1839d1d
Rollup merge of #83231 - DieracDelta:lp64d-abi-for-riscvgc-unknown-no…
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
73 changes: 72 additions & 1 deletion compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_expand::base::{self, *};
use rustc_parse::parser::Parser;
use rustc_parse_format as parse;
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::{
symbol::{kw, sym, Symbol},
BytePos,
};
use rustc_span::{InnerSpan, Span};

struct AsmArgs {
Expand Down Expand Up @@ -399,6 +402,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
let mut line_spans = Vec::with_capacity(args.templates.len());
let mut curarg = 0;

let default_dialect = ecx.sess.inline_asm_dialect();

for template_expr in args.templates.into_iter() {
if !template.is_empty() {
template.push(ast::InlineAsmTemplatePiece::String("\n".to_string()));
Expand All @@ -424,6 +429,60 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast

let template_str = &template_str.as_str();
let template_snippet = ecx.source_map().span_to_snippet(template_sp).ok();

if let Some(snippet) = &template_snippet {
let snippet = snippet.trim_matches('"');
match default_dialect {
ast::LlvmAsmDialect::Intel => {
if let Some(span) = check_syntax_directive(snippet, ".intel_syntax") {
let span = template_span.from_inner(span);
let mut err = ecx.struct_span_err(span, "intel syntax is the default syntax on this target, and trying to use this directive may cause issues");
err.span_suggestion(
span,
"remove this assembler directive",
"".to_string(),
Applicability::MachineApplicable,
);
err.emit();
}

if let Some(span) = check_syntax_directive(snippet, ".att_syntax") {
let span = template_span.from_inner(span);
let mut err = ecx.struct_span_err(span, "using the .att_syntax directive may cause issues, use the att_syntax option instead");
let asm_end = sp.hi() - BytePos(2);
let suggestions = vec![
(span, "".to_string()),
(
Span::new(asm_end, asm_end, sp.ctxt()),
", options(att_syntax)".to_string(),
),
];
err.multipart_suggestion(
"remove the assembler directive and replace it with options(att_syntax)",
suggestions,
Applicability::MachineApplicable,
);
err.emit();
}
}
ast::LlvmAsmDialect::Att => {
if let Some(span) = check_syntax_directive(snippet, ".att_syntax") {
let span = template_span.from_inner(span);
let mut err = ecx.struct_span_err(span, "att syntax is the default syntax on this target, and trying to use this directive may cause issues");
err.span_suggestion(
span,
"remove this assembler directive",
"".to_string(),
Applicability::MachineApplicable,
);
err.emit();
}

// Use of .intel_syntax is ignored
}
}
}

let mut parser = parse::Parser::new(
template_str,
str_style,
Expand Down Expand Up @@ -631,3 +690,15 @@ pub fn expand_asm<'cx>(
}
}
}

fn check_syntax_directive<S: AsRef<str>>(piece: S, syntax: &str) -> Option<InnerSpan> {
let piece = piece.as_ref();
if let Some(idx) = piece.find(syntax) {
let end =
idx + &piece[idx..].find(|c| matches!(c, '\n' | ';')).unwrap_or(piece[idx..].len());
// Offset by one because these represent the span with the " removed
Some(InnerSpan::new(idx + 1, end + 1))
} else {
None
}
}
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
Loading