Detecting generated code is an essential building block for our analyzers. At the moment, we use a heuristic on the syntax-tree level in the GeneratedCodeRecognizer. This has some problems:
Some attributes, we use for detection [DebuggerNonUserCode] can be applied at method level. We consider the whole tree as auto-generated if such an attribute is present at the method level. This causes FNs.
Each registered action invocation calls the "AutoGenerated" logic and is, therefore, on the hot path. We cache on the syntax tree, but the factory method is still executed multiple times per tree until it is stored in the cache (the factory is lock-free).
We should consider lighting up these properties and using them if the compiler supports them.
We need to see how Roslyn recognizes the AutoGenerated code, how it differs from outer logic, and what to do about the differences.
Detecting generated code is an essential building block for our analyzers. At the moment, we use a heuristic on the syntax-tree level in the GeneratedCodeRecognizer. This has some problems:
[DebuggerNonUserCode]
can be applied at method level. We consider the whole tree as auto-generated if such an attribute is present at the method level. This causes FNs.In https://github.com/dotnet/roslyn/issues/7578 from September 2022,
IsGeneratedCode
was added to all..AnalyzisContext
types by the Roslyn team:We should consider lighting up these properties and using them if the compiler supports them. We need to see how Roslyn recognizes the AutoGenerated code, how it differs from outer logic, and what to do about the differences.
Related links: