-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
7de8e7c
to
212b630
Compare
@@ -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) |
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.
That drops the side effects of args.head
, unless I'm mistaken.
b1d38f6
to
c437512
Compare
@@ -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) |
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 would factor out the newly added tests into an inner function, to make it clear what is tested: def isUnitBoxOrUnbox(fun: Symbol)
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 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?
4ca7d8d
to
749d9b4
Compare
Reimplemented fix. Now fix is in backend.
Fixes are in backend lampepfl/scala#30 |
749d9b4
to
40a25fd
Compare
scalac also ignores |
@smarter now it does the same as in |
@@ -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) |
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.
Why not change the definition of Erasure.Boxing.isBox directly?
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.
Erasure does transformations on Unit box inbox based on Boxing.isBox. If I add that condition directly there erasure starts failing.
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.
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 |
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 would add a defn.UnitModule instead.
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.
Done
40a25fd
to
85fb578
Compare
No description provided.