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

Interceptors: address duplicate interceptions feedback, handle nameof, add test coverage #67971

Merged
merged 13 commits into from
Apr 29, 2023

Conversation

RikkiGibson
Copy link
Contributor

@RikkiGibson RikkiGibson commented Apr 26, 2023

Test plan: #67421

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 26, 2023
@RikkiGibson RikkiGibson marked this pull request as ready for review April 27, 2023 00:27
@RikkiGibson RikkiGibson requested review from a team as code owners April 27, 2023 00:27
@RikkiGibson RikkiGibson changed the title Interceptors 3 Interceptors: address duplicate interceptions feedback, handle nameof, add test coverage Apr 27, 2023
@jcouv jcouv self-assigned this Apr 27, 2023
@jcouv jcouv added this to the C# 12.0 milestone Apr 27, 2023
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 27, 2023
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.

Done with review pass (iteration 7)

@RikkiGibson RikkiGibson requested a review from jcouv April 27, 2023 23:27
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 12)

if (node is BoundNameOfOperator nameofOperator)
{
Debug.Assert(!nameofOperator.WasCompilerGenerated);
var nameofIdentiferSyntax = (IdentifierNameSyntax)((InvocationExpressionSyntax)nameofOperator.Syntax).Expression;
Copy link
Member

@cston cston Apr 28, 2023

Choose a reason for hiding this comment

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

(IdentifierNameSyntax)

Minor: The cast may be unnecessary.

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 think so, but if this isn't an identifier, I'd like to fail fast here.

var matchingTrees = syntaxTrees.WhereAsArray(static (tree, filePath) => tree.FilePath == filePath, filePath);
if (matchingTrees is [])
SyntaxTree? matchingTree = null;
foreach (var tree in syntaxTrees)
Copy link
Member

Choose a reason for hiding this comment

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

foreach (var tree in syntaxTrees)

It seems expensive to iterate through the SyntaxTrees collection once for each InterceptsLocationAttribute. Can we avoid this without too much effort?

For instance, it looks like we're already building a HashSet<string> of file paths in CSharpCompilation.CheckDuplicateFilePaths(), at least temporarily. Could we create a Dictionary<string, SyntaxTree> instead, and share between this use and CheckDuplicateFilePaths()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes total sense. We are also gonna have to make a change here to resolve the FilePath before comparing (i.e. handle /pathmap). Do you mind if I leave a comment for it and resolve in future.

@RikkiGibson RikkiGibson merged commit 303412c into dotnet:features/interceptors Apr 29, 2023
@RikkiGibson RikkiGibson deleted the ic-3 branch April 29, 2023 00:09
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.

3 participants