Skip to content

Commit

Permalink
Expose and implement generic math interfaces on core types (dotnet#54650
Browse files Browse the repository at this point in the history
)

* Pin MicrosoftNetCompilersToolsetVersion to a version that supports Static Abstracts in Interfaces

* Fixed issues related to enabling generic math in a general sense (#4)

- Disable constraint checking during EEInit
- Disable il linker running on CoreLib
- Fixup generic math tests to actually build

* Adding interfaces to support generic math

* Implement generic math interfaces on core types

* Updating the System.Runtime ref assembly to support generic math

* Add a basic xunit test for generic-math

* Removing unnecessary nullable annotations

* Ensure all preview interface members are explicitly implemented

* Don't use var for various methods in Double/Half/Single

* Ensure FeatureGenericMath is defined for Mono

* Skip generic math tests on Mono WASM due to dotnet#54910

* Apply suggestions from code review

Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>

Co-authored-by: David Wrighton <davidwr@microsoft.com>
Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
  • Loading branch information
3 people authored Jul 2, 2021
1 parent 5b337cb commit fe9a54d
Show file tree
Hide file tree
Showing 52 changed files with 15,921 additions and 27 deletions.
2 changes: 2 additions & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<DotNetFinalVersionKind Condition="'$(StabilizePackageVersion)' == 'true'">release</DotNetFinalVersionKind>
<!-- Opt-in/out repo features -->
<UsingToolMicrosoftNetCompilers>true</UsingToolMicrosoftNetCompilers>
<!-- TODO: Upgrade compiler version to enable Static Abstracts in Interfaces; remove this once the employed SDK uses a new enough version. -->
<MicrosoftNetCompilersToolsetVersion>4.0.0-2.21323.11</MicrosoftNetCompilersToolsetVersion>
<UsingToolMicrosoftNetILLinkTasks>true</UsingToolMicrosoftNetILLinkTasks>
<UsingToolIbcOptimization>false</UsingToolIbcOptimization>
<UsingToolXliff>false</UsingToolXliff>
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/clr.featuredefines.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<FeaturePerfTracing>true</FeaturePerfTracing>
<FeatureTypeEquivalence>true</FeatureTypeEquivalence>
<FeatureBasicFreeze>true</FeatureBasicFreeze>
<FeatureGenericMath>true</FeatureGenericMath>
<ProfilingSupportedBuild>true</ProfilingSupportedBuild>
</PropertyGroup>

Expand Down Expand Up @@ -58,7 +59,8 @@
<DefineConstants Condition="'$(FeatureBasicFreeze)' == 'true'">$(DefineConstants);FEATURE_BASICFREEZE</DefineConstants>
<DefineConstants Condition="'$(FeaturePortableShuffleThunks)' == 'true'">$(DefineConstants);FEATURE_PORTABLE_SHUFFLE_THUNKS</DefineConstants>
<DefineConstants Condition="'$(FeatureICastable)' == 'true'">$(DefineConstants);FEATURE_ICASTABLE</DefineConstants>

<DefineConstants Condition="'$(FeatureGenericMath)' == 'true'">$(DefineConstants);FEATURE_GENERIC_MATH</DefineConstants>

<DefineConstants Condition="'$(ProfilingSupportedBuild)' == 'true'">$(DefineConstants);PROFILING_SUPPORTED</DefineConstants>
<DefineConstants Condition="'$(FeatureProfAttach)' == 'true'">$(DefineConstants);FEATURE_PROFAPI_ATTACH_DETACH</DefineConstants>
</PropertyGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/vm/typedesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,11 @@ BOOL TypeVarTypeDesc::SatisfiesConstraints(SigTypeContext *pTypeContextOfConstra
}
CONTRACTL_END;

// During EEStartup, we cannot safely validate constraints, but we can also be confident that the code doesn't violate them
// Just skip validation and declare that the constraints are satisfied.
if (g_fEEInit)
return TRUE;

IMDInternalImport* pInternalImport = GetModule()->GetMDImport();
mdGenericParamConstraint tkConstraint;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2257,4 +2257,27 @@
<Link>Interop\Windows\Kernel32\Interop.Threading.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup Condition="'$(FeatureGenericMath)' == 'true'">
<Compile Include="$(MSBuildThisFileDirectory)System\IAdditionOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IAdditiveIdentity.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IBitwiseOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IComparisonOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IDecrementOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IDivisionOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IEqualityOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IFloatingPoint.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IIncrementOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IInteger.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IMinMaxValue.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IModulusOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IMultiplicativeIdentity.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IMultiplyOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\INumber.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IParseable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IShiftOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ISpanParseable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ISubtractionOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IUnaryNegationOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IUnaryPlusOperators.cs" />
</ItemGroup>
</Project>
Loading

0 comments on commit fe9a54d

Please sign in to comment.