提交 61a165e2 编写于 作者: V Vasily Kirichenko 提交者: Kevin Ransom (msft)

Replace List.chop with List.splitAt and remove its own List.take from illib (#5090)

* replace List.chop with List.splitAt

remove List.take from illib.fs

* replace List.splitAt >> fst with List.take

* use List.truncate instead of List.take

* Revert "replace List.splitAt >> fst with List.take"

This reverts commit c4f06057724f6e2fc7c85c49c236903352ac629f.

* Revert "Revert "replace List.splitAt >> fst with List.take""

This reverts commit 2cb969341dc6031e63856db314671f5969db7aeb.

* Revert "replace List.chop with List.splitAt"

This reverts commit cde206bd17de9e4724c949c3c4f77ff2864af23e.

# Conflicts:
#	src/fsharp/SignatureConformance.fs

* remove List.take from illib.fs and replace its usages with List.truncate

* Revert "remove List.take from illib.fs and replace its usages with List.truncate"

This reverts commit 8a198b0334ada7990f5804afe800b89915b69d46.

# Conflicts:
#	src/fsharp/DetupleArgs.fs

* Revert "Revert "remove List.take from illib.fs and replace its usages with List.truncate""

This reverts commit 6722f08faae33b6b8262f67482385a81f3616dcd.

* rollback accidental change
上级 6f8f5f25
......@@ -279,30 +279,11 @@ module List =
| [] -> None
| h::t -> if f h then Some (h,n) else findi (n+1) f t
let chop n l =
if n = List.length l then (l,[]) else // avoids allocation unless necessary
let rec loop n l acc =
if n <= 0 then (List.rev acc,l) else
match l with
| [] -> failwith "List.chop: overchop"
| (h::t) -> loop (n-1) t (h::acc)
loop n l []
let take n l =
if n = List.length l then l else
let rec loop acc n l =
match l with
| [] -> List.rev acc
| x::xs -> if n<=0 then List.rev acc else loop (x::acc) (n-1) xs
loop [] n l
let rec drop n l =
match l with
| [] -> []
| _::xs -> if n=0 then l else drop (n-1) xs
let splitChoose select l =
let rec ch acc1 acc2 l =
match l with
......
......@@ -562,16 +562,16 @@ let decideTransform g z v callPatterns (m, tps, vss:Val list list, rty) =
(* NOTE: 'a in arg types may have been instanced at different tuples... *)
(* commonCallPattern has to handle those cases. *)
let callPattern = commonCallPattern callPatterns // common CallPattern
let callPattern = List.take vss.Length callPattern // restricted to max nArgs
let callPattern = List.truncate vss.Length callPattern // restricted to max nArgs
// Get formal callPattern by defn usage of formals
let formalCallPattern = decideFormalSuggestedCP g z tys vss
let callPattern = List.take callPattern.Length formalCallPattern
let callPattern = List.truncate callPattern.Length formalCallPattern
// Zip with information about known args
let callPattern, tyfringes = zipCallPatternArgTys m g callPattern vss
// Drop trivial tail AND
let callPattern = minimalCallPattern callPattern
// Shorten tyfringes (zippable)
let tyfringes = List.take callPattern.Length tyfringes
let tyfringes = List.truncate callPattern.Length tyfringes
if isTrivialCP callPattern then
None // no transform
else
......@@ -791,7 +791,7 @@ let passBind penv (TBind(fOrig, repr, letSeqPtOpt) as bind) =
let p = transformedFormals.Length
if (vss.Length < p) then internalError "passBinds: |vss|<p - detuple pass"
let xqNs = List.drop p vss
let x1ps = List.take p vss
let x1ps = List.truncate p vss
let y1Ps = List.concat (List.map2 transFormal transformedFormals x1ps)
let formals = y1Ps @ xqNs
// fCBody - parts
......
......@@ -797,7 +797,7 @@ let GetMethodSpecForMemberVal amap g (memberInfo:ValMemberInfo) (vref:ValRef) =
let parentTypars = parentTcref.TyparsNoRange
let numParentTypars = parentTypars.Length
if tps.Length < numParentTypars then error(InternalError("CodeGen check: type checking did not ensure that this method is sufficiently generic", m))
let ctps,mtps = List.chop numParentTypars tps
let ctps,mtps = List.splitAt numParentTypars tps
let isCompiledAsInstance = ValRefIsCompiledAsInstanceMember g vref
let ilActualRetTy =
......@@ -2615,7 +2615,7 @@ and GenApp cenv cgbuf eenv (f,fty,tyargs,args,m) sequel =
| Method (topValInfo,vref,mspec,_,_,_,_) ->
let nowArgs,laterArgs =
let _,curriedArgInfos,_,_ = GetTopValTypeInFSharpForm cenv.g topValInfo vref.Type m
List.chop curriedArgInfos.Length args
List.splitAt curriedArgInfos.Length args
let actualRetTy = applyTys cenv.g vref.Type (tyargs,nowArgs)
let _,curriedArgInfos,returnTy,_ = GetTopValTypeInCompiledForm cenv.g topValInfo vref.Type m
......@@ -2637,7 +2637,7 @@ and GenApp cenv cgbuf eenv (f,fty,tyargs,args,m) sequel =
let (ilEnclArgTys,ilMethArgTys) =
if ilTyArgs.Length < numEnclILTypeArgs then error(InternalError("length mismatch",m))
List.chop numEnclILTypeArgs ilTyArgs
List.splitAt numEnclILTypeArgs ilTyArgs
let boxity = mspec.DeclaringType.Boxity
let mspec = mkILMethSpec (mspec.MethodRef, boxity,ilEnclArgTys,ilMethArgTys)
......
......@@ -988,7 +988,7 @@ module Pass4_RewriteAssembly =
// Take off the variables
let tps,vss,b,rty = stripTopLambda (b,f.Type)
// Don't take all the variables - only up to length wf
let vssTake,vssDrop = List.chop wf vss
let vssTake,vssDrop = List.splitAt wf vss
// put the variables back on
let b,rty = mkMultiLambdasCore b.Range vssDrop (b,rty)
// fHat, args
......
......@@ -258,7 +258,7 @@ type CalledMeth<'T>
let nUnnamedCallerArgs = unnamedCallerArgs.Length
let nUnnamedCalledArgs = unnamedCalledArgs.Length
if allowOutAndOptArgs && nUnnamedCallerArgs < nUnnamedCalledArgs then
let unnamedCalledArgsTrimmed, unnamedCalledOptOrOutArgs = List.chop nUnnamedCallerArgs unnamedCalledArgs
let unnamedCalledArgsTrimmed, unnamedCalledOptOrOutArgs = List.splitAt nUnnamedCallerArgs unnamedCalledArgs
// Check if all optional/out arguments are byref-out args
if unnamedCalledOptOrOutArgs |> List.forall (fun x -> x.IsOutArg && isByrefTy g x.CalledArgumentType) then
......@@ -280,7 +280,7 @@ type CalledMeth<'T>
if supportsParamArgs && unnamedCallerArgs.Length >= minArgs then
let a, b = List.frontAndBack unnamedCalledArgs
List.chop minArgs unnamedCallerArgs, a, Some(b)
List.splitAt minArgs unnamedCallerArgs, a, Some(b)
else
(unnamedCallerArgs, []), unnamedCalledArgs, None
......@@ -651,7 +651,7 @@ let BuildFSharpMethodApp g m (vref: ValRef) vexp vexprty (args: Exprs) =
| 1, [] -> error(InternalError("expected additional arguments here", m))
| _ ->
if args.Length < arity then error(InternalError("internal error in getting arguments, n = "+string arity+", #args = "+string args.Length, m));
let tupargs, argst = List.chop arity args
let tupargs, argst = List.splitAt arity args
let tuptys = tupargs |> List.map (tyOfExpr g)
(mkRefTupled g m tupargs tuptys),
(argst, rangeOfFunTy g fty) )
......
......@@ -3188,7 +3188,7 @@ let ComputeItemRange wholem (lid: Ident list) rest =
match rest with
| [] -> wholem
| _ ->
let ids = List.take (max 0 (lid.Length - rest.Length)) lid
let ids = List.truncate (max 0 (lid.Length - rest.Length)) lid
match ids with
| [] -> wholem
| _ -> rangeOfLid ids
......
......@@ -170,7 +170,7 @@ module private PrintIL =
match System.Int32.TryParse(rightMost, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture) with
| true, n -> n
| false, _ -> 0 // looks like it's non-generic
ilTyparSubst |> List.rev |> List.take numParms |> List.rev
ilTyparSubst |> List.rev |> List.truncate numParms |> List.rev
let rec layoutILType (denv: DisplayEnv) (ilTyparSubst: layout list) (ty: ILType) : layout =
match ty with
......
......@@ -2590,7 +2590,7 @@ and OptimizeApplication cenv env (f0, f0ty, tyargs, args, m) =
let nDetupArgsL = detupArgsL.Length
let nShapes = min nargs nDetupArgsL
let detupArgsShapesL =
List.take nShapes detupArgsL
List.truncate nShapes detupArgsL
|> List.map (fun detupArgs ->
match detupArgs with
| [] | [_] -> UnknownValue
......
......@@ -262,7 +262,7 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
// If so, adjust and try again
let nCurriedArgInfos = curriedArgInfos.Length
if curriedArgs.Length < nCurriedArgInfos ||
((List.take nCurriedArgInfos curriedArgs,curriedArgInfos) ||> List.exists2 (fun arg argInfo ->
((List.truncate nCurriedArgInfos curriedArgs,curriedArgInfos) ||> List.exists2 (fun arg argInfo ->
(argInfo.Length > (tryDestRefTupleExpr arg).Length)))
then
if verboseCReflect then
......@@ -278,7 +278,7 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
ConvExpr cenv env (MakeApplicationAndBetaReduce cenv.g (expr,exprty,[tyargs],curriedArgs,m))
else
// Too many arguments? Chop
let (curriedArgs:Expr list ),laterArgs = List.chop nCurriedArgInfos curriedArgs
let (curriedArgs:Expr list ),laterArgs = List.splitAt nCurriedArgInfos curriedArgs
let callR =
// We now have the right number of arguments, w.r.t. currying and tupling.
......
......@@ -237,10 +237,10 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) =
err(fun(x, y, z) -> FSComp.SR.ValueNotContainedMutabilityGenericParametersDiffer(x, y, z, string mtps, string ntps))
elif implValInfo.KindsOfTypars <> sigValInfo.KindsOfTypars then
err(FSComp.SR.ValueNotContainedMutabilityGenericParametersAreDifferentKinds)
elif not (nSigArgInfos <= implArgInfos.Length && List.forall2 (fun x y -> List.length x <= List.length y) sigArgInfos (fst (List.chop nSigArgInfos implArgInfos))) then
elif not (nSigArgInfos <= implArgInfos.Length && List.forall2 (fun x y -> List.length x <= List.length y) sigArgInfos (fst (List.splitAt nSigArgInfos implArgInfos))) then
err(fun(x, y, z) -> FSComp.SR.ValueNotContainedMutabilityAritiesDiffer(x, y, z, id.idText, string nSigArgInfos, id.idText, id.idText))
else
let implArgInfos = implArgInfos |> List.take nSigArgInfos
let implArgInfos = implArgInfos |> List.truncate nSigArgInfos
let implArgInfos = (implArgInfos, sigArgInfos) ||> List.map2 (fun l1 l2 -> l1 |> List.take l2.Length)
// Propagate some information signature to implementation.
......
......@@ -2244,7 +2244,7 @@ let PartitionValTyparsForApparentEnclosingType g (v:Val) =
let parentTypars = parent.TyparsNoRange
let nparentTypars = parentTypars.Length
if nparentTypars <= fullTypars.Length then
let memberParentTypars, memberMethodTypars = List.chop nparentTypars fullTypars
let memberParentTypars, memberMethodTypars = List.splitAt nparentTypars fullTypars
let memberToParentInst, tinst = mkTyparToTyparRenaming memberParentTypars parentTypars
Some(parentTypars, memberParentTypars, memberMethodTypars, memberToParentInst, tinst)
else None
......@@ -6951,12 +6951,12 @@ let AdjustPossibleSubsumptionExpr g (expr: Expr) (suppliedArgs: Expr list) : (Ex
assert (curriedActualArgTys.Length >= nCurriedNiceNames)
let argTysWithNiceNames, argTysWithoutNiceNames =
List.chop nCurriedNiceNames argTys
List.splitAt nCurriedNiceNames argTys
/// Only consume 'suppliedArgs' up to at most the number of nice arguments
let nSuppliedArgs = min suppliedArgs.Length nCurriedNiceNames
let suppliedArgs, droppedSuppliedArgs =
List.chop nSuppliedArgs suppliedArgs
List.splitAt nSuppliedArgs suppliedArgs
/// The relevant range for any expressions and applications includes the arguments
let appm = (m, suppliedArgs) ||> List.fold (fun m e -> unionRanges m (e.Range))
......
......@@ -4992,7 +4992,7 @@ and TcNestedTypeApplication cenv newOk checkCxs occ env tpenv mWholeTypeApp ty t
if not (isAppTy cenv.g ty) then error(Error(FSComp.SR.tcTypeHasNoNestedTypes(), mWholeTypeApp))
match ty with
| TType_app(tcref, tinst) ->
let pathTypeArgs = List.take (max (tinst.Length - tcref.Typars(mWholeTypeApp).Length) 0) tinst
let pathTypeArgs = List.truncate (max (tinst.Length - tcref.Typars(mWholeTypeApp).Length) 0) tinst
TcTypeApp cenv newOk checkCxs occ env tpenv mWholeTypeApp tcref pathTypeArgs tyargs
| _ -> error(InternalError("TcNestedTypeApplication: expected type application", mWholeTypeApp))
......@@ -5274,7 +5274,7 @@ and TcPat warnOnUpper cenv env topValInfo vFlags (tpenv, names, takenNames) ty p
let args = match args with SynConstructorArgs.Pats args -> args | _ -> failwith "impossible: active patterns can be used only with SynConstructorArgs.Pats"
let e =
if dotms.Length = longId.Length then
let e = SynExpr.LongIdent(false, LongIdentWithDots(longId, List.take (dotms.Length - 1) dotms), None, m)
let e = SynExpr.LongIdent(false, LongIdentWithDots(longId, List.truncate (dotms.Length - 1) dotms), None, m)
SynExpr.DiscardAfterMissingQualificationAfterDot(e, unionRanges e.Range (List.last dotms))
else SynExpr.LongIdent(false, lidwd, None, m)
List.fold (fun f x -> mkSynApp1 f (convSynPatToSynExpr x) m) e args
......@@ -13691,7 +13691,7 @@ module MutRecBindingChecking =
let thisValOpt = GetInstanceMemberThisVariable (v, x)
// Members have at least as many type parameters as the enclosing class. Just grab the type variables for the type.
let thisTyInst = List.map mkTyparTy (List.take (tcref.Typars(v.Range).Length) v.Typars)
let thisTyInst = List.map mkTyparTy (List.truncate (tcref.Typars(v.Range).Length) v.Typars)
let x = localReps.FixupIncrClassExprPhase2C cenv thisValOpt safeStaticInitInfo thisTyInst x
......
......@@ -176,7 +176,7 @@ type LongIdentWithDots =
| LongIdentWithDots([],_) -> failwith "rangeOfLidwd"
| LongIdentWithDots([id],_) -> id.idRange
| LongIdentWithDots(h::t,dotms) ->
let nonExtraDots = if dotms.Length = t.Length then dotms else List.take t.Length dotms
let nonExtraDots = if dotms.Length = t.Length then dotms else List.truncate t.Length dotms
unionRanges h.idRange (List.last t).idRange |> unionRanges (List.last nonExtraDots)
//------------------------------------------------------------------------
......
......@@ -436,7 +436,7 @@ let private AnalyzeTypeOfMemberVal isCSharpExt g (ty,vref:ValRef) =
[],memberAllTypars,retTy,[]
else
let parentTyArgs = argsOfAppTy g ty
let memberParentTypars,memberMethodTypars = List.chop parentTyArgs.Length memberAllTypars
let memberParentTypars,memberMethodTypars = List.splitAt parentTyArgs.Length memberAllTypars
memberParentTypars,memberMethodTypars,retTy,parentTyArgs
/// Get the object type for a member value which is an extension method (C#-style or F#-style)
......@@ -1477,7 +1477,7 @@ type MethInfo =
// A slot signature is w.r.t. the type variables of the type it is associated with.
// So we have to rename from the member type variables to the type variables of the type.
let formalEnclosingTypars = x.ApparentEnclosingTyconRef.Typars(m)
let formalEnclosingTyparsFromMethod,formalMethTypars = List.chop formalEnclosingTypars.Length allTyparsFromMethod
let formalEnclosingTyparsFromMethod,formalMethTypars = List.splitAt formalEnclosingTypars.Length allTyparsFromMethod
let methodToParentRenaming,_ = mkTyparToTyparRenaming formalEnclosingTyparsFromMethod formalEnclosingTypars
let formalParams =
GetArgInfosOfMember x.IsCSharpStyleExtensionMember g vref
......
......@@ -422,7 +422,7 @@ module FSharpExprConvert =
// Check to see if there aren't enough arguments or if there is a tuple-arity mismatch
// If so, adjust and try again
if curriedArgs.Length < curriedArgInfos.Length ||
((List.take curriedArgInfos.Length curriedArgs, curriedArgInfos) ||> List.exists2 (fun arg argInfo -> (argInfo.Length > (tryDestRefTupleExpr arg).Length))) then
((List.truncate curriedArgInfos.Length curriedArgs, curriedArgInfos) ||> List.exists2 (fun arg argInfo -> (argInfo.Length > (tryDestRefTupleExpr arg).Length))) then
// Too few arguments or incorrect tupling? Convert to a lambda and beta-reduce the
// partially applied arguments to 'let' bindings
......@@ -437,7 +437,7 @@ module FSharpExprConvert =
ConvExprPrimLinear cenv env splitCallExpr contf
else
let curriedArgs, laterArgs = List.chop curriedArgInfos.Length curriedArgs
let curriedArgs, laterArgs = List.splitAt curriedArgInfos.Length curriedArgs
// detuple the args
let untupledCurriedArgs =
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册