Skip to content

Commit 32869de

Browse files
committed
Assume more traits are transparent
- include js.Any and js.Object - include others ...Ops and Is... classes from collections - Change the implementation so that we don't have to load traits or classes that are assumed transparent.
1 parent d3861ee commit 32869de

File tree

2 files changed

+48
-18
lines changed

2 files changed

+48
-18
lines changed

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

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,23 +1827,53 @@ class Definitions {
18271827
def isInfix(sym: Symbol)(using Context): Boolean =
18281828
(sym eq Object_eq) || (sym eq Object_ne)
18291829

1830-
@tu lazy val assumedTransparentClasses =
1831-
Set[Symbol](ComparableClass, ProductClass, SerializableClass,
1832-
AnyClass, AnyValClass, ObjectClass, MatchableClass,
1833-
// add these for now, until we had a chance to retrofit 2.13 stdlib
1834-
// we should do a more through sweep through it then.
1835-
requiredClass("scala.collection.IterableOps"),
1836-
requiredClass("scala.collection.SeqOps"),
1837-
requiredClass("scala.collection.SortedOps"),
1838-
requiredClass("scala.collection.StrictOptimizedSortedSetOps"),
1839-
requiredClass("scala.collection.generic.DefaultSerializable"),
1840-
requiredClass("scala.collection.generic.IsIterable"),
1841-
requiredClass("scala.collection.generic.IsIterableOnce"),
1842-
requiredClass("scala.collection.generic.IsMap"),
1843-
requiredClass("scala.collection.generic.IsSeq"),
1844-
requiredClass("scala.collection.generic.Subtractable"),
1845-
requiredClass("scala.collection.immutable.StrictOptimizedSeqOps"),
1846-
)
1830+
@tu lazy val assumedTransparentNames: Map[Name, Set[Symbol]] =
1831+
// add these for now, until we had a chance to retrofit 2.13 stdlib
1832+
// we should do a more through sweep through it then.
1833+
val strs = Map(
1834+
"Any" -> Set("scala", "scala.scalajs.js"),
1835+
"AnyVal" -> Set("scala"),
1836+
"Matchable" -> Set("scala"),
1837+
"Product" -> Set("scala"),
1838+
"Object" -> Set("java.lang", "scala.scalajs.js"),
1839+
"Comparable" -> Set("java.lang"),
1840+
"Serializable" -> Set("java.io"),
1841+
"BitSetOps" -> Set("scala.collection"),
1842+
"IndexedSeqOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
1843+
"IterableOnceOps" -> Set("scala.collection"),
1844+
"IterableOps" -> Set("scala.collection"),
1845+
"LinearSeqOps" -> Set("scala.collection", "scala.collection.immutable"),
1846+
"MapOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
1847+
"SeqOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
1848+
"SetOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
1849+
"SortedMapOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
1850+
"SortedOps" -> Set("scala.collection"),
1851+
"SortedSetOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
1852+
"StrictOptimizedIterableOps" -> Set("scala.collection"),
1853+
"StrictOptimizedLinearSeqOps" -> Set("scala.collection"),
1854+
"StrictOptimizedMapOps" -> Set("scala.collection", "scala.collection.immutable"),
1855+
"StrictOptimizedSeqOps" -> Set("scala.collection", "scala.collection.immutable"),
1856+
"StrictOptimizedSetOps" -> Set("scala.collection", "scala.collection.immutable"),
1857+
"StrictOptimizedSortedMapOps" -> Set("scala.collection", "scala.collection.immutable"),
1858+
"StrictOptimizedSortedSetOps" -> Set("scala.collection", "scala.collection.immutable"),
1859+
"ArrayDequeOps" -> Set("scala.collection.mutable"),
1860+
"DefaultSerializable" -> Set("scala.collection.generic"),
1861+
"IsIterable" -> Set("scala.collection.generic"),
1862+
"IsIterableLowPriority" -> Set("scala.collection.generic"),
1863+
"IsIterableOnce" -> Set("scala.collection.generic"),
1864+
"IsIterableOnceLowPriority" -> Set("scala.collection.generic"),
1865+
"IsMap" -> Set("scala.collection.generic"),
1866+
"IsSeq" -> Set("scala.collection.generic"))
1867+
strs.map { case (simple, pkgs) => (
1868+
simple.toTypeName,
1869+
pkgs.map(pkg => staticRef(pkg.toTermName, isPackage = true).symbol.moduleClass)
1870+
)
1871+
}
1872+
1873+
def isAssumedTransparent(sym: Symbol): Boolean =
1874+
assumedTransparentNames.get(sym.name) match
1875+
case Some(pkgs) => pkgs.contains(sym.owner)
1876+
case none => false
18471877

18481878
// ----- primitive value class machinery ------------------------------------------
18491879

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ object SymDenotations {
11531153

11541154
final def isTransparentClass(using Context): Boolean =
11551155
is(TransparentType)
1156-
|| defn.assumedTransparentClasses.contains(symbol)
1156+
|| defn.isAssumedTransparent(symbol)
11571157
|| isClass && hasAnnotation(defn.TransparentTraitAnnot)
11581158

11591159
/** The class containing this denotation which has the given effective name. */

0 commit comments

Comments
 (0)