From f6633ac6fba9a4129ec9b87f27b8f1a8ec7aa406 Mon Sep 17 00:00:00 2001 From: Luca Del Re Date: Wed, 17 Sep 2025 20:32:01 +0200 Subject: [PATCH 1/2] Add flaky test for inferred length in doc string The parameter used for inferring the length is not deterministic because of the non-determinism of hash set. This leads to changing logic between builds, shown by this flaky test. --- MKL.NET.WrapperGenerator.Tests/GeneratorTest.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MKL.NET.WrapperGenerator.Tests/GeneratorTest.cs b/MKL.NET.WrapperGenerator.Tests/GeneratorTest.cs index 65f9611..1bb073b 100644 --- a/MKL.NET.WrapperGenerator.Tests/GeneratorTest.cs +++ b/MKL.NET.WrapperGenerator.Tests/GeneratorTest.cs @@ -49,7 +49,10 @@ public static unsafe extern void dummy(int M, int N, generatorResult.Generator.Should().BeSameAs(generator); generatorResult.Diagnostics.Should().BeEmpty(); - generatorResult.GeneratedSources.Should().HaveCount(1); + generatorResult.GeneratedSources.Should().ContainSingle() + .Which.SourceText.ToString().Should().Contain( + "///" + + "This version infers the length parameter N from 's length."); generatorResult.Exception.Should().BeNull(); } From 73cfad01f1de9f13b723891da427f6c71d08efae Mon Sep 17 00:00:00 2001 From: Luca Del Re Date: Wed, 17 Sep 2025 20:38:01 +0200 Subject: [PATCH 2/2] Switch to deterministic parameter Use the first parameter for inferring the length as intended by the code --- MKL.NET.WrapperGenerator/WrapperGenerator.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MKL.NET.WrapperGenerator/WrapperGenerator.cs b/MKL.NET.WrapperGenerator/WrapperGenerator.cs index 0528cd7..9627c7c 100644 --- a/MKL.NET.WrapperGenerator/WrapperGenerator.cs +++ b/MKL.NET.WrapperGenerator/WrapperGenerator.cs @@ -36,10 +36,10 @@ public void Initialize(GeneratorInitializationContext context) return candidates[0]; } - private static (ISet changed, ParameterListSyntax newList) + private static (IList changed, ParameterListSyntax newList) TransformParameters(MethodDeclarationSyntax mds, Func f) { - var changed = mds.ParameterList.Parameters.Select(ps => f(ps) is null ? null : ps).Where(ps => ps != null).ToImmutableHashSet(); + var changed = mds.ParameterList.Parameters.Select(ps => f(ps) is null ? null : ps).Where(ps => ps != null).ToImmutableList(); var newList = SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(mds.ParameterList.Parameters.Select(ps => f(ps) ?? ps))); return (changed!, newList); @@ -57,7 +57,7 @@ private enum AdditionalTransformation void WriterTransformedMethod( MethodDeclarationSyntax mds, ClassDeclarationSyntax nativeCds, - (ISet changed, ParameterListSyntax newList) transformation, StringBuilder sb, + (IList changed, ParameterListSyntax newList) transformation, StringBuilder sb, AdditionalTransformation trafo) { (ParameterSyntax lengthParam, string takeLengthFrom)? lengthOptions = null;