-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Extract queries for the trait system operations that are performed in trans #44891
Copy link
Copy link
Closed
Labels
C-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: 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.Call 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.Relevant to the compiler team, which will review and decide on the PR/issue.WG-incr-compWorking group: Incremental compilationWorking group: Incremental compilation
Metadata
Metadata
Assignees
Labels
C-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: 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.Call 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.Relevant to the compiler team, which will review and decide on the PR/issue.WG-incr-compWorking group: Incremental compilationWorking group: Incremental compilation
Type
Fields
Give feedbackNo fields configured for issues without a type.
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
DepTrackingMapto memoize across multiple calls. It would be better for incremental if they were converted into named queries. Effectively the goal is to remove thetrans_trait_cachesfield of the tcx. For these particular operations, since they do not work on types that include inference variables, this should be fairly straight-forward:trans_fulfill_obligation, defined here, which immediately invokes thememoizefunction here.The idea would to take the following steps:
trans_fulfill_obligation.Ty<'tcx>type is.fn trans_fulfill_obligationfrom a method (as it is currently defined) into a free-standing function that serves as a provider. You can just remove the call tomemoize, which would no longer be needed.specialization_graph_ofquery).normalize_associated_type()tonormalize_associated_type_in(). This method is defined here. It only has a handful of callers (as you can see with a quickrg \.normalize_associated_type\().normalize_ty(Ty<'tcx>) -> Ty<'tcx>that simply invokesnormalize_associated_types_in. This is basically that function in query form, but specialized to inputs of typeTy<'tcx>.memoize()) with code that just invokes the queryself.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)traits::normalize_and_test_predicatestrans_normalizetrans_apply_param_substsIt'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.