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 ScopedKind to IParameterSymbol and ILocalSymbol #64190

Merged
merged 4 commits into from
Sep 23, 2022
Merged

Conversation

cston
Copy link
Member

@cston cston commented Sep 21, 2022

See #61647.

/// <summary>
/// Enumeration for kinds of scoped modifiers.
/// </summary>
public enum ScopedKind
Copy link
Member Author

Choose a reason for hiding this comment

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

ScopedKind

Should this be : byte?

@cston cston marked this pull request as ready for review September 23, 2022 04:25
@cston cston requested review from a team as code owners September 23, 2022 04:25
// https://github.com/dotnet/roslyn/issues/61647: Internally, scope is represented with this enum,
// but the public API uses a pair of IsRefScoped and IsValueScoped bools (see ILocalSymbol,
// IParameterSymbol, and ScopedRefAttribute). We should have a common representation.
// And we should use common terms for the attribute and enum names.
internal enum DeclarationScope : byte
Copy link
Member Author

Choose a reason for hiding this comment

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

DeclarationScope

Replace with ScopedKind?

Copy link
Member

Choose a reason for hiding this comment

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

Seems like it would be a reasonable change.

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -22,6 +22,11 @@ public interface IParameterSymbol : ISymbol
/// </summary>
RefKind RefKind { get; }

/// <summary>
/// Returns the scoped kind of the local.
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 23, 2022

Choose a reason for hiding this comment

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

local

parameter? #Closed

None = 0,

/// <summary>
/// A ref scoped to the current method or block.
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 23, 2022

Choose a reason for hiding this comment

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

current

enclosing? #Closed

if ((symbol as Symbols.PublicModel.ParameterSymbol)?.GetSymbol<ParameterSymbol>() is { } parameter &&
parameter.EffectiveScope == DeclarationScope.RefScoped &&
if (symbol.ScopedKind == ScopedKind.ScopedRef &&
(symbol as Symbols.PublicModel.ParameterSymbol)?.GetSymbol<ParameterSymbol>() is { } parameter &&
!ParameterHelpers.IsRefScopedByDefault(parameter) &&
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 23, 2022

Choose a reason for hiding this comment

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

Are we missing IsRefScopedByDefault as a public API? Is there an alternative way to detect this in a language independent way? #Closed

Copy link
Contributor

@AlekseyTs AlekseyTs Sep 23, 2022

Choose a reason for hiding this comment

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

If not, perhaps we should use this condition only for C# symbols and not dismiss other symbols?

Copy link
Member Author

Choose a reason for hiding this comment

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

IsRefScopedByDefault() relies on ModuleSymbol.UsesUpdatedEscapeRules, which is not tracked in VB, nor is scoped. Changed to use for C# symbols only.

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 3)

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 4)

@cston cston requested a review from a team September 23, 2022 17:39
Copy link
Member

@333fred 333fred 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 4). It does seem like it would be reasonable to remove DeclarationScope and just use ScopedKind everywhere, imo.

// https://github.com/dotnet/roslyn/issues/61647: Internally, scope is represented with this enum,
// but the public API uses a pair of IsRefScoped and IsValueScoped bools (see ILocalSymbol,
// IParameterSymbol, and ScopedRefAttribute). We should have a common representation.
// And we should use common terms for the attribute and enum names.
internal enum DeclarationScope : byte
Copy link
Member

Choose a reason for hiding this comment

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

Seems like it would be a reasonable change.

@cston cston merged commit 81407cf into dotnet:main Sep 23, 2022
@cston cston deleted the ScopedKind branch September 23, 2022 20:30
@ghost ghost added this to the Next milestone Sep 23, 2022
@Cosifne Cosifne modified the milestones: Next, 17.4 P3 Sep 26, 2022
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.

4 participants