Skip to content

Fix #3518: Do not generate calls to BoxesRunTime for Unit box/unbox #3522

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

Merged
merged 1 commit into from
Dec 11, 2017

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@@ -479,6 +479,7 @@ object Erasure {
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.

@@ -477,7 +477,7 @@ object Erasure {
*/
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

@@ -169,8 +169,10 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
s eq defn.newArrayMethod
}

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