-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #2944: propagate information from GADT bounds to normal info. #2958
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
All tests passed! |
@nicolasstucki, i've added a test file for #2944 but it just tests compilation, which produced wrong tasty before this fix. |
def get(k: K): K = k | ||
def foo: K = { | ||
this match { | ||
case that: Map2[b] => that.get(3.asInstanceOf[b]) |
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 test case passes my the check with my tests 👍
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.
Do we have a real test for this now?
def foo: K = { | ||
this match { | ||
case that: Map2[b] => that.get(3.asInstanceOf[b]) | ||
//case that: Map2[c] => that.get(4.asInstanceOf[K]) |
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 one still crashes while trying to type that.get(4.asInstanceOf[K].asInstanceOf[b @ b])
.
|
||
import tpd._ | ||
|
||
def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation = { | ||
if (sym.is(BindDefinedType) && ctx.gadt.bounds.contains(sym.symbol)) { | ||
sym.copySymDenotation(info = ctx.gadt.bounds.apply(sym.symbol) & sym.info) |
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.
you could probably remove sym.symbol
from the ctx.gadt.bounds
map at that point too.
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 still think this is possible but ¯\_(ツ)_/¯
|
||
import tpd._ | ||
|
||
def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation = { |
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.
Nitpick: sym
is usually used for symbols, for a denotation I would use ref
or d
.
You can't. You'll need to remove it from top context
…On 4 August 2017 2:41:58 pm Guillaume Martres ***@***.***> wrote:
smarter commented on this pull request.
>
import tpd._
+ def transformSym(sym: SymDenotation)(implicit ctx: Context):
SymDenotation = {
+ if (sym.is(BindDefinedType) && ctx.gadt.bounds.contains(sym.symbol)) {
+ sym.copySymDenotation(info = ctx.gadt.bounds.apply(sym.symbol) &
sym.info)
you could probably remove `sym.symbol` from the `ctx.gadt.bounds` map at
that point too.
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#2958 (review)
|
Name sym is used consistently in all SymTransforms. See original trait.
…On 4 August 2017 2:42:30 pm Guillaume Martres ***@***.***> wrote:
smarter commented on this pull request.
>
import tpd._
+ def transformSym(sym: SymDenotation)(implicit ctx: Context):
SymDenotation = {
Nitpick: `sym` is usually used for symbols, for a denotation I would use
`ref` or `d`.
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#2958 (review)
|
% git grep "def transformSym" compiler
compiler/src/dotty/tools/dotc/core/DenotTransformers.scala: def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation
compiler/src/dotty/tools/dotc/transform/Flatten.scala: def transformSym(ref: SymDenotation)(implicit ctx: Context) = {
compiler/src/dotty/tools/dotc/transform/Getters.scala: override def transformSym(d: SymDenotation)(implicit ctx: Context): SymDenotation = {
compiler/src/dotty/tools/dotc/transform/Mixin.scala: override def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation =
compiler/src/dotty/tools/dotc/transform/MoveStatics.scala: def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation = {
compiler/src/dotty/tools/dotc/transform/NormalizeFlags.scala: def transformSym(ref: SymDenotation)(implicit ctx: Context) = {
compiler/src/dotty/tools/dotc/transform/PrivateToStatic.scala.disabled: override def transformSym(sd: SymDenotation)(implicit ctx: Context): SymDenotation =
compiler/src/dotty/tools/dotc/transform/TreeChecker.scala: def transformSym(symd: SymDenotation)(implicit ctx: Context): SymDenotation = { I think everyone is confused about what name to use :). |
Nice) will look into it! Curious why the bind node is inside of cast... |
Why? When we create a fresh context we keep a reference to the same |
@nicolasstucki , though I authored this testcase, I forgot how to make this bind appear. |
Ok, found a bug by reading code. TreeUnpickeler.readTpt is obviously wrong. |
@DarkDimius you can reproduce it easily for this branch https://github.com/dotty-staging/dotty/tree/link-from-tasty-show-bug. Just run the |
That branch contains the current fix. |
@nicolasstucki, could you please validate that the last commit fixes the issue? |
It did not fix it, but that is clearly the source of the issue. Now I get:
Note that you did replace the binding by the |
@nicolasstucki, sorry. I did a stupid mistake :-) Fix incomming. |
Oh... it is actually much worse: on unpickling, c becomes a term. |
aaaand we create symbol for it twice on unpickling. And those two symbols are obviously incompatible between each other. |
I propose we postpone fixing the remaining bug till next dotty meeting. My proposed fix is to revert 79e2228 and ad6b578. Those commits made bind be handled as-if it was TypeTree in Tasty. This broke a lot of stuff because unpickler assumes that it can read TypeTrees repeatedly, which is not true for bind, which is a DefTree. We assume in multiple locations that DefTree should be only read once, as you'll get a fresh symbol every time you read it. |
@nicolasstucki, is the remaining bug also a blocker? |
@DarkDimius ~~~the fix in the first commit unblocked it~~~. The second could be left for later, lets open a separate issue for it. Thanks. |
Unfortunately the the first fix did not work in the original code from I minimised the issue again to trait Map2[K] {
def get(k: K): K = k
def foo = {
val o = new Object
o match { // now match on Object and not this
case that: Map2[b] => that.get(3.asInstanceOf[b])
case _ => get(5.asInstanceOf[K])
}
}
} |
@nicolasstucki and I have figured that this is another manifestation of #2958 (comment) |
This allows all other parts of pipeline to be less aware of existence of the GADT bounds. In particular, it makes us pickle them as normal type bounds.
binds are "shared" as type trees would be shared, see scala#2510 But they are not type trees, as you can't have them inside TypeApply. See i2944a.scala.
This reverts commit 30ec34f.
0a5e873
to
1c0f63f
Compare
Rebased. @smarter could you re-review this quickly before merging. |
test performance please This PR fails the compilation of https://github.com/liufengyun/scalaPB on the bench server. |
performance test scheduled: 1 job(s) in queue, 0 running. |
performance test failed: [check /data/workspace/bench/logs/pull-2958-09-25-14.39.out for more information] |
This allows all other parts of pipeline to be less aware of existence
of the GADT bounds.
In particular, it makes us pickle them as normal type bounds.