From 726c0da16fa6b9a2a7e841f330a4b11163c75371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 23 Nov 2021 13:26:10 +0900 Subject: [PATCH] Start building a universal System.Linq.Expressions library System.Linq.Expressions currently offers multiple build time definitions to build different flavors of the library: * `FEATURE_COMPILE` (defined everywhere except iOS/tvOS/Catalyst, and NativeAOT) - enables Reflection.Emit-based expression tree compiler. * `FEATURE_INTERPRET` (always defined and not actually possible to build without) - enables the expression interpreter * `FEATURE_DLG_INVOKE` (defined everywhere except NativeAOT, but we likely need to be able to run without it on iOS too because there's uninvestigated bugs around it ActiveIssue'd in #54970) - in the interpreter, use a delegate to invoke `CallInstructions` instead of `MethodInfo.Invoke`. The delegate might have to be Reflection.Emitted if it's not supportable with `Func`/`Action` (that's the uninvestigated iOS/tvOS/Catalyst bug). For #61231, we need to be able to build a single System.Linq.Expression library that can switch between these build-time configurations _at publish time_ since we don't want to build a separate S.L.Expressions library for NativeAOT. There are advantages in having this setup for non-NativeAOT scenarios too. This pull request accomplishes that by mechanically changing the `#define`s into feature switches. The feature switch is placed in the last proposed location for https://github.com/dotnet/runtime/issues/17973. I expect we'll want such API to be public at some point; now that Xamarin and NativeAOT use this formerly .NET Native-only thing the API request became relevant again. This pull request is focused on the mechanical replacement of `#defines` with feature switches and it's already a lot bigger than I'm comfortable with. There's some obvious "`!FEATURE_COMPILE` means this is .NET Native with everything what that meant" that I did not touch because this is meant to be a mechanical change. Some cleanup will be needed at some point. Right now this just mostly means we're running fewer tests than we could. Validation: * Verified that we're still running the same number of tests with CoreCLR as we previously were and they're all passing. * Verified we're getting mostly the same size of the S.L.Expressions library on iOS (433 kB grew to 437 kB, the diffs are expected). * Verified things work on the NativeAOT side as well. --- eng/illink.targets | 1 + .../TestUtilities/System/PlatformDetection.cs | 10 +-- ...stitutions.IsInterpreting.LibraryBuild.xml | 7 ++ .../src/ILLink/ILLink.Substitutions.xml | 13 +++ .../src/MatchingRefApiCompatBaseline.txt | 4 +- .../src/System.Linq.Expressions.csproj | 13 +-- .../Dynamic/UpdateDelegates.Generated.cs | 2 - .../Dynamic/UpdateDelegates.Generated.tt | 2 - .../System/Dynamic/Utils/DelegateHelpers.cs | 34 +++++--- .../System/Dynamic/Utils/TypeExtensions.cs | 2 - .../src/System/Dynamic/Utils/TypeUtils.cs | 4 - .../Common/CachedReflectionInfo.cs | 2 - .../Compiler/DelegateHelpers.Generated.cs | 17 ++-- .../Expressions/Compiler/DelegateHelpers.cs | 37 ++++----- .../Interpreter/CallInstruction.Generated.cs | 7 -- .../Interpreter/CallInstruction.cs | 16 ++-- .../Linq/Expressions/LambdaExpression.cs | 79 +++++++++++-------- .../Runtime/CompilerServices/CallSite.cs | 16 +--- .../CompilerServices/DebugInfoGenerator.cs | 2 - .../Coalesce/BinaryCoalesceTests.cs | 4 +- .../Logical/BinaryLogicalTests.cs | 50 ++++++------ .../tests/Cast/CastTests.cs | 10 ++- .../tests/CompilerTests.cs | 28 +++---- .../tests/Constant/ConstantTests.cs | 16 ++-- .../DelegateType/GetDelegateTypeTests.cs | 50 ++++++------ .../tests/Dynamic/InvokeMemberBindingTests.cs | 23 +++--- .../ExceptionHandlingExpressions.cs | 19 ++--- .../tests/HelperTypes.cs | 38 +++++---- .../IndexExpression/IndexExpressionTests.cs | 34 ++++---- .../tests/InterpreterTests.cs | 38 +++++---- .../tests/Invoke/InvocationTests.cs | 11 +-- .../tests/Lambda/LambdaTests.cs | 21 ++--- .../tests/Member/MemberAccessTests.cs | 4 +- .../tests/MemberInit/BindTests.cs | 6 +- .../tests/MemberInit/ListBindTests.cs | 5 +- .../tests/MemberInit/MemberBindTests.cs | 4 +- .../tests/New/NewTests.cs | 6 +- .../tests/New/NewWithByRefParameterTests.cs | 4 +- .../tests/StackSpillerTests.cs | 20 ++--- .../System.Linq.Expressions.Tests.csproj | 7 +- .../InlinePerCompilationTypeAttribute.cs | 9 +-- .../PerCompilationTypeAttribute.cs | 32 +++----- ...aryArithmeticNegateCheckedNullableTests.cs | 5 +- .../UnaryArithmeticNegateCheckedTests.cs | 5 +- 44 files changed, 342 insertions(+), 375 deletions(-) create mode 100644 src/libraries/System.Linq.Expressions/src/ILLink/ILLink.Substitutions.IsInterpreting.LibraryBuild.xml create mode 100644 src/libraries/System.Linq.Expressions/src/ILLink/ILLink.Substitutions.xml diff --git a/eng/illink.targets b/eng/illink.targets index 6c2d95c8477237..e058563d404c14 100644 --- a/eng/illink.targets +++ b/eng/illink.targets @@ -236,6 +236,7 @@ $(ILLinkArgs) -b true $(ILLinkArgs) -x "$(ILLinkDescriptorsLibraryBuildXml)" + $(ILLinkArgs) --substitutions "$(ILLinkSubstitutionsLibraryBuildXml)"