Repository navigation
Conversation
941db81 to
64ad608
Compare
dr1rrb
left a comment
There was a problem hiding this comment.
We should have attributes only for classes that are in the Presentation namespace, we should not add that attribute everywhere.
If we need this, I would assume it means that we need to generate the attributes in the generated code, but not on all interfaces.
| internal class ListStateImpl<T> : FeedToListFeedAdapter<T>, IListState<T>, IStateImpl | ||
| internal class ListStateImpl< | ||
| [DynamicallyAccessedMembers(ListFeed.TRequirements)] | ||
| T |
There was a problem hiding this comment.
There is no reason why we need this on the ListStateImpl : it's a backing state for the IListState, not necessarily bound to the UI.
There was a problem hiding this comment.
See also, but the reason this was changed was because if IListFeed<T> changes, then this also needs to change. Most of this PR, as architected, is "fallout" of adding annotations to IListFeed<T>. The only way to not have this change is by not changing IListFeed<T> (which I suspect is your actual thinking).
| @@ -340,12 +343,18 @@ public IListState<T> GetOrCreateListState<T>(IListFeed<T> feed) | |||
| /// <param name="feed">The list feed to get source from.</param> | |||
| /// <returns>The list state wrapping the given list feed</returns> | |||
| [EditorBrowsable(EditorBrowsableState.Advanced)] | |||
| public IListState<T> GetOrCreateListState<T>(IFeed<IImmutableList<T>> feed) | |||
| public IListState<T> GetOrCreateListState< | |||
| [DynamicallyAccessedMembers(ListFeed.TRequirements)] | |||
| T | |||
| >(IFeed<IImmutableList<T>> feed) | |||
| => States.GetOrCreateState<IFeed<IImmutableList<T>>, IListState<T>>(feed, static (ctx, f) => new ListStateImpl<T>((StateImpl<IImmutableList<T>>)ctx.GetOrCreateState(f))); | |||
|
|
|||
| // WARNING: DO NOT USE, this breaks the cache by providing a custom config! | |||
| // We need to make those config "upgradable" in order to properly share the instances of State | |||
| internal ListStateImpl<T> DoNotUse_GetOrCreateListState<T>(IListFeed<T> feed, StateUpdateKind updatesKind) | |||
| internal ListStateImpl<T> DoNotUse_GetOrCreateListState< | |||
| [DynamicallyAccessedMembers(ListFeed.TRequirements)] | |||
| T | |||
| >(IListFeed<T> feed, StateUpdateKind updatesKind) | |||
| => States.GetOrCreateState(feed, /*static*/ (ctx, f) => new ListStateImpl<T>(new StateImpl<IImmutableList<T>>(ctx, f.AsFeed(), updatesKind: updatesKind))); | |||
|
|
|||
| /// <summary> | |||
| @@ -367,7 +376,10 @@ public IState<T> CreateState<T>(Option<T> initialValue) | |||
| /// <returns>The list state wrapping the given list feed</returns> | |||
| /// <exception cref="ObjectDisposedException">This context has been disposed.</exception> | |||
| [EditorBrowsable(EditorBrowsableState.Advanced)] | |||
| public IListState<T> CreateListState<T>(Option<IImmutableList<T>> initialValue) | |||
| public IListState<T> CreateListState< | |||
| [DynamicallyAccessedMembers(ListFeed.TRequirements)] | |||
| T | |||
| >(Option<IImmutableList<T>> initialValue) | |||
| => States.CreateState<IImmutableList<T>, IListState<T>>(initialValue, static (ctx, iv) => new ListStateImpl<T>((StateImpl<IImmutableList<T>>)ctx.CreateState(iv))); | |||
There was a problem hiding this comment.
Same here: Those methods are not related to the UI and does not use reflection internally, we should not need any attributes in that class
There was a problem hiding this comment.
See also, but the reason this was changed was because if IListFeed<T> changes, then this also needs to change. Most of this PR, as architected, is "fallout" of adding annotations to IListFeed<T>. The only way to not have this change is by not changing IListFeed<T> (which I suspect is your actual thinking).
Related question: what use case is there to use IListFeed<T> et al in a non UI context? Would it make sense to use IListFeed<T> in e.g. a non-UI daemon process?
64ad608 to
6778137
Compare
It's our favorite exercise, making uno.chefs run under NativeAOT! dotnet publish -c Release -r osx-x64 -f net10.0-desktop -p:TargetFrameworkOverride=net10.0-desktop -bl \ Chefs/Chefs.csproj \ -p:SelfContained=true -p:PublishAot=true -p:IsAotCompatible=true -p:UseSkiaRendering=true \ -p:IlcGenerateMapFile=true -p:IlcGenerateMstatFile=true -p:IlcGenerateDgmlFile=true -p:IlcGenerateMetadataLog=true \ -p:EmitCompilerGeneratedFiles=true -p:CompilerGeneratedFilesOutputPath=`pwd`/_gen Chefs/bin/Release/net10.0-desktop/osx-x64/publish/Chefs Login to the app, click on a recipe, and no Ingredients are shown. The app log contains messages such as: fail: Uno.UI.DataBinding.BindingPropertyHelper[0] The [Name] property getter does not exist on type [Chefs.Business.Models.Ingredient] The problem is that the properties on `Ingredient` are not being preserved. The question: how "best" to preserve them? As @jonpryor is the "automagic" sort, the "obvious" (and possibly incorrect) answer is "something *outside* of uno.chefs should ensure that the properties are preserved". But where is `Ingredient` mentioned within uno.chefs? What types can be (ab)used to preserve properties? Turns out, not too many places: % git grep '\<Ingredient\>' Chefs/Business/Models/Ingredient.cs:public record Ingredient Chefs/Business/Models/Ingredient.cs: public Ingredient(IngredientData ingredientData) Chefs/Business/Services/Recipes/IRecipeService.cs: ValueTask<IImmutableList<Ingredient>> GetIngredients(Guid recipeId, CancellationToken ct); Chefs/Business/Services/Recipes/RecipeService.cs: public async ValueTask<IImmutableList<Ingredient>> GetIngredients(Guid recipeId, CancellationToken ct) Chefs/Business/Services/Recipes/RecipeService.cs: return ingredientsData?.Select(x => new Ingredient(x)).ToImmutableList() ?? ImmutableList<Ingredient>.Empty; Chefs/Presentation/RecipeDetailsModel.cs: public IListFeed<Ingredient> Ingredients => ListFeed.Async(async ct => await _recipeService.GetIngredients(Recipe.Id, ct)); The `Ingredient` type definition won't help, `IImmutableList<T>` would be a *massive* stretch (plus we don't own it), which brings us to `IListFeed<T>`: that *is* a type that we control! Update `IListFeed<T>` to preserve properties on `T`: partial interface IListFeed< [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] > {} Perhaps unsurprisingly, that change impacts *everything*. (The patch size escalated quickly.) Integrating this change back into uno.chefs, and now I'm able to see Ingredients, without other changes to uno.chefs! (At least it worked.) But! We next see this message in the app log: fail: Uno.UI.DataBinding.BindingPropertyHelper[0] The [Count] property getter does not exist on type [Uno.Extensions.Reactive.Bindings.BindableListFeed`1[Chefs.Business.Models.Ingredient]] Similar question as before: how do we preserve the properties on `BindableListFeed<T>`? Raising the question: where is `BindableListFeed<T>` coming from? This was *quite* interesting, as `BindableListFeed<T>` doesn't appear *anywhere* in uno.chefs! % git grep BindableListFeed # no source code matches % grep -ril BindableListFeed _gen # no matches Add some printf logging to the `BindableListFeed<T>` constructors to see how it's constructed, and: at Uno.Extensions.Reactive.Bindings.BindableListFeed`1..ctor(String, IListState`1) + 0x91 at Uno.Extensions.Reactive.Bindings.BindableFactory.CreateList[T](String, IListState`1) + 0x2d at Chefs.Presentation.RecipeDetailsViewModel..ctor(RecipeDetailsModel) + 0x333 at Chefs.Presentation.RecipeDetailsViewModel..ctor(Recipe recipe, INavigator navigator, IRecipeService recipeService, IUserService userService, IMessenger messenger, IShareService shareService) + 0xa0 `BindableListFeed<Ingredient>` is constructed via a `BindableFactory.CreateList(…)` invocation within the generated `RecipeDetailsViewModel` constructor. Slight problem: there is no `BindableFactory.CreateList(…)` invocation within the `RecipeDetailsViewModel` constructor! public partial class RecipeDetailsViewModel { protected RecipeDetailsViewModel(global::Chefs.Presentation.RecipeDetailsModel model) { // … if (Ingredients is null) { var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor."); var ingredientsSourceListState = ctx.GetOrCreateListState(ingredientsSource); Ingredients = global::Uno.Extensions.Reactive.Bindings.BindableHelper.CreateBindableList(nameof(Ingredients), ingredientsSourceListState); } // … } } However, `BindableHelper.CreateBindableList(…)` *does* call `BindableFactory.CreateList(…)`, so this is presumably a case of method inlining by NativeAOT. With that in mind, @jonpryor can think of three ways to cause the `BindableListFeed<Ingredient>` properties to be preserved: 1. Some form of change within FeedsGenerator, or 2. Update `BindableFactory.CreateList<T>()` to use `[DynamicDependency]` to preserve the properties, or 3. Update the `BindableListFeed<T>` constructors to have `[DynamicDependency]`. The advantages to (3) is that it works, it's straightforward, and annotation site is "close" to the site of intended effect. (`BindableFactory.CreateList<T>()` doesn't obviously scream out "I may require dynamic dependencies!" The constructor doesn't either, but at least it's on the type being impacted!) (3) also gives us an interesting "hammer" with which to solve related issues. Issues such as: fail: Uno.UI.DataBinding.BindingPropertyHelper[0] The [Count] property getter does not exist on type [Uno.Extensions.Reactive.Bindings.Collections._BindableCollection.Views.BasicView] @jonpryor has no idea where `BasicView` is constructed from, but if it's constructed, we *probably* need its properties, so: add `[DynamicDependency]` to the `BasicView` constructor! The message is fixed. (This is a fascinating hammer, ripe for abuse.)
6778137 to
832766a
Compare
I don't disagree, but I don't know what the alternative looks like or would be architected. Background?Consider this snippet from the original description:
Not mentioned in the original description, but still of potential interest: where is % grep -ri '\<Ingredient\>' _gen
_gen/Uno.Extensions.Reactive.Generator/Uno.Extensions.Reactive.Generator.FeedsGenerator/Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs: var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor.");
_gen/Uno.Extensions.Reactive.Generator/Uno.Extensions.Reactive.Generator.FeedsGenerator/Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs: var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor.");
_gen/Uno.Extensions.Reactive.Generator/Uno.Extensions.Reactive.Generator.FeedsGenerator/Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs: public global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient> Ingredients { get; private set; }(As per the original description, Here are the full contents of // Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs
namespace Chefs.Presentation
{
public partial class RecipeDetailsViewModel
{
protected RecipeDetailsViewModel(global::Chefs.Presentation.RecipeDetailsModel model)
{
// …
if (Ingredients is null)
{
var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor.");
var ingredientsSourceListState = ctx.GetOrCreateListState(ingredientsSource);
Ingredients = global::Uno.Extensions.Reactive.Bindings.BindableHelper.CreateBindableList(nameof(Ingredients), ingredientsSourceListState);
}
// …
}
protected virtual void __Reactive_BindableInitializeForUpdatedModel(object updatedModel, global::Uno.Extensions.Reactive.Core.SourceContext ctx)
{
// …
if (Ingredients is null)
{
var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor.");
var ingredientsSourceListState = ctx.GetOrCreateListState(ingredientsSource);
Ingredients = global::Uno.Extensions.Reactive.Bindings.BindableHelper.CreateBindableList(nameof(Ingredients), ingredientsSourceListState);
}
// …
}
public global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient> Ingredients { get; private set; }
}
}It's basically still restricted to Alternate solutionsI can think of two alternative solutions to abusing
Leave it to the customernothing automagic; if things break, then the customer needs to fix it. In this case, the properties on diff --git a/Chefs/Business/Models/Ingredient.cs b/Chefs/Business/Models/Ingredient.cs
index 5b2fe9e3..000e8aaf 100644
--- a/Chefs/Business/Models/Ingredient.cs
+++ b/Chefs/Business/Models/Ingredient.cs
@@ -1,8 +1,10 @@
+using System.Diagnostics.CodeAnalysis;
using IngredientData = Chefs.Client.Models.IngredientData;
namespace Chefs.Business.Models;
public record Ingredient
{
+ [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(Ingredient))]
public Ingredient(IngredientData ingredientData)
{
UrlIcon = ingredientData.UrlIcon;
This fixes the original mentioned message: but there are others, which aren't fixed: Just apply the same solution! diff --git a/Chefs/Business/Models/CategoryWithCount.cs b/Chefs/Business/Models/CategoryWithCount.cs
index 856dbf2f..c66e0755 100644
--- a/Chefs/Business/Models/CategoryWithCount.cs
+++ b/Chefs/Business/Models/CategoryWithCount.cs
@@ -2,6 +2,7 @@ namespace Chefs.Business.Models;
public record CategoryWithCount
{
+ [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties, typeof(CategoryWithCount))]
internal CategoryWithCount(int count, Category category)
{
Count = count;Then there's the other messages mentioned in the original description: Just apply the same solution…? diff --git a/Chefs/Business/Models/Ingredient.cs b/Chefs/Business/Models/Ingredient.cs
index 5b2fe9e3..ee4e868a 100644
--- a/Chefs/Business/Models/Ingredient.cs
+++ b/Chefs/Business/Models/Ingredient.cs
@@ -1,8 +1,11 @@
+using System.Diagnostics.CodeAnalysis;
using IngredientData = Chefs.Client.Models.IngredientData;
namespace Chefs.Business.Models;
public record Ingredient
{
+ [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(Ingredient))]
+ [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(Uno.Extensions.Reactive.Bindings.BindableListFeed<>))]
public Ingredient(IngredientData ingredientData)
{
UrlIcon = ingredientData.UrlIcon;This is starting to get bananas, but it works… But then there's: Minor problem: The fundamental problem here is that "nobody" is going to add FeedsGenerator changeI haven't prototyped this, so I have no idea how straightforward of complicated it would be, but one can imagine that // Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs
namespace Chefs.Presentation
{
public partial class RecipeDetailsViewModel
{
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(global::Chefs.Business.Models.Ingredient))]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(global::Chefs.Business.Models.Step))]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(global::Chefs.Business.Models.Review))]
protected RecipeDetailsViewModel(global::Chefs.Presentation.RecipeDetailsModel model)
{
// …
}
}
}This will help with This won't help at all with I can imagine this partially working, but I'm not sure what a "proper" fix for XamlGenerator change?This is the most far-out idea, and I have no idea if it's possible, much less how practical it is. My (years old) original "understanding" of XAML is that it was a "serialization format" that could 1:1 become an object graph. <utu:AutoLayout …>
<TextBlock Text="{Binding Ingredients.Count, Converter={StaticResource StringFormatter}, ConverterParameter='{}{0} items'" />
</utu:AutoLayout>would be converted into: new Uno.Toolkit.UI.AutoLayout {
new TextBlock {
Text = …,
}
}except (1) that's not at all how it works, and (2) my understanding doesn't take bindings/etc. into consideration. The actual // _gen/Uno.UI.SourceGenerators/Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator/RecipeDetailsPage_ccf3346ad2a15b56e6347d9f3770ace0.cs
__p1.SetBinding(
global::Microsoft.UI.Xaml.Controls.TextBlock.TextProperty,
new Microsoft.UI.Xaml.Data.Binding()
{
Path = @"Ingredients.Count",
Converter = (global::Microsoft.UI.Xaml.Data.IValueConverter)global::Uno.UI.ResourceResolverSingleton.Instance.ResolveResourceStatic("StringFormatter", typeof(global::Microsoft.UI.Xaml.Data.IValueConverter), context: global::Chefs.GlobalStaticResources.__ParseContext_),
ConverterParameter = @"{0} items",
}
);Notably absent: any static, C#, reference to If there were some way to have However, this would be a massive change, and I cannot currently conceive of what that would even look like. |
Context: #2990 Context: #2990 (review) Context: #2969 Context: 8870ddf It's our favorite exercise, making uno.chefs run under NativeAOT! dotnet publish -c Release -r osx-x64 -f net10.0-desktop -p:TargetFrameworkOverride=net10.0-desktop -bl \ Chefs/Chefs.csproj \ -p:SelfContained=true -p:PublishAot=true -p:IsAotCompatible=true -p:UseSkiaRendering=true \ -p:IlcGenerateMapFile=true -p:IlcGenerateMstatFile=true -p:IlcGenerateDgmlFile=true -p:IlcGenerateMetadataLog=true \ -p:EmitCompilerGeneratedFiles=true -p:CompilerGeneratedFilesOutputPath=`pwd`/_gen Chefs/bin/Release/net10.0-desktop/osx-x64/publish/Chefs Login to the app, click on a recipe, and no Ingredients are shown. The app log contains messages such as: fail: Uno.UI.DataBinding.BindingPropertyHelper[0] The [Name] property getter does not exist on type [Chefs.Business.Models.Ingredient] The problem is that the properties on `Ingredient` are not being preserved. The question: how "best" to preserve them? As @jonpryor is the "automagic" sort, the "obvious" (and possibly incorrect) answer is "something *outside* of uno.chefs should ensure that the properties are preserved". But where is `Ingredient` mentioned within uno.chefs? What types can be (ab)used to preserve properties? Turns out, not too many places: % git grep '\<Ingredient\>' Chefs/Business/Models/Ingredient.cs:public record Ingredient Chefs/Business/Models/Ingredient.cs: public Ingredient(IngredientData ingredientData) Chefs/Business/Services/Recipes/IRecipeService.cs: ValueTask<IImmutableList<Ingredient>> GetIngredients(Guid recipeId, CancellationToken ct); Chefs/Business/Services/Recipes/RecipeService.cs: public async ValueTask<IImmutableList<Ingredient>> GetIngredients(Guid recipeId, CancellationToken ct) Chefs/Business/Services/Recipes/RecipeService.cs: return ingredientsData?.Select(x => new Ingredient(x)).ToImmutableList() ?? ImmutableList<Ingredient>.Empty; Chefs/Presentation/RecipeDetailsModel.cs: public IListFeed<Ingredient> Ingredients => ListFeed.Async(async ct => await _recipeService.GetIngredients(Recipe.Id, ct)); The `Ingredient` type definition won't help, `IImmutableList<T>` would be a *massive* stretch (plus we don't own it), which brings us to `IListFeed<T>`: that *is* a type that we control! PR #2990 explored an approach of updating `IListFeed<T>` to preserve properties on `T`: partial interface IListFeed< [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] > {} This approach was deemed far-reaching and undesirable. What else can be used to preserve `Ingredient` properties? Let's look at the *generated* code: % grep -ri '\<Ingredient\>' _gen _gen/Uno.Extensions.Reactive.Generator/Uno.Extensions.Reactive.Generator.FeedsGenerator/Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs: var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor."); _gen/Uno.Extensions.Reactive.Generator/Uno.Extensions.Reactive.Generator.FeedsGenerator/Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs: var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor."); _gen/Uno.Extensions.Reactive.Generator/Uno.Extensions.Reactive.Generator.FeedsGenerator/Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs: public global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient> Ingredients { get; private set; } The last line -- the `Ingredients` property -- is similar to PR #2969/8870ddf4. We could do something similar for `IListFeed<T>` usage, and generate: namespace Chefs.Presentation; public partial class RecipeDetailsViewModel { public Uno.Extensions.Reactive.IListFeed<Chefs.Business.Models.Ingredient> Ingredients { [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(Chefs.Business.Models.Ingredient))] get; private set; } } The use of `[DynamicDependency]` ensures that the public properties on `Ingredient` can still be accessed via Reflection, *without* needing to modify `IListFeed<T>`itself. Integrating this change back into uno.chefs, and now I'm able to see Ingredients, without other changes to uno.chefs! But! We next see this message in the app log: fail: Uno.UI.DataBinding.BindingPropertyHelper[0] The [Count] property getter does not exist on type [Uno.Extensions.Reactive.Bindings.BindableListFeed`1[Chefs.Business.Models.Ingredient]] Similar question as before: how do we preserve the properties on `BindableListFeed<T>`? Raising the question: where is `BindableListFeed<T>` coming from? This was *quite* interesting, as `BindableListFeed<T>` doesn't appear *anywhere* in uno.chefs! % git grep BindableListFeed # no source code matches % grep -ril BindableListFeed _gen # no matches Add some printf logging to the `BindableListFeed<T>` constructors to see how it's constructed, and: at Uno.Extensions.Reactive.Bindings.BindableListFeed`1..ctor(String, IListState`1) + 0x91 at Uno.Extensions.Reactive.Bindings.BindableFactory.CreateList[T](String, IListState`1) + 0x2d at Chefs.Presentation.RecipeDetailsViewModel..ctor(RecipeDetailsModel) + 0x333 at Chefs.Presentation.RecipeDetailsViewModel..ctor(Recipe recipe, INavigator navigator, IRecipeService recipeService, IUserService userService, IMessenger messenger, IShareService shareService) + 0xa0 `BindableListFeed<Ingredient>` is constructed via a `BindableFactory.CreateList(…)` invocation within the generated `RecipeDetailsViewModel` constructor. Slight problem: *there is no* `BindableFactory.CreateList(…)` invocation within the `RecipeDetailsViewModel` constructor! public partial class RecipeDetailsViewModel { protected RecipeDetailsViewModel(global::Chefs.Presentation.RecipeDetailsModel model) { // … if (Ingredients is null) { var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor."); var ingredientsSourceListState = ctx.GetOrCreateListState(ingredientsSource); Ingredients = global::Uno.Extensions.Reactive.Bindings.BindableHelper.CreateBindableList(nameof(Ingredients), ingredientsSourceListState); } // … } } However, `BindableHelper.CreateBindableList(…)` *does* call `BindableFactory.CreateList(…)`, so this is presumably a case of method inlining by NativeAOT. With that in mind, @jonpryor can think of three ways to cause the `BindableListFeed<Ingredient>` properties to be preserved: 1. Some form of change within FeedsGenerator, or 2. Update `BindableFactory.CreateList<T>()` to use `[DynamicDependency]` to preserve the properties, or 3. Update the `BindableListFeed<T>` constructors to have `[DynamicDependency]`. The problem with (1) is that it associates types which perhaps shouldn't be associated "like that", e.g. namespace Chefs.Presentation; public partial class RecipeDetailsViewModel { public Uno.Extensions.Reactive.IListFeed<Chefs.Business.Models.Ingredient> Ingredients { [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(Chefs.Business.Models.Ingredient))] [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(Uno.Extensions.Reactive.Bindings.BindableListFeed<>))] get; private set; } } Why should `IListFeed<Ingredient>` use dictate referencing of `BindableListFeed<T>`? (2) is reasonable. The advantages to (3) is that it works, it's straightforward, and annotation site is "close" to the site of intended effect. (`BindableFactory.CreateList<T>()` doesn't obviously scream out "I may require dynamic dependencies!" The constructor doesn't either, but at least it's on the type being impacted!) (3) also gives us an interesting "hammer" with which to solve related issues. Issues such as: fail: Uno.UI.DataBinding.BindingPropertyHelper[0] The [Count] property getter does not exist on type [Uno.Extensions.Reactive.Bindings.Collections._BindableCollection.Views.BasicView] `BasicView` in turn is constructed via: at Uno.Extensions.Reactive.Bindings.Collections._BindableCollection.Views.BasicView..ctor(CollectionFacet, CollectionChangedFacet, BindableCollectionExtendedProperties, SelectionFacet, PaginationFacet, EditionFacet) + 0x4f at Uno.Extensions.Reactive.Bindings.Collections._BindableCollection.Data.LeafStrategy.CreateView(IBindableCollectionViewSource) + 0x1d4 at Uno.Extensions.Reactive.Bindings.Collections._BindableCollection.Data.DataLayer..ctor(DataLayer, IServiceProvider, IBindableCollectionDataLayerStrategy, IDispatcher) + 0x71 at Uno.Extensions.Reactive.Bindings.Collections._BindableCollection.Data.DataLayer.Create(IBindableCollectionDataLayerStrategy, IObservableCollection, IServiceProvider, IDispatcher) + 0x3e at Uno.Extensions.Reactive.Dispatching.DispatcherLocal`1.GetValueCore(IDispatcher, IDispatcher) + 0x285 at Uno.Extensions.Reactive.Dispatching.DispatcherLocal`1.GetValue(IDispatcher) + 0x3f at Uno.Extensions.Reactive.Bindings.BindableListFeed`1.<Uno-Extensions-Reactive-ISignal<Uno-Extensions-Reactive-IMessage>-GetSource>d__66.MoveNext() + 0xb1 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine&) + 0x4d at Uno.Extensions.Reactive.Bindings.BindableListFeed`1.<Uno-Extensions-Reactive-ISignal<Uno-Extensions-Reactive-IMessage>-GetSource>d__66.System.Collections.Generic.IAsyncEnumerator<Uno.Extensions.Reactive.IMessage>.MoveNextAsync() + 0x46 at Uno.Extensions.Reactive.Utils.FeedUIHelper.<MoveNext>d__4`1.MoveNext() + 0x115 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine&) + 0x4d at Uno.Extensions.Reactive.Utils.FeedUIHelper.MoveNext[T](IAsyncEnumerator`1, CancellationToken) + 0x82 at Uno.Extensions.Reactive.Utils.FeedUIHelper.<GetSource>d__0.MoveNext() + 0x227 at System.Threading.ExecutionContext.RunInternal(ExecutionContext, ContextCallback, Object) + 0x89 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread) + 0x57 at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox, Boolean) + 0x52 at System.Threading.Tasks.Task.RunContinuations(Object) + 0x4f at System.Threading.Tasks.Task`1.TrySetResult(TResult) + 0x8e at System.Runtime.CompilerServices.AsyncValueTaskMethodBuilder`1.SetResult(TResult) + 0x29 at Uno.Extensions.Reactive.Utils.FeedUIHelper.<GetSourceEnumerator>d__3`1.MoveNext() + 0x284 at System.Threading.ExecutionContext.RunInternal(ExecutionContext, ContextCallback, Object) + 0x89 i.e. "nowhere" near `*.Presentation` logic, and yet its properties are used by XAML. Regardless, if it's constructed, we *probably* need its properties, so: add `[DynamicDependency]` to the `BasicView` constructor! The message is fixed. (This is a fascinating hammer, ripe for abuse.)
|
PR #2994 updates |
|
Superseded by PR #2994. |
It's our favorite exercise, making uno.chefs run under NativeAOT!
Login to the app, click on a recipe, and no Ingredients are shown.
The app log contains messages such as:
The problem is that the properties on
Ingredientare not beingpreserved.
The question: how "best" to preserve them?
As @jonpryor is the "automagic" sort, the "obvious" (and possibly
incorrect) answer is "something outside of uno.chefs should ensure
that the properties are preserved".
But where is
Ingredientmentioned within uno.chefs? What typescan be (ab)used to preserve properties?
Turns out, not too many places:
The
Ingredienttype definition won't help,IImmutableList<T>would be a massive stretch (plus we don't own it), which brings us
to
IListFeed<T>: that is a type that we control!Update
IListFeed<T>to preserve properties onT:Perhaps unsurprisingly, that change impacts everything.
(The patch size escalated quickly.)
Integrating this change back into uno.chefs, and now I'm able to see
Ingredients, without other changes to uno.chefs! (At least it worked.)
But! We next see this message in the app log:
Similar question as before: how do we preserve the properties on
BindableListFeed<T>?Raising the question: where is
BindableListFeed<T>coming from?This was quite interesting, as
BindableListFeed<T>doesn't appearanywhere in uno.chefs!
Add some printf logging to the
BindableListFeed<T>constructors tosee how it's constructed, and:
BindableListFeed<Ingredient>is constructed via aBindableFactory.CreateList(…)invocation within the generatedRecipeDetailsViewModelconstructor.Slight problem: there is no
BindableFactory.CreateList(…)invocationwithin the
RecipeDetailsViewModelconstructor!However,
BindableHelper.CreateBindableList(…)does callBindableFactory.CreateList(…), so this is presumably a case ofmethod inlining by NativeAOT.
With that in mind, @jonpryor can think of three ways to cause the
BindableListFeed<Ingredient>properties to be preserved:BindableFactory.CreateList<T>()to use[DynamicDependency]to preserve the properties, orBindableListFeed<T>constructors to have[DynamicDependency].The advantages to (3) is that it works, it's straightforward, and
annotation site is "close" to the site of intended effect.
(
BindableFactory.CreateList<T>()doesn't obviously scream out"I may require dynamic dependencies!" The constructor doesn't either,
but at least it's on the type being impacted!)
(3) also gives us an interesting "hammer" with which to solve related
issues. Issues such as:
@jonpryor has no idea where
BasicViewis constructed from, but ifit's constructed, we probably need its properties, so: add
[DynamicDependency]to theBasicViewconstructor! The messageis fixed. (This is a fascinating hammer, ripe for abuse.)
GitHub Issue (If applicable): closes #
PR Type
What kind of change does this PR introduce?
What is the current behavior?
What is the new behavior?
PR Checklist
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Runresults.Other information
Internal Issue (If applicable):