-
Notifications
You must be signed in to change notification settings - Fork 790
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
Volatile.Read
can no longer read ref
(instead it wants inref
)
#16524
Comments
Actually, let me double check, it. It sounds like a different issue. Though refs and byrefs are different things. |
Is it really the same thing? Because #16265 says it has been fixed 2 days ago. But to me it seems the problem was just introduced. |
This problem was introduced with fix of dotnet/runtime#94317, not entirely sure what's happening. |
Immediate workaround would be to make it a open System;
open System.Threading
type Data = { Timestamp: DateTimeOffset }
let mutable currentData: Data =
{ Timestamp = DateTimeOffset.MinValue }
let x = Volatile.Read ¤tData or open System;
open System.Threading
type Data = { Timestamp: DateTimeOffset }
let mutable currentData: Data ref =
ref { Timestamp = DateTimeOffset.MinValue }
let x = Volatile.Read ¤tData Until I figure out why don't we resolve the method anymore. |
Ok, I think I understand what's going on, here's timeline:
I don't exactly know right now what can be done. Can we safely convert F# refs (not byrefs) to inrefs? @T-Gro @dsyme I guess yes, if bindings are not mutable? |
To recap:
So, this is not exactly a bug in compiler, but a change in BCL which caused that (since |
F# compiler could convert a RefCell to inref to overcome this breaking change, that should work. |
But probably non-mutable refcell to inref, right? Or any? |
@T-Gro what bothers me slightly, we have the following in our method calls checking: // If the called method argument is an inref type, then the caller may provide a byref or value
So, it was a conscious decision to restrict it to only refs and byrefs. |
I think it shouldn't be fixed and considered by design (since it is, and changing it will be changing spec/RFC), since it's a change in BCL method signature ( I am going to close it for the said reason, feel free to open language suggestion for having ref readonly/inref parameters to be "compatible" and "convertible" with ref cells. |
Please provide a succinct description of the issue.
Repro steps
I have a following global variable defined in a module
and I read its value in some function via
Volatile.Read
:Expected behavior
The code should type check (it type checked on net7 and also initially on net8).
Actual behavior
After updating .NET 8 it doesn't type check with error:
I think that the last mentioned overload should work but it seems that
ref<Data>
argumentcan't be given to
inref<Data>
parameter.Known workarounds
Don't know.
Related information
Provide any related information (optional):
The text was updated successfully, but these errors were encountered: