From 7ebe97febecc2bfb5c87e67627f47f96ddeb5e98 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sat, 18 Jan 2020 10:46:40 +0100 Subject: [PATCH 1/3] Do not convert back and forth from list --- src/fsharp/FSharp.Core/local.fs | 2 +- src/fsharp/TypeChecker.fs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsharp/FSharp.Core/local.fs b/src/fsharp/FSharp.Core/local.fs index 8e1b17ea91..3d812fc72c 100644 --- a/src/fsharp/FSharp.Core/local.fs +++ b/src/fsharp/FSharp.Core/local.fs @@ -83,7 +83,7 @@ open System.Collections.Generic module internal List = - let arrayZeroCreate (n:int) = (# "newarr !0" type ('T) n : 'T array #) + let inline arrayZeroCreate (n:int) = (# "newarr !0" type ('T) n : 'T array #) [] let nonempty x = match x with [] -> false | _ -> true diff --git a/src/fsharp/TypeChecker.fs b/src/fsharp/TypeChecker.fs index 5d7a170c2c..79c2d0b76c 100644 --- a/src/fsharp/TypeChecker.fs +++ b/src/fsharp/TypeChecker.fs @@ -5482,10 +5482,10 @@ and TcPat warnOnUpper cenv env topValInfo vFlags (tpenv, names, takenNames) ty p | [SynPatErrorSkip(SynPat.Tuple (false, args, _)) | SynPatErrorSkip(SynPat.Paren(SynPatErrorSkip(SynPat.Tuple (false, args, _)), _))] when numArgTys > 1 -> args // note: we allow both 'C _' and 'C (_)' regardless of number of argument of the pattern - | [SynPatErrorSkip(SynPat.Wild _ as e) | SynPatErrorSkip(SynPat.Paren(SynPatErrorSkip(SynPat.Wild _ as e), _))] -> Array.toList (Array.create numArgTys e) | [arg] -> [arg] | _ when numArgTys = 0 -> error(Error(FSComp.SR.tcUnionCaseDoesNotTakeArguments(), m)) | _ when numArgTys = 1 -> error(Error(FSComp.SR.tcUnionCaseRequiresOneArgument(), m)) + | [SynPatErrorSkip(SynPat.Wild _ as e) | SynPatErrorSkip(SynPat.Paren(SynPatErrorSkip(SynPat.Wild _ as e), _))] -> List.replicate numArgTys e | _ -> error(Error(FSComp.SR.tcUnionCaseExpectsTupledArguments numArgTys, m)) UnionCaseOrExnCheck env numArgTys args.Length m From 6191561ab4302d1e2d9699fde8bf771dff7eed13 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sat, 18 Jan 2020 11:02:11 +0100 Subject: [PATCH 2/3] Use a simple for loop in replicate --- src/fsharp/FSharp.Core/list.fs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fsharp/FSharp.Core/list.fs b/src/fsharp/FSharp.Core/list.fs index bf37ab08a1..920f0f0d9f 100644 --- a/src/fsharp/FSharp.Core/list.fs +++ b/src/fsharp/FSharp.Core/list.fs @@ -171,13 +171,13 @@ namespace Microsoft.FSharp.Collections [] let init length initializer = Microsoft.FSharp.Primitives.Basics.List.init length initializer - let rec initConstAcc n x acc = - if n <= 0 then acc else initConstAcc (n-1) x (x :: acc) - [] let replicate count initial = if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative)) - initConstAcc count initial [] + let mutable result = [] + for i in 0..count-1 do + result <- initial :: result + result [] let iter2 action list1 list2 = From e0a837871b58129187d57277fd359cbb0dd19d77 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sat, 18 Jan 2020 11:38:59 +0100 Subject: [PATCH 3/3] Put wildcard back --- src/fsharp/TypeChecker.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsharp/TypeChecker.fs b/src/fsharp/TypeChecker.fs index 79c2d0b76c..58d3b2d87b 100644 --- a/src/fsharp/TypeChecker.fs +++ b/src/fsharp/TypeChecker.fs @@ -5482,10 +5482,10 @@ and TcPat warnOnUpper cenv env topValInfo vFlags (tpenv, names, takenNames) ty p | [SynPatErrorSkip(SynPat.Tuple (false, args, _)) | SynPatErrorSkip(SynPat.Paren(SynPatErrorSkip(SynPat.Tuple (false, args, _)), _))] when numArgTys > 1 -> args // note: we allow both 'C _' and 'C (_)' regardless of number of argument of the pattern + | [SynPatErrorSkip(SynPat.Wild _ as e) | SynPatErrorSkip(SynPat.Paren(SynPatErrorSkip(SynPat.Wild _ as e), _))] -> List.replicate numArgTys e | [arg] -> [arg] | _ when numArgTys = 0 -> error(Error(FSComp.SR.tcUnionCaseDoesNotTakeArguments(), m)) | _ when numArgTys = 1 -> error(Error(FSComp.SR.tcUnionCaseRequiresOneArgument(), m)) - | [SynPatErrorSkip(SynPat.Wild _ as e) | SynPatErrorSkip(SynPat.Paren(SynPatErrorSkip(SynPat.Wild _ as e), _))] -> List.replicate numArgTys e | _ -> error(Error(FSComp.SR.tcUnionCaseExpectsTupledArguments numArgTys, m)) UnionCaseOrExnCheck env numArgTys args.Length m