Skip to content

Commit 875bdff

Browse files
authored
Merge pull request #8 from KevinRansom/dsyme-tuple-spike
Dsyme tuple spike
2 parents 6705d23 + 152cb30 commit 875bdff

File tree

6 files changed

+52
-51
lines changed

6 files changed

+52
-51
lines changed

build.cmd

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ echo Usage:
1515
echo.
1616
echo build.cmd ^all^|ci^|ci_part1^|ci_part2^|microbuild^|proto^|net40^|coreclr^|debug^|release^|diag^|compiler^|pcls^|vs^
1717
echo ^test-coreunit^|test-corecompile^|test-smoke^|test-coreclr^|test-pcls^|test-fsharp^|test-fsharpqa^|test-vs^
18-
echo.
19-
echo No arguments default to 'build'
20-
echo. rate strings by comma
21-
echo To specify multiple values, sepa
18+
echo.
19+
echo No arguments default to 'build'
20+
echo.
21+
echo To specify multiple values, separate strings by comma
2222
echo.
2323
echo.This builds the net40 build of the compiler without running tests
2424
echo.

src/fsharp/CompileOps.fs

-2
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,6 @@ let DefaultBasicReferencesForOutOfProjectSources =
16181618
yield "System.Runtime.Serialization.Formatters.Soap"
16191619
yield "System.Data"
16201620
yield "System.Drawing"
1621-
yield "System.ValueTuple"
16221621

16231622
// Don't reference System.Core for .NET 2.0 compilations.
16241623
//
@@ -1693,7 +1692,6 @@ let SystemAssemblies primaryAssemblyName =
16931692
yield "System.Threading.Thread"
16941693
yield "System.Threading.ThreadPool"
16951694
yield "System.Threading.Timer"
1696-
yield "System.ValueTuple"
16971695
]
16981696

16991697
// The set of references entered into the TcConfigBuilder for scripts prior to computing

src/fsharp/FSharp.Core/reflect.fs

+46-37
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Microsoft.FSharp.Core
88

99
open System
1010
open System.Reflection
11+
open System.Threading
1112
open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
1213
open Microsoft.FSharp.Collections
1314

@@ -390,44 +391,52 @@ module internal Impl =
390391
// Which field holds the nested tuple?
391392
let tupleEncField = maxTuple-1
392393

393-
let rec mkTupleType isStruct (asm:Assembly) (tys: Type[]) =
394-
let tupleFullName n =
395-
if isStruct then
396-
match n with
397-
| 1 -> "System.ValueTuple`1"
398-
| 2 -> "System.ValueTuple`2"
399-
| 3 -> "System.ValueTuple`3"
400-
| 4 -> "System.ValueTuple`4"
401-
| 5 -> "System.ValueTuple`5"
402-
| 6 -> "System.ValueTuple`6"
403-
| 7 -> "System.ValueTuple`7"
404-
| 8 -> "System.ValueTuple`8"
405-
| _ -> "System.ValueTuple"
406-
else
394+
let dictionaryLock = obj()
395+
let refTupleTypes = System.Collections.Generic.Dictionary<Assembly, Type[]>()
396+
let valueTupleTypes = System.Collections.Generic.Dictionary<Assembly, Type[]>()
397+
398+
let rec mkTupleType isStruct (asm:Assembly) (tys:Type[]) =
399+
let table =
400+
let makeIt n =
401+
let tupleFullName n =
402+
let structOffset = if isStruct then 9 else 0
403+
let index = n - 1 + structOffset
404+
tupleNames.[index]
405+
407406
match n with
408-
| 1 -> "System.Tuple`1"
409-
| 2 -> "System.Tuple`2"
410-
| 3 -> "System.Tuple`3"
411-
| 4 -> "System.Tuple`4"
412-
| 5 -> "System.Tuple`5"
413-
| 6 -> "System.Tuple`6"
414-
| 7 -> "System.Tuple`7"
415-
| 8 -> "System.Tuple`8"
416-
| _ -> "System.Tuple"
417-
418-
match tys.Length with
419-
| 1 -> asm.GetType(tupleFullName 1).MakeGenericType(tys)
420-
| 2 -> asm.GetType(tupleFullName 2).MakeGenericType(tys)
421-
| 3 -> asm.GetType(tupleFullName 3).MakeGenericType(tys)
422-
| 4 -> asm.GetType(tupleFullName 4).MakeGenericType(tys)
423-
| 5 -> asm.GetType(tupleFullName 5).MakeGenericType(tys)
424-
| 6 -> asm.GetType(tupleFullName 6).MakeGenericType(tys)
425-
| 7 -> asm.GetType(tupleFullName 7).MakeGenericType(tys)
426-
| n when n >= maxTuple ->
407+
| 1 -> asm.GetType(tupleFullName 1)
408+
| 2 -> asm.GetType(tupleFullName 2)
409+
| 3 -> asm.GetType(tupleFullName 3)
410+
| 4 -> asm.GetType(tupleFullName 4)
411+
| 5 -> asm.GetType(tupleFullName 5)
412+
| 6 -> asm.GetType(tupleFullName 6)
413+
| 7 -> asm.GetType(tupleFullName 7)
414+
| 8 -> asm.GetType(tupleFullName 8)
415+
| _ -> invalidArg "tys" (SR.GetString(SR.invalidTupleTypes))
416+
417+
let tables = if isStruct then valueTupleTypes else refTupleTypes
418+
match tables.TryGetValue(asm) with
419+
| false, _ ->
420+
let a = ref (Array.init<Type> 8 (fun i -> makeIt (i + 1)))
421+
lock dictionaryLock (fun () -> match tables.TryGetValue(asm) with
422+
| true, t -> a := t
423+
| false, _ -> tables.Add(asm, !a))
424+
!a
425+
| true, t -> t
426+
427+
match tys.Length with
428+
| 1 -> table.[0].MakeGenericType(tys)
429+
| 2 -> table.[1].MakeGenericType(tys)
430+
| 3 -> table.[2].MakeGenericType(tys)
431+
| 4 -> table.[3].MakeGenericType(tys)
432+
| 5 -> table.[4].MakeGenericType(tys)
433+
| 6 -> table.[5].MakeGenericType(tys)
434+
| 7 -> table.[6].MakeGenericType(tys)
435+
| n when n >= maxTuple ->
427436
let tysA = tys.[0..tupleEncField-1]
428437
let tysB = tys.[maxTuple-1..]
429438
let tyB = mkTupleType isStruct asm tysB
430-
asm.GetType(tupleFullName 8).MakeGenericType(Array.append tysA [| tyB |])
439+
table.[7].MakeGenericType(Array.append tysA [| tyB |])
431440
| _ -> invalidArg "tys" (SR.GetString(SR.invalidTupleTypes))
432441

433442
let rec getTupleTypeInfo (typ:Type) =
@@ -774,13 +783,13 @@ type FSharpType =
774783
invalidArg "types" (SR.GetString(SR.nullsNotAllowedInArray))
775784
Impl.mkTupleType false asm types
776785

777-
static member MakeTupleTypeWithAssembly (asm:Assembly) (types:Type[]) =
786+
static member MakeTupleType (asm:Assembly, types:Type[]) =
778787
Impl.checkNonNull "types" types
779788
if types |> Array.exists (function null -> true | _ -> false) then
780789
invalidArg "types" (SR.GetString(SR.nullsNotAllowedInArray))
781790
Impl.mkTupleType false asm types
782791

783-
static member MakeStructTupleTypeWithAssembly (asm:Assembly) (types:Type[]) =
792+
static member MakeValueTupleType (asm:Assembly, types:Type[]) =
784793
Impl.checkNonNull "types" types
785794
if types |> Array.exists (function null -> true | _ -> false) then
786795
invalidArg "types" (SR.GetString(SR.nullsNotAllowedInArray))
@@ -875,7 +884,7 @@ type FSharpValue =
875884
let (f : (obj -> obj) -> obj) = downcast o
876885
f implementation
877886

878-
static member MakeTuple(tupleElements: obj[],tupleType:Type) =
887+
static member MakeTuple(tupleElements: obj[], tupleType:Type) =
879888
Impl.checkNonNull "tupleElements" tupleElements
880889
Impl.checkTupleType("tupleType",tupleType)
881890
Impl.getTupleConstructor tupleType tupleElements

src/fsharp/FSharp.Core/reflect.fsi

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,12 @@ type FSharpType =
327327
/// <summary>Returns a <c>System.Type</c> representing an F# tuple type with the given element types</summary>
328328
/// <param name="types">An array of types for the tuple elements.</param>
329329
/// <returns>The type representing the tuple containing the input elements.</returns>
330-
static member MakeTupleTypeWithAssembly: asm:Assembly -> types:Type[] -> Type
330+
static member MakeTupleType: asm:Assembly * types:Type[] -> Type
331331

332332
/// <summary>Returns a <c>System.Type</c> representing an F# struct tuple type with the given element types</summary>
333333
/// <param name="types">An array of types for the tuple elements.</param>
334334
/// <returns>The type representing the struct tuple containing the input elements.</returns>
335-
static member MakeStructTupleTypeWithAssembly: asm:Assembly -> types:Type[] -> Type
335+
static member MakeValueTupleType: asm:Assembly * types:Type[] -> Type
336336

337337
/// <summary>Return true if the <c>typ</c> is a representation of an F# tuple type </summary>
338338
/// <param name="typ">The type to check.</param>

tests/fsharpqa/testenv/src/FSharp.Compiler.Hosted/FSharp.Compiler.Hosted.fsproj

-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@
4646
<Reference Include="System" />
4747
<Reference Include="System.Core" />
4848
<Reference Include="System.Numerics" />
49-
<Reference Include="..\..\..\..\..\packages\System.ValueTuple.4.0.0-rc3-24212-01\lib\netstandard1.1\System.ValueTuple.dll">
50-
<Private>True</Private>
51-
</Reference>
5249
</ItemGroup>
5350
<ItemGroup Condition=" '$(OpenBuild)' == 'True' ">
5451
<Reference Include="$(OpenDrop)\FSharp.Core.dll">

tests/fsharpqa/testenv/src/HostedCompilerServer/HostedCompilerServer.fsproj

-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@
4545
<Reference Include="System" />
4646
<Reference Include="System.Core" />
4747
<Reference Include="System.Numerics" />
48-
<Reference Include="..\..\..\..\..\packages\System.ValueTuple.4.0.0-rc3-24212-01\lib\netstandard1.1\System.ValueTuple.dll">
49-
<Private>True</Private>
50-
</Reference>
5148
</ItemGroup>
5249
<ItemGroup Condition=" '$(OpenBuild)' == 'True' ">
5350
<Reference Include="$(OpenDrop)\FSharp.Core.dll">

0 commit comments

Comments
 (0)