Skip to content

[RFC] Refactor types to be a (TypeCore, Substs) pair #42340

Closed

Description

@nikomatsakis

Currently, the Ty<'tcx> type is a reference to a struct (&TyS) that packages up a big ol' enum TypeVariants. As part of chalkification, we would like to be able to write more efficient "decision tree" like procedures that branch on this type. This would be made nicer by factoring out the type into two parts, a "core" and a "substs". This core would be roughly equivalent to the existing TypeVariants, but without the recursive references to other types, which would be uniformly packaged up in the substs.

Thus I imagine that the TyS struct would change to something like this:

pub struct TyS<'tcx> {
    pub sty: TypeVariants<'tcx>, // this is the "core" part
    pub substs: &'tcx Substs<'tcx>, // this is the "substs" part, extracted from `TypeVariants`
    pub flags: TypeFlags,

    // the maximal depth of any bound regions appearing in this type.
    region_depth: u32,
}

(Incidentally, this new notion of TypeVariants could maybe subsume the existing SimplifiedType, though that's not super important.)

Steps

This transition is best made in steps:

Unknowns

It's not 100% clear that this is a good plan, though the individual refactorings above all seem like good steps regardless. Some complicating factors:

cc @eddyb, who first suggested this to me
cc @tschottdorf, who implemented #42297, a step along this path (and an important step for ATC regardless)

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on May 31, 2017
  2. tbg commented on May 31, 2017

    @tbg
    Contributor

    just a heads up - #42171 isn't closed yet (only half of it), though I'm planning on getting to the other half this week.

  3. nikomatsakis commented on May 31, 2017

    @nikomatsakis
    ContributorAuthor

    @tschottdorf ah yeah, I was thinking of the "check" as "in progress", but ... seems fine

  4. added
    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.
    on Jul 27, 2017
  5. added 3 commits that reference this issue on Apr 27, 2019
  6. added a commit that references this issue on Oct 4, 2019
  7. eddyb commented on Oct 4, 2019

    @eddyb
    Contributor

    Existential types carry where-clauses

    Could they be moved to the binder? dyn Foo -> dyn<X: Foo> X would result in Ty::Dyn having all the information in the binder and then substs would have just an anonymous type variable (bound at the aforementioned binder) or be empty for now.

  8. added a commit that references this issue on Oct 4, 2019
    aa98a2b
  9. added 2 commits that reference this issue on Oct 4, 2019
    9fcd5ac
    cfd51ca
  10. added 2 commits that reference this issue on Oct 5, 2019
    360dc31
    7739f17
  11. csmoe commented on Oct 6, 2019

    @csmoe
    Contributor

    @nikomatsakis @eddyb not sure whether this issue should be closed or not. How about those Unknowns? (If needed, I have a lot of brandwidth to volunteer).

  12. eddyb commented on Oct 6, 2019

    @eddyb
    Contributor

    This isn't done, the checkboxes were only for prerequisites, I think.

  13. reopened this on Oct 6, 2019
  14. Nadrieril commented on Nov 7, 2025

    @Nadrieril
    Member

    Randomly stumbled upon this, this is quite outdated and not something I'm aware we're moving towards anymore. I'll close this for triage purposes, do reopen if needed of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions