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

Don't crash the trim analyzer if it finds unrecognized nodes in the input #88836

Merged
merged 1 commit into from
Jul 17, 2023

Conversation

vitek-karas
Copy link
Member

New versions of the compiler will introduce new nodes and values. The analyzer can never be 100% in sync with the compiler, so it needs to be able to gracefully handle nodes it doesn't know anything about.

Change the several throws to just Debug.Fail. For end-users if we hit unrecognized node, we will effectively ignore that part of the code. So not 100% precise, but the analyzer will never be 100% regardless.

This is in response to #88684, but we can't add tests for it yet because the necessary compiler changes are in Preview 6, the repo is still on Preview 5.

…nput

New versions of the compiler will introduce new nodes and values. The analyzer can never be 100% in sycn with the compiler, so it needs to be able to gracefully handle nodes it doesn't know anything about.

Change the several throws to just Debug.Fail. For end-users if we hit unrecognized node, we will effectively ignore that part of the code. So not 100% precise, but the analyzer will never be 100% regardles.

This is in response to dotnet#88684, but we can't add tests for it yet because the necessary compiler changes are in Preview 6, the repo is still on Preview 5.
@vitek-karas vitek-karas added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Jul 13, 2023
@vitek-karas vitek-karas added this to the 8.0.0 milestone Jul 13, 2023
@vitek-karas vitek-karas requested a review from sbomer July 13, 2023 14:53
@vitek-karas vitek-karas self-assigned this Jul 13, 2023
@ghost ghost added the linkable-framework Issues associated with delivering a linker friendly framework label Jul 13, 2023
@ghost
Copy link

ghost commented Jul 13, 2023

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
See info in area-owners.md if you want to be subscribed.

Issue Details

New versions of the compiler will introduce new nodes and values. The analyzer can never be 100% in sync with the compiler, so it needs to be able to gracefully handle nodes it doesn't know anything about.

Change the several throws to just Debug.Fail. For end-users if we hit unrecognized node, we will effectively ignore that part of the code. So not 100% precise, but the analyzer will never be 100% regardless.

This is in response to #88684, but we can't add tests for it yet because the necessary compiler changes are in Preview 6, the repo is still on Preview 5.

Author: vitek-karas
Assignees: vitek-karas
Labels:

area-Tools-ILLink

Milestone: 8.0.0

@ghost
Copy link

ghost commented Jul 13, 2023

Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr, @marek-safar
See info in area-owners.md if you want to be subscribed.

Issue Details

New versions of the compiler will introduce new nodes and values. The analyzer can never be 100% in sync with the compiler, so it needs to be able to gracefully handle nodes it doesn't know anything about.

Change the several throws to just Debug.Fail. For end-users if we hit unrecognized node, we will effectively ignore that part of the code. So not 100% precise, but the analyzer will never be 100% regardless.

This is in response to #88684, but we can't add tests for it yet because the necessary compiler changes are in Preview 6, the repo is still on Preview 5.

Author: vitek-karas
Assignees: vitek-karas
Labels:

linkable-framework, area-Tools-ILLink

Milestone: 8.0.0

Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

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

What are your thoughts on making this a warning instead? It would be nice to leave some feedback channel for the unimplemented cases.

@vitek-karas
Copy link
Member Author

I'm on the edge on this one:

  • It is non-actionable to the end user - so we're basically pushing our mess to the end user to help us to clean it... not nice
  • I'd love to know if this happens obviously

Currently I'm slightly leaning towards silence. Basically the thinking is:

  • We have to keep an eye on all language/runtime changes anyway to keep illink and NativeAOT in sync with that support. We dropped the ball on InlineArrays for some reason, but that should be easy to fix (as a process/awareness). A counter example is UnsafeAccess which was/is handled well. So we will write tests for illink/AOT for this and the analyzer will get some of that code to run on. And we will "know" about it so probably try it as well.
  • I think there's basically two types of changes the compiler might do
    • small improvements like this one which are very likely explicit opt-in (as in the user has to write the new code shape) - so not having support for it is probably not going to hurt anything. And if it does we'll hear about it.
    • large changes (like async) - but we will be well aware of those anyway, so we will react soon.

The argument against the warning is: If this happens to you (maybe because of a nuget dependency for example), there's nothing you can do other than file the issue (which most people won't bother with anyway). And there's no "Fixing it" either, you have to figure out the NoWarn and suppress it. But that's likely going to stay in your codebase forever, and so the next time this happens, you won't know and won't tell us anyway.

@sbomer
Copy link
Member

sbomer commented Jul 13, 2023

I agree that for large compiler features we would probably be able to anticipate this. I also see the potential problem you point out with NoWarn, especially since a suppression would prevent future warnings about different unimplemented node types. I still think we would get good feedback from a warning; the warning could say "please file an issue".

For smaller cases like this, I don't think we would have found out about this hole until much later without the feedback channel. Another idea is to run the debug version of the analyzer on runtime bits (not sure if the performance would be acceptable - maybe we would do it in certain ci legs only)?

@agocke in case you have other ideas.

@agocke
Copy link
Member

agocke commented Jul 13, 2023

What are your thoughts on making this a warning instead?

Warnings are errors for customers. Can't do that.

I'd instead do something like Debug.Assert or somehow run in a different configuration locally. That would let us see the failure in runtime dogfooding, but wouldn't cause problems for customers. Just looked at the diff and saw Debug.Fail. We should just ensure that the analyzer is running in Debug in some scenario.

@vitek-karas
Copy link
Member Author

Actually I think it would be valuable to have a CI leg which runs as many analyzers/sourcegenerators as we can in Debug mode. Ideally all the analyzers which are built by the runtime repo (but I don't know how the codeflow is setup).

I filed #88901 to track that.

@agocke
Copy link
Member

agocke commented Jul 14, 2023

There's also something I remember called a "non-fatal Watson" which is supposed to send some sort of Watson failure, without crashing or throwing. I can go searching for what that is.

@vitek-karas vitek-karas merged commit 0f56e16 into dotnet:main Jul 17, 2023
55 checks passed
@vitek-karas vitek-karas deleted the DontCrashAnalyzerOnUnknown branch July 17, 2023 09:06
@ghost ghost locked as resolved and limited conversation to collaborators Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants