-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Introducing fzn-rs, a better FlatZinc parser that is easier to re-use across projects
#238
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
6e4bd9e to
efde93c
Compare
b226ff1 to
0281a3c
Compare
ImkoMarijnissen
left a comment
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.
Similar error:
thread 'main' panicked at pumpkin-solver/src/bin/pumpkin-solver/flatzinc/compiler/mod.rs:29:61:
handle errors: IncorrectNumberOfArguments { expected: 3, actual: 4, span: Span { start: 7182213, end: 7182263 } }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
945b37e to
438aa3b
Compare
@ImkoMarijnissen what instance is this? |
|
I updated this branch to fix. I can now run the last 5 years of the minizinc challenge without getting errors. Sadly we do incur a performance penalty, as the "lex then parse" approach in the parser is not as fast as I would have hoped. On challenge years 2020-2024, we get the following score:
All in all I believe that, while the impact on score is not great, it is still a step forward. If we agree that the crate itself looks good, then I move to merge this PR and hopefully improve the performance of the flatzinc parser later. The reason for this is that there are many branches that depend on this already (it really makes it so much easier to consume flatzinc). Since the performance change is completely internal to the crate, we can change it (hopefully) without hurting consumers of this crate. Please re-examine #258 to see how this changes |
Review re-requested
|
Quick question: when you compare the new version and the old version, specifically on benchmarks where we can find optimal solution, are the results consistent? Just wondering if there could be some problems with the parsing! |
|
Yes the solutions are consistent |
|
I looked some more into the results, and I cannot really pinpoint where the slowdown comes from. In both configurations, if I run a profiler on instances that take a long time to parse, the main hotspot is What is also curious is that the instances that show a slowdown in What I did figure out is that the impact of lexing the source before parsing (which is not done in the main branch currently) is actually negligible. Lexing does not show up in a single one of my 10 profiles. I profiled the 10 instances which took the longest on DelftBLue. @ImkoMarijnissen could you also have a look at this PR again and give your feedback on it and the apparent slowdown? |
Quick questions: when you tests and profiling, do you stop the solver after parsing? Is slow parsing something only on DelftBlue or also locally? Let us discuss this in the solver meeting! |
|
Macro can type check? Then from_ast can say that everything is type-checked. |
…he solve item in TypedInstance
The Rc is not Send, but popular crates like anyhow do expect errors to be Send. Since these are errors, we pay the price to allocate a String instead.
…zn parser" This reverts commit 44cbb24.
cfe2685 to
1ee9455
Compare
| @@ -0,0 +1,107 @@ | |||
| use quote::quote; | |||
|
|
|||
| /// Construct a token stream that initialises a value with name `value_type` and the arguments | |||
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 appears to be the exact same documentation as used in annotation.rs, perhaps it could be clarified what the difference is?
| //! | ||
| //! /// The `TypedInstance` is parameterized by the constraint type, as well as any annotations you | ||
| //! /// may need to parse. | ||
| //! type MyInstance = TypedInstance<i64, MyConstraints>; |
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.
It's a bit unclear from this documentation what the i64 signifies here
| @@ -1,5 +1,5 @@ | |||
| [workspace] | |||
| members = ["./pumpkin-solver", "./drcp-format", "./pumpkin-solver-py", "./pumpkin-macros", "./drcp-debugger", "./pumpkin-crates/*"] | |||
| members = ["./pumpkin-solver", "./drcp-format", "./pumpkin-solver-py", "./pumpkin-macros", "./drcp-debugger", "./pumpkin-crates/*", "./fzn-rs", "./fzn-rs-derive"] | |||
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.
I think the pipeline is not running the tests for these crates if they are not part of default-members, do all test cases pass for these crates?
| //! fn parse_flatzinc(source: &str) -> MyInstance { | ||
| //! // First, the source string is parsed into a structured representation. | ||
| //! // | ||
| //! // Note: the `fzn_rs::fzn` module is only available with the `fzn` feature enabled. |
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.
Is it explained anywhere what this feature is?
Our current FlatZinc parser implementation works, but it has a few flaws:
fznformat, as well as the new JSON-based format.That is why this PR introduces a new FlatZinc parsing crate, which provides the following:
fzn-rsfor an idea of what that looks like.