Skip to content

Commit

Permalink
Remove superfluous rec keywords and untangle some functions (#16544)
Browse files Browse the repository at this point in the history
* remove some superfluous rec keywords and untangle two functions that aren't mutually recursive.
  • Loading branch information
dawedawe authored Jan 24, 2024
1 parent ac61334 commit ddf057b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@ let BuildFieldMap (cenv: cenv) env isPartial ty (flds: ((Ident list * Ident) * '
| _ -> error(Error(FSComp.SR.tcRecordFieldInconsistentTypes(), m)))
Some(tinst, tcref, fldsmap, List.rev rfldsList)

let rec ApplyUnionCaseOrExn (makerForUnionCase, makerForExnTag) m (cenv: cenv) env overallTy item =
let ApplyUnionCaseOrExn (makerForUnionCase, makerForExnTag) m (cenv: cenv) env overallTy item =
let g = cenv.g
let ad = env.eAccessRights
match item with
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/CodeGen/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ let ChooseParamNames fieldNamesAndTypes =
ilParamName, ilFieldName, ilPropType)

/// Approximation for purposes of optimization and giving a warning when compiling definition-only files as EXEs
let rec CheckCodeDoesSomething (code: ILCode) =
let CheckCodeDoesSomething (code: ILCode) =
code.Instrs
|> Array.exists (function
| AI_ldnull
Expand Down Expand Up @@ -476,7 +476,7 @@ let CompLocForPrivateImplementationDetails cloc =
}

/// Compute an ILTypeRef for a CompilationLocation
let rec TypeRefForCompLoc cloc =
let TypeRefForCompLoc cloc =
match cloc.Enclosing with
| [] -> mkILTyRef (cloc.Scope, TypeNameForPrivateImplementationDetails cloc)
| [ h ] ->
Expand Down
8 changes: 4 additions & 4 deletions src/Compiler/Optimize/Optimizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,11 +1457,11 @@ let AbstractExprInfoByVars (boundVars: Val list, boundTyVars) ivalue =
| UnknownValue -> ivalue
| SizeValue (_vdepth, vinfo) -> MakeSizedValueInfo (abstractExprInfo vinfo)

and abstractValInfo v =
let abstractValInfo v =
{ ValExprInfo=abstractExprInfo v.ValExprInfo
ValMakesNoCriticalTailcalls=v.ValMakesNoCriticalTailcalls }

and abstractModulInfo ss =
let rec abstractModulInfo ss =
{ ModuleOrNamespaceInfos = ss.ModuleOrNamespaceInfos |> NameMap.map (InterruptibleLazy.force >> abstractModulInfo >> notlazy)
ValInfos = ss.ValInfos.Map (fun (vref, e) ->
check vref (abstractValInfo e) ) }
Expand Down Expand Up @@ -1592,7 +1592,7 @@ let ValueIsUsedOrHasEffect cenv fvs (b: Binding, binfo) =
// No discarding for things that are used
Zset.contains v (fvs())

let rec SplitValuesByIsUsedOrHasEffect cenv fvs x =
let SplitValuesByIsUsedOrHasEffect cenv fvs x =
x |> List.filter (ValueIsUsedOrHasEffect cenv fvs) |> List.unzip

let IlAssemblyCodeInstrHasEffect i =
Expand Down Expand Up @@ -2016,7 +2016,7 @@ let TryRewriteBranchingTupleBinding g (v: Val) rhs tgtSeqPtOpt body m =
mkLetsBind m binds rhsAndTupleBinding |> Some
| _ -> None

let rec ExpandStructuralBinding cenv expr =
let ExpandStructuralBinding cenv expr =
let g = cenv.g

assert cenv.settings.ExpandStructuralValues()
Expand Down
71 changes: 36 additions & 35 deletions src/Compiler/TypedTree/TypedTreeOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3597,7 +3597,7 @@ let isSpanTyconRef g m tcref =
let isSpanTy g m ty =
ty |> stripTyEqns g |> (function TType_app(tcref, _, _) -> isSpanTyconRef g m tcref | _ -> false)

let rec tryDestSpanTy g m ty =
let tryDestSpanTy g m ty =
match tryAppTy g ty with
| ValueSome(tcref, [ty]) when isSpanTyconRef g m tcref -> Some(tcref, ty)
| _ -> None
Expand Down Expand Up @@ -4626,11 +4626,11 @@ module DebugPrint =
let body = moduleOrNamespaceTypeL ms.ModuleOrNamespaceType
(header @@-- body) @@ footer

let rec implFilesL implFiles =
aboveListL (List.map implFileL implFiles)

and implFileL (CheckedImplFile (signature=implFileTy; contents=implFileContents)) =
let implFileL (CheckedImplFile (signature=implFileTy; contents=implFileContents)) =
aboveListL [(wordL(tagText "top implementation ")) @@-- mexprL implFileTy implFileContents]

let implFilesL implFiles =
aboveListL (List.map implFileL implFiles)

let showType x = showL (typeL x)

Expand Down 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 inline 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 Expand Up @@ -6609,7 +6610,7 @@ let isExpansiveUnderInstantiation g fty0 tyargs pargs argsl =
| _ :: t -> not (isFunTy g fty) || loop (rangeOfFunTy g fty) t
loop fty1 argsl)

let rec mkExprAppAux g f fty argsl m =
let mkExprAppAux g f fty argsl m =
match argsl with
| [] -> f
| _ ->
Expand Down Expand Up @@ -6780,7 +6781,7 @@ let foldLinearBindingTargetsOfMatch tree (targets: _[]) =
treeR, targetsR

// Simplify a little as we go, including dead target elimination
let rec simplifyTrivialMatch spBind mExpr mMatch ty tree (targets : _[]) =
let simplifyTrivialMatch spBind mExpr mMatch ty tree (targets : _[]) =
match tree with
| TDSuccess(es, n) ->
if n >= targets.Length then failwith "simplifyTrivialMatch: target out of range"
Expand Down Expand Up @@ -10722,7 +10723,7 @@ let rec serializeNode (writer: IndentedTextWriter) (addTrailingComma:bool) (node
else
writer.WriteLine("}")

let rec serializeEntity path (entity: Entity) =
let serializeEntity path (entity: Entity) =
let root = visitEntity entity
use sw = new System.IO.StringWriter()
use writer = new IndentedTextWriter(sw)
Expand Down

0 comments on commit ddf057b

Please sign in to comment.