Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove superfluous rec keywords and untangle some functions #16544

Merged
merged 9 commits into from
Jan 24, 2024
55 changes: 28 additions & 27 deletions src/Compiler/TypedTree/TypedTreeOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5097,6 +5097,33 @@ let tryGetFreeVarsCacheValue opts cache =
if opts.canCache then tryGetCacheValue cache
else ValueNone

let accFreeLocalVal opts v fvs =
if not opts.includeLocals then fvs else
if Zset.contains v fvs.FreeLocals then fvs
else
let fvs = accFreevarsInVal opts v fvs
{fvs with FreeLocals=Zset.add v fvs.FreeLocals}

let accFreeInValFlags opts flag acc =
let isMethLocal =
match flag with
| VSlotDirectCall
| CtorValUsedAsSelfInit
| CtorValUsedAsSuperInit -> true
| PossibleConstrainedCall _
| NormalValUse -> false
let acc = accUsesFunctionLocalConstructs isMethLocal acc
match flag with
| PossibleConstrainedCall ty -> accFreeTyvars opts accFreeInType ty acc
| _ -> acc

let accLocalTyconRepr opts b fvs =
if not opts.includeLocalTyconReprs then fvs else
if Zset.contains b fvs.FreeLocalTyconReprs then fvs
else { fvs with FreeLocalTyconReprs = Zset.add b fvs.FreeLocalTyconReprs }

let accFreeExnRef _exnc fvs = fvs // Note: this exnc (TyconRef) should be collected the surround types, e.g. tinst of Expr.Op

let rec accBindRhs opts (TBind(_, repr, _)) acc = accFreeInExpr opts repr acc

and accFreeInSwitchCases opts csl dflt (acc: FreeVars) =
Expand All @@ -5123,31 +5150,6 @@ and accFreeInDecisionTree opts x (acc: FreeVars) =
| TDSwitch(e1, csl, dflt, _) -> accFreeInExpr opts e1 (accFreeInSwitchCases opts csl dflt acc)
| TDSuccess (es, _) -> accFreeInFlatExprs opts es acc
| TDBind (bind, body) -> unionFreeVars (bindLhs opts bind (accBindRhs opts bind (freeInDecisionTree opts body))) acc

and accFreeInValFlags opts flag acc =
let isMethLocal =
match flag with
| VSlotDirectCall
| CtorValUsedAsSelfInit
| CtorValUsedAsSuperInit -> true
| PossibleConstrainedCall _
| NormalValUse -> false
let acc = accUsesFunctionLocalConstructs isMethLocal acc
match flag with
| PossibleConstrainedCall ty -> accFreeTyvars opts accFreeInType ty acc
| _ -> acc

and accFreeLocalVal opts v fvs =
if not opts.includeLocals then fvs else
if Zset.contains v fvs.FreeLocals then fvs
else
let fvs = accFreevarsInVal opts v fvs
{fvs with FreeLocals=Zset.add v fvs.FreeLocals}

and accLocalTyconRepr opts b fvs =
if not opts.includeLocalTyconReprs then fvs else
if Zset.contains b fvs.FreeLocalTyconReprs then fvs
else { fvs with FreeLocalTyconReprs = Zset.add b fvs.FreeLocalTyconReprs }

and accUsedRecdOrUnionTyconRepr opts (tc: Tycon) fvs =
if (match tc.TypeReprInfo with TFSharpTyconRepr _ -> true | _ -> false) then
Expand All @@ -5170,8 +5172,7 @@ and accFreeRecdFieldRef opts rfref fvs =
let fvs = fvs |> accUsedRecdOrUnionTyconRepr opts rfref.Tycon
let fvs = fvs |> accFreevarsInTycon opts rfref.TyconRef
{ fvs with FreeRecdFields = Zset.add rfref fvs.FreeRecdFields }

and accFreeExnRef _exnc fvs = fvs // Note: this exnc (TyconRef) should be collected the surround types, e.g. tinst of Expr.Op

and accFreeValRef opts (vref: ValRef) fvs =
match vref.IsLocalRef with
| true -> accFreeLocalVal opts vref.ResolvedTarget fvs
Expand Down
Loading