Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Record trim analysis patterns in scanner - #2782

Merged
sbomer merged 4 commits into
dotnet:mainfrom
sbomer:trimPatterns
May 12, 2022
Merged

sbomer merged 4 commits into
dotnet:mainfrom
sbomer:trimPatterns

Conversation

@sbomer

@sbomer sbomer commented May 3, 2022 •

Copy link
Copy Markdown
Member

This allows running the scanner first with warnings disabled, then "replaying" the collected patterns to produce warnings. This will enable running the scanner multiple times for a compiler-generated method.

It basically works the same as the trim patterns in the analyzer. The main difference is that it also can enable
or disable marking - so during the scan, it doesn't do marking or report warnings. Then once the scan is complete,
it marks and produces warnings for the recorder call/assignment patterns. The exception is for the DAM type hierarchy
logic which will mark and warn during the scan, because it has its own cache that prevents doing any extra work the
second time around. (See #2777 (comment) for more context.)

This includes a few small changes to pass around DiagnosticContext to a few places that can produce warnings during the scan, such as resolving type names.

This allows running the scanner first with warnings disabled,
then "replaying" the collected patterns to produce warnings.
This will enable running the scanner multiple times for a
compiler-generated method.
@sbomer
sbomer requested a review from marek-safar as a code owner May 3, 2022 18:17

@vitek-karas vitek-karas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you measure perf impact? Since we're now running some of the code twice.
It's not necessarily to gate this change, but to have a feeling how bad it's going to be and if we should do something about it.

Comment on lines -331 to -332
if (operation.OpCode == OpCodes.Newobj)
AddReturnValue (methodParams[1]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This check was the reason why it is not handled by the shared code. I must admit I don't know how common it is, but it's in theory possible to see a call to .ctor I think - without the "new".
In any case, if we are to make this change, I would prefer it in a separate PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, I didn't really understand why we had this check. I kept it as before, by recording the instruction as part of the call pattern.

);
}

void RequireDynamicallyAccessedMembers (in DiagnosticContext diagnosticContext, in MultiValue value, ValueWithDynamicallyAccessedMembers targetValue)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As a separate PR - we should probably split the class into two:

  • One which is the method body scanner - so HandleCall and related - derived from MethodBodyScanner
  • Another one which provides all of the other functionality for MarkStep, like ProcessAttributeDataFlow and so on.

It's currently really weird since we have half of the class which always marks and produces diagnostics, and another half which does everything deferred.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, I had the same thought - the attribute/generic logic doesn't really have anything to do with scanning the method body.

sbomer added 3 commits May 4, 2022 10:08
- Rename some variables
- Clean up method parameter order
- Remove unnecessary parameters
- Inline variable only used once

@jtschuster jtschuster left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sbomer

sbomer commented May 4, 2022

Copy link
Copy Markdown
Member Author

Did you measure perf impact?

I measured the wall clock time to link the shared framework on my machine (mean + standard deviation):

  • Before: 9.720 +/- 0.166 s
  • After: 9.768 +/- 0.103 s

So looks like no significant perf impact from this measurement.

@sbomer
sbomer requested a review from vitek-karas May 4, 2022 19:23
@sbomer
sbomer merged commit bb974a6 into dotnet:main May 12, 2022
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
This allows running the scanner first with warnings disabled,
then "replaying" the collected patterns to produce warnings. This
will enable running the scanner multiple times for a
compiler-generated method.

It basically works the same as the trim patterns in the
analyzer. The main difference is that it also can enable or
disable marking - so during the scan, it doesn't do marking or
report warnings. Then once the scan is complete, it marks and
produces warnings for the recorder call/assignment patterns. The
exception is for the DAM type hierarchy logic which will mark and
warn during the scan, because it has its own cache that prevents
doing any extra work the second time around.

This includes a few small changes to pass around
DiagnosticContext to a few places that can produce warnings
during the scan, such as resolving type names.


Commit migrated from dotnet/linker@bb974a6
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants