Skip to content

Commit

Permalink
remove List.take from illib.fs and replace its usages with List.truncate
Browse files Browse the repository at this point in the history
  • Loading branch information
vasily-kirichenko committed Jun 5, 2018
1 parent 9e379d9 commit 8a198b0
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 27 deletions.
11 changes: 0 additions & 11 deletions src/absil/illib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -279,22 +279,11 @@ module List =
| [] -> None
| h::t -> if f h then Some (h,n) else findi (n+1) f t


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
Expand Down
10 changes: 5 additions & 5 deletions src/fsharp/DetupleArgs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ let zipCallPatternArgTys m g (callPattern : TupleStructure list) (vss : Val list
let tys = List.collect snd tstys // link fringes
tss, tys

let vss = List.take callPattern.Length vss // drop excessive tys if callPattern shorter
let vss = List.truncate callPattern.Length vss // drop excessive tys if callPattern shorter
let tstys = List.map2 (fun ts vs -> let ts, tyfringe = zipTSTyp ts (typeOfLambdaArg m vs) in ts, (tyfringe, vs)) callPattern vss
List.unzip tstys

Expand Down Expand Up @@ -561,16 +561,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
Expand Down Expand Up @@ -790,7 +790,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
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3171,7 +3171,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
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) (typ : ILType) : layout =
match typ with
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/Optimizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/QuotationTranslator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
// 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 ->
((List.truncate curriedArgInfos.Length curriedArgs,curriedArgInfos) ||> List.exists2 (fun arg argInfo ->
(argInfo.Length > (tryDestRefTupleExpr arg).Length)))
then
if verboseCReflect then
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/SignatureConformance.fs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) =
elif not (sigArgInfos.Length <= implArgInfos.Length && List.forall2 (fun x y -> List.length x <= List.length y) sigArgInfos (List.truncate sigArgInfos.Length implArgInfos)) then
err(fun(x, y, z) -> FSComp.SR.ValueNotContainedMutabilityAritiesDiffer(x, y, z, id.idText, string sigArgInfos.Length, id.idText, id.idText))
else
let implArgInfos = implArgInfos |> List.take sigArgInfos.Length
let implArgInfos = (implArgInfos, sigArgInfos) ||> List.map2 (fun l1 l2 -> l1 |> List.take l2.Length)
let implArgInfos = implArgInfos |> List.truncate sigArgInfos.Length
let implArgInfos = (implArgInfos, sigArgInfos) ||> List.map2 (fun l1 l2 -> l1 |> List.truncate l2.Length)
// Propagate some information signature to implementation.

// Check the attributes on each argument, and update the ValReprInfo for
Expand Down
6 changes: 3 additions & 3 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4991,7 +4991,7 @@ and TcNestedTypeApplication cenv newOk checkCxs occ env tpenv mWholeTypeApp typ
if not (isAppTy cenv.g typ) then error(Error(FSComp.SR.tcTypeHasNoNestedTypes(), mWholeTypeApp))
match typ 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))

Expand Down Expand Up @@ -5273,7 +5273,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
Expand Down Expand Up @@ -13690,7 +13690,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

Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/ast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

//------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/symbols/Exprs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a198b0

Please sign in to comment.