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
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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.

{
Type returnType = types[types.Length - 1];
Type[] parameters = types.RemoveLast();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public static void MethodDeclaringTypeHasNoTrueFalseOperator_ThrowsArgumentExcep
AssertExtensions.Throws<ArgumentException>(null, () => Expression.OrElse(Expression.Constant(5), Expression.Constant(5), method));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public static void AndAlso_NoMethod_NotStatic_ThrowsInvalidOperationException()
{
TypeBuilder type = GetTypeBuilder();
Expand All @@ -428,7 +428,7 @@ public static void AndAlso_NoMethod_NotStatic_ThrowsInvalidOperationException()
Assert.Throws<InvalidOperationException>(() => Expression.AndAlso(Expression.Constant(obj), Expression.Constant(obj)));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public static void OrElse_NoMethod_NotStatic_ThrowsInvalidOperationException()
{
TypeBuilder type = GetTypeBuilder();
Expand All @@ -441,7 +441,7 @@ public static void OrElse_NoMethod_NotStatic_ThrowsInvalidOperationException()
Assert.Throws<InvalidOperationException>(() => Expression.OrElse(Expression.Constant(obj), Expression.Constant(obj)));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public static void AndAlso_NoMethod_VoidReturnType_ThrowsArgumentException()
{
TypeBuilder type = GetTypeBuilder();
Expand All @@ -454,7 +454,7 @@ public static void AndAlso_NoMethod_VoidReturnType_ThrowsArgumentException()
AssertExtensions.Throws<ArgumentException>("method", () => Expression.AndAlso(Expression.Constant(obj), Expression.Constant(obj)));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public static void OrElse_NoMethod_VoidReturnType_ThrowsArgumentException()
{
TypeBuilder type = GetTypeBuilder();
Expand All @@ -467,7 +467,7 @@ public static void OrElse_NoMethod_VoidReturnType_ThrowsArgumentException()
AssertExtensions.Throws<ArgumentException>("method", () => Expression.OrElse(Expression.Constant(obj), Expression.Constant(obj)));
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[InlineData(0)]
[InlineData(1)]
[InlineData(3)]
Expand All @@ -483,7 +483,7 @@ public static void AndAlso_NoMethod_DoesntHaveTwoParameters_ThrowsInvalidOperati
Assert.Throws<InvalidOperationException>(() => Expression.AndAlso(Expression.Constant(obj), Expression.Constant(obj)));
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[InlineData(0)]
[InlineData(1)]
[InlineData(3)]
Expand All @@ -499,7 +499,7 @@ public static void OrElse_NoMethod_DoesntHaveTwoParameters_ThrowsInvalidOperatio
Assert.Throws<InvalidOperationException>(() => Expression.OrElse(Expression.Constant(obj), Expression.Constant(obj)));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public static void AndAlso_NoMethod_ExpressionDoesntMatchMethodParameters_ThrowsInvalidOperationException()
{
TypeBuilder type = GetTypeBuilder();
Expand All @@ -512,7 +512,7 @@ public static void AndAlso_NoMethod_ExpressionDoesntMatchMethodParameters_Throws
Assert.Throws<InvalidOperationException>(() => Expression.AndAlso(Expression.Constant(obj), Expression.Constant(obj)));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public static void OrElse_NoMethod_ExpressionDoesntMatchMethodParameters_ThrowsInvalidOperationException()
{
TypeBuilder type = GetTypeBuilder();
Expand All @@ -526,7 +526,7 @@ public static void OrElse_NoMethod_ExpressionDoesntMatchMethodParameters_ThrowsI
}


[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public static void AndAlso_NoMethod_ReturnTypeNotEqualToParameterTypes_ThrowsArgumentException()
{
TypeBuilder type = GetTypeBuilder();
Expand All @@ -539,7 +539,7 @@ public static void AndAlso_NoMethod_ReturnTypeNotEqualToParameterTypes_ThrowsArg
AssertExtensions.Throws<ArgumentException>(null, () => Expression.AndAlso(Expression.Constant(obj), Expression.Constant(obj)));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public static void OrElse_NoMethod_ReturnTypeNotEqualToParameterTypes_ThrowsArgumentException()
{
TypeBuilder type = GetTypeBuilder();
Expand Down Expand Up @@ -569,7 +569,7 @@ public static IEnumerable<object[]> Operator_IncorrectMethod_TestData()
yield return new object[] { GetTypeBuilder(), typeof(bool), new Type[0] };
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[MemberData(nameof(Operator_IncorrectMethod_TestData))]
public static void Method_TrueOperatorIncorrectMethod_ThrowsArgumentException(TypeBuilder builder, Type returnType, Type[] parameterTypes)
{
Expand All @@ -590,7 +590,7 @@ public static void Method_TrueOperatorIncorrectMethod_ThrowsArgumentException(Ty
AssertExtensions.Throws<ArgumentException>(null, () => Expression.OrElse(Expression.Constant(obj), Expression.Constant(obj), createdMethod));
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[MemberData(nameof(Operator_IncorrectMethod_TestData))]
public static void Method_FalseOperatorIncorrectMethod_ThrowsArgumentException(TypeBuilder builder, Type returnType, Type[]parameterTypes)
{
Expand All @@ -611,7 +611,7 @@ public static void Method_FalseOperatorIncorrectMethod_ThrowsArgumentException(T
AssertExtensions.Throws<ArgumentException>(null, () => Expression.OrElse(Expression.Constant(obj), Expression.Constant(obj), createdMethod));
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[MemberData(nameof(Operator_IncorrectMethod_TestData))]
public static void AndAlso_NoMethod_TrueOperatorIncorrectMethod_ThrowsArgumentException(TypeBuilder builder, Type returnType, Type[] parameterTypes)
{
Expand All @@ -630,7 +630,7 @@ public static void AndAlso_NoMethod_TrueOperatorIncorrectMethod_ThrowsArgumentEx
AssertExtensions.Throws<ArgumentException>(null, () => Expression.AndAlso(Expression.Constant(obj), Expression.Constant(obj)));
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[MemberData(nameof(Operator_IncorrectMethod_TestData))]
public static void OrElse_NoMethod_TrueOperatorIncorrectMethod_ThrowsArgumentException(TypeBuilder builder, Type returnType, Type[] parameterTypes)
{
Expand All @@ -649,7 +649,7 @@ public static void OrElse_NoMethod_TrueOperatorIncorrectMethod_ThrowsArgumentExc
AssertExtensions.Throws<ArgumentException>(null, () => Expression.OrElse(Expression.Constant(obj), Expression.Constant(obj)));
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[InlineData("op_True")]
[InlineData("op_False")]
public static void Method_NoTrueFalseOperator_ThrowsArgumentException(string name)
Expand All @@ -672,7 +672,7 @@ public static void Method_NoTrueFalseOperator_ThrowsArgumentException(string nam
AssertExtensions.Throws<ArgumentException>(null, () => Expression.OrElse(Expression.Constant(obj), Expression.Constant(obj), createdMethod));
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[InlineData("op_True")]
[InlineData("op_False")]
public static void AndAlso_NoMethod_NoTrueFalseOperator_ThrowsArgumentException(string name)
Expand All @@ -692,7 +692,7 @@ public static void AndAlso_NoMethod_NoTrueFalseOperator_ThrowsArgumentException(
AssertExtensions.Throws<ArgumentException>(null, () => Expression.AndAlso(Expression.Constant(obj), Expression.Constant(obj)));
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[InlineData("op_True")]
[InlineData("op_False")]
public static void OrElse_NoMethod_NoTrueFalseOperator_ThrowsArgumentException(string name)
Expand All @@ -712,7 +712,7 @@ public static void OrElse_NoMethod_NoTrueFalseOperator_ThrowsArgumentException(s
AssertExtensions.Throws<ArgumentException>(null, () => Expression.OrElse(Expression.Constant(obj), Expression.Constant(obj)));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public static void Method_ParamsDontMatchOperator_ThrowsInvalidOperationException()
{
TypeBuilder builder = GetTypeBuilder();
Expand All @@ -733,7 +733,7 @@ public static void Method_ParamsDontMatchOperator_ThrowsInvalidOperationExceptio
Assert.Throws<InvalidOperationException>(() => Expression.OrElse(Expression.Constant(5), Expression.Constant(5), createdMethod));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public static void AndAlso_NoMethod_ParamsDontMatchOperator_ThrowsInvalidOperationException()
{
TypeBuilder builder = GetTypeBuilder();
Expand All @@ -751,7 +751,7 @@ public static void AndAlso_NoMethod_ParamsDontMatchOperator_ThrowsInvalidOperati
Assert.Throws<InvalidOperationException>(() => Expression.OrElse(Expression.Constant(5), Expression.Constant(5)));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public static void OrElse_NoMethod_ParamsDontMatchOperator_ThrowsInvalidOperationException()
{
TypeBuilder builder = GetTypeBuilder();
Expand Down Expand Up @@ -817,14 +817,14 @@ public static void ToStringTest()
Assert.Equal("(a OrElse b)", e2.ToString());
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public static void AndAlsoGlobalMethod()
{
MethodInfo method = GlobalMethod(typeof(int), new[] { typeof(int), typeof(int) });
AssertExtensions.Throws<ArgumentException>(null, () => Expression.AndAlso(Expression.Constant(1), Expression.Constant(2), method));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public static void OrElseGlobalMethod()
{
MethodInfo method = GlobalMethod(typeof(int), new [] { typeof(int), typeof(int) });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2373,7 +2373,7 @@ public static IEnumerable<Type> EnumerableTypes()
yield return typeof(Int64Enum);
yield return typeof(UInt64Enum);

if (PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly)
if (PlatformDetection.IsReflectionEmitSupported)
{
yield return NonCSharpTypes.CharEnumType;
yield return NonCSharpTypes.BoolEnumType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public static void CheckTypeConstantTest(bool useInterpreter)
VerifyTypeConstant(value, useInterpreter);
}

if (PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly)
if (PlatformDetection.IsReflectionEmitSupported)
{
VerifyTypeConstant(GetTypeBuilder(), useInterpreter);
}
Expand All @@ -328,14 +328,24 @@ public static void CheckMethodInfoConstantTest(bool useInterpreter)
typeof(SomePublicMethodsForLdToken).GetMethod(nameof(SomePublicMethodsForLdToken.Qux), BindingFlags.Public | BindingFlags.Static),
typeof(SomePublicMethodsForLdToken).GetMethod(nameof(SomePublicMethodsForLdToken.Qux), BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(typeof(int)),
typeof(List<>).GetMethod(nameof(List<int>.Add)),
typeof(List<int>).GetMethod(nameof(List<int>.Add)),
GlobalMethod(Type.EmptyTypes),
GlobalMethod(typeof(PrivateGenericClass<int>)),
GlobalMethod(typeof(PrivateGenericClass<>))
typeof(List<int>).GetMethod(nameof(List<int>.Add))
})
{
VerifyMethodInfoConstant(value, useInterpreter);
}

if (PlatformDetection.IsReflectionEmitSupported)
{
foreach (MethodInfo value in new MethodInfo[]
{
GlobalMethod(Type.EmptyTypes),
GlobalMethod(typeof(PrivateGenericClass<int>)),
GlobalMethod(typeof(PrivateGenericClass<>))
})
{
VerifyMethodInfoConstant(value, useInterpreter);
}
}
}

[Theory, ClassData(typeof(CompilationTypes))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using Xunit;

Expand Down Expand Up @@ -57,7 +58,7 @@ public void GetNullaryAction()
[MemberData(nameof(ManagedPointerTypeArgs))]
public void CantBeFunc(Type[] typeArgs)
{
if (PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly)
if (!RuntimeFeature.IsDynamicCodeSupported)
{
Assert.Throws<PlatformNotSupportedException>(() => Expression.GetDelegateType(typeArgs));
}
Expand All @@ -83,7 +84,7 @@ public void CantBeFunc(Type[] typeArgs)
public void CantBeAction(Type[] typeArgs)
{
Type[] delegateArgs = typeArgs.Append(typeof(void)).ToArray();
if (PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly)
if (!RuntimeFeature.IsDynamicCodeSupported)
{
Assert.Throws<PlatformNotSupportedException>(() => Expression.GetDelegateType(delegateArgs));
}
Expand Down
Loading