-
Notifications
You must be signed in to change notification settings - Fork 267
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
Nested LetExpr chain compiles to tons of nested Java lambdas, which javac chokes on #3868
Comments
More details: the optimization is only valid when a let expression is used in a context that can emit multiple sequential statements, such as the top-level body of a (Edit: to clarify, I'm referring to multiple sequential target-language statements, so it's likely that The general solution to this is probably to introduce synthetic methods to compute subexpressions, so that the optimization can be applied more consistently. This is also the best way to work around it in source code, ensuring that chained let expressions only appear at the top level (and perhaps we can lint for this in the short term). |
This will also happen for a datatype that has a lot of constructors. include "Wrappers.dfy"
module Test {
import opened Wrappers
datatype Or =
| A(x1: string, x2: string, x3: string, x4: string, x5: string, x6: string, x7: string, x8: string, x9: string, x10: string)
| B
function WoahThatsDeep(o: Or, x: string): Option<string> {
var r :- match o {
case A(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) =>
Some(x10)
case B =>
Some("hello")
};
Some(r)
}
method Main() {
print WoahThatsDeep(A, "42"), "\n";
}
} |
Emit better target code for match-case expressions. In particular, avoid some deeply nested IIFE's that (were hard for a human to read and) caused the Java compiler to choke. Fixes #3868 <small>By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
Re-opening since it's certainly still possible to hit this, even if the linked PR improved things a lot. |
Dafny version
4.0.0
Code to produce this issue
Command to run and resulting output
What happened?
The translated java code looks like this:
Normally a chain of let expressions (i.e.
var x1 := x; var x2 := x1; ...
) is optimized to compile to a sequence of regular variable declarations in Java, but because this one is inside a match expression rather than at the top level, the optimization isn't currently applied.What type of operating system are you experiencing the problem on?
Mac
The text was updated successfully, but these errors were encountered: