Skip to content

Commit 1e92b31

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 26e5f2a commit 1e92b31

File tree

2 files changed

+49
-19
lines changed

2 files changed

+49
-19
lines changed

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

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import typer.ImportInfo.RootRef
1313
import Comments.CommentsContext
1414
import Comments.Comment
1515
import util.Spans.NoSpan
16-
import Symbols.requiredModuleRef
16+
import Denotations.staticRef
1717

1818
import scala.annotation.tailrec
1919

@@ -1761,23 +1761,53 @@ class Definitions {
17611761
def isInfix(sym: Symbol)(using Context): Boolean =
17621762
(sym eq Object_eq) || (sym eq Object_ne)
17631763

1764-
@tu lazy val assumedTransparentClasses =
1765-
Set[Symbol](ComparableClass, ProductClass, SerializableClass,
1766-
AnyClass, AnyValClass, ObjectClass, MatchableClass,
1767-
// add these for now, until we had a chance to retrofit 2.13 stdlib
1768-
// we should do a more through sweep through it then.
1769-
requiredClass("scala.collection.IterableOps"),
1770-
requiredClass("scala.collection.SeqOps"),
1771-
requiredClass("scala.collection.SortedOps"),
1772-
requiredClass("scala.collection.StrictOptimizedSortedSetOps"),
1773-
requiredClass("scala.collection.generic.DefaultSerializable"),
1774-
requiredClass("scala.collection.generic.IsIterable"),
1775-
requiredClass("scala.collection.generic.IsIterableOnce"),
1776-
requiredClass("scala.collection.generic.IsMap"),
1777-
requiredClass("scala.collection.generic.IsSeq"),
1778-
requiredClass("scala.collection.generic.Subtractable"),
1779-
requiredClass("scala.collection.immutable.StrictOptimizedSeqOps"),
1780-
)
1764+
@tu lazy val assumedTransparentNames: Map[Name, Set[Symbol]] =
1765+
// add these for now, until we had a chance to retrofit 2.13 stdlib
1766+
// we should do a more through sweep through it then.
1767+
val strs = Map(
1768+
"Any" -> Set("scala", "scala.scalajs.js"),
1769+
"AnyVal" -> Set("scala"),
1770+
"Matchable" -> Set("scala"),
1771+
"Product" -> Set("scala"),
1772+
"Object" -> Set("java.lang", "scala.scalajs.js"),
1773+
"Comparable" -> Set("java.lang"),
1774+
"Serializable" -> Set("java.io"),
1775+
"BitSetOps" -> Set("scala.collection"),
1776+
"IndexedSeqOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
1777+
"IterableOnceOps" -> Set("scala.collection"),
1778+
"IterableOps" -> Set("scala.collection"),
1779+
"LinearSeqOps" -> Set("scala.collection", "scala.collection.immutable"),
1780+
"MapOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
1781+
"SeqOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
1782+
"SetOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
1783+
"SortedMapOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
1784+
"SortedOps" -> Set("scala.collection"),
1785+
"SortedSetOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
1786+
"StrictOptimizedIterableOps" -> Set("scala.collection"),
1787+
"StrictOptimizedLinearSeqOps" -> Set("scala.collection"),
1788+
"StrictOptimizedMapOps" -> Set("scala.collection", "scala.collection.immutable"),
1789+
"StrictOptimizedSeqOps" -> Set("scala.collection", "scala.collection.immutable"),
1790+
"StrictOptimizedSetOps" -> Set("scala.collection", "scala.collection.immutable"),
1791+
"StrictOptimizedSortedMapOps" -> Set("scala.collection", "scala.collection.immutable"),
1792+
"StrictOptimizedSortedSetOps" -> Set("scala.collection", "scala.collection.immutable"),
1793+
"ArrayDequeOps" -> Set("scala.collection.mutable"),
1794+
"DefaultSerializable" -> Set("scala.collection.generic"),
1795+
"IsIterable" -> Set("scala.collection.generic"),
1796+
"IsIterableLowPriority" -> Set("scala.collection.generic"),
1797+
"IsIterableOnce" -> Set("scala.collection.generic"),
1798+
"IsIterableOnceLowPriority" -> Set("scala.collection.generic"),
1799+
"IsMap" -> Set("scala.collection.generic"),
1800+
"IsSeq" -> Set("scala.collection.generic"))
1801+
strs.map { case (simple, pkgs) => (
1802+
simple.toTypeName,
1803+
pkgs.map(pkg => staticRef(pkg.toTermName, isPackage = true).symbol.moduleClass)
1804+
)
1805+
}
1806+
1807+
def isAssumedTransparent(sym: Symbol): Boolean =
1808+
assumedTransparentNames.get(sym.name) match
1809+
case Some(pkgs) => pkgs.contains(sym.owner)
1810+
case none => false
17811811

17821812
// ----- primitive value class machinery ------------------------------------------
17831813

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

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

11471147
final def isTransparentClass(using Context): Boolean =
11481148
is(TransparentType)
1149-
|| defn.assumedTransparentClasses.contains(symbol)
1149+
|| defn.isAssumedTransparent(symbol)
11501150
|| isClass && hasAnnotation(defn.TransparentTraitAnnot)
11511151

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

0 commit comments

Comments
 (0)