@@ -160,44 +160,45 @@ type TcValF = (ValRef -> ValUseFlag -> TType list -> range -> Expr * TType)
160160
161161type ConstraintSolverState =
162162 {
163- g: TcGlobals ;
164- amap: Import .ImportMap ;
165- InfoReader : InfoReader ;
163+ g: TcGlobals
164+ amap: Import .ImportMap
165+ InfoReader : InfoReader
166166 TcVal : TcValF
167167 /// This table stores all unsolved, ungeneralized trait constraints, indexed by free type variable.
168168 /// That is, there will be one entry in this table for each free type variable in
169169 /// each outstanding, unsolved, ungeneralized trait constraint. Constraints are removed from the table and resolved
170170 /// each time a solution to an index variable is found.
171- mutable ExtraCxs: HashMultiMap < Stamp , ( TraitConstraintInfo * range )>;
171+ mutable ExtraCxs: HashMultiMap < Stamp , ( TraitConstraintInfo * range )>
172172 }
173173
174174 static member New ( g , amap , infoReader , tcVal ) =
175- { g= g; amap= amap;
175+ { g= g
176+ amap= amap
176177 ExtraCxs= HashMultiMap( 10 , HashIdentity.Structural)
177178 InfoReader= infoReader
178- TcVal = tcVal } ;
179+ TcVal = tcVal }
179180
180181
181182type ConstraintSolverEnv =
182183 {
183- SolverState: ConstraintSolverState ;
184+ SolverState: ConstraintSolverState
184185 eContextInfo: ContextInfo
185186 MatchingOnly : bool
186- m: range ;
187- EquivEnv: TypeEquivEnv ;
187+ m: range
188+ EquivEnv: TypeEquivEnv
188189 DisplayEnv : DisplayEnv
189190 }
190191 member csenv.InfoReader = csenv.SolverState.InfoReader
191192 member csenv.g = csenv.SolverState.g
192193 member csenv.amap = csenv.SolverState.amap
193194
194195let MakeConstraintSolverEnv contextInfo css m denv =
195- { SolverState= css;
196- m= m;
196+ { SolverState= css
197+ m= m
197198 eContextInfo = contextInfo
198199 // Indicates that when unifiying ty1 = ty2, only type variables in ty1 may be solved
199- MatchingOnly= false ;
200- EquivEnv= TypeEquivEnv.Empty;
200+ MatchingOnly= false
201+ EquivEnv= TypeEquivEnv.Empty
201202 DisplayEnv = denv }
202203
203204
@@ -303,9 +304,10 @@ let BakedInTraitConstraintNames =
303304// Run the constraint solver with undo (used during method overload resolution)
304305
305306type Trace =
306- | Trace of ( unit -> unit ) list ref
307- static member New () = Trace ( ref [])
308- member t.Undo () = let ( Trace trace ) = t in List.iter ( fun a -> a ()) ! trace
307+ { mutable actions: ( unit -> unit ) list }
308+ static member New () = { actions = [] }
309+ member t.Undo () = List.iter ( fun a -> a ()) t.actions
310+ member t.Push f = t.actions <- f :: t.actions
309311
310312type OptionalTrace =
311313 | NoTrace
@@ -417,7 +419,7 @@ let rec TransactStaticReq (csenv:ConstraintSolverEnv) trace (tpr:Typar) req =
417419 let orig = tpr.StaticReq
418420 match trace with
419421 | NoTrace -> ()
420- | WithTrace ( Trace actions ) -> actions := ( fun () -> tpr.SetStaticReq orig) :: ! actions
422+ | WithTrace trace -> trace.Push ( fun () -> tpr.SetStaticReq orig)
421423 tpr.SetStaticReq req;
422424 CompleteD
423425
@@ -446,7 +448,7 @@ let rec TransactDynamicReq trace (tpr:Typar) req =
446448 let orig = tpr.DynamicReq
447449 match trace with
448450 | NoTrace -> ()
449- | WithTrace ( Trace actions ) -> actions := ( fun () -> tpr.SetDynamicReq orig) :: ! actions
451+ | WithTrace trace -> trace.Push ( fun () -> tpr.SetDynamicReq orig)
450452 tpr.SetDynamicReq req;
451453 CompleteD
452454
@@ -673,7 +675,7 @@ let rec SolveTyparEqualsTyp (csenv:ConstraintSolverEnv) ndeep m2 trace ty1 ty =
673675 let tpdata = r.Data
674676 match trace with
675677 | NoTrace -> ()
676- | WithTrace ( Trace actions ) -> actions := ( fun () -> tpdata.typar_ solution <- None) :: ! actions
678+ | WithTrace trace -> trace.Push ( fun () -> tpdata.typar_ solution <- None)
677679 tpdata.typar_ solution <- Some ty;
678680
679681 (* dprintf "setting typar %d to type %s at %a\n" r.Stamp ((DebugPrint.showType ty)) outputRange m; *)
@@ -1343,7 +1345,7 @@ and TransactMemberConstraintSolution traitInfo trace sln =
13431345 traitInfo.Solution <- Some sln
13441346 match trace with
13451347 | NoTrace -> ()
1346- | WithTrace ( Trace actions ) -> actions := ( fun () -> traitInfo.Solution <- prev) :: ! actions
1348+ | WithTrace trace -> trace.Push ( fun () -> traitInfo.Solution <- prev)
13471349
13481350/// Only consider overload resolution if canonicalizing or all the types are now nominal.
13491351/// That is, don't perform resolution if more nominal information may influence the set of available overloads
@@ -1410,7 +1412,7 @@ and SolveRelevantMemberConstraintsForTypar (csenv:ConstraintSolverEnv) ndeep per
14101412
14111413 match trace with
14121414 | NoTrace -> ()
1413- | WithTrace ( Trace actions ) -> actions := ( fun () -> cxs |> List.iter ( fun cx -> cxst.Add( tpn, cx))) :: ! actions
1415+ | WithTrace trace -> trace.Push ( fun () -> cxs |> List.iter ( fun cx -> cxst.Add( tpn, cx)))
14141416
14151417 cxs |> AtLeastOneD ( fun ( traitInfo , m2 ) ->
14161418 let csenv = { csenv with m = m2 }
@@ -1437,7 +1439,7 @@ and AddMemberConstraint (csenv:ConstraintSolverEnv) ndeep m2 trace traitInfo sup
14371439 if not ( cxs |> List.exists ( fun ( traitInfo2 , _ ) -> traitsAEquiv g aenv traitInfo traitInfo2)) then
14381440 match trace with
14391441 | NoTrace -> ()
1440- | WithTrace ( Trace actions ) -> actions := ( fun () -> csenv.SolverState.ExtraCxs.Remove tpn) :: ! actions
1442+ | WithTrace trace -> trace.Push ( fun () -> csenv.SolverState.ExtraCxs.Remove tpn)
14411443 csenv.SolverState.ExtraCxs.Add ( tpn,( traitInfo, m2))
14421444 );
14431445
@@ -1613,7 +1615,7 @@ and AddConstraint (csenv:ConstraintSolverEnv) ndeep m2 trace tp newConstraint =
16131615 let orig = d.typar_ constraints
16141616 begin match trace with
16151617 | NoTrace -> ()
1616- | WithTrace ( Trace actions ) -> actions := ( fun () -> d.typar_ constraints <- orig) :: ! actions
1618+ | WithTrace trace -> trace.Push ( fun () -> d.typar_ constraints <- orig)
16171619 end ;
16181620 d.typar_ constraints <- newConstraints;
16191621
@@ -2404,7 +2406,7 @@ let EliminateConstraintsForGeneralizedTypars csenv trace (generalizedTypars: Typ
24042406 cxst.Remove tpn;
24052407 match trace with
24062408 | NoTrace -> ()
2407- | WithTrace ( Trace actions ) -> actions := ( fun () -> ( csenv.SolverState.ExtraCxs.Add ( tpn, cx))) :: ! actions )
2409+ | WithTrace trace -> trace.Push ( fun () -> ( csenv.SolverState.ExtraCxs.Add ( tpn, cx))))
24082410 )
24092411
24102412
0 commit comments