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

Flesh out handling of symbols synthesized during lowering of extension methods #77287

Open
wants to merge 2 commits into
base: features/extensions
Choose a base branch
from

Conversation

AlekseyTs
Copy link
Contributor

@AlekseyTs AlekseyTs commented Feb 20, 2025

Relates to test plan #76130

@AlekseyTs AlekseyTs added Area-Compilers Feature - Extension Everything The extension everything feature labels Feb 20, 2025
@AlekseyTs AlekseyTs requested review from jjonescz and jcouv February 20, 2025 00:30
@AlekseyTs AlekseyTs requested a review from a team as a code owner February 20, 2025 00:30
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Feb 20, 2025
@jcouv jcouv self-assigned this Feb 20, 2025
@@ -1039,6 +1039,8 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r
// The async state machine type is not synthesized until the async method body is rewritten. If we are
// only emitting metadata the method body will not have been rewritten, and the async state machine
// type will not have been created. In this case, omit the attribute.

// PROTOTYPE: These attributes probably should be synthesized only on the extension implementation method
if (moduleBuilder.CompilationState.TryGetStateMachineType(MethodCompiler.TryGetCorrespondingExtensionImplementationMethod(this) ?? (MethodSymbol)this, out NamedTypeSymbol stateMachineType))
Copy link
Member

@jjonescz jjonescz Feb 20, 2025

Choose a reason for hiding this comment

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

Looks like TryGetCorrespondingExtensionImplementationMethod is no longer used inside MethodCompiler, so perhaps it shouldn't live there? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

perhaps it shouldn't live there?

I like its current location and at this point we don't even know whether the method will survive at the end.

@@ -2090,5 +2090,29 @@ internal bool TryGetTranslatedImports(ImportChain chain, out ImmutableArray<Cci.
{
return _translatedImportsMap.GetOrAdd(chain, imports);
}

public override void AddSynthesizedDefinition(NamedTypeSymbol container, Cci.INestedTypeDefinition nestedType)
Copy link
Member

@jjonescz jjonescz Feb 20, 2025

Choose a reason for hiding this comment

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

Consider marking as sealed override here and below. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see no reason to seal these overrides.

internal DelegateCacheContainer(TypeSymbol containingType, int generationOrdinal)
: base(GeneratedNames.DelegateCacheContainerType(generationOrdinal), containingMethod: null)
internal DelegateCacheContainer(NamedTypeSymbol containingType, int generationOrdinal)
: base(GeneratedNames.DelegateCacheContainerType(generationOrdinal), [])
{
Debug.Assert(containingType.IsDefinition);

_containingSymbol = containingType;
}

/// <summary>Creates a method-scope generic delegate cache container.</summary>
Copy link
Member

@jjonescz jjonescz Feb 20, 2025

Choose a reason for hiding this comment

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

method-scope

Consider updating the doc comment, since this constructor is not limited to "method-scope" anymore. #Resolved

@@ -22,7 +22,7 @@ internal sealed class DelegateCacheRewriter
private readonly SyntheticBoundNodeFactory _factory;
private readonly int _topLevelMethodOrdinal;

private Dictionary<MethodSymbol, DelegateCacheContainer>? _genericCacheContainers;
private Dictionary<Symbol, DelegateCacheContainer>? _genericCacheContainers;
Copy link
Member

@jjonescz jjonescz Feb 20, 2025

Choose a reason for hiding this comment

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

Consider updating the doc comment of DelegateCacheRewriter since it doesn't target just methods anymore. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider updating the doc comment of DelegateCacheRewriter since it doesn't target just methods anymore.

Could you, please, elaborate? I think the purpose of the rewriter and what it targets isn't changed in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

You are right, I have misinterpreted the doc comment.


_containingSymbol = ownerMethod.ContainingType;
_containingSymbol = containingType;
_constructedContainer = Construct(ConstructedFromTypeParameters);
}

Copy link
Member

@jjonescz jjonescz Feb 20, 2025

Choose a reason for hiding this comment

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

Is the PROTOTYPE comment below still necessary? #Resolved

@AlekseyTs
Copy link
Contributor Author

@jcouv, @jjonescz, @dotnet/roslyn-compiler Please review

@AlekseyTs
Copy link
Contributor Author

@jcouv, @dotnet/roslyn-compiler For the second review

1 similar comment
@AlekseyTs
Copy link
Contributor Author

@jcouv, @dotnet/roslyn-compiler For the second review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Extension Everything The extension everything feature untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants