peachpie icon indicating copy to clipboard operation
peachpie copied to clipboard

Problems when compiling a project using Avalonia UI. Help is needed

Open FibonacciFox opened this issue 2 years ago • 6 comments

Hello, jakubmisek. I can't solve the problem for a very long time. There is a library .Net, which builds the project and replaces the AvaloniaXaml.Load(this) call with !XamlIlPopulateTrampoline(this). (screenshots are attached). In PHP, is it compiled into call_Load?0.Target(call_Load?0, this, , this); Because of this, it is impossible to build the project because the library cannot find AvaloniaXaml.Load(this) in the class. Link to the code section: XamlCompilerTaskExecutor.cs

Here is what happens in c# : image image

Here's what's going on in php:

image image

But if you specify in php like this:

public function Load(object $This){
      AvaloniaXamlLoader::Load($This)
}

Will compile to:

public virtual void Load(object This){
     AvaloniaXamlLoader.Load(This)
}

But that won't help in any way, because it's still waiting for AvaloniaXamlLoader.Load(this); when compiling. I will be very grateful in finding a solution to this problem.

FibonacciFox avatar Jul 18 '23 19:07 FibonacciFox

https://github.com/AvaloniaUI/Avalonia/blob/ffaf02cf036cd92776367cef3c0290dec9c59b84/src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs#L10C4-L25C10

FibonacciFox avatar Jul 18 '23 21:07 FibonacciFox

The compiler sees several Load() overloads, so it postpones the resolution to runtime using the callsite (call_Load?0).

The fix would be to improve the compiler so it resolves the Load(object) overload in compile time - I'm not sure, why it's not resolving it already, it should.

jakubmisek avatar Aug 28 '23 00:08 jakubmisek

The compiler sees several Load() overloads, so it postpones the resolution to runtime using the callsite (call_Load?0).

The fix would be to improve the compiler so it resolves the Load(object) overload in compile time - I'm not sure, why it's not resolving it already, it should.

As I understand it, this problem can be solved only at the compiler level?

FibonacciFox avatar Aug 28 '23 16:08 FibonacciFox

For a reference: this is how XAML compiler task tries to match AvaloniaXamlLoader.Load(this) call.

It currently recognizes the normal

ldarg.0
call AvaloniaXamlLoader.Load(object)

pattern and the monstrosity generated by F# compiler.

The peachpie pattern won't be easily recognizable since it would require us to analyze the CallSite static variable initialization that happens elsewhere and looks like an internal implementation detail.

So the preferable solution would be for peachpie to just emit the simple ldarg.0+call sequence.

kekekeks avatar Aug 29 '23 07:08 kekekeks

@kekekeks the compiler mainly emits simple .ldarg+.call. Here it's probably an unimplemented optimization where due to more similar overloads, it falls back to runtime overload resolution.

jakubmisek avatar Aug 29 '23 11:08 jakubmisek

So in PHP, you have the following?

AvaloniaXamlLoader::Load( $this );

jakubmisek avatar Jun 15 '24 14:06 jakubmisek