Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit bea00d7

Browse files
forkinosami
authored andcommitted
Remove List.headAndTail and some tuples (dotnet#9336)
1 parent c4a92b3 commit bea00d7

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

src/absil/illib.fs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,6 @@ module List =
330330
| [] -> None
331331
| h :: t -> if f h then Some (h, List.rev acc @ t) else loop (h :: acc) t
332332
loop [] inp
333-
334-
let headAndTail l =
335-
match l with
336-
| [] ->
337-
Debug.Assert(false, "empty list")
338-
failwith "List.headAndTail"
339-
| h :: t -> h, t
340333

341334
let zip4 l1 l2 l3 l4 =
342335
List.zip l1 (List.zip3 l2 l3 l4) |> List.map (fun (x1, (x2, x3, x4)) -> (x1, x2, x3, x4))

src/fsharp/MethodCalls.fs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,12 +1867,15 @@ let GenWitnessExpr amap g m (traitInfo: TraitConstraintInfo) argExprs =
18671867

18681868
// Fix bug 1281: If we resolve to an instance method on a struct and we haven't yet taken
18691869
// the address of the object then go do that
1870-
if minfo.IsStruct && minfo.IsInstance && (match argExprs with [] -> false | h :: _ -> not (isByrefTy g (tyOfExpr g h))) then
1871-
let h, t = List.headAndTail argExprs
1872-
let wrap, h', _readonly, _writeonly = mkExprAddrOfExpr g true false PossiblyMutates h None m
1873-
Some (wrap (Expr.Op (TOp.TraitCall traitInfo, [], (h' :: t), m)))
1870+
if minfo.IsStruct && minfo.IsInstance then
1871+
match argExprs with
1872+
| h :: t when not (isByrefTy g (tyOfExpr g h)) ->
1873+
let wrap, h', _readonly, _writeonly = mkExprAddrOfExpr g true false PossiblyMutates h None m
1874+
Some (wrap (Expr.Op (TOp.TraitCall traitInfo, [], (h' :: t), m)))
1875+
| _ ->
1876+
Some (MakeMethInfoCall amap m minfo methArgTys argExprs)
18741877
else
1875-
Some (MakeMethInfoCall amap m minfo methArgTys argExprs )
1878+
Some (MakeMethInfoCall amap m minfo methArgTys argExprs)
18761879

18771880
| Choice2Of5 (tinst, rfref, isSet) ->
18781881
match isSet, rfref.RecdField.IsStatic, argExprs.Length with

src/fsharp/NicePrint.fs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,12 +1472,14 @@ module InfoMemberPrinting =
14721472
let prettifyILMethInfo (amap: Import.ImportMap) m (minfo: MethInfo) typarInst ilMethInfo =
14731473
let (ILMethInfo(_, apparentTy, dty, mdef, _)) = ilMethInfo
14741474
let (prettyTyparInst, prettyTys), _ = PrettyTypes.PrettifyInstAndTypes amap.g (typarInst, (apparentTy :: minfo.FormalMethodInst))
1475-
let prettyApparentTy, prettyFormalMethInst = List.headAndTail prettyTys
1476-
let prettyMethInfo =
1477-
match dty with
1478-
| None -> MethInfo.CreateILMeth (amap, m, prettyApparentTy, mdef)
1479-
| Some declaringTyconRef -> MethInfo.CreateILExtensionMeth(amap, m, prettyApparentTy, declaringTyconRef, minfo.ExtensionMemberPriorityOption, mdef)
1480-
prettyTyparInst, prettyMethInfo, prettyFormalMethInst
1475+
match prettyTys with
1476+
| prettyApparentTy :: prettyFormalMethInst ->
1477+
let prettyMethInfo =
1478+
match dty with
1479+
| None -> MethInfo.CreateILMeth (amap, m, prettyApparentTy, mdef)
1480+
| Some declaringTyconRef -> MethInfo.CreateILExtensionMeth(amap, m, prettyApparentTy, declaringTyconRef, minfo.ExtensionMemberPriorityOption, mdef)
1481+
prettyTyparInst, prettyMethInfo, prettyFormalMethInst
1482+
| _ -> failwith "prettifyILMethInfo - prettyTys empty"
14811483

14821484
/// Format a method to a buffer using "standalone" display style.
14831485
/// For example, these are the formats used when printing signatures of methods that have not been overridden,

src/fsharp/TypeChecker.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9265,9 +9265,8 @@ and TcNameOfExpr cenv env tpenv (synArg: SynExpr) =
92659265
let m = cleanSynArg.Range
92669266
let rec check overallTyOpt expr (delayed: DelayedItem list) =
92679267
match expr with
9268-
| LongOrSingleIdent (false, (LongIdentWithDots(longId, _) as lidd), _, _) when longId.Length > 0 ->
9268+
| LongOrSingleIdent (false, (LongIdentWithDots((id::rest) as longId, _) as lidd), _, _) ->
92699269
let ad = env.eAccessRights
9270-
let id, rest = List.headAndTail longId
92719270
match ResolveLongIndentAsModuleOrNamespaceOrStaticClass cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m false true OpenQualified env.eNameResEnv ad id rest true with
92729271
| Result modref when delayed.IsEmpty && modref |> List.exists (p23 >> IsEntityAccessible cenv.amap m ad) ->
92739272
() // resolved to a module or namespace, done with checks

src/fsharp/fsi/fsi.fs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,10 +2266,15 @@ type internal FsiInteractionProcessor
22662266

22672267
// When the last declaration has a shape of DoExp (i.e., non-binding),
22682268
// transform it to a shape of "let it = <exp>", so we can refer it.
2269-
let defsA = if defsA.Length <= 1 || not (List.isEmpty defsB) then defsA else
2270-
match List.headAndTail (List.rev defsA) with
2271-
| SynModuleDecl.DoExpr(_,exp,_), rest -> (rest |> List.rev) @ (fsiDynamicCompiler.BuildItBinding exp)
2272-
| _ -> defsA
2269+
let defsA =
2270+
if not (isNil defsB) then defsA else
2271+
match defsA with
2272+
| [] -> defsA
2273+
| [_] -> defsA
2274+
| _ ->
2275+
match List.rev defsA with
2276+
| SynModuleDecl.DoExpr(_,exp,_) :: rest -> (rest |> List.rev) @ (fsiDynamicCompiler.BuildItBinding exp)
2277+
| _ -> defsA
22732278

22742279
Some (IDefns(defsA,m)),Some (IDefns(defsB,m)),istate
22752280

0 commit comments

Comments
 (0)