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

Add support for C# Experimental attribute #18253

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

edgarfgp
Copy link
Contributor

@edgarfgp edgarfgp commented Jan 20, 2025

Description

Fixes #18198

Checklist

  • Test cases added
  • Release notes entry updated

Copy link
Contributor

github-actions bot commented Jan 20, 2025

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/9.0.300.md

@edgarfgp edgarfgp changed the title Add support C# Experimental attribute Add support for C# Experimental attribute Jan 20, 2025
@edgarfgp edgarfgp marked this pull request as ready for review January 22, 2025 22:04
@edgarfgp edgarfgp requested a review from a team as a code owner January 22, 2025 22:04
@@ -1795,7 +1794,7 @@ type Exception with
if s <> "" then
os.AppendString(Obsolete2E().Format s)

| Experimental(s, _) -> os.AppendString(ExperimentalE().Format s)
| Experimental(message = s) -> os.AppendString(ExperimentalE().Format s)
Copy link
Member

Choose a reason for hiding this comment

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

I propose the message includes the added properties if they were present even in plain (text output) build results.

Copy link
Member

Choose a reason for hiding this comment

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

Especially the ID might be something useful for searching with.
The url would be better a clicklable, but at least plaintext for command line builds is IMO also beneficial.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Experimental attribute does not have a message property for now. It seems that will be added in the next mayor version to match the obsolete attribute See.
dotnet/runtime#108216

But I think we can handle this so it will work when it is available for us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding the DiagnosticId We have 2 options:

  • Use the provided id from the attribute [Experimental(diagnosticId: "MY001")] as a error number which potentially might collide with existing error numbers.
  • Use 57 like we do in F# but that will defeat the purpose of the diagnosticId

I guess the problem is to report the experimental as error number 57 and then show a diagnostic id was part the error text which will be confusing ?

@@ -78,6 +78,17 @@ module ExtendedData =
/// Represents the URL format of the diagnostic
member this.UrlFormat: string = urlFormat

/// Additional data for diagnostics about experimental attributes.
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
type ExperimentalExtendedData
Copy link
Member

Choose a reason for hiding this comment

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

Are non-nullable strings the correct signature?
Is there a particular reason for representing missing attribute with an empty string here?

(Is it e.g. what the attribute does when e.g. scanned via reflection at runtime ? )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will have to check

@@ -133,6 +133,8 @@ exception DiagnosticWithSuggestions of number: int * message: string * range: ra
/// A diagnostic that is raised when enabled manually, or by default with a language feature
exception DiagnosticEnabledWithLanguageFeature of number: int * message: string * range: range * enabledByLangFeature: bool

exception ObsoleteDiagnostic of isError: bool * diagnosticId: string * message: string * urlFormat: string * range: range
Copy link
Member

Choose a reason for hiding this comment

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

Like for Experimental, are we representing absence of information via "" because this is what the attribute does in C# or when extracted at runtime?

@KevinRansom
Copy link
Member

Is there some reason this is insufficient?

https://github.com/dotnet/fsharp/blob/main/src/FSharp.Core/prim-types.fs#L265

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

Successfully merging this pull request may close these issues.

F# compiler does not respect ExperimentalAttribute
3 participants