Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

There is an existing implementation of "does this introduce variance complexities"?

Cc @dotnet/ilc-contrib

There is an existing implementation of "does this introduce variance complexities"?
@ghost
Copy link

ghost commented Mar 3, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

There is an existing implementation of "does this introduce variance complexities"?

Cc @dotnet/ilc-contrib

Author: MichalStrehovsky
Assignees: MichalStrehovsky
Labels:

area-NativeAOT-coreclr

Milestone: -

@MichalStrehovsky
Copy link
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

// no real upper bound on the number of actual classes implementing it
// due to MakeGenericType.
if (CanAssumeWholeProgramViewOnInterfaceUse(baseInterface))
if (CanAssumeWholeProgramViewOnInterfaceUse(factory, type, baseInterface))
Copy link
Member

Choose a reason for hiding this comment

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

Is this condition just a performance optimization that is trying to keep _disqualifiedInterfaces set small? In other words, if we deleted this condition, would anything break?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I stared at it a bit and it doesn't look necessary. It wasn't a conscious perf optimization because it doesn't seem worth it. Deleted.

// Interfaces implemented by arrays and array enumerators have weird casting rules
// due to array covariance (string[] castable to object[], or int[] castable to uint[]).
// Disqualify such interfaces.
if (!type.IsCanonicalSubtype(CanonicalFormKind.Any) &&
Copy link
Member

Choose a reason for hiding this comment

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

Is the IsCanonicalSubtype early out correct? Consider:

var a = new int[1];
var b = (X<string>.MyEnum[])(object)a;

Console.WriteLine(b);

class X<T>
{
    public enum MyEnum
    {
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

It was fine for that - we were disqualifying template types above (IsCanonical detects template types).

I moved these two checks together. It looks better.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

LGTM!

@MichalStrehovsky
Copy link
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@MichalStrehovsky MichalStrehovsky merged commit 8de96c8 into dotnet:main Mar 7, 2023
@MichalStrehovsky MichalStrehovsky deleted the moredevirt branch March 7, 2023 04:52
@ghost ghost locked as resolved and limited conversation to collaborators Apr 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants