Skip to content

TypingMode #128

@lcnr

Description

@lcnr

Proposal

Some of our typing rules depend on the "mode" we're in. Most notably, whether we should force "unknowable" trait goals to be ambiguous during coherence and whether to define or reveal opaque types.

This is currently handled via ParamEnv::reveal, InferCtxt::intercrate, and InferCtxt::defining_opaque_types and never changes during the lifetime of a InferCtxt. Going forward we intend to add yet another mode to the type system: only reveal opaques defined by some body, but without being able to define them. This is necessary during places such as opaque type well-formedness checking. We currently

  • either treat them as opaque, and get an inconsistent state as HIR typeck only succeeded because it was able to observe the hidden type,
  • or we allow redefining all the opaques from the body, this causes ambiguity errors in case we end up using an opaque without actually reconstraining it.

This is the reason why we've needed rust-lang/rust#124598 for bootstrap with the new solver. We intend to fix this issue by adding an additional typing mode which allows revealing some opaque types without allowing any new definitions.

We currently also frequently accidentally forget parts of our typing mode, e.g. when calling nested queries which only take a ParamEnvAnd, dropping both the defining_opaque_types and intercrate.

I intend to change this by moving all of this information into a new typing_mode field on the InferCtxt and then change queries currently taking a ParamEnv to instead take a struct TypingEnv<'tcx> { typing_mode: TypingMode<'tcx>, param_env: ty::ParamEnv<'tcx> }.

I've started to already implement this in rust-lang/rust#131856 and am continuing this work in rust-lang/rust#132460. Given that this is ending up being quite involved and a nightmare to revert, I want to make sure the full Types Team is aware of this effort.

See https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/.60TypingMode.60 for more details, might extend this MCP tomorrow, have to leave for today 😅

Mentors or Reviewers

@compiler-errors

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.

Activity

added
T-typesAdd this label so rfcbot knows to poll the types team
on Nov 4, 2024
rustbot

rustbot commented on Nov 4, 2024

@rustbot
Collaborator

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.

Concerns or objections to the proposal should be discussed on Zulip and formally registered here by adding a comment with the following syntax:

@rustbot concern reason-for-concern 
<description of the concern> 

Concerns can be lifted with:

@rustbot resolve reason-for-concern 

See documentation at https://forge.rust-lang.org

cc @rust-lang/types

compiler-errors

compiler-errors commented on Nov 4, 2024

@compiler-errors
Member

@rustbot second

Very very in favor of this work, and have discussed at length the approach and final state of the type system after this change. I'm volunteering to review this work.

added
final-comment-periodThe FCP has started, most (if not all) team members are in agreement
on Nov 4, 2024
added a commit that references this issue on Nov 18, 2024
lcnr

lcnr commented on Jan 28, 2025

@lcnr
ContributorAuthor

closed as accepted

1 remaining item

Loading
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

    T-typesAdd this label so rfcbot knows to poll the types teamfinal-comment-periodThe FCP has started, most (if not all) team members are in agreementmajor-changeA major change proposalto-announceAnnounce this issue on triage meeting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      `TypingMode` · Issue #128 · rust-lang/types-team