Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ distroless container (`ghcr.io/nullean/assembly-differ`) and a GitHub Action (`a
| `src/Nullean.PublicApi.Diff` | the `Nullean.PublicApi.Diff` package (netstandard2.0, net10.0): `ApiComparison` compares two rich models and classifies each change by who it breaks, binary or source, and extension points; `ApiDiff`, `VersionChange` and `UsageFilter` are the JustAssembly-compatible comparison behind the commands' reports, on the internal model in `JustAssembly/` |
| `tests/Nullean.PublicApi.Tests` | TUnit tests of the reader, writer, parser and comparison (`Properties`: CsCheck properties over libraries `GeneratedLibrary` writes from a choice sequence, checked against Roslyn, round-tripped, split and compared both ways) (`ComparisonTests`: one old and new library per rule, snapshotted): `.api` snapshots of C# samples; `RoslynOracleTests`, which checks every visible signature of framework assemblies against Roslyn's reading of them; `ParserTests`, which parse each `.api` file back and require the same text and the same model, field by field (`ModelDump`) |
| `tests/assembly-differ.Tests` | TUnit tests that run the built tool as a process on assemblies Roslyn compiles from C# source |
| `benchmarks/Nullean.PublicApi.Benchmarks` | BenchmarkDotNet: reading, writing, parsing and comparing System.Collections.Immutable and CoreLib, with allocations. `dotnet run -c Release --project benchmarks/Nullean.PublicApi.Benchmarks -- --filter '*' --inProcess` (in process: BenchmarkDotNet 0.15 does not know net11.0 yet) |
| `build/scripts` | the F# build ([Runna.Fs](https://www.nuget.org/packages/Runna.Fs), net11.0) the `mise` tasks and CI call |
| `build/keys` | the strong-name key the tool's and the libraries' assemblies are signed with |
| `action.yml` | the GitHub Action: runs the `edge` container image |
Expand Down
5 changes: 5 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.12.0" />
</ItemGroup>

<!-- benchmarks/ -->
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.15.8" />
</ItemGroup>

<!-- build/scripts -->
<ItemGroup>
<!-- under CPM the F# SDK adds no implicit FSharp.Core; Runna.Fs needs 11.0.100 or later -->
Expand Down
6 changes: 6 additions & 0 deletions api/Nullean.PublicApi.net10.0.api
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ namespace Nullean.PublicApi
New = 32
AllowsRefStruct = 64

sealed class ApiDeclarationWriter
ApiDeclarationWriter(ApiType type)
string Declaration()
string Declaration(ApiMember member)
string Reference(ApiTypeReference type)

sealed class ApiDocument
ApiAssembly Assembly { get; }
int? LineOf(object node)
Expand Down
6 changes: 6 additions & 0 deletions api/Nullean.PublicApi.netstandard2.0.api
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ namespace Nullean.PublicApi
New = 32
AllowsRefStruct = 64

sealed class ApiDeclarationWriter
ApiDeclarationWriter(ApiType type)
string Declaration()
string Declaration(ApiMember member)
string Reference(ApiTypeReference type)

sealed class ApiDocument
ApiAssembly Assembly { get; }
int? LineOf(object node)
Expand Down
1 change: 1 addition & 0 deletions assembly-differ.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
<Folder Name="/tests/">
<Project Path="tests/assembly-differ.Tests/assembly-differ.Tests.csproj" />
<Project Path="tests/Nullean.PublicApi.Tests/Nullean.PublicApi.Tests.csproj" />
<Project Path="benchmarks/Nullean.PublicApi.Benchmarks/Nullean.PublicApi.Benchmarks.csproj" />
</Folder>
</Solution>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net11.0</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../../src/Nullean.PublicApi/Nullean.PublicApi.csproj" />
<ProjectReference Include="../../src/Nullean.PublicApi.Diff/Nullean.PublicApi.Diff.csproj" />
</ItemGroup>
</Project>
46 changes: 46 additions & 0 deletions benchmarks/Nullean.PublicApi.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Nullean.PublicApi;
using Nullean.PublicApi.Diff;

BenchmarkSwitcher.FromAssembly(typeof(PublicApiBenchmarks).Assembly).Run(args);

/// <summary>
/// Reading an assembly's API from metadata, writing it as a .api file, parsing the file, and comparing two APIs, for
/// a framework assembly of each size. Run with: dotnet run -c Release --project benchmarks/Nullean.PublicApi.Benchmarks
/// </summary>
[MemoryDiagnoser]
public class PublicApiBenchmarks
{
private byte[] _image = [];
private ApiAssembly _api = null!;
private string _text = "";
private ApiAssembly _parsed = null!;

[Params("System.Collections.Immutable", "System.Private.CoreLib")]
public string Assembly { get; set; } = "";

[GlobalSetup]
public void Setup()
{
var path = ((string)AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES")!).Split(Path.PathSeparator).First(
p => Path.GetFileNameWithoutExtension(p) == Assembly
);
_image = File.ReadAllBytes(path);
_api = ApiReader.Read(new MemoryStream(_image));
_text = ApiWriter.Write(_api);
_parsed = ApiParser.Parse(_text).Assembly;
}

[Benchmark]
public ApiAssembly Read() => ApiReader.Read(new MemoryStream(_image));

[Benchmark]
public string Write() => ApiWriter.Write(_api);

[Benchmark]
public ApiDocument Parse() => ApiParser.Parse(_text);

[Benchmark]
public ApiComparisonResult Compare() => ApiComparison.Compare(_api, _parsed);
}
Loading
Loading