diff --git a/AGENTS.md b/AGENTS.md
index 289f438..983dd63 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -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 |
diff --git a/Directory.Packages.props b/Directory.Packages.props
index f1b2022..5d93826 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -37,6 +37,11 @@
+
+
+
+
+
diff --git a/api/Nullean.PublicApi.net10.0.api b/api/Nullean.PublicApi.net10.0.api
index cf44add..cc5eadc 100644
--- a/api/Nullean.PublicApi.net10.0.api
+++ b/api/Nullean.PublicApi.net10.0.api
@@ -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)
diff --git a/api/Nullean.PublicApi.netstandard2.0.api b/api/Nullean.PublicApi.netstandard2.0.api
index 2c69bc2..40fdca0 100644
--- a/api/Nullean.PublicApi.netstandard2.0.api
+++ b/api/Nullean.PublicApi.netstandard2.0.api
@@ -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)
diff --git a/assembly-differ.slnx b/assembly-differ.slnx
index 153cc63..01a9f26 100644
--- a/assembly-differ.slnx
+++ b/assembly-differ.slnx
@@ -23,5 +23,6 @@
+
diff --git a/benchmarks/Nullean.PublicApi.Benchmarks/Nullean.PublicApi.Benchmarks.csproj b/benchmarks/Nullean.PublicApi.Benchmarks/Nullean.PublicApi.Benchmarks.csproj
new file mode 100644
index 0000000..f255ee0
--- /dev/null
+++ b/benchmarks/Nullean.PublicApi.Benchmarks/Nullean.PublicApi.Benchmarks.csproj
@@ -0,0 +1,18 @@
+
+
+ net11.0
+ Exe
+ false
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
diff --git a/benchmarks/Nullean.PublicApi.Benchmarks/Program.cs b/benchmarks/Nullean.PublicApi.Benchmarks/Program.cs
new file mode 100644
index 0000000..d2fc9a2
--- /dev/null
+++ b/benchmarks/Nullean.PublicApi.Benchmarks/Program.cs
@@ -0,0 +1,46 @@
+using BenchmarkDotNet.Attributes;
+using BenchmarkDotNet.Running;
+using Nullean.PublicApi;
+using Nullean.PublicApi.Diff;
+
+BenchmarkSwitcher.FromAssembly(typeof(PublicApiBenchmarks).Assembly).Run(args);
+
+///
+/// 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
+///
+[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);
+}
diff --git a/src/Nullean.PublicApi.Diff/ApiComparison.cs b/src/Nullean.PublicApi.Diff/ApiComparison.cs
index 3b389c9..db0fb17 100644
--- a/src/Nullean.PublicApi.Diff/ApiComparison.cs
+++ b/src/Nullean.PublicApi.Diff/ApiComparison.cs
@@ -30,23 +30,84 @@ public static ApiComparisonResult Compare(ApiAssembly oldApi, ApiAssembly newApi
}
/// Pairs two lists by key, in the new list's order with the removed ones after.
- private static void Pair(IReadOnlyList oldItems, IReadOnlyList newItems, Func key, Action visit) where T : class
+ private static readonly System.Runtime.CompilerServices.ConditionalWeakTable Writers = new();
+
+ /// The writer for a type, built once: it looks at the whole type to decide which names to write in full.
+ private static ApiDeclarationWriter Writer(ApiType type) => Writers.GetValue(type, t => new ApiDeclarationWriter(t));
+
+ private static void Pair(IReadOnlyList oldItems, IReadOnlyList newItems, Func key, Action visit) where T : class =>
+ Pair(oldItems, newItems, new KeyComparer(key), visit);
+
+ /// Pairs two lists by identity, in the new list's order with the removed ones after.
+ private static void Pair(IReadOnlyList oldItems, IReadOnlyList newItems, IEqualityComparer identity, Action visit) where T : class
{
- var old = new Dictionary(StringComparer.Ordinal);
+ var old = new Dictionary(oldItems.Count, identity);
foreach (var item in oldItems)
- old[key(item)] = item;
- var seen = new HashSet(StringComparer.Ordinal);
+ old[item] = item;
+ var paired = new HashSet(identity);
foreach (var item in newItems)
{
- var k = key(item);
- seen.Add(k);
- visit(old.TryGetValue(k, out var match) ? match : null, item);
+ paired.Add(item);
+ visit(old.TryGetValue(item, out var match) ? match : null, item);
}
foreach (var item in oldItems)
- if (!seen.Contains(key(item)))
+ if (!paired.Contains(item))
visit(item, null);
}
+ private sealed class KeyComparer(Func key) : IEqualityComparer
+ {
+ public bool Equals(T? x, T? y) => x is not null && y is not null && key(x) == key(y);
+
+ public int GetHashCode(T obj) => StringComparer.Ordinal.GetHashCode(key(obj));
+ }
+
+ ///
+ /// A member's identity, compared on the models: its kind, name, number of type parameters and parameter types as the
+ /// runtime sees them, the same as 's string key without writing one per member.
+ ///
+ private sealed class MemberIdentity : IEqualityComparer
+ {
+ public static readonly MemberIdentity Instance = new();
+
+ public bool Equals(ApiMember? x, ApiMember? y)
+ {
+ if (x is null || y is null || x.GetType() != y.GetType() || x.Name != y.Name)
+ return false;
+ switch (x, y)
+ {
+ case (ApiProperty a, ApiProperty b):
+ return SameParameters(a.Parameters, b.Parameters);
+ case (ApiMethod a, ApiMethod b):
+ return a.TypeParameters.Count == b.TypeParameters.Count && SameParameters(a.Parameters, b.Parameters) &&
+ (a.Kind != ApiMethodKind.Conversion || Context.SameRuntime(a.ReturnType, b.ReturnType));
+ default:
+ return true;
+ }
+ }
+
+ private static bool SameParameters(IReadOnlyList a, IReadOnlyList b)
+ {
+ if (a.Count != b.Count)
+ return false;
+ for (var i = 0; i < a.Count; i++)
+ if ((a[i].RefKind == ApiRefKind.None) != (b[i].RefKind == ApiRefKind.None) || !Context.SameRuntime(a[i].Type, b[i].Type))
+ return false;
+ return true;
+ }
+
+ public int GetHashCode(ApiMember obj)
+ {
+ var count = obj switch
+ {
+ ApiMethod m => m.Parameters.Count * 31 + m.TypeParameters.Count,
+ ApiProperty p => p.Parameters.Count,
+ _ => 0,
+ };
+ return (StringComparer.Ordinal.GetHashCode(obj.Name) * 397) ^ (count * 17) ^ obj.GetType().GetHashCode();
+ }
+ }
+
private sealed class Context(ApiComparisonOptions options, ApiAssembly newApi)
{
public List Changes { get; } = [];
@@ -80,7 +141,7 @@ public void Type(ApiType? oldType, ApiType? newType, List path)
var here = path.Append(TypeSegment(type)).ToList();
if (oldType is null)
{
- Add(here, ApiChangeKind.Added, "", null, ApiWriter.Declaration(newType!), ApiAudience.None, ApiCompatibility.None, null, newType, newType);
+ Add(here, ApiChangeKind.Added, "", null, Writer(newType!).Declaration(), ApiAudience.None, ApiCompatibility.None, null, newType, newType);
return;
}
if (newType is null)
@@ -89,7 +150,7 @@ public void Type(ApiType? oldType, ApiType? newType, List path)
here,
ApiChangeKind.Removed,
"",
- ApiWriter.Declaration(oldType),
+ Writer(oldType).Declaration(),
null,
ApiAudience.Callers,
Both,
@@ -149,10 +210,8 @@ void Changed(string part, string? old, string? @new, ApiAudience breaks, ApiComp
if (oldType.Kind == ApiTypeKind.Delegate && newType.Kind == ApiTypeKind.Delegate)
{
- var oldSignature = ApiWriter.Declaration(oldType);
- var newSignature = ApiWriter.Declaration(newType);
if (Key(oldType.Members.OfType().First(), oldType) != Key(newType.Members.OfType().First(), newType))
- Changed("signature", oldSignature, newSignature, ApiAudience.Callers, Both);
+ Changed("signature", Writer(oldType).Declaration(), Writer(newType).Declaration(), ApiAudience.Callers, Both);
else
Member(
oldType.Members.OfType().First(),
@@ -164,12 +223,7 @@ void Changed(string part, string? old, string? @new, ApiAudience breaks, ApiComp
);
}
else
- Pair(
- oldType.Members,
- newType.Members,
- m => Key(m, oldType.Members.Contains(m) ? oldType : newType),
- (o, n) => Member(o, n, oldType, newType, here)
- );
+ Pair(oldType.Members, newType.Members, MemberIdentity.Instance, (o, n) => Member(o, n, oldType, newType, here));
Pair(oldType.NestedTypes, newType.NestedTypes, t => t.Name, (o, n) => Type(o, n, here));
}
@@ -181,8 +235,8 @@ private void Bases(ApiType oldType, ApiType newType, Action i, StringComparer.Ordinal);
var newInterfaces = newType.Interfaces.ToDictionary(Erase, i => i, StringComparer.Ordinal);
foreach (var removed in oldInterfaces.Where(i => !newInterfaces.ContainsKey(i.Key)))
- changed("interfaces", ApiWriter.Reference(removed.Value, oldType), null, ApiAudience.Callers, Both, null);
+ changed("interfaces", Writer(oldType).Reference(removed.Value), null, ApiAudience.Callers, Both, null);
foreach (var added in newInterfaces.Where(i => !oldInterfaces.ContainsKey(i.Key)))
{
// an interface that extends another now asks its implementers for that one's members too
var breaks = newType.Kind == ApiTypeKind.Interface && AsksSomething(added.Value) ? ApiAudience.Implementers : ApiAudience.None;
- changed("interfaces", null, ApiWriter.Reference(added.Value, newType), breaks, breaks == ApiAudience.None ? ApiCompatibility.None : Both, null);
+ changed("interfaces", null, Writer(newType).Reference(added.Value), breaks, breaks == ApiAudience.None ? ApiCompatibility.None : Both, null);
}
}
@@ -258,6 +312,8 @@ private static void TypeParameters(
ApiCompatibility.Source,
null
);
+ if (SameConstraints(o, n))
+ continue;
var oldConstraints = Constraints(o, oldType);
var newConstraints = Constraints(n, newType);
foreach (var added in newConstraints.Except(oldConstraints))
@@ -267,6 +323,17 @@ private static void TypeParameters(
}
}
+ /// Whether two type parameters have the same constraints, checked on the models before anything is written out.
+ private static bool SameConstraints(ApiTypeParameter a, ApiTypeParameter b)
+ {
+ if (a.Constraints != b.Constraints || a.ConstraintTypes.Count != b.ConstraintTypes.Count)
+ return false;
+ for (var i = 0; i < a.ConstraintTypes.Count; i++)
+ if (!Same(a.ConstraintTypes[i], b.ConstraintTypes[i], Sameness.Exact))
+ return false;
+ return true;
+ }
+
private static string Variance(ApiVariance variance) => variance switch
{
ApiVariance.Out => "out",
@@ -294,7 +361,7 @@ private static List Constraints(ApiTypeParameter parameter, ApiType cont
ApiConstraints.New => "new()",
_ => flag.ToString().ToLowerInvariant(),
});
- constraints.AddRange(parameter.ConstraintTypes.Select(t => ApiWriter.Reference(t, context)));
+ constraints.AddRange(parameter.ConstraintTypes.Select(t => Writer(context).Reference(t)));
// allows ref struct loosens a constraint; taking it away is the break
if ((parameter.Constraints & ApiConstraints.AllowsRefStruct) == 0)
constraints.Add("not ref struct");
@@ -307,33 +374,24 @@ private void Member(ApiMember? oldMember, ApiMember? newMember, ApiType oldType,
{
var member = newMember ?? oldMember!;
var declaring = newMember is null ? oldType : newType;
- var here = delegateInvoke ? path : path.Append(MemberSegment(member, declaring)).ToList();
+ // the path is only written out for a change: most members have none
+ List? here = null;
+
+ List Here() => here ??= delegateInvoke ? path : path.Append(MemberSegment(member, declaring)).ToList();
if (oldMember is null)
{
var (breaks, compatibility, note) = Obligation(newMember!, newType);
- Add(
- here,
- ApiChangeKind.Added,
- "",
- null,
- ApiWriter.Declaration(newMember!, newType),
- breaks,
- compatibility,
- newType,
- newMember,
- newMember,
- note
- );
+ Add(Here(), ApiChangeKind.Added, "", null, Writer(newType).Declaration(newMember!), breaks, compatibility, newType, newMember, newMember, note);
return;
}
if (newMember is null)
{
- var removed = ApiWriter.Declaration(oldMember, oldType);
+ var removed = Writer(oldType).Declaration(oldMember);
// an override, or a member that moved to a base class here, is still found through the base
if (MovedToBase(oldMember, oldType, newType) is { } baseName)
Add(
- here,
+ Here(),
ApiChangeKind.Removed,
"",
removed,
@@ -354,7 +412,7 @@ private void Member(ApiMember? oldMember, ApiMember? newMember, ApiType oldType,
? "an overload with more optional parameters replaces it; callers compile, but compiled callers fail"
: null;
Add(
- here,
+ Here(),
ApiChangeKind.Removed,
"",
removed,
@@ -371,7 +429,7 @@ private void Member(ApiMember? oldMember, ApiMember? newMember, ApiType oldType,
}
void Changed(string part, string? old, string? @new, ApiAudience breaks, ApiCompatibility compatibility, string? note = null) =>
- Add(here, ApiChangeKind.Changed, part, old, @new, breaks, compatibility, oldType, oldMember, newMember, note);
+ Add(Here(), ApiChangeKind.Changed, part, old, @new, breaks, compatibility, oldType, oldMember, newMember, note);
Accessibility(
oldMember.Accessibility,
@@ -434,6 +492,8 @@ void Changed(string part, string? old, string? @new, ApiAudience breaks, ApiComp
);
for (var i = 0; i < Math.Min(o.TypeParameters.Count, n.TypeParameters.Count); i++)
{
+ if (SameConstraints(o.TypeParameters[i], n.TypeParameters[i]))
+ continue;
var oldConstraints = Constraints(o.TypeParameters[i], oldType);
var newConstraints = Constraints(n.TypeParameters[i], newType);
foreach (var added in newConstraints.Except(oldConstraints))
@@ -720,23 +780,107 @@ private static void TypeOf(
Action changed
)
{
- var oldText = ApiWriter.Reference(old, oldType);
- var newText = ApiWriter.Reference(@new, newType);
- if (Erase(old) != Erase(@new))
+ // nearly every type is unchanged: compare the models, and write the C# only for a change
+ if (Same(old, @new, Sameness.Exact))
+ return;
+ var oldText = Writer(oldType).Reference(old);
+ var newText = Writer(newType).Reference(@new);
+ if (!Same(old, @new, Sameness.Runtime))
changed(part, oldText, newText, ApiAudience.Callers, Both, null);
- else if (TupleNames(old) != TupleNames(@new))
+ else if (!Same(old, @new, Sameness.TupleNames))
changed(part, oldText, newText, ApiAudience.Callers, ApiCompatibility.Source, "callers that use the element names");
else if (oldText != newText)
changed(part, oldText, newText, ApiAudience.None, ApiCompatibility.None, "nullability");
}
- private static string TupleNames(ApiTypeReference type) => type switch
+ internal static bool SameRuntime(ApiTypeReference a, ApiTypeReference b) => Same(a, b, Sameness.Runtime);
+
+ private enum Sameness
{
- ApiTupleType tuple => "(" + string.Join(",", tuple.Elements.Select(e => e.Name + ":" + TupleNames(e.Type))) + ")",
- ApiNamedType named =>
- string.Join(",", named.TypeArguments.Select(TupleNames)) + (named.DeclaringType is null ? "" : "/" + TupleNames(named.DeclaringType)),
- ApiArrayType array => TupleNames(array.ElementType),
- _ => "",
+ /// The same type to the runtime: nullability, tuple names, dynamic and native integers aside.
+ Runtime,
+
+ /// The same to the runtime, with the same tuple element names.
+ TupleNames,
+
+ /// The same in every part, nullability included.
+ Exact,
+ }
+
+ /// Whether two types are the same, as far as looks, without writing either out.
+ private static bool Same(ApiTypeReference a, ApiTypeReference b, Sameness sameness)
+ {
+ while (a is ApiModifiedType modifiedA && sameness != Sameness.Exact)
+ a = modifiedA.Type;
+ while (b is ApiModifiedType modifiedB && sameness != Sameness.Exact)
+ b = modifiedB.Type;
+ if (sameness == Sameness.Exact && a.IsNullable != b.IsNullable)
+ return false;
+ if (sameness != Sameness.Exact)
+ {
+ // dynamic is object, and nint IntPtr, to the runtime
+ a = Runtime(a);
+ b = Runtime(b);
+ }
+ switch (a, b)
+ {
+ case (ApiNamedType x, ApiNamedType y):
+ if (x.Name != y.Name || x.Namespace != y.Namespace || x.TypeArguments.Count != y.TypeArguments.Count)
+ return false;
+ if (
+ (x.DeclaringType is null) != (y.DeclaringType is null) ||
+ (x.DeclaringType is not null && !Same(x.DeclaringType, y.DeclaringType!, sameness))
+ )
+ return false;
+ for (var i = 0; i < x.TypeArguments.Count; i++)
+ if (!Same(x.TypeArguments[i], y.TypeArguments[i], sameness))
+ return false;
+ return true;
+ case (ApiTupleType x, ApiTupleType y):
+ if (x.Elements.Count != y.Elements.Count)
+ return false;
+ for (var i = 0; i < x.Elements.Count; i++)
+ if (
+ (sameness != Sameness.Runtime && x.Elements[i].Name != y.Elements[i].Name) ||
+ !Same(x.Elements[i].Type, y.Elements[i].Type, sameness)
+ )
+ return false;
+ return true;
+ case (ApiArrayType x, ApiArrayType y):
+ return x.Rank == y.Rank && Same(x.ElementType, y.ElementType, sameness);
+ case (ApiPointerType x, ApiPointerType y):
+ return Same(x.ElementType, y.ElementType, sameness);
+ case (ApiFunctionPointerType x, ApiFunctionPointerType y):
+ if (x.IsUnmanaged != y.IsUnmanaged || x.ParameterTypes.Count != y.ParameterTypes.Count || !Same(x.ReturnType, y.ReturnType, sameness))
+ return false;
+ for (var i = 0; i < x.ParameterTypes.Count; i++)
+ if (!Same(x.ParameterTypes[i], y.ParameterTypes[i], sameness))
+ return false;
+ return true;
+ case (ApiTypeParameterReference x, ApiTypeParameterReference y):
+ return x.Name == y.Name && x.IsMethodParameter == y.IsMethodParameter;
+ case (ApiDynamicType, ApiDynamicType):
+ return true;
+ case (ApiNativeIntegerType x, ApiNativeIntegerType y):
+ return x.IsUnsigned == y.IsUnsigned;
+ case (ApiModifiedType x, ApiModifiedType y):
+ return x.IsRequired == y.IsRequired && Same(x.Modifier, y.Modifier, sameness) && Same(x.Type, y.Type, sameness);
+ default:
+ return false;
+ }
+ }
+
+ private static readonly ApiNamedType RuntimeObject = new("System", "Object", null, [], false);
+ private static readonly ApiNamedType RuntimeIntPtr = new("System", "IntPtr", null, [], true);
+ private static readonly ApiNamedType RuntimeUIntPtr = new("System", "UIntPtr", null, [], true);
+
+ private static ApiTypeReference Runtime(ApiTypeReference type) => type switch
+ {
+ ApiDynamicType => RuntimeObject,
+ ApiNativeIntegerType { IsUnsigned: true } => RuntimeUIntPtr,
+ ApiNativeIntegerType => RuntimeIntPtr,
+ // a tuple is its ValueTuple; Same compares tuples element by element, which is the same thing
+ _ => type,
};
private static void Accessibility(ApiAccessibility old, ApiAccessibility @new, Action changed)
@@ -798,6 +942,9 @@ private static void Attributes(
Action changed
)
{
+ // the reader and the parser both order attributes, so unchanged ones are equal in order
+ if (old.Count == @new.Count && SameAttributes(old, @new))
+ return;
var oldByName = old.GroupBy(a => a.Type.FullName).ToDictionary(g => g.Key, g => g.Select(Text).OrderBy(t => t, StringComparer.Ordinal).ToList());
var newByName = @new.GroupBy(a => a.Type.FullName).ToDictionary(g => g.Key, g => g.Select(Text).OrderBy(t => t, StringComparer.Ordinal).ToList());
foreach (var name in oldByName.Keys.Union(newByName.Keys).OrderBy(n => n, StringComparer.Ordinal))
@@ -811,6 +958,20 @@ private static void Attributes(
}
}
+ private static bool SameAttributes(IReadOnlyList old, IReadOnlyList @new)
+ {
+ for (var i = 0; i < old.Count; i++)
+ {
+ var (a, b) = (old[i], @new[i]);
+ if (!Same(a.Type, b.Type, Sameness.Exact) || a.Arguments.Count != b.Arguments.Count)
+ return false;
+ for (var j = 0; j < a.Arguments.Count; j++)
+ if (a.Arguments[j] != b.Arguments[j])
+ return false;
+ }
+ return true;
+ }
+
private static bool IsError(IReadOnlyList attributes) =>
attributes.Any(a => a.Type.FullName == Obsolete && a.Arguments.Count >= 2 && a.Arguments[1] == "true");
@@ -953,15 +1114,14 @@ private static string MemberSegment(ApiMember member, ApiType declaring)
{
// a path names a member by its identity, which nullability is not part of: either version gives the same one
string Types(IEnumerable parameters) =>
- string.Join(", ", parameters.Select(p => ApiWriter.Reference(WithoutAnnotations(p.Type), declaring)));
+ string.Join(", ", parameters.Select(p => Writer(declaring).Reference(WithoutAnnotations(p.Type))));
return member switch
{
ApiMethod { Kind: ApiMethodKind.Constructor } m => NonGeneric(declaring.Name) + "(" + Types(m.Parameters) + ")",
ApiMethod { Kind: ApiMethodKind.Conversion } m =>
- (m.Name == "op_Implicit" ? "implicit" : "explicit") + " operator " + ApiWriter.Reference(m.ReturnType, declaring) + "(" + Types(
- m.Parameters
- ) + ")",
+ (m.Name == "op_Implicit" ? "implicit" : "explicit") + " operator " + Writer(declaring).Reference(m.ReturnType) + "(" + Types(m.Parameters) +
+ ")",
ApiMethod m =>
m.Name + (m.TypeParameters.Count == 0 ? "" : "<" + string.Join(", ", m.TypeParameters.Select(p => p.Name)) + ">") + "(" + Types(
m.Parameters
diff --git a/src/Nullean.PublicApi/ApiParser.cs b/src/Nullean.PublicApi/ApiParser.cs
index c7c821b..59cc6a2 100644
--- a/src/Nullean.PublicApi/ApiParser.cs
+++ b/src/Nullean.PublicApi/ApiParser.cs
@@ -31,19 +31,42 @@ public sealed record ApiLocation(string? File, int Line);
/// Parsed .api files: the API they describe, and where each type and member is declared.
public sealed class ApiDocument
{
- private readonly ConditionalWeakTable