Skip to content

Commit

Permalink
Merge pull request #93 from kzrnm/feature/switch_source_expander
Browse files Browse the repository at this point in the history
Make SourceExpander.Embedder switchable
  • Loading branch information
kzrnm authored Jan 24, 2023
2 parents 834b7bb + e9b917e commit 1f045fc
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 81 deletions.
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

<PackageOutputPath>$(MSBuildThisFileDirectory)bin\Packages\$(Configuration)\</PackageOutputPath>

<EmbeddingSource>true</EmbeddingSource>
<DefineConstants Condition="'$(EmbeddingSource)'=='true'">$(DefineConstants);EMBEDDING</DefineConstants>

<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
8 changes: 0 additions & 8 deletions Source/AtCoderAnalyzer/AnalyzerReleases.Shipped.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,3 @@ AC0003 | Type Define | Error | Not defined IStaticMod
AC0004 | Type Define | Error | Not defined IDynamicModID
AC0005 | Type Define | Error | Not defined ISegtreeOperator<T>
AC0006 | Type Define | Error | Not defined ILazySegtreeOperator<T, F>

## Release 1.10.0

### Changed Rules

Rule ID | Category | Severity | Notes
--------|----------|----------|--------------------
AC0007 | Type Define | Info | Operator method doesn't have `MethodImpl(AggressiveInlining)` attribute
11 changes: 7 additions & 4 deletions Source/AtCoderAnalyzer/Diagnostics/DiagnosticDescriptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ namespace AtCoderAnalyzer.Diagnostics
{
public static class DiagnosticDescriptors
{
#pragma warning disable IDE0090 // Avoid 'new(...)' for Shipped.md
internal static Diagnostic AC0001_MultiplyOverflowInt32(SyntaxNode node)
=> Diagnostic.Create(AC0001_MultiplyOverflowInt32_Descriptor, node.GetLocation(), node.ToString());
internal static readonly DiagnosticDescriptor AC0001_MultiplyOverflowInt32_Descriptor = new(
internal static readonly DiagnosticDescriptor AC0001_MultiplyOverflowInt32_Descriptor = new DiagnosticDescriptor(
"AC0001",
new LocalizableResourceString(
nameof(DiagnosticsResources.AC0001_Title),
Expand All @@ -23,7 +24,7 @@ internal static Diagnostic AC0001_MultiplyOverflowInt32(SyntaxNode node)
);
internal static Diagnostic AC0002_LeftShiftOverflowInt32(SyntaxNode node)
=> Diagnostic.Create(AC0002_LeftShiftOverflowInt32_Descriptor, node.GetLocation(), node.ToString());
internal static readonly DiagnosticDescriptor AC0002_LeftShiftOverflowInt32_Descriptor = new(
internal static readonly DiagnosticDescriptor AC0002_LeftShiftOverflowInt32_Descriptor = new DiagnosticDescriptor(
"AC0002",
new LocalizableResourceString(
nameof(DiagnosticsResources.AC0002_Title),
Expand All @@ -40,7 +41,8 @@ internal static Diagnostic AC0002_LeftShiftOverflowInt32(SyntaxNode node)

internal static Diagnostic AC0007_AgressiveInlining(Location location, IEnumerable<string> methods)
=> Diagnostic.Create(AC0007_AgressiveInlining_Descriptor, location, string.Join(", ", methods));
internal static readonly DiagnosticDescriptor AC0007_AgressiveInlining_Descriptor = new(

internal static readonly DiagnosticDescriptor AC0007_AgressiveInlining_Descriptor = new DiagnosticDescriptor(
"AC0007",
new LocalizableResourceString(
nameof(DiagnosticsResources.AC0007_Title),
Expand All @@ -57,7 +59,7 @@ internal static Diagnostic AC0007_AgressiveInlining(Location location, IEnumerab

internal static Diagnostic AC0008_DefineOperatorType(Location location, IEnumerable<string> types)
=> Diagnostic.Create(AC0008_DefineOperatorType_Descriptor, location, string.Join(", ", types));
internal static readonly DiagnosticDescriptor AC0008_DefineOperatorType_Descriptor = new(
internal static readonly DiagnosticDescriptor AC0008_DefineOperatorType_Descriptor = new DiagnosticDescriptor(
"AC0008",
new LocalizableResourceString(
nameof(DiagnosticsResources.AC0008_Title),
Expand All @@ -71,5 +73,6 @@ internal static Diagnostic AC0008_DefineOperatorType(Location location, IEnumera
DiagnosticSeverity.Error,
isEnabledByDefault: true
);
#pragma warning restore IDE0090
}
}
4 changes: 3 additions & 1 deletion Source/ac-library-csharp/Internal/InternalBit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public static uint ExtractLowestSetBit(int n)
[MethodImpl(256)]
public static int Bsf(uint n)
{
//Contract.Assert(n > 0, reason: $"{nameof(n)} must positive");
#if EMBEDDING
Contract.Assert(n > 0, reason: $"{nameof(n)} must positive");
#endif
return BitOperations.TrailingZeroCount(n);
}

Expand Down
12 changes: 8 additions & 4 deletions Source/ac-library-csharp/Math/DynamicModInt.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Globalization;
using System.Numerics;
using System.Runtime.CompilerServices;
using AtCoder.Internal;
#if GENERIC_MATH
using System.Globalization;
using System.Numerics;
#endif

namespace AtCoder
{
Expand Down Expand Up @@ -88,8 +90,10 @@ public static int Mod
public static DynamicModInt<T> Raw(int v)
{
var u = unchecked((uint)v);
//Contract.Assert(bt != null, $"{nameof(DynamicModInt<T>)}<{nameof(T)}>.{nameof(Mod)} is undefined.");
//Contract.Assert(u < Mod, $"{nameof(u)} must be less than {nameof(Mod)}.");
#if EMBEDDING
Contract.Assert(bt != null, $"{nameof(DynamicModInt<T>)}<{nameof(T)}>.{nameof(Mod)} is undefined.");
Contract.Assert(u < Mod, $"{nameof(u)} must be less than {nameof(Mod)}.");
#endif
return new DynamicModInt<T>(u);
}

Expand Down
10 changes: 7 additions & 3 deletions Source/ac-library-csharp/Math/StaticModInt.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Globalization;
using System.Numerics;
using System.Runtime.CompilerServices;
using AtCoder.Internal;
#if GENERIC_MATH
using System.Globalization;
using System.Numerics;
#endif

namespace AtCoder
{
Expand Down Expand Up @@ -92,7 +94,9 @@ public readonly struct StaticModInt<T>
public static StaticModInt<T> Raw(int v)
{
var u = unchecked((uint)v);
//Contract.Assert(u < Mod, $"{nameof(u)} must be less than {nameof(Mod)}.");
#if EMBEDDING
Contract.Assert(u < Mod, $"{nameof(u)} must be less than {nameof(Mod)}.");
#endif
return new StaticModInt<T>(u);
}

Expand Down
4 changes: 3 additions & 1 deletion Source/ac-library-csharp/String/StringLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ static int[] CreateIdx<T>(ReadOnlySpan<T> m)
public static int[] SuffixArray(int[] s, int upper)
{
Contract.Assert(0 <= upper, reason: $"{nameof(upper)} must be positive.");
//Contract.Assert(s.All(si => (uint)si <= (uint)upper), reason: $"si ∈ {nameof(s)} must be 0 <= si && si <= {nameof(upper)}");
#if EMBEDDING
Contract.Assert(s.All(si => (uint)si <= (uint)upper), reason: $"si ∈ {nameof(s)} must be 0 <= si && si <= {nameof(upper)}");
#endif
return InternalString.SaIs(s, upper);
}
#endregion SuffixArray
Expand Down
110 changes: 55 additions & 55 deletions Source/ac-library-csharp/ac-library-csharp.csproj
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;netcoreapp3.1;netstandard2.1</TargetFrameworks>
<RootNamespace>AtCoder</RootNamespace>
<OutputType>Library</OutputType>
<PropertyGroup>
<TargetFrameworks>net7.0;netcoreapp3.1;netstandard2.1</TargetFrameworks>
<RootNamespace>AtCoder</RootNamespace>
<OutputType>Library</OutputType>

<LangVersion Condition="'$(TargetFramework)' == 'netstandard2.1'">7.3</LangVersion>
<LangVersion Condition="'$(TargetFramework)' == 'netcoreapp3.1'">8</LangVersion>
<LangVersion Condition="'$(TargetFramework)' == 'net7.0'">11</LangVersion>
<LangVersion Condition="'$(TargetFramework)' == 'netstandard2.1'">7.3</LangVersion>
<LangVersion Condition="'$(TargetFramework)' == 'netcoreapp3.1'">8</LangVersion>
<LangVersion Condition="'$(TargetFramework)' == 'net7.0'">11</LangVersion>

<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>

<PackageTags>ac-library-csharp;AtCoder</PackageTags>
<PackageId>ac-library-csharp</PackageId>
<Description>C# port of ac-library</Description>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<PackageTags>ac-library-csharp;AtCoder</PackageTags>
<PackageId>ac-library-csharp</PackageId>
<Description>C# port of ac-library</Description>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>

<NoWarn>$(NoWarn);CS1574;CA1034;CS1591;CS1734;IDE0039;IDE0057</NoWarn>
<NoWarn>$(NoWarn);CS1574;CA1034;CS1591;CS1734;IDE0039;IDE0057</NoWarn>

<PackageLicenseExpression></PackageLicenseExpression>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageLicenseExpression></PackageLicenseExpression>
<PackageLicenseFile>LICENSE</PackageLicenseFile>

<DefineConstants>$(DefineConstants);ATCODER_CONTRACT</DefineConstants>
<DefineConstants>$(DefineConstants);ATCODER_CONTRACT</DefineConstants>

<GenericMath Condition="'$(TargetFramework)'!='netstandard2.1' And '$(TargetFramework)'!='netcoreapp3.1'">true</GenericMath>
<DefineConstants Condition="'$(GenericMath)'=='true'">$(DefineConstants);GENERIC_MATH</DefineConstants>
</PropertyGroup>
<ItemGroup>
<InternalsVisibleTo Include="ac-library-csharp.Test, PublicKey=002400000480000094000000060200000024000052534131000400000100010019f27fe0b62f6a374e67a12dbd713e0b521d251abc73fcb1e3929cc74a99905daae786e8854b1ccd7401ecb850627c58ecf491bebe9a2fef9effbc63e74e1c00e036282d754dd6c8ffd12e8fd07897bf31b551f68d594c2bdd5be8009adc6eb625e10629d36d731246a8a9c353b62c49902024cf1c7fc0f59952325eec2df5a6" />
</ItemGroup>
<GenericMath Condition="'$(TargetFramework)'!='netstandard2.1' And '$(TargetFramework)'!='netcoreapp3.1'">true</GenericMath>
<DefineConstants Condition="'$(GenericMath)'=='true'">$(DefineConstants);GENERIC_MATH</DefineConstants>
</PropertyGroup>
<ItemGroup>
<InternalsVisibleTo Include="ac-library-csharp.Test, PublicKey=002400000480000094000000060200000024000052534131000400000100010019f27fe0b62f6a374e67a12dbd713e0b521d251abc73fcb1e3929cc74a99905daae786e8854b1ccd7401ecb850627c58ecf491bebe9a2fef9effbc63e74e1c00e036282d754dd6c8ffd12e8fd07897bf31b551f68d594c2bdd5be8009adc6eb625e10629d36d731246a8a9c353b62c49902024cf1c7fc0f59952325eec2df5a6" />
</ItemGroup>

<ItemGroup Condition="'$(GenericMath)'!='true'">
<Compile Remove="**/*GenericMath.cs" />
<Compile Remove="**/*GenericMath/**/*.cs" />
</ItemGroup>
<ItemGroup Condition="'$(GenericMath)'!='true'">
<Compile Remove="**/*GenericMath.cs" />
<Compile Remove="**/*GenericMath/**/*.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Source\AtCoderAnalyzer\AtCoderAnalyzer.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>Analyzer</OutputItemType>
</ProjectReference>
<PackageReference Include="SourceExpander.Embedder" Version="5.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Source\AtCoderAnalyzer\AtCoderAnalyzer.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>Analyzer</OutputItemType>
</ProjectReference>
<PackageReference Include="SourceExpander.Embedder" Version="5.1.0" Condition="'$(EmbeddingSource)'=='true'">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<None Include="LICENSE" Pack="True" PackagePath="" />
<None Include="Math\MathLib.Convolution.Primitives.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>MathLib.Convolution.Primitives.tt</DependentUpon>
</None>
<None Update="Math\MathLib.Convolution.Primitives.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>MathLib.Convolution.Primitives.cs</LastGenOutput>
</None>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
<Compile Update="Math\MathLib.Convolution.Primitives.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>MathLib.Convolution.Primitives.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="LICENSE" Pack="True" PackagePath="" />
<None Include="Math\MathLib.Convolution.Primitives.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>MathLib.Convolution.Primitives.tt</DependentUpon>
</None>
<None Update="Math\MathLib.Convolution.Primitives.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>MathLib.Convolution.Primitives.cs</LastGenOutput>
</None>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
<Compile Update="Math\MathLib.Convolution.Primitives.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>MathLib.Convolution.Primitives.tt</DependentUpon>
</Compile>
</ItemGroup>

</Project>
29 changes: 24 additions & 5 deletions Test/ac-library-csharp.Test/SourceExpanderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ namespace AtCoder.Embedding
{
public class SourceExpanderTest
{
class EmbeddingFact : FactAttribute
{
#if !EMBEDDING
public override string Skip => "SourceExpander.Embedder is disabled.";
#endif
}

#if NETCOREAPP3_0
const bool useIntrinsics = false;
const string languageVersion = "7.3";
Expand All @@ -20,12 +27,24 @@ public class SourceExpanderTest
#endif

[Fact]
public async Task Embedding()
{
var embedded = await EmbeddedData.LoadFromAssembly(typeof(Segtree<,>));
embedded.AssemblyMetadatas.Keys.Should()
#if EMBEDDING
.ContainMatch(@"SourceExpander.*");
#else
.NotContainMatch(@"SourceExpander.*");
#endif
}

[EmbeddingFact]
public void AssemblyName()
{
typeof(Segtree<,>).Assembly.GetName().Name.Should().Be("ac-library-csharp");
}

[Fact]
[EmbeddingFact]
public async Task Symbol()
{
var embedded = await EmbeddedData.LoadFromAssembly(typeof(Segtree<,>));
Expand All @@ -41,7 +60,7 @@ public async Task Symbol()
.Be(useIntrinsics);
}

[Fact]
[EmbeddingFact]
public async Task LanguageVersion()
{
var embedded = await EmbeddedData.LoadFromAssembly(typeof(Segtree<,>));
Expand All @@ -50,7 +69,7 @@ public async Task LanguageVersion()
.WhoseValue.Should().Be(languageVersion);
}

[Fact]
[EmbeddingFact]
public async Task EmbeddedSource()
{
var embedded = await EmbeddedData.LoadFromAssembly(typeof(Segtree<,>));
Expand All @@ -67,7 +86,7 @@ public async Task EmbeddedSource()
"AtCoder.Segtree<TValue, TOp>");
}

[Fact]
[EmbeddingFact]
public async Task EmbeddedNamespaces()
{
var embedded = await EmbeddedData.LoadFromAssembly(typeof(Segtree<,>));
Expand All @@ -81,7 +100,7 @@ public async Task EmbeddedNamespaces()
}


[Fact]
[EmbeddingFact]
public async Task RemoveContract()
{
var embedded = await EmbeddedData.LoadFromAssembly(typeof(Segtree<,>));
Expand Down

0 comments on commit 1f045fc

Please sign in to comment.