Skip to content

Commit 21627d6

Browse files
committed
Auto merge of #116175 - matthiaskrgr:rollup-cwteiwy, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #116099 (Add regression test for issue #79865) - #116131 (Rename `cold_path` to `outline`) - #116151 (Fix typo in rustdoc unstable features doc) - #116153 (Update books) - #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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 6 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 26 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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 {

0 commit comments

Comments
 (0)