Skip to content

Commit b012eee

Browse files
committed
Experiment: add new SourceInvisble TASTy flag
1 parent eeee3df commit b012eee

File tree

11 files changed

+42
-10
lines changed

11 files changed

+42
-10
lines changed

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

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

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ object Flags {
380380
/** Tracked modifier for class parameter / a class with some tracked parameters */
381381
val (Tracked @ _, _, Dependent @ _) = newFlags(46, "tracked")
382382

383+
/** Symbol can not be resolved from source during typer. PROVISIONAL (possibly replace with `Invisible` with new semantics) */
384+
val (SourceInvisible @ _, _, _) = newFlags(47, "<source-invisible>")
385+
383386
// ------------ Flags following this one are not pickled ----------------------------------
384387

385388
/** Symbol is not a member of its owner */
@@ -471,7 +474,7 @@ object Flags {
471474
Scala2SpecialFlags, MutableOrOpen, Opaque, Touched, JavaStatic,
472475
OuterOrCovariant, LabelOrContravariant, CaseAccessor, Tracked,
473476
Extension, NonMember, Implicit, Given, Permanent, Synthetic, Exported,
474-
SuperParamAliasOrScala2x, Inline, Macro, ConstructorProxy, Invisible)
477+
SuperParamAliasOrScala2x, Inline, Macro, ConstructorProxy, Invisible, SourceInvisible)
475478

476479
/** Flags that are not (re)set when completing the denotation, or, if symbol is
477480
* a top-level class or object, when completing the denotation once the class
@@ -525,7 +528,7 @@ object Flags {
525528
val RetainedModuleValAndClassFlags: FlagSet =
526529
AccessFlags | Package | Case |
527530
Synthetic | JavaDefined | JavaStatic | Artifact |
528-
Lifted | MixedIn | Specialized | ConstructorProxy | Invisible | Erased
531+
Lifted | MixedIn | Specialized | ConstructorProxy | Invisible | SourceInvisible | Erased
529532

530533
/** Flags that can apply to a module val */
531534
val RetainedModuleValFlags: FlagSet = RetainedModuleValAndClassFlags |

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

+4-1
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/NamerOps.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ object NamerOps:
110110
else NoSymbol.assertingErrorsReported(em"no companion $name in $scope")
111111

112112
/** If a class has one of these flags, it does not get a constructor companion */
113-
private val NoConstructorProxyNeededFlags = Abstract | Trait | Case | Synthetic | Module | Invisible
113+
private val NoConstructorProxyNeededFlags = Abstract | Trait | Case | Synthetic | Module | Invisible | SourceInvisible
114114

115115
/** The flags of a constructor companion */
116116
private val ConstructorCompanionFlags = Synthetic | ConstructorProxy

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

+1-1
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) || is(SourceInvisible) && !ctx.mode.is(Mode.ResolveFromTASTy)) && ctx.isTyper
621621
|| is(ModuleVal, butNot = Package) && moduleClass.isAbsent(canForce)
622622
}
623623

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

+1
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) {
881881
if flags.is(Transparent) then writeModTag(TRANSPARENT)
882882
if flags.is(Infix) then writeModTag(INFIX)
883883
if flags.is(Invisible) then writeModTag(INVISIBLE)
884+
if flags.is(SourceInvisible) then writeModTag(SOURCEINVISIBLE)
884885
if (flags.is(Erased)) writeModTag(ERASED)
885886
if (flags.is(Exported)) writeModTag(EXPORTED)
886887
if (flags.is(Given)) writeModTag(GIVEN)

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

+18-2
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ class TreeUnpickler(reader: TastyReader,
754754
case EXPORTED => addFlag(Exported)
755755
case OPEN => addFlag(Open)
756756
case INVISIBLE => addFlag(Invisible)
757+
case SOURCEINVISIBLE => addFlag(SourceInvisible)
757758
case TRANSPARENT => addFlag(Transparent)
758759
case INFIX => addFlag(Infix)
759760
case TRACKED => addFlag(Tracked)
@@ -1561,7 +1562,7 @@ class TreeUnpickler(reader: TastyReader,
15611562
* - sbt-test/tasty-compat/remove-override
15621563
* - sbt-test/tasty-compat/move-method
15631564
*/
1564-
def lookupInSuper =
1565+
def lookupInSuper(using Context) =
15651566
val cls = ownerTpe.classSymbol
15661567
if cls.exists then
15671568
cls.asClass.classDenot
@@ -1570,14 +1571,29 @@ class TreeUnpickler(reader: TastyReader,
15701571
else
15711572
NoDenotation
15721573

1573-
val denot =
1574+
1575+
def searchDenot(using Context): Denotation =
15741576
if owner.is(JavaAnnotation) && name == nme.CONSTRUCTOR then
15751577
// #19951 Fix up to read TASTy produced before 3.5.0 -- ignore the signature
15761578
ownerTpe.nonPrivateDecl(name).asSeenFrom(prefix)
15771579
else
15781580
val d = ownerTpe.decl(name).atSignature(sig, target)
15791581
(if !d.exists then lookupInSuper else d).asSeenFrom(prefix)
15801582

1583+
val denot0 = inContext(ctx.addMode(Mode.ResolveFromTASTy)):
1584+
searchDenot // able to resolve SourceInvisible members
1585+
1586+
val denot =
1587+
if
1588+
denot0.symbol.exists
1589+
&& denot0.symbol.is(SourceInvisible)
1590+
&& denot0.symbol.isDefinedInSource
1591+
then
1592+
searchDenot // fallback
1593+
else
1594+
denot0
1595+
1596+
15811597
makeSelect(qual, name, denot)
15821598
case REPEATED =>
15831599
val elemtpt = readTpt()

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import dotty.tools.unreachable
2626
/**Implementation of SIP-61.
2727
* Runs when `@unroll` annotations are found in a compilation unit, installing new definitions
2828
*
29-
* Note that it only generates `Invisible` methods, so no interactions with Zinc/SemanticDB
29+
* Note that it only generates `SourceInvisible` methods, so no interactions with Zinc/SemanticDB
3030
*/
3131
class UnrollDefinitions extends MacroTransform, IdentityDenotTransformer {
3232
self =>
@@ -127,7 +127,7 @@ class UnrollDefinitions extends MacroTransform, IdentityDenotTransformer {
127127
defdef.symbol.owner,
128128
defdef.name,
129129
defdef.symbol.flags &~ HasDefaultParams |
130-
Invisible | Synthetic,
130+
SourceInvisible | Synthetic,
131131
NoType, // fill in later
132132
coord = nextSymbol.span.shift(1) // shift by 1 to avoid "secondary constructor must call preceding" error
133133
).entered

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

+1
Original file line numberDiff line numberDiff line change
@@ -2955,6 +2955,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
29552955
def Infix: Flags = dotc.core.Flags.Infix
29562956
def Inline: Flags = dotc.core.Flags.Inline
29572957
def Invisible: Flags = dotc.core.Flags.Invisible
2958+
def SourceInvisible: Flags = dotc.core.Flags.SourceInvisible
29582959
def JavaDefined: Flags = dotc.core.Flags.JavaDefined
29592960
def JavaStatic: Flags = dotc.core.Flags.JavaStatic
29602961
def JavaAnnotation: Flags = dotc.core.Flags.JavaAnnotation

library/src/scala/quoted/Quotes.scala

+4
Original file line numberDiff line numberDiff line change
@@ -4588,6 +4588,10 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
45884588
/** Is this symbol invisible when typechecking? */
45894589
def Invisible: Flags
45904590

4591+
/** Is this symbol invisible when typechecking? (only from source) */
4592+
@experimental
4593+
def SourceInvisible: Flags
4594+
45914595
/** Is this symbol defined in a Java class */
45924596
def JavaDefined: Flags
45934597

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

+4
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ Standard-Section: "ASTs" TopLevelStat*
228228
EXPORTED -- An export forwarder
229229
OPEN -- an open class
230230
INVISIBLE -- invisible during typechecking
231+
SOURCEINVISIBLE -- invisible in the source code
231232
TRACKED -- a tracked class parameter / a dependent class
232233
Annotation
233234
@@ -511,6 +512,7 @@ object TastyFormat {
511512
final val EMPTYCLAUSE = 45
512513
final val SPLITCLAUSE = 46
513514
final val TRACKED = 47
515+
final val SOURCEINVISIBLE = 48
514516

515517
// Tree Cat. 2: tag Nat
516518
final val firstNatTreeTag = SHAREDterm
@@ -700,6 +702,7 @@ object TastyFormat {
700702
| EXPORTED
701703
| OPEN
702704
| INVISIBLE
705+
| SOURCEINVISIBLE
703706
| ANNOTATION
704707
| PRIVATEqualified
705708
| PROTECTEDqualified
@@ -764,6 +767,7 @@ object TastyFormat {
764767
case EXPORTED => "EXPORTED"
765768
case OPEN => "OPEN"
766769
case INVISIBLE => "INVISIBLE"
770+
case SOURCEINVISIBLE => "SOURCEINVISIBLE"
767771
case PARAMalias => "PARAMalias"
768772
case EMPTYCLAUSE => "EMPTYCLAUSE"
769773
case SPLITCLAUSE => "SPLITCLAUSE"

0 commit comments

Comments
 (0)