Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less magic number for corountine #127294

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ impl<'tcx> ty::CoroutineArgs<TyCtxt<'tcx>> {
const RETURNED: usize = 1;
/// Coroutine has been poisoned.
const POISONED: usize = 2;
/// Number of variants to reserve in coroutine state. Corresponds to
/// `UNRESUMED` (beginning of a coroutine) and `RETURNED`/`POISONED`
/// (end of a coroutine) states.
const RESERVED_VARIANTS: usize = 3;

const UNRESUMED_NAME: &'static str = "Unresumed";
const RETURNED_NAME: &'static str = "Returned";
Expand Down Expand Up @@ -116,7 +120,7 @@ impl<'tcx> ty::CoroutineArgs<TyCtxt<'tcx>> {
Self::UNRESUMED => Cow::from(Self::UNRESUMED_NAME),
Self::RETURNED => Cow::from(Self::RETURNED_NAME),
Self::POISONED => Cow::from(Self::POISONED_NAME),
_ => Cow::from(format!("Suspend{}", v.as_usize() - 3)),
_ => Cow::from(format!("Suspend{}", v.as_usize() - Self::RESERVED_VARIANTS)),
}
}

Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_mir_transform/src/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,8 @@ const UNRESUMED: usize = CoroutineArgs::UNRESUMED;
const RETURNED: usize = CoroutineArgs::RETURNED;
/// Coroutine has panicked and is poisoned.
const POISONED: usize = CoroutineArgs::POISONED;

/// Number of variants to reserve in coroutine state. Corresponds to
/// `UNRESUMED` (beginning of a coroutine) and `RETURNED`/`POISONED`
/// (end of a coroutine) states.
const RESERVED_VARIANTS: usize = 3;
/// Number of reserved variants of coroutine state.
const RESERVED_VARIANTS: usize = CoroutineArgs::RESERVED_VARIANTS;

/// A `yield` point in the coroutine.
struct SuspensionPoint<'tcx> {
Expand Down
Loading