Comments (6)
What about a separate library targeting net9 (or "netcurrent" in general), which would be overwriting the lock
function and could be statically optimized for Lock
type.
from fsharp.
What about a separate library targeting net9 (or "netcurrent" in general), which would be overwriting the
lock
function and could be statically optimized forLock
type.
It can be done, sure (not by us currently though, we don't want additional nuget to support at this moment), the issue with it though is that it will either be only supporting Lock type and not any other or will have to do srtp magic.
I will experiment with it with my fsharp.core drop-in replacement.
from fsharp.
I don't think we can do a combination of statically optimized for "something" and being SRTP at the same time.
(or the compiler would have to be taught to do it).
Since the biggest motivation is to keep using lock
call inside codebases, and make it do "the right thing", adding separate differently-called functions will not do the trick here.
from fsharp.
Can't do much about this at the moment. Anyone moving to System.Threading.Lock
now should write their own function to work with it.
from fsharp.
Can't do much about this at the moment. Anyone moving to
System.Threading.Lock
now should write their own function to work with it.
I guess that would probably look something like this?
let inline lock (lockObject : System.Threading.Lock) ([<InlineIfLambda>] action) =
let mutable scope = lockObject.EnterScope ()
try action ()
finally scope.Dispose ()
And if somebody wanted to add support in their own codebase incrementally, I guess they could do something like the following, which uses a few tricks to be source-compatible with both old and new:
// ----------------------------------------------------------------
// Fake types for demo purposes, but with the real shapes.
module System =
module Threading =
module Lock =
[<Struct; System.Runtime.CompilerServices.IsByRefLike>]
type Scope =
member _.Dispose () = ()
[<Sealed>]
type Lock () =
member _.EnterScope () = Lock.Scope ()
// End fake types.
// ----------------------------------------------------------------
open System.Threading
[<Sealed; AbstractClass>]
type LockImpl = class end
[<AutoOpen>]
module LockPriority2 =
type LockImpl with
static member inline lock (lockObject : Lock) = fun action ->
let mutable scope = lockObject.EnterScope ()
try action ()
finally scope.Dispose ()
[<AutoOpen>]
module LockPriority1 =
type LockImpl with
static member inline lock lockObject = fun action ->
FSharp.Core.Operators.lock lockObject action
open type LockImpl
// Calls the overload equivalent to the existing function.
let f x = lock (obj ()) (fun () -> x)
// Calls the System.Threading.Lock-specific overload.
let g x = lock (Lock ()) (fun () -> x)
// lockObj still resolves to 'a when 'a : not struct by default.
let h lockObj x = lock lockObj (fun () -> x)
from fsharp.
Can't do much about this at the moment. Anyone moving to
System.Threading.Lock
now should write their own function to work with it.I guess that would probably look something like this?
let inline lock (lockObject : System.Threading.Lock) ([<InlineIfLambda>] action) = let mutable scope = lockObject.EnterScope () try action () finally scope.Dispose ()And if somebody wanted to add support in their own codebase incrementally, I guess they could do something like the following, which uses a few tricks to be source-compatible with both old and new:
// ---------------------------------------------------------------- // Fake types for demo purposes, but with the real shapes. module System = module Threading = module Lock = [<Struct; System.Runtime.CompilerServices.IsByRefLike>] type Scope = member _.Dispose () = () [<Sealed>] type Lock () = member _.EnterScope () = Lock.Scope () // End fake types. // ---------------------------------------------------------------- open System.Threading [<Sealed; AbstractClass>] type LockImpl = class end [<AutoOpen>] module LockPriority2 = type LockImpl with static member inline lock (lockObject : Lock) = fun action -> let mutable scope = lockObject.EnterScope () try action () finally scope.Dispose () [<AutoOpen>] module LockPriority1 = type LockImpl with static member inline lock lockObject = fun action -> FSharp.Core.Operators.lock lockObject action open type LockImpl // Calls the overload equivalent to the existing function. let f x = lock (obj ()) (fun () -> x) // Calls the System.Threading.Lock-specific overload. let g x = lock (Lock ()) (fun () -> x) // lockObj still resolves to 'a when 'a : null by default. let h lockObj x = lock lockObj (fun () -> x)
I have implemented it in a similar (ish) way in my experimental fslib
from fsharp.
Related Issues (20)
- [Automated] PRs inserted in VS build feature.debugger.shadowDebug-35227.190
- [Automated] PRs inserted in VS build main-35228.30
- `open type T` treated as unused when unqualified extension member on `T` used HOT 1
- `open type` does not bring enum cases into scope in patterns HOT 2
- [Automated] PRs inserted in VS build feature.debugger.main-35228.301
- Tooltip suggestion - show "allow ref struct" for typars of external types and methods
- Investigate why `IsMethod` and `IsProperty` don't act as expected for generated methods/properties
- No intellisense error or meaningful errormessage on Seq.iter build error. HOT 2
- Tests are broken in main in FSharp.Compiler.Service solution HOT 4
- Nullness issue - tooling - turning on <Nullable>enable</> removes detailed API descriptions in tooltips
- Ability to dump current interactive session to a file HOT 3
- Revert workaround - https://github.com/dotnet/fsharp/pull/15982 HOT 2
- `sprintf "%b" bool` causes AOT failure
- Runtime have a mutrec codegeneration issue. --- est failure: JIT/Directed/tailcall/mutual_recursion/mutual_recursion.cmd
- [Automated] PRs inserted in VS build main-35310.33
- Symbol check fails in VS insertions
- Visual F# Go to definition from Source Link HOT 1
- error FS0192 : internal error : Length of Nullable metadata and needs of its processing do not match: { Data = [|0uy; 1uy|] Idx = 2 } HOT 2
- [Automated] PRs inserted in VS build main-35311.19
- Array comprehension no longer compiles on rc1 HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fsharp.