-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix overcompilation due to unstable context bound desugaring #18280
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package database | ||
|
||
object A { | ||
def wrapper: B.Wrapper = ??? | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package database | ||
|
||
object B { | ||
trait GetValue[T] | ||
|
||
object GetValue { | ||
implicit def inst[T]: GetValue[T] = ??? | ||
} | ||
|
||
class ResultSet { | ||
def getV[A: GetValue]: A = ??? | ||
} | ||
|
||
trait DBParse[T] { | ||
def apply(rs: ResultSet): T | ||
} | ||
|
||
class AVG() { | ||
def call: String = "AVG" | ||
} | ||
|
||
object ClientOwnerId { | ||
class CompanyId | ||
|
||
def parseClientOwnerId[T: DBParse]: Unit = {} | ||
} | ||
|
||
class Wrapper(companyId: ClientOwnerId.CompanyId) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package database | ||
|
||
object C { | ||
def foo: Unit = { | ||
val rs: B.ResultSet = ??? | ||
rs.getV[String] | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
scalaVersion := sys.props("plugin.scalaVersion") | ||
|
||
import sbt.internal.inc.Analysis | ||
import complete.DefaultParsers._ | ||
|
||
// Reset compiler iterations, necessary because tests run in batch mode | ||
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.") | ||
recordPreviousIterations := { | ||
val log = streams.value.log | ||
CompileState.previousIterations = { | ||
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala | ||
previousAnalysis match { | ||
case None => | ||
log.info("No previous analysis detected") | ||
0 | ||
case Some(a: Analysis) => a.compilations.allCompilations.size | ||
} | ||
} | ||
} | ||
|
||
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.") | ||
|
||
checkIterations := { | ||
val expected: Int = (Space ~> NatBasic).parsed | ||
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations | ||
assert(expected == actual, s"Expected $expected compilations, got $actual") | ||
} |
27 changes: 27 additions & 0 deletions
27
sbt-test/source-dependencies/stable-ctx-bounds/changes/B.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package database | ||
|
||
object B { | ||
trait GetValue[T] | ||
|
||
object GetValue { | ||
implicit def inst[T]: GetValue[T] = ??? | ||
} | ||
|
||
class ResultSet { | ||
def getV[A: GetValue]: A = ??? | ||
} | ||
|
||
trait DBParse[T] | ||
|
||
class AVG() { | ||
def call: String = "AVG2" | ||
} | ||
|
||
object ClientOwnerId { | ||
class CompanyId | ||
|
||
def parseClientOwnerId[T: DBParse]: Unit = {} | ||
} | ||
|
||
class Wrapper(companyId: ClientOwnerId.CompanyId) | ||
} |
4 changes: 4 additions & 0 deletions
4
sbt-test/source-dependencies/stable-ctx-bounds/project/CompileState.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This is necessary because tests are run in batch mode | ||
object CompileState { | ||
@volatile var previousIterations: Int = -1 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
> compile | ||
> recordPreviousIterations | ||
|
||
# change only the body of a method | ||
$ copy-file changes/B.scala B.scala | ||
|
||
# Only B.scala should be recompiled. Previously, this lead to a subsequent | ||
# compilation round because context bounds were desugared into names unique to | ||
# the whole compilation unit, and in the first `compile` the two context bounds | ||
# of B.scala were desugared into `evidence$2` and `evidence$1` in this order | ||
# (because the definitions were visited out of order), but in the second call | ||
# to `compile` we traverse them in order as we typecheck B.scala and ended up | ||
# with `evidence$1` and `evidence$2` instead. | ||
> compile | ||
> checkIterations 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
may be worth noting here the predicted order of typer visiting definitions in run 1 vs run 2, to illustrate how before the change it actually had unstable names between runs.