Skip to content

Extract queries for the trait system operations that are performed in trans #44891

Closed
@nikomatsakis

Description

@nikomatsakis

Currently, there are a number of trait system operations that are used by the code in trans. Currently, they are invoked directly, and behind the scenes they use a DepTrackingMap to memoize across multiple calls. It would be better for incremental if they were converted into named queries. Effectively the goal is to remove the trans_trait_caches field of the tcx. For these particular operations, since they do not work on types that include inference variables, this should be fairly straight-forward:

The idea would to take the following steps:

  • Define a query for trans_fulfill_obligation.
  • With respect to the normalization that is taking place here, I think a wee bit of refactoring is in order before we introduce the query. The actual setup here is a bit confused and probably could use even more refactoring, but for the purposes of this issue, we can do something fairly tailored.
    • Step 1: Rename the method normalize_associated_type() to normalize_associated_type_in(). This method is defined here. It only has a handful of callers (as you can see with a quick rg \.normalize_associated_type\().
      • This is a generic function that will normalize associated types in all kinds of things.
    • Step 2: Define a query normalize_ty(Ty<'tcx>) -> Ty<'tcx> that simply invokes normalize_associated_types_in. This is basically that function in query form, but specialized to inputs of type Ty<'tcx>.
    • Step 3. Replace these lines that invoke memoize()) with code that just invokes the query self.tcx.normalize_ty(ty).

For bonus points, we might consider converting the following functions into queries. It seems like they could benefit from caching:

  • traits::get_vtable_methods (definition)
    • would have to be converted to return a vector
  • traits::normalize_and_test_predicates
  • trans_normalize
  • trans_apply_param_substs

It's unclear though if this is a good idea. I'd keep those for a later PR so we can do some experiments with performance and memory use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-incr-compWorking group: Incremental compilationWG-traitsWorking group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions