Skip to content

Commit 5f292ee

Browse files
committed
Auto merge of rust-lang#141238 - Zalathar:rollup-zdqpazo, r=Zalathar
Rollup of 4 pull requests Successful merges: - rust-lang#140049 (fix autodiff macro on generic functions) - rust-lang#140874 (make `rustc_attr_parsing` less dominant in the rustc crate graph) - rust-lang#141094 (add regression test for rust-lang#101650) - rust-lang#141110 ([std] fix the presentation of `split_off_mut` and `split_off` documentation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e42bbfe + 93bc64d commit 5f292ee

File tree

78 files changed

+292
-138
lines changed

Some content is hidden

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

78 files changed

+292
-138
lines changed

Cargo.lock

+13-8
Original file line numberDiff line numberDiff line change
@@ -3390,6 +3390,7 @@ version = "0.0.0"
33903390
dependencies = [
33913391
"rustc_ast",
33923392
"rustc_ast_pretty",
3393+
"rustc_attr_data_structures",
33933394
"rustc_attr_parsing",
33943395
"rustc_data_structures",
33953396
"rustc_errors",
@@ -3424,7 +3425,7 @@ dependencies = [
34243425
"rustc-demangle",
34253426
"rustc_abi",
34263427
"rustc_ast",
3427-
"rustc_attr_parsing",
3428+
"rustc_attr_data_structures",
34283429
"rustc_codegen_ssa",
34293430
"rustc_data_structures",
34303431
"rustc_errors",
@@ -3467,6 +3468,7 @@ dependencies = [
34673468
"rustc_abi",
34683469
"rustc_arena",
34693470
"rustc_ast",
3471+
"rustc_attr_data_structures",
34703472
"rustc_attr_parsing",
34713473
"rustc_data_structures",
34723474
"rustc_errors",
@@ -3504,7 +3506,7 @@ dependencies = [
35043506
"rustc_abi",
35053507
"rustc_apfloat",
35063508
"rustc_ast",
3507-
"rustc_attr_parsing",
3509+
"rustc_attr_data_structures",
35083510
"rustc_data_structures",
35093511
"rustc_errors",
35103512
"rustc_fluent_macro",
@@ -3680,6 +3682,7 @@ dependencies = [
36803682
"rustc_ast",
36813683
"rustc_ast_passes",
36823684
"rustc_ast_pretty",
3685+
"rustc_attr_data_structures",
36833686
"rustc_attr_parsing",
36843687
"rustc_data_structures",
36853688
"rustc_errors",
@@ -3768,7 +3771,7 @@ dependencies = [
37683771
"rustc_abi",
37693772
"rustc_arena",
37703773
"rustc_ast",
3771-
"rustc_attr_parsing",
3774+
"rustc_attr_data_structures",
37723775
"rustc_data_structures",
37733776
"rustc_errors",
37743777
"rustc_feature",
@@ -3805,7 +3808,7 @@ dependencies = [
38053808
"itertools",
38063809
"rustc_abi",
38073810
"rustc_ast",
3808-
"rustc_attr_parsing",
3811+
"rustc_attr_data_structures",
38093812
"rustc_data_structures",
38103813
"rustc_errors",
38113814
"rustc_fluent_macro",
@@ -3950,6 +3953,7 @@ dependencies = [
39503953
"rustc_abi",
39513954
"rustc_ast",
39523955
"rustc_ast_pretty",
3956+
"rustc_attr_data_structures",
39533957
"rustc_attr_parsing",
39543958
"rustc_data_structures",
39553959
"rustc_errors",
@@ -4023,6 +4027,7 @@ dependencies = [
40234027
"odht",
40244028
"rustc_abi",
40254029
"rustc_ast",
4030+
"rustc_attr_data_structures",
40264031
"rustc_attr_parsing",
40274032
"rustc_data_structures",
40284033
"rustc_errors",
@@ -4136,7 +4141,7 @@ dependencies = [
41364141
"rustc_abi",
41374142
"rustc_arena",
41384143
"rustc_ast",
4139-
"rustc_attr_parsing",
4144+
"rustc_attr_data_structures",
41404145
"rustc_const_eval",
41414146
"rustc_data_structures",
41424147
"rustc_errors",
@@ -4162,7 +4167,7 @@ version = "0.0.0"
41624167
dependencies = [
41634168
"rustc_abi",
41644169
"rustc_ast",
4165-
"rustc_attr_parsing",
4170+
"rustc_attr_data_structures",
41664171
"rustc_data_structures",
41674172
"rustc_errors",
41684173
"rustc_fluent_macro",
@@ -4232,7 +4237,7 @@ dependencies = [
42324237
"rustc_ast",
42334238
"rustc_ast_lowering",
42344239
"rustc_ast_pretty",
4235-
"rustc_attr_parsing",
4240+
"rustc_attr_data_structures",
42364241
"rustc_data_structures",
42374242
"rustc_errors",
42384243
"rustc_expand",
@@ -4278,7 +4283,7 @@ name = "rustc_privacy"
42784283
version = "0.0.0"
42794284
dependencies = [
42804285
"rustc_ast",
4281-
"rustc_attr_parsing",
4286+
"rustc_attr_data_structures",
42824287
"rustc_data_structures",
42834288
"rustc_errors",
42844289
"rustc_fluent_macro",

compiler/rustc_attr_parsing/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
//! `#[stable(...)]` and `#[unstable()]` cannot occur together, and both semantically define
6161
//! a "stability" of an item. So, the stability attribute has an
6262
//! [`AttributeParser`](attributes::AttributeParser) that recognizes both the `#[stable()]`
63-
//! and `#[unstable()]` syntactic attributes, and at the end produce a single [`AttributeKind::Stability`].
63+
//! and `#[unstable()]` syntactic attributes, and at the end produce a single
64+
//! [`AttributeKind::Stability`](rustc_attr_data_structures::AttributeKind::Stability).
6465
//!
6566
//! As a rule of thumb, when a syntactical attribute can be applied more than once, they should be
6667
//! combined into a single semantic attribute. For example:
@@ -91,6 +92,5 @@ mod session_diagnostics;
9192
pub use attributes::cfg::*;
9293
pub use attributes::util::{find_crate_name, is_builtin_attr, parse_version};
9394
pub use context::{AttributeParser, OmitDoc};
94-
pub use rustc_attr_data_structures::*;
9595

9696
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

compiler/rustc_builtin_macros/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ doctest = false
1010
# tidy-alphabetical-start
1111
rustc_ast = { path = "../rustc_ast" }
1212
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
13+
rustc_attr_data_structures = { path = "../rustc_attr_data_structures" }
1314
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
1415
rustc_data_structures = { path = "../rustc_data_structures" }
1516
rustc_errors = { path = "../rustc_errors" }

compiler/rustc_builtin_macros/src/autodiff.rs

+62-11
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ mod llvm_enzyme {
7373
}
7474

7575
// Get information about the function the macro is applied to
76-
fn extract_item_info(iitem: &P<ast::Item>) -> Option<(Visibility, FnSig, Ident)> {
76+
fn extract_item_info(iitem: &P<ast::Item>) -> Option<(Visibility, FnSig, Ident, Generics)> {
7777
match &iitem.kind {
78-
ItemKind::Fn(box ast::Fn { sig, ident, .. }) => {
79-
Some((iitem.vis.clone(), sig.clone(), ident.clone()))
78+
ItemKind::Fn(box ast::Fn { sig, ident, generics, .. }) => {
79+
Some((iitem.vis.clone(), sig.clone(), ident.clone(), generics.clone()))
8080
}
8181
_ => None,
8282
}
@@ -210,16 +210,18 @@ mod llvm_enzyme {
210210
}
211211
let dcx = ecx.sess.dcx();
212212

213-
// first get information about the annotable item:
214-
let Some((vis, sig, primal)) = (match &item {
213+
// first get information about the annotable item: visibility, signature, name and generic
214+
// parameters.
215+
// these will be used to generate the differentiated version of the function
216+
let Some((vis, sig, primal, generics)) = (match &item {
215217
Annotatable::Item(iitem) => extract_item_info(iitem),
216218
Annotatable::Stmt(stmt) => match &stmt.kind {
217219
ast::StmtKind::Item(iitem) => extract_item_info(iitem),
218220
_ => None,
219221
},
220222
Annotatable::AssocItem(assoc_item, Impl { .. }) => match &assoc_item.kind {
221-
ast::AssocItemKind::Fn(box ast::Fn { sig, ident, .. }) => {
222-
Some((assoc_item.vis.clone(), sig.clone(), ident.clone()))
223+
ast::AssocItemKind::Fn(box ast::Fn { sig, ident, generics, .. }) => {
224+
Some((assoc_item.vis.clone(), sig.clone(), ident.clone(), generics.clone()))
223225
}
224226
_ => None,
225227
},
@@ -303,14 +305,15 @@ mod llvm_enzyme {
303305
let (d_sig, new_args, idents, errored) = gen_enzyme_decl(ecx, &sig, &x, span);
304306
let d_body = gen_enzyme_body(
305307
ecx, &x, n_active, &sig, &d_sig, primal, &new_args, span, sig_span, idents, errored,
308+
&generics,
306309
);
307310

308311
// The first element of it is the name of the function to be generated
309312
let asdf = Box::new(ast::Fn {
310313
defaultness: ast::Defaultness::Final,
311314
sig: d_sig,
312315
ident: first_ident(&meta_item_vec[0]),
313-
generics: Generics::default(),
316+
generics,
314317
contract: None,
315318
body: Some(d_body),
316319
define_opaque: None,
@@ -475,6 +478,7 @@ mod llvm_enzyme {
475478
new_decl_span: Span,
476479
idents: &[Ident],
477480
errored: bool,
481+
generics: &Generics,
478482
) -> (P<ast::Block>, P<ast::Expr>, P<ast::Expr>, P<ast::Expr>) {
479483
let blackbox_path = ecx.std_path(&[sym::hint, sym::black_box]);
480484
let noop = ast::InlineAsm {
@@ -497,7 +501,7 @@ mod llvm_enzyme {
497501
};
498502
let unsf_expr = ecx.expr_block(P(unsf_block));
499503
let blackbox_call_expr = ecx.expr_path(ecx.path(span, blackbox_path));
500-
let primal_call = gen_primal_call(ecx, span, primal, idents);
504+
let primal_call = gen_primal_call(ecx, span, primal, idents, generics);
501505
let black_box_primal_call = ecx.expr_call(
502506
new_decl_span,
503507
blackbox_call_expr.clone(),
@@ -546,6 +550,7 @@ mod llvm_enzyme {
546550
sig_span: Span,
547551
idents: Vec<Ident>,
548552
errored: bool,
553+
generics: &Generics,
549554
) -> P<ast::Block> {
550555
let new_decl_span = d_sig.span;
551556

@@ -566,6 +571,7 @@ mod llvm_enzyme {
566571
new_decl_span,
567572
&idents,
568573
errored,
574+
generics,
569575
);
570576

571577
if !has_ret(&d_sig.decl.output) {
@@ -608,7 +614,6 @@ mod llvm_enzyme {
608614
panic!("Did not expect Default ret ty: {:?}", span);
609615
}
610616
};
611-
612617
if x.mode.is_fwd() {
613618
// Fwd mode is easy. If the return activity is Const, we support arbitrary types.
614619
// Otherwise, we only support a scalar, a pair of scalars, or an array of scalars.
@@ -668,8 +673,10 @@ mod llvm_enzyme {
668673
span: Span,
669674
primal: Ident,
670675
idents: &[Ident],
676+
generics: &Generics,
671677
) -> P<ast::Expr> {
672678
let has_self = idents.len() > 0 && idents[0].name == kw::SelfLower;
679+
673680
if has_self {
674681
let args: ThinVec<_> =
675682
idents[1..].iter().map(|arg| ecx.expr_path(ecx.path_ident(span, *arg))).collect();
@@ -678,7 +685,51 @@ mod llvm_enzyme {
678685
} else {
679686
let args: ThinVec<_> =
680687
idents.iter().map(|arg| ecx.expr_path(ecx.path_ident(span, *arg))).collect();
681-
let primal_call_expr = ecx.expr_path(ecx.path_ident(span, primal));
688+
let mut primal_path = ecx.path_ident(span, primal);
689+
690+
let is_generic = !generics.params.is_empty();
691+
692+
match (is_generic, primal_path.segments.last_mut()) {
693+
(true, Some(function_path)) => {
694+
let primal_generic_types = generics
695+
.params
696+
.iter()
697+
.filter(|param| matches!(param.kind, ast::GenericParamKind::Type { .. }));
698+
699+
let generated_generic_types = primal_generic_types
700+
.map(|type_param| {
701+
let generic_param = TyKind::Path(
702+
None,
703+
ast::Path {
704+
span,
705+
segments: thin_vec![ast::PathSegment {
706+
ident: type_param.ident,
707+
args: None,
708+
id: ast::DUMMY_NODE_ID,
709+
}],
710+
tokens: None,
711+
},
712+
);
713+
714+
ast::AngleBracketedArg::Arg(ast::GenericArg::Type(P(ast::Ty {
715+
id: type_param.id,
716+
span,
717+
kind: generic_param,
718+
tokens: None,
719+
})))
720+
})
721+
.collect();
722+
723+
function_path.args =
724+
Some(P(ast::GenericArgs::AngleBracketed(ast::AngleBracketedArgs {
725+
span,
726+
args: generated_generic_types,
727+
})));
728+
}
729+
_ => {}
730+
}
731+
732+
let primal_call_expr = ecx.expr_path(primal_path);
682733
ecx.expr_call(span, primal_call_expr, args)
683734
}
684735
}

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ use rustc_ast::{
185185
self as ast, AnonConst, BindingMode, ByRef, EnumDef, Expr, GenericArg, GenericParamKind,
186186
Generics, Mutability, PatKind, VariantData,
187187
};
188-
use rustc_attr_parsing::{AttributeKind, AttributeParser, ReprPacked};
188+
use rustc_attr_data_structures::{AttributeKind, ReprPacked};
189+
use rustc_attr_parsing::AttributeParser;
189190
use rustc_expand::base::{Annotatable, ExtCtxt};
190191
use rustc_hir::Attribute;
191192
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};

compiler/rustc_codegen_gcc/src/attributes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
use gccjit::FnAttribute;
33
use gccjit::Function;
44
#[cfg(feature = "master")]
5-
use rustc_attr_parsing::InlineAttr;
6-
use rustc_attr_parsing::InstructionSetAttr;
5+
use rustc_attr_data_structures::InlineAttr;
6+
use rustc_attr_data_structures::InstructionSetAttr;
77
#[cfg(feature = "master")]
88
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
99
#[cfg(feature = "master")]

compiler/rustc_codegen_gcc/src/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)
106106
// This is a monomorphization of a generic function.
107107
if !(cx.tcx.sess.opts.share_generics()
108108
|| tcx.codegen_fn_attrs(instance_def_id).inline
109-
== rustc_attr_parsing::InlineAttr::Never)
109+
== rustc_attr_data_structures::InlineAttr::Never)
110110
{
111111
// When not sharing generics, all instances are in the same
112112
// crate and have hidden visibility.

compiler/rustc_codegen_gcc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern crate tracing;
3737
extern crate rustc_abi;
3838
extern crate rustc_apfloat;
3939
extern crate rustc_ast;
40-
extern crate rustc_attr_parsing;
40+
extern crate rustc_attr_data_structures;
4141
extern crate rustc_codegen_ssa;
4242
extern crate rustc_data_structures;
4343
extern crate rustc_errors;

compiler/rustc_codegen_llvm/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object = { version = "0.36.3", default-features = false, features = ["std", "rea
1919
rustc-demangle = "0.1.21"
2020
rustc_abi = { path = "../rustc_abi" }
2121
rustc_ast = { path = "../rustc_ast" }
22-
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
22+
rustc_attr_data_structures = { path = "../rustc_attr_data_structures" }
2323
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
2424
rustc_data_structures = { path = "../rustc_data_structures" }
2525
rustc_errors = { path = "../rustc_errors" }

compiler/rustc_codegen_llvm/src/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Set and unset common attributes on LLVM values.
2-
use rustc_attr_parsing::{InlineAttr, InstructionSetAttr, OptimizeAttr};
2+
use rustc_attr_data_structures::{InlineAttr, InstructionSetAttr, OptimizeAttr};
33
use rustc_codegen_ssa::traits::*;
44
use rustc_hir::def_id::DefId;
55
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, PatchableFunctionEntry};

compiler/rustc_codegen_llvm/src/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
103103
// This is a monomorphization of a generic function.
104104
if !(cx.tcx.sess.opts.share_generics()
105105
|| tcx.codegen_fn_attrs(instance_def_id).inline
106-
== rustc_attr_parsing::InlineAttr::Never)
106+
== rustc_attr_data_structures::InlineAttr::Never)
107107
{
108108
// When not sharing generics, all instances are in the same
109109
// crate and have hidden visibility.

compiler/rustc_codegen_ssa/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ regex = "1.4"
1919
rustc_abi = { path = "../rustc_abi" }
2020
rustc_arena = { path = "../rustc_arena" }
2121
rustc_ast = { path = "../rustc_ast" }
22+
rustc_attr_data_structures = { path = "../rustc_attr_data_structures" }
2223
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
2324
rustc_data_structures = { path = "../rustc_data_structures" }
2425
rustc_errors = { path = "../rustc_errors" }

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ fn exported_symbols_provider_local<'tcx>(
370370

371371
if !tcx.sess.opts.share_generics() {
372372
if tcx.codegen_fn_attrs(mono_item.def_id()).inline
373-
== rustc_attr_parsing::InlineAttr::Never
373+
== rustc_attr_data_structures::InlineAttr::Never
374374
{
375375
// this is OK, we explicitly allow sharing inline(never) across crates even
376376
// without share-generics.

compiler/rustc_codegen_ssa/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use itertools::Itertools;
77
use rustc_abi::FIRST_VARIANT;
88
use rustc_ast as ast;
99
use rustc_ast::expand::allocator::{ALLOCATOR_METHODS, AllocatorKind, global_fn_name};
10-
use rustc_attr_parsing::OptimizeAttr;
10+
use rustc_attr_data_structures::OptimizeAttr;
1111
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
1212
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
1313
use rustc_data_structures::sync::{IntoDynSyncSend, par_map};

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::str::FromStr;
33
use rustc_abi::ExternAbi;
44
use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, DiffActivity, DiffMode};
55
use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
6-
use rustc_attr_parsing::ReprAttr::ReprAlign;
7-
use rustc_attr_parsing::{AttributeKind, InlineAttr, InstructionSetAttr, OptimizeAttr};
6+
use rustc_attr_data_structures::ReprAttr::ReprAlign;
7+
use rustc_attr_data_structures::{AttributeKind, InlineAttr, InstructionSetAttr, OptimizeAttr};
88
use rustc_data_structures::fx::FxHashMap;
99
use rustc_hir::def::DefKind;
1010
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};

0 commit comments

Comments
 (0)