Skip to content

Commit

Permalink
refactor: redue usage of uncheckedVariance
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnaldo committed Feb 10, 2025
1 parent 9f24102 commit 6272ae9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
5 changes: 1 addition & 4 deletions src/main/scala/esmeta/util/domain/BSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,18 @@ enum BSet[+T] {

def isTop: Boolean = this == Inf
def isBottom: Boolean = this == Fin(Set())
inline def (that: BSet[T @uncheckedVariance]): Boolean = this <= that
def <=[U >: T](that: BSet[U]): Boolean = (this, that) match
case (_, Inf) => true
case (Inf, _) => false
case (Fin(lset), Fin(rset)) => lset.toSet subsetOf rset.toSet
inline def (that: BSet[T @uncheckedVariance]): BSet[T] = this || that
def ||[U >: T](that: BSet[U]): BSet[U] = (this, that) match
case (Inf, _) | (_, Inf) => Inf
case (Fin(lset), Fin(rset)) => Fin(lset ++ rset)
inline def (that: BSet[T @uncheckedVariance]): BSet[T] = this && that
def &&[U >: T](that: BSet[U]): BSet[U] = (this, that) match
case (Inf, _) => that
case (_, Inf) => this
case (Fin(lset), Fin(rset)) => Fin(lset.toSet intersect rset.toSet)
def contains(value: T @uncheckedVariance): Boolean = this match
def contains[U >: T](value: U): Boolean = this match
case Inf => true
case Fin(set) => set.toSet contains value
def toBSet: BSet[T] = this
Expand Down
8 changes: 2 additions & 6 deletions src/main/scala/esmeta/util/domain/Flat.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package esmeta.util.domain

import esmeta.util.BaseUtils.*
import scala.annotation.unchecked.uncheckedVariance
import Flat.*, BSet.*

/** flat abstraction */
Expand All @@ -17,32 +16,29 @@ enum Flat[+T] {
case Zero => Zero

/** prune operator */
def --(that: Flat[T @uncheckedVariance]): Flat[T] = (this, that) match
def --[U >: T](that: Flat[U]): Flat[U] = (this, that) match
case (Many, One(_)) => Many
case (_, Zero) => this
case (One(l), One(r)) => if (l == r) Zero else this
case (Zero, _) | (_, Many) => Zero

def isTop: Boolean = this == Many
def isBottom: Boolean = this == Zero
inline def (that: Flat[T @uncheckedVariance]): Boolean = this <= that
def <=[U >: T](that: Flat[U]): Boolean = (this, that) match
case (Zero, _) | (_, Many) => true
case (Many, _) | (_, Zero) => false
case (One(l), One(r)) => l == r
inline def (that: Flat[T @uncheckedVariance]): Flat[T] = this || that
def ||[U >: T](that: Flat[U]): Flat[U] = (this, that) match
case (Many, _) | (_, Many) => Many
case (Zero, _) => that
case (_, Zero) => this
case (One(l), One(r)) => if (l == r) this else Many
inline def (that: Flat[T @uncheckedVariance]): Flat[T] = this && that
def &&[U >: T](that: Flat[U]): Flat[U] = (this, that) match
case (Zero, _) | (_, Zero) => Zero
case (Many, _) => that
case (_, Many) => this
case (One(l), One(r)) => if (l == r) this else Zero
def contains(value: T @uncheckedVariance): Boolean = this match
def contains[U >: T](value: U): Boolean = this match
case Many => true
case One(v) => v == value
case Zero => false
Expand Down

0 comments on commit 6272ae9

Please sign in to comment.