-
Notifications
You must be signed in to change notification settings - Fork 395
Do not make ReferenceType extend Type anymore. #2150
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
Review by @gzm0 |
Refer to this link for build results (access rights to CI server needed): https://scala-webapps.epfl.ch/jenkins/job/scalajs-pr/2704/ |
It seems I am lacking fundamental knowledge here. What is the difference between a type and a reference type? (I'm assuming this is not the reference type in "value type" v.s. "reference type"). |
A
A A
(in fact, there are two |
@@ -84,13 +84,14 @@ object Types { | |||
case object NullType extends Type | |||
|
|||
/** Reference types (allowed for classOf[], is/asInstanceOf[]). */ | |||
sealed abstract class ReferenceType extends Type | |||
sealed trait ReferenceType |
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.
Any reason you do not add a toType
method here that essentially returns this
(with this
having a self-type of Type with ReferenceType
)? It seems its less fragile than the casts but essentially does the same.
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 argue that it would be more fragile, because it would lead to people assuming that it is always safe and meaningful to convert a ReferenceType
into a Type
, which it is not.
The proper toType
conversion would require a predicate isJSType: /* className: */ String => Boolean
to know whether ClassType(className)
has to erase to AnyType
or not.
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, I see. But why then don't you mark the cast in asInstanceOf
as suspicious? IIUC we're doing the following wrong:
AsInstanceOf(???, ClassType("scala.Int")).tpe // -> ClassType("scala.Int")
But it should be IntType
.
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.
AsInstanceOf(???, ClassType("scala.Int"))
(which would actually be AsInstanceOf(???, ClassType("I"))
) is not valid IR. It would be Unbox(???, 'I')
which has tpe = IntType
.
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.
This whole business is super hacky. We should definitely re-design this aspect of the IR for the next major version. At least with this PR we make it obvious that it's hacky ...
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, fair enough.
Could you also paste what you wrote about reference types into the documentation of the |
That's all. |
Sure. |
Ok. So LGTM modulo the comment on |
a2bfe19
to
0827ded
Compare
Updated with the documentation. |
Refer to this link for build results (access rights to CI server needed): https://scala-webapps.epfl.ch/jenkins/job/scalajs-pr/2722/ |
0827ded
to
b2cbb09
Compare
A ReferenceType is fundamentally *not* a Type. It so happens that all concrete implementations of ReferenceType also implement Type, but those two concepts must not be confused. There are a few cases were it is OK-ish to treat a ReferenceType as a Type (such as serializing/hashing), for which we introduced casts. This refactoring highlights a suspicious usage of ReferenceType as Type in the OptimizerCore core. This commit leaves them as is, with casts.
Rebased on top of #2148. There was a compile error with the automatic clean merge. |
Refer to this link for build results (access rights to CI server needed): https://scala-webapps.epfl.ch/jenkins/job/scalajs-pr/2726/ |
LGTM |
Do not make ReferenceType extend Type anymore.
A ReferenceType is fundamentally not a Type. It so happens that
all concrete implementations of ReferenceType also implement Type,
but those two concepts must not be confused.
There are a few cases were it is OK-ish to treat a ReferenceType
as a Type (such as serializing/hashing), for which we introduced
casts.
This refactoring highlights a suspicious usage of ReferenceType as
Type in the OptimizerCore core. This commit leaves them as is,
with casts.