Skip to content

Switch TypeApplications to given extensions #23512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import dotty.tools.dotc.CompilationUnit
import dotty.tools.dotc.core.Constants.*
import dotty.tools.dotc.core.Flags.{Label => LabelFlag, _}
import dotty.tools.dotc.core.Types.*
import dotty.tools.dotc.core.TypeApplications.*
import dotty.tools.dotc.core.StdNames.{nme, str}
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.transform.Erasure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import dotty.tools.dotc.core.NameKinds.*
import dotty.tools.dotc.core.Names.TermName
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.core.Types.*
import dotty.tools.dotc.core.TypeApplications.*
import dotty.tools.dotc.core.Contexts.*
import dotty.tools.dotc.util.Spans.*
import dotty.tools.dotc.report
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/debug/ExtractExpression.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dotty.tools.dotc.core.Flags.*
import dotty.tools.dotc.core.Names.*
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.core.Types.*
import dotty.tools.dotc.core.TypeApplications.*
import dotty.tools.dotc.core.DenotTransformers.DenotTransformer
import dotty.tools.dotc.core.Denotations.SingleDenotation
import dotty.tools.dotc.core.SymDenotations.SymDenotation
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/debug/ResolveReflectEval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import dotty.tools.dotc.core.StdNames.*
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.core.TypeErasure.ErasedValueType
import dotty.tools.dotc.core.Types.*
import dotty.tools.dotc.core.TypeApplications.*
import dotty.tools.dotc.report
import dotty.tools.dotc.transform.MegaPhase.MiniPhase
import dotty.tools.dotc.transform.ValueClasses
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package ast

import core.*
import util.Spans.*, Types.*, Contexts.*, Constants.*, Names.*, NameOps.*, Flags.*
import TypeApplications.*
import Symbols.*, StdNames.*, Trees.*, ContextOps.*
import Decorators.*
import Annotations.Annotation
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package ast

import core.*
import util.Spans.*, Types.*, Contexts.*, Constants.*, Names.*, Flags.*
import TypeApplications.*
import Symbols.*, StdNames.*, Trees.*
import Decorators.*
import util.{Property, SourceFile}
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/ast/MainProxies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ast

import core.*
import Symbols.*, Types.*, Contexts.*, Decorators.*, util.Spans.*, Flags.*, Constants.*
import TypeApplications.*
import StdNames.{nme, tpnme}
import ast.Trees.*
import Names.Name
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package ast

import core.*
import Flags.*, Trees.*, Types.*, Contexts.*
import TypeApplications.*
import Names.*, StdNames.*, NameOps.*, Symbols.*
import Annotations.Annotation
import NameKinds.ContextBoundParamName
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package ast

import core.*
import Types.*, Contexts.*, Flags.*
import TypeApplications.*
import Symbols.*, Annotations.*, Trees.*, Symbols.*, Constants.Constant
import Decorators.*

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package ast

import core.*
import Types.*, Names.*, NameOps.*, Flags.*, util.Spans.*, Contexts.*, Constants.*
import TypeApplications.*
import typer.{ ConstFold, ProtoTypes }
import SymDenotations.*, Symbols.*, Denotations.*, StdNames.*, Comments.*
import collection.mutable.ListBuffer
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import typer.ProtoTypes
import core.*
import Scopes.newScope
import util.Spans.*, Types.*, Contexts.*, Constants.*, Names.*, Flags.*, NameOps.*
import TypeApplications.*
import Symbols.*, StdNames.*, Annotations.*, Trees.*, Symbols.*
import Decorators.*, DenotTransformers.*
import collection.{immutable, mutable}
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package ast

import core.*
import Types.*, Contexts.*, Constants.*, Names.*, Flags.*
import TypeApplications.*
import dotty.tools.dotc.typer.ProtoTypes
import Symbols.*, StdNames.*, Trees.*
import util.{Property, SourceFile, NoSource}
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/cc/CaptureSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package cc

import core.*
import Types.*, Symbols.*, Flags.*, Contexts.*, Decorators.*
import TypeApplications.*
import config.Printers.{capt, captDebug}
import Annotations.Annotation
import annotation.threadUnsafe
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import core.*
import Phases.*, DenotTransformers.*, SymDenotations.*
import Contexts.*, Names.*, Flags.*, Symbols.*, Decorators.*
import Types.*, StdNames.*, Denotations.*
import TypeApplications.*
import config.Printers.{capt, recheckr, noPrinter}
import config.{Config, Feature}
import ast.{tpd, untpd, Trees}
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/cc/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import core.*
import Phases.*, DenotTransformers.*, SymDenotations.*
import Contexts.*, Names.*, Flags.*, Symbols.*, Decorators.*
import Types.*, StdNames.*
import TypeApplications.*
import Annotations.Annotation
import config.Feature
import config.Printers.{capt, captDebug}
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dotc
package core

import Symbols.*, Types.*, Contexts.*, Constants.*, Phases.*
import TypeApplications.*
import ast.tpd, tpd.*
import util.Spans.Span
import printing.{Showable, Printer}
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/CheckRealizable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dotc
package core

import Contexts.*, Types.*, Symbols.*, Names.*, Flags.*
import TypeApplications.*
import Denotations.SingleDenotation
import Decorators.*
import collection.mutable
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Comments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package core

import ast.{ untpd, tpd }
import Symbols.*, Contexts.*
import TypeApplications.*
import util.{SourceFile, ReadOnlyMap}
import util.Spans.*
import util.CommentParsing.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dotc
package core

import Types.*
import TypeApplications.*
import Contexts.*
import Symbols.*
import Decorators.*
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Periods.*
import Names.*
import Phases.*
import Types.*
import TypeApplications.*
import Symbols.*
import Scopes.*
import Uniques.*
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package core

import scala.annotation.{threadUnsafe => tu}
import Types.*, Contexts.*, Symbols.*, SymDenotations.*, StdNames.*, Names.*, Phases.*
import TypeApplications.*
import Flags.*, Scopes.*, Decorators.*, NameOps.*, Periods.*, NullOpsDecorator.*
import unpickleScala2.Scala2Unpickler.ensureConstructor
import scala.collection.mutable
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/NamerOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package dotc
package core

import Contexts.*, Symbols.*, Types.*, Flags.*, Scopes.*, Decorators.*, Names.*, NameOps.*
import TypeApplications.*
import SymDenotations.{LazyType, SymDenotation}, StdNames.nme
import ContextOps.enter
import TypeApplications.EtaExpansion
import collection.mutable
import config.Printers.typr
import rewrites.Rewrites.patch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package core
import Decorators.*
import Symbols.*
import Types.*
import TypeApplications.*
import Flags.*
import Contexts.ctx
import dotty.tools.dotc.reporting.trace
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ package core

import Periods.*, Contexts.*, Symbols.*, Denotations.*, Names.*, NameOps.*, Annotations.*
import Types.*, Flags.*, Decorators.*, DenotTransformers.*, StdNames.*, Scopes.*
import TypeApplications.*
import NameOps.*, NameKinds.*
import Phases.{Phase, typerPhase, unfusedPhases}
import Constants.Constant
import TypeApplications.TypeParamInfo
import Scopes.Scope
import dotty.tools.io.AbstractFile
import Decorators.*
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Denotations.*
import printing.Texts.*
import printing.Printer
import Types.*
import TypeApplications.*
import util.Spans.*
import DenotTransformers.*
import StdNames.*
Expand Down
30 changes: 13 additions & 17 deletions compiler/src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dotc
package core

import Types.*
import TypeApplications.*
import Contexts.*
import Symbols.*
import SymDenotations.LazyType
Expand All @@ -13,16 +14,10 @@ import StdNames.nme
import Flags.{Module, Provisional}
import dotty.tools.dotc.config.Config

object TypeApplications {
object TypeApplications:

type TypeParamInfo = ParamInfo.Of[TypeName]

/** Assert type is not a TypeBounds instance and return it unchanged */
def noBounds(tp: Type): Type = tp match {
case tp: TypeBounds => throw new AssertionError("no TypeBounds allowed")
case _ => tp
}

/** Extractor for
*
* [X1: B1, ..., Xn: Bn] -> C[X1, ..., Xn]
Expand All @@ -31,7 +26,7 @@ object TypeApplications {
*
* @param tycon C
*/
object EtaExpansion:
object EtaExpansion: // note typer.EtaExpansion

/** Test that the parameter bounds in a hk type lambda `[X1,...,Xn] => C[X1, ..., Xn]`
* contain the bounds of the type parameters of `C`. This is necessary to be able to
Expand Down Expand Up @@ -153,13 +148,9 @@ object TypeApplications {
mapOver(t)
}
}
}

import TypeApplications.*

/** A decorator that provides methods for modeling type application */
class TypeApplications(val self: Type) extends AnyVal {

// Extensions that model type application.
extension (self: Type) { // braces to avoid indent
/** The type parameters of this type are:
* For a ClassInfo type, the type parameters of its class.
* For a typeref referring to a class, the type parameters of the class.
Expand Down Expand Up @@ -315,7 +306,7 @@ class TypeApplications(val self: Type) extends AnyVal {
/** Convert a type constructor `TC` which has type parameters `X1, ..., Xn`
* to `[X1, ..., Xn] -> TC[X1, ..., Xn]`.
*/
def etaExpand(using Context): Type =
def etaExpand(using Context): Type = // note typer.EtaExpansion.etaExpand
val tparams = self.typeParams
val resType = self.appliedTo(tparams.map(_.paramRef))
self.dealias match
Expand Down Expand Up @@ -554,7 +545,7 @@ class TypeApplications(val self: Type) extends AnyVal {
case _ => self.dropDependentRefinement.dealias.argInfos

/** Argument types where existential types in arguments are disallowed */
def argTypes(using Context): List[Type] = argInfos mapConserve noBounds
def argTypes(using Context): List[Type] = argInfos.mapConserve(_.noBounds)

/** Argument types where existential types in arguments are approximated by their lower bound */
def argTypesLo(using Context): List[Type] = argInfos.mapConserve(_.loBound)
Expand Down Expand Up @@ -588,4 +579,9 @@ class TypeApplications(val self: Type) extends AnyVal {
.orElse(self.baseType(defn.ArrayClass))
.argInfos.headOption.getOrElse(NoType)
}
}

/** Assert type is not a TypeBounds instance and return it unchanged */
def noBounds: self.type =
assert(!self.isInstanceOf[TypeBounds], "no TypeBounds allowed")
self
}
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dotc
package core

import Types.*, Contexts.*, Symbols.*, Flags.*, Names.*, NameOps.*, Denotations.*
import TypeApplications.*
import Decorators.*
import Phases.{gettersPhase, elimByNamePhase}
import StdNames.nme
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dotc
package core

import Symbols.*, Types.*, Contexts.*, Flags.*, Names.*, StdNames.*, Phases.*
import TypeApplications.*
import Flags.JavaDefined
import Uniques.unique
import backend.sjs.JSDefinitions
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/TypeEval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dotc
package core

import Types.*, Contexts.*, Symbols.*, Constants.*, Decorators.*
import TypeApplications.*
import config.Printers.typr
import reporting.trace
import StdNames.tpnme
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dotc
package core

import Contexts.*, Types.*, Symbols.*, Names.*, NameKinds.*, Flags.*
import TypeApplications.*
import SymDenotations.*
import util.Spans.*
import util.Stats
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/TypeUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package core

import TypeErasure.ErasedValueType
import Types.*, Contexts.*, Symbols.*, Flags.*, Decorators.*, SymDenotations.*
import TypeApplications.*
import Names.{Name, TermName}
import Constants.Constant

Expand Down
6 changes: 2 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Denotations.*
import Periods.*
import CheckRealizable.*
import Variances.{Variance, setStructuralVariances, Invariant}
import TypeApplications.*
import typer.Nullables
import util.Stats.*
import util.{SimpleIdentityMap, SimpleIdentitySet}
Expand Down Expand Up @@ -2132,8 +2133,7 @@ object Types extends TypeUtils {
/** Is the `hash` of this type the same for all possible sequences of enclosing binders? */
def hashIsStable: Boolean = true
}

// end Type
end Type

// ----- Type categories ----------------------------------------------

Expand Down Expand Up @@ -7160,8 +7160,6 @@ object Types extends TypeUtils {

// ----- Helpers and Decorator implicits --------------------------------------

implicit def decorateTypeApplications(tpe: Type): TypeApplications = new TypeApplications(tpe)

extension (tps1: List[Type]) {
@tailrec def hashIsStable: Boolean =
tps1.isEmpty || tps1.head.hashIsStable && tps1.tail.hashIsStable
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Variances.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dotty.tools.dotc
package core

import Types.*, Contexts.*, Flags.*, Symbols.*, Annotations.*
import TypeApplications.TypeParamInfo
import TypeApplications.*
import Decorators.*

object Variances {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import scala.language.unsafeNulls
import dotty.tools.tasty.{ TastyReader, TastyHeaderUnpickler }

import Contexts.*, Symbols.*, Types.*, Names.*, StdNames.*, NameOps.*, Scopes.*, Decorators.*
import TypeApplications.*
import SymDenotations.*, unpickleScala2.Scala2Unpickler.*, Constants.*, Annotations.*, util.Spans.*
import Phases.*
import ast.{ tpd, untpd }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Comments.docCtx
import Contexts.*
import Symbols.*
import Types.*
import TypeApplications.*
import Scopes.*
import SymDenotations.*
import Denotations.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.lang.Float.intBitsToFloat
import java.lang.Double.longBitsToDouble

import Contexts.*, Symbols.*, Types.*, Scopes.*, SymDenotations.*, Names.*, NameOps.*
import TypeApplications.*
import StdNames.*, Denotations.*, NameOps.*, Flags.*, Constants.*, Annotations.*, Phases.*
import NameKinds.{Scala2MethodNameKinds, SuperAccessorName, ExpandedName}
import util.Spans.*
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package inlines

import ast.*, core.*
import Flags.*, Symbols.*, Types.*, Decorators.*, Constants.*, Contexts.*
import TypeApplications.*
import StdNames.nme
import typer.*
import Names.Name
Expand Down
Loading
Loading