Skip to content

Commit 2b353ba

Browse files
committed
Rename is... and info extension methods in Symbol
There are two separate problems with having `is` and `info` as extension methods in Symnbol. For `is` methods: There's a "data race" error when compiling the compiler with itself. It seems that both of the following conditions must hold for that error to come up: - the extension method must be overloaded - it must have a same-named real method in the target type that is reachable via an implicit conversion. We need to minimize and dig deeper on this one. For `info` the problem is different. We can't have both `info` and `info_=` as extension methods since assignment desugaring does not work for extension methods. We cannot have `info` alone either since then the conversion-based `info =` would not work anymore. We should add a fix that allows assignment desugaring of extension methods to the language; then this problem would go away.
1 parent 3c4fdf9 commit 2b353ba

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

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

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ object Symbols {
272272
val d = denot
273273
d.owner match
274274
case owner: ClassSymbol =>
275-
if owner.is(Package) then
275+
if owner._is(Package) then
276276
d.validFor |= InitialPeriod
277277
if d.is(Module) then d.moduleClass.denot.validFor |= InitialPeriod
278278
else
@@ -296,7 +296,7 @@ object Symbols {
296296
atPhase(phase.next)(dropAfter(phase))
297297
else
298298
val d = denot
299-
assert(!d.owner.is(Package))
299+
assert(!d.owner._is(Package))
300300
d.owner.classDenot.ensureFreshScopeAfter(phase)
301301
assert(isPrivate || phase.changesMembers, i"$_self deleted in ${d.owner} at undeclared phase $phase")
302302
drop()
@@ -362,7 +362,7 @@ object Symbols {
362362
d.moduleClass.sourceSymbol // The module val always has a zero-extent position
363363
else if d.is(Synthetic) then
364364
val linked = d.linkedClass
365-
if linked.exists && !linked.is(Synthetic) then linked
365+
if linked.exists && !linked._is(Synthetic) then linked
366366
else d.owner.sourceSymbol
367367
else if d.isPrimaryConstructor then
368368
d.owner.sourceSymbol
@@ -375,6 +375,7 @@ object Symbols {
375375
def thisType(using Context): Type = _self.denot.thisType
376376
def typeRef(using Context): TypeRef = _self.denot.typeRef
377377
def termRef(using Context): TermRef = _self.denot.termRef
378+
def _info(using Context): Type = _self.denot.info
378379
def isCompleted(using Context): Boolean = _self.denot.isCompleted
379380
def isCompleting(using Context): Boolean = _self.denot.isCompleting
380381
def ensureCompleted()(using Context): Unit = _self.denot.ensureCompleted()
@@ -391,12 +392,12 @@ object Symbols {
391392
def enclosingClass(using Context): Symbol = _self.denot.enclosingClass
392393
def enclosingMethod(using Context): Symbol = _self.denot.enclosingMethod
393394
def typeParamCreationFlags(using Context): FlagSet = _self.denot.typeParamCreationFlags
394-
//def is(flag: Flag)(using Context): Boolean = _self.denot.is(flag)
395-
//def is(flag: Flag, butNot: FlagSet)(using Context): Boolean = _self.denot.is(flag, butNot)
396-
//def isOneOf(fs: FlagSet)(using Context): Boolean = _self.denot.isOneOf(fs)
397-
//def isOneOf(fs: FlagSet, butNot: FlagSet)(using Context): Boolean = _self.denot.isOneOf(fs, butNot)
398-
//def isAllOf(fs: FlagSet)(using Context): Boolean = _self.denot.isAllOf(fs)
399-
//def isAllOf(fs: FlagSet, butNot: FlagSet)(using Context): Boolean = _self.denot.isAllOf(fs, butNot)
395+
def _is(flag: Flag)(using Context): Boolean = _self.denot.is(flag)
396+
def _is(flag: Flag, butNot: FlagSet)(using Context): Boolean = _self.denot.is(flag, butNot)
397+
def _isOneOf(fs: FlagSet)(using Context): Boolean = _self.denot.isOneOf(fs)
398+
def _isOneOf(fs: FlagSet, butNot: FlagSet)(using Context): Boolean = _self.denot.isOneOf(fs, butNot)
399+
def _isAllOf(fs: FlagSet)(using Context): Boolean = _self.denot.isAllOf(fs)
400+
def _isAllOf(fs: FlagSet, butNot: FlagSet)(using Context): Boolean = _self.denot.isAllOf(fs, butNot)
400401
// !!! Dotty problem: overloaded extension methods here lead to failures like
401402
// Assertion failed: data race? overwriting method isAllOf with method isAllOf in type TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class dotc)),object core),object Symbols),isAllOf),
402403
// |last sym id = 10301, new sym id = 10299,
@@ -513,7 +514,7 @@ object Symbols {
513514

514515
def sourceOfClass(using Context): SourceFile =
515516
val common = _self.lastKnownDenotation.common.asClass
516-
if !common.source.exists && !_self.is(Package) then
517+
if !common.source.exists && !_self._is(Package) then
517518
// this allows sources to be added in annotations after `sourceOfClass` is first called
518519
val file = _self.associatedFile
519520
if file != null && file.extension != "class" then
@@ -664,7 +665,7 @@ object Symbols {
664665
owner, name, modFlags | ModuleValCreationFlags, NoCompleter, privateWithin, coord)
665666
val modcls = newClassSymbol(
666667
owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, assocFile)
667-
module.info =
668+
module.denot.info =
668669
if (modcls.isCompleted) TypeRef(owner.thisType, modcls)
669670
else new ModuleCompleter(modcls)
670671
module
@@ -756,7 +757,7 @@ object Symbols {
756757
*/
757758
def newStubSymbol(owner: Symbol, name: Name, file: AbstractFile | Null = null)(using Context): Symbol = {
758759
def stubCompleter = new StubInfo()
759-
val normalizedOwner = if (owner.is(ModuleVal)) owner.moduleClass else owner
760+
val normalizedOwner = if (owner._is(ModuleVal)) owner.moduleClass else owner
760761
typr.println(s"creating stub for ${name.show}, owner = ${normalizedOwner.denot.debugString}, file = $file")
761762
typr.println(s"decls = ${normalizedOwner.unforcedDecls.toList.map(_.debugString).mkString("\n ")}") // !!! DEBUG
762763
//if (base.settings.debug.value) throw new Error()
@@ -838,7 +839,7 @@ object Symbols {
838839
val tparams = tparamBuf.toList
839840
val bounds = boundsFn(trefBuf.toList)
840841
for (tparam, bound) <- tparams.lazyZip(bounds) do
841-
tparam.info = bound
842+
tparam.denot.info = bound
842843
tparams
843844
}
844845

@@ -861,7 +862,7 @@ object Symbols {
861862
*/
862863
def mapSymbols(originals: List[Symbol], ttmap: TreeTypeMap, mapAlways: Boolean = false)(using Context): List[Symbol] =
863864
if (originals.forall(sym =>
864-
(ttmap.mapType(sym.info) eq sym.info) &&
865+
(ttmap.mapType(sym._info) eq sym._info) &&
865866
!(ttmap.oldOwners contains sym.owner)) && !mapAlways)
866867
originals
867868
else {
@@ -880,7 +881,7 @@ object Symbols {
880881

881882
def complete(denot: SymDenotation)(using Context): Unit =
882883

883-
val oinfo = original.info match
884+
val oinfo = original._info match
884885
case ClassInfo(pre, _, parents, decls, selfInfo) =>
885886
assert(original.isClass)
886887
val parents1 = parents.mapConserve(ttmap.mapType)
@@ -894,7 +895,7 @@ object Symbols {
894895
val decls1 = newScope
895896
val newTypeParams = mapSymbols(original.typeParams, ttmap1, mapAlways = true)
896897
newTypeParams.foreach(decls1.enter)
897-
for sym <- decls do if !sym.is(TypeParam) then decls1.enter(sym)
898+
for sym <- decls do if !sym._is(TypeParam) then decls1.enter(sym)
898899
val parents2 = parents1.map(_.substSym(otypeParams, newTypeParams))
899900
val selfInfo1 = selfInfo match
900901
case selfInfo: Type => selfInfo.substSym(otypeParams, newTypeParams)
@@ -910,10 +911,10 @@ object Symbols {
910911

911912
end completer
912913

913-
copy.info = completer
914+
copy.denot.info = completer
914915
copy.denot match
915916
case cd: ClassDenotation =>
916-
cd.registeredCompanion = original.registeredCompanion.subst(originals, copies)
917+
cd.registeredCompanion = original.denot.registeredCompanion.subst(originals, copies)
917918
case _ =>
918919
}
919920

@@ -922,9 +923,9 @@ object Symbols {
922923
// Update Child annotations of classes encountered previously to new values
923924
// if some child is among the mapped symbols
924925
for orig <- ttmap1.substFrom do
925-
if orig.is(Sealed) && orig.children.exists(originals.contains) then
926+
if orig._is(Sealed) && orig.children.exists(originals.contains) then
926927
val sealedCopy = orig.subst(ttmap1.substFrom, ttmap1.substTo)
927-
sealedCopy.annotations = sealedCopy.annotations.mapConserve(ttmap1.apply)
928+
sealedCopy.denot.annotations = sealedCopy.denot.annotations.mapConserve(ttmap1.apply)
928929

929930
copies
930931
}
@@ -949,7 +950,7 @@ object Symbols {
949950

950951
def requiredPackage(path: PreName)(using Context): TermSymbol = {
951952
val name = path.toTermName
952-
staticRef(name, isPackage = true).requiredSymbol("package", name)(_.is(Package)).asTerm
953+
staticRef(name, isPackage = true).requiredSymbol("package", name)(_._is(Package)).asTerm
953954
}
954955

955956
def requiredPackageRef(path: PreName)(using Context): TermRef = requiredPackage(path).termRef
@@ -982,25 +983,25 @@ object Symbols {
982983
*/
983984
def getPackageClassIfDefined(path: PreName)(using Context): Symbol =
984985
staticRef(path.toTypeName, isPackage = true, generateStubs = false)
985-
.disambiguate(_ is PackageClass).symbol
986+
.disambiguate(_._is(PackageClass)).symbol
986987

987988
def requiredModule(path: PreName)(using Context): TermSymbol = {
988989
val name = path.toTermName
989-
staticRef(name).requiredSymbol("object", name)(_.is(Module)).asTerm
990+
staticRef(name).requiredSymbol("object", name)(_._is(Module)).asTerm
990991
}
991992

992993
/** Get module symbol if the module is either defined in current compilation run
993994
* or present on classpath. Returns NoSymbol otherwise.
994995
*/
995996
def getModuleIfDefined(path: PreName)(using Context): Symbol =
996997
staticRef(path.toTermName, generateStubs = false)
997-
.disambiguate(_.is(Module)).symbol
998+
.disambiguate(_._is(Module)).symbol
998999

9991000
def requiredModuleRef(path: PreName)(using Context): TermRef = requiredModule(path).termRef
10001001

10011002
def requiredMethod(path: PreName)(using Context): TermSymbol = {
10021003
val name = path.toTermName
1003-
staticRef(name).requiredSymbol("method", name)(_.is(Method)).asTerm
1004+
staticRef(name).requiredSymbol("method", name)(_._is(Method)).asTerm
10041005
}
10051006

10061007
def requiredMethodRef(path: PreName)(using Context): TermRef = requiredMethod(path).termRef

0 commit comments

Comments
 (0)