Skip to content

Commit 92c5dad

Browse files
dwijnandKordyjan
authored andcommitted
Split out immutable GadtConstraint
1 parent 7ee369f commit 92c5dad

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

@@ -541,8 +541,8 @@ object Contexts {
541541
private var _typerState: TyperState = uninitialized
542542
final def typerState: TyperState = _typerState
543543

544-
private var _gadt: GadtConstraint = uninitialized
545-
final def gadt: GadtConstraint = _gadt
544+
private var _gadt: GadtConstraintHandling = uninitialized
545+
final def gadt: GadtConstraintHandling = _gadt
546546

547547
private var _searchHistory: SearchHistory = uninitialized
548548
final def searchHistory: SearchHistory = _searchHistory
@@ -624,7 +624,7 @@ object Contexts {
624624
this._scope = typer.scope
625625
setTypeAssigner(typer)
626626

627-
def setGadt(gadt: GadtConstraint): this.type =
627+
def setGadt(gadt: GadtConstraintHandling): this.type =
628628
util.Stats.record("Context.setGadt")
629629
this._gadt = gadt
630630
this
@@ -721,7 +721,7 @@ object Contexts {
721721
.updated(notNullInfosLoc, Nil)
722722
.updated(compilationUnitLoc, NoCompilationUnit)
723723
c._searchHistory = new SearchRoot
724-
c._gadt = GadtConstraint.empty
724+
c._gadt = GadtConstraintHandling(GadtConstraint.empty)
725725
c
726726
end FreshContext
727727

0 commit comments

Comments
 (0)