-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Description
The ordering of source code generated by LoggerMessageGenerator is unstable, leading to non-deterministic builds.
Reproduction Steps
Reproduction repo: https://github.com/omsmith/UnstableLoggerMessageGenerator
Workflow run showing the output changes between builds: https://github.com/omsmith/UnstableLoggerMessageGenerator/actions/runs/17649313698/job/50155741046
Expected behavior
I would expect the generator to produce stable, consistent, output in order to contribute to a deterministic build output.
Actual behavior
Generated output varies between generator runs:
diff --git a/sums1 b/sums2
index c57fc00..7212393 100644
--- a/sums1
+++ b/sums2
@@ -1,4 +1,4 @@
-0cbf1d2ffda033884441cff20838d1297f1ea7a3bc7e4170a7cfe59a68b6515d generated/Microsoft.Extensions.Logging.Generators/Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator/LoggerMessage.g.cs
+81ce9fd64ffb27eeb2091027a9c5f881d3e94444ef5bec144e79381b069ff65c generated/Microsoft.Extensions.Logging.Generators/Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator/LoggerMessage.g.cs
2b32257e1f1322ba7aff78f09fa4b07ee6c30bc0fd1ab714fd18326ad10750e7 published/Consumer.deps.json
ceea04c4d35fa3f007b87d2d91ec96fbc03f8b22e36d71c49dbb51f9d5bc1357 published/Consumer.dll
e4bb0c3c38a7e35488b9775938096c158e393ddc416ad61b254370e9417aaf68 published/Consumer.pdb
@@ -6,5 +6,5 @@ e4bb0c3c38a7e35488b9775938096c158e393ddc416ad61b254370e9417aaf68 published/Cons
622cf6cafd1d5a402c12574515dfaab8ce99018a8b1d324045487ed7a5dfbb62 published/Microsoft.Extensions.Logging.Abstractions.dll
84cbe6b2d711d9634cdea73c5614d43f11d569a2de0df5dd48f2ac26980993ca published/StableDep.dll
a86eb98c5ed0f9b41e431ef6d7620f0031c2b6bd649f21f3e89c411d9dd69d92 published/StableDep.pdb
-d748fbfd0a99b86cbc8b875147c3316a3a76b6c5a3c7c9365363e62a5077c286 published/UnstableDep.dll
-dec237d698d2f25329fda3321d6595fe82b2165921256911059111779972a548 published/UnstableDep.pdb
+4e41796882705baa91f0d855700d6234e4b1cb377c0e1ad6a8611664cf5a5374 published/UnstableDep.dll
+fb1e5ab124a6a13e9b941c7caa05eb3ae3f0b1d06d2af8debcac6e4709e0e99c published/UnstableDep.pdbdiff --git a/generated1/Microsoft.Extensions.Logging.Generators/Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator/LoggerMessage.g.cs b/generated2/Microsoft.Extensions.Logging.Generators/Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator/LoggerMessage.g.cs
index 72cea2c..4f4dc0a 100644
--- a/generated1/Microsoft.Extensions.Logging.Generators/Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator/LoggerMessage.g.cs
+++ b/generated2/Microsoft.Extensions.Logging.Generators/Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator/LoggerMessage.g.cs
@@ -3,7 +3,7 @@
namespace UnstableDep
{
- partial class X
+ partial class Z
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "9.0.12.41916")]
private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, global::System.Exception?> __LogFooCallback =
@@ -21,7 +21,7 @@ namespace UnstableDep
}
namespace UnstableDep
{
- partial class Z
+ partial class R
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "9.0.12.41916")]
private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, global::System.Exception?> __LogFooCallback =
@@ -39,7 +39,7 @@ namespace UnstableDep
}
namespace UnstableDep
{
- partial class R
+ partial class P
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "9.0.12.41916")]
private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, global::System.Exception?> __LogFooCallback =
@@ -57,7 +57,7 @@ namespace UnstableDep
}
namespace UnstableDep
{
- partial class P
+ partial class Y
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "9.0.12.41916")]
private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, global::System.Exception?> __LogFooCallback =
@@ -93,7 +93,7 @@ namespace UnstableDep
}
namespace UnstableDep
{
- partial class Y
+ partial class X
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "9.0.12.41916")]
private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, global::System.Exception?> __LogFooCallback =Regression?
No response
Known Workarounds
No response
Configuration
SDK 9.0.304
ubuntu-24.04
Microsoft.Extensions.Logging.Abstractions 9.0.9
Other information
A straight-forward solution should be to order the GetLogClasses results list by their full class name:
runtime/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs
Line 601 in 3823740
| return results; |
Similar to JsonSourceGenerator:
| GeneratedTypes = _generatedTypes.Values.OrderBy(t => t.TypeRef.FullyQualifiedName).ToImmutableEquatableArray(), |