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 10 pull requests #93921

Merged
merged 27 commits into from
Feb 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
69803f7
Make `span_extend_to_prev_str()` more robust
FabianWolff Jan 15, 2022
71ff16b
Update test output for `ui/asm/aarch64/parse-error.rs`
FabianWolff Jan 31, 2022
2d0bb0d
jsondocck: Improved error messages for invalid json value and failed …
aDotInTheVoid Feb 4, 2022
bf0e862
rustdoc-json: Add some tests for `typealias` item
aDotInTheVoid Feb 4, 2022
1115f15
windows: Map `ERROR_INVALID_NAME` as `InvalidInput`
JohnTitor Nov 16, 2021
755e475
Rename `FilenameTooLong` to `FilenameInvalid`
JohnTitor Jan 31, 2022
cc94079
Map `ERROR_INVALID_NAME` to `FilenameInvalid`
JohnTitor Jan 31, 2022
861f3c7
Fix description of FilenameInvalid
joshtriplett Jan 31, 2022
a898b31
Rename to `InvalidFilename`
JohnTitor Feb 10, 2022
d39a637
Split PAuth target feature
adamgemmell Jan 31, 2022
20e6c1d
Fix incorrect register conflict detection in asm!
Amanieu Feb 10, 2022
1f98ef7
Implement `AsFd` for `&T` and `&mut T`.
sunfishcode Feb 11, 2022
22a24c9
Add missing platform-specific information on current_dir and set_curr…
GuillaumeGomez Feb 3, 2022
45dc8eb
fix mention of moved function in `rustc_hir` docs
rosefromthedead Feb 11, 2022
f9cb01f
Fix typo: explicitely->explicitly
saschanaz Feb 11, 2022
55ceed8
Remove the alt_std_name option
bjorn3 Jan 14, 2022
7ba4110
Make two functions private
bjorn3 Jun 25, 2021
ce4df92
Rollup merge of #90955 - JohnTitor:os-error-123-as-invalid-input, r=m…
matthiaskrgr Feb 11, 2022
b7c48b4
Rollup merge of #91607 - FabianWolff:issue-91560-const-span, r=jackh726
matthiaskrgr Feb 11, 2022
642414e
Rollup merge of #92895 - bjorn3:simplifications, r=jackh726
matthiaskrgr Feb 11, 2022
15d71cf
Rollup merge of #93635 - GuillaumeGomez:missing-platform-spec-info, r…
matthiaskrgr Feb 11, 2022
ffa8d6b
Rollup merge of #93660 - aDotInTheVoid:rustdoc-type-tests, r=CraftSpider
matthiaskrgr Feb 11, 2022
13d636d
Rollup merge of #93782 - adamgemmell:dev/adagem01/split-pauth, r=Amanieu
matthiaskrgr Feb 11, 2022
db71248
Rollup merge of #93868 - Amanieu:asm_reg_conflict, r=cjgillot
matthiaskrgr Feb 11, 2022
34997f0
Rollup merge of #93888 - sunfishcode:sunfishcode/impl-asfd-for-ref, r…
matthiaskrgr Feb 11, 2022
0986b2d
Rollup merge of #93909 - saschanaz:patch-2, r=petrochenkov
matthiaskrgr Feb 11, 2022
de0feb3
Rollup merge of #93910 - rosehuds:master, r=cjgillot
matthiaskrgr Feb 11, 2022
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: 3 additions & 1 deletion compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
err.emit();
}
Entry::Vacant(v) => {
v.insert(idx);
if r == reg {
v.insert(idx);
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub fn inject(
mut krate: ast::Crate,
resolver: &mut dyn ResolverExpand,
sess: &Session,
alt_std_name: Option<Symbol>,
) -> ast::Crate {
let edition = sess.parse_sess.edition;

Expand Down Expand Up @@ -53,7 +52,7 @@ pub fn inject(
span,
ident,
vec![cx.attribute(cx.meta_word(span, sym::macro_use))],
ast::ItemKind::ExternCrate(alt_std_name),
ast::ItemKind::ExternCrate(None),
),
);
}
Expand Down
31 changes: 26 additions & 5 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,33 @@ pub fn from_fn_attrs<'ll, 'tcx>(
// The target doesn't care; the subtarget reads our attribute.
apply_tune_cpu_attr(cx, llfn);

let mut function_features = codegen_fn_attrs
.target_features
let function_features =
codegen_fn_attrs.target_features.iter().map(|f| f.as_str()).collect::<Vec<&str>>();

if let Some(f) = llvm_util::check_tied_features(
cx.tcx.sess,
&function_features.iter().map(|f| (*f, true)).collect(),
) {
let span = cx
.tcx
.get_attrs(instance.def_id())
.iter()
.find(|a| a.has_name(rustc_span::sym::target_feature))
.map_or_else(|| cx.tcx.def_span(instance.def_id()), |a| a.span);
let msg = format!(
"the target features {} must all be either enabled or disabled together",
f.join(", ")
);
let mut err = cx.tcx.sess.struct_span_err(span, &msg);
err.help("add the missing features in a `target_feature` attribute");
err.emit();
return;
}

let mut function_features = function_features
.iter()
.flat_map(|f| {
let feature = f.as_str();
llvm_util::to_llvm_feature(cx.tcx.sess, feature)
.flat_map(|feat| {
llvm_util::to_llvm_feature(cx.tcx.sess, feat)
.into_iter()
.map(|f| format!("+{}", f))
.collect::<Vec<String>>()
Expand Down
49 changes: 41 additions & 8 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::back::write::create_informational_target_machine;
use crate::{llvm, llvm_util};
use libc::c_int;
use libloading::Library;
use rustc_codegen_ssa::target_features::supported_target_features;
use rustc_data_structures::fx::FxHashSet;
use rustc_codegen_ssa::target_features::{supported_target_features, tied_target_features};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_fs_util::path_to_c_string;
use rustc_middle::bug;
use rustc_session::config::PrintRequest;
Expand Down Expand Up @@ -191,10 +191,30 @@ pub fn to_llvm_feature<'a>(sess: &Session, s: &'a str) -> Vec<&'a str> {
("aarch64", "frintts") => vec!["fptoint"],
("aarch64", "fcma") => vec!["complxnum"],
("aarch64", "pmuv3") => vec!["perfmon"],
("aarch64", "paca") => vec!["pauth"],
("aarch64", "pacg") => vec!["pauth"],
(_, s) => vec![s],
}
}

// Given a map from target_features to whether they are enabled or disabled,
// ensure only valid combinations are allowed.
pub fn check_tied_features(
sess: &Session,
features: &FxHashMap<&str, bool>,
) -> Option<&'static [&'static str]> {
for tied in tied_target_features(sess) {
// Tied features must be set to the same value, or not set at all
let mut tied_iter = tied.iter();
let enabled = features.get(tied_iter.next().unwrap());

if tied_iter.any(|f| enabled != features.get(f)) {
return Some(tied);
}
}
None
}

pub fn target_features(sess: &Session) -> Vec<Symbol> {
let target_machine = create_informational_target_machine(sess);
supported_target_features(sess)
Expand Down Expand Up @@ -395,15 +415,19 @@ pub fn llvm_global_features(sess: &Session) -> Vec<String> {
Some(_) | None => {}
};

fn strip(s: &str) -> &str {
s.strip_prefix(&['+', '-']).unwrap_or(s)
}

let filter = |s: &str| {
if s.is_empty() {
return vec![];
}
let feature = if s.starts_with('+') || s.starts_with('-') {
&s[1..]
} else {
let feature = strip(s);
if feature == s {
return vec![s.to_string()];
};
}

// Rustc-specific feature requests like `+crt-static` or `-crt-static`
// are not passed down to LLVM.
if RUSTC_SPECIFIC_FEATURES.contains(&feature) {
Expand All @@ -420,8 +444,17 @@ pub fn llvm_global_features(sess: &Session) -> Vec<String> {
features.extend(sess.target.features.split(',').flat_map(&filter));

// -Ctarget-features
features.extend(sess.opts.cg.target_feature.split(',').flat_map(&filter));

let feats: Vec<&str> = sess.opts.cg.target_feature.split(',').collect();
// LLVM enables based on the last occurence of a feature
if let Some(f) =
check_tied_features(sess, &feats.iter().map(|f| (strip(f), !f.starts_with("-"))).collect())
{
sess.err(&format!(
"Target features {} must all be enabled or disabled together",
f.join(", ")
));
}
features.extend(feats.iter().flat_map(|&f| filter(f)));
features
}

Expand Down
15 changes: 13 additions & 2 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ const AARCH64_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
("ssbs", Some(sym::aarch64_target_feature)),
// FEAT_SB
("sb", Some(sym::aarch64_target_feature)),
// FEAT_PAUTH
("pauth", Some(sym::aarch64_target_feature)),
// FEAT_PAUTH (address authentication)
("paca", Some(sym::aarch64_target_feature)),
// FEAT_PAUTH (generic authentication)
("pacg", Some(sym::aarch64_target_feature)),
// FEAT_DPB
("dpb", Some(sym::aarch64_target_feature)),
// FEAT_DPB2
Expand Down Expand Up @@ -137,6 +139,8 @@ const AARCH64_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
("v8.7a", Some(sym::aarch64_target_feature)),
];

const AARCH64_TIED_FEATURES: &[&[&str]] = &[&["paca", "pacg"]];

const X86_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
("adx", Some(sym::adx_target_feature)),
("aes", None),
Expand Down Expand Up @@ -256,6 +260,13 @@ pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Opt
}
}

pub fn tied_target_features(sess: &Session) -> &'static [&'static [&'static str]] {
match &*sess.target.arch {
"aarch64" => AARCH64_TIED_FEATURES,
_ => &[],
}
}

pub(crate) fn provide(providers: &mut Providers) {
providers.supported_target_features = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir/src/itemlikevisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{ForeignItem, ImplItem, Item, TraitItem};
///
/// 1. **Shallow visit**: Get a simple callback for every item (or item-like thing) in the HIR.
/// - Example: find all items with a `#[foo]` attribute on them.
/// - How: Implement `ItemLikeVisitor` and call `tcx.hir().krate().visit_all_item_likes()`.
/// - How: Implement `ItemLikeVisitor` and call `tcx.hir().visit_all_item_likes()`.
/// - Pro: Efficient; just walks the lists of item-like things, not the nodes themselves.
/// - Con: Don't get information about nesting
/// - Con: Don't have methods for specific bits of HIR, like "on
Expand All @@ -19,9 +19,9 @@ use super::{ForeignItem, ImplItem, Item, TraitItem};
/// - Example: Examine each expression to look for its type and do some check or other.
/// - How: Implement `intravisit::Visitor` and override the `nested_visit_map()` method
/// to return `NestedVisitorMap::OnlyBodies` and use
/// `tcx.hir().krate().visit_all_item_likes(&mut visitor.as_deep_visitor())`. Within
/// your `intravisit::Visitor` impl, implement methods like `visit_expr()` (don't forget
/// to invoke `intravisit::walk_expr()` to keep walking the subparts).
/// `tcx.hir().visit_all_item_likes(&mut visitor.as_deep_visitor())`. Within your
/// `intravisit::Visitor` impl, implement methods like `visit_expr()` (don't forget to invoke
/// `intravisit::walk_expr()` to keep walking the subparts).
/// - Pro: Visitor methods for any kind of HIR node, not just item-like things.
/// - Pro: Integrates well into dependency tracking.
/// - Con: Don't get information about nesting between items
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ pub fn configure_and_expand(
rustc_builtin_macros::register_builtin_macros(resolver);

krate = sess.time("crate_injection", || {
let alt_std_name = sess.opts.alt_std_name.as_ref().map(|s| Symbol::intern(s));
rustc_builtin_macros::standard_library_imports::inject(krate, resolver, sess, alt_std_name)
rustc_builtin_macros::standard_library_imports::inject(krate, resolver, sess)
});

util::check_attr_crate_type(sess, &krate.attrs, &mut resolver.lint_buffer());
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn get_stack_size() -> Option<usize> {
/// Like a `thread::Builder::spawn` followed by a `join()`, but avoids the need
/// for `'static` bounds.
#[cfg(not(parallel_compiler))]
pub fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f: F) -> R {
fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f: F) -> R {
// SAFETY: join() is called immediately, so any closure captures are still
// alive.
match unsafe { cfg.spawn_unchecked(f) }.unwrap().join() {
Expand Down Expand Up @@ -379,7 +379,7 @@ fn sysroot_candidates() -> Vec<PathBuf> {
}
}

pub fn get_codegen_sysroot(maybe_sysroot: &Option<PathBuf>, backend_name: &str) -> MakeBackendFn {
fn get_codegen_sysroot(maybe_sysroot: &Option<PathBuf>, backend_name: &str) -> MakeBackendFn {
// For now we only allow this function to be called once as it'll dlopen a
// few things, which seems to work best if we only do that once. In
// general this assertion never trips due to the once guard in `get_codegen_backend`,
Expand Down
38 changes: 19 additions & 19 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,28 +453,28 @@ impl<'a> Resolver<'a> {
// edit:
// only do this if the const and usage of the non-constant value are on the same line
// the further the two are apart, the higher the chance of the suggestion being wrong
// also make sure that the pos for the suggestion is not 0 (ICE #90878)

let sp =
self.session.source_map().span_extend_to_prev_str(ident.span, current, true);

let pos_for_suggestion = sp.lo().0.saturating_sub(current.len() as u32);
let sp = self
.session
.source_map()
.span_extend_to_prev_str(ident.span, current, true, false);

if sp.lo().0 == 0
|| pos_for_suggestion == 0
|| self.session.source_map().is_multiline(sp)
{
err.span_label(ident.span, &format!("this would need to be a `{}`", sugg));
} else {
let sp = sp.with_lo(BytePos(pos_for_suggestion));
err.span_suggestion(
sp,
&format!("consider using `{}` instead of `{}`", sugg, current),
format!("{} {}", sugg, ident),
Applicability::MaybeIncorrect,
);
err.span_label(span, "non-constant value");
match sp {
Some(sp) if !self.session.source_map().is_multiline(sp) => {
let sp = sp.with_lo(BytePos(sp.lo().0 - (current.len() as u32)));
err.span_suggestion(
sp,
&format!("consider using `{}` instead of `{}`", sugg, current),
format!("{} {}", sugg, ident),
Applicability::MaybeIncorrect,
);
err.span_label(span, "non-constant value");
}
_ => {
err.span_label(ident.span, &format!("this would need to be a `{}`", sugg));
}
}

err
}
ResolutionError::BindingShadowsSomethingUnacceptable {
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,6 @@ impl Default for Options {
externs: Externs(BTreeMap::new()),
extern_dep_specs: ExternDepSpecs(BTreeMap::new()),
crate_name: None,
alt_std_name: None,
libs: Vec::new(),
unstable_features: UnstableFeatures::Disallow,
debug_assertions: true,
Expand Down Expand Up @@ -2382,7 +2381,6 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
unstable_features: UnstableFeatures::from_environment(crate_name.as_deref()),
extern_dep_specs,
crate_name,
alt_std_name: None,
libs,
debug_assertions,
actually_rustdoc: false,
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ top_level_options!(
externs: Externs [UNTRACKED],
extern_dep_specs: ExternDepSpecs [UNTRACKED],
crate_name: Option<String> [TRACKED],
/// An optional name to use as the crate for std during std injection,
/// written `extern crate name as std`. Defaults to `std`. Used by
/// out-of-tree drivers.
alt_std_name: Option<String> [TRACKED],
/// Indicates how the compiler should treat unstable features.
unstable_features: UnstableFeatures [TRACKED],

Expand Down
40 changes: 27 additions & 13 deletions compiler/rustc_span/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,26 +629,41 @@ impl SourceMap {
}

/// Extends the given `Span` to just after the previous occurrence of `pat` when surrounded by
/// whitespace. Returns the same span if no character could be found or if an error occurred
/// while retrieving the code snippet.
pub fn span_extend_to_prev_str(&self, sp: Span, pat: &str, accept_newlines: bool) -> Span {
/// whitespace. Returns None if the pattern could not be found or if an error occurred while
/// retrieving the code snippet.
pub fn span_extend_to_prev_str(
&self,
sp: Span,
pat: &str,
accept_newlines: bool,
include_whitespace: bool,
) -> Option<Span> {
// assure that the pattern is delimited, to avoid the following
// fn my_fn()
// ^^^^ returned span without the check
// ---------- correct span
let prev_source = self.span_to_prev_source(sp).ok()?;
for ws in &[" ", "\t", "\n"] {
let pat = pat.to_owned() + ws;
if let Ok(prev_source) = self.span_to_prev_source(sp) {
let prev_source = prev_source.rsplit(&pat).next().unwrap_or("").trim_start();
if prev_source.is_empty() && sp.lo().0 != 0 {
return sp.with_lo(BytePos(sp.lo().0 - 1));
} else if accept_newlines || !prev_source.contains('\n') {
return sp.with_lo(BytePos(sp.lo().0 - prev_source.len() as u32));
if let Some(pat_pos) = prev_source.rfind(&pat) {
let just_after_pat_pos = pat_pos + pat.len() - 1;
let just_after_pat_plus_ws = if include_whitespace {
just_after_pat_pos
+ prev_source[just_after_pat_pos..]
.find(|c: char| !c.is_whitespace())
.unwrap_or(0)
} else {
just_after_pat_pos
};
let len = prev_source.len() - just_after_pat_plus_ws;
let prev_source = &prev_source[just_after_pat_plus_ws..];
if accept_newlines || !prev_source.trim_start().contains('\n') {
return Some(sp.with_lo(BytePos(sp.lo().0 - len as u32)));
}
}
}

sp
None
}

/// Returns the source snippet as `String` after the given `Span`.
Expand Down Expand Up @@ -927,7 +942,7 @@ impl SourceMap {
}

pub fn generate_fn_name_span(&self, span: Span) -> Option<Span> {
let prev_span = self.span_extend_to_prev_str(span, "fn", true);
let prev_span = self.span_extend_to_prev_str(span, "fn", true, true).unwrap_or(span);
if let Ok(snippet) = self.span_to_snippet(prev_span) {
debug!(
"generate_fn_name_span: span={:?}, prev_span={:?}, snippet={:?}",
Expand Down Expand Up @@ -968,8 +983,7 @@ impl SourceMap {
pub fn generate_local_type_param_snippet(&self, span: Span) -> Option<(Span, String)> {
// Try to extend the span to the previous "fn" keyword to retrieve the function
// signature.
let sugg_span = self.span_extend_to_prev_str(span, "fn", false);
if sugg_span != span {
if let Some(sugg_span) = self.span_extend_to_prev_str(span, "fn", false, true) {
if let Ok(snippet) = self.span_to_snippet(sugg_span) {
// Consume the function name.
let mut offset = snippet
Expand Down
Loading