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

Generic struct type whose fields are all unmanaged types is unmanaged #692

Open
3 of 4 tasks
dzmitry-lahoda opened this issue Sep 10, 2018 · 6 comments
Open
3 of 4 tasks

Comments

@dzmitry-lahoda
Copy link

dzmitry-lahoda commented Sep 10, 2018

Generic struct type whose fields are all unmanaged types is unmanaged

A non-generic struct type whose fields are all unmanaged types is unmanaged.

into

A generic struct type whose fields are all unmanaged types is unmanaged.

as

The unmanaged constraint on generic type T enforces the type to be an 'unmanaged' struct that does not recursively contain reference type fields.

as for cases

type Cell<'T when 'T: unmanaged> =
    struct
        val element: 'T
        val next: nativeptr<Cell<'T>>
    end    

type UnmanagedCell<'T when 'T: unmanaged> =
    struct
    end  

[<EntryPoint>]
let main argv =
    let fine = UnmanagedCell<int>()
    let FS0001 = UnmanagedCell<UnmanagedCell<int>>()
    0

The existing way of approaching this problem in F# is prevent compilation with error

error FS0001: A generic construct requires that the type 'X' is an unmanaged type

I have asked the question on SO and found that it is F# limitation, not CLR.

Pros and Cons

See Related suggestions

Extra information

Related suggestions:
dotnet/csharplang#1504
dotnet/csharplang#1649

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • [x ] This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this
@TIHan
Copy link

TIHan commented Jan 5, 2019

This is actually quite easy to implement and it should not be a breaking change. We should make this change to follow C#.

@TIHan
Copy link

TIHan commented Jan 5, 2019

We would also need to interop with C# by looking at the IsUnmanagedAttribute on the type argument and be able to emit it as well.

@abelbraaksma
Copy link

abelbraaksma commented Jan 5, 2019

For reference, here's a link to the original PR for C#, which is now merged: dotnet/roslyn#31148.

Edit: apparently more work was done on several PR's, here's all: https://github.com/dotnet/roslyn/commits/features/unmanaged-constructed-types.

@cartermp
Copy link
Member

cartermp commented Jan 5, 2019

@TIHan as a part of this we should also update the Span 'n Friends RFC

@TIHan
Copy link

TIHan commented Jan 6, 2019

Yes and we would need to update docs as well.

@TIHan
Copy link

TIHan commented Jan 6, 2019

I have a PR for this: dotnet/fsharp#6064

vzarytovskii added a commit to vzarytovskii/fslang-design that referenced this issue Jun 28, 2020
cartermp added a commit to fsharp/fslang-design that referenced this issue Jul 27, 2020
* Added an RFC for fsharp/fslang-suggestions#692

* Simplify summary

* Added more verbose error message example; Change wording in the detailed design

* Added more examples; Added description of the unmanaged types; Added supportedd types section; Updated motivation section

* Update RFCs/FS-1090-Generic-struct-type-whose-fields-are-all-unmanaged-types-is-unmanaged.md

Co-authored-by: Phillip Carter <pcarter@fastmail.com>

* Update RFCs/FS-1090-Generic-struct-type-whose-fields-are-all-unmanaged-types-is-unmanaged.md

Co-authored-by: Phillip Carter <pcarter@fastmail.com>

* Update RFCs/FS-1090-Generic-struct-type-whose-fields-are-all-unmanaged-types-is-unmanaged.md

Co-authored-by: Phillip Carter <pcarter@fastmail.com>

* Update RFCs/FS-1090-Generic-struct-type-whose-fields-are-all-unmanaged-types-is-unmanaged.md

Co-authored-by: Phillip Carter <pcarter@fastmail.com>

* Update RFCs/FS-1090-Generic-struct-type-whose-fields-are-all-unmanaged-types-is-unmanaged.md

Co-authored-by: Phillip Carter <pcarter@fastmail.com>

* Update RFCs/FS-1090-Generic-struct-type-whose-fields-are-all-unmanaged-types-is-unmanaged.md

Co-authored-by: Phillip Carter <pcarter@fastmail.com>

* Update RFCs/FS-1090-Generic-struct-type-whose-fields-are-all-unmanaged-types-is-unmanaged.md

Co-authored-by: Phillip Carter <pcarter@fastmail.com>

* Address RFC comments; Added modreq requirement; Added more examples; Re-phrased some definitions

* Update RFCs/FS-1090-Generic-struct-type-whose-fields-are-all-unmanaged-types-is-unmanaged.md

Co-authored-by: Phillip Carter <pcarter@fastmail.com>

* Update RFCs/FS-1090-Generic-struct-type-whose-fields-are-all-unmanaged-types-is-unmanaged.md

Co-authored-by: Phillip Carter <pcarter@fastmail.com>

* Update RFCs/FS-1090-Generic-struct-type-whose-fields-are-all-unmanaged-types-is-unmanaged.md

Co-authored-by: Phillip Carter <pcarter@fastmail.com>

* Update RFCs/FS-1090-Generic-struct-type-whose-fields-are-all-unmanaged-types-is-unmanaged.md

Co-authored-by: Phillip Carter <pcarter@fastmail.com>

* Address PR comments.

Co-authored-by: Phillip Carter <pcarter@fastmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants