Skip to content

Commit 4e77a07

Browse files
committed
WIP
1 parent e257c16 commit 4e77a07

File tree

2 files changed

+59
-23
lines changed

2 files changed

+59
-23
lines changed

Diff for: compiler/src/dotty/tools/dotc/config/Printers.scala

+1-1
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

Diff for: compiler/src/dotty/tools/dotc/typer/Applications.scala

+58-22
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)
@@ -1394,8 +1402,10 @@ trait Applications extends Compatibility {
13941402
* @param resultType The expected result type of the application
13951403
*/
13961404
def isApplicableMethodRef(methRef: TermRef, args: List[Tree], resultType: Type, keepConstraint: Boolean, argMatch: ArgMatch)(using Context): Boolean = {
1405+
//println("entered isApplicableMethodRef")
13971406
def isApp(using Context): Boolean =
13981407
new ApplicableToTrees(methRef, args, resultType, argMatch).success
1408+
//println(isApp) // check above ^
13991409
if (keepConstraint) isApp else explore(isApp)
14001410
}
14011411

@@ -1757,23 +1767,30 @@ trait Applications extends Compatibility {
17571767
* probability of pruning the search. result type comparisons are neither cheap nor
17581768
* do they prune much, on average.
17591769
*/
1760-
def adaptByResult(chosen: TermRef, alts: List[TermRef]) = pt match {
1761-
case pt: FunProto if !explore(resultConforms(chosen.symbol, chosen, pt.resultType)) =>
1762-
val conformingAlts = alts.filterConserve(alt =>
1763-
(alt ne chosen) && explore(resultConforms(alt.symbol, alt, pt.resultType)))
1764-
conformingAlts match {
1765-
case Nil => chosen
1766-
case alt2 :: Nil => alt2
1767-
case alts2 =>
1768-
resolveOverloaded(alts2, pt) match {
1769-
case alt2 :: Nil => alt2
1770-
case _ => chosen
1771-
}
1772-
}
1773-
case _ => chosen
1774-
}
1770+
def adaptByResult(chosen: TermRef, alts: List[TermRef]) =
1771+
//println("entered adaptByResult")
1772+
//println(chosen.symbol.showDcl)
1773+
//println(alts.map(_.symbol.showDcl))
1774+
pt match {
1775+
case pt: FunProto if !explore(resultConforms(chosen.symbol, chosen, pt.resultType)) =>
1776+
//println("pt funproto")
1777+
val conformingAlts = alts.filterConserve(alt =>
1778+
(alt ne chosen) && explore(resultConforms(alt.symbol, alt, pt.resultType)))
1779+
//println(conformingAlts.map(_.symbol.showDcl))
1780+
conformingAlts match {
1781+
case Nil => chosen
1782+
case alt2 :: Nil => alt2
1783+
case alts2 =>
1784+
resolveOverloaded(alts2, pt) match {
1785+
case alt2 :: Nil => alt2
1786+
case _ => chosen
1787+
}
1788+
}
1789+
case _ => chosen
1790+
}
17751791

17761792
def resolve(alts: List[TermRef]): List[TermRef] =
1793+
//println("enter resolve")
17771794
pt match
17781795
case pt: FunProto =>
17791796
if pt.applyKind == ApplyKind.Using then
@@ -1784,11 +1801,18 @@ trait Applications extends Compatibility {
17841801
case _ =>
17851802

17861803
var found = withoutMode(Mode.ImplicitsEnabled)(resolveOverloaded1(alts, pt))
1804+
//println("found =")
1805+
//println(found.map(_.symbol.showDcl))
17871806
if found.isEmpty && ctx.mode.is(Mode.ImplicitsEnabled) then
1807+
//println("update found")
17881808
found = resolveOverloaded1(alts, pt)
17891809
found match
1790-
case alt :: Nil => adaptByResult(alt, alts) :: Nil
1791-
case _ => found
1810+
case alt :: Nil =>
1811+
//println("resolve1")
1812+
adaptByResult(alt, alts) :: Nil
1813+
case _ =>
1814+
//println("resolve2")
1815+
found
17921816
end resolve
17931817

17941818
/** Try an apply method, if
@@ -1836,6 +1860,9 @@ trait Applications extends Compatibility {
18361860
trace(i"resolve over $alts%, %, pt = $pt", typr, show = true) {
18371861
record(s"resolveOverloaded1", alts.length)
18381862

1863+
//println(pt.show)
1864+
//println(pt)
1865+
18391866
def isDetermined(alts: List[TermRef]) = alts.isEmpty || alts.tail.isEmpty
18401867

18411868
/** The shape of given tree as a type; cannot handle named arguments. */
@@ -1935,16 +1962,25 @@ trait Applications extends Compatibility {
19351962
record("resolveOverloaded.FunProto", alts.length)
19361963
val alts1 = narrowBySize(alts)
19371964
//report.log(i"narrowed by size: ${alts1.map(_.symbol.showDcl)}%, %")
1965+
//println(i"narrowed by size: ${alts1.map(_.symbol.showDcl)}%, %")
19381966
if isDetermined(alts1) then alts1
19391967
else
19401968
record("resolveOverloaded.narrowedBySize", alts1.length)
19411969
val alts2 = narrowByShapes(alts1)
19421970
//report.log(i"narrowed by shape: ${alts2.map(_.symbol.showDcl)}%, %")
1943-
if isDetermined(alts2) then alts2
1971+
//println(i"narrowed by shape: ${alts2.map(_.symbol.showDcl)}%, %")
1972+
if isDetermined(alts2)
1973+
then
1974+
//println("1")
1975+
//println(alts2.map(_.symbol.showDcl))
1976+
alts2
19441977
else
19451978
record("resolveOverloaded.narrowedByShape", alts2.length)
19461979
pretypeArgs(alts2, pt)
1947-
narrowByTrees(alts2, pt.typedArgs(normArg(alts2, _, _)), resultType)
1980+
val res = narrowByTrees(alts2, pt.typedArgs(normArg(alts2, _, _)), resultType)
1981+
//println("2")
1982+
//println(res.map(_.symbol.showDcl))
1983+
res
19481984

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

0 commit comments

Comments
 (0)