Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster CodeGenerator if FSHARP6 defined #407

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions src/ProvidedTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14044,25 +14044,59 @@ namespace ProviderImplementation.ProvidedTypes
let stringTypeTgt = convTypeToTgt typeof<string>
let mathTypeTgt = convTypeToTgt typeof<System.Math>

#if FSHARP6_OR_GREATER
let makeTypePattern tp =
let tt = convTypeToTgt tp
fun (t : Type) -> if t = tt then Some() else None
fun (t : Type) -> if t = tt then ValueSome() else ValueNone

[<return: Struct>]
let (|Bool|_|) = makeTypePattern(typeof<bool>)
[<return: Struct>]
let (|SByte|_|) = makeTypePattern(typeof<sbyte>)
[<return: Struct>]
let (|Int16|_|) = makeTypePattern(typeof<int16>)
[<return: Struct>]
let (|Int32|_|) = makeTypePattern(typeof<int32>)
[<return: Struct>]
let (|Int64|_|) = makeTypePattern(typeof<int64>)
[<return: Struct>]
let (|Byte|_|) = makeTypePattern(typeof<byte>)
[<return: Struct>]
let (|UInt16|_|) = makeTypePattern(typeof<uint16>)
[<return: Struct>]
let (|UInt32|_|) = makeTypePattern(typeof<uint32>)
[<return: Struct>]
let (|UInt64|_|) = makeTypePattern(typeof<uint64>)
[<return: Struct>]
let (|Single|_|) = makeTypePattern(typeof<single>)
[<return: Struct>]
let (|Double|_|) = makeTypePattern(typeof<double>)
[<return: Struct>]
let (|Char|_|) = makeTypePattern(typeof<char>)
[<return: Struct>]
let (|Decimal|_|) = makeTypePattern(typeof<decimal>)
[<return: Struct>]
let (|String|_|) = makeTypePattern(typeof<string>)
#else
let makeTypePattern tp =
let tt = convTypeToTgt tp
fun (t : Type) -> if t = tt then Some() else None

let (|Bool|_|) = makeTypePattern(typeof<bool>)
let (|SByte|_|) = makeTypePattern(typeof<sbyte>)
let (|Int16|_|) = makeTypePattern(typeof<int16>)
let (|Int32|_|) = makeTypePattern(typeof<int32>)
let (|Int64|_|) = makeTypePattern(typeof<int64>)
let (|Byte|_|) = makeTypePattern(typeof<byte>)
let (|UInt16|_|) = makeTypePattern(typeof<uint16>)
let (|UInt32|_|) = makeTypePattern(typeof<uint32>)
let (|UInt64|_|) = makeTypePattern(typeof<uint64>)
let (|Single|_|) = makeTypePattern(typeof<single>)
let (|Double|_|) = makeTypePattern(typeof<double>)
let (|Char|_|) = makeTypePattern(typeof<char>)
let (|Decimal|_|) = makeTypePattern(typeof<decimal>)
let (|String|_|) = makeTypePattern(typeof<string>)
#endif
let (|StaticMethod|_|) name tps (t : Type) =
match t.GetMethod(name, BindingFlags.Static ||| BindingFlags.Public, null, tps, null) with
| null -> None
Expand Down Expand Up @@ -14115,7 +14149,10 @@ namespace ProviderImplementation.ProvidedTypes
minfo1 = minfo2) ->
Some(args)
| _ -> None)


#if FSHARP6_OR_GREATER
[<return: Struct>]
#endif
let (|NaN|_|) =
let operatorsType = convTypeToTgt (typedefof<list<_>>.Assembly.GetType("Microsoft.FSharp.Core.Operators"))
let minfo1 = operatorsType.GetProperty("NaN").GetGetMethod()
Expand All @@ -14124,9 +14161,17 @@ namespace ProviderImplementation.ProvidedTypes
| Call(None, minfo2, [])
when (minfo1.MetadataToken = minfo2.MetadataToken &&
minfo1 = minfo2) ->
#if FSHARP6_OR_GREATER
ValueSome()
| _ -> ValueNone)
#else
Some()
| _ -> None)

#endif

#if FSHARP6_OR_GREATER
[<return: Struct>]
#endif
let (|NaNSingle|_|) =
let operatorsType = convTypeToTgt (typedefof<list<_>>.Assembly.GetType("Microsoft.FSharp.Core.Operators"))
let minfo1 = operatorsType.GetProperty("NaNSingle").GetGetMethod()
Expand All @@ -14135,8 +14180,13 @@ namespace ProviderImplementation.ProvidedTypes
| Call(None, minfo2, [])
when (minfo1.MetadataToken = minfo2.MetadataToken &&
minfo1 = minfo2) ->
#if FSHARP6_OR_GREATER
ValueSome()
| _ -> ValueNone)
#else
Some()
| _ -> None)
#endif

let (|TypeOf|_|) = (|SpecificCall|_|) <@ typeof<obj> @>

Expand Down
Loading