Skip to content

Commit f090fac

Browse files
committed
Split out immutable GadtConstraint
1 parent 805dda8 commit f090fac

10 files changed

+213
-215
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ abstract class Constraint extends Showable {
7171
*/
7272
def nonParamBounds(param: TypeParamRef)(using Context): TypeBounds
7373

74+
/** The current bounds of type parameter `param` */
75+
def bounds(param: TypeParamRef)(using Context): TypeBounds
76+
7477
/** A new constraint which is derived from this constraint by adding
7578
* entries for all type parameters of `poly`.
7679
* @param tvars A list of type variables associated with the params,

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -749,16 +749,7 @@ trait ConstraintHandling {
749749
}
750750

751751
/** The current bounds of type parameter `param` */
752-
def bounds(param: TypeParamRef)(using Context): TypeBounds = {
753-
val e = constraint.entry(param)
754-
if (e.exists) e.bounds
755-
else {
756-
// TODO: should we change the type of paramInfos to nullable?
757-
val pinfos: List[param.binder.PInfo] | Null = param.binder.paramInfos
758-
if (pinfos != null) pinfos(param.paramNum) // pinfos == null happens in pos/i536.scala
759-
else TypeBounds.empty
760-
}
761-
}
752+
def bounds(param: TypeParamRef)(using Context): TypeBounds = constraint.bounds(param)
762753

763754
/** Add type lambda `tl`, possibly with type variables `tvars`, to current constraint
764755
* and propagate all bounds.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ object Contexts {
141141
def tree: Tree[?]
142142
def scope: Scope
143143
def typerState: TyperState
144-
def gadt: GadtConstraint
144+
def gadt: GadtConstraintHandling
145145
def searchHistory: SearchHistory
146146
def source: SourceFile
147147

@@ -539,8 +539,8 @@ object Contexts {
539539
private var _typerState: TyperState = uninitialized
540540
final def typerState: TyperState = _typerState
541541

542-
private var _gadt: GadtConstraint = uninitialized
543-
final def gadt: GadtConstraint = _gadt
542+
private var _gadt: GadtConstraintHandling = uninitialized
543+
final def gadt: GadtConstraintHandling = _gadt
544544

545545
private var _searchHistory: SearchHistory = uninitialized
546546
final def searchHistory: SearchHistory = _searchHistory
@@ -622,7 +622,7 @@ object Contexts {
622622
this._scope = typer.scope
623623
setTypeAssigner(typer)
624624

625-
def setGadt(gadt: GadtConstraint): this.type =
625+
def setGadt(gadt: GadtConstraintHandling): this.type =
626626
util.Stats.record("Context.setGadt")
627627
this._gadt = gadt
628628
this
@@ -719,7 +719,7 @@ object Contexts {
719719
.updated(notNullInfosLoc, Nil)
720720
.updated(compilationUnitLoc, NoCompilationUnit)
721721
c._searchHistory = new SearchRoot
722-
c._gadt = GadtConstraint.empty
722+
c._gadt = GadtConstraintHandling(GadtConstraint.empty)
723723
c
724724
end FreshContext
725725

0 commit comments

Comments
 (0)