Skip to content

Commit

Permalink
operators
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRansom committed Jul 1, 2024
1 parent 9eb672b commit 6747af8
Show file tree
Hide file tree
Showing 17 changed files with 545 additions and 40 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/8.0.400.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* Support empty-bodied computation expressions. ([Language suggestion #1232](https://github.com/fsharp/fslang-suggestions/issues/1232), [RFC FS-1144 (PR #774)](https://github.com/fsharp/fslang-design/pull/774), [PR #17352](https://github.com/dotnet/fsharp/pull/17352))

### Changed
* `Initial refactoring of FSharp.Core` ([Issues #17372](https://github.com/dotnet/fsharp/issues/17372), [PR #17370](https://github.com/dotnet/fsharp/pull/17370))
* Enforce `AttributeTargets.Interface` ([PR #17173](https://github.com/dotnet/fsharp/pull/17173))
* Minor compiler perf improvements. ([PR #17130](https://github.com/dotnet/fsharp/pull/17130))
* Improve error messages for active pattern argument count mismatch ([PR #16846](https://github.com/dotnet/fsharp/pull/16846), [PR #17186](https://github.com/dotnet/fsharp/pull/17186))
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Core/8.0.400.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

* Cache delegate in query extensions. ([PR #17130](https://github.com/dotnet/fsharp/pull/17130))
* Update `AllowNullLiteralAttribute` to also use `AttributeTargets.Interface` ([PR #17173](https://github.com/dotnet/fsharp/pull/17173))
* `Initial refactoring of FSharp.Core` ([Issues #17372](https://github.com/dotnet/fsharp/issues/17372), [PR #17370](https://github.com/dotnet/fsharp/pull/17370))

### Breaking Changes

Expand Down
11 changes: 7 additions & 4 deletions src/Compiler/Driver/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ let ComputeMakePathAbsolute implicitIncludeDir (path: string) =
with :? ArgumentException ->
path

let isCoreLibrary compilingLibraryName =
compilingLibraryName = "FSharp.Core"
let isCoreLibrary compilingLibraryName = compilingLibraryName = "FSharp.Core"

//----------------------------------------------------------------------------
// Configuration
Expand Down Expand Up @@ -1234,7 +1233,10 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
member _.noFeedback = data.noFeedback
member _.stackReserveSize = data.stackReserveSize
member _.implicitIncludeDir = data.implicitIncludeDir
member _.openDebugInformationForLaterStaticLinking = data.openDebugInformationForLaterStaticLinking

member _.openDebugInformationForLaterStaticLinking =
data.openDebugInformationForLaterStaticLinking

member _.fsharpBinariesDir = data.defaultFSharpBinariesDir
member _.compilingLibraryName = data.compilingLibraryName
member _.useIncrementalBuilder = data.useIncrementalBuilder
Expand Down Expand Up @@ -1470,7 +1472,8 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =

member tcConfig.GenerateOptimizationData = tcConfig.GenerateSignatureData

member tcConfig.assumeDotNetFramework = tcConfig.primaryAssembly = PrimaryAssembly.Mscorlib
member tcConfig.assumeDotNetFramework =
tcConfig.primaryAssembly = PrimaryAssembly.Mscorlib

member tcConfig.compilingCoreLibrary = isCoreLibrary tcConfig.compilingLibraryName

Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Core/FSharp.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<OtherFlags>$(OtherFlags) --nowarn:3511</OtherFlags>
<!-- Turn off 3513: resumable code invocation' - expected for resumable code combinators -->
<OtherFlags>$(OtherFlags) --nowarn:3513</OtherFlags>
<OtherFlags>$(OtherFlags) --compiling-fslib --compiling-fslib-40 --maxerrors:100 --extraoptimizationloops:1</OtherFlags>
<OtherFlags>$(OtherFlags) --compiling-fslib --maxerrors:100 --extraoptimizationloops:1</OtherFlags>
<!-- .tail annotations always emitted for this binary, even in debug mode -->
<Tailcalls>true</Tailcalls>
<PreRelease>true</PreRelease>
Expand Down
12 changes: 6 additions & 6 deletions src/FSharp.Core/Linq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ module LeafExpressionConverter =
let (|ConvIntPtrQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Operators.nativeint))
let (|ConvUIntPtrQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Operators.unativeint))

let (|ConvInt8Q|_|) = SpecificCallToMethodInfo (typeof<ConvEnv>.Assembly.GetType("Microsoft.FSharp.Core.ExtraTopLevelOperators").GetMethod("ToSByte"))
let (|ConvUInt8Q|_|) = SpecificCallToMethodInfo (typeof<ConvEnv>.Assembly.GetType("Microsoft.FSharp.Core.ExtraTopLevelOperators").GetMethod("ToByte"))
let (|ConvDoubleQ|_|) = SpecificCallToMethodInfo (typeof<ConvEnv>.Assembly.GetType("Microsoft.FSharp.Core.ExtraTopLevelOperators").GetMethod("ToDouble"))
let (|ConvSingleQ|_|) = SpecificCallToMethodInfo (typeof<ConvEnv>.Assembly.GetType("Microsoft.FSharp.Core.ExtraTopLevelOperators").GetMethod("ToSingle"))
let (|ConvInt8Q|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun x -> Operators.int8 x))
let (|ConvUInt8Q|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun x -> Operators.uint8 x))
let (|ConvDoubleQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun x -> Operators.double x))
let (|ConvSingleQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun x -> Operators.single x))

let (|ConvNullableCharQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Nullable.char))
let (|ConvNullableDecimalQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Nullable.decimal))
Expand All @@ -374,8 +374,8 @@ module LeafExpressionConverter =
let (|TypeTestGeneric|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun x -> LanguagePrimitives.IntrinsicFunctions.TypeTestGeneric x))
let (|CheckedConvCharQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Checked.char))
let (|CheckedConvSByteQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Checked.sbyte))
let (|CheckedConvInt8Q|_|) = SpecificCallToMethodInfo (typeof<ConvEnv>.Assembly.GetType("Microsoft.FSharp.Core.ExtraTopLevelOperators+Checked").GetMethod("ToSByte"))
let (|CheckedConvUInt8Q|_|) = SpecificCallToMethodInfo (typeof<ConvEnv>.Assembly.GetType("Microsoft.FSharp.Core.ExtraTopLevelOperators+Checked").GetMethod("ToByte"))
let (|CheckedConvInt8Q|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun x -> Operators.Checked.int8 x))
let (|CheckedConvUInt8Q|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun x -> Operators.Checked.uint8 x))
let (|CheckedConvInt16Q|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Checked.int16))
let (|CheckedConvInt32Q|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Checked.int32))
let (|CheckedConvInt64Q|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Checked.int64))
Expand Down
13 changes: 7 additions & 6 deletions src/FSharp.Core/fslib-extra-pervasives.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module ExtraTopLevelOperators =

open System
open System.Collections.Generic
open System.ComponentModel
open System.IO
open System.Diagnostics
open Microsoft.FSharp
Expand Down Expand Up @@ -283,29 +284,29 @@ module ExtraTopLevelOperators =
[<CompiledName("DefaultAsyncBuilder")>]
let async = AsyncBuilder()

[<CompiledName("ToSingle")>]
[<CompiledName("ToSingle"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
let inline single value =
float32 value

[<CompiledName("ToDouble")>]
[<CompiledName("ToDouble"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
let inline double value =
float value

[<CompiledName("ToByte")>]
[<CompiledName("ToByte"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
let inline uint8 value =
byte value

[<CompiledName("ToSByte")>]
[<CompiledName("ToSByte"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
let inline int8 value =
sbyte value

module Checked =

[<CompiledName("ToByte")>]
[<CompiledName("ToByte"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
let inline uint8 value =
Checked.byte value

[<CompiledName("ToSByte")>]
[<CompiledName("ToSByte"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
let inline int8 value =
Checked.sbyte value

Expand Down
15 changes: 8 additions & 7 deletions src/FSharp.Core/fslib-extra-pervasives.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Microsoft.FSharp.Core
[<AutoOpen>]
module ExtraTopLevelOperators =

open System.ComponentModel
open System.IO
open Microsoft.FSharp.Core
open Microsoft.FSharp.Control
Expand Down Expand Up @@ -144,7 +145,7 @@ module ExtraTopLevelOperators =
/// </code>
/// Evaluates to <c>45.0f</c>.
/// </example>
[<CompiledName("ToSingle")>]
[<CompiledName("ToSingle"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
val inline single: value: ^T -> single when ^T : (static member op_Explicit : ^T -> single) and default ^T : int

/// <summary>Converts the argument to 64-bit float.</summary>
Expand All @@ -165,7 +166,7 @@ module ExtraTopLevelOperators =
/// </code>
/// Evaluates to <c>12.30000019</c>.
/// </example>
[<CompiledName("ToDouble")>]
[<CompiledName("ToDouble"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
val inline double: value: ^T -> double when ^T : (static member op_Explicit : ^T -> double) and default ^T : int

/// <summary>Converts the argument to byte.</summary>
Expand All @@ -178,7 +179,7 @@ module ExtraTopLevelOperators =
/// </code>
/// Evaluates to <c>12uy</c>.
/// </example>
[<CompiledName("ToByte")>]
[<CompiledName("ToByte"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
val inline uint8: value: ^T -> uint8 when ^T : (static member op_Explicit : ^T -> uint8) and default ^T : int

/// <summary>Converts the argument to signed byte.</summary>
Expand All @@ -199,7 +200,7 @@ module ExtraTopLevelOperators =
/// </code>
/// Evaluates to <c>3y</c>.
/// </example>
[<CompiledName("ToSByte")>]
[<CompiledName("ToSByte"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
val inline int8: value: ^T -> int8 when ^T : (static member op_Explicit : ^T -> int8) and default ^T : int

module Checked =
Expand All @@ -221,7 +222,7 @@ module ExtraTopLevelOperators =
/// </code>
/// Throws <c>System.OverflowException</c>.
/// </example>
[<CompiledName("ToByte")>]
[<CompiledName("ToByte"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
val inline uint8: value: ^T -> byte when ^T : (static member op_Explicit : ^T -> uint8) and default ^T : int

/// <summary>Converts the argument to signed byte.</summary>
Expand All @@ -242,7 +243,7 @@ module ExtraTopLevelOperators =
/// </code>
/// Throws <c>System.OverflowException</c>.
/// </example>
[<CompiledName("ToSByte")>]
[<CompiledName("ToSByte"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
val inline int8: value: ^T -> sbyte when ^T : (static member op_Explicit : ^T -> int8) and default ^T : int

/// <summary>Builds a read-only lookup table from a sequence of key/value pairs. The key objects are indexed using generic hashing and equality.</summary>
Expand Down Expand Up @@ -339,7 +340,7 @@ module ExtraTopLevelOperators =
/// </code>
/// Evaluates to <c>10</c>. The text <c>eval!</c> is printed once on the first invocation of <c>f</c>.
/// </example>
[<CompiledName("LazyPattern")>]
[<CompiledName("LazyPattern"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
val (|Lazy|): input: Lazy<'T> -> 'T

/// <summary>Builds a query using query syntax and operators.</summary>
Expand Down
21 changes: 21 additions & 0 deletions src/FSharp.Core/prim-types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4742,6 +4742,9 @@ namespace Microsoft.FSharp.Core
// this condition is used whenever ^T is resolved to a nominal type or witnesses are available
when ^T : ^T = (^T : (static member op_Explicit: ^T -> byte) (value))

[<CompiledName("ToUInt8")>]
let inline uint8 value = byte value

[<NoDynamicInvocation(isLegacy=true)>]
[<CompiledName("ToSByte")>]
let inline sbyte (value: ^T) =
Expand All @@ -4764,6 +4767,10 @@ namespace Microsoft.FSharp.Core
// this condition is used whenever ^T is resolved to a nominal type or witnesses are available
when ^T : ^T = (^T : (static member op_Explicit: ^T -> sbyte) (value))


[<CompiledName("ToInt8")>]
let inline int8 value = sbyte value

[<NoDynamicInvocation(isLegacy=true)>]
[<CompiledName("ToUInt16")>]
let inline uint16 (value: ^T) =
Expand Down Expand Up @@ -4944,6 +4951,8 @@ namespace Microsoft.FSharp.Core
when ^T : byte = (# "conv.r.un conv.r4" value : float32 #)
when ^T : ^T = (^T : (static member op_Explicit: ^T -> float32) (value))

let inline single value = float32 value

[<NoDynamicInvocation(isLegacy=true)>]
[<CompiledName("ToDouble")>]
let inline float (value: ^T) =
Expand All @@ -4966,6 +4975,8 @@ namespace Microsoft.FSharp.Core
when ^T : decimal = (Convert.ToDouble((# "" value : decimal #)))
when ^T : ^T = (^T : (static member op_Explicit: ^T -> float) (value))

let inline double value = float value

[<NoDynamicInvocation(isLegacy=true)>]
[<CompiledName("ToDecimal")>]
let inline decimal (value: ^T) =
Expand Down Expand Up @@ -5496,6 +5507,9 @@ namespace Microsoft.FSharp.Core
when ^T : byte = (# "" value : byte #)
when ^T : ^T = (^T : (static member op_Explicit: ^T -> byte) (value))

[<CompiledName("ToUInt8")>]
let inline uint8 value = byte value

[<NoDynamicInvocation(isLegacy=true)>]
[<CompiledName("ToSByte")>]
let inline sbyte (value: ^T) =
Expand All @@ -5516,6 +5530,9 @@ namespace Microsoft.FSharp.Core
when ^T : byte = (# "conv.ovf.i1.un" value : sbyte #)
when ^T : ^T = (^T : (static member op_Explicit: ^T -> sbyte) (value))

[<CompiledName("ToInt8")>]
let inline int8 value = sbyte value

[<NoDynamicInvocation(isLegacy=true)>]
[<CompiledName("ToUInt16")>]
let inline uint16 (value: ^T) =
Expand Down Expand Up @@ -7152,6 +7169,7 @@ namespace Microsoft.FSharp.Control
open Microsoft.FSharp.Core.Operators

module LazyExtensions =

type System.Lazy<'T> with
[<CompiledName("Create")>] // give the extension member a 'nice', unmangled compiled name, unique within this module
static member Create(creator : unit -> 'T) : Lazy<'T> =
Expand All @@ -7176,6 +7194,9 @@ namespace Microsoft.FSharp.Control

[<CompiledName("UnsynchronizedForceDeprecated")>] // give the extension member a 'nice', unmangled compiled name, unique within this module
member x.UnsynchronizedForce() = x.Value

[<CompiledName("LazyPattern")>]
let (|Lazy|) (input: Lazy<_>) = input.Force()

type Lazy<'T> = System.Lazy<'T>

Expand Down
Loading

0 comments on commit 6747af8

Please sign in to comment.