From 8b0de36222d6a250ec38ede910eec29a04af146b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 19 Jul 2023 12:24:20 +0900 Subject: [PATCH 1/3] Expand description of generic recursions Addresses https://github.com/dotnet/runtime/issues/85184#issuecomment-1636472826. --- .../deploying/native-aot/warnings/il3054.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/core/deploying/native-aot/warnings/il3054.md b/docs/core/deploying/native-aot/warnings/il3054.md index 66e29ff6bedd6..e84fb582a41a9 100644 --- a/docs/core/deploying/native-aot/warnings/il3054.md +++ b/docs/core/deploying/native-aot/warnings/il3054.md @@ -20,6 +20,8 @@ When the AOT compilation process detects such unbounded growth, it cuts off the Even though it's unlikely the throwing method body will be reached at run time, it's advisable to remove the generic recursion by restructuring the code. Generic recursion negatively affects compilation speed and the size of the output executable. +In .NET, generic code instantiated over reference type is shared across all reference typed instantiations (for example, the code to support `List` and `List` is the same). However, additional native data structures are needed to express the "generic context" (the thing that gets substituted for `T`). It is possible to form generic recursion within these data structures as well. For example, this can happen if the generic context for `Foo` needs to refer to `Foo>` that in turn needs `Foo>>`. + ## Example The following program will work correctly for input "2" but throws an exception for input "100". @@ -56,3 +58,25 @@ Unhandled Exception: System.TypeLoadException: Could not load type 'Program' fro at Program.<
$>g__CauseGenericRecursion|0_0[T](Int32) + 0x1f at Program.
$(String[]) + 0x3a ``` + +Similarly, the following program causes recursion within native data structures (as opposed to generic recursion: + +ILC: AOT analysis warning IL3054: Program.<
$>g__Recursive|0_0>>>>(): Generic expansion to 'Program.<
$>g__Recursive|0_0>>>>>()' was aborted due to generic recursion. An exception will be thrown at runtime if this codepath is ever reached. Generic recursion also negatively affects compilation speed and the size of the compilation output. It is advisable to remove the source of the generic recursion by restructuring the program around the source of recursion. The source of generic recursion might include: 'Program.<
$>g__Recursive|0_0()' + +```csharp +// AOT analysis warning IL3054: +// Program.<
$>g__Recursive|0_0>>>>(): +// Generic expansion to 'Program.<
$>g__Recursive|0_0>>>>>()' +// was aborted due to generic recursion. An exception will be thrown at runtime if this codepath +// is ever reached. Generic recursion also negatively affects compilation speed and the size of +// the compilation output. It is advisable to remove the source of the generic recursion +// by restructuring the program around the source of recursion. The source of generic recursion +// might include: 'Program.<
$>g__Recursive|0_0()' + +using System.Collections.Generic; + +Recursive(); + +static void Recursive() => Recursive>(); +``` + From 12b38a7cf73534436b99951fd4f65db38500eb49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 19 Jul 2023 12:25:11 +0900 Subject: [PATCH 2/3] Update il3054.md --- docs/core/deploying/native-aot/warnings/il3054.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/core/deploying/native-aot/warnings/il3054.md b/docs/core/deploying/native-aot/warnings/il3054.md index e84fb582a41a9..9627e5d94523a 100644 --- a/docs/core/deploying/native-aot/warnings/il3054.md +++ b/docs/core/deploying/native-aot/warnings/il3054.md @@ -61,8 +61,6 @@ Unhandled Exception: System.TypeLoadException: Could not load type 'Program' fro Similarly, the following program causes recursion within native data structures (as opposed to generic recursion: -ILC: AOT analysis warning IL3054: Program.<
$>g__Recursive|0_0>>>>(): Generic expansion to 'Program.<
$>g__Recursive|0_0>>>>>()' was aborted due to generic recursion. An exception will be thrown at runtime if this codepath is ever reached. Generic recursion also negatively affects compilation speed and the size of the compilation output. It is advisable to remove the source of the generic recursion by restructuring the program around the source of recursion. The source of generic recursion might include: 'Program.<
$>g__Recursive|0_0()' - ```csharp // AOT analysis warning IL3054: // Program.<
$>g__Recursive|0_0>>>>(): @@ -79,4 +77,3 @@ Recursive(); static void Recursive() => Recursive>(); ``` - From a8a154502b0a2e36a173941749feb54c009e60c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 19 Jul 2023 12:40:29 +0900 Subject: [PATCH 3/3] Update il3054.md --- docs/core/deploying/native-aot/warnings/il3054.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/deploying/native-aot/warnings/il3054.md b/docs/core/deploying/native-aot/warnings/il3054.md index 9627e5d94523a..5eedff23d6dd7 100644 --- a/docs/core/deploying/native-aot/warnings/il3054.md +++ b/docs/core/deploying/native-aot/warnings/il3054.md @@ -59,7 +59,7 @@ Unhandled Exception: System.TypeLoadException: Could not load type 'Program' fro at Program.
$(String[]) + 0x3a ``` -Similarly, the following program causes recursion within native data structures (as opposed to generic recursion: +Similarly, the following program causes recursion within native data structures (as opposed to generic recursion within native code), since the instantiation is over a reference type, but has a cycle: ```csharp // AOT analysis warning IL3054: