Skip to content

Commit 97bf23d

Browse files
committed
Auto merge of #112877 - Nilstrieb:rollup-5g5hegl, r=Nilstrieb
Rollup of 6 pull requests Successful merges: - #112632 (Implement PartialOrd for `Vec`s over different allocators) - #112759 (Make closure_saved_names_of_captured_variables a query. ) - #112772 (Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind`) - #112790 (Syntactically accept `become` expressions (explicit tail calls experiment)) - #112830 (More codegen cleanups) - #112844 (Add retag in MIR transform: `Adt` for `Unique` may contain a reference) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 67da586 + 82e6a16 commit 97bf23d

File tree

137 files changed

+950
-775
lines changed

Some content is hidden

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

137 files changed

+950
-775
lines changed

compiler/rustc_ast/src/ast.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,7 @@ impl Expr {
12951295
ExprKind::Yield(..) => ExprPrecedence::Yield,
12961296
ExprKind::Yeet(..) => ExprPrecedence::Yeet,
12971297
ExprKind::FormatArgs(..) => ExprPrecedence::FormatArgs,
1298+
ExprKind::Become(..) => ExprPrecedence::Become,
12981299
ExprKind::Err => ExprPrecedence::Err,
12991300
}
13001301
}
@@ -1515,6 +1516,11 @@ pub enum ExprKind {
15151516
/// with an optional value to be returned.
15161517
Yeet(Option<P<Expr>>),
15171518

1519+
/// A tail call return, with the value to be returned.
1520+
///
1521+
/// While `.0` must be a function call, we check this later, after parsing.
1522+
Become(P<Expr>),
1523+
15181524
/// Bytes included via `include_bytes!`
15191525
/// Added for optimization purposes to avoid the need to escape
15201526
/// large binary blobs - should always behave like [`ExprKind::Lit`]

compiler/rustc_ast/src/mut_visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
14571457
ExprKind::Yeet(expr) => {
14581458
visit_opt(expr, |expr| vis.visit_expr(expr));
14591459
}
1460+
ExprKind::Become(expr) => vis.visit_expr(expr),
14601461
ExprKind::InlineAsm(asm) => vis.visit_inline_asm(asm),
14611462
ExprKind::FormatArgs(fmt) => vis.visit_format_args(fmt),
14621463
ExprKind::OffsetOf(container, fields) => {

compiler/rustc_ast/src/util/parser.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ pub enum ExprPrecedence {
245245
Ret,
246246
Yield,
247247
Yeet,
248+
Become,
248249

249250
Range,
250251

@@ -298,7 +299,8 @@ impl ExprPrecedence {
298299
| ExprPrecedence::Continue
299300
| ExprPrecedence::Ret
300301
| ExprPrecedence::Yield
301-
| ExprPrecedence::Yeet => PREC_JUMP,
302+
| ExprPrecedence::Yeet
303+
| ExprPrecedence::Become => PREC_JUMP,
302304

303305
// `Range` claims to have higher precedence than `Assign`, but `x .. x = x` fails to
304306
// parse, instead of parsing as `(x .. x) = x`. Giving `Range` a lower precedence

compiler/rustc_ast/src/visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
908908
ExprKind::Yeet(optional_expression) => {
909909
walk_list!(visitor, visit_expr, optional_expression);
910910
}
911+
ExprKind::Become(expr) => visitor.visit_expr(expr),
911912
ExprKind::MacCall(mac) => visitor.visit_mac_call(mac),
912913
ExprKind::Paren(subexpression) => visitor.visit_expr(subexpression),
913914
ExprKind::InlineAsm(asm) => visitor.visit_inline_asm(asm),

compiler/rustc_ast_lowering/src/expr.rs

+6
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
275275
hir::ExprKind::Ret(e)
276276
}
277277
ExprKind::Yeet(sub_expr) => self.lower_expr_yeet(e.span, sub_expr.as_deref()),
278+
ExprKind::Become(sub_expr) => {
279+
let sub_expr = self.lower_expr(sub_expr);
280+
281+
// FIXME(explicit_tail_calls): Use `hir::ExprKind::Become` once we implemented it
282+
hir::ExprKind::Ret(Some(sub_expr))
283+
}
278284
ExprKind::InlineAsm(asm) => {
279285
hir::ExprKind::InlineAsm(self.lower_inline_asm(e.span, asm))
280286
}

compiler/rustc_ast_passes/src/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
555555
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
556556
gate_all!(const_closures, "const closures are experimental");
557557
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");
558+
gate_all!(explicit_tail_calls, "`become` expression is experimental");
558559

559560
if !visitor.features.negative_bounds {
560561
for &span in spans.get(&sym::negative_bounds).iter().copied().flatten() {

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

+5
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,11 @@ impl<'a> State<'a> {
537537
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
538538
}
539539
}
540+
ast::ExprKind::Become(result) => {
541+
self.word("become");
542+
self.word(" ");
543+
self.print_expr_maybe_paren(result, parser::PREC_JUMP);
544+
}
540545
ast::ExprKind::InlineAsm(a) => {
541546
// FIXME: This should have its own syntax, distinct from a macro invocation.
542547
self.word("asm!");

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
679679

680680
// Find out if the predicates show that the type is a Fn or FnMut
681681
let find_fn_kind_from_did = |(pred, _): (ty::Predicate<'tcx>, _)| {
682-
if let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) = pred.kind().skip_binder()
682+
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) = pred.kind().skip_binder()
683683
&& pred.self_ty() == ty
684684
{
685685
if Some(pred.def_id()) == tcx.lang_items().fn_trait() {
@@ -776,7 +776,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
776776
let predicates: Result<Vec<_>, _> = errors
777777
.into_iter()
778778
.map(|err| match err.obligation.predicate.kind().skip_binder() {
779-
PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
779+
PredicateKind::Clause(ty::ClauseKind::Trait(predicate)) => {
780780
match predicate.self_ty().kind() {
781781
ty::Param(param_ty) => Ok((
782782
generics.type_param(param_ty, tcx),

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
939939
{
940940
predicates.iter().any(|pred| {
941941
match pred.kind().skip_binder() {
942-
ty::PredicateKind::Clause(ty::Clause::Trait(data)) if data.self_ty() == ty => {}
943-
ty::PredicateKind::Clause(ty::Clause::Projection(data)) if data.projection_ty.self_ty() == ty => {}
942+
ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) if data.self_ty() == ty => {}
943+
ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) if data.projection_ty.self_ty() == ty => {}
944944
_ => return false,
945945
}
946946
tcx.any_free_region_meets(pred, |r| {

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,9 @@ fn check_opaque_type_well_formed<'tcx>(
330330
// Require the hidden type to be well-formed with only the generics of the opaque type.
331331
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
332332
// hidden type is well formed even without those bounds.
333-
let predicate =
334-
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::WellFormed(definition_ty.into())));
333+
let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(
334+
definition_ty.into(),
335+
)));
335336
ocx.register_obligation(Obligation::misc(tcx, definition_span, def_id, param_env, predicate));
336337

337338
// Check that all obligations are satisfied by the implementation's

compiler/rustc_borrowck/src/type_check/canonical.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
8989
category: ConstraintCategory<'tcx>,
9090
) {
9191
self.prove_predicate(
92-
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::Trait(ty::TraitPredicate {
93-
trait_ref,
94-
constness: ty::BoundConstness::NotConst,
95-
polarity: ty::ImplPolarity::Positive,
96-
}))),
92+
ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::Trait(
93+
ty::TraitPredicate {
94+
trait_ref,
95+
constness: ty::BoundConstness::NotConst,
96+
polarity: ty::ImplPolarity::Positive,
97+
},
98+
))),
9799
locations,
98100
category,
99101
);

compiler/rustc_borrowck/src/type_check/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14211421
// See #91068 for an example.
14221422
self.prove_predicates(
14231423
sig.inputs_and_output.iter().map(|ty| {
1424-
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::WellFormed(
1424+
ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(
14251425
ty.into(),
14261426
)))
14271427
}),
@@ -1853,7 +1853,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18531853

18541854
let array_ty = rvalue.ty(body.local_decls(), tcx);
18551855
self.prove_predicate(
1856-
ty::PredicateKind::Clause(ty::Clause::WellFormed(array_ty.into())),
1856+
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(array_ty.into())),
18571857
Locations::Single(location),
18581858
ConstraintCategory::Boring,
18591859
);
@@ -2026,10 +2026,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20262026
ConstraintCategory::Cast,
20272027
);
20282028

2029-
let outlives_predicate =
2030-
tcx.mk_predicate(Binder::dummy(ty::PredicateKind::Clause(
2031-
ty::Clause::TypeOutlives(ty::OutlivesPredicate(self_ty, *region)),
2032-
)));
2029+
let outlives_predicate = tcx.mk_predicate(Binder::dummy(
2030+
ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(
2031+
ty::OutlivesPredicate(self_ty, *region),
2032+
)),
2033+
));
20332034
self.prove_predicate(
20342035
outlives_predicate,
20352036
location.to_locations(),

compiler/rustc_builtin_macros/src/assert/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
320320
| ExprKind::Underscore
321321
| ExprKind::While(_, _, _)
322322
| ExprKind::Yeet(_)
323+
| ExprKind::Become(_)
323324
| ExprKind::Yield(_) => {}
324325
}
325326
}

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
10311031
build_field_di_node(
10321032
cx,
10331033
closure_or_generator_di_node,
1034-
capture_name,
1034+
capture_name.as_str(),
10351035
cx.size_and_align_of(up_var_ty),
10361036
layout.fields.offset(index),
10371037
DIFlags::FlagZero,

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,7 @@ fn build_union_fields_for_direct_tag_generator<'ll, 'tcx>(
676676
_ => unreachable!(),
677677
};
678678

679-
let (generator_layout, state_specific_upvar_names) =
680-
cx.tcx.generator_layout_and_saved_local_names(generator_def_id);
679+
let generator_layout = cx.tcx.optimized_mir(generator_def_id).generator_layout().unwrap();
681680

682681
let common_upvar_names = cx.tcx.closure_saved_names_of_captured_variables(generator_def_id);
683682
let variant_range = generator_substs.variant_range(generator_def_id, cx.tcx);
@@ -714,7 +713,6 @@ fn build_union_fields_for_direct_tag_generator<'ll, 'tcx>(
714713
generator_type_and_layout,
715714
generator_type_di_node,
716715
generator_layout,
717-
&state_specific_upvar_names,
718716
&common_upvar_names,
719717
);
720718

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir::def::CtorKind;
66
use rustc_index::IndexSlice;
77
use rustc_middle::{
88
bug,
9-
mir::{GeneratorLayout, GeneratorSavedLocal},
9+
mir::GeneratorLayout,
1010
ty::{
1111
self,
1212
layout::{IntegerExt, LayoutOf, PrimitiveExt, TyAndLayout},
@@ -323,8 +323,7 @@ pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>(
323323
generator_type_and_layout: TyAndLayout<'tcx>,
324324
generator_type_di_node: &'ll DIType,
325325
generator_layout: &GeneratorLayout<'tcx>,
326-
state_specific_upvar_names: &IndexSlice<GeneratorSavedLocal, Option<Symbol>>,
327-
common_upvar_names: &[String],
326+
common_upvar_names: &IndexSlice<FieldIdx, Symbol>,
328327
) -> &'ll DIType {
329328
let variant_name = GeneratorSubsts::variant_name(variant_index);
330329
let unique_type_id = UniqueTypeId::for_enum_variant_struct_type(
@@ -357,7 +356,7 @@ pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>(
357356
.map(|field_index| {
358357
let generator_saved_local = generator_layout.variant_fields[variant_index]
359358
[FieldIdx::from_usize(field_index)];
360-
let field_name_maybe = state_specific_upvar_names[generator_saved_local];
359+
let field_name_maybe = generator_layout.field_names[generator_saved_local];
361360
let field_name = field_name_maybe
362361
.as_ref()
363362
.map(|s| Cow::from(s.as_str()))
@@ -380,12 +379,13 @@ pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>(
380379
// Fields that are common to all states
381380
let common_fields: SmallVec<_> = generator_substs
382381
.prefix_tys()
382+
.zip(common_upvar_names)
383383
.enumerate()
384-
.map(|(index, upvar_ty)| {
384+
.map(|(index, (upvar_ty, upvar_name))| {
385385
build_field_di_node(
386386
cx,
387387
variant_struct_type_di_node,
388-
&common_upvar_names[index],
388+
upvar_name.as_str(),
389389
cx.size_and_align_of(upvar_ty),
390390
generator_type_and_layout.fields.offset(index),
391391
DIFlags::FlagZero,

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>(
155155
DIFlags::FlagZero,
156156
),
157157
|cx, generator_type_di_node| {
158-
let (generator_layout, state_specific_upvar_names) =
159-
cx.tcx.generator_layout_and_saved_local_names(generator_def_id);
158+
let generator_layout =
159+
cx.tcx.optimized_mir(generator_def_id).generator_layout().unwrap();
160160

161161
let Variants::Multiple { tag_encoding: TagEncoding::Direct, ref variants, .. } = generator_type_and_layout.variants else {
162162
bug!(
@@ -195,7 +195,6 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>(
195195
generator_type_and_layout,
196196
generator_type_di_node,
197197
generator_layout,
198-
&state_specific_upvar_names,
199198
&common_upvar_names,
200199
),
201200
source_info,

compiler/rustc_codegen_ssa/src/back/write.rs

+22-34
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ use jobserver::{Acquired, Client};
1111
use rustc_ast::attr;
1212
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
1313
use rustc_data_structures::memmap::Mmap;
14-
use rustc_data_structures::profiling::SelfProfilerRef;
15-
use rustc_data_structures::profiling::TimingGuard;
16-
use rustc_data_structures::profiling::VerboseTimingGuard;
14+
use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard};
1715
use rustc_data_structures::sync::Lrc;
1816
use rustc_errors::emitter::Emitter;
1917
use rustc_errors::{translation::Translate, DiagnosticId, FatalError, Handler, Level};
@@ -705,20 +703,6 @@ impl<B: WriteBackendMethods> WorkItem<B> {
705703
}
706704
}
707705

708-
fn start_profiling<'a>(&self, cgcx: &'a CodegenContext<B>) -> TimingGuard<'a> {
709-
match *self {
710-
WorkItem::Optimize(ref m) => {
711-
cgcx.prof.generic_activity_with_arg("codegen_module_optimize", &*m.name)
712-
}
713-
WorkItem::CopyPostLtoArtifacts(ref m) => cgcx
714-
.prof
715-
.generic_activity_with_arg("codegen_copy_artifacts_from_incr_cache", &*m.name),
716-
WorkItem::LTO(ref m) => {
717-
cgcx.prof.generic_activity_with_arg("codegen_module_perform_lto", m.name())
718-
}
719-
}
720-
}
721-
722706
/// Generate a short description of this work item suitable for use as a thread name.
723707
fn short_description(&self) -> String {
724708
// `pthread_setname()` on *nix is limited to 15 characters and longer names are ignored.
@@ -759,21 +743,6 @@ pub enum FatLTOInput<B: WriteBackendMethods> {
759743
InMemory(ModuleCodegen<B::Module>),
760744
}
761745

762-
fn execute_work_item<B: ExtraBackendMethods>(
763-
cgcx: &CodegenContext<B>,
764-
work_item: WorkItem<B>,
765-
) -> Result<WorkItemResult<B>, FatalError> {
766-
let module_config = cgcx.config(work_item.module_kind());
767-
768-
match work_item {
769-
WorkItem::Optimize(module) => execute_optimize_work_item(cgcx, module, module_config),
770-
WorkItem::CopyPostLtoArtifacts(module) => {
771-
Ok(execute_copy_from_cache_work_item(cgcx, module, module_config))
772-
}
773-
WorkItem::LTO(module) => execute_lto_work_item(cgcx, module, module_config),
774-
}
775-
}
776-
777746
/// Actual LTO type we end up choosing based on multiple factors.
778747
pub enum ComputedLtoType {
779748
No,
@@ -1706,8 +1675,27 @@ fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>
17061675
// as a diagnostic was already sent off to the main thread - just
17071676
// surface that there was an error in this worker.
17081677
bomb.result = {
1709-
let _prof_timer = work.start_profiling(&cgcx);
1710-
Some(execute_work_item(&cgcx, work))
1678+
let module_config = cgcx.config(work.module_kind());
1679+
1680+
Some(match work {
1681+
WorkItem::Optimize(m) => {
1682+
let _timer =
1683+
cgcx.prof.generic_activity_with_arg("codegen_module_optimize", &*m.name);
1684+
execute_optimize_work_item(&cgcx, m, module_config)
1685+
}
1686+
WorkItem::CopyPostLtoArtifacts(m) => {
1687+
let _timer = cgcx.prof.generic_activity_with_arg(
1688+
"codegen_copy_artifacts_from_incr_cache",
1689+
&*m.name,
1690+
);
1691+
Ok(execute_copy_from_cache_work_item(&cgcx, m, module_config))
1692+
}
1693+
WorkItem::LTO(m) => {
1694+
let _timer =
1695+
cgcx.prof.generic_activity_with_arg("codegen_module_perform_lto", m.name());
1696+
execute_lto_work_item(&cgcx, m, module_config)
1697+
}
1698+
})
17111699
};
17121700
})
17131701
.expect("failed to spawn thread");

compiler/rustc_data_structures/src/stable_hasher.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::sip128::SipHasher128;
22
use rustc_index::bit_set::{self, BitSet};
3-
use rustc_index::{Idx, IndexVec};
3+
use rustc_index::{Idx, IndexSlice, IndexVec};
44
use smallvec::SmallVec;
55
use std::fmt;
66
use std::hash::{BuildHasher, Hash, Hasher};
@@ -597,6 +597,18 @@ where
597597
}
598598
}
599599

600+
impl<I: Idx, T, CTX> HashStable<CTX> for IndexSlice<I, T>
601+
where
602+
T: HashStable<CTX>,
603+
{
604+
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
605+
self.len().hash_stable(ctx, hasher);
606+
for v in &self.raw {
607+
v.hash_stable(ctx, hasher);
608+
}
609+
}
610+
}
611+
600612
impl<I: Idx, T, CTX> HashStable<CTX> for IndexVec<I, T>
601613
where
602614
T: HashStable<CTX>,

0 commit comments

Comments
 (0)