Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit db15940

Browse files
borsJonathanBrouwer
authored andcommitted
Port #[no_mangle] to new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2 parents 15c701f + 432c7d0 commit db15940

File tree

99 files changed

+8535
-327
lines changed

Some content is hidden

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

99 files changed

+8535
-327
lines changed

‎Cargo.lock

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,6 +2983,15 @@ dependencies = [
29832983
"getrandom 0.3.3",
29842984
]
29852985

2986+
[[package]]
2987+
name = "rand_xorshift"
2988+
version = "0.4.0"
2989+
source = "registry+https://github.com/rust-lang/crates.io-index"
2990+
checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a"
2991+
dependencies = [
2992+
"rand_core 0.9.3",
2993+
]
2994+
29862995
[[package]]
29872996
name = "rand_xoshiro"
29882997
version = "0.7.0"
@@ -3182,16 +3191,6 @@ dependencies = [
31823191
"tikv-jemalloc-sys",
31833192
]
31843193

3185-
[[package]]
3186-
name = "rustc-rayon-core"
3187-
version = "0.5.1"
3188-
source = "registry+https://github.com/rust-lang/crates.io-index"
3189-
checksum = "2f42932dcd3bcbe484b38a3ccf79b7906fac41c02d408b5b1bac26da3416efdb"
3190-
dependencies = [
3191-
"crossbeam-deque",
3192-
"crossbeam-utils",
3193-
]
3194-
31953194
[[package]]
31963195
name = "rustc-semver"
31973196
version = "1.1.0"
@@ -3558,14 +3557,14 @@ dependencies = [
35583557
"parking_lot",
35593558
"portable-atomic",
35603559
"rustc-hash 2.1.1",
3561-
"rustc-rayon-core",
35623560
"rustc-stable-hash",
35633561
"rustc_arena",
35643562
"rustc_graphviz",
35653563
"rustc_hashes",
35663564
"rustc_index",
35673565
"rustc_macros",
35683566
"rustc_serialize",
3567+
"rustc_thread_pool",
35693568
"smallvec",
35703569
"stacker",
35713570
"tempfile",
@@ -3913,7 +3912,6 @@ dependencies = [
39133912
name = "rustc_interface"
39143913
version = "0.0.0"
39153914
dependencies = [
3916-
"rustc-rayon-core",
39173915
"rustc_abi",
39183916
"rustc_ast",
39193917
"rustc_ast_lowering",
@@ -3952,6 +3950,7 @@ dependencies = [
39523950
"rustc_span",
39533951
"rustc_symbol_mangling",
39543952
"rustc_target",
3953+
"rustc_thread_pool",
39553954
"rustc_trait_selection",
39563955
"rustc_traits",
39573956
"rustc_ty_utils",
@@ -4079,7 +4078,6 @@ dependencies = [
40794078
"either",
40804079
"gsgdt",
40814080
"polonius-engine",
4082-
"rustc-rayon-core",
40834081
"rustc_abi",
40844082
"rustc_apfloat",
40854083
"rustc_arena",
@@ -4103,6 +4101,7 @@ dependencies = [
41034101
"rustc_session",
41044102
"rustc_span",
41054103
"rustc_target",
4104+
"rustc_thread_pool",
41064105
"rustc_type_ir",
41074106
"smallvec",
41084107
"thin-vec",
@@ -4349,7 +4348,6 @@ version = "0.0.0"
43494348
dependencies = [
43504349
"hashbrown",
43514350
"parking_lot",
4352-
"rustc-rayon-core",
43534351
"rustc_abi",
43544352
"rustc_ast",
43554353
"rustc_attr_data_structures",
@@ -4364,6 +4362,7 @@ dependencies = [
43644362
"rustc_serialize",
43654363
"rustc_session",
43664364
"rustc_span",
4365+
"rustc_thread_pool",
43674366
"smallvec",
43684367
"tracing",
43694368
]
@@ -4525,6 +4524,18 @@ dependencies = [
45254524
"tracing",
45264525
]
45274526

4527+
[[package]]
4528+
name = "rustc_thread_pool"
4529+
version = "0.0.0"
4530+
dependencies = [
4531+
"crossbeam-deque",
4532+
"crossbeam-utils",
4533+
"libc",
4534+
"rand 0.9.1",
4535+
"rand_xorshift",
4536+
"scoped-tls",
4537+
]
4538+
45284539
[[package]]
45294540
name = "rustc_tools_util"
45304541
version = "0.4.2"

‎Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ exclude = [
6060
"obj",
6161
]
6262

63-
[profile.release.package.rustc-rayon-core]
63+
[profile.release.package.rustc_thread_pool]
6464
# The rustc fork of Rayon has deadlock detection code which intermittently
6565
# causes overflows in the CI (see https://github.com/rust-lang/rust/issues/90227)
6666
# so we turn overflow checks off for now.

‎compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -386,18 +386,44 @@ impl<'a> State<'a> {
386386

387387
let ib = self.ibox(INDENT_UNIT);
388388

389-
// The Match subexpression in `match x {} - 1` must be parenthesized if
390-
// it is the leftmost subexpression in a statement:
391-
//
392-
// (match x {}) - 1;
393-
//
394-
// But not otherwise:
395-
//
396-
// let _ = match x {} - 1;
397-
//
398-
// Same applies to a small set of other expression kinds which eagerly
399-
// terminate a statement which opens with them.
400-
let needs_par = fixup.would_cause_statement_boundary(expr);
389+
let needs_par = {
390+
// The Match subexpression in `match x {} - 1` must be parenthesized
391+
// if it is the leftmost subexpression in a statement:
392+
//
393+
// (match x {}) - 1;
394+
//
395+
// But not otherwise:
396+
//
397+
// let _ = match x {} - 1;
398+
//
399+
// Same applies to a small set of other expression kinds which
400+
// eagerly terminate a statement which opens with them.
401+
fixup.would_cause_statement_boundary(expr)
402+
} || {
403+
// If a binary operation ends up with an attribute, such as
404+
// resulting from the following macro expansion, then parentheses
405+
// are required so that the attribute encompasses the right
406+
// subexpression and not just the left one.
407+
//
408+
// #![feature(stmt_expr_attributes)]
409+
//
410+
// macro_rules! add_attr {
411+
// ($e:expr) => { #[attr] $e };
412+
// }
413+
//
414+
// let _ = add_attr!(1 + 1);
415+
//
416+
// We must pretty-print `#[attr] (1 + 1)` not `#[attr] 1 + 1`.
417+
!attrs.is_empty()
418+
&& matches!(
419+
expr.kind,
420+
ast::ExprKind::Binary(..)
421+
| ast::ExprKind::Cast(..)
422+
| ast::ExprKind::Assign(..)
423+
| ast::ExprKind::AssignOp(..)
424+
| ast::ExprKind::Range(..)
425+
)
426+
};
401427
if needs_par {
402428
self.popen();
403429
fixup = FixupContext::default();

‎compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ pub enum AttributeKind {
233233

234234
/// Represents `#[rustc_macro_transparency]`.
235235
MacroTransparency(Transparency),
236+
/// Represents `#[no_mangle]`
237+
NoMangle(Span),
236238
/// Represents `#[optimize(size|speed)]`
237239
Optimize(OptimizeAttr, Span),
238240
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).

‎compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,21 @@ impl<S: Stage> SingleAttributeParser<S> for ColdParser {
5656
Some(AttributeKind::Cold(cx.attr_span))
5757
}
5858
}
59+
60+
pub(crate) struct NoMangleParser;
61+
62+
impl<S: Stage> SingleAttributeParser<S> for NoMangleParser {
63+
const PATH: &[rustc_span::Symbol] = &[sym::no_mangle];
64+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
65+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
66+
const TEMPLATE: AttributeTemplate = template!(Word);
67+
68+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
69+
if !args.no_args() {
70+
cx.expected_no_args(args.span().unwrap_or(cx.attr_span));
71+
return None;
72+
};
73+
74+
Some(AttributeKind::NoMangle(cx.attr_span))
75+
}
76+
}

‎compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_session::Session;
1515
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1616

1717
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
18-
use crate::attributes::codegen_attrs::{ColdParser, OptimizeParser};
18+
use crate::attributes::codegen_attrs::{ColdParser, NoMangleParser,OptimizeParser};
1919
use crate::attributes::confusables::ConfusablesParser;
2020
use crate::attributes::deprecation::DeprecationParser;
2121
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
@@ -110,6 +110,7 @@ attribute_parsers!(
110110
Single<ConstStabilityIndirectParser>,
111111
Single<DeprecationParser>,
112112
Single<InlineParser>,
113+
Single<NoMangleParser>,
113114
Single<OptimizeParser>,
114115
Single<RustcForceInlineParser>,
115116
Single<TransparencyParser>,

‎compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,28 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
122122
}
123123
AttributeKind::Cold(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD,
124124
AttributeKind::Align { align, .. } => codegen_fn_attrs.alignment = Some(*align),
125+
AttributeKind::NoMangle(attr_span) => {
126+
no_mangle_span = Some(*attr_span);
127+
if tcx.opt_item_name(did.to_def_id()).is_some() {
128+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
129+
mixed_export_name_no_mangle_lint_state.track_no_mangle(
130+
*attr_span,
131+
tcx.local_def_id_to_hir_id(did),
132+
attr,
133+
);
134+
} else {
135+
tcx.dcx()
136+
.struct_span_err(
137+
*attr_span,
138+
format!(
139+
"`#[no_mangle]` cannot be used on {} {} as it has no name",
140+
tcx.def_descr_article(did.to_def_id()),
141+
tcx.def_descr(did.to_def_id()),
142+
),
143+
)
144+
.emit();
145+
}
146+
}
125147
_ => {}
126148
}
127149
}
@@ -141,28 +163,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
141163
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
142164
}
143165
sym::naked => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED,
144-
sym::no_mangle => {
145-
no_mangle_span = Some(attr.span());
146-
if tcx.opt_item_name(did.to_def_id()).is_some() {
147-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
148-
mixed_export_name_no_mangle_lint_state.track_no_mangle(
149-
attr.span(),
150-
tcx.local_def_id_to_hir_id(did),
151-
attr,
152-
);
153-
} else {
154-
tcx.dcx()
155-
.struct_span_err(
156-
attr.span(),
157-
format!(
158-
"`#[no_mangle]` cannot be used on {} {} as it has no name",
159-
tcx.def_descr_article(did.to_def_id()),
160-
tcx.def_descr(did.to_def_id()),
161-
),
162-
)
163-
.emit();
164-
}
165-
}
166166
sym::rustc_std_internal_symbol => {
167167
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL
168168
}

‎compiler/rustc_data_structures/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ indexmap = "2.4.0"
1414
jobserver_crate = { version = "0.1.28", package = "jobserver" }
1515
measureme = "12.0.1"
1616
rustc-hash = "2.0.0"
17-
rustc-rayon-core = { version = "0.5.0" }
1817
rustc-stable-hash = { version = "0.1.0", features = ["nightly"] }
1918
rustc_arena = { path = "../rustc_arena" }
2019
rustc_graphviz = { path = "../rustc_graphviz" }
2120
rustc_hashes = { path = "../rustc_hashes" }
2221
rustc_index = { path = "../rustc_index", package = "rustc_index" }
2322
rustc_macros = { path = "../rustc_macros" }
2423
rustc_serialize = { path = "../rustc_serialize" }
24+
rustc_thread_pool = { path = "../rustc_thread_pool" }
2525
smallvec = { version = "1.8.1", features = ["const_generics", "union", "may_dangle"] }
2626
stacker = "0.1.17"
2727
tempfile = "3.2"

‎compiler/rustc_data_structures/src/sync.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
//! | | | `parking_lot::Mutex<T>` |
2323
//! | `RwLock<T>` | `RefCell<T>` | `parking_lot::RwLock<T>` |
2424
//! | `MTLock<T>` [^1] | `T` | `Lock<T>` |
25-
//! | | | |
26-
//! | `ParallelIterator` | `Iterator` | `rayon::iter::ParallelIterator` |
2725
//!
2826
//! [^1]: `MTLock` is similar to `Lock`, but the serial version avoids the cost
2927
//! of a `RefCell`. This is appropriate when interior mutability is not

‎compiler/rustc_data_structures/src/sync/parallel.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ macro_rules! parallel {
9696
pub fn spawn(func: impl FnOnce() + DynSend + 'static) {
9797
if mode::is_dyn_thread_safe() {
9898
let func = FromDyn::from(func);
99-
rayon_core::spawn(|| {
99+
rustc_thread_pool::spawn(|| {
100100
(func.into_inner())();
101101
});
102102
} else {
@@ -107,11 +107,11 @@ pub fn spawn(func: impl FnOnce() + DynSend + 'static) {
107107
// This function only works when `mode::is_dyn_thread_safe()`.
108108
pub fn scope<'scope, OP, R>(op: OP) -> R
109109
where
110-
OP: FnOnce(&rayon_core::Scope<'scope>) -> R + DynSend,
110+
OP: FnOnce(&rustc_thread_pool::Scope<'scope>) -> R + DynSend,
111111
R: DynSend,
112112
{
113113
let op = FromDyn::from(op);
114-
rayon_core::scope(|s| FromDyn::from(op.into_inner()(s))).into_inner()
114+
rustc_thread_pool::scope(|s| FromDyn::from(op.into_inner()(s))).into_inner()
115115
}
116116

117117
#[inline]
@@ -124,7 +124,7 @@ where
124124
let oper_a = FromDyn::from(oper_a);
125125
let oper_b = FromDyn::from(oper_b);
126126
let (a, b) = parallel_guard(|guard| {
127-
rayon_core::join(
127+
rustc_thread_pool::join(
128128
move || guard.run(move || FromDyn::from(oper_a.into_inner()())),
129129
move || guard.run(move || FromDyn::from(oper_b.into_inner()())),
130130
)
@@ -158,7 +158,7 @@ fn par_slice<I: DynSend>(
158158
let (left, right) = items.split_at_mut(items.len() / 2);
159159
let mut left = state.for_each.derive(left);
160160
let mut right = state.for_each.derive(right);
161-
rayon_core::join(move || par_rec(*left, state), move || par_rec(*right, state));
161+
rustc_thread_pool::join(move || par_rec(*left, state), move || par_rec(*right, state));
162162
}
163163
}
164164

@@ -241,7 +241,7 @@ pub fn par_map<I: DynSend, T: IntoIterator<Item = I>, R: DynSend, C: FromIterato
241241
pub fn broadcast<R: DynSend>(op: impl Fn(usize) -> R + DynSync) -> Vec<R> {
242242
if mode::is_dyn_thread_safe() {
243243
let op = FromDyn::from(op);
244-
let results = rayon_core::broadcast(|context| op.derive(op(context.index())));
244+
let results = rustc_thread_pool::broadcast(|context| op.derive(op(context.index())));
245245
results.into_iter().map(|r| r.into_inner()).collect()
246246
} else {
247247
vec![op(0)]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /