Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit05e11e2

Browse files
committed
Transform Span-based overloads to Enumerable in funcletizer
Fixes#35100(cherry picked from commit6c0106b)
1 parentfb2f189 commit05e11e2

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

‎src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public class ExpressionTreeFuncletizer : ExpressionVisitor
109109
privatestaticreadonlyboolUseOldBehavior35111=
110110
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue35111",outvarenabled35111)&&enabled35111;
111111

112+
privatestaticreadonlyboolUseOldBehavior35339=
113+
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue35339",outvarenabled35339)&&enabled35339;
114+
112115
privatestaticreadonlyMethodInfoReadOnlyCollectionIndexerGetter=typeof(ReadOnlyCollection<Expression>).GetProperties()
113116
.Single(p=>p.GetIndexParameters()is{Length:1}indexParameters&&indexParameters[0].ParameterType==typeof(int)).GetMethod!;
114117

@@ -971,6 +974,51 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCall)
971974
}
972975
}
973976

977+
// .NET 10 made changes to overload resolution to prefer Span-based overloads when those exist ("first-class spans").
978+
// Unfortunately, the LINQ interpreter does not support ref structs, so we rewrite e.g. MemoryExtensions.Contains to
979+
// Enumerable.Contains here. See https://github.com/dotnet/runtime/issues/109757.
980+
if(method.DeclaringType==typeof(MemoryExtensions)&&!UseOldBehavior35339)
981+
{
982+
switch(method.Name)
983+
{
984+
casenameof(MemoryExtensions.Contains)
985+
whenmethodCall.Argumentsis[vararg0,vararg1]&&TryUnwrapSpanImplicitCast(arg0,outvarunwrappedArg0):
986+
{
987+
returnVisit(
988+
Call(
989+
EnumerableMethods.Contains.MakeGenericMethod(methodCall.Method.GetGenericArguments()[0]),
990+
unwrappedArg0,arg1));
991+
}
992+
993+
casenameof(MemoryExtensions.SequenceEqual)
994+
whenmethodCall.Argumentsis[vararg0,vararg1]
995+
&&TryUnwrapSpanImplicitCast(arg0,outvarunwrappedArg0)
996+
&&TryUnwrapSpanImplicitCast(arg1,outvarunwrappedArg1):
997+
returnVisit(
998+
Call(
999+
EnumerableMethods.SequenceEqual.MakeGenericMethod(methodCall.Method.GetGenericArguments()[0]),
1000+
unwrappedArg0,unwrappedArg1));
1001+
}
1002+
1003+
staticboolTryUnwrapSpanImplicitCast(Expressionexpression,[NotNullWhen(true)]outExpression?result)
1004+
{
1005+
if(expressionisMethodCallExpression
1006+
{
1007+
Method:{Name:"op_Implicit",DeclaringType:{IsGenericType:true}implicitCastDeclaringType},
1008+
Arguments:[varunwrapped]
1009+
}
1010+
&&implicitCastDeclaringType.GetGenericTypeDefinition()isvargenericTypeDefinition
1011+
&&(genericTypeDefinition==typeof(Span<>)||genericTypeDefinition==typeof(ReadOnlySpan<>)))
1012+
{
1013+
result=unwrapped;
1014+
returntrue;
1015+
}
1016+
1017+
result=null;
1018+
returnfalse;
1019+
}
1020+
}
1021+
9741022
// Regular/arbitrary method handling from here on
9751023

9761024
// First, visit the object and all arguments, saving states as well

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp