Skip to content

Commit f44a1ed

Browse files
committed
Remove isVolatile and DNF methods
These are replaced by the realizibility logic.
1 parent 1441622 commit f44a1ed

File tree

1 file changed

+1
-91
lines changed

1 file changed

+1
-91
lines changed

src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 1 addition & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -342,96 +342,6 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
342342
}
343343
}
344344

345-
/** A type is volatile if its DNF contains an alternative of the form
346-
* {P1, ..., Pn}, {N1, ..., Nk}, where the Pi are parent typerefs and the
347-
* Nj are refinement names, and one the 4 following conditions is met:
348-
*
349-
* 1. At least two of the parents Pi are abstract types.
350-
* 2. One of the parents Pi is an abstract type, and one other type Pj,
351-
* j != i has an abstract member which has the same name as an
352-
* abstract member of the whole type.
353-
* 3. One of the parents Pi is an abstract type, and one of the refinement
354-
* names Nj refers to an abstract member of the whole type.
355-
* 4. One of the parents Pi is an an alias type with a volatile alias
356-
* or an abstract type with a volatile upper bound.
357-
*
358-
* Lazy values are not allowed to have volatile type, as otherwise
359-
* unsoundness can result.
360-
*/
361-
final def isVolatile(tp: Type): Boolean = {
362-
363-
/** Pre-filter to avoid expensive DNF computation
364-
* If needsChecking returns false it is guaranteed that
365-
* DNF does not contain intersections, or abstract types with upper
366-
* bounds that themselves need checking.
367-
*/
368-
def needsChecking(tp: Type, isPart: Boolean): Boolean = tp match {
369-
case tp: TypeRef =>
370-
tp.info match {
371-
case TypeAlias(alias) =>
372-
needsChecking(alias, isPart)
373-
case TypeBounds(lo, hi) =>
374-
isPart || tp.controlled(isVolatile(hi))
375-
case _ => false
376-
}
377-
case tp: RefinedType =>
378-
needsChecking(tp.parent, true)
379-
case tp: TypeProxy =>
380-
needsChecking(tp.underlying, isPart)
381-
case tp: AndType =>
382-
true
383-
case tp: OrType =>
384-
isPart || needsChecking(tp.tp1, isPart) && needsChecking(tp.tp2, isPart)
385-
case _ =>
386-
false
387-
}
388-
389-
needsChecking(tp, false) && {
390-
DNF(tp) forall { case (parents, refinedNames) =>
391-
val absParents = parents filter (_.symbol is Deferred)
392-
absParents.nonEmpty && {
393-
absParents.lengthCompare(2) >= 0 || {
394-
val ap = absParents.head
395-
((parents exists (p =>
396-
(p ne ap)
397-
|| p.memberNames(abstractTypeNameFilter, tp).nonEmpty
398-
|| p.memberNames(abstractTermNameFilter, tp).nonEmpty))
399-
|| (refinedNames & tp.memberNames(abstractTypeNameFilter, tp)).nonEmpty
400-
|| (refinedNames & tp.memberNames(abstractTermNameFilter, tp)).nonEmpty
401-
|| isVolatile(ap))
402-
}
403-
}
404-
}
405-
}
406-
}
407-
408-
/** The disjunctive normal form of this type.
409-
* This collects a set of alternatives, each alternative consisting
410-
* of a set of typerefs and a set of refinement names. Both sets are represented
411-
* as lists, to obtain a deterministic order. Collected are
412-
* all type refs reachable by following aliases and type proxies, and
413-
* collecting the elements of conjunctions (&) and disjunctions (|).
414-
* The set of refinement names in each alternative
415-
* are the set of names in refinement types encountered during the collection.
416-
*/
417-
final def DNF(tp: Type): List[(List[TypeRef], Set[Name])] = ctx.traceIndented(s"DNF($this)", checks) {
418-
tp.dealias match {
419-
case tp: TypeRef =>
420-
(tp :: Nil, Set[Name]()) :: Nil
421-
case RefinedType(parent, name) =>
422-
for ((ps, rs) <- DNF(parent)) yield (ps, rs + name)
423-
case tp: TypeProxy =>
424-
DNF(tp.underlying)
425-
case AndType(l, r) =>
426-
for ((lps, lrs) <- DNF(l); (rps, rrs) <- DNF(r))
427-
yield (lps | rps, lrs | rrs)
428-
case OrType(l, r) =>
429-
DNF(l) | DNF(r)
430-
case tp =>
431-
emptyDNF
432-
}
433-
}
434-
435345
/** The realizability status of given type `tp`*/
436346
def realizability(tp: Type): Realizability = tp.dealias match {
437347
case tp: TermRef =>
@@ -452,7 +362,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
452362
else boundsRealizability(tp)
453363
}
454364

455-
/** `Realizable` is `tp` has good bounds, a `HasProblemBounds` instance
365+
/** `Realizable` if `tp` has good bounds, a `HasProblemBounds` instance
456366
* pointing to a bad bounds member otherwise.
457367
*/
458368
def boundsRealizability(tp: Type)(implicit ctx: Context) = {

0 commit comments

Comments
 (0)