Skip to content

Conversation

@nicolasstucki
Copy link
Contributor

No description provided.

val Apply(fun, args) = tree
if (fun.symbol == defn.cbnArg)
typedUnadapted(args.head, pt)
else if ((tree.symbol.name == nme.box || tree.symbol.name == nme.unbox) && tree.symbol.owner.asClass.companionClass == defn.UnitClass) ref(defn.BoxedUnit_UNIT)
Copy link
Member

Choose a reason for hiding this comment

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

That drops the side effects of args.head, unless I'm mistaken.

override def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = {
val Apply(fun, args) = tree
if (fun.symbol == defn.cbnArg)
if (fun.symbol == defn.cbnArg || (tree.symbol.name == nme.box || tree.symbol.name == nme.unbox) && tree.symbol.owner.asClass.companionClass == defn.UnitClass)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would factor out the newly added tests into an inner function, to make it clear what is tested: def isUnitBoxOrUnbox(fun: Symbol)

Copy link
Member

@smarter smarter left a 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 why these methods need to be erased. They have a legitimate implementation in https://github.com/scala/scala/blob/2.13.x/src/library/scala/Unit.scala, why is the backend exploding on them in the first place?

@nicolasstucki
Copy link
Contributor Author

Fixes are in backend lampepfl/scala#30

@nicolasstucki nicolasstucki changed the title Fix #3518: Erase explicit Unit.box and Unit.unbox in erasure Fix #3518: Do not generate calls to BoxesRunTime for Unit box/unbox Nov 27, 2017
@nicolasstucki
Copy link
Contributor Author

@smarter now it does the same as in scalac


def isBox(sym: Symbol): Boolean = Erasure.Boxing.isBox(sym)
def isUnbox(sym: Symbol): Boolean = Erasure.Boxing.isUnbox(sym)
def isBox(sym: Symbol): Boolean = Erasure.Boxing.isBox(sym) && !isInUnit(sym)
Copy link
Member

Choose a reason for hiding this comment

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

Why not change the definition of Erasure.Boxing.isBox directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Erasure does transformations on Unit box inbox based on Boxing.isBox. If I add that condition directly there erasure starts failing.

Copy link
Member

Choose a reason for hiding this comment

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

ok

def isBox(sym: Symbol): Boolean = Erasure.Boxing.isBox(sym) && !isInUnit(sym)
def isUnbox(sym: Symbol): Boolean = Erasure.Boxing.isUnbox(sym) && !isInUnit(sym)

private def isInUnit(sym: Symbol) = sym.denot.owner.denot.linkedClass == defn.UnitClass
Copy link
Member

Choose a reason for hiding this comment

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

I would add a defn.UnitModule instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@nicolasstucki nicolasstucki merged commit 60d04ca into scala:master Dec 11, 2017
@allanrenucci allanrenucci deleted the fix-#3518 branch December 11, 2017 13:00
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.

5 participants