rust-lang / types-team

Home of the "types team", affiliated with the compiler and lang teams.
https://rust-lang.github.io/types-team/
Apache License 2.0
94 stars 19 forks source link

Combine `ty::Opaque` and `ty::Projection` into `ty::Alias` #79

Closed compiler-errors closed 1 year ago

compiler-errors commented 1 year ago

Combine ty::Opaque and ty::Projection into ty::Alias

Aims to combine ty::Opaque and ty::Projection into ty::Alias. Both are just a def-id and set of substitutions. We should also be able to easily add new alias variants in the future if needed.

The new TyKind API will somewhat look like:

enum TyKind {
  ..
  // New variant, remove `TyKind::{Opaque, Projection}`
  Alias(AliasKind, AliasTy),
  ..
}

enum AliasKind {
  Opaque,
  Projection,
}

// Replaces `ProjectionTy`
struct AliasTy<'tcx> {
  def_id: DefId,
  substs: SubstsRef<'tcx>,
}

To make sure that code can still match on the old usages ty::Opaque and ty::Projection, we distinguish the variants with AliasKind. This is important in places where we don't have access to TyCtxt, such as flags computation. Also, it would be somewhat expensive to add new def-id comparisons.

This means most match sites can go from ty::Projection(proj) to ty::Alias(ty::Projection, proj), meaning the refactor will be mostly mechanical.

The API is somewhat different from the way that Chalk does it, where AliasTy is an enum with a data-ful Projection and Opaque variant: https://docs.rs/chalk-ir/0.87.0/chalk_ir/enum.AliasTy.html

Mentors or Reviewers

@compiler-errors's implementation: https://github.com/rust-lang/rust/compare/master...compiler-errors:rust:opaques still needs some cleaning, but only took like an hour or so.. also we might want to tweak the API a bit...

The change is mostly mechanical, so anyone on the team can review.

Process

The main points of the Major Change Process are as follows:

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

rustbot commented 1 year ago

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

cc @rust-lang/types

oli-obk commented 1 year ago

@rustbot second

lcnr commented 1 year ago

we still have to manually close those :grin: