Skip to content

Commit d2218f5

Browse files
committed
Auto merge of #153344 - JonathanBrouwer:rollup-uL4XlqI, r=JonathanBrouwer
Rollup of 6 pull requests Successful merges: - #153336 (stdarch subtree update) - #152943 (Parse `impl` restrictions) - #153184 (Replace CodegenResults with CompiledModules) - #153285 (Update call-llvm-intrinsics test for Rust 1.94.0 IR) - #153319 (Comments and docs: add missing periods to "ie.") - #153326 (Make `rustc_with_all_queries!` pass query modifiers as named values)
2 parents 1b7d722 + d53a01c commit d2218f5

File tree

87 files changed

+2622
-2139
lines changed

Some content is hidden

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

87 files changed

+2622
-2139
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,6 +3553,19 @@ impl VisibilityKind {
35533553
}
35543554
}
35553555

3556+
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
3557+
pub struct ImplRestriction {
3558+
pub kind: RestrictionKind,
3559+
pub span: Span,
3560+
pub tokens: Option<LazyAttrTokenStream>,
3561+
}
3562+
3563+
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
3564+
pub enum RestrictionKind {
3565+
Unrestricted,
3566+
Restricted { path: Box<Path>, id: NodeId, shorthand: bool },
3567+
}
3568+
35563569
/// Field definition in a struct, variant or union.
35573570
///
35583571
/// E.g., `bar: usize` as in `struct Foo { bar: usize }`.
@@ -3752,6 +3765,7 @@ pub struct Trait {
37523765
pub constness: Const,
37533766
pub safety: Safety,
37543767
pub is_auto: IsAuto,
3768+
pub impl_restriction: ImplRestriction,
37553769
pub ident: Ident,
37563770
pub generics: Generics,
37573771
#[visitable(extra = BoundKind::SuperTraits)]

compiler/rustc_ast/src/ast_traits.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::marker::PhantomData;
88
use crate::tokenstream::LazyAttrTokenStream;
99
use crate::{
1010
Arm, AssocItem, AttrItem, AttrKind, AttrVec, Attribute, Block, Crate, Expr, ExprField,
11-
FieldDef, ForeignItem, GenericParam, Item, NodeId, Param, Pat, PatField, Path, Stmt, StmtKind,
12-
Ty, Variant, Visibility, WherePredicate,
11+
FieldDef, ForeignItem, GenericParam, ImplRestriction, Item, NodeId, Param, Pat, PatField, Path,
12+
Stmt, StmtKind, Ty, Variant, Visibility, WherePredicate,
1313
};
1414

1515
/// A trait for AST nodes having an ID.
@@ -97,7 +97,19 @@ macro_rules! impl_has_tokens_none {
9797
};
9898
}
9999

100-
impl_has_tokens!(AssocItem, AttrItem, Block, Expr, ForeignItem, Item, Pat, Path, Ty, Visibility);
100+
impl_has_tokens!(
101+
AssocItem,
102+
AttrItem,
103+
Block,
104+
Expr,
105+
ForeignItem,
106+
Item,
107+
Pat,
108+
Path,
109+
Ty,
110+
Visibility,
111+
ImplRestriction
112+
);
101113
impl_has_tokens_none!(
102114
Arm,
103115
ExprField,
@@ -242,7 +254,7 @@ impl_has_attrs!(
242254
Variant,
243255
WherePredicate,
244256
);
245-
impl_has_attrs_none!(Attribute, AttrItem, Block, Pat, Path, Ty, Visibility);
257+
impl_has_attrs_none!(Attribute, AttrItem, Block, Pat, Path, Ty, Visibility, ImplRestriction);
246258

247259
impl<T: HasAttrs> HasAttrs for Box<T> {
248260
const SUPPORTS_CUSTOM_INNER_ATTRS: bool = T::SUPPORTS_CUSTOM_INNER_ATTRS;

compiler/rustc_ast/src/visit.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ macro_rules! common_visitor_and_walkers {
467467
RangeEnd,
468468
RangeSyntax,
469469
Recovered,
470+
RestrictionKind,
470471
Safety,
471472
StaticItem,
472473
StrLit,
@@ -595,6 +596,7 @@ macro_rules! common_visitor_and_walkers {
595596
fn visit_poly_trait_ref(PolyTraitRef);
596597
fn visit_precise_capturing_arg(PreciseCapturingArg);
597598
fn visit_qself(QSelf);
599+
fn visit_impl_restriction(ImplRestriction);
598600
fn visit_trait_ref(TraitRef);
599601
fn visit_ty_pat(TyPat);
600602
fn visit_ty(Ty);
@@ -1117,6 +1119,7 @@ macro_rules! common_visitor_and_walkers {
11171119
pub fn walk_poly_trait_ref(PolyTraitRef);
11181120
pub fn walk_precise_capturing_arg(PreciseCapturingArg);
11191121
pub fn walk_qself(QSelf);
1122+
pub fn walk_impl_restriction(ImplRestriction);
11201123
pub fn walk_trait_ref(TraitRef);
11211124
pub fn walk_ty_pat(TyPat);
11221125
pub fn walk_ty(Ty);

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
512512
constness,
513513
is_auto,
514514
safety,
515+
// FIXME(impl_restrictions): lower to HIR
516+
impl_restriction: _,
515517
ident,
516518
generics,
517519
bounds,

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
590590
gate_all!(coroutines, "coroutine syntax is experimental");
591591
gate_all!(const_block_items, "const block items are experimental");
592592
gate_all!(final_associated_functions, "`final` on trait functions is experimental");
593+
gate_all!(impl_restriction, "`impl` restrictions are experimental");
593594

594595
if !visitor.features.never_patterns() {
595596
if let Some(spans) = spans.get(&sym::never_patterns) {

compiler/rustc_ast_pretty/src/pprust/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ pub fn vis_to_string(v: &ast::Visibility) -> String {
8080
State::new().vis_to_string(v)
8181
}
8282

83+
pub fn impl_restriction_to_string(r: &ast::ImplRestriction) -> String {
84+
State::new().impl_restriction_to_string(r)
85+
}
86+
8387
pub fn meta_list_item_to_string(li: &ast::MetaItemInner) -> String {
8488
State::new().meta_list_item_to_string(li)
8589
}

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
11101110
Self::to_string(|s| s.print_visibility(v))
11111111
}
11121112

1113+
fn impl_restriction_to_string(&self, r: &ast::ImplRestriction) -> String {
1114+
Self::to_string(|s| s.print_impl_restriction(r))
1115+
}
1116+
11131117
fn block_to_string(&self, blk: &ast::Block) -> String {
11141118
Self::to_string(|s| {
11151119
let (cb, ib) = s.head("");

compiler/rustc_ast_pretty/src/pprust/state/item.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ impl<'a> State<'a> {
365365
constness,
366366
safety,
367367
is_auto,
368+
impl_restriction,
368369
ident,
369370
generics,
370371
bounds,
@@ -375,6 +376,7 @@ impl<'a> State<'a> {
375376
self.print_constness(*constness);
376377
self.print_safety(*safety);
377378
self.print_is_auto(*is_auto);
379+
self.print_impl_restriction(impl_restriction);
378380
self.word_nbsp("trait");
379381
self.print_ident(*ident);
380382
self.print_generic_params(&generics.params);
@@ -483,6 +485,20 @@ impl<'a> State<'a> {
483485
}
484486
}
485487

488+
pub(crate) fn print_impl_restriction(&mut self, impl_restriction: &ast::ImplRestriction) {
489+
match &impl_restriction.kind {
490+
ast::RestrictionKind::Restricted { path, shorthand, .. } => {
491+
let path = Self::to_string(|s| s.print_path(path, false, 0));
492+
if *shorthand {
493+
self.word_nbsp(format!("impl({path})"))
494+
} else {
495+
self.word_nbsp(format!("impl(in {path})"))
496+
}
497+
}
498+
ast::RestrictionKind::Unrestricted => {}
499+
}
500+
}
501+
486502
fn print_defaultness(&mut self, defaultness: ast::Defaultness) {
487503
if let ast::Defaultness::Default(_) = defaultness {
488504
self.word_nbsp("default");

compiler/rustc_codegen_cranelift/src/driver/aot.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use std::thread::JoinHandle;
1010

1111
use cranelift_object::{ObjectBuilder, ObjectModule};
1212
use rustc_codegen_ssa::assert_module_sources::CguReuse;
13-
use rustc_codegen_ssa::back::write::{CompiledModules, produce_final_output_artifacts};
13+
use rustc_codegen_ssa::back::write::produce_final_output_artifacts;
1414
use rustc_codegen_ssa::base::determine_cgu_reuse;
15-
use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind};
15+
use rustc_codegen_ssa::{CompiledModule, CompiledModules, ModuleKind};
1616
use rustc_data_structures::profiling::SelfProfilerRef;
1717
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1818
use rustc_data_structures::sync::{IntoDynSyncSend, par_map};
@@ -54,7 +54,6 @@ impl<HCX> HashStable<HCX> for OngoingModuleCodegen {
5454
pub(crate) struct OngoingCodegen {
5555
modules: Vec<OngoingModuleCodegen>,
5656
allocator_module: Option<CompiledModule>,
57-
crate_info: CrateInfo,
5857
concurrency_limiter: ConcurrencyLimiter,
5958
}
6059

@@ -63,7 +62,7 @@ impl OngoingCodegen {
6362
self,
6463
sess: &Session,
6564
outputs: &OutputFilenames,
66-
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
65+
) -> (CompiledModules, FxIndexMap<WorkProductId, WorkProduct>) {
6766
let mut work_products = FxIndexMap::default();
6867
let mut modules = vec![];
6968
let disable_incr_cache = disable_incr_cache();
@@ -126,15 +125,7 @@ impl OngoingCodegen {
126125

127126
produce_final_output_artifacts(sess, &compiled_modules, outputs);
128127

129-
(
130-
CodegenResults {
131-
crate_info: self.crate_info,
132-
133-
modules: compiled_modules.modules,
134-
allocator_module: compiled_modules.allocator_module,
135-
},
136-
work_products,
137-
)
128+
(compiled_modules, work_products)
138129
}
139130
}
140131

@@ -483,13 +474,6 @@ fn emit_allocator_module(tcx: TyCtxt<'_>) -> Option<CompiledModule> {
483474
}
484475

485476
pub(crate) fn run_aot(tcx: TyCtxt<'_>) -> Box<OngoingCodegen> {
486-
// FIXME handle `-Ctarget-cpu=native`
487-
let target_cpu = match tcx.sess.opts.cg.target_cpu {
488-
Some(ref name) => name,
489-
None => tcx.sess.target.cpu.as_ref(),
490-
}
491-
.to_owned();
492-
493477
let cgus = tcx.collect_and_partition_mono_items(()).codegen_units;
494478

495479
if tcx.dep_graph.is_fully_enabled() {
@@ -549,7 +533,6 @@ pub(crate) fn run_aot(tcx: TyCtxt<'_>) -> Box<OngoingCodegen> {
549533
Box::new(OngoingCodegen {
550534
modules,
551535
allocator_module,
552-
crate_info: CrateInfo::new(tcx, target_cpu),
553536
concurrency_limiter: concurrency_limiter.0,
554537
})
555538
}

compiler/rustc_codegen_cranelift/src/driver/jit.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ use crate::debuginfo::TypeDebugContext;
1616
use crate::prelude::*;
1717
use crate::unwind_module::UnwindModule;
1818

19-
fn create_jit_module(tcx: TyCtxt<'_>) -> (UnwindModule<JITModule>, Option<DebugContext>) {
20-
let crate_info = CrateInfo::new(tcx, "dummy_target_cpu".to_string());
21-
19+
fn create_jit_module(
20+
tcx: TyCtxt<'_>,
21+
crate_info: &CrateInfo,
22+
) -> (UnwindModule<JITModule>, Option<DebugContext>) {
2223
let isa = crate::build_isa(tcx.sess, true);
2324
let mut jit_builder = JITBuilder::with_isa(isa, cranelift_module::default_libcall_names());
2425
crate::compiler_builtins::register_functions_for_jit(&mut jit_builder);
25-
jit_builder.symbol_lookup_fn(dep_symbol_lookup_fn(tcx.sess, crate_info));
26+
jit_builder.symbol_lookup_fn(dep_symbol_lookup_fn(tcx.sess, crate_info.clone()));
2627
let mut jit_module = UnwindModule::new(JITModule::new(jit_builder), false);
2728

2829
let cx = DebugContext::new(tcx, jit_module.isa(), false, "dummy_cgu_name");
@@ -32,14 +33,14 @@ fn create_jit_module(tcx: TyCtxt<'_>) -> (UnwindModule<JITModule>, Option<DebugC
3233
(jit_module, cx)
3334
}
3435

35-
pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec<String>) -> ! {
36+
pub(crate) fn run_jit(tcx: TyCtxt<'_>, crate_info: &CrateInfo, jit_args: Vec<String>) -> ! {
3637
if !tcx.crate_types().contains(&rustc_session::config::CrateType::Executable) {
3738
tcx.dcx().fatal("can't jit non-executable crate");
3839
}
3940

4041
let output_filenames = tcx.output_filenames(());
4142
let should_write_ir = crate::pretty_clif::should_write_ir(tcx.sess);
42-
let (mut jit_module, mut debug_context) = create_jit_module(tcx);
43+
let (mut jit_module, mut debug_context) = create_jit_module(tcx, crate_info);
4344
let mut cached_context = Context::new();
4445

4546
let cgus = tcx.collect_and_partition_mono_items(()).codegen_units;

0 commit comments

Comments
 (0)