Skip to content

Commit 7a2e8a2

Browse files
authored
Merge pull request #474 from dadhi/wip-issue472
@wip issue472
2 parents d059e9a + ba43325 commit 7a2e8a2

28 files changed

+1639
-721
lines changed

.github/workflows/publish.yml

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,46 @@ name: Publish
22

33
on:
44
push:
5-
tags:
6-
- 'v*.*.*'
5+
tags:
6+
- "v*.*.*"
77

88
jobs:
99
build:
10-
1110
runs-on: ubuntu-latest
1211
env:
1312
DOTNET_NOLOGO: true
1413
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
1514
DOTNET_CLI_TELEMETRY_OPTOUT: true
1615

1716
steps:
18-
- uses: actions/checkout@v4
19-
- uses: actions/setup-dotnet@v4
20-
with:
21-
global-json-file: global.json
22-
23-
- name: Build
24-
run: dotnet build -c:Release
25-
26-
- name: Make Internal
27-
shell: pwsh
28-
run: ./BuildScripts/MakeInternal.ps1
29-
30-
- name: Pack with dotnet
31-
run: |
32-
arrTag=(${GITHUB_REF//\// })
33-
VERSION="${arrTag[2]}"
34-
VERSION="${VERSION//v}"
35-
echo "$VERSION"
36-
37-
dotnet pack --no-build --output artifacts -p:Version=$VERSION -p:ContinuousIntegrationBuild=True ./nuspecs/FastExpressionCompiler.src.nuspec
38-
dotnet pack --no-build --output artifacts -p:Version=$VERSION -p:ContinuousIntegrationBuild=True ./nuspecs/FastExpressionCompiler.LightExpression.src.nuspec
39-
dotnet pack --no-build --output artifacts -p:Version=$VERSION -p:ContinuousIntegrationBuild=True ./nuspecs/FastExpressionCompiler.Internal.src.nuspec
40-
dotnet pack --no-build --output artifacts -p:Version=$VERSION -p:ContinuousIntegrationBuild=True ./nuspecs/FastExpressionCompiler.LightExpression.Internal.src.nuspec
41-
42-
- uses: actions/upload-artifact@v4
43-
with:
44-
name: Packages
45-
path: ./artifacts
46-
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-dotnet@v4
19+
with:
20+
global-json-file: global.json
21+
22+
- name: Build
23+
run: dotnet build -c:Release
24+
25+
- name: Make Internal
26+
shell: pwsh
27+
run: ./BuildScripts/MakeInternal.ps1
28+
29+
- name: Pack with dotnet
30+
run: |
31+
arrTag=(${GITHUB_REF//\// })
32+
VERSION="${arrTag[2]}"
33+
VERSION="${VERSION//v}"
34+
echo "$VERSION"
35+
36+
dotnet pack --no-build --output artifacts -p:Version=$VERSION -p:ContinuousIntegrationBuild=True ./nuspecs/FastExpressionCompiler.src.nuspec
37+
dotnet pack --no-build --output artifacts -p:Version=$VERSION -p:ContinuousIntegrationBuild=True ./nuspecs/FastExpressionCompiler.LightExpression.src.nuspec
38+
dotnet pack --no-build --output artifacts -p:Version=$VERSION -p:ContinuousIntegrationBuild=True ./nuspecs/FastExpressionCompiler.Internal.src.nuspec
39+
dotnet pack --no-build --output artifacts -p:Version=$VERSION -p:ContinuousIntegrationBuild=True ./nuspecs/FastExpressionCompiler.LightExpression.Internal.src.nuspec
40+
41+
- uses: actions/upload-artifact@v4
42+
with:
43+
name: Packages
44+
path: ./artifacts
45+
4746
# - name: Push with dotnet
4847
# run: dotnet nuget push artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json

Directory.Build.props

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55

66
<NeutralLanguage>en-US</NeutralLanguage>
77
<LangVersion>latest</LangVersion>
8-
<LatestSupportedNet>net9.0</LatestSupportedNet>
98

109
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1110
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
1211

1312
<NoWarn>IDE0251;IDE0079;IDE0047;NETSDK1212</NoWarn>
13+
14+
<!-- When set, reducec number of the TargetPlatforms to speedup a local Dev -->
15+
<DevMode>false</DevMode>
16+
1417
</PropertyGroup>
1518

1619
<ItemGroup>

b.bat

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
@echo off
22

3+
echo:
4+
echo:## Starting BUILD...
5+
echo:
6+
dotnet build -p:DevMode=true -v:m -c:Release
7+
if %ERRORLEVEL% neq 0 goto :error
8+
39
echo:
4-
echo:## Starting: TESTS...
10+
echo:## Starting TESTS...
511
echo:
612

7-
dotnet run -c:Release -f:net9.0 --project test/FastExpressionCompiler.TestsRunner/FastExpressionCompiler.TestsRunner.csproj
13+
dotnet run --no-build -p:DevMode=true -f:net9.0 -c:Release --project test/FastExpressionCompiler.TestsRunner/FastExpressionCompiler.TestsRunner.csproj
814
if %ERRORLEVEL% neq 0 goto :error
915

10-
dotnet run -c:Release --project test/FastExpressionCompiler.TestsRunner.Net472
16+
dotnet run --no-build -p:DevMode=true -c:Release --project test/FastExpressionCompiler.TestsRunner.Net472
1117
if %ERRORLEVEL% neq 0 goto :error
1218

1319
echo:

bt.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
echo:
44
echo:## Running TESTS on the Latest Supported .NET...
55
echo:
6-
dotnet run -c:Release -f:net9.0 --project test/FastExpressionCompiler.TestsRunner/FastExpressionCompiler.TestsRunner.csproj
6+
dotnet run -p:DevMode=true -f:net9.0 -c:Release --project test/FastExpressionCompiler.TestsRunner/FastExpressionCompiler.TestsRunner.csproj
77
if %ERRORLEVEL% neq 0 goto :error
88

99
echo:

build.bat

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,11 @@ setlocal EnableDelayedExpansion
33

44
echo: # BUILDING AND RUNNING THE TESTS IN RELEASE MODE
55
echo:
6-
echo:
7-
8-
set "FrameworkParam=-f:net9.0"
9-
set "LatestSupportedNetProp=-p:LatestSupportedNet=net9.0"
10-
if [%1] NEQ [] (
11-
set "FrameworkParam=-f:%1"
12-
set "LatestSupportedNetProp=-p:LatestSupportedNet=%1"
13-
)
14-
echo:FrameworkParam == '%FrameworkParam%', LatestSupportedNetProp == '%LatestSupportedNetProp%'
15-
166
echo:
177
echo:## Starting: RESTORE and BUILD...
188
echo:
19-
20-
dotnet clean -v:m %LatestSupportedNetProp%
21-
dotnet build -v:m %LatestSupportedNetProp% -c:Release
9+
dotnet clean -v:m
10+
dotnet build -v:m -c:Release
2211
if %ERRORLEVEL% neq 0 goto :error
2312

2413
echo:
@@ -27,19 +16,22 @@ echo:## Finished: RESTORE and BUILD
2716
echo:
2817
echo:## Starting: TESTS...
2918
echo:
30-
echo: running on .NET 9.0 (Latest)
31-
echo:
32-
dotnet run --no-build net9.0 %FrameworkParam% -c:Release --project test/FastExpressionCompiler.TestsRunner
19+
echo:running on .NET 9.0 (Latest)
20+
dotnet run --no-build -f:net9.0 -c:Release --project test/FastExpressionCompiler.TestsRunner
21+
if %ERRORLEVEL% neq 0 goto :error
3322

34-
echo: running on .NET 8.0 (LTS)
3523
echo:
36-
dotnet run --no-build net8.0 %FrameworkParam% -c:Release --project test/FastExpressionCompiler.TestsRunner
24+
echo:running on .NET 8.0 (LTS)
25+
dotnet run --no-build -f:net8.0 -c:Release --project test/FastExpressionCompiler.TestsRunner
26+
if %ERRORLEVEL% neq 0 goto :error
3727

38-
echo: running on .NET 6.0 (LTS)
3928
echo:
40-
dotnet run --no-build net6.0 %FrameworkParam% -c:Release --project test/FastExpressionCompiler.TestsRunner
29+
echo:running on .NET 6.0 (Previous LTS)
30+
dotnet run --no-build -f:net6.0 -c:Release --project test/FastExpressionCompiler.TestsRunner
4131
if %ERRORLEVEL% neq 0 goto :error
4232

33+
echo:
34+
echo:running on .NET 4.7.2
4335
dotnet run --no-build -c:Release --project test/FastExpressionCompiler.TestsRunner.Net472
4436
if %ERRORLEVEL% neq 0 goto :error
4537
echo:

build_debug.bat

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
@echo off
22
setlocal EnableDelayedExpansion
33

4-
echo: # BUILDING AND RUNNNG THE TESTS IN DEBUG MODE
4+
echo: # BUILDING AND RUNNING THE TESTS IN DEBUG MODE
55
echo:
6-
echo:
7-
8-
set "FrameworkParam=-f:net9.0"
9-
set "LatestSupportedNetProp=-p:LatestSupportedNet=net9.0"
10-
if [%1] NEQ [] (
11-
set "FrameworkParam=-f:%1"
12-
set "LatestSupportedNetProp=-p:LatestSupportedNet=%1"
13-
)
14-
echo:FrameworkParam == '%FrameworkParam%', LatestSupportedNetProp == '%LatestSupportedNetProp%'
15-
166
echo:
177
echo:## Starting: RESTORE and BUILD...
188
echo:
199

20-
dotnet build %LatestSupportedNetProp% -c:Debug
10+
dotnet build -c:Debug
2111
if %ERRORLEVEL% neq 0 goto :error
2212

2313
echo:
@@ -26,10 +16,22 @@ echo:## Finished: RESTORE and BUILD
2616
echo:
2717
echo:## Starting: TESTS...
2818
echo:
19+
echo:running on .NET 9.0 (Latest)
20+
dotnet run --no-build -f:net9.0 -c:Debug --project test/FastExpressionCompiler.TestsRunner
21+
if %ERRORLEVEL% neq 0 goto :error
2922

30-
dotnet run --no-build %LatestSupportedNetProp% %FrameworkParam% -c:Debug --project test/FastExpressionCompiler.TestsRunner
23+
echo:
24+
echo:running on .NET 8.0 (LTS)
25+
dotnet run --no-build -f:net8.0 -c:Debug --project test/FastExpressionCompiler.TestsRunner
3126
if %ERRORLEVEL% neq 0 goto :error
3227

28+
echo:
29+
echo:running on .NET 6.0 (Previous LTS)
30+
dotnet run --no-build -f:net6.0 -c:Debug --project test/FastExpressionCompiler.TestsRunner
31+
if %ERRORLEVEL% neq 0 goto :error
32+
33+
echo:
34+
echo:running on .NET 4.7.2
3335
dotnet run --no-build -c:Debug --project test/FastExpressionCompiler.TestsRunner.Net472
3436
if %ERRORLEVEL% neq 0 goto :error
3537
echo:

running

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
on .NET 9.0 (Latest)
2+
on .NET 8.0 (LTS)
3+
on .NET 6.0 (Previous LTS)
4+
on .NET 4.7.2
5+
on .NET 9.0 (Latest)
6+
on .NET 8.0 (LTS)

src/FastExpressionCompiler.LightExpression/Expression.cs

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,25 @@ private static ParameterExpression TryToMakeKnownTypeParameter(Type type, string
184184
public static readonly ConstantExpression OneConstant = new IntConstantExpression(1);
185185
public static readonly ConstantExpression MinusOneConstant = new IntConstantExpression(-1);
186186

187-
public static ConstantRefExpression<T> ConstantRef<T>(T value) => new ConstantRefExpression<T>(value);
187+
/// <summary>Holds the value that you can change lately</summary>
188+
public sealed class ValueRef<T>
189+
{
190+
/// <summary>Reflection access to the value FieldInfo</summary>
191+
public static readonly FieldInfo ValueField = typeof(ValueRef<T>).GetField(nameof(Value), BindingFlags.Public | BindingFlags.Instance);
192+
/// <summary>The adjustable value</summary>
193+
public T Value;
194+
/// <summary>Construct with the initial value</summary>
195+
public ValueRef(T value) => Value = value;
196+
}
188197

189-
public static ConstantRefExpression ConstantRef(object value, Type type) => new ConstantRefExpression(value, type);
198+
/// <summary>Simplifies the constant which is always hold in Closure and which Value can be modified after the compilation</summary>
199+
public static Expression ConstantRef<T>(T value, out ValueRef<T> valueRef)
200+
{
201+
valueRef = new ValueRef<T>(value);
202+
203+
// todo: @perf try the intrinsic?
204+
return new InstanceFieldExpression(new ValueConstantExpression<ValueRef<T>>(valueRef), ValueRef<T>.ValueField);
205+
}
190206

191207
/// <summary>Avoids the boxing for all (two) bool values</summary>
192208
public static ConstantExpression Constant(bool value) => value ? TrueConstant : FalseConstant;
@@ -3827,10 +3843,6 @@ public abstract class ConstantExpression : Expression
38273843
public sealed override ExpressionType NodeType => ExpressionType.Constant;
38283844
public abstract object Value { get; }
38293845

3830-
///<summary>Constant with this field defined will be always put in Closure as a Constant instance and not its value,
3831-
/// and will always be accessed by its mutable Field directly, without putting its value into the local variable</summary>
3832-
public virtual FieldInfo RefField => null;
3833-
38343846
#if SUPPORTS_VISITOR
38353847
[RequiresUnreferencedCode(Trimming.Message)]
38363848
protected internal override Expression Accept(ExpressionVisitor visitor) => visitor.VisitConstant(this);
@@ -3869,36 +3881,7 @@ public sealed class ValueConstantExpression<T> : ConstantExpression
38693881
// Note: the Value is specifically an object despite possibility of strongly typed T, because this way it will be a single boxing.
38703882
// Otherwise even using the typed `T _value`, it will be boxed multiple times through its `object Value` accessor.
38713883
public override object Value { get; }
3872-
internal ValueConstantExpression(object value) => Value = value;
3873-
}
3874-
3875-
/// <summary>A special case of Constant entirely stored in Closure,
3876-
/// so that its ValueRef can be updated and the all its Value usage sites will be updated as well, #466.</summary>
3877-
public sealed class ConstantRefExpression<T> : ConstantExpression
3878-
{
3879-
public override Type Type => typeof(T);
3880-
public override object Value => ValueRef;
3881-
private static readonly FieldInfo ValueRefField = typeof(ConstantRefExpression<T>).GetField(nameof(ValueRef));
3882-
public override FieldInfo RefField => ValueRefField;
3883-
public T ValueRef;
3884-
internal ConstantRefExpression(T value) => ValueRef = value;
3885-
}
3886-
3887-
/// <summary>
3888-
/// Note: There is no RefConstantExpression which relies on `Value.GetType()`, because the Value may change (by design), so the Type, which may produce unexpected results.
3889-
/// </summary>
3890-
public sealed class ConstantRefExpression : ConstantExpression
3891-
{
3892-
public override Type Type { get; }
3893-
public override object Value => ValueRef;
3894-
public object ValueRef;
3895-
private static readonly FieldInfo ValueRefField = typeof(ConstantRefExpression).GetField(nameof(ValueRef));
3896-
public override FieldInfo RefField => ValueRefField;
3897-
internal ConstantRefExpression(object value, Type type)
3898-
{
3899-
Type = type ?? typeof(object); // The type always should be set
3900-
ValueRef = value;
3901-
}
3884+
internal ValueConstantExpression(T value) => Value = value;
39023885
}
39033886

39043887
public sealed class TypedValueConstantExpression : ConstantExpression

src/FastExpressionCompiler.LightExpression/FastExpressionCompiler.LightExpression.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks Condition=" '$(LatestSupportedNet)' == 'net7.0' ">net472;netstandard2.0;netstandard2.1;net6.0;net7.0</TargetFrameworks>
4-
<TargetFrameworks Condition=" '$(LatestSupportedNet)' == 'net8.0' ">net472;netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
5-
<TargetFrameworks Condition=" '$(LatestSupportedNet)' == 'net9.0' ">net472;netstandard2.0;netstandard2.1;net6.0;net8.0;net9.0</TargetFrameworks>
3+
<TargetFrameworks Condition="'$(DevMode)' != 'true'">net472;netstandard2.0;netstandard2.1;net6.0;net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks Condition="'$(DevMode)' == 'true'">net472;net9.0</TargetFrameworks>
65

76
<VersionPrefix>5.2.0</VersionPrefix>
8-
<VersionSuffix>preview-02</VersionSuffix>
7+
<VersionSuffix>preview-03</VersionSuffix>
98

109
<Product>FastExpressionCompiler.LightExpression</Product>
1110

@@ -16,7 +15,8 @@
1615
<PackageReleaseNotes><![CDATA[
1716
## v5.2.0
1817
19-
- add: Expose TestTools and FastExpressionCompiler.ILDecoder to enable testing and diagnostic in the consumer projects
18+
- feat: #472 Interpreter to reduce the IL emitted by the Logical, Comparison, Arithmetics expressions, by calculating them during compile time and using the calculation result in IL
19+
- feat: Expose TestTools and FastExpressionCompiler.ILDecoder to enable testing and diagnostic in the consumer code
2020
2121
2222
## v5.1.1. Bug-fix release

0 commit comments

Comments
 (0)