rust-lang / rust-lang/rust

Tracking issue to remove `TyKind::CoroutineWitness` from the type system

Open
#143,017 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-coroutines C-cleanup C-tracking-issue T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I'm interested in removing the TyKind::CoroutineWitness variant from the type system.

Coroutine witnesses are a synthetic generic arg given to coroutines to stall the computation of the "witness" types of the coroutine (which are the variables live across await points) by initially being populated with an infer var, then getting inferred to a tuple after analysis was run at the end of typeck. (We do similar things for closures, for example, for their upvars.)

Since #101692, the tuple was replaced with a TyKind::CoroutineWitness which defers that computation further to MIR. However, we still use an infer var to stall obligations that would rely on using these witness types (and only unify with with a CoroutineWitness at the end of typeck), since if we try to query for the witnesses during typeck in the same body that defines the coroutine, we would encounter query cycles.

#138845 introduced a more appropriate way to stall oblgiations that rely on coroutine witnesses which is currently used in the new solver. I'd like to use this in the old solver, and eventually rip out the TyKind::CoroutineWitness altogether, since it's redundant with TyKind::Coroutine which stores the same def-id and args as the former.

This is a tracking issue to make sure that I follow up with the work.

Rough timeline:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the issue's completed work in PRs #138845 and #141762, then investigate the unchecked coroutine handling in drop live outlives machinery. The goal is to fix that handling and eventually remove TyKind::CoroutineWitness, verifying that coroutine type-system behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.