Skip to content

fix: Avoid stack overflow in BindableTypeLinkerGeneratorTask - #23148

Merged
jonpryor merged 1 commit into
masterfrom
dev/jonpryor/jonp-fix-stack-overflow-in-BindableTypeLinkerGenerator
Apr 29, 2026
Merged

jonpryor merged 1 commit into
masterfrom
dev/jonpryor/jonp-fix-stack-overflow-in-BindableTypeLinkerGenerator

Conversation

@jonpryor

Copy link
Copy Markdown
Contributor

Fixes: #23147

The <BindableTypeLinkerGeneratorTask*/> task didn't properly support types which reference themselves in the inheritance list, for example:

public class SomeInfo<T>
{
}

public class MyInfo : SomeInfo<MyInfo>
{
}

[Microsoft.UI.Xaml.Data.Bindable]
public partial class SampleChooserCategory
{
    public MyInfo MyInfo => null;
}

BindableTypeLinkerGeneratorTask.AddDeclaredPropertyTypes(), would try to "fully process" a type before "registering" the type within typesToProperties.

This fails in the above "self-referencing" scenario, because when processing MyInfo, it would first process the base class SomeInfo<MyInfo>, which would then process the type argument MyInfo, which would then process the base class SomeInfo<MyInfo>… and blow up with an MSB4217:

% dotnet publish src/SamplesApp/SamplesApp.Skia.netcoremobile/SamplesApp.Skia.netcoremobile.csproj \
  -r android-arm64 -f net10.0-android -p:UnoTargetFrameworkOverride=net10.0-android \
  -p:ApplicationId=uno.platform.samplesapp.skia.nativeaot -p:SkiaPublishAot=true \
  -p:SkiaSharpVersion=3.119.2-preview.1 -bl
…
…/src/SourceGenerators/Uno.UI.Tasks/Content/Uno.UI.Tasks.targets(483,3): error MSB4217:
  Task host node exited prematurely. Diagnostic information may be found in files in the
  temporary files directory named MSBuild_*.failure.txt.

To fix this, "registring a type within typesToProperties" needs to be done as a two step process:

  1. Register the type as soon as it is seen, by adding it to typesToProperties with an empty list of properties.

  2. Once the properties have been computed, update the registration with the actual list of properties.

This two step process allows the generator to "break the cycle" when processing such "self-referencing" types.

Updates src/SamplesApp to include a "test" for this scenario.

GitHub Issue: closes #

PR Type:

What is the current behavior? 🤔

What is the new behavior? 🚀

PR Checklist ✅

Please check if your PR fulfills the following requirements:

Other information ℹ️

Copilot AI review requested due to automatic review settings April 28, 2026 11:51
@github-actions github-actions Bot added area/code-generation Categorizes an issue or PR as relevant to code generation area/automation Categorizes an issue or PR as relevant to project automation labels Apr 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a build-time crash in the BindableTypeLinkerGeneratorTask by preventing infinite recursion when encountering self-referencing generic inheritance patterns during type graph traversal (notably in Native AOT builds).

Changes:

  • Register types in typesToProperties as soon as they’re discovered (placeholder entry), then update with computed properties to break recursive cycles.
  • Add a SamplesApp scenario that exercises the self-referencing generic base-type case via a [Bindable] type property.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/SourceGenerators/Uno.UI.Tasks/LinkerHintsGenerator/BindableTypeLinkerGeneratorTask.cs Adds early “seen” registration in AddDeclaredPropertyTypes to prevent stack overflow on recursive type graphs.
src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/SampleChooserCategory.cs Introduces a self-referencing generic type pattern and a bindable property referencing it to reproduce/guard the scenario.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 209541 has failed on Uno.UI - CI.

Fixes: #23147

The `<BindableTypeLinkerGeneratorTask*/>` task didn't properly
support types which reference themselves in the inheritance list,
for example:

	public class SomeInfo<T>
	{
	}

	public class MyInfo : SomeInfo<MyInfo>
	{
	}

	[Microsoft.UI.Xaml.Data.Bindable]
	public partial class SampleChooserCategory
	{
	    public MyInfo MyInfo => null;
	}

`BindableTypeLinkerGeneratorTask.AddDeclaredPropertyTypes()`, would try
to "fully process" a type before "registering" the type within
`typesToProperties`.

This fails in the above "self-referencing" scenario, because when
processing `MyInfo`, it would first process the base class
`SomeInfo<MyInfo>`, which would then process the type argument
`MyInfo`, which would then process the base class `SomeInfo<MyInfo>`…
and blow up with an MSB4217:

	% dotnet publish src/SamplesApp/SamplesApp.Skia.netcoremobile/SamplesApp.Skia.netcoremobile.csproj \
	  -r android-arm64 -f net10.0-android -p:UnoTargetFrameworkOverride=net10.0-android \
	  -p:ApplicationId=uno.platform.samplesapp.skia.nativeaot -p:SkiaPublishAot=true \
	  -p:SkiaSharpVersion=3.119.2-preview.1 -bl
	…
	…/src/SourceGenerators/Uno.UI.Tasks/Content/Uno.UI.Tasks.targets(483,3): error MSB4217:
	  Task host node exited prematurely. Diagnostic information may be found in files in the
	  temporary files directory named MSBuild_*.failure.txt.

To fix this, "registring a type within `typesToProperties`" needs to
be done as a *two step* process:

 1. Register the type *as soon as it is seen*, by adding it to
    `typesToProperties` with an empty list of properties.

 2. Once the properties have been computed, update the registration
    with the actual list of properties.

This two step process allows the generator to "break the cycle" when
processing such "self-referencing" types.

Updates `src/SamplesApp` to include a "test" for this scenario.
@jonpryor
jonpryor force-pushed the dev/jonpryor/jonp-fix-stack-overflow-in-BindableTypeLinkerGenerator branch from 28c2cf0 to 6024b09 Compare April 29, 2026 13:23
@jonpryor
jonpryor enabled auto-merge April 29, 2026 13:36
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 209790 has failed on Uno.UI - CI.

@jonpryor
jonpryor merged commit ceb8e2d into master Apr 29, 2026
42 checks passed
@jonpryor
jonpryor deleted the dev/jonpryor/jonp-fix-stack-overflow-in-BindableTypeLinkerGenerator branch April 29, 2026 18:14
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/code-generation Categorizes an issue or PR as relevant to code generation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StackOverflow in <BindableTypeLinkerGeneratorTask*/> on "recursive" types

4 participants