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

Rename astconv::AstConv and related items #723

Closed
3 tasks done
fmease opened this issue Feb 11, 2024 · 3 comments
Closed
3 tasks done

Rename astconv::AstConv and related items #723

fmease opened this issue Feb 11, 2024 · 3 comments
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@fmease
Copy link
Member

fmease commented Feb 11, 2024

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 lowering1 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).

  • in crate rustc_hir_analysis
    • module astconvhir_ty_lowering
    • quasi-deprecated helper hir_ty_to_tylower_ty
  • in module hir_ty_lowering
    • trait AstConvHirTyLowerer
      • allow_ty_inferallow_infer
      • astconvlowerer
      • get_type_parameter_boundsprobe_ty_param_bounds
      • projected_ty_from_poly_trait_reflower_assoc_ty
    • struct PathSegGenericPathSegment
  • methods on formally dyn AstConv (sorted alphabetically)
    • add_boundslower_poly_bounds
    • add_implicitly_sizedadd_sized_bound
    • add_predicates_for_ast_type_bindinglower_assoc_item_binding2
    • associated_path_to_tylower_assoc_path
    • ast_path_args_for_tylower_generic_args_of_path_segment
    • ast_path_to_mono_trait_reflower_mono_trait_ref
    • ast_path_to_tylower_path_segment
    • ast_region_to_regionlower_lifetime
    • ast_ty_to_tylower_ty
    • ast_ty_to_ty_in_pathlower_ty_in_path
    • ast_ty_to_ty_innerlower_ty_common
    • compute_boundslower_mono_bounds
    • conv_object_ty_poly_trait_reflower_trait_object_ty
    • create_args_for_associated_itemlower_generic_args_of_assoc_item
    • create_args_for_ast_pathlower_generic_args_of_path
    • def_ids_for_value_path_segmentsprobe_generic_path_segments
    • find_bound_for_assoc_itemprobe_single_ty_param_bound_for_assoc_ty
    • hir_id_to_bound_constlower_const_param
    • hir_id_to_bound_tylower_ty_param
    • impl_trait_ty_to_tylower_opaque_ty
    • instantiate_mono_trait_reflower_impl_trait_ref3
    • instantiate_poly_trait_reflower_poly_trait_ref3
    • lookup_assoc_typrobe_assoc_ty4
    • lookup_assoc_ty_uncheckedprobe_assoc_ty_unchecked4
    • lookup_inherent_assoc_typrobe_inherent_assoc_ty4
    • one_bound_for_assoc_itemprobe_single_bound_for_assoc_item
    • prohibit_assoc_ty_bindingprohibit_assoc_item_binding2
    • prohibit_genericsprohibit_generic_args
    • qpath_to_tylower_qpath
    • report_ambiguous_associated_typereport_ambiguous_assoc_type
    • res_to_tylower_path
    • trait_defines_associated_item_namedprobe_trait_that_defines_assoc_item
    • ty_from_delegationlower_delegation_ty
    • ty_of_arglower_arg_ty
    • ty_of_fnlower_fn_ty
  • generic args lowering
    • trait CreateSubstsForGenericArgsCtxtGenericArgsLowerer
    • local struct SubstsForAstPathCtxtGenericArgsCtxt (in rustc_hir_analysis)
    • local struct MethodSubstsCtxtGenericArgsCtxt5 (in rustc_hir_typeck)
    • local struct CreateCtorSubstsContextCtorGenericArgsCtxt
  • in rustc_trait_selection::traits
    • astconv_object_safety_violationshir_ty_lowering_object_safety_violations
  • ConstrainedCollectorPostAstConvConstrainedCollectorPostHirTyLowering
  • in generics
    • create_args_for_parent_generic_argslower_generic_args6
  • on ItemCtxt
    • to_tylower_ty
    • type_parameter_bounds_in_genericsprobe_ty_param_bounds_in_generics
  • methods on FnCtxt (sorted alphabetically)
    • array_length_to_constlower_array_length
    • const_arg_to_tylower_const_arg
    • to_tylower_ty
    • to_ty_saving_user_provided_tylower_ty_saving_user_provided_ty
  • in collect:
    • convert_{item,trait_item,impl_item,variant_ctor,enum_variant_types,variant}lower_$item

Mentors or Reviewers

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

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.

Footnotes

  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.

  2. Not only applies to (assoc) type bindings but also assoc const bindings and RTN (return type notation) 2

  3. It's not instantiating anything in the usual sense, it's just lowering. 2

  4. Consistent with probe_single_bound_for_assoc_{item,ty}, probe_trait_that_defines_assoc_item, probe_traits_that_match_assoc_ty, probe_adt 2 3

  5. It's not only used for assoc fns but also for assoc consts

  6. 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.

@fmease fmease added T-compiler Add this label so rfcbot knows to poll the compiler team major-change A proposal to make a major change to rustc labels Feb 11, 2024
@rustbot
Copy link
Collaborator

rustbot commented Feb 11, 2024

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

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Feb 11, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Feb 11, 2024

@rustbot second this has been bugging me for forever 😅

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Feb 11, 2024
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Feb 15, 2024
@fmease
Copy link
Member Author

fmease commented Feb 21, 2024

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

@fmease fmease closed this as completed Feb 21, 2024
@rustbot rustbot added major-change-accepted A major change proposal that was accepted to-announce Announce this issue on triage meeting and removed final-comment-period The FCP has started, most (if not all) team members are in agreement labels Feb 21, 2024
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Feb 22, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 14, 2024
[WIP] [MCP 723] Rename `astconv::AstConv` and related items

See rust-lang/compiler-team#723.
Corresponding rustc-dev-guide PR: rust-lang/rustc-dev-guide#1916.

DO NOT REVIEW THIS JUST YET: I still need to finalize it: Renaming & adding/updating more (doc) comments!

r? ghost
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 22, 2024
[MCP 723] Rename `astconv::AstConv` and related items

See rust-lang/compiler-team#723.
Corresponding rustc-dev-guide PR: rust-lang/rustc-dev-guide#1916.

Please consult the following *normative* list of changes here:
https://fmease.dev/rustc-dev/astconv-no-mo.html ([2024-03-22 archive link](https://web.archive.org/web/20240322054711/https://fmease.dev/rustc-dev/astconv-no-mo.html)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests

4 participants