ConstraintSystem
struct ConstraintSystem
A collection of constraints over a set of open type variables and a set of unresolved name expressions.
-
The scope in which the goals are solved.
Declaration
Swift
private let scope: AnyScopeID -
The type checker used to query type relations and resolve names.
Declaration
Swift
private var checker: TypeChecker! -
The goals in the system.
Declaration
Swift
private var goals: [Constraint] -
A map from goal its outcome.
Invariant
This array has the same length asthis.goals.Declaration
Swift
private var outcomes: OutcomeMap -
The fresh goals to solve.
Declaration
Swift
private var fresh: [GoalIdentity] -
The goals that are currently stale.
Declaration
Swift
private var stale: [GoalIdentity] -
The root goals that could not be solved.
Declaration
Swift
private var failureRoots: [GoalIdentity] -
A map from open type or term variable to its assignment.
This map is monotonically extended during constraint solving to assign a type or term to each open variable in the constraint system. A system is complete if it can be used to derive a complete substitution map w.r.t. its open variables.
Declaration
Swift
private var substitutions: SubstitutionMap -
A map from name expression to its referred declaration.
This map is monotonically extended during constraint solving to assign a declaration to each unresolved name expression in the constraint system. A system is complete if it can be used to derive a complete name binding map w.r.t. its unresolved name expressions.
Declaration
Swift
private var bindings: [NameExpr.ID : DeclReference] -
A map from call expression to its operands after desugaring and implicit resolution.
Declaration
Swift
private var callOperands: [CallID : [ArgumentResolutionResult]] -
The penalties associated with the constraint system.
This value serves to prune explorations that cannot produce a better solution than one already computed.
Declaration
Swift
private var penalties: Int -
Indicates whether this instance should log a trace.
Declaration
Swift
private let loggingIsEnabled: Bool -
The current indentation level for logging messages.
Declaration
Swift
private var indentation: Int -
Creates an instance for solving the constraints in
obligations, logging a trace of the deduction process ifloggingIsEnabledistrue.Declaration
Swift
init(_ obligations: ProofObligations, logging loggingIsEnabled: Bool) -
Creates an instance copying the state of
other.Declaration
Swift
private init(copying other: `Self`) -
Solves this instance, using
checkerto query type relations and resolve names and returning the best solution found.Declaration
Swift
mutating func solution(querying checker: inout TypeChecker) -> Solution -
Solves this instance and returns the best solution with a score inferior or equal to
self.maxScore, ornilif no such solution can be found.Declaration
Swift
private mutating func solution( notWorseThan maxScore: Solution.Score, querying checker: inout TypeChecker ) -> Solution? -
Eliminates
g, storing the necessary assumptions about its open variables inselfand returning a solution if there are no more goals to solve.Declaration
Swift
private mutating func solve(_ g: GoalIdentity) -> Solution? -
Returns the currently known cost of the solution being computed.
The cost of a solution increases monotonically when a constraint is eliminated.
Declaration
Swift
private func score() -> Solution.Score -
Returns
trueiff the solvinggfailed andgisn’t subordinate.Declaration
Swift
private func isFailureRoot(_ g: GoalIdentity) -> Bool -
Records the outcome
ofor the goalkey.Declaration
Swift
private mutating func setOutcome(_ o: Outcome?, for key: GoalIdentity) -
Creates a solution from the current state.
Requires
There is no fresh goal to solve left.Declaration
Swift
private mutating func formSolution() -> Solution -
Creates an ambiguous solution, reporting the ambiguity with
d.The return value is the intersection of the choices and diagnostics that are identical in each result along with an additional diagnostic describing the ambiguity.
Requires
resultcontains at least two elements.Declaration
Swift
private func formAmbiguousSolution<T>( _ results: Explorations<T>, diagnosedBy d: Diagnostic ) -> Solution -
Determines whether
g.modelconforms tog.conceptand returns:.successif it conforms explicitly,.productif it may conform structurally,.failureif it doesn’t conform, ornilif neither of these outcomes can be be determined yet.Declaration
Swift
private mutating func solve(conformance g: GoalIdentity) -> Outcome? -
Returns a closure diagnosing a failure to solve
goal.Declaration
Swift
private mutating func failureToSolve(_ goal: ConformanceConstraint) -> DiagnoseFailure -
Returns eiteher
.successifg.leftis unifiable withg.rightor.failureotherwise.Declaration
Swift
private mutating func solve(equality g: GoalIdentity) -> Outcome -
Returns a closure diagnosing a failure to solve
goal.Declaration
Swift
private mutating func failureToSolve(_ goal: EqualityConstraint) -> DiagnoseFailure -
Returns
.successifg.leftis subtype ofg.right,.failureif it isn’t,.productifgmust be broken down to smaller goals, ornilif that can’t be determined yet.If the constraint is strict, then
g.leftmust be different thang.right.Declaration
Swift
private mutating func solve(subtyping g: GoalIdentity) -> Outcome? -
Implements of
solve(subtyping:)for twoArrowTypes.Declaration
Swift
private mutating func solve( subtyping g: GoalIdentity, between l: ArrowType, and r: ArrowType ) -> Outcome? -
Implements of
solve(subtyping:)for twoUnionTypes.Declaration
Swift
private mutating func solve( subtyping g: GoalIdentity, between l: UnionType, and r: UnionType ) -> Outcome? -
Returns the outcome of solving
subtype <: suprtypeas a simplification ofgoal.Declaration
Swift
private mutating func simplify( _ goal: SubtypingConstraint, as subtype: AnyType, isSubtypeOf supertype: AnyType ) -> Outcome -
Returns a closure diagnosing a failure to solve
goal.Declaration
Swift
private mutating func failureToSolve(_ goal: SubtypingConstraint) -> DiagnoseFailure -
Returns either
.successif instances ofg.leftcan be passed to a parameterg.right,.failureif they can’t, ornilif neither of these outcomes can be determined yet.Declaration
Swift
private mutating func solve(parameter g: GoalIdentity) -> Outcome? -
Returns either
.successif instances ofgoal.leftcan be passed to a parameterp,.failureif they can’t, ornilif neither of these outcomes can be determined yet.Declaration
Swift
private mutating func solve( autoclosureParameter goal: ParameterConstraint, ofType p: ParameterType ) -> Outcome? -
Returns either
.successifg.subjecthas a memberg.memberNameof typeg.memberType,.failureif it doesn’t,.productifgmust be broken down to smaller goals, ornilif if neither of these outcomes can be determined yet.Declaration
Swift
private mutating func solve(member g: GoalIdentity) -> Outcome? -
Returns either
.successifg.subjectis a tuple type whoseg.elementIndex-th element has typeg.elementType,.failureif it doesn’t,.productifgmust be broken down to smaller goals, ornilif if neither of these outcomes can be determined yet.Declaration
Swift
private mutating func solve(tupleMember g: GoalIdentity) -> Outcome? -
Returns either
.successifg.calleeis a callable type with parametersg.parametersand return typeg.output,.failureif it doesn’t,.productifgmust be broken down to smaller goals, ornilif neither of these outcomes can be determined yet.Declaration
Swift
private mutating func solve(call g: GoalIdentity) -> Outcome? -
Returns a closure diagnosing a failure to solve
gbecause of an invalid callee.Declaration
Swift
private mutating func invalidCallee(_ g: CallConstraint) -> DiagnoseFailure -
Returns how the arguments in
goalmatch the parameters ofcallee.Declaration
Swift
private mutating func match( argumentsOf goal: CallConstraint, parametersOf callee: CallableType ) -> (constraints: [ParameterConstraint], pairings: [ArgumentResolutionResult])? -
Undocumented
Declaration
Swift
private mutating func solve(merging g: GoalIdentity) -> Outcome? -
Solves the remaining goals separately for each choice in
gand returns the best solution.Declaration
Swift
private mutating func solve(disjunction g: GoalIdentity) -> Solution? -
Solves the remaining goals separately for each choice in
gand returns the best solution.Declaration
Swift
private mutating func solve(overload g: GoalIdentity) -> Solution? -
Solves the remaining goals in
selfexploring each choice ingwith a separate constraint systems configured withconfigureSubSystemreturns the best solution of each exploration.Declaration
Swift
private mutating func explore<T: DisjunctiveConstraintProtocol>( _ g: GoalIdentity, configuringSubSystemWith configureSubSystem: (inout Self, T.Predicate) -> [GoalIdentity] ) -> Explorations<T>Parameters
gthe goal whose choices would be explored; must denote a constraint of type
T.checkeran instance used to query type relations and resolve names.
configureSubSystemA closure that prepares a constraint system using one of
g‘s choices and returns the identities of the goals added to that system. -
Returns an outcome indicating that a goal has been broken into given
subordinatesand forwards their diagnostics.Declaration
Swift
private func delegate(to s: [GoalIdentity]) -> Outcome -
Schedules
gto be solved in the future and returns its identity.Declaration
Swift
private mutating func schedule(_ g: Constraint) -> GoalIdentity -
Inserts
ginto the fresh set and returns its identity.Declaration
Swift
private mutating func insert(fresh g: Constraint) -> GoalIdentity -
Inserts
batchinto the fresh set.Declaration
Swift
private mutating func insert<S>(fresh batch: S) -> [GoalIdentity] where S : Sequence, S.Element == any Constraint -
Schedules
gto be solved only once the solver has inferred more information about at least one of its type variables.Requires
gmust involve type variables.Declaration
Swift
private mutating func postpone(_ g: GoalIdentity) -
Returns
trueifflhsandrhscan be unified, updating the substitution table.Type unification consists of finding substitutions that makes
lhsandrhsequal. Both types are visited in lockstep, updatingself.subscritutionsevery time either side is a variable for which no substitution has been made yet. -
Returns
trueifflhsandrhscan be unified. -
Returns
trueifflhsandrhscan be unified. -
Returns
trueifflhsandrhscan be unified. -
Returns
trueifftanduare equal under some substitution of their variables. -
Returns
trueiff the result ofmatches(_:_:)applied on all elements fromtsanduspairwise istrue.Declaration
Swift
private mutating func matches<T: Sequence>( _ ts: T, _ us: T, at p: KeyPath<T.Element, AnyType> ) -> Bool -
Returns
trueifftanduare equal under some substitution of their variables. -
Returns
trueifftanduare equal under some substitution of their variables.Declaration
Swift
private mutating func matches(_ t: CompileTimeValue, _ u: CompileTimeValue) -> Bool -
Extends the type substution table to map
tautosubstitute.Declaration
Swift
private mutating func assume(_ tau: TypeVariable, equals substitute: AnyType) -
Extends the term substution table to map
tautosubstitute.Declaration
Swift
private mutating func assume(_ tau: TermVariable, equals substitute: AnyTerm) -
Refresh stale constraints containing variables that have been assigned.
Declaration
Swift
private mutating func refresh() -
Logs a line of text in the standard output if
self.loggingIsEnabledistrue.Declaration
Swift
private func log(_ line: @autoclosure () -> String) -
Logs
outcomein the standard output ifself.loggingIsEnabledistrue.Declaration
Swift
private func log(outcome: Outcome?) -
Logs
self‘s current state in the standard output ifself.loggingIsEnabledistrue.Declaration
Swift
private func logState()
View on GitHub