Skip to content

Stop using GetRequired* reflection wrappers to enable trimming #27099

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 5 commits into from
Jan 8, 2022
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
7 changes: 7 additions & 0 deletions All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.AspNet.Sqlite.Functi
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.AspNet.InMemory.FunctionalTests", "test\EFCore.AspNet.InMemory.FunctionalTests\EFCore.AspNet.InMemory.FunctionalTests.csproj", "{F1B2E5A0-8C74-414A-B262-353FEE325E9F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.Trimming.Tests", "test\EFCore.Trimming.Tests\EFCore.Trimming.Tests.csproj", "{933C8662-817C-4F45-B98B-6557E28F7BB1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -318,6 +320,10 @@ Global
{F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Release|Any CPU.Build.0 = Release|Any CPU
{933C8662-817C-4F45-B98B-6557E28F7BB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{933C8662-817C-4F45-B98B-6557E28F7BB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{933C8662-817C-4F45-B98B-6557E28F7BB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{933C8662-817C-4F45-B98B-6557E28F7BB1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -371,6 +377,7 @@ Global
{F956A344-5C8D-4015-A3BF-7A8304C58BE4} = {258D5057-81B9-40EC-A872-D21E27452749}
{CC93C465-F5AC-4CB9-A064-3675955962F4} = {258D5057-81B9-40EC-A872-D21E27452749}
{F1B2E5A0-8C74-414A-B262-353FEE325E9F} = {258D5057-81B9-40EC-A872-D21E27452749}
{933C8662-817C-4F45-B98B-6557E28F7BB1} = {258D5057-81B9-40EC-A872-D21E27452749}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {285A5EB4-BCF4-40EB-B9E1-DF6DBCB5E705}
Expand Down
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup Condition="'$(IsUnitTestProject)' == ''">
<IsUnitTestProject Condition="$(MSBuildProjectName.EndsWith('.FunctionalTests'))">True</IsUnitTestProject>
<IsUnitTestProject Condition="$(MSBuildProjectName.EndsWith('.Specification.Tests'))">False</IsUnitTestProject>
<IsUnitTestProject Condition="$(MSBuildProjectName.EndsWith('.Trimming.Tests'))">False</IsUnitTestProject>
</PropertyGroup>

<Import Project="Sdk.props" Sdk="Microsoft.DotNet.Arcade.Sdk" />
Expand Down
6 changes: 6 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
variables:
- name: _BuildConfig
value: Release
- name: _BuildTargetFramework
value: net6.0
- name: _TeamName
value: AspNetCore
- name: DOTNET_SKIP_FIRST_TIME_EXPERIENCE
Expand Down Expand Up @@ -100,6 +102,10 @@ stages:
env:
Test__Cosmos__DefaultConnection: $(_CosmosConnectionUrl)
name: Build
- script: |
.dotnet\dotnet publish --configuration $(_BuildConfig) --runtime win-x64 --self-contained test\EFCore.Trimming.Tests
artifacts\bin\EFCore.Trimming.Tests\$(_BuildConfig)\$(_BuildTargetFramework)\win-x64\publish\EFCore.Trimming.Tests.exe
displayName: Test trimming
- task: PublishBuildArtifacts@1
displayName: Upload TestResults
condition: always()
Expand Down
5 changes: 5 additions & 0 deletions eng/helix.proj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<XUnitProject Remove="$(SqlServerTests)"/>
</ItemGroup>

<!-- The trimming test project is a console program -->
<ItemGroup>
<XUnitProject Remove="$(RepoRoot)/test/EFCore.Trimming.Tests/*.csproj"/>
</ItemGroup>

<PropertyGroup>
<XUnitPublishTargetFramework>net6.0</XUnitPublishTargetFramework>
<XUnitRuntimeTargetFramework>netcoreapp2.0</XUnitRuntimeTargetFramework>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Microsoft.EntityFrameworkCore;
public static class CosmosQueryableExtensions
{
internal static readonly MethodInfo WithPartitionKeyMethodInfo
= typeof(CosmosQueryableExtensions).GetRequiredDeclaredMethod(nameof(WithPartitionKey));
= typeof(CosmosQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(WithPartitionKey))!;

/// <summary>
/// Specify the partition key for partition used for the query. Required when using
Expand Down
42 changes: 21 additions & 21 deletions src/EFCore.Cosmos/Query/Internal/CosmosStringMethodTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,52 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal;
public class CosmosStringMethodTranslator : IMethodCallTranslator
{
private static readonly MethodInfo IndexOfMethodInfo
= typeof(string).GetRequiredRuntimeMethod(nameof(string.IndexOf), typeof(string));
= typeof(string).GetRuntimeMethod(nameof(string.IndexOf), new[] { typeof(string) })!;

private static readonly MethodInfo IndexOfMethodInfoWithStartingPosition
= typeof(string).GetRequiredRuntimeMethod(nameof(string.IndexOf), typeof(string), typeof(int));
= typeof(string).GetRuntimeMethod(nameof(string.IndexOf), new[] { typeof(string), typeof(int) })!;

private static readonly MethodInfo ReplaceMethodInfo
= typeof(string).GetRequiredRuntimeMethod(nameof(string.Replace), typeof(string), typeof(string));
= typeof(string).GetRuntimeMethod(nameof(string.Replace), new[] { typeof(string), typeof(string) })!;

private static readonly MethodInfo ContainsMethodInfo
= typeof(string).GetRequiredRuntimeMethod(nameof(string.Contains), typeof(string));
= typeof(string).GetRuntimeMethod(nameof(string.Contains), new[] { typeof(string) })!;

private static readonly MethodInfo StartsWithMethodInfo
= typeof(string).GetRequiredRuntimeMethod(nameof(string.StartsWith), typeof(string));
= typeof(string).GetRuntimeMethod(nameof(string.StartsWith), new[] { typeof(string) })!;

private static readonly MethodInfo EndsWithMethodInfo
= typeof(string).GetRequiredRuntimeMethod(nameof(string.EndsWith), typeof(string));
= typeof(string).GetRuntimeMethod(nameof(string.EndsWith), new[] { typeof(string) })!;

private static readonly MethodInfo ToLowerMethodInfo
= typeof(string).GetRequiredRuntimeMethod(nameof(string.ToLower), Array.Empty<Type>());
= typeof(string).GetRuntimeMethod(nameof(string.ToLower), Array.Empty<Type>())!;

private static readonly MethodInfo ToUpperMethodInfo
= typeof(string).GetRequiredRuntimeMethod(nameof(string.ToUpper), Array.Empty<Type>());
= typeof(string).GetRuntimeMethod(nameof(string.ToUpper), Array.Empty<Type>())!;

private static readonly MethodInfo TrimStartMethodInfoWithoutArgs
= typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimStart), Array.Empty<Type>());
= typeof(string).GetRuntimeMethod(nameof(string.TrimStart), Array.Empty<Type>())!;

private static readonly MethodInfo TrimEndMethodInfoWithoutArgs
= typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimEnd), Array.Empty<Type>());
= typeof(string).GetRuntimeMethod(nameof(string.TrimEnd), Array.Empty<Type>())!;

private static readonly MethodInfo TrimMethodInfoWithoutArgs
= typeof(string).GetRequiredRuntimeMethod(nameof(string.Trim), Array.Empty<Type>());
= typeof(string).GetRuntimeMethod(nameof(string.Trim), Array.Empty<Type>())!;

private static readonly MethodInfo TrimStartMethodInfoWithCharArrayArg
= typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimStart), typeof(char[]));
= typeof(string).GetRuntimeMethod(nameof(string.TrimStart), new[] { typeof(char[]) })!;

private static readonly MethodInfo TrimEndMethodInfoWithCharArrayArg
= typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimEnd), typeof(char[]));
= typeof(string).GetRuntimeMethod(nameof(string.TrimEnd), new[] { typeof(char[]) })!;

private static readonly MethodInfo TrimMethodInfoWithCharArrayArg
= typeof(string).GetRequiredRuntimeMethod(nameof(string.Trim), typeof(char[]));
= typeof(string).GetRuntimeMethod(nameof(string.Trim), new[] { typeof(char[]) })!;

private static readonly MethodInfo SubstringMethodInfoWithOneArg
= typeof(string).GetRequiredRuntimeMethod(nameof(string.Substring), typeof(int));
= typeof(string).GetRuntimeMethod(nameof(string.Substring), new[] { typeof(int) })!;

private static readonly MethodInfo SubstringMethodInfoWithTwoArgs
= typeof(string).GetRequiredRuntimeMethod(nameof(string.Substring), typeof(int), typeof(int));
= typeof(string).GetRuntimeMethod(nameof(string.Substring), new[] { typeof(int), typeof(int) })!;

private static readonly MethodInfo FirstOrDefaultMethodInfoWithoutArgs
= typeof(Enumerable).GetRuntimeMethods().Single(
Expand All @@ -70,19 +70,19 @@ private static readonly MethodInfo LastOrDefaultMethodInfoWithoutArgs
&& m.GetParameters().Length == 1).MakeGenericMethod(typeof(char));

private static readonly MethodInfo StringConcatWithTwoArguments =
typeof(string).GetRequiredRuntimeMethod(nameof(string.Concat), typeof(string), typeof(string));
typeof(string).GetRuntimeMethod(nameof(string.Concat), new[] { typeof(string), typeof(string) })!;

private static readonly MethodInfo StringConcatWithThreeArguments =
typeof(string).GetRequiredRuntimeMethod(nameof(string.Concat), typeof(string), typeof(string), typeof(string));
typeof(string).GetRuntimeMethod(nameof(string.Concat), new[] { typeof(string), typeof(string), typeof(string) })!;

private static readonly MethodInfo StringConcatWithFourArguments =
typeof(string).GetRequiredRuntimeMethod(nameof(string.Concat), typeof(string), typeof(string), typeof(string), typeof(string));
typeof(string).GetRuntimeMethod(nameof(string.Concat), new[] { typeof(string), typeof(string), typeof(string), typeof(string) })!;

private static readonly MethodInfo StringComparisonWithComparisonTypeArgumentInstance
= typeof(string).GetRequiredRuntimeMethod(nameof(string.Equals), typeof(string), typeof(StringComparison));
= typeof(string).GetRuntimeMethod(nameof(string.Equals), new[] { typeof(string), typeof(StringComparison) })!;

private static readonly MethodInfo StringComparisonWithComparisonTypeArgumentStatic
= typeof(string).GetRequiredRuntimeMethod(nameof(string.Equals), typeof(string), typeof(string), typeof(StringComparison));
= typeof(string).GetRuntimeMethod(nameof(string.Equals), new[] { typeof(string), typeof(string), typeof(StringComparison) })!;

private readonly ISqlExpressionFactory _sqlExpressionFactory;

Expand Down
Loading