Skip to content

Commit fe9a54d

Browse files
tannergoodingdavidwrightonlambdageek
authored
Expose and implement generic math interfaces on core types (#54650)
* 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 #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>
1 parent 5b337cb commit fe9a54d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+15921
-27
lines changed

eng/Versions.props

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<DotNetFinalVersionKind Condition="'$(StabilizePackageVersion)' == 'true'">release</DotNetFinalVersionKind>
1818
<!-- Opt-in/out repo features -->
1919
<UsingToolMicrosoftNetCompilers>true</UsingToolMicrosoftNetCompilers>
20+
<!-- TODO: Upgrade compiler version to enable Static Abstracts in Interfaces; remove this once the employed SDK uses a new enough version. -->
21+
<MicrosoftNetCompilersToolsetVersion>4.0.0-2.21323.11</MicrosoftNetCompilersToolsetVersion>
2022
<UsingToolMicrosoftNetILLinkTasks>true</UsingToolMicrosoftNetILLinkTasks>
2123
<UsingToolIbcOptimization>false</UsingToolIbcOptimization>
2224
<UsingToolXliff>false</UsingToolXliff>

src/coreclr/clr.featuredefines.props

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<FeaturePerfTracing>true</FeaturePerfTracing>
1010
<FeatureTypeEquivalence>true</FeatureTypeEquivalence>
1111
<FeatureBasicFreeze>true</FeatureBasicFreeze>
12+
<FeatureGenericMath>true</FeatureGenericMath>
1213
<ProfilingSupportedBuild>true</ProfilingSupportedBuild>
1314
</PropertyGroup>
1415

@@ -58,7 +59,8 @@
5859
<DefineConstants Condition="'$(FeatureBasicFreeze)' == 'true'">$(DefineConstants);FEATURE_BASICFREEZE</DefineConstants>
5960
<DefineConstants Condition="'$(FeaturePortableShuffleThunks)' == 'true'">$(DefineConstants);FEATURE_PORTABLE_SHUFFLE_THUNKS</DefineConstants>
6061
<DefineConstants Condition="'$(FeatureICastable)' == 'true'">$(DefineConstants);FEATURE_ICASTABLE</DefineConstants>
61-
62+
<DefineConstants Condition="'$(FeatureGenericMath)' == 'true'">$(DefineConstants);FEATURE_GENERIC_MATH</DefineConstants>
63+
6264
<DefineConstants Condition="'$(ProfilingSupportedBuild)' == 'true'">$(DefineConstants);PROFILING_SUPPORTED</DefineConstants>
6365
<DefineConstants Condition="'$(FeatureProfAttach)' == 'true'">$(DefineConstants);FEATURE_PROFAPI_ATTACH_DETACH</DefineConstants>
6466
</PropertyGroup>

src/coreclr/vm/typedesc.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,11 @@ BOOL TypeVarTypeDesc::SatisfiesConstraints(SigTypeContext *pTypeContextOfConstra
17301730
}
17311731
CONTRACTL_END;
17321732

1733+
// During EEStartup, we cannot safely validate constraints, but we can also be confident that the code doesn't violate them
1734+
// Just skip validation and declare that the constraints are satisfied.
1735+
if (g_fEEInit)
1736+
return TRUE;
1737+
17331738
IMDInternalImport* pInternalImport = GetModule()->GetMDImport();
17341739
mdGenericParamConstraint tkConstraint;
17351740

src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems

+23
Original file line numberDiff line numberDiff line change
@@ -2257,4 +2257,27 @@
22572257
<Link>Interop\Windows\Kernel32\Interop.Threading.cs</Link>
22582258
</Compile>
22592259
</ItemGroup>
2260+
<ItemGroup Condition="'$(FeatureGenericMath)' == 'true'">
2261+
<Compile Include="$(MSBuildThisFileDirectory)System\IAdditionOperators.cs" />
2262+
<Compile Include="$(MSBuildThisFileDirectory)System\IAdditiveIdentity.cs" />
2263+
<Compile Include="$(MSBuildThisFileDirectory)System\IBitwiseOperators.cs" />
2264+
<Compile Include="$(MSBuildThisFileDirectory)System\IComparisonOperators.cs" />
2265+
<Compile Include="$(MSBuildThisFileDirectory)System\IDecrementOperators.cs" />
2266+
<Compile Include="$(MSBuildThisFileDirectory)System\IDivisionOperators.cs" />
2267+
<Compile Include="$(MSBuildThisFileDirectory)System\IEqualityOperators.cs" />
2268+
<Compile Include="$(MSBuildThisFileDirectory)System\IFloatingPoint.cs" />
2269+
<Compile Include="$(MSBuildThisFileDirectory)System\IIncrementOperators.cs" />
2270+
<Compile Include="$(MSBuildThisFileDirectory)System\IInteger.cs" />
2271+
<Compile Include="$(MSBuildThisFileDirectory)System\IMinMaxValue.cs" />
2272+
<Compile Include="$(MSBuildThisFileDirectory)System\IModulusOperators.cs" />
2273+
<Compile Include="$(MSBuildThisFileDirectory)System\IMultiplicativeIdentity.cs" />
2274+
<Compile Include="$(MSBuildThisFileDirectory)System\IMultiplyOperators.cs" />
2275+
<Compile Include="$(MSBuildThisFileDirectory)System\INumber.cs" />
2276+
<Compile Include="$(MSBuildThisFileDirectory)System\IParseable.cs" />
2277+
<Compile Include="$(MSBuildThisFileDirectory)System\IShiftOperators.cs" />
2278+
<Compile Include="$(MSBuildThisFileDirectory)System\ISpanParseable.cs" />
2279+
<Compile Include="$(MSBuildThisFileDirectory)System\ISubtractionOperators.cs" />
2280+
<Compile Include="$(MSBuildThisFileDirectory)System\IUnaryNegationOperators.cs" />
2281+
<Compile Include="$(MSBuildThisFileDirectory)System\IUnaryPlusOperators.cs" />
2282+
</ItemGroup>
22602283
</Project>

0 commit comments

Comments
 (0)