-
Notifications
You must be signed in to change notification settings - Fork 323
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
Recognize if-like Tree.MultiSegmentApp as IfThenElse IR #11365
base: develop
Are you sure you want to change the base?
Conversation
To keep compatibility with original from Standard.Base import all
type X
Ok
Bad
if_then_else self ~t ~f = case self of
X.Ok -> t
X.Bad -> f
if_then self ~t = case self of
X.Ok -> t
X.Bad -> Nothing
main =
a = X.Ok.if_then_else "true" "false"
b = X.Bad.if_then_else "true" "false"
c = if X.Ok then "true" else "false"
d = if X.Bad then "true" else "false"
x = X.Ok.if_then "true"
y = X.Bad.if_then "true"
z = if X.Ok then "true"
w = if X.Bad then "true"
[a, b, c, d, x, y, z, w] should print It has to be Boolean!Decision: The condition of |
Instrumenter_Spec tests are failing probably because we don't support instrumentation inside of |
While working on this PR I realized that we represent every Creating wip/jtulach/LazyIfCaseOfBranches9165 branch and measuring startup again and engine. Let's see the result! |
After running engine benchmarks it looks like just converting Quite contrary. The most essential benchmark is slowing down. I guess direct conversion of This state of work is now preserved as ConvertingIfThenElseToCaseExpr and this PR will try to go different direction. |
…e all the sub-branches
Work on #11365 made me realize that `GraphOccurrence.Global` isn't really used anywhere. Simplifying the code by removing it and associated methods.
Standard library tests are green: https://github.com/enso-org/enso/actions/runs/11582091869/job/32244310882?pr=11365 Next: Fix error reporting - e.g. unit tests |
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.
The overall direction seems good. What are your intentions regarding scoping rules of the if-then-else branches?
boolean cond, | ||
ExpressionNode trueBranch, | ||
ExpressionNode falseBranch, | ||
@Shared("profile") @Cached InlinedCountingConditionProfile profile) { |
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.
nit: You don't have to specify the name "profile" here. It is OK to just specify @Shared
. As long as the parameter name is the same as in the other specialization, the shared annotation will work as expected.
|
||
/** The Enso case expression. */ | ||
case class IfThenElse( | ||
val cond: Expression, |
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.
nit: val
modifier is redundant for parameter of case class primary constructor
engine/runtime/src/main/java/org/enso/interpreter/node/controlflow/IfThenElseNode.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/node/controlflow/IfThenElseNode.java
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/node/controlflow/IfThenElseNode.java
Outdated
Show resolved
Hide resolved
engine/runtime-compiler/src/main/java/org/enso/compiler/pass/analyse/TailCall.java
Outdated
Show resolved
Hide resolved
engine/runtime-compiler/src/main/java/org/enso/compiler/pass/analyse/TailCall.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
@Test | ||
public void variableNotVisibleAfterBranches() throws Exception { |
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.
Testing scopes of if then else is a good idea. I would like to see more expanded tests. Something like:
x = True
if x then
y = True
if x then if y then "Foo"
and
x = False
cond = False
if cond then "cond" else
y = False
if x then "x" else
if y then "y" else 42
that is, try to use bindings from various parent scopes in the condition, true branch and false branch.
These tests could be placed in Base_Tests
as well I believe.
.asInstanceOf[Application.Prefix] | ||
.arguments(2) | ||
.value | ||
.asInstanceOf[IfThenElse] |
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.
IfThenElse
as a builtin IR is indeed better than representing it as Application.Prefix
with 2 arguments
t1 = table_builder [["X", [My_Type.Value 1 2, 2.0, 2]], ["Y", [10, 20, 30]]] | ||
t2 = table_builder [["Z", [2.0, 1.5, 2.0]], ["W", [1, 2, 3]]] | ||
r3 = t1.join t2 join_kind=Join_Kind.Inner on=(Join_Condition.Equals "X" "Z") on_problems=..Report_Warning | ||
t8 = table_builder [["X", [My_Type.Value 1 2, 2.0, 2]], ["Y", [10, 20, 30]]] |
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 don't understand the requirement that you cannot override a binding from parent scope in the branches. The true branch and else branch is nothing more than a block of expressions, right? The following code:
foo ~action =
action
main =
x = 42
foo <|
x = 23
x
prints 23, so it let's me override the x
from the parent scope as well.
Is this the desired state or is this still WIP?
… FrameAnalysisMeta is different.
Pull Request Description
Fixes #9165 by recognizing
if/then/else
in a special way. Introduces newIfThenElse
IR
element to represent bothif_then_else
as well asif_then
cases. Such element needs to be recognized by variousIR
processing passes and at the end converted into executableIfThenElseNode
inIrToTruffle
.Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,