Skip to content

Commit

Permalink
Split out immutable GadtConstraint
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Dec 30, 2022
1 parent 805dda8 commit f090fac
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 215 deletions.
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Constraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ abstract class Constraint extends Showable {
*/
def nonParamBounds(param: TypeParamRef)(using Context): TypeBounds

/** The current bounds of type parameter `param` */
def bounds(param: TypeParamRef)(using Context): TypeBounds

/** A new constraint which is derived from this constraint by adding
* entries for all type parameters of `poly`.
* @param tvars A list of type variables associated with the params,
Expand Down
11 changes: 1 addition & 10 deletions compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -749,16 +749,7 @@ trait ConstraintHandling {
}

/** The current bounds of type parameter `param` */
def bounds(param: TypeParamRef)(using Context): TypeBounds = {
val e = constraint.entry(param)
if (e.exists) e.bounds
else {
// TODO: should we change the type of paramInfos to nullable?
val pinfos: List[param.binder.PInfo] | Null = param.binder.paramInfos
if (pinfos != null) pinfos(param.paramNum) // pinfos == null happens in pos/i536.scala
else TypeBounds.empty
}
}
def bounds(param: TypeParamRef)(using Context): TypeBounds = constraint.bounds(param)

/** Add type lambda `tl`, possibly with type variables `tvars`, to current constraint
* and propagate all bounds.
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ object Contexts {
def tree: Tree[?]
def scope: Scope
def typerState: TyperState
def gadt: GadtConstraint
def gadt: GadtConstraintHandling
def searchHistory: SearchHistory
def source: SourceFile

Expand Down Expand Up @@ -539,8 +539,8 @@ object Contexts {
private var _typerState: TyperState = uninitialized
final def typerState: TyperState = _typerState

private var _gadt: GadtConstraint = uninitialized
final def gadt: GadtConstraint = _gadt
private var _gadt: GadtConstraintHandling = uninitialized
final def gadt: GadtConstraintHandling = _gadt

private var _searchHistory: SearchHistory = uninitialized
final def searchHistory: SearchHistory = _searchHistory
Expand Down Expand Up @@ -622,7 +622,7 @@ object Contexts {
this._scope = typer.scope
setTypeAssigner(typer)

def setGadt(gadt: GadtConstraint): this.type =
def setGadt(gadt: GadtConstraintHandling): this.type =
util.Stats.record("Context.setGadt")
this._gadt = gadt
this
Expand Down Expand Up @@ -719,7 +719,7 @@ object Contexts {
.updated(notNullInfosLoc, Nil)
.updated(compilationUnitLoc, NoCompilationUnit)
c._searchHistory = new SearchRoot
c._gadt = GadtConstraint.empty
c._gadt = GadtConstraintHandling(GadtConstraint.empty)
c
end FreshContext

Expand Down
Loading

0 comments on commit f090fac

Please sign in to comment.