forked from dotnet/efcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce liftable constants to shaper to prepare for precompilation
Part of dotnet#25009
- Loading branch information
Showing
31 changed files
with
1,318 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/EFCore.Relational/Query/IRelationalLiftableConstantFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query; | ||
|
||
public interface IRelationalLiftableConstantFactory : ILiftableConstantFactory | ||
{ | ||
LiftableConstantExpression CreateLiftableConstant( | ||
Expression<Func<RelationalMaterializerLiftableConstantContext, object>> resolverExpression, | ||
string variableName, | ||
Type type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/EFCore.Relational/Query/RelationalLiftableConstantFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query; | ||
|
||
public class RelationalLiftableConstantFactory : LiftableConstantFactory, IRelationalLiftableConstantFactory | ||
{ | ||
public virtual LiftableConstantExpression CreateLiftableConstant( | ||
Expression<Func<RelationalMaterializerLiftableConstantContext, object>> resolverExpression, | ||
string variableName, | ||
Type type) | ||
=> new(resolverExpression, variableName, type); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/EFCore.Relational/Query/RelationalLiftableConstantProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.EntityFrameworkCore.Query.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query; | ||
|
||
#pragma warning disable EF1001 // LiftableConstantProcessor is internal | ||
|
||
public class RelationalLiftableConstantProcessor : LiftableConstantProcessor | ||
{ | ||
private RelationalMaterializerLiftableConstantContext _relationalMaterializerLiftableConstantContext; | ||
|
||
public RelationalLiftableConstantProcessor( | ||
ShapedQueryCompilingExpressionVisitorDependencies dependencies, | ||
RelationalShapedQueryCompilingExpressionVisitorDependencies relationalDependencies) | ||
: base(dependencies) | ||
=> _relationalMaterializerLiftableConstantContext = new(dependencies, relationalDependencies); | ||
|
||
protected override ConstantExpression InlineConstant(LiftableConstantExpression liftableConstant) | ||
{ | ||
if (liftableConstant.ResolverExpression is Expression<Func<RelationalMaterializerLiftableConstantContext, object>> | ||
resolverExpression) | ||
{ | ||
var resolver = resolverExpression.Compile(preferInterpretation: true); | ||
var value = resolver(_relationalMaterializerLiftableConstantContext); | ||
return Expression.Constant(value, liftableConstant.Type); | ||
} | ||
|
||
return base.InlineConstant(liftableConstant); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/EFCore.Relational/Query/RelationalMaterializerLiftableConstantContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query; | ||
|
||
public record RelationalMaterializerLiftableConstantContext( | ||
ShapedQueryCompilingExpressionVisitorDependencies Dependencies, | ||
RelationalShapedQueryCompilingExpressionVisitorDependencies RelationalDependencies) | ||
: MaterializerLiftableConstantContext(Dependencies); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.