Skip to content

Follow up to universal System.Linq.Expressions #62229

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

Merged
merged 2 commits into from
Dec 7, 2021

Conversation

MichalStrehovsky
Copy link
Member

Most of this is test changes so that we run more tests when the expression IL compiler is disabled. There is one product change that we don't need to take, but felt like an improvement. I'll put comments inline in a bit.

@ghost
Copy link

ghost commented Dec 1, 2021

Tagging subscribers to this area: @cston
See info in area-owners.md if you want to be subscribed.

Issue Details

Most of this is test changes so that we run more tests when the expression IL compiler is disabled. There is one product change that we don't need to take, but felt like an improvement. I'll put comments inline in a bit.

Author: MichalStrehovsky
Assignees: -
Labels:

area-System.Linq.Expressions

Milestone: -

Copy link
Member Author

@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.

I've validated that we run the same number of tests in default CoreCLR configuration.

I've also validated that the test fully passes when I artificially disable IL expression compiler on CoreCLR.

@@ -109,7 +109,7 @@ private static bool IsByRef(DynamicMetaObject mo)

private static Type MakeNewCustomDelegate(Type[] types)
{
if (LambdaExpression.CanCompileToIL)
if (RuntimeFeature.IsDynamicCodeSupported)
Copy link
Member Author

Choose a reason for hiding this comment

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

PRODUCT CHANGE: the existing setting was mechanically propagated from FEATURE_COMPILE, but I think here we should be more nuanced between "IL expression compiler is disabled" and "the platform supports reflection emit".

This codepath is not related to compiling IL expressions and we can allow it if emit is otherwise supported. It doesn't feel like it should be lumped into IL expression compiler not being enabled.

If we don't take this change, we need to disable a couple more tests on IL compiler being unavailable.

@@ -54,7 +54,7 @@ public static IEnumerable<object[]> ObjectArguments()
yield return new[] {new object()};
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/55070", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55070", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
Copy link
Member Author

Choose a reason for hiding this comment

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

This test is passing with CoreCLR and IL compiler disabled, so whatever this is, it's iDevice-specific. This test was disabled in #54970 and not part of the mechanical refactoring.

@@ -335,8 +331,7 @@ private class ManyOverloads
int arg10) => 11;
}

// We're not testing compilation, but we do need Reflection.Emit for the test
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[Fact]
Copy link
Member Author

Choose a reason for hiding this comment

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

This was probably hitting some .NET Native specific issues with dynamic keyword. I don't see it using Ref.Emit anywhere so leaving like this.

@@ -380,8 +375,7 @@ public static IEnumerable<object[]> SameNameObjectPairs()
return testObjects.SelectMany(i => testObjects.Select(j => new[] { i, j }));
}

// We're not testing compilation, but we do need Reflection.Emit for the test
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[Theory]
Copy link
Member Author

Choose a reason for hiding this comment

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

Also don't see anything ref.emitting. Was probably some .NET Native issue related to dynamic.

@@ -464,15 +464,15 @@ public void IndexedPropertyVarArgs()
AssertExtensions.Throws<ArgumentException>("propertyName", () => Expression.Property(instance, "Item", Expression.Constant(0), Expression.Constant(0), Expression.Constant(0)));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[Fact]
Copy link
Member Author

Choose a reason for hiding this comment

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

Don't see ref emitting here and it passes with IL expression compiler disabled, so leaving like this.

// IsNotLinqExpressionsBuiltWithIsInterpretingOnly is not directly required,
// but this functionality relies on private reflection and that would not work with AOT
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[Fact]
Copy link
Member Author

Choose a reason for hiding this comment

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

Original motivation sounds .NET Native related.

@@ -70,7 +70,8 @@ public void CreateByRefAliasingInterpreted()
CreateByRefAliasing(useInterpreter: true);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/19286", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
Copy link
Member Author

Choose a reason for hiding this comment

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

Switched this one to ActiveIssue - the preceding test has the motivation for this.

@MichalStrehovsky
Copy link
Member Author

@cston do you have any objection to the change in DelegateHelpers.cs?

The behavior change is basically:

  1. In deployment models with expression compiler disabled, but ref emit available, we would newly not throw PNSE, but make things work.
  2. In deployment models with expression compiler disabled, but ref emit unavailable, no change.
  3. In deployment models with ref emit unavilable, PNSE, but from a different codepath (Ref.Emit would throw originally, now we short circuit earlier).
  4. In deployment models with expression compiler enabled and ref.emit available, no change.

Basically, it either makes things work, which sounds like a good thing, or just throws PNSE from a different place.

@MichalStrehovsky MichalStrehovsky merged commit 98e3fbb into dotnet:main Dec 7, 2021
@MichalStrehovsky MichalStrehovsky deleted the exprfollow branch December 7, 2021 00:20
@ghost ghost locked as resolved and limited conversation to collaborators Jan 6, 2022
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.

3 participants