Repository navigation
Refactor split_block in check_pointers to avoid Terminator: None - #165716
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
Error: Failed to set assignee to
Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip. |
|
|
Yeah, I see what you mean, this isn't good. I'm reminded why I generally prefer first-order control flow and drop guards over higher order functions and (all but the most trivial) functional combinators. I think my earlier skepticism was over-indexing on the possible extension to multiple reservations. For the case where only a single block at a time is pending, I think it could be pretty straightforward to implement and easier to use then nesting closures. Please feel free to give it a shot! |
|
Update: I tried some The problem is that if I do something like this: let (reserved, blocks) = blocks.reserve_idx();
blocks[some_existing_bb].terminator.some_target_bb = reserved.idx();
// ...
reserved.push_reserved(Terminator::new(...))then, without linear types, there's nothing that guarantees the final push actually happens. You can just forget the
I was imagining this a bit like HashMap's entry api, or as rusqlite's transaction, but came to realize those are different from what I actually want - HashMap doesn't need to guarantee that the entry is filled, it's fine to forget the entry. And similarly, The other point is that it didn't actually make the code easier to understand - in fact, the code looks almost identical, it's pretty much just less indented. I think the thing that makes this difficult to understand is that we're doing some operations that fundementally overlap:
The previous implementation could at least neatly separate the "move everything after the split point into a new block" operation from finalizing the block that has been split. The new implementation can't do that because we can't keep the edited block without terminator, so these two opreations become fundamentally intertwined. In other words, the previous code did use So, I think I will try to shuffle the code around and maybe get rid of one of those closures, either by inlining the Maybe too much overthinking for such a simple piece of code, but I treat this as a bit of a testing ground for how to write MIR edits in general without the |
|
I added a second commit which reshuffles this a little bit to separate inserting the checks form finalizing the new block - we inline the This way the @rustbot ready |
There was a problem hiding this comment.
Splitting out the statement insertion to make the block manipulation visually go last and fit on one screen makes sense to me. I hope that this approach scales to other uses of block splitting, we'll see.
I don't love the extra nesting, but this code was already near or over my limit for nesting before, and yeah I wouldn't expect turning it into a free function would be any better. The complex signature of the on_finding callback in particular is Not Great but none of that is really related to or affected by this PR.
r=me after squashing and updating the PR description for posterity (you can keep the history if you want, but right now it contradicts the final version of the diff).
FWIW, I think that an |
|
Thanks ;)
Yea, I really don't like how this thing is tangled with that callback in there. I don't like that this code just gives out its partially broken datastructures with some unclear invariants into an opaque function call. Those callbacks do some fairly simple things in the end I think it could somehow be unified better. If the callback just returned some |
We also inline split_block and outline insert_check instead in check_pointers. The goal is to separate inserting the check from creating and inserting the new block. This should make the logic slightly easier to follow
2c77a98 to
d7bfe5e
Compare
|
@bors r=hanna-kruppe |
…it-block, r=hanna-kruppe Refactor split_block in check_pointers to avoid Terminator: None Step N towards changing `Option<Terminator>` to `Terminator` in `BasicBlockData`. More info in [this thread](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/vibe.20check.20-.20removing.20Option.20from.20Terminator/with/637588808). This one used `None` for because it again needs new block id to create the terminator to put into the split point. We use the same `push_with` strategy as we used in coroutine transform. We also inline the `split_block` function and instead outline insert_check, to keep the `push_with` block smaller and focused. r? hanna-kruppe
Rollup of 21 pull requests Successful merges: - #165707 (bootstrap: Make low priority the default) - #165716 (Refactor split_block in check_pointers to avoid Terminator: None) - #165934 (Avoid using Terminator:None in simplify_cfg) - #166050 (Use attribute parser for lang attributes in `LateResolutionVisitor`) - #166069 (bootstrap: fix keep-stage-std) - #166117 (Remove ebadf handling from stdio) - #166119 (Avoid an ICE on re-exports of private imports without a DefId) - #165094 (reflection: doc attributes from adts, fields, and variants) - #165216 (Clearer diagnostics when `&FnOnce` was provided when `FnOnce` was expected) - #165694 (view-types: make sure view types are !Sized) - #165802 (Add CI workflow to publish backtrace after a push to main) - #165883 (Report a recursion limit error instead of delaying a bug in RPITIT collector) - #165906 (fix ICE when a forced keyword follows a parameter pattern) - #166064 (Add const generic transmute min support) - #166136 (Move ub_checks() inside the const_eval_select branch.) - #166158 (bump some tools' `toml` dependency) - #166166 (Don't recover if not allowed in `parse_seq_to_before_tokens`) - #166176 (compiletest: Move all code out of the crate root) - #166185 (simd-test: Fix cfg syntax in the test macro) - #166194 (std: Unstably constify `std::process::abort`) - #166210 (Avoid terminator: None in insert_direct_enum_check) Failed merges: - #166150 (Reflection: refactor Type and TypeKind) - #166160 (refactor CTFE-specific intrinsics to different file)
Rollup of 20 pull requests Successful merges: - #165716 (Refactor split_block in check_pointers to avoid Terminator: None) - #165934 (Avoid using Terminator:None in simplify_cfg) - #166050 (Use attribute parser for lang attributes in `LateResolutionVisitor`) - #166069 (bootstrap: fix keep-stage-std) - #166117 (Remove ebadf handling from stdio) - #166119 (Avoid an ICE on re-exports of private imports without a DefId) - #165094 (reflection: doc attributes from adts, fields, and variants) - #165216 (Clearer diagnostics when `&FnOnce` was provided when `FnOnce` was expected) - #165694 (view-types: make sure view types are !Sized) - #165802 (Add CI workflow to publish backtrace after a push to main) - #165883 (Report a recursion limit error instead of delaying a bug in RPITIT collector) - #165906 (fix ICE when a forced keyword follows a parameter pattern) - #166064 (Add const generic transmute min support) - #166136 (Move ub_checks() inside the const_eval_select branch.) - #166158 (bump some tools' `toml` dependency) - #166166 (Don't recover if not allowed in `parse_seq_to_before_tokens`) - #166176 (compiletest: Move all code out of the crate root) - #166185 (simd-test: Fix cfg syntax in the test macro) - #166194 (std: Unstably constify `std::process::abort`) - #166210 (Avoid terminator: None in insert_direct_enum_check) Failed merges: - #166150 (Reflection: refactor Type and TypeKind) - #166160 (refactor CTFE-specific intrinsics to different file)
Rollup merge of #165716 - panstromek:no-terminato-option-split-block, r=hanna-kruppe Refactor split_block in check_pointers to avoid Terminator: None Step N towards changing `Option<Terminator>` to `Terminator` in `BasicBlockData`. More info in [this thread](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/vibe.20check.20-.20removing.20Option.20from.20Terminator/with/637588808). This one used `None` for because it again needs new block id to create the terminator to put into the split point. We use the same `push_with` strategy as we used in coroutine transform. We also inline the `split_block` function and instead outline insert_check, to keep the `push_with` block smaller and focused. r? hanna-kruppe
Rollup of 20 pull requests Successful merges: - rust-lang/rust#165716 (Refactor split_block in check_pointers to avoid Terminator: None) - rust-lang/rust#165934 (Avoid using Terminator:None in simplify_cfg) - rust-lang/rust#166050 (Use attribute parser for lang attributes in `LateResolutionVisitor`) - rust-lang/rust#166069 (bootstrap: fix keep-stage-std) - rust-lang/rust#166117 (Remove ebadf handling from stdio) - rust-lang/rust#166119 (Avoid an ICE on re-exports of private imports without a DefId) - rust-lang/rust#165094 (reflection: doc attributes from adts, fields, and variants) - rust-lang/rust#165216 (Clearer diagnostics when `&FnOnce` was provided when `FnOnce` was expected) - rust-lang/rust#165694 (view-types: make sure view types are !Sized) - rust-lang/rust#165802 (Add CI workflow to publish backtrace after a push to main) - rust-lang/rust#165883 (Report a recursion limit error instead of delaying a bug in RPITIT collector) - rust-lang/rust#165906 (fix ICE when a forced keyword follows a parameter pattern) - rust-lang/rust#166064 (Add const generic transmute min support) - rust-lang/rust#166136 (Move ub_checks() inside the const_eval_select branch.) - rust-lang/rust#166158 (bump some tools' `toml` dependency) - rust-lang/rust#166166 (Don't recover if not allowed in `parse_seq_to_before_tokens`) - rust-lang/rust#166176 (compiletest: Move all code out of the crate root) - rust-lang/rust#166185 (simd-test: Fix cfg syntax in the test macro) - rust-lang/rust#166194 (std: Unstably constify `std::process::abort`) - rust-lang/rust#166210 (Avoid terminator: None in insert_direct_enum_check) Failed merges: - rust-lang/rust#166150 (Reflection: refactor Type and TypeKind) - rust-lang/rust#166160 (refactor CTFE-specific intrinsics to different file)
Step N towards changing
Option<Terminator>toTerminatorinBasicBlockData. More info in this thread.This one used
Nonefor because it again needs new block id to create the terminator to put into the split point. We use the samepush_withstrategy as we used in coroutine transform.We also inline the
split_blockfunction and instead outline insert_check, to keep thepush_withblock smaller and focused.r? hanna-kruppe