Skip to content

Commit b28572e

Browse files
committed
Auto merge of rust-lang#118436 - bvanjoi:merge_coroutinue_into_closure_3, r=<try>
revert for benchmark This PR reverts rust-lang#118311 and rust-lang#118188, with the intent to assess the performance impact brought about by rust-lang#118311
2 parents f440b5f + 6caa433 commit b28572e

File tree

41 files changed

+276
-248
lines changed

Some content is hidden

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

41 files changed

+276
-248
lines changed

compiler/rustc_ast_lowering/src/asm.rs

-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
228228
parent_def_id.def_id,
229229
node_id,
230230
DefPathData::AnonConst,
231-
DefKind::AnonConst,
232231
*op_sp,
233232
);
234233
let anon_const = AnonConst { id: node_id, value: P(expr) };

compiler/rustc_ast_lowering/src/expr.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_ast::ptr::P as AstP;
1212
use rustc_ast::*;
1313
use rustc_data_structures::stack::ensure_sufficient_stack;
1414
use rustc_hir as hir;
15-
use rustc_hir::def::{DefKind, Res};
15+
use rustc_hir::def::Res;
1616
use rustc_hir::definitions::DefPathData;
1717
use rustc_session::errors::report_lit_error;
1818
use rustc_span::source_map::{respan, Spanned};
@@ -395,13 +395,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
395395
let node_id = self.next_node_id();
396396

397397
// Add a definition for the in-band const def.
398-
self.create_def(
399-
parent_def_id.def_id,
400-
node_id,
401-
DefPathData::AnonConst,
402-
DefKind::AnonConst,
403-
f.span,
404-
);
398+
self.create_def(parent_def_id.def_id, node_id, DefPathData::AnonConst, f.span);
405399

406400
let anon_const = AnonConst { id: node_id, value: arg };
407401
generic_args.push(AngleBracketedArg::Arg(GenericArg::Const(anon_const)));

compiler/rustc_ast_lowering/src/index.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
8989
}
9090
}
9191

92-
self.nodes.insert(hir_id.local_id, ParentedNode { parent: self.parent_node, node });
92+
self.nodes.insert(hir_id.local_id, ParentedNode { parent: self.parent_node, node: node });
9393
}
9494

9595
fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_node_id: HirId, f: F) {

compiler/rustc_ast_lowering/src/item.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
480480
}
481481
ItemKind::MacroDef(MacroDef { body, macro_rules }) => {
482482
let body = P(self.lower_delim_args(body));
483-
let DefKind::Macro(macro_kind) = self.tcx.def_kind(self.local_def_id(id)) else {
484-
unreachable!()
485-
};
483+
let macro_kind = self.resolver.decl_macro_kind(self.local_def_id(id));
486484
let macro_def = self.arena.alloc(ast::MacroDef { body, macro_rules: *macro_rules });
487485
hir::ItemKind::Macro(macro_def, macro_kind)
488486
}
@@ -1401,7 +1399,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
14011399
self.local_def_id(parent_node_id),
14021400
param_node_id,
14031401
DefPathData::TypeNs(sym::host),
1404-
DefKind::ConstParam,
14051402
span,
14061403
);
14071404
self.host_param_id = Some(def_id);
@@ -1460,13 +1457,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
14601457

14611458
if let Some((span, hir_id, def_id)) = host_param_parts {
14621459
let const_node_id = self.next_node_id();
1463-
let anon_const = self.create_def(
1464-
def_id,
1465-
const_node_id,
1466-
DefPathData::AnonConst,
1467-
DefKind::AnonConst,
1468-
span,
1469-
);
1460+
let anon_const: LocalDefId =
1461+
self.create_def(def_id, const_node_id, DefPathData::AnonConst, span);
14701462

14711463
let const_id = self.next_id();
14721464
let const_expr_id = self.next_id();

compiler/rustc_ast_lowering/src/lib.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ use rustc_middle::{
6767
ty::{ResolverAstLowering, TyCtxt},
6868
};
6969
use rustc_session::parse::{add_feature_diagnostics, feature_err};
70+
use rustc_span::hygiene::MacroKind;
7071
use rustc_span::symbol::{kw, sym, Ident, Symbol};
7172
use rustc_span::{DesugaringKind, Span, DUMMY_SP};
7273
use smallvec::SmallVec;
@@ -152,6 +153,7 @@ trait ResolverAstLoweringExt {
152153
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes>;
153154
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)>;
154155
fn remap_extra_lifetime_params(&mut self, from: NodeId, to: NodeId);
156+
fn decl_macro_kind(&self, def_id: LocalDefId) -> MacroKind;
155157
}
156158

157159
impl ResolverAstLoweringExt for ResolverAstLowering {
@@ -215,6 +217,10 @@ impl ResolverAstLoweringExt for ResolverAstLowering {
215217
let lifetimes = self.extra_lifetime_params_map.remove(&from).unwrap_or_default();
216218
self.extra_lifetime_params_map.insert(to, lifetimes);
217219
}
220+
221+
fn decl_macro_kind(&self, def_id: LocalDefId) -> MacroKind {
222+
self.builtin_macro_kinds.get(&def_id).copied().unwrap_or(MacroKind::Bang)
223+
}
218224
}
219225

220226
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
@@ -461,7 +467,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
461467
parent: LocalDefId,
462468
node_id: ast::NodeId,
463469
data: DefPathData,
464-
def_kind: DefKind,
465470
span: Span,
466471
) -> LocalDefId {
467472
debug_assert_ne!(node_id, ast::DUMMY_NODE_ID);
@@ -473,7 +478,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
473478
self.tcx.hir().def_key(self.local_def_id(node_id)),
474479
);
475480

476-
let def_id = self.tcx.at(span).create_def(parent, data, def_kind).def_id();
481+
let def_id = self.tcx.at(span).create_def(parent, data).def_id();
477482

478483
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
479484
self.resolver.node_id_to_def_id.insert(node_id, def_id);
@@ -775,7 +780,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
775780
self.current_hir_id_owner.def_id,
776781
param,
777782
DefPathData::LifetimeNs(kw::UnderscoreLifetime),
778-
DefKind::LifetimeParam,
779783
ident.span,
780784
);
781785
debug!(?_def_id);
@@ -1188,7 +1192,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11881192
parent_def_id.def_id,
11891193
node_id,
11901194
DefPathData::AnonConst,
1191-
DefKind::AnonConst,
11921195
span,
11931196
);
11941197

@@ -1426,7 +1429,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14261429
self.current_hir_id_owner.def_id,
14271430
*def_node_id,
14281431
DefPathData::TypeNs(ident.name),
1429-
DefKind::TyParam,
14301432
span,
14311433
);
14321434
let (param, bounds, path) = self.lower_universal_param_and_bounds(
@@ -1580,7 +1582,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15801582
self.current_hir_id_owner.def_id,
15811583
opaque_ty_node_id,
15821584
DefPathData::ImplTrait,
1583-
DefKind::OpaqueTy,
15841585
opaque_ty_span,
15851586
);
15861587
debug!(?opaque_ty_def_id);
@@ -1635,7 +1636,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16351636
opaque_ty_def_id,
16361637
duplicated_lifetime_node_id,
16371638
DefPathData::LifetimeNs(lifetime.ident.name),
1638-
DefKind::LifetimeParam,
16391639
lifetime.ident.span,
16401640
);
16411641
captured_to_synthesized_mapping.insert(old_def_id, duplicated_lifetime_def_id);
@@ -2505,13 +2505,8 @@ impl<'hir> GenericArgsCtor<'hir> {
25052505
});
25062506
lcx.attrs.insert(hir_id.local_id, std::slice::from_ref(attr));
25072507

2508-
let def_id = lcx.create_def(
2509-
lcx.current_hir_id_owner.def_id,
2510-
id,
2511-
DefPathData::AnonConst,
2512-
DefKind::AnonConst,
2513-
span,
2514-
);
2508+
let def_id =
2509+
lcx.create_def(lcx.current_hir_id_owner.def_id, id, DefPathData::AnonConst, span);
25152510
lcx.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
25162511
self.args.push(hir::GenericArg::Const(hir::ConstArg {
25172512
value: hir::AnonConst { def_id, hir_id, body },

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -2072,15 +2072,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20722072
.map(|name| format!("function `{name}`"))
20732073
.unwrap_or_else(|| {
20742074
match &self.infcx.tcx.def_kind(self.mir_def_id()) {
2075-
DefKind::Closure
2076-
if self
2077-
.infcx
2078-
.tcx
2079-
.is_coroutine(self.mir_def_id().to_def_id()) =>
2080-
{
2081-
"enclosing coroutine"
2082-
}
20832075
DefKind::Closure => "enclosing closure",
2076+
DefKind::Coroutine => "enclosing coroutine",
20842077
kind => bug!("expected closure or coroutine, found {:?}", kind),
20852078
}
20862079
.to_string()

compiler/rustc_borrowck/src/type_check/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2678,10 +2678,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26782678
let typeck_root_args = ty::GenericArgs::identity_for_item(tcx, typeck_root_def_id);
26792679

26802680
let parent_args = match tcx.def_kind(def_id) {
2681-
DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => {
2682-
args.as_coroutine().parent_args()
2683-
}
26842681
DefKind::Closure => args.as_closure().parent_args(),
2682+
DefKind::Coroutine => args.as_coroutine().parent_args(),
26852683
DefKind::InlineConst => args.as_inline_const().parent_args(),
26862684
other => bug!("unexpected item {:?}", other),
26872685
};

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,10 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {
373373
// just "functions", like consts, statics, etc. Filter those out.
374374
// If `ignore_unused_generics` was specified, filter out any
375375
// generic functions from consideration as well.
376-
if !matches!(kind, DefKind::Fn | DefKind::AssocFn | DefKind::Closure) {
376+
if !matches!(
377+
kind,
378+
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Coroutine
379+
) {
377380
return None;
378381
}
379382
if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) {

compiler/rustc_hir/src/def.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ pub enum DefKind {
114114
of_trait: bool,
115115
},
116116
Closure,
117+
Coroutine,
117118
}
118119

119120
impl DefKind {
@@ -156,6 +157,7 @@ impl DefKind {
156157
DefKind::Field => "field",
157158
DefKind::Impl { .. } => "implementation",
158159
DefKind::Closure => "closure",
160+
DefKind::Coroutine => "coroutine",
159161
DefKind::ExternCrate => "extern crate",
160162
DefKind::GlobalAsm => "global assembly block",
161163
}
@@ -214,6 +216,7 @@ impl DefKind {
214216
| DefKind::LifetimeParam
215217
| DefKind::ExternCrate
216218
| DefKind::Closure
219+
| DefKind::Coroutine
217220
| DefKind::Use
218221
| DefKind::ForeignMod
219222
| DefKind::GlobalAsm
@@ -223,7 +226,7 @@ impl DefKind {
223226

224227
#[inline]
225228
pub fn is_fn_like(self) -> bool {
226-
matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure)
229+
matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Coroutine)
227230
}
228231

229232
/// Whether `query get_codegen_attrs` should be used with this definition.
@@ -233,6 +236,7 @@ impl DefKind {
233236
| DefKind::AssocFn
234237
| DefKind::Ctor(..)
235238
| DefKind::Closure
239+
| DefKind::Coroutine
236240
| DefKind::Static(_) => true,
237241
DefKind::Mod
238242
| DefKind::Struct

compiler/rustc_hir_analysis/src/check/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ fn opaque_type_cycle_error(
14491449
label_match(capture.place.ty(), capture.get_path_span(tcx));
14501450
}
14511451
// Label any coroutine locals that capture the opaque
1452-
if tcx.is_coroutine(closure_def_id)
1452+
if let DefKind::Coroutine = tcx.def_kind(closure_def_id)
14531453
&& let Some(coroutine_layout) = tcx.mir_coroutine_witnesses(closure_def_id)
14541454
{
14551455
for interior_ty in &coroutine_layout.field_tys {
@@ -1470,7 +1470,7 @@ pub(super) fn check_coroutine_obligations(
14701470
tcx: TyCtxt<'_>,
14711471
def_id: LocalDefId,
14721472
) -> Result<(), ErrorGuaranteed> {
1473-
debug_assert!(tcx.is_coroutine(def_id.to_def_id()));
1473+
debug_assert!(matches!(tcx.def_kind(def_id), DefKind::Coroutine));
14741474

14751475
let typeck = tcx.typeck(def_id);
14761476
let param_env = tcx.param_env(def_id);

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
757757
});
758758

759759
tcx.hir().par_body_owners(|def_id| {
760-
if tcx.is_coroutine(def_id.to_def_id()) {
760+
if let rustc_hir::def::DefKind::Coroutine = tcx.def_kind(def_id) {
761761
tcx.ensure().mir_coroutine_witnesses(def_id);
762762
tcx.ensure().check_coroutine_obligations(def_id);
763763
}

compiler/rustc_interface/src/queries.rs

-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_codegen_ssa::CodegenResults;
88
use rustc_data_structures::steal::Steal;
99
use rustc_data_structures::svh::Svh;
1010
use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, OnceLock, WorkerLocal};
11-
use rustc_hir::def::DefKind;
1211
use rustc_hir::def_id::{StableCrateId, CRATE_DEF_ID, LOCAL_CRATE};
1312
use rustc_hir::definitions::Definitions;
1413
use rustc_incremental::setup_dep_graph;
@@ -172,9 +171,6 @@ impl<'tcx> Queries<'tcx> {
172171
)));
173172
feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs))));
174173
feed.output_filenames(Arc::new(outputs));
175-
176-
let feed = tcx.feed_local_def_id(CRATE_DEF_ID);
177-
feed.def_kind(DefKind::Mod);
178174
});
179175
Ok(qcx)
180176
})

0 commit comments

Comments
 (0)