-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Refactor away the TypeckTables::cast_kinds field #52482
Copy link
Copy link
Closed
Labels
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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.
Metadata
Metadata
Assignees
Labels
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Motivation
This field has a lot of code going into creating it, while its use sites barely care at all about all the nice data it contains. They could just as well compute the data they need themselves. Computing the data is cheap, so there's no point in computing this ahead of time.
Instructions
1. Eliminate uses
The field is used in two places:
rust/src/librustc_mir/hair/cx/expr.rs
Line 590 in 50702b2
rust/src/librustc_passes/rvalue_promotion.rs
Line 371 in 50702b2
The 1. use can be fixed by just checking whether the type of
sourceis the same type asexpr_ty. This means allfoo as Barcasts get ignored iffoois already of typeBar. Which is exactly what that code is trying to do.The 2. use actually wants to know the cast kind, but there's no need to get that from the
cast_kindsfield. Instead one would again obtain the type of the expression being cast and the type being cast to, and then do exactly what MIR based borrowck does when going through the same code (UseCastTyto figure out the details):rust/src/librustc_mir/transform/qualify_consts.rs
Lines 719 to 725 in 38168a7
2. Eliminate the field and all the code feeding into it
This part is easy now. Remove the field, and the compiler will guide you to all the places it's used. All you have to do is remove code until the compiler is happy.