Skip to content

Commit 4c62650

Browse files
committed
Changed based on code-review
1 parent 330ea57 commit 4c62650

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

src/FSharp.Core/array.fs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ module Array =
15781578
checkNonNull "array" array
15791579
Microsoft.FSharp.Primitives.Basics.Array.permute indexMap array
15801580

1581-
let inline private classicSum (array: ^T array) : ^T =
1581+
let inline private fsharpSumImpl (array: ^T array) : ^T =
15821582
checkNonNull "array" array
15831583
let mutable acc = LanguagePrimitives.GenericZero< ^T>
15841584

@@ -1587,26 +1587,28 @@ module Array =
15871587

15881588
acc
15891589

1590+
let isNetFramework = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith ".NET Framework"
1591+
15901592
[<CompiledName("Sum")>]
15911593
let inline sum (array: ^T array) : ^T =
1592-
classicSum array
1594+
fsharpSumImpl array
15931595
when ^T : float =
1594-
if System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith ".NET Framework" then classicSum array
1596+
if isNetFramework then fsharpSumImpl array
15951597
else
15961598
let r = (System.Linq.Enumerable.Sum : IEnumerable<float> -> float) (# "" array : IEnumerable<float> #)
15971599
(# "" r : 'T #)
15981600
when ^T : float32 =
1599-
if System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith ".NET Framework" then classicSum array
1601+
if isNetFramework then fsharpSumImpl array
16001602
else
16011603
let r = (System.Linq.Enumerable.Sum : IEnumerable<float32> -> float32) (# "" array : IEnumerable<float32> #)
16021604
(# "" r : 'T #)
16031605
when ^T : int =
1604-
if System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith ".NET Framework" then classicSum array
1606+
if isNetFramework then fsharpSumImpl array
16051607
else
16061608
let r = (System.Linq.Enumerable.Sum : IEnumerable<int> -> int) (# "" array : IEnumerable<int> #)
16071609
(# "" r : 'T #)
16081610
when ^T : int64 =
1609-
if System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith ".NET Framework" then classicSum array
1611+
if isNetFramework then fsharpSumImpl array
16101612
else
16111613
let r = (System.Linq.Enumerable.Sum : IEnumerable<int64> -> int64) (# "" array : IEnumerable<int64> #)
16121614
(# "" r : 'T #)

src/FSharp.Core/array.fsi

+5
Original file line numberDiff line numberDiff line change
@@ -2465,6 +2465,11 @@ module Array =
24652465
[<CompiledName("SortByDescending")>]
24662466
val inline sortByDescending: projection: ('T -> 'Key) -> array: 'T array -> 'T array when 'Key: comparison
24672467

2468+
/// Internal use of Array.sum to detect if vectorization can be used.
2469+
/// Due to sum "inline" this can't be private.
2470+
[<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>]
2471+
val isNetFramework : bool
2472+
24682473
/// <summary>Returns the sum of the elements in the array.</summary>
24692474
///
24702475
/// <param name="array">The input array.</param>

src/FSharp.Core/seq.fs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ module Seq =
14641464
else
14651465
mkDelayedSeq (fun () -> countByRefType projection source)
14661466

1467-
let inline private classicSum (source: seq< ^a >) : ^a =
1467+
let inline private fsharpSumImpl (source: seq< ^a >) : ^a =
14681468
use e = source.GetEnumerator()
14691469
let mutable acc = LanguagePrimitives.GenericZero< ^a>
14701470

@@ -1473,26 +1473,28 @@ module Seq =
14731473

14741474
acc
14751475

1476+
let isNetFramework = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith ".NET Framework"
1477+
14761478
[<CompiledName("Sum")>]
14771479
let inline sum (source: seq< ^a >) : ^a =
1478-
classicSum source
1480+
fsharpSumImpl source
14791481
when ^a: int64 =
1480-
if System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith ".NET Framework" then classicSum source
1482+
if isNetFramework then fsharpSumImpl source
14811483
else
14821484
let r = (System.Linq.Enumerable.Sum: IEnumerable<int64> -> int64) (# "" source : IEnumerable<int64> #)
14831485
(# "" r : 'a #)
14841486
when ^a: int =
1485-
if System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith ".NET Framework" then classicSum source
1487+
if isNetFramework then fsharpSumImpl source
14861488
else
14871489
let r = (System.Linq.Enumerable.Sum: IEnumerable<int> -> int) (# "" source : IEnumerable<int> #)
14881490
(# "" r : 'a #)
14891491
when ^a: float32 =
1490-
if System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith ".NET Framework" then classicSum source
1492+
if isNetFramework then fsharpSumImpl source
14911493
else
14921494
let r = (System.Linq.Enumerable.Sum: IEnumerable<float32> -> float32) (# "" source : IEnumerable<float32> #)
14931495
(# "" r : 'a #)
14941496
when ^a: float =
1495-
if System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith ".NET Framework" then classicSum source
1497+
if isNetFramework then fsharpSumImpl source
14961498
else
14971499
let r = (System.Linq.Enumerable.Sum: IEnumerable<float> -> float) (# "" source : IEnumerable<float> #)
14981500
(# "" r : 'a #)

src/FSharp.Core/seq.fsi

+5
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,11 @@ module Seq =
23282328
[<CompiledName("SortByDescending")>]
23292329
val inline sortByDescending: projection: ('T -> 'Key) -> source: seq<'T> -> seq<'T> when 'Key: comparison
23302330

2331+
/// Internal use of Seq.sum to detect if vectorization can be used.
2332+
/// Due to sum "inline" this can't be private.
2333+
[<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>]
2334+
val isNetFramework : bool
2335+
23312336
/// <summary>Returns the sum of the elements in the sequence.</summary>
23322337
///
23332338
/// <remarks>The elements are summed using the <c>+</c> operator and <c>Zero</c> property associated with the generated type.</remarks>

0 commit comments

Comments
 (0)