Skip to content

Commit fcdfdd4

Browse files
committed
WIP
1 parent 92b4ac0 commit fcdfdd4

File tree

2 files changed

+59
-23
lines changed

2 files changed

+59
-23
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ object Printers {
3333
val interactiv = noPrinter
3434
val matchTypes = noPrinter
3535
val nullables = noPrinter
36-
val overload = noPrinter
36+
val overload = default
3737
val patmatch = noPrinter
3838
val pickling = noPrinter
3939
val quotePickling = noPrinter

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

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,9 @@ trait Applications extends Compatibility {
404404
private var _ok = true
405405

406406
def ok: Boolean = _ok
407-
def ok_=(x: Boolean): Unit = _ok = x
407+
def ok_=(x: Boolean): Unit =
408+
//if !x then println("set ok to false")
409+
_ok = x
408410

409411
/** The function's type after widening and instantiating polytypes
410412
* with TypeParamRefs in constraint set
@@ -446,7 +448,9 @@ trait Applications extends Compatibility {
446448
// match all arguments with corresponding formal parameters
447449
matchArgs(orderedArgs, methType.paramInfos, 0)
448450
case _ =>
449-
if (methType.isError) ok = false
451+
if (methType.isError) then
452+
//println("methType.isError")
453+
ok = false
450454
else fail(s"$methString does not take parameters")
451455
}
452456

@@ -654,7 +658,7 @@ trait Applications extends Compatibility {
654658
defn.isFunctionType(argtpe1) && formal.match
655659
case SAMType(sam) => argtpe <:< sam.toFunctionType(isJava = formal.classSymbol.is(JavaDefined))
656660
case _ => false
657-
661+
//println(s"argOK($arg,$formal) = ${isCompatible(argtpe, formal)}")
658662
isCompatible(argtpe, formal)
659663
// Only allow SAM-conversion to PartialFunction if implicit conversions
660664
// are enabled. This is necessary to avoid ambiguity between an overload
@@ -688,8 +692,11 @@ trait Applications extends Compatibility {
688692
final def addArg(arg: TypedArg, formal: Type): Unit = ok = ok & argOK(arg, formal)
689693
def makeVarArg(n: Int, elemFormal: Type): Unit = {}
690694
def fail(msg: Message, arg: Arg): Unit =
695+
//println(msg)
696+
//println(arg)
691697
ok = false
692698
def fail(msg: Message): Unit =
699+
//println(msg)
693700
ok = false
694701
def appPos: SrcPos = NoSourcePosition
695702
@threadUnsafe lazy val normalizedFun: Tree = ref(methRef)
@@ -701,6 +708,7 @@ trait Applications extends Compatibility {
701708
*/
702709
class ApplicableToTrees(methRef: TermRef, args: List[Tree], resultType: Type, argMatch: ArgMatch)(using Context)
703710
extends TestApplication(methRef, methRef.widen, args, resultType, argMatch) {
711+
//println("ApplicableToTrees created")
704712
def argType(arg: Tree, formal: Type): Type =
705713
if untpd.isContextualClosure(arg) && defn.isContextFunctionType(formal) then arg.tpe
706714
else normalize(arg.tpe, formal)
@@ -1385,8 +1393,10 @@ trait Applications extends Compatibility {
13851393
* @param resultType The expected result type of the application
13861394
*/
13871395
def isApplicableMethodRef(methRef: TermRef, args: List[Tree], resultType: Type, keepConstraint: Boolean, argMatch: ArgMatch)(using Context): Boolean = {
1396+
//println("entered isApplicableMethodRef")
13881397
def isApp(using Context): Boolean =
13891398
new ApplicableToTrees(methRef, args, resultType, argMatch).success
1399+
//println(isApp) // check above ^
13901400
if (keepConstraint) isApp else explore(isApp)
13911401
}
13921402

@@ -1748,23 +1758,30 @@ trait Applications extends Compatibility {
17481758
* probability of pruning the search. result type comparisons are neither cheap nor
17491759
* do they prune much, on average.
17501760
*/
1751-
def adaptByResult(chosen: TermRef, alts: List[TermRef]) = pt match {
1752-
case pt: FunProto if !explore(resultConforms(chosen.symbol, chosen, pt.resultType)) =>
1753-
val conformingAlts = alts.filterConserve(alt =>
1754-
(alt ne chosen) && explore(resultConforms(alt.symbol, alt, pt.resultType)))
1755-
conformingAlts match {
1756-
case Nil => chosen
1757-
case alt2 :: Nil => alt2
1758-
case alts2 =>
1759-
resolveOverloaded(alts2, pt) match {
1760-
case alt2 :: Nil => alt2
1761-
case _ => chosen
1762-
}
1763-
}
1764-
case _ => chosen
1765-
}
1761+
def adaptByResult(chosen: TermRef, alts: List[TermRef]) =
1762+
//println("entered adaptByResult")
1763+
//println(chosen.symbol.showDcl)
1764+
//println(alts.map(_.symbol.showDcl))
1765+
pt match {
1766+
case pt: FunProto if !explore(resultConforms(chosen.symbol, chosen, pt.resultType)) =>
1767+
//println("pt funproto")
1768+
val conformingAlts = alts.filterConserve(alt =>
1769+
(alt ne chosen) && explore(resultConforms(alt.symbol, alt, pt.resultType)))
1770+
//println(conformingAlts.map(_.symbol.showDcl))
1771+
conformingAlts match {
1772+
case Nil => chosen
1773+
case alt2 :: Nil => alt2
1774+
case alts2 =>
1775+
resolveOverloaded(alts2, pt) match {
1776+
case alt2 :: Nil => alt2
1777+
case _ => chosen
1778+
}
1779+
}
1780+
case _ => chosen
1781+
}
17661782

17671783
def resolve(alts: List[TermRef]): List[TermRef] =
1784+
//println("enter resolve")
17681785
pt match
17691786
case pt: FunProto =>
17701787
if pt.applyKind == ApplyKind.Using then
@@ -1775,11 +1792,18 @@ trait Applications extends Compatibility {
17751792
case _ =>
17761793

17771794
var found = withoutMode(Mode.ImplicitsEnabled)(resolveOverloaded1(alts, pt))
1795+
//println("found =")
1796+
//println(found.map(_.symbol.showDcl))
17781797
if found.isEmpty && ctx.mode.is(Mode.ImplicitsEnabled) then
1798+
//println("update found")
17791799
found = resolveOverloaded1(alts, pt)
17801800
found match
1781-
case alt :: Nil => adaptByResult(alt, alts) :: Nil
1782-
case _ => found
1801+
case alt :: Nil =>
1802+
//println("resolve1")
1803+
adaptByResult(alt, alts) :: Nil
1804+
case _ =>
1805+
//println("resolve2")
1806+
found
17831807
end resolve
17841808

17851809
/** Try an apply method, if
@@ -1827,6 +1851,9 @@ trait Applications extends Compatibility {
18271851
trace(i"resolve over $alts%, %, pt = $pt", typr, show = true) {
18281852
record(s"resolveOverloaded1", alts.length)
18291853

1854+
//println(pt.show)
1855+
//println(pt)
1856+
18301857
def isDetermined(alts: List[TermRef]) = alts.isEmpty || alts.tail.isEmpty
18311858

18321859
/** The shape of given tree as a type; cannot handle named arguments. */
@@ -1926,16 +1953,25 @@ trait Applications extends Compatibility {
19261953
record("resolveOverloaded.FunProto", alts.length)
19271954
val alts1 = narrowBySize(alts)
19281955
//report.log(i"narrowed by size: ${alts1.map(_.symbol.showDcl)}%, %")
1956+
//println(i"narrowed by size: ${alts1.map(_.symbol.showDcl)}%, %")
19291957
if isDetermined(alts1) then alts1
19301958
else
19311959
record("resolveOverloaded.narrowedBySize", alts1.length)
19321960
val alts2 = narrowByShapes(alts1)
19331961
//report.log(i"narrowed by shape: ${alts2.map(_.symbol.showDcl)}%, %")
1934-
if isDetermined(alts2) then alts2
1962+
//println(i"narrowed by shape: ${alts2.map(_.symbol.showDcl)}%, %")
1963+
if isDetermined(alts2)
1964+
then
1965+
//println("1")
1966+
//println(alts2.map(_.symbol.showDcl))
1967+
alts2
19351968
else
19361969
record("resolveOverloaded.narrowedByShape", alts2.length)
19371970
pretypeArgs(alts2, pt)
1938-
narrowByTrees(alts2, pt.typedArgs(normArg(alts2, _, _)), resultType)
1971+
val res = narrowByTrees(alts2, pt.typedArgs(normArg(alts2, _, _)), resultType)
1972+
//println("2")
1973+
//println(res.map(_.symbol.showDcl))
1974+
res
19391975

19401976
case pt @ PolyProto(targs1, pt1) =>
19411977
val alts1 = alts.filterConserve(pt.canInstantiate)

0 commit comments

Comments
 (0)