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 #100797

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7913b85
unit tests that inspect LLVM output directly. This relies on a human …
pnkfelix Jun 16, 2022
b2777ab
End-to-end regression test for 97463.
pnkfelix Jun 6, 2022
8ae5a55
fix issue 97463 using change suggested by nbdd0121.
pnkfelix Jun 6, 2022
dfdb017
experiment: trying to encode the end-to-end test as a ui test via rus…
pnkfelix Jun 30, 2022
99c0f91
fix typo, thanks wesley
pnkfelix Aug 4, 2022
9bf3d5a
Ignore test on wasm
wesleywiser Aug 5, 2022
940f078
Add pointer masking convenience functions
WaffleLapkin May 11, 2022
876ff21
use shorter `ptr_mask` impl in cg cranelift
WaffleLapkin May 11, 2022
08d488b
Implement `ptr_mask` intrinsic in cg gcc
WaffleLapkin May 11, 2022
8102e71
Fix `ptr_mask` impl in cg gcc
WaffleLapkin May 13, 2022
729334a
fill in tracking issue for `feature(ptr_mask)`
WaffleLapkin Jun 20, 2022
1dfac52
fix cg cranelift
WaffleLapkin Aug 7, 2022
de9dc86
Add codegen test for `intinsics::ptr_mask`
WaffleLapkin Aug 8, 2022
ccc558a
make `ptr_mask` codegen test more specific
WaffleLapkin Aug 9, 2022
4b16214
Ban references to `Self` in trait object substs for projection predic…
cjgillot Aug 13, 2022
9233298
Revert "Revert "Allow dynamic linking for iOS/tvOS targets.""
cutsoy Aug 16, 2022
e9e46c9
Don't treat stashed warnings as errors
CAD97 Aug 17, 2022
767239f
Reenable early feature-gates as future-compat warnings
CAD97 Aug 17, 2022
944c6b6
New ui tests for new soft feature gates
CAD97 Aug 17, 2022
be2641a
Fortify check for const generics.
cjgillot Aug 17, 2022
72acd94
Add const-generics test.
cjgillot Aug 17, 2022
5abe2dc
Do not use void pointer for `ptr_mask` intrinsic
WaffleLapkin Aug 18, 2022
ac66baa
add miri-test-libstd support to libstd
RalfJung Aug 4, 2022
27b0444
add some Miri-only tests
RalfJung Aug 4, 2022
8c8dc12
make many std tests work in Miri
RalfJung Aug 4, 2022
438e49c
silence some unused-fn warnings in miri std builds
RalfJung Aug 6, 2022
fbcdf2a
clarify lib.rs attribute structure
RalfJung Aug 18, 2022
622e425
add a ui test for `.as_ref` suggestion
WaffleLapkin Aug 19, 2022
59cc718
Update codegen tests to accommodate the potential presence/absence of…
pnkfelix Aug 19, 2022
f47b61d
elaborate how revisions work with FileCheck stuff in src/test/codegen
pnkfelix Aug 19, 2022
9735107
remove unnecessary string searchings
TaKO8Ki Aug 20, 2022
b8f6983
Rollup merge of #96946 - WaffleLapkin:ptr_mask, r=scottmcm
matthiaskrgr Aug 20, 2022
ad2e624
Rollup merge of #97800 - pnkfelix:issue-97463-fix-aarch64-call-abi-do…
matthiaskrgr Aug 20, 2022
6c2ff7c
Rollup merge of #99935 - CAD97:unstable-syntax-lints, r=petrochenkov
matthiaskrgr Aug 20, 2022
80fa648
Rollup merge of #100129 - RalfJung:miri-test-libstd, r=thomcc
matthiaskrgr Aug 20, 2022
2038658
Rollup merge of #100500 - cjgillot:verify-self-predicate, r=lcnr
matthiaskrgr Aug 20, 2022
c4d57f5
Rollup merge of #100636 - cutsoy:revert-77716, r=davidtwco
matthiaskrgr Aug 20, 2022
e5b9afc
Rollup merge of #100773 - WaffleLapkin:addasreftest, r=TaKO8Ki
matthiaskrgr Aug 20, 2022
90ca06d
Rollup merge of #100777 - pnkfelix:expand-codegen-tests-readme, r=TaK…
matthiaskrgr Aug 20, 2022
959b876
Rollup merge of #100796 - TaKO8Ki:remove-unnecessary-string-searching…
matthiaskrgr Aug 20, 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
58 changes: 35 additions & 23 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use rustc_ast as ast;
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
use rustc_ast::{AssocConstraint, AssocConstraintKind, NodeId};
use rustc_ast::{PatKind, RangeEnd, VariantData};
use rustc_errors::{struct_span_err, Applicability};
use rustc_errors::{struct_span_err, Applicability, StashKey};
use rustc_feature::Features;
use rustc_feature::{AttributeGate, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
use rustc_feature::{Features, GateIssue};
use rustc_session::parse::{feature_err, feature_err_issue};
use rustc_session::parse::{feature_err, feature_warn};
use rustc_session::Session;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::sym;
Expand All @@ -20,9 +20,7 @@ macro_rules! gate_feature_fn {
let has_feature: bool = has_feature(visitor.features);
debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", name, span, has_feature);
if !has_feature && !span.allows_unstable($name) {
feature_err_issue(&visitor.sess.parse_sess, name, span, GateIssue::Language, explain)
.help(help)
.emit();
feature_err(&visitor.sess.parse_sess, name, span, explain).help(help).emit();
}
}};
($visitor: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr) => {{
Expand All @@ -31,8 +29,19 @@ macro_rules! gate_feature_fn {
let has_feature: bool = has_feature(visitor.features);
debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", name, span, has_feature);
if !has_feature && !span.allows_unstable($name) {
feature_err_issue(&visitor.sess.parse_sess, name, span, GateIssue::Language, explain)
.emit();
feature_err(&visitor.sess.parse_sess, name, span, explain).emit();
}
}};
(future_incompatible; $visitor: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr) => {{
let (visitor, has_feature, span, name, explain) =
(&*$visitor, $has_feature, $span, $name, $explain);
let has_feature: bool = has_feature(visitor.features);
debug!(
"gate_feature(feature = {:?}, span = {:?}); has? {} (future_incompatible)",
name, span, has_feature
);
if !has_feature && !span.allows_unstable($name) {
feature_warn(&visitor.sess.parse_sess, name, span, explain);
}
}};
}
Expand All @@ -44,6 +53,9 @@ macro_rules! gate_feature_post {
($visitor: expr, $feature: ident, $span: expr, $explain: expr) => {
gate_feature_fn!($visitor, |x: &Features| x.$feature, $span, sym::$feature, $explain)
};
(future_incompatible; $visitor: expr, $feature: ident, $span: expr, $explain: expr) => {
gate_feature_fn!(future_incompatible; $visitor, |x: &Features| x.$feature, $span, sym::$feature, $explain)
};
}

pub fn check_attribute(attr: &ast::Attribute, sess: &Session, features: &Features) {
Expand Down Expand Up @@ -588,11 +600,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
{
// When we encounter a statement of the form `foo: Ty = val;`, this will emit a type
// ascription error, but the likely intention was to write a `let` statement. (#78907).
feature_err_issue(
feature_err(
&self.sess.parse_sess,
sym::type_ascription,
lhs.span,
GateIssue::Language,
"type ascription is experimental",
).span_suggestion_verbose(
lhs.span.shrink_to_lo(),
Expand All @@ -615,15 +626,22 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
);
}
ast::ExprKind::Type(..) => {
// To avoid noise about type ascription in common syntax errors, only emit if it
// is the *only* error.
if self.sess.parse_sess.span_diagnostic.err_count() == 0 {
// To avoid noise about type ascription in common syntax errors,
// only emit if it is the *only* error.
gate_feature_post!(
&self,
type_ascription,
e.span,
"type ascription is experimental"
);
} else {
// And if it isn't, cancel the early-pass warning.
self.sess
.parse_sess
.span_diagnostic
.steal_diagnostic(e.span, StashKey::EarlySyntaxWarning)
.map(|err| err.cancel());
}
}
ast::ExprKind::TryBlock(_) => {
Expand Down Expand Up @@ -789,14 +807,12 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {

// All uses of `gate_all!` below this point were added in #65742,
// and subsequently disabled (with the non-early gating readded).
// We emit an early future-incompatible warning for these.
// New syntax gates should go above here to get a hard error gate.
macro_rules! gate_all {
($gate:ident, $msg:literal) => {
// FIXME(eddyb) do something more useful than always
// disabling these uses of early feature-gatings.
if false {
for span in spans.get(&sym::$gate).unwrap_or(&vec![]) {
gate_feature_post!(&visitor, $gate, *span, $msg);
}
for span in spans.get(&sym::$gate).unwrap_or(&vec![]) {
gate_feature_post!(future_incompatible; &visitor, $gate, *span, $msg);
}
};
}
Expand All @@ -809,11 +825,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
gate_all!(try_blocks, "`try` blocks are unstable");
gate_all!(label_break_value, "labels on blocks are unstable");
gate_all!(box_syntax, "box expression syntax is experimental; you can call `Box::new` instead");
// To avoid noise about type ascription in common syntax errors,
// only emit if it is the *only* error. (Also check it last.)
if sess.parse_sess.span_diagnostic.err_count() == 0 {
gate_all!(type_ascription, "type ascription is experimental");
}
gate_all!(type_ascription, "type ascription is experimental");

visit::walk_crate(&mut visitor, krate);
}
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
ret.write_cvalue(fx, CValue::by_val(res, base.layout()));
}

sym::ptr_mask => {
intrinsic_args!(fx, args => (ptr, mask); intrinsic);
let ptr = ptr.load_scalar(fx);
let mask = mask.load_scalar(fx);
fx.bcx.ins().band(ptr, mask);
}

sym::transmute => {
intrinsic_args!(fx, args => (from); intrinsic);

Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_codegen_gcc/src/intrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,18 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
return;
}

sym::ptr_mask => {
let usize_type = self.context.new_type::<usize>();
let void_ptr_type = self.context.new_type::<*const ()>();

let ptr = args[0].immediate();
let mask = args[1].immediate();

let addr = self.bitcast(ptr, usize_type);
let masked = self.and(addr, mask);
self.bitcast(masked, void_ptr_type)
},

_ if name_str.starts_with("simd_") => {
match generic_simd_intrinsic(self, name, callee_ty, args, ret_ty, llret_ty, span) {
Ok(llval) => llval,
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,9 @@ impl<'ll> CodegenCx<'ll, '_> {
ifn!("llvm.dbg.declare", fn(t_metadata, t_metadata) -> void);
ifn!("llvm.dbg.value", fn(t_metadata, t_i64, t_metadata) -> void);
}

ifn!("llvm.ptrmask", fn(i8p, t_isize) -> i8p);

None
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ fn get_simple_intrinsic<'ll>(
sym::nearbyintf64 => "llvm.nearbyint.f64",
sym::roundf32 => "llvm.round.f32",
sym::roundf64 => "llvm.round.f64",
sym::ptr_mask => "llvm.ptrmask",
_ => return None,
};
Some(cx.get_intrinsic(llvm_name))
Expand Down
75 changes: 63 additions & 12 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ struct HandlerInner {
pub enum StashKey {
ItemNoType,
UnderscoreForArrayLengths,
EarlySyntaxWarning,
}

fn default_track_diagnostic(_: &Diagnostic) {}
Expand Down Expand Up @@ -626,19 +627,13 @@ impl Handler {
/// Stash a given diagnostic with the given `Span` and `StashKey` as the key for later stealing.
pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: Diagnostic) {
let mut inner = self.inner.borrow_mut();
// FIXME(Centril, #69537): Consider reintroducing panic on overwriting a stashed diagnostic
// if/when we have a more robust macro-friendly replacement for `(span, key)` as a key.
// See the PR for a discussion.
inner.stashed_diagnostics.insert((span, key), diag);
inner.stash((span, key), diag);
}

/// Steal a previously stashed diagnostic with the given `Span` and `StashKey` as the key.
pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option<DiagnosticBuilder<'_, ()>> {
self.inner
.borrow_mut()
.stashed_diagnostics
.remove(&(span, key))
.map(|diag| DiagnosticBuilder::new_diagnostic(self, diag))
let mut inner = self.inner.borrow_mut();
inner.steal((span, key)).map(|diag| DiagnosticBuilder::new_diagnostic(self, diag))
}

/// Emit all stashed diagnostics.
Expand Down Expand Up @@ -1106,13 +1101,31 @@ impl HandlerInner {

/// Emit all stashed diagnostics.
fn emit_stashed_diagnostics(&mut self) -> Option<ErrorGuaranteed> {
let has_errors = self.has_errors();
let diags = self.stashed_diagnostics.drain(..).map(|x| x.1).collect::<Vec<_>>();
let mut reported = None;
for mut diag in diags {
// Decrement the count tracking the stash; emitting will increment it.
if diag.is_error() {
reported = Some(ErrorGuaranteed(()));
if matches!(diag.level, Level::Error { lint: true }) {
self.lint_err_count -= 1;
} else {
self.err_count -= 1;
}
} else {
if diag.is_force_warn() {
self.warn_count -= 1;
} else {
// Unless they're forced, don't flush stashed warnings when
// there are errors, to avoid causing warning overload. The
// stash would've been stolen already if it were important.
if has_errors {
continue;
}
}
}
self.emit_diagnostic(&mut diag);
let reported_this = self.emit_diagnostic(&mut diag);
reported = reported.or(reported_this);
}
reported
}
Expand Down Expand Up @@ -1302,9 +1315,47 @@ impl HandlerInner {
}
}

fn stash(&mut self, key: (Span, StashKey), diagnostic: Diagnostic) {
// Track the diagnostic for counts, but don't panic-if-treat-err-as-bug
// yet; that happens when we actually emit the diagnostic.
if diagnostic.is_error() {
if matches!(diagnostic.level, Level::Error { lint: true }) {
self.lint_err_count += 1;
} else {
self.err_count += 1;
}
} else {
// Warnings are only automatically flushed if they're forced.
if diagnostic.is_force_warn() {
self.warn_count += 1;
}
}

// FIXME(Centril, #69537): Consider reintroducing panic on overwriting a stashed diagnostic
// if/when we have a more robust macro-friendly replacement for `(span, key)` as a key.
// See the PR for a discussion.
self.stashed_diagnostics.insert(key, diagnostic);
}

fn steal(&mut self, key: (Span, StashKey)) -> Option<Diagnostic> {
let diagnostic = self.stashed_diagnostics.remove(&key)?;
if diagnostic.is_error() {
if matches!(diagnostic.level, Level::Error { lint: true }) {
self.lint_err_count -= 1;
} else {
self.err_count -= 1;
}
} else {
if diagnostic.is_force_warn() {
self.warn_count -= 1;
}
}
Some(diagnostic)
}

#[inline]
fn err_count(&self) -> usize {
self.err_count + self.stashed_diagnostics.len()
self.err_count
}

fn has_errors(&self) -> bool {
Expand Down
51 changes: 51 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3212,6 +3212,56 @@ declare_lint! {
};
}

declare_lint! {
/// The `unstable_syntax_pre_expansion` lint detects the use of unstable
/// syntax that is discarded during attribute expansion.
///
/// ### Example
///
/// ```rust
/// #[cfg(FALSE)]
/// macro foo() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The input to active attributes such as `#[cfg]` or procedural macro
/// attributes is required to be valid syntax. Previously, the compiler only
/// gated the use of unstable syntax features after resolving `#[cfg]` gates
/// and expanding procedural macros.
///
/// To avoid relying on unstable syntax, move the use of unstable syntax
/// into a position where the compiler does not parse the syntax, such as a
/// functionlike macro.
///
/// ```rust
/// # #![deny(unstable_syntax_pre_expansion)]
///
/// macro_rules! identity {
/// ( $($tokens:tt)* ) => { $($tokens)* }
/// }
///
/// #[cfg(FALSE)]
/// identity! {
/// macro foo() {}
/// }
/// ```
///
/// This is a [future-incompatible] lint to transition this
/// to a hard error in the future. See [issue #65860] for more details.
///
/// [issue #65860]: https://github.com/rust-lang/rust/issues/65860
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub UNSTABLE_SYNTAX_PRE_EXPANSION,
Warn,
"unstable syntax can change at any point in the future, causing a hard error!",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #65860 <https://github.com/rust-lang/rust/issues/65860>",
};
}

declare_lint_pass! {
/// Does nothing as a lint pass, but registers some `Lint`s
/// that are used by other parts of the compiler.
Expand Down Expand Up @@ -3280,6 +3330,7 @@ declare_lint_pass! {
POINTER_STRUCTURAL_MATCH,
NONTRIVIAL_STRUCTURAL_MATCH,
SOFT_UNSTABLE,
UNSTABLE_SYNTAX_PRE_EXPANSION,
INLINE_NO_SANITIZE,
BAD_ASM_STYLE,
ASM_SUB_REGISTER,
Expand Down
Loading