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

Init-only & required properties support #13490

Merged
merged 22 commits into from
Jul 29, 2022

Conversation

vzarytovskii
Copy link
Member

@vzarytovskii vzarytovskii commented Jul 11, 2022

@vzarytovskii vzarytovskii self-assigned this Jul 11, 2022
@vzarytovskii vzarytovskii added the Area-Compiler-ImportAndInterop import of .NET DLLs and interop label Jul 11, 2022
@vzarytovskii vzarytovskii added this to the July-2022 milestone Jul 11, 2022
@vzarytovskii vzarytovskii linked an issue Jul 11, 2022 that may be closed by this pull request
@vzarytovskii
Copy link
Member Author

I will need to add one more language feature, and hide init-only checking under it, so F#6 continues to allow current behaviour.

@vzarytovskii vzarytovskii changed the title WIP Init-only & required properties support Init-only & required properties support Jul 15, 2022
@vzarytovskii
Copy link
Member Author

This is ready for a first wave of reviews.
cc @dsyme

@vzarytovskii vzarytovskii removed this from the July-2022 milestone Jul 15, 2022
@dsyme
Copy link
Contributor

dsyme commented Jul 16, 2022

System.Exception : Unable to emit C# compilation.
seq
[(26,48): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported;
(15,43): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported]

@vzarytovskii
Copy link
Member Author

vzarytovskii commented Jul 16, 2022

System.Exception : Unable to emit C# compilation.
seq
[(26,48): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported;
(15,43): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported]

That is okay, C# compiler cannot find the attribute in the net472 runtime, it's known, i will fix it.

Quote from Jared:

The IsExternalInit type is only included in the net5.0 (and future) target frameworks. When compiling against older target frameworks you will need to manually define this type.

src/Compiler/FSComp.txt Outdated Show resolved Hide resolved
src/Compiler/Checking/CheckExpressions.fs Outdated Show resolved Hide resolved
src/Compiler/TypedTree/TcGlobals.fs Outdated Show resolved Hide resolved
src/Compiler/Checking/AttributeChecking.fs Outdated Show resolved Hide resolved
src/Compiler/Checking/CheckExpressions.fs Outdated Show resolved Hide resolved
src/Compiler/Checking/CheckExpressions.fs Outdated Show resolved Hide resolved
src/Compiler/Checking/CheckExpressions.fs Show resolved Hide resolved
src/Compiler/Checking/CheckExpressions.fs Outdated Show resolved Hide resolved
src/Compiler/Checking/CheckExpressions.fs Outdated Show resolved Hide resolved
src/Compiler/Checking/infos.fs Show resolved Hide resolved
@vzarytovskii
Copy link
Member Author

vzarytovskii commented Jul 22, 2022

@dsyme Addressed all comments except 1 (not entirely sure whether we should warn user when they place RequiredMemberAttribute or not).

@vzarytovskii
Copy link
Member Author

We may want to retarget this feature to 17.4, and update sdk to .NET7-preview, since it will be much easier to test runtime features without the need of adding attributes ourselves.

@vzarytovskii vzarytovskii requested review from dsyme and 0101 July 25, 2022 16:24
@vzarytovskii
Copy link
Member Author

Added attributes to unsupported ones, compiler will produce a warning for them if used in F# code.

Copy link
Member

@KevinRansom KevinRansom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@@ -1562,6 +1579,16 @@ type ILPropInfo =
/// Indicates if the IL property has a 'set' method
member x.HasSetter = Option.isSome x.RawMetadata.SetMethod

/// Indidcates whether IL property has an init-only setter (i.e. has the `System.Runtime.CompilerServices.IsExternalInit` modifer)
member x.IsSetterInitOnly =
assert x.HasSetter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably shouldn't be here.

src/Compiler/Checking/infos.fs Outdated Show resolved Hide resolved
src/Compiler/Checking/CheckExpressions.fs Show resolved Hide resolved
src/Compiler/Checking/CheckExpressions.fs Outdated Show resolved Hide resolved
src/Compiler/Checking/CheckExpressions.fs Outdated Show resolved Hide resolved
@vzarytovskii vzarytovskii requested a review from 0101 July 28, 2022 12:43
dsyme
dsyme previously requested changes Jul 28, 2022
Copy link
Contributor

@dsyme dsyme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of small changes needed

@dsyme
Copy link
Contributor

dsyme commented Jul 28, 2022

@vzarytovskii A couple of small changes needed - Please feel free to clear my review after you've addressed them, no 2nd review needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-ImportAndInterop import of .NET DLLs and interop
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Tracking Init properties and required members support
4 participants