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 LanguageVersion 10 #54359

Merged
merged 4 commits into from
Jun 24, 2021
Merged

Add LanguageVersion 10 #54359

merged 4 commits into from
Jun 24, 2021

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Jun 24, 2021

Fixes #53857

This PR:

  • adds LanguageVersion.CSharp10, makes it the current version and attaches the new feature that are in main already to it
  • attaches the variance safety feature to C# 9 where it was meant to ship
  • leaves most usages of LanguageVersion.Preview and TestOptions.RegularPreview in tests as-is
  • changes the default used by test APIs like CreateCompilation to use LanguageVersion.Preview, so most new tests don't have to specify a language version at all
  • introduces TestOptions.RegularNext and LanguageVersionFacts.CSharpNext. Those should be used in new tests that are specifically about language version. We'll do a search&replace

@jcouv jcouv added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Jun 24, 2021
@jcouv jcouv self-assigned this Jun 24, 2021
@jcouv jcouv force-pushed the langver-10 branch 2 times, most recently from 322d150 to bb957a3 Compare June 24, 2021 15:41
@jcouv jcouv removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Jun 24, 2021
@jcouv jcouv force-pushed the langver-10 branch 3 times, most recently from 804a63e to f236add Compare June 24, 2021 19:14
@jcouv jcouv marked this pull request as ready for review June 24, 2021 19:29
@jcouv jcouv requested review from a team as code owners June 24, 2021 19:29
@jcouv jcouv added this to the C# 10 milestone Jun 24, 2021
@@ -876,7 +876,7 @@ public static SyntaxTree Parse(string text, string filename = "", CSharpParseOpt
{
if ((object)options == null)
{
options = TestOptions.Regular;
options = TestOptions.RegularPreview;
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 This changes the default for tests using APIs like CreateCompilation.

@@ -17,6 +17,10 @@
<_MaxSupportedLangVersion Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' == '5.0' AND
'$(_MaxSupportedLangVersion)' == ''">9.0</_MaxSupportedLangVersion>

<!-- .NETCoreApp == 6.0 -->
<_MaxSupportedLangVersion Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' == '6.0' AND
'$(_MaxSupportedLangVersion)' == ''">10.0</_MaxSupportedLangVersion>
Copy link
Member Author

Choose a reason for hiding this comment

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

@chsienki The LanguageVersionGivenTargetFramework test was good at catching the new language version :-)
Can you take a look?

I left GeneratorDriver with a LanguageVersion.Preview check at the moment (based on offline discussion).

Copy link
Member

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

IDE side LGTM

@RikkiGibson RikkiGibson self-assigned this Jun 24, 2021
| [Mix declarations and variables in deconstruction](https://github.com/dotnet/csharplang/issues/125) | main | [Merged into 16.10](https://github.com/dotnet/roslyn/issues/47746) | [YairHalberstadt ](https://github.com/YairHalberstadt) | [jcouv](https://github.com/jcouv) | [MadsTorgersen](https://github.com/MadsTorgersen) |
| [List patterns](https://github.com/dotnet/csharplang/issues/3435) | [list-patterns](https://github.com/dotnet/roslyn/tree/features/list-patterns) | [In Progress](https://github.com/dotnet/roslyn/issues/51289) | [alrz](https://github.com/alrz) | [jcouv](https://github.com/jcouv), [333fred](https://github.com/333fred) | [333fred](https://github.com/333fred) |

# C# 10.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have individually done this at the time we marked the features merged?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nah, it's fine. But it would be good if features that get merged following this PR updated this doc individually.

Copy link
Contributor

@chsienki chsienki left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -115,18 +115,18 @@ class C
";
var compilation = CreateCompilationWithMscorlib45(source, parseOptions: TestOptions.Regular9);
compilation.VerifyDiagnostics(
// (11,25): error CS8652: The feature 'async method builder override' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// (11,25): error CS8773: Feature 'async method builder override' is not available in C# 9.0. Please use language version 10.0 or greater.
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like even with the new scheme of "use LanguageVersionFacts.CSharpNext" we still have this churn of updating diagnostic IDs when we snap off a new language version.

When we snap a language version, should we also introduce an error code specific to 'C# vNext' which becomes the ERR_FeatureNotAvailableInVersionN error code when the language version gets snapped? (although this perhaps doesn't work for features like static abstracts in interfaces where we don't yet know what language version they are likely to ship in.)

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right that such diagnostics will still churn. We can explore some mitigations when we start working on C# 11.

@@ -1337,7 +1339,7 @@ public void Incremental_Generators_Exception_During_Execution()
var source = @"
class C { }
";
var parseOptions = TestOptions.Regular.WithLanguageVersion(LanguageVersion.Preview);
var parseOptions = TestOptions.RegularPreview;
Copy link
Member

@cston cston Jun 24, 2021

Choose a reason for hiding this comment

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

RegularPreview

Regular10 or Regular here and below?

Copy link
Member Author

Choose a reason for hiding this comment

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

The GeneratorDriver only uses incremental general when LangVer==Preview at the moment. That is kept that way intentionally (based on chat with Chris).

@jcouv jcouv merged commit 9e30164 into dotnet:main Jun 24, 2021
@ghost ghost modified the milestones: C# 10, Next Jun 24, 2021
@jcouv jcouv deleted the langver-10 branch June 24, 2021 22:39
@PathogenDavid
Copy link
Contributor

@jcouv Just to clarify: The features now listed under C# Next are still (tentatively) planned for C# 10 but just haven't merged to main, right?

@jcouv
Copy link
Member Author

jcouv commented Jun 25, 2021

@PathogenDavid Yes. Most are still in progress for C# 10. Which one are you asking about?

@PathogenDavid
Copy link
Contributor

PathogenDavid commented Jun 25, 2021

@jcouv Thanks for confirming!

As boring as it might sound, parameterless struct constructors is the main C# 10 feature I care about.

It's something that'd really help Biohazrd since we wrap arbitrary C++ code and C++ uses parameterless constructors a lot. Currently parameterless constructors are a weird edge case that creates awkward friction, enough so that I was investigating maintaining a soft fork of Roslyn at one point just to build the generated wrappers. (My main sponsor wants to standardize on .NET 6 since it'll be LTS, so it'd be really disappointing to see the feature bumped again.)

It appears to me like the PR for it is purring along smoothly, but if there's anything I can do to help with it definitely let me know.

@jcouv
Copy link
Member Author

jcouv commented Jun 25, 2021

@PathogenDavid Parameterless struct constructors are still on track for C# 10. Should be in dev17.0p3.

| [Async method builder override](https://github.com/dotnet/csharplang/issues/1407) | main | [In Progress](https://github.com/dotnet/roslyn/issues/51999) | [jcouv](https://github.com/jcouv) | TBD | [stephentoub](https://github.com/stephentoub) |
| [Source Generator V2 APIs](https://github.com/dotnet/roslyn/issues/51257) | [features/source-generators](https://github.com/dotnet/roslyn/tree/features/source-generators) | [Merged into 17.0p2](https://github.com/dotnet/roslyn/issues/51257) | [chsienki](https://github.com/chsienki/) | [rikkigibson](https://github.com/rikkigibson), [jaredpar](https://github.com/jaredpar), [cston](https://github.com/cston) | N/A |
| [Mix declarations and variables in deconstruction](https://github.com/dotnet/csharplang/issues/125) | main | [Merged into 16.10](https://github.com/dotnet/roslyn/issues/47746) | [YairHalberstadt ](https://github.com/YairHalberstadt) | [jcouv](https://github.com/jcouv) | [MadsTorgersen](https://github.com/MadsTorgersen) |
| [Async method builder override](https://github.com/dotnet/csharplang/issues/1407) | main | [Merged into 17.0p2](https://github.com/dotnet/roslyn/issues/51999) | [jcouv](https://github.com/jcouv) | [cston](https://github.com/cston), [RikkiGibson](https://github.com/RikkiGibson) | [stephentoub](https://github.com/stephentoub) |
Copy link
Member

Choose a reason for hiding this comment

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

Async

#line directives? dotnet/csharplang#4747

@PathogenDavid
Copy link
Contributor

@jcouv Excellent news, I'll look forward to using them. Thanks for the info!

333fred added a commit that referenced this pull request Jun 25, 2021
…ures/caller-argument-expression

* upstream/main: (492 commits)
  Add nullable ref annotations to SyntaxFactory (#54199)
  Add 'replace' APIs and hook them up to the IDE (#54270)
  Allow implicit implementation of non-public interface members (#54182)
  Make insertion a stage of the official build (#54376)
  Cleanup
  Remove unused property
  Simplify glyph computation
  Report all-empty top level statements. (#54385)
  Calculate TypeParameterKind based on the container type (#54200)
  vert
  not roaming
  Split tests
  Multple matches
  Report as we get results
  Fixup tests
  Update tests
  Avoid thread dependency in VirtualMemoryNotificationListener constructor
  Fast progression search.
  Add LanguageVersion 10 (#54359)
  Sure, why not
  ...
@RikkiGibson RikkiGibson modified the milestones: Next, 17.0.P2 Jun 29, 2021
@JunTaoLuo
Copy link

Hey @jcouv I'm trying to use C# 10 features in the dotnet/SDK repo without needing the <LangVersion>preview</LangVersion> setting in my project. I think this PR would allow me to do that.

However, even though it seems like the ingestion of Roslyn bits have been occurring regularly in the SDK repo, e.g. dotnet/sdk#18630, I still encounter errors like:

The feature 'global using directive' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.

What else is needed here so that global usings are supported by default?

FYI @wli3

@RikkiGibson
Copy link
Contributor

It would be useful to know the output when #error version is added to your source code.

Does the project where the error occurs actually have a PackageReference to Microsoft.Net.Compilers.Toolset? If not, then the compiler used for the build probably comes from whatever SDK is included in global.json.

@JunTaoLuo
Copy link

Hmm I see, I'm not too familiar with the workings of the dotnet/SDK repo so let me dig a little.

@jcouv
Copy link
Member Author

jcouv commented Jul 14, 2021

Recording for future reference:
After we add a new language version, we need to add that version to the release in our documentation.
Here's how that was done for C# 10 (thanks @rbhanda!):

https://dotnet.microsoft.com/download/dotnet/6.0 - This is where it got the update

dotnet/core#6466
https://github.com/dotnet/core/blob/8fe8b54383589e79e94ee338481fd1d1beddf946/release-notes/6.0/releases.json - This is the file which drives dot.net

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

Successfully merging this pull request may close these issues.

MaxSupportedLangVersion needs to be updated for .NET 6
8 participants