Skip to content

Commit 4e2cd5a

Browse files
committed
Drop code for previous creator expression scheme
1 parent 63d5cbd commit 4e2cd5a

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
@@ -2800,55 +2800,6 @@ class Typer extends Namer
28002800
case _ => false
28012801
}
28022802

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

28872838
def tryImplicit(fallBack: => Tree) =
2888-
tryInsertImplicitOnQualifier(tree, pt.withContext(ctx), locked)
2889-
.getOrElse(
2890-
if Config.addConstructorProxies then fallBack
2891-
else tryNew(tpd)(tree, pt, _ => fallBack))
2839+
tryInsertImplicitOnQualifier(tree, pt.withContext(ctx), locked).getOrElse(fallBack)
28922840

28932841
if (ctx.mode.is(Mode.SynthesizeExtMethodReceiver))
28942842
// Suppress insertion of apply or implicit conversion on extension method receiver
@@ -3660,10 +3608,8 @@ class Typer extends Namer
36603608
adaptOverloaded(ref)
36613609
}
36623610
case poly: PolyType if !(ctx.mode is Mode.Type) =>
3663-
if tree.symbol.isAllOf(ApplyProxyFlags) && Config.addConstructorProxies then
3664-
newExpr
3665-
else if pt.isInstanceOf[PolyProto] then
3666-
tree
3611+
if tree.symbol.isAllOf(ApplyProxyFlags) then newExpr
3612+
else if pt.isInstanceOf[PolyProto] then tree
36673613
else
36683614
var typeArgs = tree match
36693615
case Select(qual, nme.CONSTRUCTOR) => qual.tpe.widenDealias.argTypesLo.map(TypeTree)
@@ -3676,7 +3622,7 @@ class Typer extends Namer
36763622
readaptSimplified(handleStructural(tree))
36773623
else pt match {
36783624
case pt: FunProto =>
3679-
if tree.symbol.isAllOf(ApplyProxyFlags) && Config.addConstructorProxies then newExpr
3625+
if tree.symbol.isAllOf(ApplyProxyFlags) then newExpr
36803626
else adaptToArgs(wtp, pt)
36813627
case pt: PolyProto =>
36823628
tree match {

0 commit comments

Comments
 (0)