Skip to content

Commit 682f224

Browse files
authored
Unrolled build for #142801
Rollup merge of #142801 - compiler-errors:gen-blocks, r=oli-obk Use gen blocks in the compiler instead of `from_coroutine` r? oli-obk
2 parents df4ad9e + 48060c9 commit 682f224

File tree

7 files changed

+139
-154
lines changed

7 files changed

+139
-154
lines changed

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 64 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,84 +2177,80 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
21772177
/// Walk the generics of the item for a trait bound whose self type
21782178
/// corresponds to the expected res, and return the trait def id.
21792179
fn for_each_trait_bound_on_res(&self, expected_res: Res) -> impl Iterator<Item = DefId> {
2180-
std::iter::from_coroutine(
2181-
#[coroutine]
2182-
move || {
2183-
let mut scope = self.scope;
2184-
loop {
2185-
let hir_id = match *scope {
2186-
Scope::Binder { hir_id, .. } => Some(hir_id),
2187-
Scope::Root { opt_parent_item: Some(parent_def_id) } => {
2188-
Some(self.tcx.local_def_id_to_hir_id(parent_def_id))
2189-
}
2190-
Scope::Body { .. }
2191-
| Scope::ObjectLifetimeDefault { .. }
2192-
| Scope::Supertrait { .. }
2193-
| Scope::TraitRefBoundary { .. }
2194-
| Scope::LateBoundary { .. }
2195-
| Scope::Opaque { .. }
2196-
| Scope::Root { opt_parent_item: None } => None,
2197-
};
2180+
gen move {
2181+
let mut scope = self.scope;
2182+
loop {
2183+
let hir_id = match *scope {
2184+
Scope::Binder { hir_id, .. } => Some(hir_id),
2185+
Scope::Root { opt_parent_item: Some(parent_def_id) } => {
2186+
Some(self.tcx.local_def_id_to_hir_id(parent_def_id))
2187+
}
2188+
Scope::Body { .. }
2189+
| Scope::ObjectLifetimeDefault { .. }
2190+
| Scope::Supertrait { .. }
2191+
| Scope::TraitRefBoundary { .. }
2192+
| Scope::LateBoundary { .. }
2193+
| Scope::Opaque { .. }
2194+
| Scope::Root { opt_parent_item: None } => None,
2195+
};
21982196

2199-
if let Some(hir_id) = hir_id {
2200-
let node = self.tcx.hir_node(hir_id);
2201-
// If this is a `Self` bound in a trait, yield the trait itself.
2202-
// Specifically, we don't need to look at any supertraits since
2203-
// we already do that in `BoundVarContext::supertrait_hrtb_vars`.
2204-
if let Res::SelfTyParam { trait_: _ } = expected_res
2205-
&& let hir::Node::Item(item) = node
2206-
&& let hir::ItemKind::Trait(..) = item.kind
2207-
{
2208-
// Yield the trait's def id. Supertraits will be
2209-
// elaborated from that.
2210-
yield item.owner_id.def_id.to_def_id();
2211-
} else if let Some(generics) = node.generics() {
2212-
for pred in generics.predicates {
2213-
let hir::WherePredicateKind::BoundPredicate(pred) = pred.kind
2214-
else {
2215-
continue;
2216-
};
2217-
let hir::TyKind::Path(hir::QPath::Resolved(None, bounded_path)) =
2218-
pred.bounded_ty.kind
2219-
else {
2220-
continue;
2221-
};
2222-
// Match the expected res.
2223-
if bounded_path.res != expected_res {
2224-
continue;
2225-
}
2226-
for pred in pred.bounds {
2227-
match pred {
2228-
hir::GenericBound::Trait(poly_trait_ref) => {
2229-
if let Some(def_id) =
2230-
poly_trait_ref.trait_ref.trait_def_id()
2231-
{
2232-
yield def_id;
2233-
}
2197+
if let Some(hir_id) = hir_id {
2198+
let node = self.tcx.hir_node(hir_id);
2199+
// If this is a `Self` bound in a trait, yield the trait itself.
2200+
// Specifically, we don't need to look at any supertraits since
2201+
// we already do that in `BoundVarContext::supertrait_hrtb_vars`.
2202+
if let Res::SelfTyParam { trait_: _ } = expected_res
2203+
&& let hir::Node::Item(item) = node
2204+
&& let hir::ItemKind::Trait(..) = item.kind
2205+
{
2206+
// Yield the trait's def id. Supertraits will be
2207+
// elaborated from that.
2208+
yield item.owner_id.def_id.to_def_id();
2209+
} else if let Some(generics) = node.generics() {
2210+
for pred in generics.predicates {
2211+
let hir::WherePredicateKind::BoundPredicate(pred) = pred.kind else {
2212+
continue;
2213+
};
2214+
let hir::TyKind::Path(hir::QPath::Resolved(None, bounded_path)) =
2215+
pred.bounded_ty.kind
2216+
else {
2217+
continue;
2218+
};
2219+
// Match the expected res.
2220+
if bounded_path.res != expected_res {
2221+
continue;
2222+
}
2223+
for pred in pred.bounds {
2224+
match pred {
2225+
hir::GenericBound::Trait(poly_trait_ref) => {
2226+
if let Some(def_id) =
2227+
poly_trait_ref.trait_ref.trait_def_id()
2228+
{
2229+
yield def_id;
22342230
}
2235-
hir::GenericBound::Outlives(_)
2236-
| hir::GenericBound::Use(_, _) => {}
22372231
}
2232+
hir::GenericBound::Outlives(_)
2233+
| hir::GenericBound::Use(_, _) => {}
22382234
}
22392235
}
22402236
}
22412237
}
2238+
}
22422239

2243-
match *scope {
2244-
Scope::Binder { s, .. }
2245-
| Scope::Body { s, .. }
2246-
| Scope::ObjectLifetimeDefault { s, .. }
2247-
| Scope::Supertrait { s, .. }
2248-
| Scope::TraitRefBoundary { s }
2249-
| Scope::LateBoundary { s, .. }
2250-
| Scope::Opaque { s, .. } => {
2251-
scope = s;
2252-
}
2253-
Scope::Root { .. } => break,
2240+
match *scope {
2241+
Scope::Binder { s, .. }
2242+
| Scope::Body { s, .. }
2243+
| Scope::ObjectLifetimeDefault { s, .. }
2244+
| Scope::Supertrait { s, .. }
2245+
| Scope::TraitRefBoundary { s }
2246+
| Scope::LateBoundary { s, .. }
2247+
| Scope::Opaque { s, .. } => {
2248+
scope = s;
22542249
}
2250+
Scope::Root { .. } => break,
22552251
}
2256-
},
2257-
)
2252+
}
2253+
}
22582254
}
22592255
}
22602256

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ This API is completely unstable and subject to change.
6262
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
6363
#![doc(rust_logo)]
6464
#![feature(assert_matches)]
65-
#![feature(coroutines)]
6665
#![feature(debug_closure_helpers)]
66+
#![feature(gen_blocks)]
6767
#![feature(if_let_guard)]
6868
#![feature(iter_from_coroutine)]
6969
#![feature(iter_intersperse)]

compiler/rustc_metadata/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#![allow(internal_features)]
33
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
44
#![doc(rust_logo)]
5-
#![feature(coroutines)]
65
#![feature(decl_macro)]
76
#![feature(error_iter)]
87
#![feature(file_buffered)]
8+
#![feature(gen_blocks)]
99
#![feature(if_let_guard)]
1010
#![feature(iter_from_coroutine)]
1111
#![feature(macro_metavar_expr)]

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::iter::TrustedLen;
44
use std::path::{Path, PathBuf};
55
use std::sync::{Arc, OnceLock};
6-
use std::{io, iter, mem};
6+
use std::{io, mem};
77

88
pub(super) use cstore_impl::provide;
99
use rustc_ast as ast;
@@ -1272,34 +1272,30 @@ impl<'a> CrateMetadataRef<'a> {
12721272
id: DefIndex,
12731273
sess: &'a Session,
12741274
) -> impl Iterator<Item = ModChild> {
1275-
iter::from_coroutine(
1276-
#[coroutine]
1277-
move || {
1278-
if let Some(data) = &self.root.proc_macro_data {
1279-
// If we are loading as a proc macro, we want to return
1280-
// the view of this crate as a proc macro crate.
1281-
if id == CRATE_DEF_INDEX {
1282-
for child_index in data.macros.decode(self) {
1283-
yield self.get_mod_child(child_index, sess);
1284-
}
1285-
}
1286-
} else {
1287-
// Iterate over all children.
1288-
let non_reexports =
1289-
self.root.tables.module_children_non_reexports.get(self, id);
1290-
for child_index in non_reexports.unwrap().decode(self) {
1275+
gen move {
1276+
if let Some(data) = &self.root.proc_macro_data {
1277+
// If we are loading as a proc macro, we want to return
1278+
// the view of this crate as a proc macro crate.
1279+
if id == CRATE_DEF_INDEX {
1280+
for child_index in data.macros.decode(self) {
12911281
yield self.get_mod_child(child_index, sess);
12921282
}
1283+
}
1284+
} else {
1285+
// Iterate over all children.
1286+
let non_reexports = self.root.tables.module_children_non_reexports.get(self, id);
1287+
for child_index in non_reexports.unwrap().decode(self) {
1288+
yield self.get_mod_child(child_index, sess);
1289+
}
12931290

1294-
let reexports = self.root.tables.module_children_reexports.get(self, id);
1295-
if !reexports.is_default() {
1296-
for reexport in reexports.decode((self, sess)) {
1297-
yield reexport;
1298-
}
1291+
let reexports = self.root.tables.module_children_reexports.get(self, id);
1292+
if !reexports.is_default() {
1293+
for reexport in reexports.decode((self, sess)) {
1294+
yield reexport;
12991295
}
13001296
}
1301-
},
1302-
)
1297+
}
1298+
}
13031299
}
13041300

13051301
fn is_ctfe_mir_available(self, id: DefIndex) -> bool {

compiler/rustc_middle/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
#![feature(box_patterns)]
4141
#![feature(closure_track_caller)]
4242
#![feature(core_intrinsics)]
43-
#![feature(coroutines)]
4443
#![feature(debug_closure_helpers)]
4544
#![feature(decl_macro)]
4645
#![feature(discriminant_kind)]
4746
#![feature(extern_types)]
4847
#![feature(file_buffered)]
48+
#![feature(gen_blocks)]
4949
#![feature(if_let_guard)]
5050
#![feature(intra_doc_pointers)]
5151
#![feature(iter_from_coroutine)]

compiler/rustc_middle/src/ty/closure.rs

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -422,53 +422,49 @@ pub fn analyze_coroutine_closure_captures<'a, 'tcx: 'a, T>(
422422
child_captures: impl IntoIterator<Item = &'a CapturedPlace<'tcx>>,
423423
mut for_each: impl FnMut((usize, &'a CapturedPlace<'tcx>), (usize, &'a CapturedPlace<'tcx>)) -> T,
424424
) -> impl Iterator<Item = T> {
425-
std::iter::from_coroutine(
426-
#[coroutine]
427-
move || {
428-
let mut child_captures = child_captures.into_iter().enumerate().peekable();
429-
430-
// One parent capture may correspond to several child captures if we end up
431-
// refining the set of captures via edition-2021 precise captures. We want to
432-
// match up any number of child captures with one parent capture, so we keep
433-
// peeking off this `Peekable` until the child doesn't match anymore.
434-
for (parent_field_idx, parent_capture) in parent_captures.into_iter().enumerate() {
435-
// Make sure we use every field at least once, b/c why are we capturing something
436-
// if it's not used in the inner coroutine.
437-
let mut field_used_at_least_once = false;
438-
439-
// A parent matches a child if they share the same prefix of projections.
440-
// The child may have more, if it is capturing sub-fields out of
441-
// something that is captured by-move in the parent closure.
442-
while child_captures.peek().is_some_and(|(_, child_capture)| {
443-
child_prefix_matches_parent_projections(parent_capture, child_capture)
444-
}) {
445-
let (child_field_idx, child_capture) = child_captures.next().unwrap();
446-
// This analysis only makes sense if the parent capture is a
447-
// prefix of the child capture.
448-
assert!(
449-
child_capture.place.projections.len()
450-
>= parent_capture.place.projections.len(),
451-
"parent capture ({parent_capture:#?}) expected to be prefix of \
425+
gen move {
426+
let mut child_captures = child_captures.into_iter().enumerate().peekable();
427+
428+
// One parent capture may correspond to several child captures if we end up
429+
// refining the set of captures via edition-2021 precise captures. We want to
430+
// match up any number of child captures with one parent capture, so we keep
431+
// peeking off this `Peekable` until the child doesn't match anymore.
432+
for (parent_field_idx, parent_capture) in parent_captures.into_iter().enumerate() {
433+
// Make sure we use every field at least once, b/c why are we capturing something
434+
// if it's not used in the inner coroutine.
435+
let mut field_used_at_least_once = false;
436+
437+
// A parent matches a child if they share the same prefix of projections.
438+
// The child may have more, if it is capturing sub-fields out of
439+
// something that is captured by-move in the parent closure.
440+
while child_captures.peek().is_some_and(|(_, child_capture)| {
441+
child_prefix_matches_parent_projections(parent_capture, child_capture)
442+
}) {
443+
let (child_field_idx, child_capture) = child_captures.next().unwrap();
444+
// This analysis only makes sense if the parent capture is a
445+
// prefix of the child capture.
446+
assert!(
447+
child_capture.place.projections.len() >= parent_capture.place.projections.len(),
448+
"parent capture ({parent_capture:#?}) expected to be prefix of \
452449
child capture ({child_capture:#?})"
453-
);
454-
455-
yield for_each(
456-
(parent_field_idx, parent_capture),
457-
(child_field_idx, child_capture),
458-
);
459-
460-
field_used_at_least_once = true;
461-
}
450+
);
462451

463-
// Make sure the field was used at least once.
464-
assert!(
465-
field_used_at_least_once,
466-
"we captured {parent_capture:#?} but it was not used in the child coroutine?"
452+
yield for_each(
453+
(parent_field_idx, parent_capture),
454+
(child_field_idx, child_capture),
467455
);
456+
457+
field_used_at_least_once = true;
468458
}
469-
assert_eq!(child_captures.next(), None, "leftover child captures?");
470-
},
471-
)
459+
460+
// Make sure the field was used at least once.
461+
assert!(
462+
field_used_at_least_once,
463+
"we captured {parent_capture:#?} but it was not used in the child coroutine?"
464+
);
465+
}
466+
assert_eq!(child_captures.next(), None, "leftover child captures?");
467+
}
472468
}
473469

474470
fn child_prefix_matches_parent_projections(

compiler/rustc_middle/src/ty/context.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,23 +2087,20 @@ impl<'tcx> TyCtxt<'tcx> {
20872087
self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE);
20882088

20892089
let definitions = &self.untracked.definitions;
2090-
std::iter::from_coroutine(
2091-
#[coroutine]
2092-
|| {
2093-
let mut i = 0;
2094-
2095-
// Recompute the number of definitions each time, because our caller may be creating
2096-
// new ones.
2097-
while i < { definitions.read().num_definitions() } {
2098-
let local_def_index = rustc_span::def_id::DefIndex::from_usize(i);
2099-
yield LocalDefId { local_def_index };
2100-
i += 1;
2101-
}
2090+
gen {
2091+
let mut i = 0;
2092+
2093+
// Recompute the number of definitions each time, because our caller may be creating
2094+
// new ones.
2095+
while i < { definitions.read().num_definitions() } {
2096+
let local_def_index = rustc_span::def_id::DefIndex::from_usize(i);
2097+
yield LocalDefId { local_def_index };
2098+
i += 1;
2099+
}
21022100

2103-
// Freeze definitions once we finish iterating on them, to prevent adding new ones.
2104-
definitions.freeze();
2105-
},
2106-
)
2101+
// Freeze definitions once we finish iterating on them, to prevent adding new ones.
2102+
definitions.freeze();
2103+
}
21072104
}
21082105

21092106
pub fn def_path_table(self) -> &'tcx rustc_hir::definitions::DefPathTable {

0 commit comments

Comments
 (0)