Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5d16c54
Extend tidy alphabetical checking to `tests/`.
nnethercote Dec 8, 2023
d2d742c
coverage: Add a dedicated test for coverage of `if !`
Zalathar Nov 23, 2023
44b47aa
coverage: Add `CoverageKind::SpanMarker` for including extra spans in…
Zalathar Nov 23, 2023
9816635
coverage: Use `SpanMarker` to mark `continue` expressions.
Zalathar Nov 23, 2023
d90fd02
coverage: Use `SpanMarker` to mark the full condition of `if !`
Zalathar Nov 23, 2023
e0cd805
coverage: Simplify the heuristic for ignoring `async fn` return spans
Zalathar Dec 6, 2023
cec8142
coverage: Add `#[track_caller]` to the span generator's unwrap methods
Zalathar Dec 6, 2023
e01338a
coverage: Regression test for unwrapping `prev` when there are no spans
Zalathar Dec 8, 2023
b378059
update target feature following LLVM API change
krasimirgg Dec 4, 2023
287c77e
Add tests related to normalization in implied bounds
spastorino Dec 1, 2023
8361a72
Introduce closure_id method on CoroutineKind
compiler-errors Dec 8, 2023
d5dcd85
More nits
compiler-errors Dec 8, 2023
384a49e
Rename some more coro_kind -> coroutine_kind
compiler-errors Dec 8, 2023
e987812
Make async generators fused by default
compiler-errors Dec 8, 2023
7079adb
Add Bevy related test cases
spastorino Dec 8, 2023
a71ab45
Rollup merge of #118198 - Zalathar:if-not, r=cjgillot
workingjubilee Dec 9, 2023
8f9d827
Rollup merge of #118512 - spastorino:add-implied-bounds-related-tests…
workingjubilee Dec 9, 2023
85c9de9
Rollup merge of #118610 - krasimirgg:llvm-18-dec, r=nikic
workingjubilee Dec 9, 2023
feb8793
Rollup merge of #118666 - Zalathar:body-closure, r=cjgillot
workingjubilee Dec 9, 2023
ad91141
Rollup merge of #118737 - nnethercote:tidy-alphabetical-in-testsa, r=…
workingjubilee Dec 9, 2023
402cfb1
Rollup merge of #118762 - compiler-errors:gen-nits, r=eholk
workingjubilee Dec 9, 2023
61dfb1f
Rollup merge of #118764 - compiler-errors:fused-async-iterator, r=eholk
workingjubilee Dec 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 33 additions & 11 deletions compiler/rustc_mir_transform/src/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ struct TransformVisitor<'tcx> {

impl<'tcx> TransformVisitor<'tcx> {
fn insert_none_ret_block(&self, body: &mut Body<'tcx>) -> BasicBlock {
assert!(matches!(self.coroutine_kind, CoroutineKind::Gen(_)));

let block = BasicBlock::new(body.basic_blocks.len());
let source_info = SourceInfo::outermost(body.span);
let option_def_id = self.tcx.require_lang_item(LangItem::Option, None);

let statements = vec![Statement {
kind: StatementKind::Assign(Box::new((
Place::return_place(),
let none_value = match self.coroutine_kind {
CoroutineKind::Async(_) => span_bug!(body.span, "`Future`s are not fused inherently"),
CoroutineKind::Coroutine => span_bug!(body.span, "`Coroutine`s cannot be fused"),
// `gen` continues return `None`
CoroutineKind::Gen(_) => {
let option_def_id = self.tcx.require_lang_item(LangItem::Option, None);
Rvalue::Aggregate(
Box::new(AggregateKind::Adt(
option_def_id,
Expand All @@ -270,8 +270,29 @@ impl<'tcx> TransformVisitor<'tcx> {
None,
)),
IndexVec::new(),
),
))),
)
}
// `async gen` continues to return `Poll::Ready(None)`
CoroutineKind::AsyncGen(_) => {
let ty::Adt(_poll_adt, args) = *self.old_yield_ty.kind() else { bug!() };
let ty::Adt(_option_adt, args) = *args.type_at(0).kind() else { bug!() };
let yield_ty = args.type_at(0);
Rvalue::Use(Operand::Constant(Box::new(ConstOperand {
span: source_info.span,
const_: Const::Unevaluated(
UnevaluatedConst::new(
self.tcx.require_lang_item(LangItem::AsyncGenFinished, None),
self.tcx.mk_args(&[yield_ty.into()]),
),
self.old_yield_ty,
),
user_ty: None,
})))
}
};

let statements = vec![Statement {
kind: StatementKind::Assign(Box::new((Place::return_place(), none_value))),
source_info,
}];

Expand Down Expand Up @@ -1393,11 +1414,12 @@ fn create_coroutine_resume_function<'tcx>(

if can_return {
let block = match coroutine_kind {
// FIXME(gen_blocks): Should `async gen` yield `None` when resumed once again?
CoroutineKind::Async(_) | CoroutineKind::AsyncGen(_) | CoroutineKind::Coroutine => {
CoroutineKind::Async(_) | CoroutineKind::Coroutine => {
insert_panic_block(tcx, body, ResumedAfterReturn(coroutine_kind))
}
CoroutineKind::Gen(_) => transform.insert_none_ret_block(body),
CoroutineKind::AsyncGen(_) | CoroutineKind::Gen(_) => {
transform.insert_none_ret_block(body)
}
};
cases.insert(1, (RETURNED, block));
}
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/coroutine/async_gen_fn_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ async fn async_main() {
assert_eq!(iter.as_mut().next().await, Some(2));
assert_eq!(iter.as_mut().next().await, Some(3));
assert_eq!(iter.as_mut().next().await, None);

// Test that the iterator is fused and does not panic
assert_eq!(iter.as_mut().next().await, None);
assert_eq!(iter.as_mut().next().await, None);
}

// ------------------------------------------------------------------------- //
Expand Down