rust-lang / compiler-team

A home for compiler team planning documents, meeting minutes, and other such things.
https://rust-lang.github.io/compiler-team/
Apache License 2.0
387 stars 69 forks source link

Rename `astconv::AstConv` and related items #723

Closed fmease closed 9 months ago

fmease commented 9 months ago

Proposal

Problem Statement

The current naming scheme of the astconv module in crate rustc_hir_analysis is incredibly misleading. The methods provided by astconv::AstConv do in fact not “[convert] from the AST representation of types to the ty.rs representation” (to quote the module-level documention) but from HIR constructs to ty.rs (rustc_middle::ty) constructs.

The name is very historical dating back to a time when the HIR didn't exist yet! Since the HIR was first introduced in rust-lang/rust#28138 roughly 8½ years ago, the name has never been adjusted!

This outdated nomenclature extends to methods (e.g., ast_ty_to_ty, ast_region_to_region, add_predicates_for_ast_type_binding) and local variables (e.g., ast_ty, ast_bounds) despite them operating on HIR types or being of HIR types, respectively.

This is not at all friendly to new rustc devs and I assume it's slightly annoying for seasoned rustc hackers.

Proposed Solution

I hereby propose renaming the module astconv together with its contents, most notably the trait AstConv, to something that actually reflects its role and functionality. Since “astconv” effectively lowers type-system entities from HIR to rustc_middle::ty representation I choose the terminology HIR ty lowering[^1] going forward with rustc_hir_analysis::astconv turning into rustc_hir_analysis::hir_ty_lowering and AstConv becoming HirTyLowerer (NB: the concrete names aren't necessarily fixed).

Additionally, I'd like to update the naming scheme of dyn AstConv methods from ast_XXX_to_XXX (and similar) to lower_XXX since method names should generally be verbs and since the current names are relatively hard to parse in my opinion (them consisting of multiple acronyms).

Local variables whose name is of the form ast_xxx and that are of a HIR type should be renamed to hir_xxx.

Note that I've an almost complete patch over at rust-lang/rust#120926 which implements the proposed changes.

Concrete Proposal

NOTE: The complete & normative proposal can be found here: https://fmease.dev/rustc-dev/astconv-no-mo.html (2024-03-22 archive link).

Mentors or Reviewers

Implementer: Myself. Reviewers: @compiler-errors probably.

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.

[^1]: Thanks, @compiler-errors, for the initial suggestion and thanks, @Nilstrieb, for the suggestion to incorporate the word ty to make it clear that this only concerns type-system entities, not MIR building. [^6]: It's not only used for assoc fns but also for assoc consts [^7]: Not only applies to (assoc) type bindings but also assoc const bindings and RTN (return type notation) [^8]: It's not instantiating anything in the usual sense, it's just lowering. [^10]: Before the “substs → generic args” renaming, this used to be called create_substs_for_generic_args. The new name create_args_for_parent_generic_args is absolutely incorrect and therefore confusing! We're not “creating generic args for parent generics args” but we're lowering generic args for the item whose DefId was provided (with the help of a GenericArgsLowerer) which also requires the pre-lowered parent generic args to be passed. Respectfully, I think the author of the renaming PR saw the parent_args parameter and thought that the parent args were being lowered. [^11]: Consistent with probe_single_bound_for_assoc_{item,ty}, probe_trait_that_defines_assoc_item, probe_traits_that_match_assoc_ty, probe_adt

rustbot commented 9 months 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.

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

oli-obk commented 9 months ago

@rustbot second this has been bugging me for forever 😅

fmease commented 9 months ago

@rustbot label -final-comment-period +major-change-accepted