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

Support ref readonly parameters #16222

Closed
vzarytovskii opened this issue Nov 2, 2023 · 5 comments
Closed

Support ref readonly parameters #16222

vzarytovskii opened this issue Nov 2, 2023 · 5 comments
Assignees
Labels
Milestone

Comments

@vzarytovskii
Copy link
Member

vzarytovskii commented Nov 2, 2023

Ref readonly are encoded as inrefs ([in] &T) with special attribute: https://github.com/jjonescz/csharplang/blob/5134bd7042bcd71dbddbdff618b9b63dc54775a0/proposals/ref-readonly-parameters.md#metadata-encoding

More info: https://discord.com/channels/143867839282020352/312132327348240384/1169766448063856650

Update 1: Intermediate ad-hoc fix (#16232) treats ref readonly as if it was inert in parameters. Proper fix should be introducing new byref type - readonlyref<_>, which should be a long-term fix.

cc @Tarmil @Sergio0694 @TIHan

@teo-tsirpanis
Copy link
Contributor

My understanding is that inref<_> is already equivalent to C#'s ref readonly. You cannot pass an rvalue to an inref<_> for example.

If you want to fix inref and support passing rvalues to it, maybe the issue should be reworded accordingly.

@nodakai
Copy link

nodakai commented Dec 7, 2023

F# 8.0.100 sees a ref readonly parameter as a byref parameter, broke my code

Available overloads:
- Unsafe.AsRef<'T>(source: byref<'T>) : byref<'T> // Argument 'source' doesn't match
- Unsafe.AsRef<'T>(source: voidptr) : byref<'T> // Argument 'source' doesn't match

C.f. dotnet/runtime#93251 (comment)

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafe.asref?view=net-8.0#system-runtime-compilerservices-unsafe-asref-1(-0@)

@vzarytovskii
Copy link
Member Author

My understanding is that inref<_> is already equivalent to C#'s ref readonly. You cannot pass an rvalue to an inref<_> for example.

If you want to fix inref and support passing rvalues to it, maybe the issue should be reworded accordingly.

Yeah. I actually think I'm going to close it now, since we have an ad-hoc fix which works, and it should be a small rfc if we want any additional support.

@vzarytovskii
Copy link
Member Author

F# 8.0.100 sees a ref readonly parameter as a byref parameter, broke my code


Available overloads:

- Unsafe.AsRef<'T>(source: byref<'T>) : byref<'T> // Argument 'source' doesn't match

- Unsafe.AsRef<'T>(source: voidptr) : byref<'T> // Argument 'source' doesn't match

C.f. dotnet/runtime#93251 (comment)

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafe.asref?view=net-8.0#system-runtime-compilerservices-unsafe-asref-1(-0@)

Yes, it's known. BCL changed the API and we didn't have much time to revert or fix on F# side. 8.0.101 should have the fix with will treat ref readonly as inrefs.

@vzarytovskii vzarytovskii closed this as not planned Won't fix, can't repro, duplicate, stale Dec 7, 2023
@nodakai
Copy link

nodakai commented Jan 21, 2024

8.0.101 should have the fix with will treat ref readonly as inrefs.

8.0.101 seems to be working fine for me. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants