Skip to content

Commit 419ea48

Browse files
dsymebaronfel
authored andcommitted
debug formatting (#7196)
* debug formatting * whitespace * whitespace * Update DetupleArgs.fs
1 parent ef99bf4 commit 419ea48

File tree

11 files changed

+153
-37
lines changed

11 files changed

+153
-37
lines changed

src/absil/ilreflect.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ type cenv =
327327
generatePdb: bool
328328
resolveAssemblyRef: (ILAssemblyRef -> Choice<string, System.Reflection.Assembly> option) }
329329

330+
override x.ToString() = "<cenv>"
331+
330332
/// Convert an Abstract IL type reference to Reflection.Emit System.Type value.
331333
// This ought to be an adequate substitute for this whole function, but it needs
332334
// to be thoroughly tested.

src/absil/ilwrite.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ type cenv =
605605

606606
member cenv.GetCode() = cenv.codeChunks.Close()
607607

608+
override x.ToString() = "<cenv>"
608609

609610
let FindOrAddSharedRow (cenv: cenv) tbl x = cenv.GetTable(tbl).FindOrAddSharedEntry x
610611

src/fsharp/ConstraintSolver.fs

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ let compgenId = mkSynId range0 unassignedTyparName
6464
let NewCompGenTypar (kind, rigid, staticReq, dynamicReq, error) =
6565
NewTypar(kind, rigid, Typar(compgenId, staticReq, true), error, dynamicReq, [], false, false)
6666

67-
let anon_id m = mkSynId m unassignedTyparName
67+
let AnonTyparId m = mkSynId m unassignedTyparName
6868

6969
let NewAnonTypar (kind, m, rigid, var, dyn) =
70-
NewTypar (kind, rigid, Typar(anon_id m, var, true), false, dyn, [], false, false)
70+
NewTypar (kind, rigid, Typar(AnonTyparId m, var, true), false, dyn, [], false, false)
7171

7272
let NewNamedInferenceMeasureVar (_m, rigid, var, id) =
7373
NewTypar(TyparKind.Measure, rigid, Typar(id, var, false), false, TyparDynamicReq.No, [], false, false)
@@ -104,6 +104,7 @@ let FreshenAndFixupTypars m rigid fctps tinst tpsorig =
104104
tps, renaming, tinst
105105

106106
let FreshenTypeInst m tpsorig = FreshenAndFixupTypars m TyparRigidity.Flexible [] [] tpsorig
107+
107108
let FreshMethInst m fctps tinst tpsorig = FreshenAndFixupTypars m TyparRigidity.Flexible fctps tinst tpsorig
108109

109110
let FreshenTypars m tpsorig =
@@ -126,62 +127,95 @@ let FreshenMethInfo m (minfo: MethInfo) =
126127
[<RequireQualifiedAccess>]
127128
/// Information about the context of a type equation.
128129
type ContextInfo =
130+
129131
/// No context was given.
130132
| NoContext
133+
131134
/// The type equation comes from an IF expression.
132135
| IfExpression of range
136+
133137
/// The type equation comes from an omitted else branch.
134138
| OmittedElseBranch of range
139+
135140
/// The type equation comes from a type check of the result of an else branch.
136141
| ElseBranchResult of range
142+
137143
/// The type equation comes from the verification of record fields.
138144
| RecordFields
145+
139146
/// The type equation comes from the verification of a tuple in record fields.
140147
| TupleInRecordFields
148+
141149
/// The type equation comes from a list or array constructor
142150
| CollectionElement of bool * range
151+
143152
/// The type equation comes from a return in a computation expression.
153+
144154
| ReturnInComputationExpression
155+
145156
/// The type equation comes from a yield in a computation expression.
146157
| YieldInComputationExpression
158+
147159
/// The type equation comes from a runtime type test.
148160
| RuntimeTypeTest of bool
161+
149162
/// The type equation comes from an downcast where a upcast could be used.
150163
| DowncastUsedInsteadOfUpcast of bool
164+
151165
/// The type equation comes from a return type of a pattern match clause (not the first clause).
152166
| FollowingPatternMatchClause of range
167+
153168
/// The type equation comes from a pattern match guard.
154169
| PatternMatchGuard of range
170+
155171
/// The type equation comes from a sequence expression.
156172
| SequenceExpression of TType
157173

158-
exception ConstraintSolverTupleDiffLengths of displayEnv: DisplayEnv * TType list * TType list * range * range
159-
exception ConstraintSolverInfiniteTypes of displayEnv: DisplayEnv * contextInfo: ContextInfo * TType * TType * range * range
160-
exception ConstraintSolverTypesNotInEqualityRelation of displayEnv: DisplayEnv * TType * TType * range * range * ContextInfo
174+
exception ConstraintSolverTupleDiffLengths of displayEnv: DisplayEnv * TType list * TType list * range * range
175+
176+
exception ConstraintSolverInfiniteTypes of displayEnv: DisplayEnv * contextInfo: ContextInfo * TType * TType * range * range
177+
178+
exception ConstraintSolverTypesNotInEqualityRelation of displayEnv: DisplayEnv * TType * TType * range * range * ContextInfo
179+
161180
exception ConstraintSolverTypesNotInSubsumptionRelation of displayEnv: DisplayEnv * TType * TType * range * range
162-
exception ConstraintSolverMissingConstraint of displayEnv: DisplayEnv * Tast.Typar * Tast.TyparConstraint * range * range
163-
exception ConstraintSolverError of string * range * range
164-
exception ConstraintSolverRelatedInformation of string option * range * exn
165181

166-
exception ErrorFromApplyingDefault of tcGlobals: TcGlobals * displayEnv: DisplayEnv * Tast.Typar * TType * exn * range
167-
exception ErrorFromAddingTypeEquation of tcGlobals: TcGlobals * displayEnv: DisplayEnv * TType * TType * exn * range
182+
exception ConstraintSolverMissingConstraint of displayEnv: DisplayEnv * Tast.Typar * Tast.TyparConstraint * range * range
183+
184+
exception ConstraintSolverError of string * range * range
185+
186+
exception ConstraintSolverRelatedInformation of string option * range * exn
187+
188+
exception ErrorFromApplyingDefault of tcGlobals: TcGlobals * displayEnv: DisplayEnv * Tast.Typar * TType * exn * range
189+
190+
exception ErrorFromAddingTypeEquation of tcGlobals: TcGlobals * displayEnv: DisplayEnv * TType * TType * exn * range
191+
168192
exception ErrorsFromAddingSubsumptionConstraint of tcGlobals: TcGlobals * displayEnv: DisplayEnv * TType * TType * exn * ContextInfo * range
169-
exception ErrorFromAddingConstraint of displayEnv: DisplayEnv * exn * range
170-
exception PossibleOverload of displayEnv: DisplayEnv * string * exn * range
171-
exception UnresolvedOverloading of displayEnv: DisplayEnv * exn list * string * range
172-
exception UnresolvedConversionOperator of displayEnv: DisplayEnv * TType * TType * range
193+
194+
exception ErrorFromAddingConstraint of displayEnv: DisplayEnv * exn * range
195+
196+
exception PossibleOverload of displayEnv: DisplayEnv * string * exn * range
197+
198+
exception UnresolvedOverloading of displayEnv: DisplayEnv * exn list * string * range
199+
200+
exception UnresolvedConversionOperator of displayEnv: DisplayEnv * TType * TType * range
173201

174202
let GetPossibleOverloads amap m denv (calledMethGroup: (CalledMeth<_> * exn) list) =
175-
calledMethGroup |> List.map (fun (cmeth, e) -> PossibleOverload(denv, NicePrint.stringOfMethInfo amap m denv cmeth.Method, e, m))
203+
calledMethGroup |> List.map (fun (cmeth, e) ->
204+
PossibleOverload(denv, NicePrint.stringOfMethInfo amap m denv cmeth.Method, e, m))
176205

177206
type TcValF = (ValRef -> ValUseFlag -> TType list -> range -> Expr * TType)
178207

179208
type ConstraintSolverState =
180209
{
181210
g: TcGlobals
211+
182212
amap: Import.ImportMap
213+
183214
InfoReader: InfoReader
215+
216+
/// The function used to freshen values we encounter during trait constraint solving
184217
TcVal: TcValF
218+
185219
/// This table stores all unsolved, ungeneralized trait constraints, indexed by free type variable.
186220
/// That is, there will be one entry in this table for each free type variable in
187221
/// each outstanding, unsolved, ungeneralized trait constraint. Constraints are removed from the table and resolved
@@ -196,20 +230,29 @@ type ConstraintSolverState =
196230
InfoReader = infoReader
197231
TcVal = tcVal }
198232

199-
200233
type ConstraintSolverEnv =
201234
{
202235
SolverState: ConstraintSolverState
236+
203237
eContextInfo: ContextInfo
238+
204239
MatchingOnly: bool
240+
205241
m: range
242+
206243
EquivEnv: TypeEquivEnv
244+
207245
DisplayEnv: DisplayEnv
208246
}
247+
209248
member csenv.InfoReader = csenv.SolverState.InfoReader
249+
210250
member csenv.g = csenv.SolverState.g
251+
211252
member csenv.amap = csenv.SolverState.amap
212253

254+
override csenv.ToString() = "<ConstraintSolverEnv> @ " + csenv.m.ToString()
255+
213256
let MakeConstraintSolverEnv contextInfo css m denv =
214257
{ SolverState = css
215258
m = m
@@ -219,11 +262,6 @@ let MakeConstraintSolverEnv contextInfo css m denv =
219262
EquivEnv = TypeEquivEnv.Empty
220263
DisplayEnv = denv }
221264

222-
223-
//-------------------------------------------------------------------------
224-
// Occurs check
225-
//-------------------------------------------------------------------------
226-
227265
/// Check whether a type variable occurs in the r.h.s. of a type, e.g. to catch
228266
/// infinite equations such as
229267
/// 'a = list<'a>
@@ -287,9 +325,13 @@ let isDecimalTy g ty =
287325
typeEquivAux EraseMeasures g g.decimal_ty ty
288326

289327
let IsNonDecimalNumericOrIntegralEnumType g ty = isIntegerOrIntegerEnumTy g ty || isFpTy g ty
328+
290329
let IsNumericOrIntegralEnumType g ty = IsNonDecimalNumericOrIntegralEnumType g ty || isDecimalTy g ty
330+
291331
let IsNonDecimalNumericType g ty = isIntegerTy g ty || isFpTy g ty
332+
292333
let IsNumericType g ty = IsNonDecimalNumericType g ty || isDecimalTy g ty
334+
293335
let IsRelationalType g ty = IsNumericType g ty || isStringTy g ty || isCharTy g ty || isBoolTy g ty
294336

295337
// Get measure of type, float<_> or float32<_> or decimal<_> but not float=float<1> or float32=float32<1> or decimal=decimal<1>
@@ -386,8 +428,11 @@ let ShowAccessDomain ad =
386428
// Solve
387429

388430
exception NonRigidTypar of displayEnv: DisplayEnv * string option * range * TType * TType * range
431+
389432
exception LocallyAbortOperationThatFailsToResolveOverload
433+
390434
exception LocallyAbortOperationThatLosesAbbrevs
435+
391436
let localAbortD = ErrorD LocallyAbortOperationThatLosesAbbrevs
392437

393438
/// Return true if we would rather unify this variable v1 := v2 than vice versa
@@ -652,7 +697,6 @@ let NormalizeExponentsInTypeScheme uvars ty =
652697
SubstMeasure v (Measure.RationalPower (Measure.Var v', DivRational OneRational expGcd))
653698
v')
654699

655-
656700
// We normalize unit-of-measure-polymorphic type schemes. There
657701
// are three reasons for doing this:
658702
// (1) to present concise and consistent type schemes to the programmer
@@ -732,8 +776,6 @@ let rec SolveTyparEqualsType (csenv: ConstraintSolverEnv) ndeep m2 (trace: Optio
732776
// Record a entry in the undo trace if one is provided
733777
trace.Exec (fun () -> r.typar_solution <- Some ty) (fun () -> r.typar_solution <- None)
734778

735-
(* dprintf "setting typar %d to type %s at %a\n" r.Stamp ((DebugPrint.showType ty)) outputRange m; *)
736-
737779
// Only solve constraints if this is not an error var
738780
if r.IsFromError then () else
739781
// Check to see if this type variable is relevant to any trait constraints.
@@ -745,15 +787,17 @@ let rec SolveTyparEqualsType (csenv: ConstraintSolverEnv) ndeep m2 (trace: Optio
745787

746788
| _ -> failwith "SolveTyparEqualsType"
747789
}
748-
749790

750791
/// Apply the constraints on 'typar' to the type 'ty'
751792
and solveTypMeetsTyparConstraints (csenv: ConstraintSolverEnv) ndeep m2 trace ty (r: Typar) = trackErrors {
752793
let g = csenv.g
794+
753795
// Propagate compat flex requirements from 'tp' to 'ty'
754796
do! SolveTypIsCompatFlex csenv trace r.IsCompatFlex ty
797+
755798
// Propagate dynamic requirements from 'tp' to 'ty'
756799
do! SolveTypDynamicReq csenv trace r.DynamicReq ty
800+
757801
// Propagate static requirements from 'tp' to 'ty'
758802
do! SolveTypStaticReq csenv trace r.StaticReq ty
759803

@@ -899,6 +943,7 @@ and SolveTypeSubsumesType (csenv: ConstraintSolverEnv) ndeep m2 (trace: Optional
899943
let amap = csenv.amap
900944
let aenv = csenv.EquivEnv
901945
let denv = csenv.DisplayEnv
946+
902947
match sty1, sty2 with
903948
| TType_var tp1, _ ->
904949
match aenv.EquivTypars.TryFind tp1 with
@@ -914,15 +959,19 @@ and SolveTypeSubsumesType (csenv: ConstraintSolverEnv) ndeep m2 (trace: Optional
914959
| TType_tuple (tupInfo1, l1), TType_tuple (tupInfo2, l2) ->
915960
if evalTupInfoIsStruct tupInfo1 <> evalTupInfoIsStruct tupInfo2 then ErrorD (ConstraintSolverError(FSComp.SR.tcTupleStructMismatch(), csenv.m, m2)) else
916961
SolveTypeEqualsTypeEqns csenv ndeep m2 trace cxsln l1 l2 (* nb. can unify since no variance *)
962+
917963
| TType_anon (anonInfo1, l1), TType_anon (anonInfo2, l2) ->
918964
SolveAnonInfoEqualsAnonInfo csenv m2 anonInfo1 anonInfo2 ++ (fun () ->
919965
SolveTypeEqualsTypeEqns csenv ndeep m2 trace cxsln l1 l2) (* nb. can unify since no variance *)
966+
920967
| TType_fun (d1, r1), TType_fun (d2, r2) -> SolveFunTypeEqn csenv ndeep m2 trace cxsln d1 d2 r1 r2 (* nb. can unify since no variance *)
968+
921969
| TType_measure ms1, TType_measure ms2 -> UnifyMeasures csenv trace ms1 ms2
922970

923971
// Enforce the identities float=float<1>, float32=float32<1> and decimal=decimal<1>
924972
| (_, TType_app (tc2, [ms])) when (tc2.IsMeasureableReprTycon && typeEquiv csenv.g sty1 (reduceTyconRefMeasureableOrProvided csenv.g tc2 [ms]))
925973
-> SolveTypeEqualsTypeKeepAbbrevsWithCxsln csenv ndeep m2 trace cxsln ms (TType_measure Measure.One)
974+
926975
| (TType_app (tc2, [ms]), _) when (tc2.IsMeasureableReprTycon && typeEquiv csenv.g sty2 (reduceTyconRefMeasureableOrProvided csenv.g tc2 [ms]))
927976
-> SolveTypeEqualsTypeKeepAbbrevsWithCxsln csenv ndeep m2 trace cxsln ms (TType_measure Measure.One)
928977

@@ -973,6 +1022,7 @@ and SolveTypeSubsumesType (csenv: ConstraintSolverEnv) ndeep m2 (trace: Optional
9731022
let ty2arg = destArrayTy g ty2
9741023
SolveTypeEqualsTypeKeepAbbrevsWithCxsln csenv ndeep m2 trace cxsln ty1arg ty2arg
9751024
| _ -> error(InternalError("destArrayTy", m))
1025+
9761026
| _ ->
9771027
// D<inst> :> Head<_> --> C<inst'> :> Head<_> for the
9781028
// first interface or super-class C supported by D which
@@ -991,7 +1041,6 @@ and SolveTypeSubsumesTypeKeepAbbrevs csenv ndeep m2 trace cxsln ty1 ty2 =
9911041
// Solve and record non-equality constraints
9921042
//-------------------------------------------------------------------------
9931043

994-
9951044
and SolveTyparSubtypeOfType (csenv: ConstraintSolverEnv) ndeep m2 trace tp ty1 =
9961045
let g = csenv.g
9971046
if isObjTy g ty1 then CompleteD
@@ -1052,7 +1101,7 @@ and SolveMemberConstraint (csenv: ConstraintSolverEnv) ignoreUnresolvedOverload
10521101
| _ -> do! ErrorD (ConstraintSolverError(FSComp.SR.csExpectedArguments(), m, m2))
10531102
// Trait calls are only supported on pseudo type (variables)
10541103
for e in tys do
1055-
do! SolveTypStaticReq csenv trace HeadTypeStaticReq e
1104+
do! SolveTypStaticReq csenv trace HeadTypeStaticReq e
10561105

10571106
let argtys = if memFlags.IsInstance then List.tail argtys else argtys
10581107

@@ -1108,14 +1157,18 @@ and SolveMemberConstraint (csenv: ConstraintSolverEnv) ignoreUnresolvedOverload
11081157
do! SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace argty2 (mkAppTy tcref [TType_measure ms2])
11091158
do! SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace rty (mkAppTy tcref [TType_measure (Measure.Prod(ms1, if nm = "op_Multiply" then ms2 else Measure.Inv ms2))])
11101159
return TTraitBuiltIn
1160+
11111161
| _ ->
1162+
11121163
match GetMeasureOfType g argty2 with
11131164
| Some (tcref, ms2) ->
11141165
let ms1 = freshMeasure ()
11151166
do! SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace argty1 (mkAppTy tcref [TType_measure ms1])
11161167
do! SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace rty (mkAppTy tcref [TType_measure (Measure.Prod(ms1, if nm = "op_Multiply" then ms2 else Measure.Inv ms2))])
11171168
return TTraitBuiltIn
1169+
11181170
| _ ->
1171+
11191172
do! SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace argty2 argty1
11201173
do! SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace rty argty1
11211174
return TTraitBuiltIn

src/fsharp/DetupleArgs.fs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,17 +644,26 @@ let hasTransfrom penv f = Zmap.tryFind f penv.transforms
644644
*)
645645

646646
type env =
647-
{ eg : TcGlobals
648-
prefix : string
649-
m : Range.range }
647+
{
648+
eg: TcGlobals
649+
650+
prefix: string
651+
652+
m: Range.range
653+
}
654+
655+
override __.ToString() = "<env>"
650656

651657
let suffixE env s = {env with prefix = env.prefix + s}
658+
652659
let rangeE env m = {env with m = m}
653660

654661
let push b bs = b :: bs
662+
655663
let pushL xs bs = xs@bs
656664

657665
let newLocal env ty = mkCompGenLocal env.m env.prefix ty
666+
658667
let newLocalN env i ty = mkCompGenLocal env.m (env.prefix + string i) ty
659668

660669
let noEffectExpr env bindings x =
@@ -712,7 +721,6 @@ and collapseArgs env bindings n (callPattern) args =
712721
| _ts :: _tss, [] ->
713722
internalError "collapseArgs: CallPattern longer than callsite args. REPORT BUG"
714723

715-
716724
//-------------------------------------------------------------------------
717725
// pass - app fixup
718726
//-------------------------------------------------------------------------

src/fsharp/FindUnsolved.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ type cenv =
2121
denv: DisplayEnv
2222
mutable unsolved: Typars }
2323

24+
override x.ToString() = "<cenv>"
25+
2426
/// Walk types, collecting type variables
2527
let accTy cenv _env ty =
2628
let normalizedTy = tryNormalizeMeasureInType cenv.g ty

0 commit comments

Comments
 (0)