Skip to content

Commit 74086ac

Browse files
authored
Addressing code review suggestions (#1975)
* remove redundant ctor * use rootAllApplicationAssemblies to determine whether TrimmerDefaultAction should be set to link or not * set TrimMode to link in explicit way as for older versions it might have different default value * remove NativeAot50, nobody should be using it
1 parent a578194 commit 74086ac

File tree

11 files changed

+23
-67
lines changed

11 files changed

+23
-67
lines changed

src/BenchmarkDotNet.Annotations/Attributes/GenericTypeArgumentsAttribute.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using JetBrains.Annotations;
2-
using System;
1+
using System;
32
using System.Diagnostics.CodeAnalysis;
43

54
namespace BenchmarkDotNet.Attributes
@@ -9,9 +8,6 @@ public class GenericTypeArgumentsAttribute : Attribute
98
{
109
public Type[] GenericTypeArguments { get; }
1110

12-
// CLS-Compliant Code requires a constructor without an array in the argument list
13-
[PublicAPI] public GenericTypeArgumentsAttribute() => GenericTypeArguments = new Type[0];
14-
1511
public GenericTypeArgumentsAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
1612
=> GenericTypeArguments = new Type[] { type };
1713

src/BenchmarkDotNet.Annotations/Jobs/RuntimeMoniker.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ public enum RuntimeMoniker
9595
/// </summary>
9696
Net70,
9797

98-
/// <summary>
99-
/// NativeAOT compiled as net5.0
100-
/// </summary>
101-
NativeAot50,
102-
10398
/// <summary>
10499
/// NativeAOT compiled as net6.0
105100
/// </summary>

src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ private static Job CreateJobForGivenRuntime(Job baseJob, string runtimeId, Comma
363363
.WithToolchain(CsProjCoreToolchain.From(new NetCoreAppSettings(runtimeId, null, runtimeId, options.CliPath?.FullName, options.RestorePath?.FullName)));
364364
case RuntimeMoniker.Mono:
365365
return baseJob.WithRuntime(new MonoRuntime("Mono", options.MonoPath?.FullName));
366-
case RuntimeMoniker.NativeAot50:
367366
case RuntimeMoniker.NativeAot60:
368367
return CreateAotJob(baseJob, options, runtimeMoniker, "6.0.0-*", "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json");
369368
case RuntimeMoniker.NativeAot70:

src/BenchmarkDotNet/Environments/Runtimes/NativeAotRuntime.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ namespace BenchmarkDotNet.Environments
66
{
77
public class NativeAotRuntime : Runtime
88
{
9-
/// <summary>
10-
/// NativeAOT compiled as net5.0
11-
/// </summary>
12-
public static readonly NativeAotRuntime Net50 = new NativeAotRuntime(RuntimeMoniker.NativeAot50, "net5.0", "NativeAOT 5.0");
139
/// <summary>
1410
/// NativeAOT compiled as net6.0
1511
/// </summary>
@@ -40,7 +36,6 @@ public static NativeAotRuntime GetCurrentVersion()
4036

4137
switch (version)
4238
{
43-
case Version v when v.Major == 5 && v.Minor == 0: return Net50;
4439
case Version v when v.Major == 6 && v.Minor == 0: return Net60;
4540
case Version v when v.Major == 7 && v.Minor == 0: return Net70;
4641
default:

src/BenchmarkDotNet/Extensions/RuntimeMonikerExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ internal static Runtime GetRuntime(this RuntimeMoniker runtimeMoniker)
4343
return CoreRuntime.Core70;
4444
case RuntimeMoniker.Mono:
4545
return MonoRuntime.Default;
46-
case RuntimeMoniker.NativeAot50:
47-
return NativeAotRuntime.Net50;
4846
case RuntimeMoniker.NativeAot60:
4947
return NativeAotRuntime.Net60;
5048
case RuntimeMoniker.NativeAot70:

src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal Generator(string ilCompilerVersion,
2626
string runtimeFrameworkVersion, string targetFrameworkMoniker, string cliPath,
2727
string runtimeIdentifier, IReadOnlyDictionary<string, string> feeds, bool useNuGetClearTag,
2828
bool useTempFolderForRestore, string packagesRestorePath,
29-
bool rootAllApplicationAssemblies, bool ilcGenerateCompleteTypeMetadata, bool ilcGenerateStackTraceData, string trimmerDefaultAction)
29+
bool rootAllApplicationAssemblies, bool ilcGenerateCompleteTypeMetadata, bool ilcGenerateStackTraceData)
3030
: base(targetFrameworkMoniker, cliPath, GetPackagesDirectoryPath(useTempFolderForRestore, packagesRestorePath), runtimeFrameworkVersion)
3131
{
3232
this.ilCompilerVersion = ilCompilerVersion;
@@ -38,7 +38,6 @@ internal Generator(string ilCompilerVersion,
3838
this.rootAllApplicationAssemblies = rootAllApplicationAssemblies;
3939
this.ilcGenerateCompleteTypeMetadata = ilcGenerateCompleteTypeMetadata;
4040
this.ilcGenerateStackTraceData = ilcGenerateStackTraceData;
41-
this.trimmerDefaultAction = trimmerDefaultAction;
4241
}
4342

4443
private readonly string ilCompilerVersion;
@@ -51,7 +50,6 @@ internal Generator(string ilCompilerVersion,
5150
private readonly bool rootAllApplicationAssemblies;
5251
private readonly bool ilcGenerateCompleteTypeMetadata;
5352
private readonly bool ilcGenerateStackTraceData;
54-
private readonly string trimmerDefaultAction;
5553

5654
private bool IsNuGet => feeds.ContainsKey(NativeAotNuGetFeed) && !string.IsNullOrWhiteSpace(ilCompilerVersion);
5755

@@ -189,24 +187,17 @@ private string GenerateProjectForLocalBuild(BuildPartition buildPartition, Artif
189187
</Project>";
190188

191189
private string GetTrimmingSettings()
192-
{
193-
StringBuilder sb = new StringBuilder();
194-
195-
sb.AppendLine(rootAllApplicationAssemblies ? "<PublishTrimmed>false</PublishTrimmed>" : "<TrimMode>link</TrimMode>");
196-
197-
if (!string.IsNullOrEmpty(trimmerDefaultAction))
198-
{
199-
sb.Append($"<TrimmerDefaultAction>{trimmerDefaultAction}</TrimmerDefaultAction>");
200-
}
201-
202-
return sb.ToString();
203-
}
190+
=> rootAllApplicationAssemblies
191+
? "" // use the defaults
192+
// TrimMode is set in explicit way as for older versions it might have different default value
193+
: "<TrimMode>link</TrimMode><TrimmerDefaultAction>link</TrimmerDefaultAction>";
204194

205195
public IEnumerable<string> GetRdXmlFiles(Type benchmarkTarget, ILogger logger)
206196
{
197+
yield return GeneratedRdXmlFileName;
198+
207199
var projectFile = GetProjectFilePath(benchmarkTarget, logger);
208200
var projectFileFolder = projectFile.DirectoryName;
209-
yield return GeneratedRdXmlFileName;
210201
var rdXml = Path.Combine(projectFileFolder, "rd.xml");
211202
if (File.Exists(rdXml))
212203
{

src/BenchmarkDotNet/Toolchains/NativeAot/NativeAotToolchain.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,32 @@ namespace BenchmarkDotNet.Toolchains.NativeAot
77
{
88
public class NativeAotToolchain : Toolchain
99
{
10-
/// <summary>
11-
/// compiled as net5.0, targets experimental 6.0.0-* NativeAOT build from the https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json
12-
/// </summary>
13-
public static readonly IToolchain Net50 = GetBuilderForOldExperimentalFeed().TargetFrameworkMoniker("net5.0").ToToolchain();
1410
/// <summary>
1511
/// compiled as net6.0, targets experimental 6.0.0-* NativeAOT build from the https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json
1612
/// </summary>
17-
public static readonly IToolchain Net60 = GetBuilderForOldExperimentalFeed().TargetFrameworkMoniker("net6.0").ToToolchain();
13+
public static readonly IToolchain Net60 = CreateBuilder()
14+
.UseNuGet("6.0.0-*", "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json")
15+
.TargetFrameworkMoniker("net6.0")
16+
.ToToolchain();
17+
1818
/// <summary>
1919
/// compiled as net7.0, targets latest (7.0.0-*) NativeAOT build from the .NET 7 feed: https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json
2020
/// </summary>
21-
public static readonly IToolchain Net70 = CreateBuilder().UseNuGet().TargetFrameworkMoniker("net7.0").ToToolchain();
22-
23-
private static NativeAotToolchainBuilder GetBuilderForOldExperimentalFeed()
24-
=> CreateBuilder().UseNuGet("6.0.0-*", "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json");
21+
public static readonly IToolchain Net70 = CreateBuilder()
22+
.UseNuGet("7.0.0-*", "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json")
23+
.TargetFrameworkMoniker("net7.0")
24+
.ToToolchain();
2525

2626
internal NativeAotToolchain(string displayName,
2727
string ilCompilerVersion, string ilcPath,
2828
string runtimeFrameworkVersion, string targetFrameworkMoniker, string runtimeIdentifier,
2929
string customDotNetCliPath, string packagesRestorePath,
3030
Dictionary<string, string> feeds, bool useNuGetClearTag, bool useTempFolderForRestore,
31-
bool rootAllApplicationAssemblies, bool ilcGenerateCompleteTypeMetadata, bool ilcGenerateStackTraceData, string trimmerDefaultAction)
31+
bool rootAllApplicationAssemblies, bool ilcGenerateCompleteTypeMetadata, bool ilcGenerateStackTraceData)
3232
: base(displayName,
3333
new Generator(ilCompilerVersion, runtimeFrameworkVersion, targetFrameworkMoniker, customDotNetCliPath,
3434
runtimeIdentifier, feeds, useNuGetClearTag, useTempFolderForRestore, packagesRestorePath,
35-
rootAllApplicationAssemblies, ilcGenerateCompleteTypeMetadata, ilcGenerateStackTraceData, trimmerDefaultAction),
35+
rootAllApplicationAssemblies, ilcGenerateCompleteTypeMetadata, ilcGenerateStackTraceData),
3636
new DotNetCliPublisher(customDotNetCliPath, GetExtraArguments(runtimeIdentifier), GetEnvironmentVariables(ilcPath)),
3737
new Executor())
3838
{
@@ -43,8 +43,7 @@ internal NativeAotToolchain(string displayName,
4343

4444
public static NativeAotToolchainBuilder CreateBuilder() => NativeAotToolchainBuilder.Create();
4545

46-
public static string GetExtraArguments(string runtimeIdentifier)
47-
=> $"-r {runtimeIdentifier}";
46+
public static string GetExtraArguments(string runtimeIdentifier) => $"-r {runtimeIdentifier}";
4847

4948
// https://github.com/dotnet/corert/blob/7f902d4d8b1c3280e60f5e06c71951a60da173fb/Documentation/how-to-build-and-run-ilcompiler-in-console-shell-prompt.md#compiling-source-to-native-code-using-the-ilcompiler-you-built
5049
// we have to pass IlcPath env var to get it working

src/BenchmarkDotNet/Toolchains/NativeAot/NativeAotToolchainBuilder.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public class NativeAotToolchainBuilder : CustomDotNetCliToolchainBuilder
1919
private bool ilcGenerateStackTraceData = true;
2020

2121
private bool isIlCompilerConfigured;
22-
private string trimmerDefaultAction = "link";
2322

2423
/// <summary>
2524
/// creates a NativeAOT toolchain targeting NuGet build of Microsoft.DotNet.ILCompiler
@@ -111,19 +110,6 @@ public NativeAotToolchainBuilder IlcGenerateStackTraceData(bool value)
111110
return this;
112111
}
113112

114-
/// <summary>
115-
/// By using the default value ("link") this ensures that the trimmer only analyzes the parts of the library's dependencies that are used.
116-
/// It tells the trimmer that any code that is not part of a "root" can be trimmed if it is unused.
117-
/// </summary>
118-
/// <remarks>Pass null or empty string to NOT set TrimmerDefaultAction to any value.</remarks>
119-
[PublicAPI]
120-
public NativeAotToolchainBuilder SeTrimmerDefaultAction(string value = "link")
121-
{
122-
trimmerDefaultAction = value;
123-
124-
return this;
125-
}
126-
127113
[PublicAPI]
128114
public override IToolchain ToToolchain()
129115
{
@@ -144,8 +130,7 @@ public override IToolchain ToToolchain()
144130
useTempFolderForRestore: useTempFolderForRestore,
145131
rootAllApplicationAssemblies: rootAllApplicationAssemblies,
146132
ilcGenerateCompleteTypeMetadata: ilcGenerateCompleteTypeMetadata,
147-
ilcGenerateStackTraceData: ilcGenerateStackTraceData,
148-
trimmerDefaultAction: trimmerDefaultAction
133+
ilcGenerateStackTraceData: ilcGenerateStackTraceData
149134
);
150135
}
151136
}

src/BenchmarkDotNet/Toolchains/ToolchainExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ private static IToolchain GetToolchain(RuntimeMoniker runtimeMoniker)
108108
return CsProjCoreToolchain.NetCoreApp60;
109109
case RuntimeMoniker.Net70:
110110
return CsProjCoreToolchain.NetCoreApp70;
111-
case RuntimeMoniker.NativeAot50:
112-
return NativeAotToolchain.Net50;
113111
case RuntimeMoniker.NativeAot60:
114112
return NativeAotToolchain.Net60;
115113
case RuntimeMoniker.NativeAot70:

tests/BenchmarkDotNet.IntegrationTests/BuildTimeoutTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void WhenBuildTakesMoreTimeThanTheTimeoutTheBuildIsCancelled()
2929
var config = ManualConfig.CreateEmpty()
3030
.WithBuildTimeout(timeout)
3131
.AddJob(Job.Dry
32-
.WithRuntime(NativeAotRuntime.Net50)
32+
.WithRuntime(NativeAotRuntime.Net60)
3333
.WithToolchain(NativeAotToolchain.CreateBuilder()
3434
.UseNuGet(
3535
"6.0.0-rc.1.21420.1", // we test against specific version to keep this test stable

0 commit comments

Comments
 (0)