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

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

Closed
1 of 3 tasks
compiler-errors opened this issue Nov 26, 2022 · 3 comments
Closed
1 of 3 tasks

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

compiler-errors opened this issue Nov 26, 2022 · 3 comments
Labels
final-comment-period The FCP has started, most (if not all) team members are in agreement major-change A major change proposal T-types Add this label so rfcbot knows to poll the types team to-announce Announce this issue on triage meeting

Comments

@compiler-errors
Copy link
Member

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: rust-lang/rust@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:

  • File an issue describing the proposal.
  • A types team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Types team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

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.

@compiler-errors compiler-errors added major-change A major change proposal T-types Add this label so rfcbot knows to poll the types team labels Nov 26, 2022
@rustbot
Copy link
Collaborator

rustbot commented Nov 26, 2022

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

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Nov 26, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Nov 27, 2022

@rustbot second

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Nov 27, 2022
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 14, 2022
Combine `ty::Projection` and `ty::Opaque` into `ty::Alias`

Implements rust-lang/types-team#79.

This PR consolidates `ty::Projection` and `ty::Opaque` into a single `ty::Alias`, with an `AliasKind` and `AliasTy` type (renamed from `ty::ProjectionTy`, which is the inner data of `ty::Projection`) defined as so:

```
enum AliasKind {
  Projection,
  Opaque,
}

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

Since we don't have access to `TyCtxt` in type flags computation, and because repeatedly calling `DefKind` on the def-id is expensive, these two types are distinguished with `ty::AliasKind`, conveniently glob-imported into `ty::{Projection, Opaque}`. For example:

```diff
  match ty.kind() {
-   ty::Opaque(..) =>
+   ty::Alias(ty::Opaque, ..) => {}
    _ => {}
  }
```

This PR also consolidates match arms that treated `ty::Opaque` and `ty::Projection` identically.

r? `@ghost`
@lcnr
Copy link
Contributor

lcnr commented Jan 9, 2023

we still have to manually close those 😁

@lcnr lcnr closed this as completed Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
final-comment-period The FCP has started, most (if not all) team members are in agreement major-change A major change proposal T-types Add this label so rfcbot knows to poll the types team to-announce Announce this issue on triage meeting
Projects
None yet
Development

No branches or pull requests

4 participants