Skip to content

[Do not merge] Aborted Experiment: Native AppliedType #2947

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

Closed
wants to merge 18 commits into from
Closed
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 @@ -889,7 +889,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
// to inner symbols of DefDef
// todo: somehow handle.

def parents: List[Type] = tp.parents
def parents: List[Type] = tp.parentsNEW
}


Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ object desugar {
* class C { type v C$T; type v T = C$T }
*/
def typeDef(tdef: TypeDef)(implicit ctx: Context): Tree = {
if (tdef.mods is PrivateLocalParam) {
if (tdef.mods.is(PrivateLocalParam) && !dotty.tools.dotc.config.Config.newScheme) {
val tparam = cpy.TypeDef(tdef)(name = tdef.name.expandedName(ctx.owner))
.withMods(tdef.mods &~ PrivateLocal)
val alias = cpy.TypeDef(tdef)(rhs = refOfDef(tparam))
Expand Down Expand Up @@ -1132,7 +1132,8 @@ object desugar {
*/
def refinedTypeToClass(parent: tpd.Tree, refinements: List[Tree])(implicit ctx: Context): TypeDef = {
def stripToCore(tp: Type): List[Type] = tp match {
case tp: RefinedType if tp.argInfos.nonEmpty => tp :: Nil // parameterized class type
case tp: AppliedType => tp :: Nil
case tp: RefinedType if !config.Config.newScheme && tp.argInfos.nonEmpty => tp :: Nil // parameterized class type
case tp: TypeRef if tp.symbol.isClass => tp :: Nil // monomorphic class type
case tp: TypeProxy => stripToCore(tp.underlying)
case AndType(tp1, tp2) => stripToCore(tp1) ::: stripToCore(tp2)
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
ta.assignType(untpd.TypeDef(sym.name, TypeTree(sym.info)), sym)

def ClassDef(cls: ClassSymbol, constr: DefDef, body: List[Tree], superArgs: List[Tree] = Nil)(implicit ctx: Context): TypeDef = {
val firstParentRef :: otherParentRefs = cls.info.parents
val firstParent = cls.typeRef.baseTypeWithArgs(firstParentRef.symbol)
val firstParentRef :: otherParentRefs = cls.info.parentRefs
val firstParent = cls.appliedRef.baseTypeWithArgs(firstParentRef.symbol)
val superRef =
if (cls is Trait) TypeTree(firstParent)
else {
Expand Down Expand Up @@ -261,7 +261,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def AnonClass(parents: List[Type], fns: List[TermSymbol], methNames: List[TermName])(implicit ctx: Context): Block = {
val owner = fns.head.owner
val parents1 =
if (parents.head.classSymbol.is(Trait)) parents.head.parents.head :: parents
if (parents.head.classSymbol.is(Trait)) parents.head.parentRefs.head :: parents
else parents
val cls = ctx.newNormalizedClassSymbol(owner, tpnme.ANON_FUN, Synthetic, parents1,
coord = fns.map(_.pos).reduceLeft(_ union _))
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/config/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ object Config {
final val traceDeepSubTypeRecursions = false

/** When explaining subtypes and this flag is set, also show the classes of the compared types. */
final val verboseExplainSubtype = false
final val verboseExplainSubtype = true

/** If this flag is set, take the fast path when comparing same-named type-aliases and types */
final val fastPathForRefinedSubtype = true
Expand Down Expand Up @@ -174,4 +174,6 @@ object Config {

/** When in IDE, turn StaleSymbol errors into warnings instead of crashing */
final val ignoreStaleInIDE = true

val newScheme = true
}
10 changes: 8 additions & 2 deletions compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Types._, Contexts._, Symbols._
import Decorators._
import config.Config
import config.Printers.{constr, typr}
import TypeApplications.EtaExpansion
import TypeApplications.{EtaExpansion, TypeParamInfo}
import collection.mutable

/** Methods for adding constraints and solving them.
Expand Down Expand Up @@ -194,9 +194,15 @@ trait ConstraintHandling {
final def approximation(param: TypeParamRef, fromBelow: Boolean): Type = {
val avoidParam = new TypeMap {
override def stopAtStatic = true
def avoidInArg(arg: Type, formal: TypeParamInfo): Type =
if (param.occursIn(arg)) TypeBounds.empty else arg
def apply(tp: Type) = mapOver {
tp match {
case tp: RefinedType if param occursIn tp.refinedInfo => tp.parent
case tp @ AppliedType(tycon, args) =>
tp.derivedAppliedType(tycon,
args.zipWithConserve(tycon.typeParams)(avoidInArg))
case tp: RefinedType if param occursIn tp.refinedInfo =>
tp.parent
case tp: WildcardType =>
val bounds = tp.optBounds.orElse(TypeBounds.empty).bounds
// Try to instantiate the wildcard to a type that is known to conform to it.
Expand Down
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import NameOps._
import Uniques._
import SymDenotations._
import Comments._
import Flags.ParamAccessor
import util.Positions._
import ast.Trees._
import ast.untpd
Expand Down Expand Up @@ -335,7 +334,9 @@ object Contexts {
* from constructor parameters to class parameter accessors.
*/
def superCallContext: Context = {
val locals = newScopeWith(owner.asClass.paramAccessors: _*)
val locals = newScopeWith(
(if (Config.newScheme) owner.typeParams ++ owner.asClass.paramAccessors
else owner.asClass.paramAccessors): _*)
superOrThisCallContext(owner.primaryConstructor, locals)
}

Expand Down Expand Up @@ -605,7 +606,7 @@ object Contexts {
}

/** A table for hash consing unique refined types */
private[dotc] val uniqueRefinedTypes = new RefinedUniques
private[dotc] val uniqueRefinedTypes = new RefinedUniques // @!!! replace with uniqueAppliedTypes

/** A table for hash consing unique named types */
private[core] val uniqueNamedTypes = new NamedTypeUniques
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Definitions {
if (tpe.typeParams.nonEmpty) tpe.appliedTo(typeParam.typeRef)
else tpe
val parents = parentConstrs.toList map instantiate
val parentRefs: List[TypeRef] = ctx.normalizeToClassRefs(parents, cls, paramDecls)
val parentRefs = ctx.normalizeToClassRefs(parents, cls, paramDecls)
denot.info = ClassInfo(ScalaPackageClass.thisType, cls, parentRefs, paramDecls)
}
}
Expand Down Expand Up @@ -721,7 +721,8 @@ class Definitions {
if (ctx.erasedTypes) JavaArrayType(elem)
else ArrayType.appliedTo(elem :: Nil)
def unapply(tp: Type)(implicit ctx: Context): Option[Type] = tp.dealias match {
case at: RefinedType if (at isRef ArrayType.symbol) && at.argInfos.length == 1 => Some(at.argInfos.head)
case AppliedType(at, arg :: Nil) if at isRef ArrayType.symbol => Some(arg)
case at: RefinedType if (at isRef ArrayType.symbol) && at.argInfos.length == 1 => Some(at.argInfos.head) // @!!!
case _ => None
}
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@ object Denotations {
// ------ Forming types -------------------------------------------

/** The TypeRef representing this type denotation at its original location. */
def appliedRef(implicit ctx: Context): Type =
if (Config.newScheme) typeRef.appliedTo(symbol.typeParams.map(_.typeRef))
else typeRef

def typeRef(implicit ctx: Context): TypeRef =
TypeRef(symbol.owner.thisType, symbol.name.asTypeName, this)

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ object Flags {
*/
final val ParamAccessor = commonFlag(14, "<paramaccessor>")
final val TermParamAccessor = ParamAccessor.toTermFlags
final val TypeParamAccessor = ParamAccessor.toTypeFlags
final val TypeParamAccessor = ParamAccessor.toTypeFlags // @!!!

/** A value or class implementing a module */
final val Module = commonFlag(15, "module")
Expand Down Expand Up @@ -306,7 +306,7 @@ object Flags {

/** A binding for a type parameter of a base class or trait.
*/
final val BaseTypeArg = typeFlag(25, "<basetypearg>")
final val BaseTypeArg = typeFlag(25, "<basetypearg>") // @!!!

final val CaseAccessorOrBaseTypeArg = CaseAccessor.toCommonFlags

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Substituters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait Substituters { this: Context =>
else tp.derivedSelect(subst(tp.prefix, from, to, theMap))
case _: ThisType | NoPrefix =>
tp
case tp: RefinedType =>
case tp: RefinedType => // @!!! remove
tp.derivedRefinedType(subst(tp.parent, from, to, theMap), tp.refinedName, subst(tp.refinedInfo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(subst(tp.alias, from, to, theMap))
Expand Down
Loading