Skip to content

Conversation

@vitek-karas
Copy link
Member

… code.

The problem occurs when an entire type/assembly is preserved through explicit rooting (command line, rd.xml, ...). If such type contains a local function (for example) which is only called from a branch which is going to be removed by constant-prop/branch removal the internal tracking of compiler generated methods will see this local function as orphaned (not belonging to any user method). This leads to a case where we will try to run data flow on the local function - but that should never happen for compiler generated methods directly -> assert.

The fix is (just like in the linker), to never run data flow on compiler generated methods directly - they should only run data flow as part of their respective user method.

Fixes #73027

… code.

The problem occurs when an entire type/assembly is preserved through explicit rooting (command line, rd.xml, ...). If such type contains a local function (for example) which is only called from a branch which is going to be removed by constant-prop/branch removal the internal tracking of compiler generated methods will see this local function as orphaned (not belonging to any user method). This leads to a case where we will try to run data flow on the local function - but that should never happen for compiler generated methods directly -> assert.

The fix is (just like in the linker), to never run data flow on compiler generated methods directly - they should only run data flow as part of their respective user method.

Fixes dotnet#73027
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.

I don't have much context about the surrounding NativeAot code, but locally it LGTM. Thanks!

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

Another possible fix would be to not use ILProvider, but EcmaMethodIL.Create directly - that one sees untransformed IL before constprop. I could see that having both advantages and disadvantages.

methodILDefinition = FlowAnnotations.ILProvider.GetMethodIL(userMethod);
}

// Data-flow (reflection scanning) for compiler-generated methods will happen as part of the
Copy link
Member

Choose a reason for hiding this comment

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

I only understood what's going on after re-reading the pull request description - could you add a sentence describing when this can happen (the lines before this are supposed to do this conversion to user code).

@MichalStrehovsky
Copy link
Member

Merging because I'm running into this in #69108 and can't get a checked build of anything without this fix. We need to add checked test coverage to the CI matrix.

@MichalStrehovsky MichalStrehovsky merged commit 75abdd4 into dotnet:main Aug 1, 2022
@vitek-karas vitek-karas deleted the FixAssertInCGDataFlow branch August 1, 2022 08:27
@ghost ghost locked as resolved and limited conversation to collaborators Aug 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[NativeAOT] Assert when compiling System.Runtime.Tests

3 participants