Skip to content

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Apr 1, 2025

  • check extension parameter (like this parameter in classic extension method)
  • checks for parameters of async and iterator methods include the extension parameter
  • init disallowed
  • certain modifiers disallowed
  • instance members and parameter modifiers disallowed if the receiver parameter is unnamed
  • reserve "extension"

Corresponding spec update: dotnet/csharplang#9274

Relates to test plan #76130

@jcouv jcouv added Area-Compilers Feature - Extension Everything The extension everything feature labels Apr 1, 2025
@jcouv jcouv self-assigned this Apr 1, 2025
@ghost ghost added the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 1, 2025
@jcouv jcouv force-pushed the extensions-validation branch from a180d42 to b981f62 Compare April 1, 2025 13:19
@jcouv jcouv force-pushed the extensions-validation branch from b981f62 to 04e23e9 Compare April 1, 2025 13:40
@jcouv jcouv force-pushed the extensions-validation branch from 04e23e9 to 9fe5bae Compare April 1, 2025 15:10
@jcouv jcouv marked this pull request as ready for review April 1, 2025 15:31
@jcouv jcouv requested review from a team as code owners April 1, 2025 15:31
@jcouv jcouv requested review from jjonescz and AlekseyTs April 1, 2025 15:31
internal static bool IsExtensionParameterImplementation(this ParameterSymbol parameter)
{
return parameter.ContainingSymbol is SourceExtensionImplementationMethodSymbol implementationMethod
&& parameter.Ordinal == 0;
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

parameter.Ordinal == 0

I think this condition is insufficient and will lead to an incorrect result for static extension methods #Closed

if (parameter.RefKind != RefKind.None)
{
diagnostics.Add(ErrorCode.ERR_BadIteratorArgType, parameter.GetFirstLocation());
var location = isReceiverParameter
? ((MethodDeclarationSyntax)iterator.GetNonNullSyntaxNode()).Identifier.GetLocation()
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

((MethodDeclarationSyntax)iterator.GetNonNullSyntaxNode()).Identifier.GetLocation()

Wouldn't simply requesting location from iterator work? #Closed

@@ -3879,7 +3879,7 @@ private static EffectiveParameters GetEffectiveParametersInNormalForm<TMember>(
hasAnyRefOmittedArgument = false;

bool isNewExtensionMember = member.GetIsNewExtensionMember();
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

bool isNewExtensionMember = member.GetIsNewExtensionMember();

Consider moving declaration closer to usage #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Apr 1, 2025

            if (member.GetIsNewExtensionMember())

isNewExtensionMember? #Closed


Refers to: src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs:3890 in 9fe5bae. [](commit_id = 9fe5bae, deletion_comment = False)

@@ -79,7 +72,7 @@ private static ArgumentAnalysisResult AnalyzeArguments(
Debug.Assert(arguments != null);

bool isNewExtensionMember = symbol.GetIsNewExtensionMember();
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

bool isNewExtensionMember = symbol.GetIsNewExtensionMember();

It looks like the local is no longer used #Closed


internal static bool IsExtensionParameterImplementation(this ParameterSymbol parameter)
{
return parameter.ContainingSymbol is SourceExtensionImplementationMethodSymbol implementationMethod
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

parameter

It looks like we are making an assumption that this method is always called on a definition. Consider asserting the fact. #Closed

else if (parameterRefKind is RefKind.In or RefKind.RefReadOnlyParameter && parameterType.TypeKind != TypeKind.Struct)
{
diagnostics.Add(ErrorCode.ERR_InExtensionParameterMustBeValueType, parameterTypeSyntax);
}
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

I think it would be desirable to try sharing logic with ExtensionMethodChecks in order to avoid an accidental diverging #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree and I tried that initially, but the logic for these three checks in ExtensionMethodChecks uses locations and also the name of the method

Copy link
Member

Choose a reason for hiding this comment

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

Consider leaving a comment in both places saying that we should keep them in sync.

@@ -139,7 +139,7 @@ protected override void GenerateControlFields()
// Add a field: bool disposeMode
_disposeModeField = F.StateMachineField(boolType, GeneratedNames.MakeDisposeModeFieldName());

if (_isEnumerable && this.method.Parameters.Any(static p => p.IsSourceParameterWithEnumeratorCancellationAttribute()))
if (_isEnumerable && this.method.Parameters.Any(static p => !p.IsExtensionParameterImplementation() && p.HasEnumeratorCancellationAttribute))
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

!p.IsExtensionParameterImplementation()

It is not obvious why extension parameter is getting special treatment #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean we should leave a comment here (the attribute is ignored on extension parameter) or do you mean you think the attribute should be effective on the extension parameter too?

The reason I don't think the attribute should be effective is that this attribute is very specific to async-iterator method implementations. I don't think it belongs on an extension parameter, as the extension block may contain many kinds of members. Also, the scenario where you need an async-iterator extension method on a CancellationToken receiver seems very niche to say the least.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it belongs on an extension parameter

I am fine with this design decision, Could you please mention this explicitly in the speclet?

Also, please make sure to test scenario where extension parameter implementation is the only parameter for the method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good. Linked to corresponding spec update.
The test ReceiverParameterValidation_CancellationTokenParameter_Instance shows that the attribute doesn't have an effect (it includes another parameter, but I think that's fine)

Copy link
Contributor

Choose a reason for hiding this comment

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

it includes another parameter, but I think that's fine

Are you saying the CancellationToken parameter doesn't have to be the last parameter in a general case?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's correct. The only restriction is that only one parameter may be marked with this attribute.

@@ -1132,6 +1132,10 @@ private void CheckModifiers(bool isExplicitInterfaceImplementation, Location loc
{
diagnostics.Add(AccessCheck.GetProtectedMemberInSealedTypeError(ContainingType), location, this);
}
else if (ContainingType is { IsExtension: true, ExtensionParameter: { Name: "" } } && !IsStatic)
{
diagnostics.Add(ErrorCode.ERR_InstanceMemberWithUnnamedExtensionsParameter, location, Name);
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

Name

Will the name work for an indexer? #Closed

@@ -121,6 +121,11 @@ public override ImmutableArray<CustomModifier> RefCustomModifiers
get { return _underlyingParameter.RefCustomModifiers; }
}

internal sealed override bool HasEnumeratorCancellationAttribute
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

internal sealed override bool HasEnumeratorCancellationAttribute

I think we should override this property only in leaves #Closed

@@ -1760,6 +1760,67 @@ .maxstack 8
);
}

[Fact]
public void Member_InstanceIndexer_Metadata()
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

Member_InstanceIndexer_Metadata

It feels like this test isn't very useful right now. At least in the form that uses IL. I think we can compile an indexer declaration to metadata. #Closed

diagnostics.Add(ErrorCode.ERR_InExtensionParameterMustBeValueType, parameterTypeSyntax);
}

if (parameter.Name is "" && parameterRefKind != RefKind.None)
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

parameterRefKind != RefKind.None

Should scoped be disallowed as well? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but that's currently a parsing error. See ReceiverParameterValidation_UnnamedReceiverParameter_Scoped, which has a comment for follow-up


static class E
{
extension(ref MyCollection c)
{
public void Add(int i) { System.Console.Write("ran "); c = null; }
public void Add(int i) { System.Console.Write("ran "); c = new MyCollection() { field = 42 }; }
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

42

i? #Closed

""";
var comp = CreateCompilation(source, targetFramework: TargetFramework.Net90);
comp.VerifyDiagnostics(
// (7,16): warning CS8424: The EnumeratorCancellationAttribute applied to parameter 'token1' will have no effect. The attribute is only effective on a parameter of type CancellationToken in an async-iterator method returning IAsyncEnumerable
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

warning CS8424: The EnumeratorCancellationAttribute applied to parameter 'token1' will have no effect.

Is this warning misleading and likely incorrect in a general case? #Closed

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 warning is correct for the current design/implementation. See detailed explanation in other response

}

[Fact]
public void ReceiverParameterValidation_UnnamedReceiverParameter()
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

ReceiverParameterValidation_UnnamedReceiverParameter

Consider testing indexers as well #Closed

}

[Fact]
public void Validation_Modifiers_Abstract()
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2025

Choose a reason for hiding this comment

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

Validation_Modifiers_Abstract

Consider testing indexers as well #Closed


internal static bool IsExtensionParameterImplementation(this ParameterSymbol parameter)
{
Debug.Assert(parameter.ContainingSymbol.IsDefinition);
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 2, 2025

Choose a reason for hiding this comment

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

parameter.ContainingSymbol.IsDefinition

Debug.Assert(parameter.IsDefinition);? #Closed

// (5,22): error CS0751: A partial member must be declared within a partial type
// partial void M();
Diagnostic(ErrorCode.ERR_PartialMemberOnlyInPartialClass, "M").WithLocation(5, 22),
// (6,22): error CS0751: A partial member must be declared within a partial type
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 2, 2025

Choose a reason for hiding this comment

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

error CS0751: A partial member must be declared within a partial type

Do we understand why this error is reported twice for methods and only once for properties/indexers? #Closed

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 is an existing behavior. There's a difference between properties and methods in that regard.

{
Debug.Assert(parameter.ContainingSymbol.IsDefinition);
return parameter.ContainingSymbol is SourceExtensionImplementationMethodSymbol implementationMethod
&& !implementationMethod.UnderlyingMethod.IsStatic
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 2, 2025

Choose a reason for hiding this comment

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

&& !implementationMethod.UnderlyingMethod.IsStatic

It looks like this fix was not covered by a corresponding test. Was it not possible to observe the incorrect behavior without a direct API test? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

Will add a test

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 4)

@@ -334,8 +334,7 @@ class partial { }

## `extension` treated as a contextual keyword

PROTOTYPE record which version this break is introduced in
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 2, 2025

Choose a reason for hiding this comment

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

PROTOTYPE

Shouldn't one be able to use this word? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

Not in the main branch

@jcouv jcouv requested a review from AlekseyTs April 2, 2025 14:28
Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 7)

""";
var comp = CreateCompilation(source, targetFramework: TargetFramework.Net90);
comp.VerifyDiagnostics(
// (7,16): warning CS8424: The EnumeratorCancellationAttribute applied to parameter 'token1' will have no effect. The attribute is only effective on a parameter of type CancellationToken in an async-iterator method returning IAsyncEnumerable
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 2, 2025

Choose a reason for hiding this comment

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

warning CS8424: The EnumeratorCancellationAttribute applied to parameter 'token1' will have no effect.

Given the speclet wording "The receiver parameter may not have an [EnumeratorCancellation] attribute." I would expect an error instead. #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. I'll fix the spec

@jcouv
Copy link
Member Author

jcouv commented Apr 2, 2025

@jjonescz for second review. Thanks

@AlekseyTs AlekseyTs added the breaking-change https://github.com/dotnet/sdk/blob/main/documentation/project-docs/breaking-change-guidelines.md label Apr 2, 2025
@@ -334,8 +334,7 @@ class partial { }

## `extension` treated as a contextual keyword

PROTOTYPE record which version this break is introduced in

***Introduced in Visual Studio 2022 version 17.4.***
Copy link
Member

@jjonescz jjonescz Apr 3, 2025

Choose a reason for hiding this comment

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

Is this change part of this PR? Then it should be probably 17.15. If it was already merged, then 17.14.

Suggested change
***Introduced in Visual Studio 2022 version 17.4.***
***Introduced in Visual Studio 2022 version 17.14.***
``` #Resolved

@@ -107,14 +107,21 @@ public static void ValidateIteratorMethod(CSharpCompilation compilation, MethodS
return;
}

foreach (var parameter in iterator.Parameters)
var parameters = !iterator.IsStatic
? iterator.GetParametersIncludingExtensionParameter()
Copy link
Member

@jjonescz jjonescz Apr 3, 2025

Choose a reason for hiding this comment

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

Should the GetParametersIncludingExtensionParameter helper check that the member is not static? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

That would not be convenient. That method is also used in overload resolution, and for the purpose of overload resolution, we do want to account for the extension parameter even when the method is static (the static receiver counts as an argument in that case).

else if (parameterRefKind is RefKind.In or RefKind.RefReadOnlyParameter && parameterType.TypeKind != TypeKind.Struct)
{
diagnostics.Add(ErrorCode.ERR_InExtensionParameterMustBeValueType, parameterTypeSyntax);
}
Copy link
Member

Choose a reason for hiding this comment

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

Consider leaving a comment in both places saying that we should keep them in sync.

@@ -908,6 +917,10 @@ private void CheckModifiers(bool isExplicitInterfaceImplementation, Location loc
{
diagnostics.Add(AccessCheck.GetProtectedMemberInSealedTypeError(ContainingType), location, this);
}
else if (ContainingType is { IsExtension: true, ExtensionParameter: { Name: "" } } && !IsStatic)
Copy link
Member

@jjonescz jjonescz Apr 3, 2025

Choose a reason for hiding this comment

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

nit: this can be simplified

Suggested change
else if (ContainingType is { IsExtension: true, ExtensionParameter: { Name: "" } } && !IsStatic)
else if (ContainingType is { IsExtension: true, ExtensionParameter.Name: "" } && !IsStatic)
``` #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

ExtensionParameter can be null even when IsExtension is true. That happens when the extension parameter is __arglist.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but the pattern would handle nulls right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, you're right. I'll update

@@ -1132,6 +1132,10 @@ private void CheckModifiers(bool isExplicitInterfaceImplementation, Location loc
{
diagnostics.Add(AccessCheck.GetProtectedMemberInSealedTypeError(ContainingType), location, this);
}
else if (ContainingType is { IsExtension: true, ExtensionParameter: { Name: "" } } && !IsStatic)
Copy link
Member

@jjonescz jjonescz Apr 3, 2025

Choose a reason for hiding this comment

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

Suggested change
else if (ContainingType is { IsExtension: true, ExtensionParameter: { Name: "" } } && !IsStatic)
else if (ContainingType is { IsExtension: true, ExtensionParameter.Name: "" } && !IsStatic)
``` #Resolved

@@ -63,24 +63,32 @@ protected bool AreContainingSymbolLocalsZeroed

internal void ReportAsyncParameterErrors(BindingDiagnosticBag diagnostics, Location location)
{
foreach (var parameter in Parameters)
var parameters = !this.IsStatic ? this.GetParametersIncludingExtensionParameter() : Parameters;
Copy link
Member

@jjonescz jjonescz Apr 3, 2025

Choose a reason for hiding this comment

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

This could be also simplified if we checked IsStatic inside GetParametersIncludingExtensionParameter. #ByDesign

public void ReceiverParameter_RefReadonly()
public void ReceiverParameter_In_03()
{
var src = $$"""
Copy link
Member

@jjonescz jjonescz Apr 3, 2025

Choose a reason for hiding this comment

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

Suggested change
var src = $$"""
var src = """
``` #Resolved

@@ -12062,10 +12172,11 @@ static class E
[Fact]
public void InstanceMethodInvocation_Simple_ExpressionTree()
{
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : decide whether to allow expression tree scenarios. Verify shape of the tree if we decide to allow
var source = """
Copy link
Member

@jjonescz jjonescz Apr 3, 2025

Choose a reason for hiding this comment

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

It looks like we are not verifying the shape of the tree as the prototype comment suggested. #Resolved

@@ -334,26 +334,33 @@ class partial { }

## `extension` treated as a contextual keyword

PROTOTYPE record which version this break is introduced in

***Introduced in Visual Studio 2022 version 17.4.***
Copy link
Member

@jjonescz jjonescz Apr 3, 2025

Choose a reason for hiding this comment

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

Suggested change
***Introduced in Visual Studio 2022 version 17.4.***
***Introduced in Visual Studio 2022 version 17.14.***
``` #Resolved

@jcouv jcouv enabled auto-merge (squash) April 3, 2025 08:01
@jcouv jcouv merged commit f72da0b into dotnet:main Apr 3, 2025
28 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 3, 2025
@jcouv jcouv deleted the extensions-validation branch April 3, 2025 11:04
333fred added a commit that referenced this pull request Apr 12, 2025
* Addressing feedback

* Addressing PR feedback

* Addressing PR comments

* Remove workaround for dotnet/msbuild#10306

The VS SDK was fixed, so the problem shouldn't occur anymore.

* move to a workspace factory

* No need for solution

* Simplify handlers

* Add helper

* move more over

* move more over

* Add remove calls

* Move handlers over

* Move remote service over

* async lock

* async lock

* async lock

* More work

* Fixup

* Correct

* Move to immutable dictionary

* in progress

* in progress

* in progress

* in progress

* in progress

* in progress

* Simplify

* Serialize

* simplify

* simplify

* simplify

* in progress

* in progress

* Reset code

* Clelar

* renames

* Simplify

* rename

* No more null

* Simplify

* Exception throwing

* Extensions: update feature status (#77923)

* Add ignored directives feature status (#77965)

* Extensions: misc checks on receiver parameter and extension members (#77937)

* Add porject back in

* CHange how locking works

* Simplify

* Docs

* Add new message for getting registered method names

* IN progres

* in progress

* Simplify

* Simplify

* Handle exceptions

* Simplify

* Docs

* move method

* Simplify and regions

* Tweaks

* Docs

* Break into files

* Simplify exception handling

* Simplify

* Simplify

* Move

* Docs

* Simplify

* Simplify

* Share code

* Split into local and remote calls

* Add throw

* Add throw

* Simplify

* Simplify

* Simplify

* Simplify

* Simplify

* Simplify

* Simplify

* Simplify

* Simplify

* Simplify

* Simplify

* Simplify

* Avoid potential disposal exception during MEF shutdown (#77990)

Previously, if VS was shutdown before Workspace.EnsureEventListeners was invoked, we would cause an exception during MEF disposal. This would happen because our workspace disposal would attempt to get a service that hadn't already been cached, and thus would ask MEF to compose the item during MEF disposal (which doesn't work).

Instead, just cache the IWorkspaceEventListenerService for use during the dispose.

* Remove unused elements form PublishData.json (#77994)

Removing some elements that seem to be left over from how the publish tooling used to work

* Reduce main thread switches in VisualStudioProjectFactory.CreateAndAddToWorkspaceAsync (#77920)

* Reduce main thread switches in VisualStudioProjectFactory.CreateAndAddToWorkspaceAsync

This method is called once for each project in the solution during solution open, and each call was essentially switching to the main thread twice (once explicitly, once via call to _visualStudioWorkspaceImpl.RefreshProjectExistsUIContextForLanguageAsync). For my testing of opening Roslyn.sln, this removed over 600 main thread switches.

Instead:

1) Move the first main thread switch to just occur once in an initialization task. This task is joined when CreateAndAddToWorkspaceAsync is invoked to ensure that that initialization is completed.
2) Move the second main thread switch to instead move inside the callback from an ABWQ. The code being called needs the UI thread, but doesn't need to occur synchronously during the call to CreateAndAddToWorkspaceAsync.

* Explicitly releasE

* Cancellation is fine

* Reorder

* remove net

* docs

* docs

* remove exception handling

* Add public api

* lint

* Reduce main thread switches in VisualStudioProjectFactory.CreateAndAddToWorkspaceAsync (#77920) (#77998)

* Reduce main thread switches in VisualStudioProjectFactory.CreateAndAddToWorkspaceAsync

This method is called once for each project in the solution during solution open, and each call was essentially switching to the main thread twice (once explicitly, once via call to _visualStudioWorkspaceImpl.RefreshProjectExistsUIContextForLanguageAsync). For my testing of opening Roslyn.sln, this removed over 600 main thread switches.

Instead:

1) Move the first main thread switch to just occur once in an initialization task. This task is joined when CreateAndAddToWorkspaceAsync is invoked to ensure that that initialization is completed.
2) Move the second main thread switch to instead move inside the callback from an ABWQ. The code being called needs the UI thread, but doesn't need to occur synchronously during the call to CreateAndAddToWorkspaceAsync.

* make nested

* Simplify

* Simplify

* Simplify

* Simplify

* Simplify

* restore

* Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20250402.2 (#77982)

Microsoft.SourceBuild.Intermediate.source-build-reference-packages
 From Version 10.0.618101 -> To Version 10.0.620202

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>

* Allow null

* Simplify

* No VoidResult

* Make everything non-capturing

* 'nameof(T<>)' not supported yet.

* Update references

* Revert "Another attempt to move MiscellaneousFilesWorkspace to a bg thread (#77983)

This reverts commit 2e8fcbe.

* fix

* Exception work

* Update Roslyn.sln

* More exception work

* Add remote end

* Complete the exception handling work

* Add docs

* docs

* Add docs

* Rename type

* Rename type

* update publishdata

* Change SolutionState.ProjectStates from an ImmutableDictionary<ProjectId, ProjectState> to an ImmutableArray<ProjectState> (#77971)

* *** WIP. Definitely needs supporting speedometer numbers before being considered ***

Change SolutionState to keep/expose and ImmutableArray<ProjectState> instead of an IReadOnlyList<ProjectId>

By exposing the project states, there is a bunch of code that can be changed to enumerate over that collection rather than over the values of an ImmutableDictionary<ProjectId, ProjectState>. That enumeration is actually *very* expensive.

For example, during roslyn load, local etl traces indicates the following CPU usage enumerating this dictionary:

Under ComputeDocumentIdsWithFilePath: 2.6 seconds
Under GetFirstRelatedDocumentId: 1.1 seconds

There is a bit of a tradeoff associated with this change. The IReadOnlyList<ProjectId> could be reused very often, whereas there is much less opportunity for sharing ImmutableArray<ProjectState> when forking the solution state. I expect there to be more memory allocated in the speedometer runs, so I'd like to get a feel on how much worse that is before elevating this PR out of draft status.

Additionally, SolutionState had a CWT over a sorted version of this IReadOnlyList<ProjectId>. As mentioned earlier, the sharing of this data is quite a bit less common now that it's an ImmutableArray<ProjectState>. I locally measured the stopwatch time spent always sorting this data in ComputeChecksumsAsync and it was a total of 4 ms (averaged over two separate VS runs) when loading the roslyn sln.

The ImmutableDictionary is still present in SolutionState, but it was renamed to indicate that it's primarily useful as a lookup tool, and all references treating it as an enumeration mechanism were changed to instead use the ImmutableArray<ProjectState>.

* Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20250404.2 (#78008)

Microsoft.SourceBuild.Intermediate.source-build-reference-packages
 From Version 10.0.620202 -> To Version 10.0.620402

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>

* Fix VSTypeScript lsp tests

* localize servicehub service name

* Simplify workspace initialization in the LSP server

Right now we have the logic for which analyzers get added to a workspace
in Program.cs, which calls a special method that specifically
initializes the main host workspace. This refactors it so that could
be used to initialize any workspace, and removes any tricky ordering
problems that might happen by using cleaner MEF imports when we have
them.

* Update test

* Update dependencies from https://github.com/dotnet/arcade build 20250404.5

Microsoft.SourceBuild.Intermediate.arcade , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.XliffTasks
 From Version 9.0.0-beta.25164.2 -> To Version 9.0.0-beta.25204.5

* Update maintenance-packages versions (#78005)

* Update maintenance-packages versions

* Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20250404.2

Microsoft.SourceBuild.Intermediate.source-build-reference-packages
 From Version 10.0.620202 -> To Version 10.0.620402

* Address feedback

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>

* Fix EA layering for Razor.ExternalAccess (#77927)

Moves things to /Shared to ship in both MS.CA.EA.Razor and MS.CA.EA.Razor.Features

At some point we can rename MS.CA.EA.Razor to MS.CA.EA.Razor.EditorFeatures but I didn't bother with that in this PR
Shipping in both to not require dual insertion. We can fix this after a consuming change in Razor is inserted

* Delete

* Update PublishData.json after VS snap to rel/d17.14

* Handle nameof(indexer) in ref analysis (#78015)

* Make a couple of features non-experimental

* Ensure external access extensions package gets codebase

* Feedback

* Add extension message handler service teest

* Add extension message handler service test

* FIx

* Add testS

* In progress

* Test work

* Tests

* Add test

* More tests

* Add tests

* Add tests

* Add tests

* Add test

* Add test

* Add test

* Add test

* Add test

* Update comment

* Disable TransitiveVersioningPinning for RoslynAnalyzers.

* Remove dependency on EditorFeatures from lsp tests

* Remove dependency on EditorFeatures from codelens layer

* Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20250407.2

Microsoft.SourceBuild.Intermediate.source-build-reference-packages
 From Version 10.0.620402 -> To Version 10.0.620702

* Remove dependency on EditorFeatures from build tools

* Update dependency versions

* Extensions: ref safety analysis (#77967)

* Update PublishData.json after VS span to main

* In progress

* Fix crash in backing field nullability cycle scenario (#77993)

* More work

* Pass along when an extension was unloaded

* Add teset

* Add tests

* Docs

* Simplify

* Using alias

* Fix

* Add tests

* Add docs

* Update gladstone/roslyn api

* Simplify channels in SemanticSearch

* Semantic Search: Add support for async queries and FAR tool (#77906)

* Simplify further

* Simplify further

* Localize exception messages

* Docs

* Docs

* Docs

* named args

* named args

* Docs

* Move type

* Docs

* Fix name

* Compile just for NET

* Unseal LSP types (#78041)

* Simplify analyzer api

* Update RoslynAnalyzer package projects with dependencies

This will fix issues with transitive pinning during source builds.

* Ensure LSP uses actual signature help trigger characters

* Improve detection of code whose updates may not have effect (#78009)

* Do not return metadata names for document symbols

* Fix nullability warnings

* Review feedback

* Remove EditorFeatures from OOP (#78069)

* Add back EA.Razor for servicing branches

publishdata is pulled from main always.  this needs to be present even though the package no longer exists for servicing branches

* Remove unused ISemanticSearchWorkspaceHost (#78083)

* Split query execution into compile and execute calls (#78081)

* Update resourceManagement.yml (#77948)

* Expression trees: support optional arguments and named arguments in parameter order (#77972)

* Update ignored directives public API (#77968)

* Remove experiment

* Add Content token to IgnoredDirectiveTriviaSyntax

* Add Content token to ShebangDirectiveTriviaSyntax

* Fixup public API

* Fixup semantic search API list

* Fix CLI flag in error message

* Remove Update API

* Update SemanticSearch API list

---------

Co-authored-by: Matteo Prosperi <[email protected]>
Co-authored-by: Jason Malinowski <[email protected]>
Co-authored-by: Cyrus Najmabadi <[email protected]>
Co-authored-by: Cyrus Najmabadi <[email protected]>
Co-authored-by: Julien Couvreur <[email protected]>
Co-authored-by: Jan Jones <[email protected]>
Co-authored-by: Matteo Prosperi <[email protected]>
Co-authored-by: Todd Grunke <[email protected]>
Co-authored-by: Jared Parsons <[email protected]>
Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: David Barbet <[email protected]>
Co-authored-by: Carlos Sánchez López <[email protected]>
Co-authored-by: Andrew Hall <[email protected]>
Co-authored-by: Charles Stoner <[email protected]>
Co-authored-by: Tomas Matousek <[email protected]>
Co-authored-by: Joey Robichaud <[email protected]>
Co-authored-by: Rikki Gibson <[email protected]>
Co-authored-by: Tomáš Matoušek <[email protected]>
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers breaking-change https://github.com/dotnet/sdk/blob/main/documentation/project-docs/breaking-change-guidelines.md Feature - Extension Everything The extension everything feature untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants