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

Expose IsGeneratedCode boolean property on diagnostic analyzer contexts #63447

Merged
merged 4 commits into from
Sep 20, 2022

Conversation

mavasani
Copy link
Contributor

Closes #7578

Based on the recent feature requests in allowing more fine grained generated code analysis, we have decided to initially expose a boolean IsGeneratedCode property on each of the analysis contexts. Note that this flag indicates if the callback symbol/node/operation/tree is considered generated code or not based on compiler's internal heuristics for analyzer execution. This flag helps the analyzers that only want to analyze certain kinds of generated code to narrow down their custom fine grained generated code analysis to only those callbacks that have this flag set to true.

Closes dotnet#7578

Based on the recent feature requests in allowing more fine grained generated code analysis, we have decided to initially expose a boolean IsGeneratedCode property on each of the analysis contexts. Note that this flag indicates if the callback symbol/node/operation/tree is considered generated code or not based on compiler's internal heuristics for analyzer execution. This flag helps the analyzers that only want to analyze certain kinds of generated code to narrow down their custom fine grained generated code analysis to only those callbacks that have this flag set to true.
@mavasani mavasani marked this pull request as ready for review August 18, 2022 14:12
@mavasani mavasani requested review from a team as code owners August 18, 2022 14:12
@RikkiGibson RikkiGibson self-assigned this Aug 18, 2022
@RikkiGibson
Copy link
Contributor

In the Razor scenario, you might have "generated platform code" and "generated code from user code" in the same method, right? Something like:

<h1>@MyMethod()</h1>

might turn into (extreme pseudocode, sorry if I've totally botched what Razor actually does)

void RenderTemplate()
{
    #line hidden
    Render("<h1>");

    #line 1,5 Index.cshtml
    Model.MyMethod();

    #line hidden
    Render("</h1>");
}

This kind of thing is not handled in this PR, right? Is there any expectation to handle it eventually?

@mavasani
Copy link
Contributor Author

In the Razor scenario, you might have "generated platform code" and "generated code from user code" in the same method, right?

This kind of thing is not handled in this PR, right? Is there any expectation to handle it eventually?

Yes, that is correct. This PR is not changing semantics, just exposing a public API for an existing isGeneratedCode flag tracked within analyzer driver.

@mavasani
Copy link
Contributor Author

@dotnet/roslyn-compiler for another review

@mavasani
Copy link
Contributor Author

mavasani commented Sep 6, 2022

@dotnet/roslyn-compiler for second review

1 similar comment
@mavasani
Copy link
Contributor Author

mavasani commented Sep 12, 2022

@dotnet/roslyn-compiler for second review

@mavasani mavasani closed this Sep 12, 2022
@mavasani mavasani reopened this Sep 12, 2022
@RikkiGibson RikkiGibson requested a review from a team September 12, 2022 17:44
@mavasani mavasani removed the Needs API Review Needs to be reviewed by the API review council label Sep 20, 2022
@mavasani
Copy link
Contributor Author

Merging this PR as the underlying public API has been approved by the compiler team in #7578 (comment). I'll address any further feedback with a follow-up PR.

@mavasani mavasani merged commit cd5e689 into dotnet:main Sep 20, 2022
@mavasani mavasani deleted the IsGeneratedCode branch September 20, 2022 05:02
@ghost ghost added this to the Next milestone Sep 20, 2022
@Cosifne Cosifne removed this from the Next milestone Sep 26, 2022
@Cosifne Cosifne added this to the 17.4 P3 milestone 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.

Expose "IsGeneratedCode" on analysis contexts
4 participants