Skip to content

Commit ef38e0c

Browse files
committed
Drop code for previous creator expression scheme
1 parent d697007 commit ef38e0c

File tree

6 files changed

+13
-108
lines changed

6 files changed

+13
-108
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ object Config {
88
inline val cacheImplicitScopes = true
99
inline val cacheMatchReduced = true
1010

11-
/** If true, we implement creator expressions by adding constructor proxies.
12-
* If false, we rely on fallbacks in Typer to try a constructor if everything else failed.
13-
*/
14-
inline val addConstructorProxies = true
15-
1611
/** If true, the `runWithOwner` operation uses a re-usable context,
1712
* similar to explore. This requires that the context does not escape
1813
* the call. If false, `runWithOwner` runs its operation argument

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,19 +300,10 @@ class Definitions {
300300
cls.info = ClassInfo(cls.owner.thisType, cls, List(AnyType, MatchableType), newScope)
301301
cls.setFlag(NoInits | JavaDefined)
302302

303-
if config.Config.addConstructorProxies then
304-
ensureConstructor(cls, cls.denot.asClass, EmptyScope)
305-
val companion = JavaLangPackageVal.info.decl(nme.Object).symbol.asTerm
306-
NamerOps.makeConstructorCompanion(companion, cls)
307-
cls
308-
else
309-
// The companion object doesn't really exist, so it needs to be marked as
310-
// absent. Here we need to set it before completing attempt to load Object's
311-
// classfile, which causes issue #1648.
312-
val companion = JavaLangPackageVal.info.decl(nme.Object).symbol
313-
companion.moduleClass.markAbsent()
314-
companion.markAbsent()
315-
completeClass(cls)
303+
ensureConstructor(cls, cls.denot.asClass, EmptyScope)
304+
val companion = JavaLangPackageVal.info.decl(nme.Object).symbol.asTerm
305+
NamerOps.makeConstructorCompanion(companion, cls)
306+
cls
316307
}
317308
def ObjectType: TypeRef = ObjectClass.typeRef
318309

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ object NamerOps:
7171

7272
/** Does symbol `cls` need constructor proxies to be generated? */
7373
def needsConstructorProxies(cls: Symbol)(using Context): Boolean =
74-
Config.addConstructorProxies
75-
&& cls.isClass
74+
cls.isClass
7675
&& !cls.flagsUNSAFE.isOneOf(NoConstructorProxyNeededFlags)
7776
&& !cls.isAnonymousClass
7877

@@ -89,9 +88,8 @@ object NamerOps:
8988
newSymbol(
9089
modcls, nme.apply, ApplyProxyFlags | (constr.flagsUNSAFE & AccessFlags),
9190
ApplyProxyCompleter(constr), coord = constr.coord)
92-
if Config.addConstructorProxies then
93-
for dcl <- cls.info.decls do
94-
if dcl.isConstructor then scope.enter(proxy(dcl))
91+
for dcl <- cls.info.decls do
92+
if dcl.isConstructor then scope.enter(proxy(dcl))
9593
scope
9694
end addConstructorApplies
9795

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -844,24 +844,6 @@ trait Applications extends Compatibility {
844844
if (ctx.owner.isClassConstructor && untpd.isSelfConstrCall(app)) ctx.thisCallArgContext
845845
else ctx
846846

847-
/** Typecheck the function part of an application.
848-
* Fallback if this fails: try to convert `E` to `new E`.
849-
*/
850-
def typedFunPart(fn: untpd.Tree, pt: Type)(using Context): Tree =
851-
if Config.addConstructorProxies then typedExpr(fn, pt)
852-
else
853-
tryEither {
854-
typedExpr(fn, pt)
855-
} { (result, tstate) =>
856-
def fallBack(nuState: TyperState) =
857-
if (nuState ne ctx.typerState) && !saysNotFound(nuState, EmptyTypeName)
858-
then nuState.commit() // nuState messages are more interesting that tstate's "not found"
859-
else tstate.commit() // it's "not found" both ways; keep original message
860-
result
861-
if untpd.isPath(fn) then tryNew(untpd)(fn, pt, fallBack)
862-
else fallBack(ctx.typerState)
863-
}
864-
865847
/** Typecheck application. Result could be an `Apply` node,
866848
* or, if application is an operator assignment, also an `Assign` or
867849
* Block node.
@@ -872,7 +854,7 @@ trait Applications extends Compatibility {
872854
val originalProto =
873855
new FunProto(tree.args, IgnoredProto(pt))(this, tree.applyKind)(using argCtx(tree))
874856
record("typedApply")
875-
val fun1 = typedFunPart(tree.fun, originalProto)
857+
val fun1 = typedExpr(tree.fun, originalProto)
876858

877859
// Warning: The following lines are dirty and fragile.
878860
// We record that auto-tupling or untupling was demanded as a side effect in adapt.
@@ -1077,7 +1059,7 @@ trait Applications extends Compatibility {
10771059
val isNamed = hasNamedArg(tree.args)
10781060
val typedArgs = if (isNamed) typedNamedArgs(tree.args) else tree.args.mapconserve(typedType(_))
10791061
record("typedTypeApply")
1080-
typedFunPart(tree.fun, PolyProto(typedArgs, pt)) match {
1062+
typedExpr(tree.fun, PolyProto(typedArgs, pt)) match {
10811063
case IntegratedTypeArgs(app) =>
10821064
app
10831065
case _: TypeApply if !ctx.isAfterTyper =>

compiler/src/dotty/tools/dotc/typer/ReTyper.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ class ReTyper extends Typer with ReChecking {
7171
override def typedRefinedTypeTree(tree: untpd.RefinedTypeTree)(using Context): TypTree =
7272
promote(TypeTree(tree.tpe).withSpan(tree.span))
7373

74-
override def typedFunPart(fn: untpd.Tree, pt: Type)(using Context): Tree =
75-
typedExpr(fn, pt)
76-
7774
override def typedBind(tree: untpd.Bind, pt: Type)(using Context): Bind = {
7875
assertTyped(tree)
7976
val body1 = typed(tree.body, pt)
@@ -104,10 +101,6 @@ class ReTyper extends Typer with ReChecking {
104101
override def tryInsertApplyOrImplicit(tree: Tree, pt: ProtoType, locked: TypeVars)(fallBack: => Tree)(using Context): Tree =
105102
fallBack
106103

107-
override def tryNew[T >: Untyped <: Type]
108-
(treesInst: Instance[T])(tree: Trees.Tree[T], pt: Type, fallBack: TyperState => Tree)(using Context): Tree =
109-
fallBack(ctx.typerState)
110-
111104
override def completeAnnotations(mdef: untpd.MemberDef, sym: Symbol)(using Context): Unit = ()
112105

113106
override def ensureConstrCall(cls: ClassSymbol, parents: List[Tree])(using Context): List[Tree] =

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2791,55 +2791,6 @@ class Typer extends Namer
27912791
case _ => false
27922792
}
27932793

2794-
/** Try to rename `tpt` to a type `T` and typecheck `new T` with given expected type `pt`.
2795-
* The operation is called from either `adapt` or `typedApply`. `adapt` gets to call `tryNew`
2796-
* for calls `p.C(..)` if there is a value `p.C`. `typedApply` calls `tryNew` as a fallback
2797-
* in case typing `p.C` fails since there is no value with path `p.C`. The call from `adapt`
2798-
* is more efficient since it re-uses the prefix `p` in typed form.
2799-
*/
2800-
def tryNew[T >: Untyped <: Type]
2801-
(treesInst: Instance[T])(tree: Trees.Tree[T], pt: Type, fallBack: TyperState => Tree)(using Context): Tree = {
2802-
2803-
def tryWithType(tpt: untpd.Tree): Tree =
2804-
tryEither {
2805-
val tycon = typed(tpt)
2806-
if (summon[Context].reporter.hasErrors)
2807-
EmptyTree // signal that we should return the error in fallBack
2808-
else {
2809-
def recur(tpt: Tree, pt: Type): Tree = pt.revealIgnored match {
2810-
case PolyProto(targs, pt1) if !targs.exists(_.isInstanceOf[NamedArg]) =>
2811-
// Applications with named arguments cannot be converted, since new expressions
2812-
// don't accept named arguments
2813-
IntegratedTypeArgs(recur(AppliedTypeTree(tpt, targs), pt1))
2814-
case _ =>
2815-
typed(untpd.Select(untpd.New(untpd.TypedSplice(tpt)), nme.CONSTRUCTOR), pt)
2816-
}
2817-
recur(tycon, pt)
2818-
.showing(i"try new $tree -> $result", typr)
2819-
}
2820-
} { (nu, nuState) =>
2821-
if (nu.isEmpty) fallBack(nuState)
2822-
else {
2823-
// we found a type constructor, signal the error in its application instead of the original one
2824-
nuState.commit()
2825-
nu
2826-
}
2827-
}
2828-
2829-
tree match {
2830-
case Ident(name) =>
2831-
tryWithType(cpy.Ident(tree)(name.toTypeName))
2832-
case Select(qual, name) =>
2833-
val qual1 = treesInst match {
2834-
case `tpd` => untpd.TypedSplice(qual)
2835-
case `untpd` => qual
2836-
}
2837-
tryWithType(cpy.Select(tree)(qual1, name.toTypeName))
2838-
case _ =>
2839-
fallBack(ctx.typerState)
2840-
}
2841-
}
2842-
28432794
/** Potentially add apply node or implicit conversions. Before trying either,
28442795
* if the function is applied to an empty parameter list (), we try
28452796
*
@@ -2876,10 +2827,7 @@ class Typer extends Namer
28762827
}
28772828

28782829
def tryImplicit(fallBack: => Tree) =
2879-
tryInsertImplicitOnQualifier(tree, pt.withContext(ctx), locked)
2880-
.getOrElse(
2881-
if Config.addConstructorProxies then fallBack
2882-
else tryNew(tpd)(tree, pt, _ => fallBack))
2830+
tryInsertImplicitOnQualifier(tree, pt.withContext(ctx), locked).getOrElse(fallBack)
28832831

28842832
if (ctx.mode.is(Mode.SynthesizeExtMethodReceiver))
28852833
// Suppress insertion of apply or implicit conversion on extension method receiver
@@ -3651,10 +3599,8 @@ class Typer extends Namer
36513599
adaptOverloaded(ref)
36523600
}
36533601
case poly: PolyType if !(ctx.mode is Mode.Type) =>
3654-
if tree.symbol.isAllOf(ApplyProxyFlags) && Config.addConstructorProxies then
3655-
newExpr
3656-
else if pt.isInstanceOf[PolyProto] then
3657-
tree
3602+
if tree.symbol.isAllOf(ApplyProxyFlags) then newExpr
3603+
else if pt.isInstanceOf[PolyProto] then tree
36583604
else
36593605
var typeArgs = tree match
36603606
case Select(qual, nme.CONSTRUCTOR) => qual.tpe.widenDealias.argTypesLo.map(TypeTree)
@@ -3667,7 +3613,7 @@ class Typer extends Namer
36673613
readaptSimplified(handleStructural(tree))
36683614
else pt match {
36693615
case pt: FunProto =>
3670-
if tree.symbol.isAllOf(ApplyProxyFlags) && Config.addConstructorProxies then newExpr
3616+
if tree.symbol.isAllOf(ApplyProxyFlags) then newExpr
36713617
else adaptToArgs(wtp, pt)
36723618
case pt: PolyProto =>
36733619
tree match {

0 commit comments

Comments
 (0)