Skip to content

Only ignore inlined if conditions if pure. #2264

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

Conversation

nicolasstucki
Copy link
Contributor

Idempotent ones could have a side effect.

Idempotent ones could have a side effect.
@@ -527,7 +527,7 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
cond1.tpe.widenTermRefExpr match {
case ConstantType(Constant(condVal: Boolean)) =>
val selected = typed(if (condVal) tree.thenp else tree.elsep, pt)
if (isIdempotentExpr(cond1)) selected
if (isPureExpr(cond1)) selected
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact it looks like all constant type conditions that reach this code are pure. Are they all supposed to be in this particular case? If not how could I construct a condition that has a constant type and is not pure.

Copy link
Contributor

@DarkDimius DarkDimius Apr 15, 2017

Choose a reason for hiding this comment

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

I think code should be transformed in a different way instead(That's what is done in linker):

if ($cond: true.type) { $themp } else { $elsep } 

==>> 
cond$; 
thenp$

Similar for false.type .

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact it looks like all constant type conditions that reach this code are pure. Are they all supposed to be in this particular case?

lazy val s: true = { println(1); true}

@inline def bla = 
  if (s) {...} else {...}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That lazy val creates the idempotent condition with constant type. Just found another bug with lazy vals with constant type #2266.

@felixmulder
Copy link
Contributor

Deferring for now. Awaiting effects system :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants