Skip to content

Commit d8c980f

Browse files
committed
Rename & to meet and update doc comments
1 parent e82756a commit d8c980f

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

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

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -366,29 +366,32 @@ object Denotations {
366366
*
367367
* NoDenotations are dropped. MultiDenotations are handled by merging
368368
* parts with same signatures. SingleDenotations with equal signatures
369-
* are joined as follows:
369+
* are joined by following this sequence of steps:
370370
*
371-
* In a first step, consider only those denotations which have symbols
372-
* that are accessible from prefix `pre`.
371+
* 1. If exactly one the denotations has an inaccessible symbol, pick the other one.
372+
* 2. Otherwise, if one of the infos overrides the other one, and the associated
373+
* symbol does not score strictly lower than the other one,
374+
* pick the associated denotation.
375+
* 3. Otherwise, if the two infos can be combined with `infoMeet`, pick that as
376+
* result info, and pick the symbol that scores higher as result symbol,
377+
* or pick `sym2` as a tie breaker. The picked info and symbol are combined
378+
* in a JointDenotation.
379+
* 4. Otherwise, if one of the two symbols scores strongly higher than the
380+
* other one, pick the associated denotation.
381+
* 5. Otherwise return a multi-denotation consisting of both denotations.
373382
*
374-
* If there are several such denotations, try to pick one by applying the following
375-
* three precedence rules in decreasing order of priority:
383+
* Symbol scoring is determined according to the following ranking
384+
* where earlier criteria trump later ones. Cases marked with (*)
385+
* give a strong score advantage, the others a weak one.
376386
*
377-
* 1. Prefer denotations with more specific infos.
378-
* 2. If infos are equally specific, prefer denotations with concrete symbols over denotations
379-
* with abstract symbols.
380-
* 3. If infos are equally specific and symbols are equally concrete,
381-
* prefer denotations with symbols defined in subclasses
382-
* over denotations with symbols defined in proper superclasses.
383-
*
384-
* If there is exactly one (preferred) accessible denotation, return it.
385-
*
386-
* If there is no preferred accessible denotation, return a JointRefDenotation
387-
* with one of the operand symbols (unspecified which one), and an info which
388-
* is the intersection using `&` or `safe_&` if `safeIntersection` is true)
389-
* of the infos of the operand denotations.
387+
* 1. The symbol exists, and the other one does not. (*)
388+
* 2. The symbol is concrete, and the other one is deferred
389+
* 3. The symbol appears before the other in the linearization of `pre`
390+
* 4. The symbol's visibility is strictly greater than the other one's.
391+
* 5. The symbol is not a bridge, but the other one is. (*)
392+
* 6. The symbol is a method, but the other one is not. (*)
390393
*/
391-
def & (that: Denotation, pre: Type, safeIntersection: Boolean = false)(implicit ctx: Context): Denotation = {
394+
def meet(that: Denotation, pre: Type, safeIntersection: Boolean = false)(implicit ctx: Context): Denotation = {
392395
/** Try to merge denot1 and denot2 without adding a new signature. */
393396
def mergeDenot(denot1: Denotation, denot2: SingleDenotation): Denotation = denot1 match {
394397
case denot1 @ MultiDenotation(denot11, denot12) =>
@@ -412,7 +415,7 @@ object Denotations {
412415
val sym1 = denot1.symbol
413416
val sym2 = denot2.symbol
414417

415-
/** Does `sym1` come before `sym2` in the linearization of `pre`? */
418+
/** Does `owner1` come before `owner2` in the linearization of `pre`? */
416419
def linearScore(owner1: Symbol, owner2: Symbol): Int =
417420

418421
def searchBaseClasses(bcs: List[ClassSymbol]): Int = bcs match
@@ -441,6 +444,10 @@ object Denotations {
441444
if hidden1 && !hidden2 then denot2
442445
else if hidden2 && !hidden1 then denot1
443446
else
447+
// The score that determines which symbol to pick for the result denotation.
448+
// A value > 0 means pick `sym1`, < 0 means pick `sym2`.
449+
// A value of +/- 2 means pick one of the denotations as a tie-breaker
450+
// if a common info does not exist.
444451
val symScore: Int =
445452
if !sym1.exists then -2
446453
else if !sym2.exists then 2
@@ -488,7 +495,7 @@ object Denotations {
488495
val r = mergeDenot(this, that)
489496
if (r.exists) r else MultiDenotation(this, that)
490497
case that @ MultiDenotation(denot1, denot2) =>
491-
this & (denot1, pre) & (denot2, pre)
498+
this.meet(denot1, pre).meet(denot2, pre)
492499
}
493500
}
494501

@@ -1106,7 +1113,7 @@ object Denotations {
11061113
final case class DenotUnion(denot1: PreDenotation, denot2: PreDenotation) extends MultiPreDenotation {
11071114
def exists: Boolean = true
11081115
def toDenot(pre: Type)(implicit ctx: Context): Denotation =
1109-
denot1.toDenot(pre).&(denot2.toDenot(pre), pre)
1116+
denot1.toDenot(pre).meet(denot2.toDenot(pre), pre)
11101117
def containsSym(sym: Symbol): Boolean =
11111118
(denot1 containsSym sym) || (denot2 containsSym sym)
11121119
type AsSeenFromResult = PreDenotation

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ object Types {
675675
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, jointInfo)
676676
}
677677
else
678-
val joint = pdenot & (
678+
val joint = pdenot.meet(
679679
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId), pre),
680680
pre,
681681
safeIntersection = ctx.base.pendingMemberSearches.contains(name))
@@ -726,7 +726,7 @@ object Types {
726726
}
727727

728728
def goAnd(l: Type, r: Type) =
729-
go(l) & (go(r), pre, safeIntersection = ctx.base.pendingMemberSearches.contains(name))
729+
go(l).meet(go(r), pre, safeIntersection = ctx.base.pendingMemberSearches.contains(name))
730730

731731
def goOr(tp: OrType) = tp match {
732732
case OrUncheckedNull(tp1) =>

0 commit comments

Comments
 (0)