Skip to content

Conversation

@davidwrighton
Copy link
Member

Fix issue in R2R compilation where we would compile a method we could not generate a name for

  • This is caused by the the type of a parameter having a generic parameter which derived from a type not found in the compilation information
  • There are 2 fixes here
    1. Change the logic for computing the set of compilable methods to require that all parameters are loadable
    2. Change the implementation of loadable types to check generic instantiations for loadability
    • This required implementing a stack system to check types for loadability, as loading can require circular references to be resolved.
    • Add a check that the instantiation types of an instantiated generic are loadable. - Generic interfaces on arrays work now, so enable the the constraint checking logic.

Fixes #89337

… not generate a name for

- This is caused by the the type of a parameter having a generic parameter which derived from a type not found in the compilation information
- There are 2 fixes here
  1. Change the logic for computing the set of compilable methods to require that all parameters are loadable
  2. Change the implementation of loadable types to check generic instantiations for loadability
    - This required implementing a stack system to check types for loadability, as loading can require circular references to be resolved.
    - Add a check that the instantiation types of an instantiated generic are loadable.
    - Generic interfaces on arrays work now, so enable the the constraint checking logic.
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.

Looks good otherwise!

}
}

if (checkingMode)
Copy link
Member

Choose a reason for hiding this comment

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

I don't see a codepath that would lead to this if being taken.

ThrowHelper.ThrowTypeLoadException(ExceptionStringID.ClassLoadGeneral, type);
}

((CompilerTypeSystemContext)type.Context).EnsureLoadableType(type.BaseType);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
((CompilerTypeSystemContext)type.Context).EnsureLoadableType(type.BaseType);
((CompilerTypeSystemContext)type.Context).EnsureLoadableType(typeArg);

@davidwrighton davidwrighton merged commit 8c51f01 into dotnet:main Jul 25, 2023
trylek added a commit to trylek/runtime that referenced this pull request Aug 9, 2023
After David Wrighton's refactoring of type loadability check
in dotnet#89415 we started seeing stack overflow in Crossgen2 compilation
of the outerloop test

Loader/classloader/generics/regressions/DD117522/Test.csproj

This is because the test is a negative test that exercises runtime
behavior in the presence of a non-loadable type with recursive
definition. David's stricter descent into the type ends up in an
infinite recursion when presented with this invalid type.

I haven't found any easy way to incorporate the additional check
for recursive types into the loadability algorithm - in fact I'm
not even sure whether that's generally doable.

As a very simple way to protect against the infinite recursion
I propose adding a heuristic limit for the type analysis stack
size. I assume the proposed value 1024 to be more than enough for
both Crossgen2 and NativeAOT, if it's realistic that NativeAOT can
encounter deeper types than this, I can make the check specific
for Crossgen2.

Thanks

Tomas

Fixes: dotnet#89645
jkotas pushed a commit that referenced this pull request Aug 11, 2023
After David Wrighton's refactoring of type loadability check
in #89415 we started seeing stack overflow in Crossgen2 compilation
of the outerloop test

Loader/classloader/generics/regressions/DD117522/Test.csproj

This is because the test is a negative test that exercises runtime
behavior in the presence of a non-loadable type with recursive
definition. David's stricter descent into the type ends up in an
infinite recursion when presented with this invalid type.

I haven't found any easy way to incorporate the additional check
for recursive types into the loadability algorithm - in fact I'm
not even sure whether that's generally doable.

As a very simple way to protect against the infinite recursion
I propose adding a heuristic limit for the type analysis stack
size. I assume the proposed value 1024 to be more than enough for
both Crossgen2 and NativeAOT, if it's realistic that NativeAOT can
encounter deeper types than this, I can make the check specific
for Crossgen2.

Fixes: #89645
@ghost ghost locked as resolved and limited conversation to collaborators Aug 25, 2023
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.

Cross-gen failed to produce PDB for C# Dev Kit binaries

2 participants