Skip to content

Commit c1c1e95

Browse files
committed
new Invisble flag semantics
- now invisible members are visible in typer when resolving SELECTin from TASTy. - add sbt-test/tasty-compat test to demonstrate when inline method calls forwarder
1 parent 3f2925f commit c1c1e95

File tree

12 files changed

+98
-6
lines changed

12 files changed

+98
-6
lines changed

compiler/src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ object Denotations {
10721072
def filterDisjoint(denots: PreDenotation)(using Context): SingleDenotation =
10731073
if (denots.exists && denots.matches(this)) NoDenotation else this
10741074
def filterWithFlags(required: FlagSet, excluded: FlagSet)(using Context): SingleDenotation =
1075-
val realExcluded = if ctx.isAfterTyper then excluded else excluded | Invisible
1075+
val realExcluded = if ctx.isAfterTyper then excluded else excluded | (if ctx.mode.is(Mode.ResolveFromTASTy) then EmptyFlags else Invisible)
10761076
def symd: SymDenotation = this match
10771077
case symd: SymDenotation => symd
10781078
case _ => symbol.denot

compiler/src/dotty/tools/dotc/core/Mode.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ object Mode {
105105

106106
/** Use previous Scheme for implicit resolution. Currently significant
107107
* in 3.0-migration where we use Scala-2's scheme instead and in 3.5 and 3.6-migration
108-
* where we use the previous scheme up to 3.4 for comparison with the new scheme.
108+
* where we use the previous scheme up to 3.4 for comparison with the new scheme.
109109
*/
110110
val OldImplicitResolution: Mode = newMode(15, "OldImplicitResolution")
111111

@@ -125,6 +125,9 @@ object Mode {
125125
/** Read original positions when unpickling from TASTY */
126126
val ReadPositions: Mode = newMode(17, "ReadPositions")
127127

128+
/** We are resolving a SELECT name from TASTy */
129+
val ResolveFromTASTy: Mode = newMode(18, "ResolveFromTASTy")
130+
128131
/** We are elaborating the fully qualified name of a package clause.
129132
* In this case, identifiers should never be imported.
130133
*/

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ object SymDenotations {
617617
case _ =>
618618
// Otherwise, no completion is necessary, see the preconditions of `markAbsent()`.
619619
(myInfo `eq` NoType)
620-
|| is(Invisible) && ctx.isTyper
620+
|| (is(Invisible) && !ctx.mode.is(Mode.ResolveFromTASTy)) && ctx.isTyper
621621
|| is(ModuleVal, butNot = Package) && moduleClass.isAbsent(canForce)
622622
}
623623

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ class TreeUnpickler(reader: TastyReader,
15631563
* - sbt-test/tasty-compat/remove-override
15641564
* - sbt-test/tasty-compat/move-method
15651565
*/
1566-
def lookupInSuper =
1566+
def lookupInSuper(using Context) =
15671567
val cls = ownerTpe.classSymbol
15681568
if cls.exists then
15691569
cls.asClass.classDenot
@@ -1572,14 +1572,18 @@ class TreeUnpickler(reader: TastyReader,
15721572
else
15731573
NoDenotation
15741574

1575-
val denot =
1575+
1576+
def searchDenot(using Context): Denotation =
15761577
if owner.is(JavaAnnotation) && name == nme.CONSTRUCTOR then
15771578
// #19951 Fix up to read TASTy produced before 3.5.0 -- ignore the signature
15781579
ownerTpe.nonPrivateDecl(name).asSeenFrom(prefix)
15791580
else
15801581
val d = ownerTpe.decl(name).atSignature(sig, target)
15811582
(if !d.exists then lookupInSuper else d).asSeenFrom(prefix)
15821583

1584+
val denot = inContext(ctx.addMode(Mode.ResolveFromTASTy)):
1585+
searchDenot // able to resolve Invisible members
1586+
15831587
makeSelect(qual, name, denot)
15841588
case REPEATED =>
15851589
val elemtpt = readTpt()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package a
2+
3+
import scala.annotation.unroll
4+
5+
object A {
6+
7+
def foo(s: String, x: Int, @unroll b: Boolean = true): String = s + x + b
8+
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package a
2+
3+
import scala.annotation.unroll
4+
5+
object A {
6+
7+
def foo(s: String, x: Int): String = s + x
8+
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package b
2+
3+
import a.*
4+
5+
object B {
6+
transparent inline def caller = A.foo("abc", 2)
7+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
lazy val commonSettings = Seq(
2+
scalacOptions += "-experimental",
3+
)
4+
5+
lazy val printSettings = Seq(
6+
scalacOptions += "-Yprint-tasty",
7+
)
8+
9+
lazy val a = project.in(file("a"))
10+
.settings(commonSettings)
11+
.settings(
12+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "b-input"
13+
)
14+
15+
lazy val b = project.in(file("b"))
16+
.settings(commonSettings)
17+
.settings(
18+
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "b-input",
19+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-input"
20+
)
21+
22+
lazy val `a-changes` = project.in(file("a-changes"))
23+
.settings(commonSettings)
24+
.settings(
25+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-input"
26+
)
27+
28+
lazy val c = project.in(file("c"))
29+
.settings(commonSettings)
30+
.settings(printSettings)
31+
.settings(
32+
// scalacOptions ++= Seq("-from-tasty", "-Ycheck:readTasty", "-Xfatal-warnings", "-Xprint:readTasty", "-Xprint-types"),
33+
// Compile / sources := Seq(new java.io.File("c-input/B.tasty")),
34+
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "c-input",
35+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-output"
36+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import b.*
2+
3+
object C {
4+
val res = B.caller
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sbt._
2+
import Keys._
3+
4+
object DottyInjectedPlugin extends AutoPlugin {
5+
override def requires = plugins.JvmPlugin
6+
override def trigger = allRequirements
7+
8+
override val projectSettings = Seq(
9+
scalaVersion := sys.props("plugin.scalaVersion")
10+
)
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# compile library A
2+
> a/compile
3+
# compile library B, from source, against A
4+
> b/compile
5+
# add a new parameter in method to library A', using @unroll to generate a forwarder
6+
> a-changes/compile
7+
# compile B, from tasty, against A', it should still compile: the generated forwarder is resolved.
8+
> c/compile

tasty/src/dotty/tools/tasty/TastyFormat.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ Standard-Section: "ASTs" TopLevelStat*
227227
PARAMalias -- Parameter is alias of a superclass parameter
228228
EXPORTED -- An export forwarder
229229
OPEN -- an open class
230-
INVISIBLE -- invisible during typechecking
230+
INVISIBLE -- invisible during typechecking, except when resolving from TASTy
231231
TRACKED -- a tracked class parameter / a dependent class
232232
Annotation
233233

0 commit comments

Comments
 (0)