Skip to content

Commit 21627d6

Browse files
committed
Auto merge of rust-lang#116175 - matthiaskrgr:rollup-cwteiwy, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#116099 (Add regression test for issue rust-lang#79865) - rust-lang#116131 (Rename `cold_path` to `outline`) - rust-lang#116151 (Fix typo in rustdoc unstable features doc) - rust-lang#116153 (Update books) - rust-lang#116162 (Gate and validate `#[rustc_safe_intrinsic]`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1f2bacf + 6f4a0a1 commit 21627d6

File tree

26 files changed

+135
-31
lines changed

26 files changed

+135
-31
lines changed

compiler/rustc_arena/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ use std::ptr::{self, NonNull};
3737
use std::slice;
3838
use std::{cmp, intrinsics};
3939

40+
/// This calls the passed function while ensuring it won't be inlined into the caller.
4041
#[inline(never)]
4142
#[cold]
42-
fn cold_path<F: FnOnce() -> R, R>(f: F) -> R {
43+
fn outline<F: FnOnce() -> R, R>(f: F) -> R {
4344
f()
4445
}
4546

@@ -600,7 +601,7 @@ impl DroplessArena {
600601
unsafe { self.write_from_iter(iter, len, mem) }
601602
}
602603
(_, _) => {
603-
cold_path(move || -> &mut [T] {
604+
outline(move || -> &mut [T] {
604605
let mut vec: SmallVec<[_; 8]> = iter.collect();
605606
if vec.is_empty() {
606607
return &mut [];

compiler/rustc_data_structures/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ use std::fmt;
5151

5252
pub use rustc_index::static_assert_size;
5353

54+
/// This calls the passed function while ensuring it won't be inlined into the caller.
5455
#[inline(never)]
5556
#[cold]
56-
pub fn cold_path<F: FnOnce() -> R, R>(f: F) -> R {
57+
pub fn outline<F: FnOnce() -> R, R>(f: F) -> R {
5758
f()
5859
}
5960

compiler/rustc_data_structures/src/profiling.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181
//!
8282
//! [mm]: https://github.com/rust-lang/measureme/
8383
84-
use crate::cold_path;
8584
use crate::fx::FxHashMap;
85+
use crate::outline;
8686

8787
use std::borrow::Borrow;
8888
use std::collections::hash_map::Entry;
@@ -697,7 +697,7 @@ impl<'a> TimingGuard<'a> {
697697
#[inline]
698698
pub fn finish_with_query_invocation_id(self, query_invocation_id: QueryInvocationId) {
699699
if let Some(guard) = self.0 {
700-
cold_path(|| {
700+
outline(|| {
701701
let event_id = StringId::new_virtual(query_invocation_id.0);
702702
let event_id = EventId::from_virtual(event_id);
703703
guard.finish_with_override_event_id(event_id);

compiler/rustc_data_structures/src/sync/worker_local.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::ptr;
66
use std::sync::Arc;
77

88
#[cfg(parallel_compiler)]
9-
use {crate::cold_path, crate::sync::CacheAligned};
9+
use {crate::outline, crate::sync::CacheAligned};
1010

1111
/// A pointer to the `RegistryData` which uniquely identifies a registry.
1212
/// This identifier can be reused if the registry gets freed.
@@ -25,11 +25,7 @@ impl RegistryId {
2525
fn verify(self) -> usize {
2626
let (id, index) = THREAD_DATA.with(|data| (data.registry_id.get(), data.index.get()));
2727

28-
if id == self {
29-
index
30-
} else {
31-
cold_path(|| panic!("Unable to verify registry association"))
32-
}
28+
if id == self { index } else { outline(|| panic!("Unable to verify registry association")) }
3329
}
3430
}
3531

compiler/rustc_error_codes/src/error_codes/E0094.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ An invalid number of generic parameters was passed to an intrinsic function.
33
Erroneous code example:
44

55
```compile_fail,E0094
6-
#![feature(intrinsics)]
6+
#![feature(intrinsics, rustc_attrs)]
77
#![allow(internal_features)]
88
99
extern "rust-intrinsic" {
@@ -18,7 +18,7 @@ and verify with the function declaration in the Rust source code.
1818
Example:
1919

2020
```
21-
#![feature(intrinsics)]
21+
#![feature(intrinsics, rustc_attrs)]
2222
#![allow(internal_features)]
2323
2424
extern "rust-intrinsic" {

compiler/rustc_error_codes/src/error_codes/E0211.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You used a function or type which doesn't fit the requirements for where it was
44
used. Erroneous code examples:
55

66
```compile_fail
7-
#![feature(intrinsics)]
7+
#![feature(intrinsics, rustc_attrs)]
88
#![allow(internal_features)]
99
1010
extern "rust-intrinsic" {
@@ -41,7 +41,7 @@ impl Foo {
4141
For the first code example, please check the function definition. Example:
4242

4343
```
44-
#![feature(intrinsics)]
44+
#![feature(intrinsics, rustc_attrs)]
4545
#![allow(internal_features)]
4646
4747
extern "rust-intrinsic" {

compiler/rustc_feature/src/builtin_attrs.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
537537
allow_internal_unsafe, Normal, template!(Word), WarnFollowing,
538538
"allow_internal_unsafe side-steps the unsafe_code lint",
539539
),
540-
ungated!(rustc_safe_intrinsic, Normal, template!(Word), DuplicatesOk),
541540
rustc_attr!(rustc_allowed_through_unstable_modules, Normal, template!(Word), WarnFollowing,
542541
"rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \
543542
through unstable paths"),
@@ -806,6 +805,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
806805
rustc_doc_primitive, Normal, template!(NameValueStr: "primitive name"), ErrorFollowing,
807806
r#"`rustc_doc_primitive` is a rustc internal attribute"#,
808807
),
808+
rustc_attr!(
809+
rustc_safe_intrinsic, Normal, template!(Word), WarnFollowing,
810+
"the `#[rustc_safe_intrinsic]` attribute is used internally to mark intrinsics as safe"
811+
),
809812

810813
// ==========================================================================
811814
// Internal attributes, Testing:

compiler/rustc_passes/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,10 @@ passes_rustc_lint_opt_ty =
648648
`#[rustc_lint_opt_ty]` should be applied to a struct
649649
.label = not a struct
650650
651+
passes_rustc_safe_intrinsic =
652+
attribute should be applied to intrinsic functions
653+
.label = not an intrinsic function
654+
651655
passes_rustc_std_internal_symbol =
652656
attribute should be applied to functions or statics
653657
.label = not a function or static

compiler/rustc_passes/src/check_attr.rs

+26
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ impl CheckAttrVisitor<'_> {
195195
| sym::rustc_promotable => self.check_stability_promotable(&attr, span, target),
196196
sym::link_ordinal => self.check_link_ordinal(&attr, span, target),
197197
sym::rustc_confusables => self.check_confusables(&attr, target),
198+
sym::rustc_safe_intrinsic => {
199+
self.check_rustc_safe_intrinsic(hir_id, attr, span, target)
200+
}
198201
_ => true,
199202
};
200203

@@ -2042,6 +2045,29 @@ impl CheckAttrVisitor<'_> {
20422045
}
20432046
}
20442047

2048+
fn check_rustc_safe_intrinsic(
2049+
&self,
2050+
hir_id: HirId,
2051+
attr: &Attribute,
2052+
span: Span,
2053+
target: Target,
2054+
) -> bool {
2055+
let hir = self.tcx.hir();
2056+
2057+
if let Target::ForeignFn = target
2058+
&& let Some(parent) = hir.opt_parent_id(hir_id)
2059+
&& let hir::Node::Item(Item {
2060+
kind: ItemKind::ForeignMod { abi: Abi::RustIntrinsic | Abi::PlatformIntrinsic, .. },
2061+
..
2062+
}) = hir.get(parent)
2063+
{
2064+
return true;
2065+
}
2066+
2067+
self.tcx.sess.emit_err(errors::RustcSafeIntrinsic { attr_span: attr.span, span });
2068+
false
2069+
}
2070+
20452071
fn check_rustc_std_internal_symbol(
20462072
&self,
20472073
attr: &Attribute,

compiler/rustc_passes/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,15 @@ pub struct RustcAllowConstFnUnstable {
620620
pub span: Span,
621621
}
622622

623+
#[derive(Diagnostic)]
624+
#[diag(passes_rustc_safe_intrinsic)]
625+
pub struct RustcSafeIntrinsic {
626+
#[primary_span]
627+
pub attr_span: Span,
628+
#[label]
629+
pub span: Span,
630+
}
631+
623632
#[derive(Diagnostic)]
624633
#[diag(passes_rustc_std_internal_symbol)]
625634
pub struct RustcStdInternalSymbol {

compiler/rustc_query_system/src/query/plumbing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_data_structures::sharded::Sharded;
1818
use rustc_data_structures::stack::ensure_sufficient_stack;
1919
use rustc_data_structures::sync::Lock;
2020
#[cfg(parallel_compiler)]
21-
use rustc_data_structures::{cold_path, sync};
21+
use rustc_data_structures::{outline, sync};
2222
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, FatalError};
2323
use rustc_span::{Span, DUMMY_SP};
2424
use std::cell::Cell;
@@ -265,7 +265,7 @@ where
265265
match result {
266266
Ok(()) => {
267267
let Some((v, index)) = query.query_cache(qcx).lookup(&key) else {
268-
cold_path(|| {
268+
outline(|| {
269269
// We didn't find the query result in the query cache. Check if it was
270270
// poisoned due to a panic instead.
271271
let lock = query.query_state(qcx).active.get_shard_by_value(&key).lock();

compiler/rustc_span/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern crate rustc_macros;
3333
#[macro_use]
3434
extern crate tracing;
3535

36-
use rustc_data_structures::{cold_path, AtomicRef};
36+
use rustc_data_structures::{outline, AtomicRef};
3737
use rustc_macros::HashStable_Generic;
3838
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
3939

@@ -1592,7 +1592,7 @@ impl SourceFile {
15921592
return &lines[..];
15931593
}
15941594

1595-
cold_path(|| {
1595+
outline(|| {
15961596
self.convert_diffs_to_lines_frozen();
15971597
if let Some(SourceFileLines::Lines(lines)) = self.lines.get() {
15981598
return &lines[..];

src/doc/nomicon

src/doc/rustdoc/src/unstable-features.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ library, as an equivalent command-line argument is provided to `rustc` when buil
375375
This feature allows you to generate an index-page with a given markdown file. A good example of it
376376
is the [rust documentation index](https://doc.rust-lang.org/nightly/index.html).
377377

378-
With this, you'll have a page which you can custom as much as you want at the top of your crates.
378+
With this, you'll have a page which you can customize as much as you want at the top of your crates.
379379

380380
Using `index-page` option enables `enable-index-page` option as well.
381381

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// run-pass
2+
// only-x86_64
3+
// compile-flags: -C opt-level=3
4+
5+
// Regression test for issue #79865.
6+
// The assertion will fail when compiled with Rust 1.56..=1.59
7+
// due to a LLVM miscompilation.
8+
9+
use std::arch::x86_64::*;
10+
11+
fn main() {
12+
if is_x86_feature_detected!("avx") {
13+
let res: [f64; 4] = unsafe { std::mem::transmute::<_, _>(first()) };
14+
assert_eq!(res, [22.0, 44.0, 66.0, 88.0]);
15+
}
16+
}
17+
18+
#[target_feature(enable = "avx")]
19+
unsafe fn first() -> __m256d {
20+
second()
21+
}
22+
23+
unsafe fn second() -> __m256d {
24+
let v0 = _mm256_setr_pd(1.0, 2.0, 3.0, 4.0);
25+
let v1 = _mm256_setr_pd(10.0, 20.0, 30.0, 40.0);
26+
27+
// needs to be called twice to hit the miscompilation
28+
let (add, _) = add_sub(v0, v1);
29+
let (add, _) = add_sub(add, add);
30+
add
31+
}
32+
33+
#[inline(never)] // needed to hit the miscompilation
34+
unsafe fn add_sub(v1: __m256d, v0: __m256d) -> (__m256d, __m256d) {
35+
let add = _mm256_add_pd(v0, v1);
36+
let sub = _mm256_sub_pd(v0, v1);
37+
(add, sub)
38+
}

tests/ui/error-codes/E0094.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(intrinsics)]
1+
#![feature(intrinsics, rustc_attrs)]
22

33
extern "rust-intrinsic" {
44
#[rustc_safe_intrinsic]

tests/ui/extern/extern-with-type-bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(intrinsics)]
1+
#![feature(intrinsics, rustc_attrs)]
22

33
extern "rust-intrinsic" {
44
// Real example from libcore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[rustc_safe_intrinsic]
2+
//~^ ERROR the `#[rustc_safe_intrinsic]` attribute is used internally to mark intrinsics as safe
3+
//~| ERROR attribute should be applied to intrinsic functions
4+
fn safe() {}
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0658]: the `#[rustc_safe_intrinsic]` attribute is used internally to mark intrinsics as safe
2+
--> $DIR/feature-gate-safe-intrinsic.rs:1:1
3+
|
4+
LL | #[rustc_safe_intrinsic]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
8+
9+
error: attribute should be applied to intrinsic functions
10+
--> $DIR/feature-gate-safe-intrinsic.rs:1:1
11+
|
12+
LL | #[rustc_safe_intrinsic]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^
14+
...
15+
LL | fn safe() {}
16+
| ------------ not an intrinsic function
17+
18+
error: aborting due to 2 previous errors
19+
20+
For more information about this error, try `rustc --explain E0658`.

tests/ui/intrinsics/intrinsic-alignment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// run-pass
22
// ignore-wasm32-bare seems not important to test here
33

4-
#![feature(intrinsics)]
4+
#![feature(intrinsics, rustc_attrs)]
55

66
mod rusti {
77
extern "rust-intrinsic" {

tests/ui/repr/16-bit-repr-c-enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// [avr] compile-flags: --target=avr-unknown-gnu-atmega328 --crate-type=rlib
66
// [msp430] needs-llvm-components: msp430
77
// [msp430] compile-flags: --target=msp430-none-elf --crate-type=rlib
8-
#![feature(no_core, lang_items, intrinsics, staged_api)]
8+
#![feature(no_core, lang_items, intrinsics, staged_api, rustc_attrs)]
99
#![no_core]
1010
#![crate_type = "lib"]
1111
#![stable(feature = "", since = "")]

tests/ui/structs-enums/rec-align-u32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(unused_unsafe)]
44
// Issue #2303
55

6-
#![feature(intrinsics)]
6+
#![feature(intrinsics, rustc_attrs)]
77

88
use std::mem;
99

tests/ui/structs-enums/rec-align-u64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// Issue #2303
77

8-
#![feature(intrinsics)]
8+
#![feature(intrinsics, rustc_attrs)]
99

1010
use std::mem;
1111

0 commit comments

Comments
 (0)