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

Fix how root provider resolve generic methods #749

Merged
merged 9 commits into from
Mar 1, 2021
Merged

Fix how root provider resolve generic methods #749

merged 9 commits into from
Mar 1, 2021

Conversation

hez2010
Copy link

@hez2010 hez2010 commented Feb 26, 2021

  • There may be multiple candidate generic methods available, ilc shouldn't throw exceptions when it meets the first unmatched method.
  • To improve diagnosability I also append generic parameters to failure output.
  • Matching methods containing signature variables

Contributes to #733

@hez2010
Copy link
Author

hez2010 commented Feb 26, 2021

I think it's better to do matching for signature variables, but it seems that the correct approach is not as simple as the implementation in 2eef27e, so I want to skip it for now.

Update: Done.

@hez2010
Copy link
Author

hez2010 commented Feb 27, 2021

@MichalStrehovsky I've added support to match all parameters, and I've tested it with below code:

using System;
using System.Collections.Generic;

namespace DimRepro
{
    unsafe interface ITest<T>
    {
        void Bar(string baz) => Console.WriteLine(baz);
        void Bar(T what, string baz) => Console.WriteLine(what.ToString() + baz);
        void Bar<U>(U what, string baz, List<T> how) => Console.WriteLine(what.ToString() + how.ToString() + baz);
        void Bar<U>(U[] what, string baz, List<T> how) => Console.WriteLine(what.ToString() + how.ToString() + baz);
        void Bar<U>(List<T> what, string baz, List<U> how) => Console.WriteLine(what.ToString() + how.ToString() + baz);
        void Bar<U>(List<U[]> what, string baz, List<T> how) => Console.WriteLine(what.ToString() + how.ToString() + baz);
        void Bar<U>(Dictionary<U, T> what, string baz, List<T> how) => Console.WriteLine(what.ToString() + how.ToString() + baz);
    }

    class Test<T> : ITest<T> { }

    class Program
    {
        static void Main(string[] args)
        {
            ITest<float> x = new Test<float>();
            x.Bar("test");
            x.Bar(5, "test");
            x.Bar(5, "hello", new List<float>());
            x.Bar(new[] { 5 }, "hello", new List<float>());
            x.Bar(new List<float> { 5f }, "hello", new List<string>());
            x.Bar(new List<int[]> { new[] { 5 } }, "hello", new List<float>());
            x.Bar(new Dictionary<int, float>(), "hello", new List<float>());
        }
    }
}

rd.xml:

<Directives>
    <Application>
        <Assembly Name="DimRepro">
            <Type Name="DimRepro.ITest`1[[System.Single,System.Private.CoreLib]]" Dynamic="Required All">
                <Method Name="Bar" Dynamic="Required">
                    <Parameter Name="System.Single,System.Private.CoreLib" />
                    <Parameter Name="System.String,System.Private.CoreLib" />
                </Method>
                <Method Name="Bar" Dynamic="Required">
                    <GenericArgument Name="System.Int32,System.Private.CoreLib" />
                    <Parameter Name="System.Int32,System.Private.CoreLib" />
                    <Parameter Name="System.String,System.Private.CoreLib" />
                    <Parameter Name="System.Collections.Generic.List`1[[System.Single,System.Private.CoreLib]],System.Private.CoreLib" />
                </Method>
                <Method Name="Bar" Dynamic="Required">
                    <GenericArgument Name="System.Int32,System.Private.CoreLib" />
                    <Parameter Name="System.Int32[],System.Private.CoreLib" />
                    <Parameter Name="System.String,System.Private.CoreLib" />
                    <Parameter Name="System.Collections.Generic.List`1[[System.Single,System.Private.CoreLib]],System.Private.CoreLib" />
                </Method>
                <Method Name="Bar" Dynamic="Required">
                    <GenericArgument Name="System.Int32,System.Private.CoreLib" />
                    <Parameter Name="System.Collections.Generic.List`1[[System.Single,System.Private.CoreLib]],System.Private.CoreLib" />
                    <Parameter Name="System.String,System.Private.CoreLib" />
                    <Parameter Name="System.Collections.Generic.List`1[[System.Int32,System.Private.CoreLib]],System.Private.CoreLib" />
                </Method>
                <Method Name="Bar" Dynamic="Required">
                    <GenericArgument Name="System.Int32,System.Private.CoreLib" />
                    <Parameter Name="System.Collections.Generic.List`1[[System.Int32[],System.Private.CoreLib]],System.Private.CoreLib" />
                    <Parameter Name="System.String,System.Private.CoreLib" />
                    <Parameter Name="System.Collections.Generic.List`1[[System.Single,System.Private.CoreLib]],System.Private.CoreLib" />
                </Method>
                <Method Name="Bar" Dynamic="Required">
                    <GenericArgument Name="System.Int32,System.Private.CoreLib" />
                    <Parameter Name="System.Collections.Generic.Dictionary`2[[System.Int32,System.Private.CoreLib],[System.Single,System.Private.CoreLib]],System.Private.CoreLib" />
                    <Parameter Name="System.String,System.Private.CoreLib" />
                    <Parameter Name="System.Collections.Generic.List`1[[System.Single,System.Private.CoreLib]],System.Private.CoreLib" />
                </Method>
            </Type>
            <Type Name="DimRepro.Test`1[[System.Single,System.Private.CoreLib]]" Dynamic="Required All" />
        </Assembly>

    </Application>
</Directives>

@hez2010
Copy link
Author

hez2010 commented Feb 28, 2021

I think this PR is ready. rd.xml documents may need updates later.

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

Thank you!

@MichalStrehovsky MichalStrehovsky merged commit dbcc4ce into dotnet:feature/NativeAOT Mar 1, 2021
@hez2010 hez2010 deleted the codespace-6b0e branch March 5, 2021 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants