Skip to content

Commit 1c7d10e

Browse files
committed
Auto merge of rust-lang#127004 - matthiaskrgr:rollup-gft2hqv, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#125016 (Update compiler_builtins to 0.1.113) - rust-lang#126571 (Less `maybe_whole_expr`, take 2) - rust-lang#126692 (patch `rust-lld` and `ld.lld` on NixOS) - rust-lang#126721 (coverage: Make `#[coverage(..)]` apply recursively to nested functions) - rust-lang#126928 (Some `Nonterminal` removal precursors) - rust-lang#126929 (Remove `__rust_force_expr`.) - rust-lang#126970 (Simplify `str::clone_into`) - rust-lang#126980 (set self.is_known_utf8 to false in extend_from_slice) - rust-lang#126983 (Remove `f16` and `f128` ICE paths from smir) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4bc39f0 + 30c64d8 commit 1c7d10e

File tree

48 files changed

+595
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+595
-424
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -794,9 +794,9 @@ checksum = "55b672471b4e9f9e95499ea597ff64941a309b2cdbffcc46f2cc5e2d971fd335"
794794

795795
[[package]]
796796
name = "compiler_builtins"
797-
version = "0.1.109"
797+
version = "0.1.113"
798798
source = "registry+https://github.com/rust-lang/crates.io-index"
799-
checksum = "f11973008a8cf741fe6d22f339eba21fd0ca81e2760a769ba8243ed6c21edd7e"
799+
checksum = "f7a6025b8e1885a239509ec7a00859e721eecb5725a64206ab1a6a96f7b55660"
800800
dependencies = [
801801
"cc",
802802
"rustc-std-workspace-core",

compiler/rustc_ast/src/attr/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ impl MetaItem {
327327
I: Iterator<Item = &'a TokenTree>,
328328
{
329329
// FIXME: Share code with `parse_path`.
330-
let path = match tokens.next().map(|tt| TokenTree::uninterpolate(tt)).as_deref() {
330+
let tt = tokens.next().map(|tt| TokenTree::uninterpolate(tt));
331+
let path = match tt.as_deref() {
331332
Some(&TokenTree::Token(
332333
Token { kind: ref kind @ (token::Ident(..) | token::PathSep), span },
333334
_,
@@ -368,6 +369,12 @@ impl MetaItem {
368369
token::Nonterminal::NtPath(path) => (**path).clone(),
369370
_ => return None,
370371
},
372+
Some(TokenTree::Token(
373+
Token { kind: token::OpenDelim(_) | token::CloseDelim(_), .. },
374+
_,
375+
)) => {
376+
panic!("Should be `AttrTokenTree::Delimited`, not delim tokens: {:?}", tt);
377+
}
371378
_ => return None,
372379
};
373380
let list_closing_paren_pos = tokens.peek().map(|tt| tt.span().hi());

compiler/rustc_ast/src/tokenstream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl AttrTokenStream {
224224
// Inner attributes are only supported on extern blocks, functions,
225225
// impls, and modules. All of these have their inner attributes
226226
// placed at the beginning of the rightmost outermost braced group:
227-
// e.g. fn foo() { #![my_attr} }
227+
// e.g. fn foo() { #![my_attr] }
228228
//
229229
// Therefore, we can insert them back into the right location
230230
// without needing to do any extra position tracking.

compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ fn build_clif_sysroot_for_triple(
276276
if channel == "release" {
277277
build_cmd.arg("--release");
278278
}
279-
build_cmd.arg("--features").arg("backtrace panic-unwind");
279+
build_cmd.arg("--features").arg("backtrace panic-unwind compiler-builtins-no-f16-f128");
280280
build_cmd.env("CARGO_PROFILE_RELEASE_DEBUG", "true");
281281
build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
282282
if compiler.triple.contains("apple") {

compiler/rustc_codegen_gcc/build_system/src/build.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,14 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
112112
}
113113
let mut env = env.clone();
114114

115-
let mut args: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"build", &"--target", &config.target];
115+
let mut args: Vec<&dyn AsRef<OsStr>> = vec![
116+
&"cargo",
117+
&"build",
118+
&"--target",
119+
&config.target,
120+
&"--features",
121+
&"compiler-builtins-no-f16-f128",
122+
];
116123

117124
if config.no_default_features {
118125
rustflags.push_str(" -Csymbol-mangling-version=v0");

compiler/rustc_codegen_llvm/src/abi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ impl LlvmType for Reg {
121121
match self.kind {
122122
RegKind::Integer => cx.type_ix(self.size.bits()),
123123
RegKind::Float => match self.size.bits() {
124+
16 => cx.type_f16(),
124125
32 => cx.type_f32(),
125126
64 => cx.type_f64(),
127+
128 => cx.type_f128(),
126128
_ => bug!("unsupported float: {:?}", self),
127129
},
128130
RegKind::Vector => cx.type_vector(cx.type_i8(), self.size.bytes()),

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

-17
Original file line numberDiff line numberDiff line change
@@ -124,22 +124,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
124124
.emit();
125125
}
126126
}
127-
sym::coverage => {
128-
let inner = attr.meta_item_list();
129-
match inner.as_deref() {
130-
Some([item]) if item.has_name(sym::off) => {
131-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE;
132-
}
133-
Some([item]) if item.has_name(sym::on) => {
134-
// Allow #[coverage(on)] for being explicit, maybe also in future to enable
135-
// coverage on a smaller scope within an excluded larger scope.
136-
}
137-
Some(_) | None => {
138-
tcx.dcx()
139-
.span_delayed_bug(attr.span, "unexpected value of coverage attribute");
140-
}
141-
}
142-
}
143127
sym::rustc_std_internal_symbol => {
144128
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL
145129
}
@@ -584,7 +568,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
584568
}
585569

586570
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
587-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE;
588571
codegen_fn_attrs.inline = InlineAttr::Never;
589572
}
590573

compiler/rustc_expand/src/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ impl<'a> StripUnconfigured<'a> {
214214
) => {
215215
panic!("Nonterminal should have been flattened: {:?}", tree);
216216
}
217+
AttrTokenTree::Token(
218+
Token { kind: TokenKind::OpenDelim(_) | TokenKind::CloseDelim(_), .. },
219+
_,
220+
) => {
221+
panic!("Should be `AttrTokenTree::Delimited`, not delim tokens: {:?}", tree);
222+
}
217223
AttrTokenTree::Token(token, spacing) => {
218224
Some(AttrTokenTree::Token(token, spacing)).into_iter()
219225
}

compiler/rustc_middle/src/middle/codegen_fn_attrs.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ bitflags::bitflags! {
8787
/// #[cmse_nonsecure_entry]: with a TrustZone-M extension, declare a
8888
/// function as an entry function from Non-Secure code.
8989
const CMSE_NONSECURE_ENTRY = 1 << 13;
90-
/// `#[coverage(off)]`: indicates that the function should be ignored by
91-
/// the MIR `InstrumentCoverage` pass and not added to the coverage map
92-
/// during codegen.
93-
const NO_COVERAGE = 1 << 14;
90+
// (Bit 14 was used for `#[coverage(off)]`, but is now unused.)
9491
/// `#[used(linker)]`:
9592
/// indicates that neither LLVM nor the linker will eliminate this function.
9693
const USED_LINKER = 1 << 15;

compiler/rustc_middle/src/query/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,15 @@ rustc_queries! {
572572
separate_provide_extern
573573
}
574574

575+
/// Checks for the nearest `#[coverage(off)]` or `#[coverage(on)]` on
576+
/// this def and any enclosing defs, up to the crate root.
577+
///
578+
/// Returns `false` if `#[coverage(off)]` was found, or `true` if
579+
/// either `#[coverage(on)]` or no coverage attribute was found.
580+
query coverage_attr_on(key: LocalDefId) -> bool {
581+
desc { |tcx| "checking for `#[coverage(..)]` on `{}`", tcx.def_path_str(key) }
582+
}
583+
575584
/// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass
576585
/// (for compiler option `-Cinstrument-coverage`), after MIR optimizations
577586
/// have had a chance to potentially remove some of them.

compiler/rustc_mir_transform/src/coverage/query.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ use rustc_middle::query::TyCtxtAt;
66
use rustc_middle::ty::{self, TyCtxt};
77
use rustc_middle::util::Providers;
88
use rustc_span::def_id::LocalDefId;
9+
use rustc_span::sym;
910

1011
/// Registers query/hook implementations related to coverage.
1112
pub(crate) fn provide(providers: &mut Providers) {
1213
providers.hooks.is_eligible_for_coverage =
1314
|TyCtxtAt { tcx, .. }, def_id| is_eligible_for_coverage(tcx, def_id);
15+
providers.queries.coverage_attr_on = coverage_attr_on;
1416
providers.queries.coverage_ids_info = coverage_ids_info;
1517
}
1618

@@ -38,14 +40,43 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
3840
return false;
3941
}
4042

41-
if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::NO_COVERAGE) {
43+
if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::NAKED) {
44+
trace!("InstrumentCoverage skipped for {def_id:?} (`#[naked]`)");
45+
return false;
46+
}
47+
48+
if !tcx.coverage_attr_on(def_id) {
4249
trace!("InstrumentCoverage skipped for {def_id:?} (`#[coverage(off)]`)");
4350
return false;
4451
}
4552

4653
true
4754
}
4855

56+
/// Query implementation for `coverage_attr_on`.
57+
fn coverage_attr_on(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
58+
// Check for annotations directly on this def.
59+
if let Some(attr) = tcx.get_attr(def_id, sym::coverage) {
60+
match attr.meta_item_list().as_deref() {
61+
Some([item]) if item.has_name(sym::off) => return false,
62+
Some([item]) if item.has_name(sym::on) => return true,
63+
Some(_) | None => {
64+
// Other possibilities should have been rejected by `rustc_parse::validate_attr`.
65+
tcx.dcx().span_bug(attr.span, "unexpected value of coverage attribute");
66+
}
67+
}
68+
}
69+
70+
match tcx.opt_local_parent(def_id) {
71+
// Check the parent def (and so on recursively) until we find an
72+
// enclosing attribute or reach the crate root.
73+
Some(parent) => tcx.coverage_attr_on(parent),
74+
// We reached the crate root without seeing a coverage attribute, so
75+
// allow coverage instrumentation by default.
76+
None => true,
77+
}
78+
}
79+
4980
/// Query implementation for `coverage_ids_info`.
5081
fn coverage_ids_info<'tcx>(
5182
tcx: TyCtxt<'tcx>,

compiler/rustc_parse/src/parser/expr.rs

+41-32
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,6 @@ use rustc_span::{BytePos, ErrorGuaranteed, Pos, Span};
3939
use thin_vec::{thin_vec, ThinVec};
4040
use tracing::instrument;
4141

42-
/// Possibly accepts an `token::Interpolated` expression (a pre-parsed expression
43-
/// dropped into the token stream, which happens while parsing the result of
44-
/// macro expansion). Placement of these is not as complex as I feared it would
45-
/// be. The important thing is to make sure that lookahead doesn't balk at
46-
/// `token::Interpolated` tokens.
47-
macro_rules! maybe_whole_expr {
48-
($p:expr) => {
49-
if let token::Interpolated(nt) = &$p.token.kind {
50-
match &**nt {
51-
token::NtExpr(e) | token::NtLiteral(e) => {
52-
let e = e.clone();
53-
$p.bump();
54-
return Ok(e);
55-
}
56-
token::NtPath(path) => {
57-
let path = (**path).clone();
58-
$p.bump();
59-
return Ok($p.mk_expr($p.prev_token.span, ExprKind::Path(None, path)));
60-
}
61-
token::NtBlock(block) => {
62-
let block = block.clone();
63-
$p.bump();
64-
return Ok($p.mk_expr($p.prev_token.span, ExprKind::Block(block, None)));
65-
}
66-
_ => {}
67-
};
68-
}
69-
};
70-
}
71-
7242
#[derive(Debug)]
7343
pub(super) enum LhsExpr {
7444
// Already parsed just the outer attributes.
@@ -1421,7 +1391,27 @@ impl<'a> Parser<'a> {
14211391
/// correctly if called from `parse_dot_or_call_expr()`.
14221392
fn parse_expr_bottom(&mut self) -> PResult<'a, P<Expr>> {
14231393
maybe_recover_from_interpolated_ty_qpath!(self, true);
1424-
maybe_whole_expr!(self);
1394+
1395+
if let token::Interpolated(nt) = &self.token.kind {
1396+
match &**nt {
1397+
token::NtExpr(e) | token::NtLiteral(e) => {
1398+
let e = e.clone();
1399+
self.bump();
1400+
return Ok(e);
1401+
}
1402+
token::NtPath(path) => {
1403+
let path = (**path).clone();
1404+
self.bump();
1405+
return Ok(self.mk_expr(self.prev_token.span, ExprKind::Path(None, path)));
1406+
}
1407+
token::NtBlock(block) => {
1408+
let block = block.clone();
1409+
self.bump();
1410+
return Ok(self.mk_expr(self.prev_token.span, ExprKind::Block(block, None)));
1411+
}
1412+
_ => {}
1413+
};
1414+
}
14251415

14261416
// Outer attributes are already parsed and will be
14271417
// added to the return value after the fact.
@@ -2190,7 +2180,26 @@ impl<'a> Parser<'a> {
21902180
/// Matches `'-' lit | lit` (cf. `ast_validation::AstValidator::check_expr_within_pat`).
21912181
/// Keep this in sync with `Token::can_begin_literal_maybe_minus`.
21922182
pub fn parse_literal_maybe_minus(&mut self) -> PResult<'a, P<Expr>> {
2193-
maybe_whole_expr!(self);
2183+
if let token::Interpolated(nt) = &self.token.kind {
2184+
match &**nt {
2185+
// FIXME(nnethercote) The `NtExpr` case should only match if
2186+
// `e` is an `ExprKind::Lit` or an `ExprKind::Unary` containing
2187+
// an `UnOp::Neg` and an `ExprKind::Lit`, like how
2188+
// `can_begin_literal_maybe_minus` works. But this method has
2189+
// been over-accepting for a long time, and to make that change
2190+
// here requires also changing some `parse_literal_maybe_minus`
2191+
// call sites to accept additional expression kinds. E.g.
2192+
// `ExprKind::Path` must be accepted when parsing range
2193+
// patterns. That requires some care. So for now, we continue
2194+
// being less strict here than we should be.
2195+
token::NtExpr(e) | token::NtLiteral(e) => {
2196+
let e = e.clone();
2197+
self.bump();
2198+
return Ok(e);
2199+
}
2200+
_ => {}
2201+
};
2202+
}
21942203

21952204
let lo = self.token.span;
21962205
let minus_present = self.eat(&token::BinOp(token::Minus));

compiler/rustc_passes/src/check_attr.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,16 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
369369
}
370370
}
371371

372-
/// Checks that `#[coverage(..)]` is applied to a function or closure.
372+
/// Checks that `#[coverage(..)]` is applied to a function/closure/method,
373+
/// or to an impl block or module.
373374
fn check_coverage(&self, attr: &Attribute, span: Span, target: Target) -> bool {
374375
match target {
375-
// #[coverage(..)] on function is fine
376376
Target::Fn
377377
| Target::Closure
378-
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,
378+
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent)
379+
| Target::Impl
380+
| Target::Mod => true,
381+
379382
_ => {
380383
self.dcx().emit_err(errors::CoverageNotFnOrClosure {
381384
attr_span: attr.span,

compiler/rustc_smir/src/rustc_internal/internal.rs

+2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,10 @@ impl RustcInternal for FloatTy {
188188

189189
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
190190
match self {
191+
FloatTy::F16 => rustc_ty::FloatTy::F16,
191192
FloatTy::F32 => rustc_ty::FloatTy::F32,
192193
FloatTy::F64 => rustc_ty::FloatTy::F64,
194+
FloatTy::F128 => rustc_ty::FloatTy::F128,
193195
}
194196
}
195197
}

compiler/rustc_smir/src/rustc_smir/convert/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ impl<'tcx> Stable<'tcx> for ty::FloatTy {
304304

305305
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
306306
match self {
307-
ty::FloatTy::F16 => unimplemented!("f16_f128"),
307+
ty::FloatTy::F16 => FloatTy::F16,
308308
ty::FloatTy::F32 => FloatTy::F32,
309309
ty::FloatTy::F64 => FloatTy::F64,
310-
ty::FloatTy::F128 => unimplemented!("f16_f128"),
310+
ty::FloatTy::F128 => FloatTy::F128,
311311
}
312312
}
313313
}

compiler/rustc_target/src/abi/call/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,10 @@ impl Reg {
237237
_ => panic!("unsupported integer: {self:?}"),
238238
},
239239
RegKind::Float => match self.size.bits() {
240+
16 => dl.f16_align.abi,
240241
32 => dl.f32_align.abi,
241242
64 => dl.f64_align.abi,
243+
128 => dl.f128_align.abi,
242244
_ => panic!("unsupported float: {self:?}"),
243245
},
244246
RegKind::Vector => dl.vector_align(self.size).abi,

compiler/stable_mir/src/ty.rs

+2
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,10 @@ impl UintTy {
608608

609609
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
610610
pub enum FloatTy {
611+
F16,
611612
F32,
612613
F64,
614+
F128,
613615
}
614616

615617
#[derive(Clone, Copy, Debug, PartialEq, Eq)]

library/alloc/Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ edition = "2021"
1010

1111
[dependencies]
1212
core = { path = "../core" }
13-
compiler_builtins = { version = "0.1.40", features = ['rustc-dep-of-std'] }
13+
compiler_builtins = { version = "0.1.113", features = ['rustc-dep-of-std'] }
14+
15+
[target.'cfg(not(any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")))'.dependencies]
16+
compiler_builtins = { version = "0.1.113", features = ["no-f16-f128"] }
1417

1518
[dev-dependencies]
1619
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
@@ -38,8 +41,8 @@ harness = false
3841
compiler-builtins-mem = ['compiler_builtins/mem']
3942
compiler-builtins-c = ["compiler_builtins/c"]
4043
compiler-builtins-no-asm = ["compiler_builtins/no-asm"]
44+
compiler-builtins-no-f16-f128 = ["compiler_builtins/no-f16-f128"]
4145
compiler-builtins-mangled-names = ["compiler_builtins/mangled-names"]
42-
compiler-builtins-weak-intrinsics = ["compiler_builtins/weak-intrinsics"]
4346
# Make panics and failed asserts immediately abort without formatting any message
4447
panic_immediate_abort = ["core/panic_immediate_abort"]
4548
# Choose algorithms that are optimized for binary size instead of runtime performance

0 commit comments

Comments
 (0)