-
Notifications
You must be signed in to change notification settings - Fork 121
Fix #102: Better main class detection #287
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
I'm unsure this is possible at all. API detection needs dealiased types to work correctly. @smarter I'll review this one, thanks for the PR. |
API detection of what? |
4e52bf4
to
a355a43
Compare
|
81bec72
to
1ed5b11
Compare
I fixed the added test to:
|
1ed5b11
to
80a2a13
Compare
Ping for review. |
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.
LGTM. Excellent job!
It's true that we need to put the hooks (or provide the necessary information) to detect main classes for tests. I'll look into the best way to do so.
@@ -0,0 +1,4 @@ | |||
> compile |
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.
These tests look great!
@@ -94,6 +96,16 @@ object ClassToAPI { | |||
val defsEmptyMembers = clsDef :: statDef :: Nil | |||
cmap.memo(name) = defsEmptyMembers | |||
cmap.allNonLocalClasses ++= defs | |||
|
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.
👍
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 is imperfect because it relies on ExtractAPI
dealiasing types (because Discovery will look for a main method with a
parameter type of java.lang.String and won't recognize
scala.Predef.String), dealiasing means that the extracted API looses
information and thus can lead to undercompilation.
Is it possible to fix the root cause rather than adding special case for main class detection?
The root cause is the use of Discovery, the fix is to not use Discovery and the same should be done for tests, and Discovery should be removed. There is no way to make Discovery understand all the semantics of Scala type system. |
80a2a13
to
5a4cb09
Compare
Previously, the main class detection was handled by https://github.com/sbt/zinc/blob/1.0/internal/zinc-apiinfo/src/main/scala/xsbt/api/Discovery.scala which looks for a main method with the correct signature in the extracted API. This is imperfect because it relies on ExtractAPI dealiasing types (because Discovery will look for a main method with a parameter type of `java.lang.String` and won't recognize `scala.Predef.String`), dealiasing means that the extracted API looses information and thus can lead to undercompilation. This commit partially fixes this by adding a new callback to AnalysisCallback: void mainClass(File sourceFile, String className) that is used to explicitly register main entry points. This way, tools do not need to interpret the extracted API, this is much better since it makes it easier for zinc to evolve the API representation. This commit does not actually changes ExtractAPI to not dealias, this can be done in a later PR. Note that there is another usecase for xsbt.api.Discovery that this PR does not replace: discovering tests. This is more complicated because different test frameworks have different ways to discover tests. For more information, grep for "Fingerprint" in https://github.com/sbt/sbt and https://github.com/sbt/junit-interface
5a4cb09
to
f10c53c
Compare
Updated, phew! Hopefully this gets merged before the next major reformatting/refactoring of the codebase. |
See sbt/zinc#287 for details.
See sbt/zinc#287 for details.
Use seed.next for Success in Cogen for Try
Previously, the main class detection was handled by
https://github.com/sbt/zinc/blob/1.0/internal/zinc-apiinfo/src/main/scala/xsbt/api/Discovery.scala
which looks for a main method with the correct signature in the
extracted API. This is imperfect because it relies on ExtractAPI
dealiasing types (because Discovery will look for a main method with a
parameter type of
java.lang.String
and won't recognizescala.Predef.String
), dealiasing means that the extracted API loosesinformation and thus can lead to undercompilation.
This commit partially fixes this by adding a new callback to AnalysisCallback:
that is used to explicitly register main entry points. This way, tools
do not need to interpret the extracted API, this is much better since it
makes it easier for zinc to evolve the API representation.
This commit does not actually changes ExtractAPI to not dealias, this
can be done in a later PR.
Note that there is another usecase for xsbt.api.Discovery that this PR
does not replace: discovering tests. This is more complicated because
different test frameworks have different ways to discover tests. For
more information, grep for "Fingerprint" in https://github.com/sbt/sbt
and https://github.com/sbt/junit-interface
Note also that the added scripted test does not actually test that this
PR is correct since sbt itself needs to be updated to use this new API,
the branch at
https://github.com/smarter/sbt/commits/fix/main-class-detection does
this, but cannot be merged in sbt until a new zinc is published.
Fix #102