Skip to content

Commit 3f972df

Browse files
author
Julien Couvreur
committed
Simplify
1 parent e4530d3 commit 3f972df

File tree

3 files changed

+36
-62
lines changed

3 files changed

+36
-62
lines changed

src/Compilers/Core/Portable/Compilation/DeterministicKey.cs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -62,44 +62,11 @@ public static string GetDeterministicKey(
6262
ImmutableArray<ResourceDescription> resources = default,
6363
DeterministicKeyOptions options = DeterministicKeyOptions.Default,
6464
CancellationToken cancellationToken = default)
65-
{
66-
return GetDeterministicKey(
67-
compilationOptions,
68-
syntaxTrees.SelectAsArray(static t => SyntaxTreeKey.Create(t)),
69-
references,
70-
publicKey,
71-
additionalTexts,
72-
analyzers,
73-
generators,
74-
pathMap,
75-
emitOptions,
76-
sourceLinkText,
77-
ruleSetFilePath,
78-
resources,
79-
options,
80-
cancellationToken);
81-
}
82-
83-
public static string GetDeterministicKey(
84-
CompilationOptions compilationOptions,
85-
ImmutableArray<SyntaxTreeKey> syntaxTrees,
86-
ImmutableArray<MetadataReference> references,
87-
ImmutableArray<byte> publicKey,
88-
ImmutableArray<AdditionalText> additionalTexts = default,
89-
ImmutableArray<DiagnosticAnalyzer> analyzers = default,
90-
ImmutableArray<ISourceGenerator> generators = default,
91-
ImmutableArray<KeyValuePair<string, string>> pathMap = default,
92-
EmitOptions? emitOptions = null,
93-
SourceText? sourceLinkText = null,
94-
string? ruleSetFilePath = null,
95-
ImmutableArray<ResourceDescription> resources = default,
96-
DeterministicKeyOptions options = DeterministicKeyOptions.Default,
97-
CancellationToken cancellationToken = default)
9865
{
9966
var keyBuilder = compilationOptions.CreateDeterministicKeyBuilder();
10067
return keyBuilder.GetKey(
10168
compilationOptions,
102-
syntaxTrees,
69+
syntaxTrees.SelectAsArray(static t => SyntaxTreeKey.Create(t)),
10370
references,
10471
publicKey,
10572
additionalTexts,

src/Compilers/Core/Portable/Compilation/DeterministicKeyBuilder.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Collections.Immutable;
8-
using System.Globalization;
8+
using System.Diagnostics;
99
using System.IO;
1010
using System.Linq;
1111
using System.Reflection;
@@ -153,6 +153,10 @@ internal string GetKey(
153153
DeterministicKeyOptions options,
154154
CancellationToken cancellationToken)
155155
{
156+
Debug.Assert(!syntaxTrees.IsDefault);
157+
Debug.Assert(!references.IsDefault);
158+
Debug.Assert(!publicKey.IsDefault);
159+
156160
additionalTexts = additionalTexts.NullToEmpty();
157161
analyzers = analyzers.NullToEmpty();
158162
generators = generators.NullToEmpty();

src/Compilers/Core/RebuildTest/CSharpDeterministicKeyBuilderTests.cs

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,12 @@ public void SourceLink()
599599
var compilation = CSharpTestBase.CreateCompilation(syntaxTree, options: Options);
600600

601601
var sourceLinkContent = """
602-
{
603-
"documents": {
604-
"/*": "https://raw.githubusercontent.com/test/repo/*"
605-
}
606-
}
607-
""";
602+
{
603+
"documents": {
604+
"/*": "https://raw.githubusercontent.com/test/repo/*"
605+
}
606+
}
607+
""";
608608
var sourceLinkText = SourceText.From(sourceLinkContent, Encoding.UTF8, SourceHashAlgorithm.Sha256);
609609
var sourceLinkChecksum = GetChecksum(sourceLinkText);
610610

@@ -614,12 +614,13 @@ public void SourceLink()
614614
sourceLinkText: sourceLinkText,
615615
options: DeterministicKeyOptions.IgnoreToolVersions);
616616

617-
var expected = $@"
618-
""sourceLink"": {{
619-
""checksum"": ""{sourceLinkChecksum}"",
620-
""checksumAlgorithm"": ""Sha256"",
621-
""encodingName"": ""Unicode (UTF-8)""
622-
}}";
617+
var expected = $$"""
618+
"sourceLink": {
619+
"checksum": "{{sourceLinkChecksum}}",
620+
"checksumAlgorithm": "Sha256",
621+
"encodingName": "Unicode (UTF-8)"
622+
}
623+
""";
623624
AssertJsonSection(expected, key, "emitOptions.sourceLink");
624625
}
625626

@@ -637,8 +638,9 @@ public void RuleSet()
637638
ruleSetFilePath: ruleSetPath,
638639
options: DeterministicKeyOptions.IgnoreToolVersions);
639640

640-
var expected = @$"
641-
""ruleSetPath"": ""{ruleSetPath}""";
641+
var expected = $"""
642+
"ruleSetPath": "{ruleSetPath}"
643+
""";
642644
AssertJsonSection(expected, key, "compilation.options.ruleSetPath");
643645
}
644646

@@ -666,21 +668,22 @@ public void Resources()
666668
isPublic: true);
667669

668670
var key = compilation.GetDeterministicKey(
669-
resources: ImmutableArray.Create(resource),
671+
resources: [resource],
670672
options: DeterministicKeyOptions.IgnoreToolVersions);
671673

672-
var expected = $@"
673-
""resources"": [
674-
{{
675-
""resourceName"": ""TestResource"",
676-
""fileName"": null,
677-
""isPublic"": true,
678-
""isEmbedded"": true,
679-
""content"": {{
680-
""checksum"": ""{resourceChecksum}""
681-
}}
682-
}}
683-
]";
674+
var expected = $$"""
675+
"resources": [
676+
{
677+
"resourceName": "TestResource",
678+
"fileName": null,
679+
"isPublic": true,
680+
"isEmbedded": true,
681+
"content": {
682+
"checksum": "{{resourceChecksum}}"
683+
}
684+
}
685+
]
686+
""";
684687
AssertJsonSection(expected, key, "resources");
685688
}
686689
}

0 commit comments

Comments
 (0)