Skip to content

Derive noop impls of TypeFoldable/Visitable #593

Closed as not planned
Closed as not planned
@eggyal

Description

@eggyal

Proposal

Move "trivial" (no-op) implementations of TypeFoldable and TypeVisitable from macro-by-example (currently rustc_middle::macros::TrivialTypeTraversalImpls into the existing derive macros when a new attribute (such as #[contains_nothing_interesting_for_traversers], still subject to bike-shedding) is present.

This work has already been undertaken as part of rust-lang/rust#108214—but because inappropriate use of that attribute will generate impls that are erroneously no-ops, I think (though I'm far from certain) it could result in unsoundness. Accordingly, @RalfJung was rightly concerned that this change is not without risk and for that reason I thought an MCP may be wise.

For historical context, the existing TrivialTypeTraversalImpls macro started out as CopyImpls in 8403b82. The current comment that types need implement Copy appears to be a hangover from that, and ceased being relevant when folding was changed to take self by value in rust-lang/rust#78313; the comment that they must not care (sic) arena allocated data is more relevant, but I think it is more correct to say they must not transitively contain types that may be of interest to folders/visitors: other arena-allocated data is irrelevant, and those interesting types would not cease being interesting if they were no longer arena-allocated.

Mentors or Reviewers

The implementing PR itself was not motivated by this change, but rather by a move to generalise such no-op implementations over the interner. This was suggested to me by @oli-obk, who I therefore already nominated as the reviewer for the PR.

Process

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

  • File an issue describing the proposal.
  • A compiler 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.
    • Compiler 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerAdd this label so rfcbot knows to poll the compiler teammajor-changeA proposal to make a major change to rustc

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions