Skip to content

Commit 7a01b0f

Browse files
committed
keep given instance summoner type params
1 parent ec3a21a commit 7a01b0f

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class ExtractSemanticDB extends Phase:
8080
|| sym.is(Synthetic)
8181
|| sym.isSetter
8282
|| sym.isOldStyleImplicitConversion(forImplicitClassOnly = true)
83-
|| sym.owner.isGivenInstanceSummoner
83+
|| sym.isTypeParam && sym.owner.isGivenInstanceClass
8484
|| excludeDefOrUse(sym)
8585

8686
private def excludeDefOrUse(sym: Symbol)(using Context): Boolean =

compiler/src/dotty/tools/dotc/semanticdb/Tools.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ object Tools:
4141
document.copy(text = text)
4242
end loadTextDocument
4343

44+
def loadTextDocumentUnsafe(scalaAbsolutePath: Path, semanticdbAbsolutePath: Path): TextDocument =
45+
val docs = parseTextDocuments(semanticdbAbsolutePath).documents
46+
assert(docs.length == 1)
47+
docs.head.copy(text = new String(Files.readAllBytes(scalaAbsolutePath), StandardCharsets.UTF_8))
48+
4449
/** Parses SemanticDB text documents from an absolute path to a `*.semanticdb` file. */
4550
private def parseTextDocuments(path: Path): TextDocuments =
4651
val bytes = Files.readAllBytes(path) // NOTE: a semanticdb file is a TextDocuments message, not TextDocument

compiler/src/dotty/tools/dotc/transform/SymUtils.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ object SymUtils:
8787

8888
def isGenericProduct(using Context): Boolean = whyNotGenericProduct.isEmpty
8989

90-
/** Is this the an old style implicit conversion?
90+
/** Is this an old style implicit conversion?
9191
* @param directOnly only consider explicitly written methods
9292
* @param forImplicitClassOnly only consider methods generated from implicit classes
9393
*/
@@ -100,6 +100,7 @@ object SymUtils:
100100
case _ =>
101101
false
102102

103+
/** Is this the method that summons a structural given instance? */
103104
def isGivenInstanceSummoner(using Context): Boolean =
104105
def isCodefined(info: Type): Boolean = info.stripPoly match
105106
case mt: MethodType =>
@@ -111,6 +112,9 @@ object SymUtils:
111112
self.isCoDefinedGiven(res.typeSymbol)
112113
self.isAllOf(Given | Method) && isCodefined(self.info)
113114

115+
def isGivenInstanceClass(using Context): Boolean =
116+
self.isClass && self.is(Given)
117+
114118
def useCompanionAsMirror(using Context): Boolean = self.linkedClass.exists && !self.is(Scala2x)
115119

116120
/** Is this a sealed class or trait for which a sum mirror is generated?

compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ import dotty.tools.dotc.util.SourceFile
2525
@main def updateExpect =
2626
SemanticdbTests().runExpectTest(updateExpectFiles = true)
2727

28+
@main def metac(root: String, source: String) =
29+
val rootSrc = Paths.get(root)
30+
val sourceSrc = Paths.get(source)
31+
val semanticFile = FileSystems.getDefault.getPathMatcher("glob:**.semanticdb")
32+
def inputFiles(): List[Path] =
33+
val ls = Files.walk(rootSrc.resolve("META-INF").resolve("semanticdb"))
34+
val files =
35+
try ls.filter(p => semanticFile.matches(p)).collect(Collectors.toList).asScala
36+
finally ls.close()
37+
require(files.nonEmpty, s"No semanticdb files! $rootSrc")
38+
files.toList
39+
val metacSb: StringBuilder = StringBuilder(5000)
40+
for
41+
semanticdbPath <- inputFiles().sorted
42+
do
43+
val doc = Tools.loadTextDocumentUnsafe(sourceSrc.toAbsolutePath, semanticdbPath)
44+
Tools.metac(doc, Paths.get(doc.uri))(using metacSb)
45+
Files.write(rootSrc.resolve("metac.expect"), metacSb.toString.getBytes(StandardCharsets.UTF_8))
46+
47+
2848
@Category(Array(classOf[BootstrappedOnlyTests]))
2949
class SemanticdbTests:
3050
val javaFile = FileSystems.getDefault.getPathMatcher("glob:**.java")

tests/semanticdb/expect/InventedNames.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ given X/*->givens::X#*/ with
2525
given (using X/*->givens::X#*/): Y/*->givens::Y#*/ with
2626
def doY/*<-givens::InventedNames$package.given_Y#doY().*/ = "7"
2727

28-
given [T/*<-givens::InventedNames$package.given_Z_T#[T]*/]: Z/*->givens::Z#*/[T/*->givens::InventedNames$package.given_Z_T#[T]*/] with
28+
given [T/*<-givens::InventedNames$package.given_Z_T().[T]*/]: Z/*->givens::Z#*/[T/*->givens::InventedNames$package.given_Z_T#[T]*/] with
2929
def doZ/*<-givens::InventedNames$package.given_Z_T#doZ().*/: List/*->scala::package.List#*/[T/*->givens::InventedNames$package.given_Z_T#[T]*/] = Nil/*->scala::package.Nil.*/
3030

3131

tests/semanticdb/metac.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ Occurrences:
17661766
[24:13..24:14): X -> givens/X#
17671767
[24:17..24:18): Y -> givens/Y#
17681768
[25:6..25:9): doY <- givens/InventedNames$package.given_Y#doY().
1769-
[27:7..27:8): T <- givens/InventedNames$package.given_Z_T#[T]
1769+
[27:7..27:8): T <- givens/InventedNames$package.given_Z_T().[T]
17701770
[27:11..27:12): Z -> givens/Z#
17711771
[27:13..27:14): T -> givens/InventedNames$package.given_Z_T#[T]
17721772
[28:6..28:9): doZ <- givens/InventedNames$package.given_Z_T#doZ().

0 commit comments

Comments
 (0)