Skip to content
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

Add an overlap checker to ISLE #4906

Merged
merged 27 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d9235c6
Add an overlap checker to ISLE
elliottt Aug 31, 2022
992ce46
Fix comments
elliottt Sep 13, 2022
2871a9c
Minimize diff
elliottt Sep 13, 2022
9906df0
Add more comments
elliottt Sep 13, 2022
15283d3
Expand comments about handling non-linear patterns
elliottt Sep 13, 2022
84de3dd
Refactor the overlap checker to process pairs of rules
elliottt Sep 14, 2022
1e7ef90
Checkpoint
elliottt Sep 14, 2022
e9f26d2
Improve errors consumption
elliottt Sep 15, 2022
443066d
Collect errors from the highest degree node at each iteration
elliottt Sep 15, 2022
49424cc
Don't register overlap for rules of different priorities
elliottt Sep 15, 2022
8e48ca2
More fold/reduce instead of sequential reduction
elliottt Sep 15, 2022
2c0ea5a
Always run the overlap checker, but add a feature for raising errors
elliottt Sep 15, 2022
ff6c081
Fix spelling error
elliottt Sep 15, 2022
f184e07
Format
elliottt Sep 15, 2022
75ed9b9
Fix some comments and function names
elliottt Sep 15, 2022
7173097
Remove the `remove_node` function on `Errors`
elliottt Sep 15, 2022
b42eab9
The collected errors no longer need to be mutable
elliottt Sep 15, 2022
353880b
Reverse the row patterns after constructing them
elliottt Sep 16, 2022
ac09ba2
Remove the single_case field on Pattern::Variant
elliottt Sep 16, 2022
ae7cb60
Simplify by removing some abstractions
jameysharp Sep 17, 2022
b702e46
Only loop over rule list once
jameysharp Sep 19, 2022
6534a84
Remove nodes as soon as they have no edges left
jameysharp Sep 19, 2022
c97fe05
Iterate over values instead of looking them up by key
jameysharp Sep 19, 2022
e0339a9
Update comments
jameysharp Sep 19, 2022
c5490c0
Remove `Env` wrapper in favor of TypeEnv/TermEnv
jameysharp Sep 19, 2022
569b3f5
Remove `Node` abstraction
jameysharp Sep 19, 2022
01b078b
Use boxed slices instead of Vec for immutable arrays
jameysharp Sep 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cranelift/isle/isle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ version = "0.89.0"
[dependencies]
log = { version = "0.4", optional = true }
miette = { version = "5.1.0", optional = true }
rayon = "^1.5"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a lot of dependencies to Cranelift. Is the overlap checking really so expensive that paralleling it makes a lot of difference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked it. Takes less than half a second total even when not parallelizing. Will open a PR to remove rayon.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We depend on rayon elsewhere in cranelift, which is why we added it to the overlap checker. Were you removing it completely from cranelift?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasmtime-cranelift depends on rayon, but cranelift itself doesn't apart from cranelift-isle because of this PR. bjorn3/rustc_codegen_cranelift@266e967 reverted cg_clif back to cranelift 0.88.1 from before this PR. This commit removes rayon from cg_clif's Cargo.lock.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. My assumption had been that since it was in cranelift/Cargo.toml that it would be okay to rely on it in isle.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW cranelift/Cargo.toml defines the crate for cranelift-tools, the CLI utility; we do want to keep dependencies of cranelift-codegen as minimal as possible, and since cranelift-isle is a build-dep of that I'd consider the same policy to apply. Sorry for not catching this earlier!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, when we added the rayon dependency, overlap checking was dramatically slower, so parallelism shaved a lot of time off the wasmtime build. But by the time we actually merged overlap checking to main, we'd fixed its performance, so rayon didn't matter any more; we just didn't re-evaluate it at that point.

So thank you for #5101: it's a good change.


[dev-dependencies]
tempfile = "3"

[features]
default = []

overlap-errors = []
logging = ["log"]
miette-errors = ["miette"]
1 change: 1 addition & 0 deletions cranelift/isle/isle/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{ast, codegen, sema, trie};
pub fn compile(defs: &ast::Defs, options: &codegen::CodegenOptions) -> Result<String> {
let mut typeenv = sema::TypeEnv::from_ast(defs)?;
let termenv = sema::TermEnv::from_ast(&mut typeenv, defs)?;
crate::overlap::check(&mut typeenv, &termenv)?;
jameysharp marked this conversation as resolved.
Show resolved Hide resolved
let tries = trie::build_tries(&typeenv, &termenv);
Ok(codegen::codegen(&typeenv, &termenv, &tries, options))
}
25 changes: 25 additions & 0 deletions cranelift/isle/isle/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ pub enum Error {
span: Span,
},

/// The rules mentioned overlap in the input they accept.
OverlapError {
/// The error message.
msg: String,

/// The locations of all the rules that overlap. When there are more than two rules
/// present, the first rule is the one with the most overlaps (likely a fall-through
/// wildcard case).
rules: Vec<(Source, Span)>,
},

/// Multiple errors.
Errors(Vec<Error>),
}
Expand Down Expand Up @@ -108,6 +119,10 @@ impl std::fmt::Display for Error {
#[cfg(feature = "miette-errors")]
Error::TypeError { msg, .. } => write!(f, "type error: {}", msg),

Error::OverlapError { msg, rules, .. } => {
writeln!(f, "overlap error: {}\n{}", msg, OverlappingRules(&rules))
}
Comment on lines +122 to +124
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the most helpful error output, but I'm assuming that as we start burning down the list of overlaps we'll figure out what's most useful to identify.


Error::Errors(_) => write!(
f,
"found {} errors:\n\n{}",
Expand All @@ -128,6 +143,16 @@ impl std::fmt::Display for DisplayErrors<'_> {
}
}

struct OverlappingRules<'a>(&'a [(Source, Span)]);
impl std::fmt::Display for OverlappingRules<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for (src, span) in self.0 {
writeln!(f, " {}", span.from.pretty_print_with_filename(&*src.name))?;
}
Ok(())
}
}

/// A source file and its contents.
#[derive(Clone)]
pub struct Source {
Expand Down
1 change: 1 addition & 0 deletions cranelift/isle/isle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub mod error;
pub mod ir;
pub mod lexer;
mod log;
pub mod overlap;
pub mod parser;
pub mod sema;
pub mod trie;
Expand Down
Loading