Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Extend mono_gsharedvt_constrained_call JIT icall to handle static virtual methods #90875

Merged
merged 5 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/mono/mono/mini/jit-icalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ constrained_gsharedvt_call_setup (gpointer mp, MonoMethod *cmethod, MonoClass *k

error_init (error);

if (mono_class_is_interface (klass) || !m_class_is_valuetype (klass)) {
if ((mono_class_is_interface (klass) || !m_class_is_valuetype (klass)) && !m_method_is_static (cmethod)) {
MonoObject *this_obj;

is_iface = mono_class_is_interface (klass);
Expand Down Expand Up @@ -1390,7 +1390,12 @@ constrained_gsharedvt_call_setup (gpointer mp, MonoMethod *cmethod, MonoClass *k
}
}

if (m_class_is_valuetype (klass) && (m->klass == mono_defaults.object_class || m->klass == m_class_get_parent (mono_defaults.enum_class) || m->klass == mono_defaults.enum_class)) {
if (m_method_is_static (cmethod)) {
/*
* Static calls don't have this arg
*/
*this_arg = NULL;
} else if (m_class_is_valuetype (klass) && (m->klass == mono_defaults.object_class || m->klass == m_class_get_parent (mono_defaults.enum_class) || m->klass == mono_defaults.enum_class)) {
/*
* Calling a non-vtype method with a vtype receiver, has to box.
*/
Expand Down
47 changes: 47 additions & 0 deletions src/tests/JIT/Generics/ConstrainedCall/static_virtual_calls.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

using System;
using Xunit;


public interface ITypeChecker
{
static abstract bool Test<T>();
}

public interface IHandler
{
bool Test<T>();
}

public class TypeChecker : ITypeChecker
{
public static bool Test<T>() => true;
}

public class Handler<TChecker> : IHandler where TChecker : ITypeChecker
{
public bool Test<T>() => TChecker.Test<T>();
}

public class test
{
[Fact]
public static int TestEntryPoint()
Copy link
Member

Choose a reason for hiding this comment

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

This test seems quite trivial. Would it even fail on CI ? Or is the failure dependent on compilation flags that we don't use on CI.

Copy link
Member Author

@kotlarmilos kotlarmilos Aug 23, 2023

Choose a reason for hiding this comment

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

The issue occurred in full AOT mode only. This test is used locally to reproduce and fix the issue, which is similar to the customer reported issue. Do you think it should be expanded?

Copy link
Member

Choose a reason for hiding this comment

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

If you disable your fix will this test fail on CI currently ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Before adding a new test, we should verify if it is not already covered on the CI. This will be done once the AOT job is fixed. The customer issue won't be closed until we verify that this case has test coverage.

{
var handler = GetHandler();
bool test = handler.Test<int>();
if (test) {
Console.WriteLine("PASSED");
return 100;
}

Console.WriteLine("FAILED");
return 101;
}

public static IHandler GetHandler() => new Handler<TypeChecker>();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
Loading