-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Use stable metric for const eval limit instead of current terminator-based logic #106227
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
360db51
Create stable metric to measure long computation in Const Eval
bryangarza 026a673
Clean up CtfeLimit MirPass
bryangarza b763f90
Remove debugging-related code
bryangarza 009beb0
Change code to use map insead of for-loop
bryangarza 8d99b0f
Abstract out has_back_edge fn
bryangarza eea4273
Replace terminator-based const eval limit
bryangarza 164ff64
Update codegen cranelift for ConstEvalCounter
bryangarza 80a3d2a
Update Clippy for ConstEvalCounter
bryangarza 08de246
Move CtfeLimit to mir_const's set of passes
bryangarza 172662d
Add back Machine::before_terminator(...) method
bryangarza d3c13a0
Revert "Move CtfeLimit to mir_const's set of passes"
bryangarza 999d19d
Move CtfeLimit MirPass to inner_mir_for_ctfe
bryangarza aae331d
During MirBorrowck, ignore ConstEvalCounter
bryangarza 75b7c6c
Bless and update consts tests
bryangarza a8c9528
Bless z-help test for new flag
bryangarza f9982ea
Add comment on cause of panic in dominators algorithm
bryangarza 7618163
Add comments and remove unnecessary code
bryangarza 1bbd655
Improve efficiency of has_back_edge(...)
bryangarza bdb815a
Move const-eval/stable-metric ui tests
bryangarza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//! A pass that inserts the `ConstEvalCounter` instruction into any blocks that have a back edge | ||
//! (thus indicating there is a loop in the CFG), or whose terminator is a function call. | ||
use crate::MirPass; | ||
|
||
use rustc_data_structures::graph::dominators::Dominators; | ||
use rustc_middle::mir::{ | ||
BasicBlock, BasicBlockData, Body, Statement, StatementKind, TerminatorKind, | ||
}; | ||
use rustc_middle::ty::TyCtxt; | ||
|
||
pub struct CtfeLimit; | ||
bryangarza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
impl<'tcx> MirPass<'tcx> for CtfeLimit { | ||
#[instrument(skip(self, _tcx, body))] | ||
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { | ||
let doms = body.basic_blocks.dominators(); | ||
oli-obk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let indices: Vec<BasicBlock> = body | ||
.basic_blocks | ||
.iter_enumerated() | ||
.filter_map(|(node, node_data)| { | ||
if matches!(node_data.terminator().kind, TerminatorKind::Call { .. }) | ||
// Back edges in a CFG indicate loops | ||
|| has_back_edge(&doms, node, &node_data) | ||
{ | ||
Some(node) | ||
} else { | ||
None | ||
} | ||
}) | ||
.collect(); | ||
for index in indices { | ||
insert_counter( | ||
body.basic_blocks_mut() | ||
.get_mut(index) | ||
.expect("basic_blocks index {index} should exist"), | ||
); | ||
} | ||
} | ||
} | ||
|
||
fn has_back_edge( | ||
doms: &Dominators<BasicBlock>, | ||
node: BasicBlock, | ||
node_data: &BasicBlockData<'_>, | ||
) -> bool { | ||
if !doms.is_reachable(node) { | ||
return false; | ||
} | ||
// Check if any of the dominators of the node are also the node's successor. | ||
doms.dominators(node) | ||
.any(|dom| node_data.terminator().successors().into_iter().any(|succ| succ == dom)) | ||
} | ||
|
||
fn insert_counter(basic_block_data: &mut BasicBlockData<'_>) { | ||
basic_block_data.statements.push(Statement { | ||
source_info: basic_block_data.terminator().source_info, | ||
kind: StatementKind::ConstEvalCounter, | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.