-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 #25009
- Loading branch information
Showing
175 changed files
with
4,329 additions
and
1,338 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 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; | ||
|
||
/// <summary> | ||
/// Contains IDs of diagnostics created by EF analyzers and other mechanisms. | ||
/// </summary> | ||
public static class EFDiagnostics | ||
{ | ||
public const string InternalUsage = "EF1001"; | ||
public const string SuppressUninitializedDbSetRule = "EFSPR1001"; | ||
public const string PrecompiledQueryExperimental = "EF2001"; | ||
} |
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,41 @@ | ||
// 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.Cosmos.Query.Internal; | ||
using Microsoft.EntityFrameworkCore.Query.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Cosmos.Query; | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public class CosmosLiftableConstantFactory : LiftableConstantFactory, ICosmosLiftableConstantFactory | ||
{ | ||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public CosmosLiftableConstantFactory( | ||
#pragma warning disable EF1001 // Internal EF Core API usage. | ||
LiftableConstantExpressionDependencies dependencies) | ||
#pragma warning restore EF1001 // Internal EF Core API usage. | ||
// CosmosLiftableConstantExpressionDependencies cosmosDependencies) | ||
: base(dependencies) | ||
{ | ||
// CosmosDependencies = cosmosDependencies; | ||
} | ||
|
||
///// <summary> | ||
///// TODO | ||
///// </summary> | ||
//public virtual CosmosLiftableConstantExpressionDependencies CosmosDependencies { get; } | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public virtual LiftableConstantExpression CreateLiftableConstant( | ||
ConstantExpression originalExpression, | ||
Expression<Func<CosmosMaterializerLiftableConstantContext, object>> resolverExpression, | ||
string variableName, | ||
Type type) | ||
=> new(originalExpression, resolverExpression, variableName, type); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/EFCore.Cosmos/Query/CosmosLiftableConstantProcessor.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,42 @@ | ||
// 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.Cosmos.Query.Internal; | ||
using Microsoft.EntityFrameworkCore.Query.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Cosmos.Query; | ||
|
||
#pragma warning disable EF1001 // LiftableConstantProcessor is internal | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public class CosmosLiftableConstantProcessor : LiftableConstantProcessor | ||
{ | ||
private readonly CosmosMaterializerLiftableConstantContext _cosmosMaterializerLiftableConstantContext; | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public CosmosLiftableConstantProcessor( | ||
ShapedQueryCompilingExpressionVisitorDependencies dependencies, | ||
IQuerySqlGeneratorFactory querySqlGeneratorFactory, | ||
ISqlExpressionFactory sqlExpressionFactory) | ||
//CosmosShapedQueryCompilingExpressionVisitorDependencies cosmosDependencies) | ||
: base(dependencies) | ||
=> _cosmosMaterializerLiftableConstantContext = new(dependencies, querySqlGeneratorFactory, sqlExpressionFactory); | ||
|
||
/// <inheritdoc/> | ||
protected override ConstantExpression InlineConstant(LiftableConstantExpression liftableConstant) | ||
{ | ||
if (liftableConstant.ResolverExpression is Expression<Func<CosmosMaterializerLiftableConstantContext, object>> | ||
resolverExpression) | ||
{ | ||
var resolver = resolverExpression.Compile(preferInterpretation: true); | ||
var value = resolver(_cosmosMaterializerLiftableConstantContext); | ||
return Expression.Constant(value, liftableConstant.Type); | ||
} | ||
|
||
return base.InlineConstant(liftableConstant); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/EFCore.Cosmos/Query/CosmosMaterializerLiftableConstantContext.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,16 @@ | ||
// 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.Cosmos.Query.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Cosmos.Query; | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public sealed record CosmosMaterializerLiftableConstantContext( | ||
ShapedQueryCompilingExpressionVisitorDependencies Dependencies, | ||
IQuerySqlGeneratorFactory QuerySqlGeneratorFactory, | ||
ISqlExpressionFactory SqlExpressionFactory) | ||
//CosmosShapedQueryCompilingExpressionVisitorDependencies CosmosDependencies) | ||
: MaterializerLiftableConstantContext(Dependencies); |
81 changes: 81 additions & 0 deletions
81
src/EFCore.Cosmos/Query/CosmosShapedQueryCompilingExpressionVisitorDependencies.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,81 @@ | ||
// 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.Cosmos.Query.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Cosmos.Query; | ||
|
||
/// <summary> | ||
/// <para> | ||
/// Service dependencies parameter class for <see cref="CosmosShapedQueryCompilingExpressionVisitorFactory" /> | ||
/// </para> | ||
/// <para> | ||
/// This type is typically used by database providers (and other extensions). It is generally | ||
/// not used in application code. | ||
/// </para> | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// Do not construct instances of this class directly from either provider or application code as the | ||
/// constructor signature may change as new dependencies are added. Instead, use this type in | ||
/// your constructor so that an instance will be created and injected automatically by the | ||
/// dependency injection container. To create an instance with some dependent services replaced, | ||
/// first resolve the object from the dependency injection container, then replace selected | ||
/// services using the C# 'with' operator. Do not call the constructor at any point in this process. | ||
/// </para> | ||
/// <para> | ||
/// The service lifetime is <see cref="ServiceLifetime.Scoped" />. This means that each | ||
/// <see cref="DbContext" /> instance will use its own instance of this service. | ||
/// The implementation may depend on other services registered with any lifetime. | ||
/// The implementation does not need to be thread-safe. | ||
/// </para> | ||
/// </remarks> | ||
public sealed record CosmosShapedQueryCompilingExpressionVisitorDependencies | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
/// <remarks> | ||
/// Do not call this constructor directly from either provider or application code as it may change | ||
/// as new dependencies are added. Instead, use this type in your constructor so that an instance | ||
/// will be created and injected automatically by the dependency injection container. To create | ||
/// an instance with some dependent services replaced, first resolve the object from the dependency | ||
/// injection container, then replace selected services using the C# 'with' operator. Do not call | ||
/// the constructor at any point in this process. | ||
/// </remarks> | ||
[EntityFrameworkInternal] | ||
public CosmosShapedQueryCompilingExpressionVisitorDependencies( | ||
IQuerySqlGeneratorFactory querySqlGeneratorFactory, | ||
ISqlExpressionFactory sqlExpressionFactory, | ||
//IRelationalParameterBasedSqlProcessorFactory relationalParameterBasedSqlProcessorFactory, | ||
ICosmosLiftableConstantFactory cosmosLiftableConstantFactory) | ||
{ | ||
QuerySqlGeneratorFactory = querySqlGeneratorFactory; | ||
SqlExpressionFactory = sqlExpressionFactory; | ||
//RelationalParameterBasedSqlProcessorFactory = relationalParameterBasedSqlProcessorFactory; | ||
CosmosLiftableConstantFactory = cosmosLiftableConstantFactory; | ||
} | ||
|
||
/// <summary> | ||
/// The SQL generator factory. | ||
/// </summary> | ||
public IQuerySqlGeneratorFactory QuerySqlGeneratorFactory { get; init; } | ||
|
||
/// <summary> | ||
/// The SQL expression factory. | ||
/// </summary> | ||
public ISqlExpressionFactory SqlExpressionFactory { get; init; } | ||
|
||
///// <summary> | ||
///// The SQL processor based on parameter values. | ||
///// </summary> | ||
//public IRelationalParameterBasedSqlProcessorFactory RelationalParameterBasedSqlProcessorFactory { get; init; } | ||
|
||
/// <summary> | ||
/// The liftable constant factory. | ||
/// </summary> | ||
public ICosmosLiftableConstantFactory CosmosLiftableConstantFactory { get; init; } | ||
} |
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,19 @@ | ||
// 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.Cosmos.Query; | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public interface ICosmosLiftableConstantFactory : ILiftableConstantFactory | ||
{ | ||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
LiftableConstantExpression CreateLiftableConstant( | ||
ConstantExpression originalExpression, | ||
Expression<Func<CosmosMaterializerLiftableConstantContext, object>> resolverExpression, | ||
string variableName, | ||
Type type); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/EFCore.Cosmos/Query/Internal/CosmosLiftableConstantExpressionDependencies.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. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal; | ||
|
||
/// <summary> | ||
/// <para> | ||
/// Service dependencies parameter class for <see cref="CosmosLiftableConstantFactory" /> | ||
/// </para> | ||
/// <para> | ||
/// This type is typically used by database providers (and other extensions). It is generally | ||
/// not used in application code. | ||
/// </para> | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// Do not construct instances of this class directly from either provider or application code as the | ||
/// constructor signature may change as new dependencies are added. Instead, use this type in | ||
/// your constructor so that an instance will be created and injected automatically by the | ||
/// dependency injection container. To create an instance with some dependent services replaced, | ||
/// first resolve the object from the dependency injection container, then replace selected | ||
/// services using the C# 'with' operator. Do not call the constructor at any point in this process. | ||
/// </para> | ||
/// <para> | ||
/// The service lifetime is <see cref="ServiceLifetime.Singleton" />. This means a single instance | ||
/// is used by many <see cref="DbContext" /> instances. The implementation must be thread-safe. | ||
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped" />. | ||
/// </para> | ||
/// </remarks> | ||
public sealed record CosmosLiftableConstantExpressionDependencies | ||
{ | ||
} |
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
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
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
19 changes: 19 additions & 0 deletions
19
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,19 @@ | ||
// 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; | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public interface IRelationalLiftableConstantFactory : ILiftableConstantFactory | ||
{ | ||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
LiftableConstantExpression CreateLiftableConstant( | ||
ConstantExpression originalExpression, | ||
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
Oops, something went wrong.