Skip to content

Fix #2137: Create dummy companions for top-level objects without a real one #2139

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 3 commits into from
Mar 28, 2017

Conversation

smarter
Copy link
Member

@smarter smarter commented Mar 23, 2017

Previously, we sometimes ended up forcing a companion class symbol from
a previous run or from the classpath which lead to weird issues like in
tests/pos-special/false-companion. Even if we end up not forcing such
a symbol, its presence can still lead to issue: before this commit
incremental compilation of dotty-compiler-bootstrapped was broken
because we recorded a false dependency on the non-bootstrapped
dotty-compiler jar.

This reverts commit 57641b9.

Using `Type#select` instead of `Type#member` turned out to not help at
all in avoiding false dependencies, you can still get a symbol whose
denotation does not reallyExists. A proper fix for this issue is
contained in the next commit.
@smarter smarter requested a review from odersky March 23, 2017 16:44
@smarter
Copy link
Member Author

smarter commented Mar 23, 2017

/cc @felixmulder My added special test will conflict with your PR, sorry!

@smarter
Copy link
Member Author

smarter commented Mar 23, 2017

@felixmulder Actually scratch that, I don't need to do anything special to get the test to run correctly with partest.

@smarter smarter force-pushed the fix/false-companion branch from dc50896 to 47a2593 Compare March 23, 2017 19:42
… a real one

Previously, we sometimes ended up forcing a companion class symbol from
a previous run or from the classpath which lead to weird issues like in
`false-companion`. Even if we end up not forcing such a symbol, its
presence can still lead to issue: before this commit incremental
compilation of `dotty-compiler-bootstrapped` was broken because we
recorded a false dependency on the non-bootstrapped `dotty-compiler`
jar.

The added test is currently marked pending because it does not work with
JUnit (which doesn't handle separate compilation), only partest. I
didn't managed to get it to work right, and this won't be necessary once
our testing framework is overhauled by
scala#2125 anyway, so I'll just have to
remember to enable this test afterwards.
@smarter smarter force-pushed the fix/false-companion branch from 47a2593 to df40ac6 Compare March 23, 2017 20:14
@smarter
Copy link
Member Author

smarter commented Mar 23, 2017

While the test works fine with partest,I couldn't get it to even compile with JUnit, and making it do so seems complicated, so I'll just disable it until #2125 is in.

@odersky
Copy link
Contributor

odersky commented Mar 23, 2017

What's the problem with junit?

@smarter
Copy link
Member Author

smarter commented Mar 23, 2017

it will try to compile the four files together, but two of them define the same object, so it fails. I tried using the trick you used for pos_t5545 but that fails too, because the second run needs the output of the first run to work. I tried changing the compiler options so that the output of the first run is in the classpath of the second run and that failed again and at that point I gave up.

@smarter
Copy link
Member Author

smarter commented Mar 24, 2017

@felixmulder http://dotty-ci.epfl.ch/lampepfl/dotty/1418/4 has been marked in progress for 21 hours, even though all tests finished successfully, any idea what's going on? This also seems to be happenning in http://dotty-ci.epfl.ch/lampepfl/dotty/1423/3 which succeeded a while ago but has been marked in progress for 2 hours now. Meanwhile, I'll push-force commits with a different timestamp to force the CI to rerun.

The previous commit introduced two new usages of `denotNamed` which broke
tests/run/t1987b because `denotNamed` indirectly calls `packageObj`
which caches the package object, except that at this point the package
object is not yet entered, so the cache was incorrect. We fix this by
using `effectiveScope.lookup` instead since we only need to look into
the current scope, this is also true for the two existing usage of
`denotNamed` in `createCompanionLinks` so they were also replaced by
`effectiveScope.lookup`.
@smarter smarter force-pushed the fix/false-companion branch from df40ac6 to b641181 Compare March 24, 2017 16:54
@felixmulder
Copy link
Contributor

felixmulder commented Mar 24, 2017 via email

@smarter
Copy link
Member Author

smarter commented Mar 24, 2017

I was hoping there was some debug information we could recover to understand what's going on before restarting stuff

@felixmulder
Copy link
Contributor

felixmulder commented Mar 24, 2017 via email

@smarter
Copy link
Member Author

smarter commented Mar 24, 2017

How do I know what logs correspond to a specific test run?

@felixmulder
Copy link
Contributor

felixmulder commented Mar 24, 2017 via email

@smarter
Copy link
Member Author

smarter commented Mar 28, 2017

Ping for review.

Copy link
Contributor

@DarkDimius DarkDimius left a comment

Choose a reason for hiding this comment

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

LGTM, but this change may conflict with the semantic names PR. If it does I propose to not merge it yet.

@smarter
Copy link
Member Author

smarter commented Mar 28, 2017

why would it conflict?

@smarter
Copy link
Member Author

smarter commented Mar 28, 2017

It doesn't conflict currently so I think it's fine.

@smarter smarter merged commit 9ba9b14 into scala:master Mar 28, 2017
smarter added a commit to dotty-staging/dotty that referenced this pull request Mar 29, 2017
In scala#2139 I added code to create dummy companions for companion-less
objects, but not for companion-less classes because I thought it wasn't
needed. But it turns out that even if the classpath only has `Foo.class`
and not `Foo$.class`, a module for `Foo` is entered by
`initializeFromClassPath` when it calls `enterClassAndModule`, so we
have to add dummy companions to classes. I don't have a test to
illustrate this issue, but note that it fixes the incremental
compilation bug demonstrated by
https://github.com/dotty-staging/dotty/commits/incremental-compilation-bug.

Note: I verified that adding a dummy companion to "class Foo" did not
cause the backend to emit a Foo$.class, so this should have no visible
impact.
@allanrenucci allanrenucci deleted the fix/false-companion branch December 14, 2017 19:22
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.

4 participants