-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Add a fast path for lowering trivial consts #148040
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,7 @@ mod liveness; | |
| mod patch; | ||
| mod shim; | ||
| mod ssa; | ||
| mod trivial_const; | ||
|
|
||
| /// We import passes via this macro so that we can have a static list of pass names | ||
| /// (used to verify CLI arguments). It takes a list of modules, followed by the passes | ||
|
|
@@ -226,6 +227,7 @@ pub fn provide(providers: &mut Providers) { | |
| promoted_mir, | ||
| deduced_param_attrs: deduce_param_attrs::deduced_param_attrs, | ||
| coroutine_by_move_body_def_id: coroutine::coroutine_by_move_body_def_id, | ||
| trivial_const: trivial_const::trivial_const_provider, | ||
| ..providers.queries | ||
| }; | ||
| } | ||
|
|
@@ -379,6 +381,16 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def: LocalDefId) -> ConstQualifs { | |
| fn mir_built(tcx: TyCtxt<'_>, def: LocalDefId) -> &Steal<Body<'_>> { | ||
| let mut body = build_mir(tcx, def); | ||
|
|
||
| // Identifying trivial consts based on their mir_built is easy, but a little wasteful. | ||
| // Trying to push this logic earlier in the compiler and never even produce the Body would | ||
| // probably improve compile time. | ||
| if trivial_const::trivial_const(tcx, def, || &body).is_some() { | ||
| // Skip all the passes below for trivial consts. | ||
| let body = tcx.alloc_steal_mir(body); | ||
| pass_manager::dump_mir_for_phase_change(tcx, &body.borrow()); | ||
| return body; | ||
| } | ||
|
|
||
| pass_manager::dump_mir_for_phase_change(tcx, &body); | ||
|
|
||
| pm::run_passes( | ||
|
|
@@ -409,6 +421,8 @@ fn mir_promoted( | |
| tcx: TyCtxt<'_>, | ||
| def: LocalDefId, | ||
| ) -> (&Steal<Body<'_>>, &Steal<IndexVec<Promoted, Body<'_>>>) { | ||
| debug_assert!(!tcx.is_trivial_const(def), "Tried to get mir_promoted of a trivial const"); | ||
|
|
||
| // Ensure that we compute the `mir_const_qualif` for constants at | ||
| // this point, before we steal the mir-const result. | ||
| // Also this means promotion can rely on all const checks having been done. | ||
|
|
@@ -436,6 +450,9 @@ fn mir_promoted( | |
| tcx.ensure_done().coroutine_by_move_body_def_id(def); | ||
| } | ||
|
|
||
| // the `trivial_const` query uses mir_built, so make sure it is run. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's a bit goofy, but that's all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That code flow feels worth putting in a comment somewhere. Also, doesn't that mean we do the work of checking triviality twice? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noting that I did add this to a comment in which I noted that we are checking for triviality multiple times which is undesirable. |
||
| tcx.ensure_done().trivial_const(def); | ||
|
|
||
| let mut body = tcx.mir_built(def).steal(); | ||
| if let Some(error_reported) = const_qualifs.tainted_by_errors { | ||
| body.tainted_by_errors = Some(error_reported); | ||
|
|
@@ -463,6 +480,7 @@ fn mir_promoted( | |
|
|
||
| /// Compute the MIR that is used during CTFE (and thus has no optimizations run on it) | ||
| fn mir_for_ctfe(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &Body<'_> { | ||
| debug_assert!(!tcx.is_trivial_const(def_id), "Tried to get mir_for_ctfe of a trivial const"); | ||
| tcx.arena.alloc(inner_mir_for_ctfe(tcx, def_id)) | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.