Skip to content

Update SymbolDisplay API to include scoped for parameters and locals#64285

Merged
cston merged 11 commits intodotnet:mainfrom
cston:63208
Oct 1, 2022
Merged

Update SymbolDisplay API to include scoped for parameters and locals#64285
cston merged 11 commits intodotnet:mainfrom
cston:63208

Conversation

@cston
Copy link
Contributor

@cston cston commented Sep 26, 2022

Fixes #63208.

@ghost ghost added the Area-Compilers label Sep 26, 2022
@cston cston force-pushed the 63208 branch 2 times, most recently from c9f79a4 to ee0e0e7 Compare September 29, 2022 15:29
@cston cston changed the base branch from main to release/dev17.4 September 29, 2022 15:30
@cston cston changed the base branch from release/dev17.4 to main September 29, 2022 20:56
@cston cston marked this pull request as ready for review September 30, 2022 04:17
@cston cston requested review from a team as code owners September 30, 2022 04:17
if (symbol.ScopedKind == ScopedKind.ScopedRef &&
!symbol.IsThis &&
format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.IncludeScoped))
symbol.RefKind != RefKind.Out &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

out parameters are implicitly scoped (at least from modules compiled with -langversion:11 or net7.0) so scoped is dropped from out parameters here, regardless of whether scoped appeared explicitly in source.

!symbol.IsThis &&
format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.IncludeScoped))
symbol.RefKind != RefKind.Out &&
!symbol.IsThis)
Copy link
Contributor

Choose a reason for hiding this comment

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

might want to comment these conditions to explain why they're there.

{
AddKeyword(SyntaxKind.ScopedKeyword);
AddSpace();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

kinda surprised this isn't in AddParameterRefKindIfNeeded

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This scoped refers to the value rather than the ref. We could perhaps inline AddParameterRefKindIfNeeded() at the call-site above since it's only used in that one location. That might make the sequence clearer. But I've left AddParameterRefKindIfNeeded() as a distinct method for now, so the differences in this PR are easier to follow.

AddKeyword(SyntaxKind.ReadOnlyKeyword);
AddKeyword(SyntaxKind.ScopedKeyword);
AddSpace();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

does this mean you can have ref scoped as well as scoped ref?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

does this mean you can have ref scoped as well as scoped ref?

The ILocalSymbol API allows ref scoped but that is not supported from C#.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should just make it into an else if so that ref and non-ref code paths do not overlap.

@cston cston requested a review from a team as a code owner September 30, 2022 22:22
AddKeyword(SyntaxKind.ScopedKeyword);
AddSpace();
}
if (symbol.ScopedKind == ScopedKind.ScopedValue)
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 30, 2022

Choose a reason for hiding this comment

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

if (symbol.ScopedKind == ScopedKind.ScopedValue)

We could perhaps inline AddParameterRefKindIfNeeded() at the call-site above since it's only used in that one location. That might make the sequence clearer.

I think we should seriously consider doing this and avoid introducing ref/non-ref overlapping code paths for scoped as we have right now. In other words, ScopedKind.ScopedValue should not affect ref parameters the same way as ScopedKind.ScopedRef doesn't affect value parameters. Language doesn't support these combinations and it will make the code easier to follow. BTW, I think it should be fine to do AddCustomModifiersIfNeeded(symbol.RefCustomModifiers ... only if we display ref, after all they are modifying the ref and will look very confusing without it. #Closed

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've inlined AddParameterRefKindIfNeeded() but did not move AddCustomModifiers() into the if (IncludeModifiers) { } block. I agree it might be confusing to have ref custom modifiers without a leading ref but that seems like an unnecessary change for this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the code paths for ref and ScopedKind.ScopedValue still overlap. The primary motivation for suggesting refactoring was to avoid that.

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 8), with a refactoring suggestion.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 9)

@jcouv jcouv self-assigned this Sep 30, 2022
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 11)

@cston cston merged commit 6260291 into dotnet:main Oct 1, 2022
@cston cston deleted the 63208 branch October 1, 2022 15:00
@ghost ghost added this to the Next milestone Oct 1, 2022
@RikkiGibson RikkiGibson modified the milestones: Next, 17.5 P1 Oct 24, 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.

Update SymbolDisplay to include scoped for parameters and locals

5 participants