Skip to content

Commit c06ede4

Browse files
committed
Operators
1 parent 9eb672b commit c06ede4

18 files changed

+743
-42
lines changed

Diff for: docs/release-notes/.FSharp.Compiler.Service/8.0.400.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* 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))
3131

3232
### Changed
33+
* `Initial refactoring of FSharp.Core` ([Issues #17372](https://github.com/dotnet/fsharp/issues/17372), [PR #17370](https://github.com/dotnet/fsharp/pull/17370))
3334
* Enforce `AttributeTargets.Interface` ([PR #17173](https://github.com/dotnet/fsharp/pull/17173))
3435
* Minor compiler perf improvements. ([PR #17130](https://github.com/dotnet/fsharp/pull/17130))
3536
* 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))

Diff for: docs/release-notes/.FSharp.Core/8.0.400.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

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

1213
### Breaking Changes
1314

Diff for: src/Compiler/Driver/CompilerConfig.fs

+7-4
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ let ComputeMakePathAbsolute implicitIncludeDir (path: string) =
122122
with :? ArgumentException ->
123123
path
124124

125-
let isCoreLibrary compilingLibraryName =
126-
compilingLibraryName = "FSharp.Core"
125+
let isCoreLibrary compilingLibraryName = compilingLibraryName = "FSharp.Core"
127126

128127
//----------------------------------------------------------------------------
129128
// Configuration
@@ -1234,7 +1233,10 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
12341233
member _.noFeedback = data.noFeedback
12351234
member _.stackReserveSize = data.stackReserveSize
12361235
member _.implicitIncludeDir = data.implicitIncludeDir
1237-
member _.openDebugInformationForLaterStaticLinking = data.openDebugInformationForLaterStaticLinking
1236+
1237+
member _.openDebugInformationForLaterStaticLinking =
1238+
data.openDebugInformationForLaterStaticLinking
1239+
12381240
member _.fsharpBinariesDir = data.defaultFSharpBinariesDir
12391241
member _.compilingLibraryName = data.compilingLibraryName
12401242
member _.useIncrementalBuilder = data.useIncrementalBuilder
@@ -1470,7 +1472,8 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
14701472

14711473
member tcConfig.GenerateOptimizationData = tcConfig.GenerateSignatureData
14721474

1473-
member tcConfig.assumeDotNetFramework = tcConfig.primaryAssembly = PrimaryAssembly.Mscorlib
1475+
member tcConfig.assumeDotNetFramework =
1476+
tcConfig.primaryAssembly = PrimaryAssembly.Mscorlib
14741477

14751478
member tcConfig.compilingCoreLibrary = isCoreLibrary tcConfig.compilingLibraryName
14761479

Diff for: src/FSharp.Core/FSharp.Core.fsproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<OtherFlags>$(OtherFlags) --nowarn:3511</OtherFlags>
2626
<!-- Turn off 3513: resumable code invocation' - expected for resumable code combinators -->
2727
<OtherFlags>$(OtherFlags) --nowarn:3513</OtherFlags>
28-
<OtherFlags>$(OtherFlags) --compiling-fslib --compiling-fslib-40 --maxerrors:100 --extraoptimizationloops:1</OtherFlags>
28+
<OtherFlags>$(OtherFlags) --compiling-fslib --maxerrors:100 --extraoptimizationloops:1</OtherFlags>
2929
<!-- .tail annotations always emitted for this binary, even in debug mode -->
3030
<Tailcalls>true</Tailcalls>
3131
<PreRelease>true</PreRelease>

Diff for: src/FSharp.Core/Linq.fs

+6-6
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ module LeafExpressionConverter =
345345
let (|ConvIntPtrQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Operators.nativeint))
346346
let (|ConvUIntPtrQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Operators.unativeint))
347347

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

353353
let (|ConvNullableCharQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Nullable.char))
354354
let (|ConvNullableDecimalQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Nullable.decimal))
@@ -374,8 +374,8 @@ module LeafExpressionConverter =
374374
let (|TypeTestGeneric|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun x -> LanguagePrimitives.IntrinsicFunctions.TypeTestGeneric x))
375375
let (|CheckedConvCharQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Checked.char))
376376
let (|CheckedConvSByteQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Checked.sbyte))
377-
let (|CheckedConvInt8Q|_|) = SpecificCallToMethodInfo (typeof<ConvEnv>.Assembly.GetType("Microsoft.FSharp.Core.ExtraTopLevelOperators+Checked").GetMethod("ToSByte"))
378-
let (|CheckedConvUInt8Q|_|) = SpecificCallToMethodInfo (typeof<ConvEnv>.Assembly.GetType("Microsoft.FSharp.Core.ExtraTopLevelOperators+Checked").GetMethod("ToByte"))
377+
let (|CheckedConvInt8Q|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun x -> Operators.Checked.int8 x))
378+
let (|CheckedConvUInt8Q|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun x -> Operators.Checked.uint8 x))
379379
let (|CheckedConvInt16Q|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Checked.int16))
380380
let (|CheckedConvInt32Q|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Checked.int32))
381381
let (|CheckedConvInt64Q|_|) = (|SpecificCallToMethod|_|) (methodhandleof (Checked.int64))

Diff for: src/FSharp.Core/async.fs

+3
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,9 @@ type Async =
22462246

22472247
module CommonExtensions =
22482248

2249+
[<CompiledName("DefaultAsyncBuilder")>]
2250+
let async = AsyncBuilder()
2251+
22492252
type System.IO.Stream with
22502253

22512254
[<CompiledName("AsyncRead")>] // give the extension member a 'nice', unmangled compiled name, unique within this module

Diff for: src/FSharp.Core/async.fsi

+18
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,24 @@ namespace Microsoft.FSharp.Control
13941394
[<AutoOpen>]
13951395
module CommonExtensions =
13961396

1397+
/// <summary>Builds an asynchronous workflow using computation expression syntax.</summary>
1398+
///
1399+
/// <example id="async-1">
1400+
/// <code lang="fsharp">
1401+
/// let sleepExample() =
1402+
/// async {
1403+
/// printfn "sleeping"
1404+
/// do! Async.Sleep 10
1405+
/// printfn "waking up"
1406+
/// return 6
1407+
/// }
1408+
///
1409+
/// sleepExample() |> Async.RunSynchronously
1410+
/// </code>
1411+
/// </example>
1412+
[<CompiledName("DefaultAsyncBuilder")>]
1413+
val async: AsyncBuilder
1414+
13971415
type System.IO.Stream with
13981416

13991417
/// <summary>Returns an asynchronous computation that will read from the stream into the given buffer.</summary>

Diff for: src/FSharp.Core/fslib-extra-pervasives.fs

+8-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module ExtraTopLevelOperators =
66

77
open System
88
open System.Collections.Generic
9+
open System.ComponentModel
910
open System.IO
1011
open System.Diagnostics
1112
open Microsoft.FSharp
@@ -280,32 +281,32 @@ module ExtraTopLevelOperators =
280281
let eprintfn format =
281282
Printf.eprintfn format
282283

283-
[<CompiledName("DefaultAsyncBuilder")>]
284+
[<CompiledName("DefaultAsyncBuilder"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
284285
let async = AsyncBuilder()
285286

286-
[<CompiledName("ToSingle")>]
287+
[<CompiledName("ToSingle"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
287288
let inline single value =
288289
float32 value
289290

290-
[<CompiledName("ToDouble")>]
291+
[<CompiledName("ToDouble"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
291292
let inline double value =
292293
float value
293294

294-
[<CompiledName("ToByte")>]
295+
[<CompiledName("ToByte"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
295296
let inline uint8 value =
296297
byte value
297298

298-
[<CompiledName("ToSByte")>]
299+
[<CompiledName("ToSByte"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
299300
let inline int8 value =
300301
sbyte value
301302

302303
module Checked =
303304

304-
[<CompiledName("ToByte")>]
305+
[<CompiledName("ToByte"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
305306
let inline uint8 value =
306307
Checked.byte value
307308

308-
[<CompiledName("ToSByte")>]
309+
[<CompiledName("ToSByte"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
309310
let inline int8 value =
310311
Checked.sbyte value
311312

Diff for: src/FSharp.Core/fslib-extra-pervasives.fsi

+9-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Microsoft.FSharp.Core
99
[<AutoOpen>]
1010
module ExtraTopLevelOperators =
1111

12+
open System.ComponentModel
1213
open System.IO
1314
open Microsoft.FSharp.Core
1415
open Microsoft.FSharp.Control
@@ -130,7 +131,7 @@ module ExtraTopLevelOperators =
130131
/// sleepExample() |> Async.RunSynchronously
131132
/// </code>
132133
/// </example>
133-
[<CompiledName("DefaultAsyncBuilder")>]
134+
[<CompiledName("DefaultAsyncBuilder"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
134135
val async: AsyncBuilder
135136

136137
/// <summary>Converts the argument to 32-bit float.</summary>
@@ -144,7 +145,7 @@ module ExtraTopLevelOperators =
144145
/// </code>
145146
/// Evaluates to <c>45.0f</c>.
146147
/// </example>
147-
[<CompiledName("ToSingle")>]
148+
[<CompiledName("ToSingle"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
148149
val inline single: value: ^T -> single when ^T : (static member op_Explicit : ^T -> single) and default ^T : int
149150

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

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

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

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

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

248249
/// <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>
@@ -339,7 +340,7 @@ module ExtraTopLevelOperators =
339340
/// </code>
340341
/// Evaluates to <c>10</c>. The text <c>eval!</c> is printed once on the first invocation of <c>f</c>.
341342
/// </example>
342-
[<CompiledName("LazyPattern")>]
343+
[<CompiledName("LazyPattern"); EditorBrowsableAttribute(EditorBrowsableState.Never)>]
343344
val (|Lazy|): input: Lazy<'T> -> 'T
344345

345346
/// <summary>Builds a query using query syntax and operators.</summary>

Diff for: src/FSharp.Core/prim-types.fs

+21
Original file line numberDiff line numberDiff line change
@@ -4742,6 +4742,9 @@ namespace Microsoft.FSharp.Core
47424742
// this condition is used whenever ^T is resolved to a nominal type or witnesses are available
47434743
when ^T : ^T = (^T : (static member op_Explicit: ^T -> byte) (value))
47444744

4745+
[<CompiledName("ToUInt8")>]
4746+
let inline uint8 value = byte value
4747+
47454748
[<NoDynamicInvocation(isLegacy=true)>]
47464749
[<CompiledName("ToSByte")>]
47474750
let inline sbyte (value: ^T) =
@@ -4764,6 +4767,10 @@ namespace Microsoft.FSharp.Core
47644767
// this condition is used whenever ^T is resolved to a nominal type or witnesses are available
47654768
when ^T : ^T = (^T : (static member op_Explicit: ^T -> sbyte) (value))
47664769

4770+
4771+
[<CompiledName("ToInt8")>]
4772+
let inline int8 value = sbyte value
4773+
47674774
[<NoDynamicInvocation(isLegacy=true)>]
47684775
[<CompiledName("ToUInt16")>]
47694776
let inline uint16 (value: ^T) =
@@ -4944,6 +4951,8 @@ namespace Microsoft.FSharp.Core
49444951
when ^T : byte = (# "conv.r.un conv.r4" value : float32 #)
49454952
when ^T : ^T = (^T : (static member op_Explicit: ^T -> float32) (value))
49464953

4954+
let inline single value = float32 value
4955+
49474956
[<NoDynamicInvocation(isLegacy=true)>]
49484957
[<CompiledName("ToDouble")>]
49494958
let inline float (value: ^T) =
@@ -4966,6 +4975,8 @@ namespace Microsoft.FSharp.Core
49664975
when ^T : decimal = (Convert.ToDouble((# "" value : decimal #)))
49674976
when ^T : ^T = (^T : (static member op_Explicit: ^T -> float) (value))
49684977

4978+
let inline double value = float value
4979+
49694980
[<NoDynamicInvocation(isLegacy=true)>]
49704981
[<CompiledName("ToDecimal")>]
49714982
let inline decimal (value: ^T) =
@@ -5496,6 +5507,9 @@ namespace Microsoft.FSharp.Core
54965507
when ^T : byte = (# "" value : byte #)
54975508
when ^T : ^T = (^T : (static member op_Explicit: ^T -> byte) (value))
54985509

5510+
[<CompiledName("ToUInt8")>]
5511+
let inline uint8 value = byte value
5512+
54995513
[<NoDynamicInvocation(isLegacy=true)>]
55005514
[<CompiledName("ToSByte")>]
55015515
let inline sbyte (value: ^T) =
@@ -5516,6 +5530,9 @@ namespace Microsoft.FSharp.Core
55165530
when ^T : byte = (# "conv.ovf.i1.un" value : sbyte #)
55175531
when ^T : ^T = (^T : (static member op_Explicit: ^T -> sbyte) (value))
55185532

5533+
[<CompiledName("ToInt8")>]
5534+
let inline int8 value = sbyte value
5535+
55195536
[<NoDynamicInvocation(isLegacy=true)>]
55205537
[<CompiledName("ToUInt16")>]
55215538
let inline uint16 (value: ^T) =
@@ -7152,6 +7169,7 @@ namespace Microsoft.FSharp.Control
71527169
open Microsoft.FSharp.Core.Operators
71537170

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

71777195
[<CompiledName("UnsynchronizedForceDeprecated")>] // give the extension member a 'nice', unmangled compiled name, unique within this module
71787196
member x.UnsynchronizedForce() = x.Value
7197+
7198+
[<CompiledName("LazyPattern")>]
7199+
let (|Lazy|) (input: Lazy<_>) = input.Force()
71797200

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

0 commit comments

Comments
 (0)