Skip to content

Commit

Permalink
Make LambdaCompiler prefer interpretation to compilation on iOS (#54970)
Browse files Browse the repository at this point in the history
This is an attempt to address #47112 based on Egor's suggestion.

The changes:

- set IsInterpreting MSBuild property to 'true' in case of iOS;
- made System.Linq.Expressions.ExpressionCreator class internal static in order not to introduce new public type; otherwise it throws Type 'System.Linq.Expressions.ExpressionCreator<TDelegate>' does not exist in the reference but it does exist in the implementation.
-updated the iOS simulator functional test for AOT to verify the fix
- added PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly which checks whether the System.Linq.Expressions is built with IsInterpreting property set to true. To do so, it uses reflection to verify the Expression.Accept method doesn't exist.
- disabled some failing library tests using ActiveIssue + PlatformDetection.
- updated the invariant functional test for the iOS simulator (b/c of Allow restricting cultures creation with any arbitrary names in Globalization Invariant Mode #54247)

Co-authored-by: Stephen Toub <stoub@microsoft.com>
  • Loading branch information
MaximLipnin and stephentoub committed Jul 9, 2021
1 parent cb1beaa commit 3319fa8
Show file tree
Hide file tree
Showing 31 changed files with 142 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Diagnostics;
using System.IO;
using System.Linq.Expressions;
using System.Security;
using System.Security.Authentication;
using System.Reflection;
Expand Down Expand Up @@ -66,6 +67,22 @@ public static partial class PlatformDetection
public static bool IsUsingLimitedCultures => !IsNotMobile;
public static bool IsNotUsingLimitedCultures => IsNotMobile;

public static bool IsLinqExpressionsBuiltWithIsInterpretingOnly => s_LinqExpressionsBuiltWithIsInterpretingOnly.Value;
public static bool IsNotLinqExpressionsBuiltWithIsInterpretingOnly => !IsLinqExpressionsBuiltWithIsInterpretingOnly;
private static readonly Lazy<bool> s_LinqExpressionsBuiltWithIsInterpretingOnly = new Lazy<bool>(GetLinqExpressionsBuiltWithIsInterpretingOnly);
private static bool GetLinqExpressionsBuiltWithIsInterpretingOnly()
{
Type type = typeof(LambdaExpression);
if (type != null)
{
// The "Accept" method is under FEATURE_COMPILE conditional so it should not exist
MethodInfo methodInfo = type.GetMethod("Accept", BindingFlags.NonPublic | BindingFlags.Static);
return methodInfo == null;
}

return false;
}

// Please make sure that you have the libgdiplus dependency installed.
// For details, see https://docs.microsoft.com/dotnet/core/install/dependencies?pivots=os-macos&tabs=netcore31#libgdiplus
public static bool IsDrawingSupported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static IEnumerable<object[]> LateCall_OptionalValues_Data()
static object[] CreateData(string memberName, object[] arguments, Type[] typeArguments, string expectedValue) => new object[] { memberName, arguments, typeArguments, expectedValue };
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51834", typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltWithAggressiveTrimming), nameof(PlatformDetection.IsBrowser))]
[MemberData(nameof(LateCall_OptionalValues_Data))]
public void LateCall_OptionalValues(string memberName, object[] arguments, Type[] typeArguments, string expectedValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ namespace ManagedTests.DynamicCSharp.Conformance.dynamic.context.indexer.genclas
public class Test
{
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55118", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void TryCatchFinally()
{
dynamic dy = new MemberClass<int>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,12 @@ namespace ManagedTests.DynamicCSharp.Conformance.dynamic.context.operate.compoun
// <RelatedBugs></RelatedBugs>
// <Expects Status=success></Expects>
// <Code>
using System;

public class Test
{
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public static int MainMethod(string[] args)

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.declarations.formalParameter.Methods.extensionmethod006.extensionmethod006
{
using System;

static // <Title>Extension method that extends dynamic</Title>
// <Description>
// </Description>
Expand All @@ -115,6 +117,7 @@ public static string Foo(this object x, dynamic d)
public class Test
{
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down Expand Up @@ -189,6 +192,8 @@ public static int Method(this Test t, int value)

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.declarations.formalParameter.Methods.method001.method001
{
using System;

public class Test
{
private static bool s_ok = false;
Expand All @@ -203,6 +208,7 @@ public void Foo(dynamic d)
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down Expand Up @@ -260,6 +266,8 @@ public static int MainMethod(string[] args)

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.declarations.formalParameter.Methods.method003.method003
{
using System;

public class Test
{
private static bool s_ok = false;
Expand All @@ -273,6 +281,7 @@ public void Foo(dynamic d)
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand All @@ -294,6 +303,8 @@ public static int MainMethod(string[] args)

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.declarations.formalParameter.Methods.method004.method004
{
using System;

public class Test
{
private static bool s_ok = false;
Expand All @@ -306,6 +317,7 @@ public void Foo(ref dynamic d)
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand All @@ -330,6 +342,8 @@ public static int MainMethod(string[] args)

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.declarations.formalParameter.Methods.method005.method005
{
using System;

public class Test
{
private static bool s_ok = false;
Expand All @@ -345,6 +359,7 @@ public void Foo(params dynamic[] d)
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand All @@ -367,6 +382,8 @@ public static int MainMethod(string[] args)

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.declarations.formalParameter.Methods.method007.method007
{
using System;

public class Test
{
private static bool s_ok = false;
Expand All @@ -380,6 +397,7 @@ public void Foo(dynamic d, dynamic d2)
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand All @@ -403,6 +421,8 @@ public static int MainMethod(string[] args)

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.declarations.formalParameter.Methods.method008.method008
{
using System;

public class Test
{
private static bool s_ok = false;
Expand All @@ -416,6 +436,7 @@ public void Foo(dynamic d, int d2)
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand All @@ -438,6 +459,8 @@ public static int MainMethod(string[] args)

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.declarations.formalParameter.Methods.method009.method009
{
using System;

public class Test
{
private static bool s_ok = false;
Expand All @@ -451,6 +474,7 @@ public void Foo(dynamic d, dynamic d2, dynamic d3)
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand All @@ -473,6 +497,8 @@ public static int MainMethod(string[] args)

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.declarations.formalParameter.Methods.method010.method010
{
using System;

public class Test
{
private static bool s_ok = false;
Expand All @@ -488,6 +514,7 @@ public MyClass(params dynamic[] d)
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand All @@ -509,6 +536,8 @@ public static int MainMethod(string[] args)

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.declarations.formalParameter.Methods.method011.method011
{
using System;

public class Test
{
private static bool s_ok = false;
Expand All @@ -523,6 +552,7 @@ public static void Foo(dynamic d)
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand All @@ -543,6 +573,8 @@ public static int MainMethod(string[] args)

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.declarations.formalParameter.Methods.method012.method012
{
using System;

public class Test
{
private static bool s_ok = false;
Expand All @@ -555,6 +587,7 @@ public void Foo<T>(ref dynamic d)
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand All @@ -579,6 +612,8 @@ public static int MainMethod(string[] args)

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.declarations.formalParameter.Methods.method013.method013
{
using System;

public class Test
{
private static bool s_ok = false;
Expand All @@ -591,6 +626,7 @@ public void Foo<T>(T d)
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1189,9 +1189,12 @@ from d in numbers

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.declarations.localVariable.blockVariable.trycatch002.trycatch002
{
using System;

public class Test
{
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4356,6 +4356,8 @@ public static int MainMethod()

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.conversions.dlgate003.dlgate003
{
using System;

// <Title>Delegate conversions</Title>
// <Description>
// Tests to figure out if the right conversion from method groups to delegates are applied
Expand All @@ -4375,6 +4377,7 @@ public static object Foo()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,8 @@ public static int MainMethod(string[] args)

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.overloadResolution.Indexers.Oneclass2indexers.onedynamicparam004.onedynamicparam004
{
using System;

// <Title> Tests overload resolution for 1 class and 2 methods</Title>
// <Description>
// </Description>
Expand Down Expand Up @@ -720,6 +722,7 @@ public object this[object x]
public class Test
{
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ public static int MainMethod(string[] args)

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.overloadResolution.Methods.Oneclass2methods.onedynamicparam004.onedynamicparam004
{
using System;

// <Title> Tests overload resolution for 1 class and 2 methods</Title>
// <Description>
// </Description>
Expand Down Expand Up @@ -530,6 +532,7 @@ public void Method(object x)
public class Test
{
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55117", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ public static int MainMethod()

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.Variance.assign.assignment07.assignment07
{
using System;

// <Area>variance</Area>
// <Title> assignment Contravariant delegates</Title>
// <Description> contravariance on delegates assigned to arrays</Description>
Expand All @@ -499,6 +501,7 @@ public class C
private static dynamic s_array3;

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/55119", typeof(PlatformDetection), nameof(PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly))]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>67,168,219,414,162,184,458,464,78,169,114,693,108,1981,649,109,1066,3021,3026,3002,3014,3022,660,661,429;xUnit1013</NoWarn>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-MacCatalyst</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<AssembliesBeingTested Include="Microsoft.CSharp" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<FeatureInterpret>true</FeatureInterpret>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-MacCatalyst</TargetFrameworks>
<Nullable>enable</Nullable>
<IsInterpreting>false</IsInterpreting>
<IsInterpreting Condition="'$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsMacCatalyst)' == 'true'">true</IsInterpreting>
<DefineConstants> $(DefineConstants);FEATURE_DLG_INVOKE;FEATURE_FAST_CREATE</DefineConstants>
<DefineConstants Condition=" '$(IsInterpreting)' != 'true' ">$(DefineConstants);FEATURE_COMPILE</DefineConstants>
<DefineConstants Condition=" '$(FeatureInterpret)' == 'true' ">$(DefineConstants);FEATURE_INTERPRET</DefineConstants>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ internal static Expression<TDelegate> Create(Expression body, string? name, bool

#if !FEATURE_COMPILE
// Separate expression creation class to hide the CreateExpressionFunc function from users reflecting on Expression<T>
public class ExpressionCreator<TDelegate>
internal static class ExpressionCreator<TDelegate>
{
public static Expression<TDelegate> CreateExpressionFunc(Expression body, string? name, bool tailCall, ReadOnlyCollection<ParameterExpression> parameters)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace System.Linq.Expressions.Tests
{
[ActiveIssue("https://github.com/dotnet/runtime/issues/51952", TestPlatforms.tvOS)]
public static class ArrayArrayIndexTests
{
#region Boolean tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace System.Linq.Expressions.Tests
{
[ActiveIssue("https://github.com/dotnet/runtime/issues/51952", TestPlatforms.tvOS)]
public static class ArrayIndexTests
{
#region Boolean tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace System.Linq.Expressions.Tests
{
[ActiveIssue("https://github.com/dotnet/runtime/issues/51952", TestPlatforms.tvOS)]
public static class NullableArrayIndexTests
{
#region NullableBool tests
Expand Down
Loading

0 comments on commit 3319fa8

Please sign in to comment.