-
Notifications
You must be signed in to change notification settings - Fork 14k
compute temporary scopes when building MIR, not THIR #148706
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
base: main
Are you sure you want to change the base?
Conversation
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…try> compute temporary scopes when building MIR, not THIR
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (9de26a5): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -0.5%, secondary -2.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.3%, secondary -4.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 475.809s -> 473.629s (-0.46%) |
| /// The lifetime of this expression if it should be spilled into a | ||
| /// temporary | ||
| pub temp_lifetime: TempLifetime, | ||
| /// The id of the HIR expression whose [temporary scope] should be used for this expression. | ||
| /// | ||
| /// [temporary scope]: https://doc.rust-lang.org/reference/destructors.html#temporary-scopes | ||
| pub temp_scope_id: hir::ItemLocalId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be removed entirely from thir::Expr, and we could use thir::ExprKind::Scopes to set up temporary scopes, but it's a little subtle/inconvenient for certain THIR lowerings (looking at &pin mut here) so for now I've opted to keep it simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The temp_scope_id annotations here are even more obscure than the previous version. Should we dump the region tree alongside THIR for debugging purposes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might help, yeah. I'm not sure a raw Debug dump of the scope tree would be that legible either, but maybe for the -Zunpretty=thir-tree output it'd make sense to inline the relevant bits? I worry a little it could be confusing to have information in there that isn't actually part of the THIR, but it'd also let us print scopes for binding patterns (which aren't straightforward for super let).
I think my ideal though would be to add a new way of pretty-printing the THIR that contains the actual drop scopes used to build the MIR (and maybe also get rid of temp_scope_id entirely). It'd be more work to implement, but it might be more useful? Speaking for myself at least, currently when I want to know drop scopes I read a promoted MIR dump since the THIR doesn't tell me at a glance which expressions correspond to places/operands/temporaries/constants/etc. (and since THIR dumps are verbose enough that they're not particularly more readable than MIR, but I'm not sure how fixable that is).
d186978 to
cb42731
Compare
|
Opening for review now that #148658 is merged. r? cjgillot if you don't mind |
|
Some changes occurred in match lowering cc @Nadrieril |
This accomplishes two things:
TempLifetimeto every expression.ScopeTreeby only callingScopeTree::temporary_scopewhen building MIR for something that needs to be dropped in a temporary scope.