Skip to content

Commit cce03ce

Browse files
committed
Eliminate Config switches
We are going to dismantle the old scheme code, so no need to keep the switches.
1 parent 039fec9 commit cce03ce

File tree

17 files changed

+47
-275
lines changed

17 files changed

+47
-275
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Run(comp: Compiler, ictx: Context) {
118118
ctx.usePhases(phases)
119119
var lastPrintedTree: PrintedTree = NoPrintedTree
120120
for (phase <- ctx.allPhases)
121-
if (phase.isRunnable) // @!!! check? was: !ctx.reporter.hasErrors
121+
if (phase.isRunnable)
122122
Stats.trackTime(s"$phase ms ") {
123123
val start = System.currentTimeMillis
124124
units = phase.runOn(units)

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -238,23 +238,6 @@ object desugar {
238238
Nil
239239
}
240240

241-
/** Fill in empty type bounds with Nothing/Any. Expand private local type parameters as follows:
242-
*
243-
* class C[v T]
244-
* ==>
245-
* class C { type v C$T; type v T = C$T }
246-
*/
247-
def typeDef(tdef: TypeDef)(implicit ctx: Context): Tree = {
248-
if (tdef.mods.is(PrivateLocalParam) && !dotty.tools.dotc.config.Config.newScheme) {
249-
val tparam = cpy.TypeDef(tdef)(name = tdef.name.expandedName(ctx.owner))
250-
.withMods(tdef.mods &~ PrivateLocal)
251-
val alias = cpy.TypeDef(tdef)(rhs = refOfDef(tparam))
252-
.withMods(tdef.mods & VarianceFlags | PrivateLocalParamAccessor | Synthetic)
253-
Thicket(tparam, alias)
254-
}
255-
else tdef
256-
}
257-
258241
@sharable private val synthetic = Modifiers(Synthetic)
259242

260243
private def toDefParam(tparam: TypeDef): TypeDef =
@@ -696,7 +679,7 @@ object desugar {
696679

697680
def defTree(tree: Tree)(implicit ctx: Context): Tree = tree match {
698681
case tree: ValDef => valDef(tree)
699-
case tree: TypeDef => if (tree.isClassDef) classDef(tree) else typeDef(tree)
682+
case tree: TypeDef => if (tree.isClassDef) classDef(tree) else tree
700683
case tree: DefDef => defDef(tree)
701684
case tree: ModuleDef => moduleDef(tree)
702685
case tree: PatDef => patDef(tree)
@@ -1133,7 +1116,6 @@ object desugar {
11331116
def refinedTypeToClass(parent: tpd.Tree, refinements: List[Tree])(implicit ctx: Context): TypeDef = {
11341117
def stripToCore(tp: Type): List[Type] = tp match {
11351118
case tp: AppliedType => tp :: Nil
1136-
case tp: RefinedType if !config.Config.newScheme && tp.argInfos.nonEmpty => tp :: Nil // parameterized class type
11371119
case tp: TypeRef if tp.symbol.isClass => tp :: Nil // monomorphic class type
11381120
case tp: TypeProxy => stripToCore(tp.underlying)
11391121
case AndType(tp1, tp2) => stripToCore(tp1) ::: stripToCore(tp2)

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
213213
ta.assignType(untpd.TypeDef(sym.name, TypeTree(sym.info)), sym)
214214

215215
def ClassDef(cls: ClassSymbol, constr: DefDef, body: List[Tree], superArgs: List[Tree] = Nil)(implicit ctx: Context): TypeDef = {
216-
val (firstParent, otherParents) =
217-
if (config.Config.newScheme) {
218-
val firstParent :: otherParents = cls.info.parentsNEW
219-
(firstParent, otherParents)
220-
}
221-
else {
222-
val firstParentRef :: otherParentRefs = cls.info.parentRefs // @!!! adapt
223-
val firstParent = cls.appliedRef.baseTypeWithArgs(firstParentRef.symbol)
224-
(firstParent, otherParentRefs)
225-
}
216+
val firstParent :: otherParents = cls.info.parentsNEW
226217
val superRef =
227218
if (cls is Trait) TypeTree(firstParent)
228219
else {
@@ -269,9 +260,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
269260
def AnonClass(parents: List[Type], fns: List[TermSymbol], methNames: List[TermName])(implicit ctx: Context): Block = {
270261
val owner = fns.head.owner
271262
val parents1 =
272-
if (parents.head.classSymbol.is(Trait))
273-
if (config.Config.newScheme) parents.head.parentsNEW.head :: parents
274-
else parents.head.parentRefs.head :: parents
263+
if (parents.head.classSymbol.is(Trait)) parents.head.parentsNEW.head :: parents
275264
else parents
276265
val cls = ctx.newNormalizedClassSymbol(owner, tpnme.ANON_FUN, Synthetic, parents1,
277266
coord = fns.map(_.pos).reduceLeft(_ union _))

compiler/src/dotty/tools/dotc/config/Config.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,4 @@ object Config {
181181

182182
/** When in IDE, turn StaleSymbol errors into warnings instead of crashing */
183183
final val ignoreStaleInIDE = true
184-
185-
val newScheme = true
186-
val newBoundsScheme = true
187184
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,7 @@ object Contexts {
334334
* from constructor parameters to class parameter accessors.
335335
*/
336336
def superCallContext: Context = {
337-
val locals = newScopeWith(
338-
(if (Config.newScheme) owner.typeParams ++ owner.asClass.paramAccessors
339-
else owner.asClass.paramAccessors): _*)
337+
val locals = newScopeWith(owner.typeParams ++ owner.asClass.paramAccessors: _*)
340338
superOrThisCallContext(owner.primaryConstructor, locals)
341339
}
342340

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,7 @@ object Denotations {
645645

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

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ object Flags {
497497

498498
/** The flags of a class type parameter */
499499
final val ClassTypeParamCreationFlags =
500-
TypeParam | Deferred | (if (config.Config.newScheme) Private else Protected) | Local
500+
TypeParam | Deferred | Private | Local
501501

502502
/** Flags that can apply to both a module val and a module class, except those that
503503
* are added at creation anyway
@@ -593,7 +593,7 @@ object Flags {
593593
/** Is valid forever */
594594
final val ValidForever = Package | Permanent | Scala2ExistentialCommon
595595

596-
/** A type parameter of a class or trait (works only under Config.newScheme) */
596+
/** A type parameter of a class or trait */
597597
final val ClassTypeParam = allOf(TypeParam, Private)
598598

599599
/** Is a default parameter in Scala 2*/

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

Lines changed: 6 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -402,54 +402,6 @@ class TypeApplications(val self: Type) extends AnyVal {
402402
}
403403
val stripped = self.stripTypeVar
404404
val dealiased = stripped.safeDealias
405-
406-
/** Normalize a TypeBounds argument. This involves (1) propagating bounds
407-
* from the type parameters into the argument, (2) possibly choosing the argument's
408-
* upper or lower bound according to variance.
409-
*
410-
* Bounds propagation works as follows: If the dealiased type constructor is a TypeRef
411-
* `p.c`,
412-
* - take the type paramater bounds of `c` as seen from `p`,
413-
* - substitute concrete (non-bound) arguments for corresponding formal type parameters,
414-
* - interpolate, so that any (F-bounded) type parameters in the resulting bounds are avoided.
415-
* The resulting bounds are joined (via &) with corresponding type bound arguments.
416-
*/
417-
def normalizeWildcardArg(typParams: List[TypeSymbol])(arg: Type, tparam: TypeSymbol): Type = arg match {
418-
case TypeBounds(lo, hi) =>
419-
if (Config.newBoundsScheme) arg
420-
else {
421-
def avoidParams(seen: Set[Symbol], v: Int): ApproximatingTypeMap = new ApproximatingTypeMap {
422-
variance = if (v >= 0) 1 else -1
423-
def apply(t: Type) = t match {
424-
case t: TypeRef if typParams contains t.symbol =>
425-
val lo = atVariance(-variance)(apply(t.info.loBound))
426-
val hi =
427-
if (seen.contains(t.symbol)) t.topType
428-
else avoidParams(seen + t.symbol, variance)(t.info.hiBound)
429-
range(lo, hi)
430-
case _ => mapOver(t)
431-
}
432-
}
433-
val v = tparam.paramVariance
434-
val pbounds = dealiased match {
435-
case dealiased @ TypeRef(prefix, _) =>
436-
val (concreteArgs, concreteParams) = // @!!! optimize?
437-
args.zip(typParams).filter(!_._1.isInstanceOf[TypeBounds]).unzip
438-
if (tparam.isCompleting) TypeBounds.empty
439-
else avoidParams(Set(tparam), v)(
440-
tparam.paramInfo.asSeenFrom(prefix, tparam.owner)
441-
.subst(concreteParams, concreteArgs))
442-
case _ =>
443-
TypeBounds.empty
444-
}
445-
typr.println(i"normalize arg $arg for $tparam in $self app $args%, %, pbounds, = $pbounds")
446-
if (v > 0) hi & pbounds.hiBound
447-
else if (v < 0) lo | pbounds.loBound
448-
else arg recoverable_& pbounds
449-
}
450-
case _ => arg
451-
}
452-
453405
if (args.isEmpty || ctx.erasedTypes) self
454406
else dealiased match {
455407
case dealiased: HKTypeLambda =>
@@ -500,11 +452,7 @@ class TypeApplications(val self: Type) extends AnyVal {
500452
case _ if typParams.isEmpty || typParams.head.isInstanceOf[LambdaParam] =>
501453
HKApply(self, args)
502454
case dealiased =>
503-
if (Config.newScheme) {
504-
val tparamSyms = typParams.asInstanceOf[List[TypeSymbol]]
505-
AppliedType(self, args.zipWithConserve(tparamSyms)(normalizeWildcardArg(tparamSyms)))
506-
} else
507-
matchParams(dealiased, typParams, args)
455+
AppliedType(self, args)
508456
}
509457
}
510458

@@ -540,48 +488,16 @@ class TypeApplications(val self: Type) extends AnyVal {
540488
/** The type arguments of this type's base type instance wrt. `base`.
541489
* Wildcard types in arguments are returned as TypeBounds instances.
542490
*/
543-
final def baseArgInfos(base: Symbol)(implicit ctx: Context): List[Type] =
544-
if (Config.newScheme)
545-
self.baseType(base).argInfos
546-
else if (self derivesFrom base)
547-
self.dealias match {
548-
case self: TypeRef if !self.symbol.isClass => self.superType.baseArgInfos(base)
549-
case self: HKApply => self.superType.baseArgInfos(base)
550-
case _ => base.typeParams.map(param => self.member(param.name).info.argInfo)
551-
}
552-
else
553-
Nil
491+
final def baseArgInfos(base: Symbol)(implicit ctx: Context): List[Type] = // @!!! drop
492+
self.baseType(base).argInfos
554493

555494
/** The base type including all type arguments and applicable refinements
556495
* of this type. Refinements are applicable if they refine a member of
557496
* the parent type which furthermore is not a name-mangled type parameter.
558497
* Existential types in arguments are returned as TypeBounds instances.
559498
*/
560-
final def baseTypeWithArgs(base: Symbol)(implicit ctx: Context): Type =
561-
if (Config.newScheme) self.baseType(base)
562-
else ctx.traceIndented(s"btwa ${self.show} wrt $base", core, show = true) {
563-
def default = self.baseTypeTycon(base).appliedTo(baseArgInfos(base))
564-
def isExpandedTypeParam(sym: Symbol) = sym.is(TypeParam) && sym.name.is(ExpandedName)
565-
self match {
566-
case tp: TypeRef =>
567-
tp.info match {
568-
case TypeBounds(_, hi) => hi.baseTypeWithArgs(base)
569-
case _ => default
570-
}
571-
case tp @ RefinedType(parent, name, _) if !Config.newScheme && !isExpandedTypeParam(tp.member(name).symbol) =>
572-
tp.wrapIfMember(parent.baseTypeWithArgs(base))
573-
case tp: TermRef =>
574-
tp.underlying.baseTypeWithArgs(base)
575-
case tp: HKApply =>
576-
tp.superType.baseTypeWithArgs(base)
577-
case AndType(tp1, tp2) =>
578-
tp1.baseTypeWithArgs(base) & tp2.baseTypeWithArgs(base)
579-
case OrType(tp1, tp2) =>
580-
tp1.baseTypeWithArgs(base) | tp2.baseTypeWithArgs(base)
581-
case _ =>
582-
default
583-
}
584-
}
499+
final def baseTypeWithArgs(base: Symbol)(implicit ctx: Context): Type = // @!!! drop
500+
self.baseType(base)
585501

586502
/** Translate a type of the form From[T] to To[T], keep other types as they are.
587503
* `from` and `to` must be static classes, both with one type parameter, and the same variance.
@@ -593,8 +509,7 @@ class TypeApplications(val self: Type) extends AnyVal {
593509
case _ =>
594510
if (self.derivesFrom(from))
595511
if (ctx.erasedTypes) to.typeRef // @!!! can be dropped; appliedTo does the right thing anyway
596-
else if (Config.newScheme) to.typeRef.appliedTo(self.baseType(from).argInfos)
597-
else RefinedType(to.typeRef, to.typeParams.head.name, self.member(from.typeParams.head.name).info)
512+
else to.typeRef.appliedTo(self.baseType(from).argInfos)
598513
else self
599514
}
600515

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,20 +1026,11 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
10261026
val classBounds = tp2.classSymbols
10271027
def recur(bcs: List[ClassSymbol]): Boolean = bcs match {
10281028
case bc :: bcs1 =>
1029-
if (Config.newScheme)
1030-
(classBounds.exists(bc.derivesFrom) &&
1031-
variancesConform(bc.typeParams, tparams) &&
1032-
p(tp1.baseType(bc))
1033-
||
1034-
recur(bcs1))
1035-
else {
1036-
val baseRef = tp1.baseTypeTycon(bc)
1037-
(classBounds.exists(bc.derivesFrom) &&
1038-
variancesConform(baseRef.typeParams, tparams) &&
1039-
p(baseRef.appliedTo(tp1.baseArgInfos(bc)))
1040-
||
1041-
recur(bcs1))
1042-
}
1029+
(classBounds.exists(bc.derivesFrom) &&
1030+
variancesConform(bc.typeParams, tparams) &&
1031+
p(tp1.baseType(bc))
1032+
||
1033+
recur(bcs1))
10431034
case nil =>
10441035
false
10451036
}

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

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -268,56 +268,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
268268
* all (possibly applied) references to classes.
269269
*/
270270
def normalizeToClassRefs(parents: List[Type], cls: ClassSymbol, decls: Scope): List[Type] = {
271-
if (Config.newScheme) return parents.mapConserve(_.dealias) // !@@@ track and eliminate usages?
272-
// println(s"normalizing $parents of $cls in ${cls.owner}") // !!! DEBUG
273-
274-
// A map consolidating all refinements arising from parent type parameters
275-
var refinements: SimpleMap[TypeName, Type] = SimpleMap.Empty
276-
277-
// A map of all formal type parameters of base classes that get refined
278-
var formals: SimpleMap[TypeName, Symbol] = SimpleMap.Empty // A map of all formal parent parameter
279-
280-
// Strip all refinements from parent type, populating `refinements` and `formals` maps.
281-
def normalizeToRef(tp: Type): TypeRef = {
282-
def fail = throw new TypeError(s"unexpected parent type: $tp")
283-
tp.dealias match {
284-
case tp: TypeRef =>
285-
tp
286-
case tp @ RefinedType(tp1, name: TypeName, rinfo) =>
287-
val prevInfo = refinements(name)
288-
refinements = refinements.updated(name,
289-
if (prevInfo == null) tp.refinedInfo else prevInfo & tp.refinedInfo)
290-
formals = formals.updated(name, tp1.typeParamNamed(name))
291-
normalizeToRef(tp1)
292-
case tp @ RefinedType(tp1, _: TermName, _) =>
293-
normalizeToRef(tp1)
294-
case _: ErrorType =>
295-
defn.AnyType
296-
case AnnotatedType(tpe, _) =>
297-
normalizeToRef(tpe)
298-
case HKApply(tycon: TypeRef, args) =>
299-
tycon.info match {
300-
case TypeAlias(alias) => normalizeToRef(alias.appliedTo(args))
301-
case _ => fail
302-
}
303-
case _ =>
304-
fail
305-
}
306-
}
307-
308-
val parentRefs = parents map normalizeToRef
309-
310-
// Enter all refinements into current scope.
311-
refinements foreachBinding { (name, refinedInfo) =>
312-
assert(decls.lookup(name) == NoSymbol, // DEBUG
313-
s"redefinition of ${decls.lookup(name).debugString} in ${cls.showLocated}")
314-
enterArgBinding(formals(name), refinedInfo, cls, decls)
315-
}
316-
317-
if (Config.forwardTypeParams)
318-
forwardParamBindings(parentRefs, refinements, cls, decls)
319-
320-
parentRefs
271+
parents.mapConserve(_.dealias) // !@@@ track and eliminate usages?
321272
}
322273

323274
/** Forward parameter bindings in baseclasses to argument types of

0 commit comments

Comments
 (0)