Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/BenchmarkDotNet.Build/Runners/BuildRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void BuildAnalyzers()
context.Information("BuildSystemProvider: " + context.BuildSystem().Provider);
// Each band must restore as well as build: the PackageReference is chosen by MccVersion, so reusing the
// default band's project.assets.json silently compiles every band against the default's Roslyn.
string[] mccVersions = ["2.8", "3.0", "3.8", "4.4", "4.8", "4.12"];
string[] mccVersions = ["4.0", "4.4", "4.8", "4.12"];
foreach (string version in mccVersions)
{
context.DotNetBuild(context.AnalyzersProjectFile.FullPath, new DotNetBuildSettings
Expand Down
9 changes: 4 additions & 5 deletions build/roslynBands.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
<OutputPath>bin\$(Configuration)\roslyn$(MccVersion)\cs</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<!-- We multi-target for different compiler versions. https://github.com/dotnet/roslyn/discussions/81256#discussioncomment-14975130, https://github.com/dotnet/roslyn/blob/main/docs/wiki/NuGet-packages.md#versioning -->
<!-- C# 7.3/Roslyn 2.8 is our baseline (min version we support) -->
<!-- ITypeSymbol.IsRefLikeType -->
<DefineConstants Condition="$([MSBuild]::VersionGreaterThanOrEquals('$(MccVersion)', '3.0'))">$(DefineConstants);CODE_ANALYSIS_3_0</DefineConstants>
<!-- C# 9 -->
<DefineConstants Condition="$([MSBuild]::VersionGreaterThanOrEquals('$(MccVersion)', '3.8'))">$(DefineConstants);CODE_ANALYSIS_3_8</DefineConstants>
<!-- Roslyn 4.0 (VS 2022 RTM, .NET SDK 6) is the lowest band: picking a version-specific analyzer folder at all
requires that tooling, so a lower band could only ever be selected by a compiler that cannot select. The
lowest band is the fallback for every supported compiler below the next one up, so it needs no successor
below it. Older hosts are handed no analyzer at all - see BenchmarkDotNet.Annotations.targets. -->
<!-- C# 11 -->
<DefineConstants Condition="$([MSBuild]::VersionGreaterThanOrEquals('$(MccVersion)', '4.4'))">$(DefineConstants);CODE_ANALYSIS_4_4</DefineConstants>
<!-- C# 12 -->
Expand Down
15 changes: 3 additions & 12 deletions src/BenchmarkDotNet.Analyzers/AnalyzerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,31 +148,22 @@ public static bool MayBeRefLike(ITypeSymbol type)
return true;
}
#endif
return IsRefLikeType(type);
return type.IsRefLikeType;
}

// ref structs are C# 7.2, but no public symbol carries IsRefLikeType until Roslyn 3.0; the oldest band reads
// the internal property behind it instead.
private static bool IsRefLikeType(ITypeSymbol type)
#if CODE_ANALYSIS_3_0
=> type.IsRefLikeType;
#else
=> RefLikeTypePolyfill.IsRefLikeType(type);
#endif

/// <summary>
/// Names which of the two <see cref="MayBeRefLike"/> found, so a message reads the same from either source analyzer.
/// </summary>
public static string ByRefLikeClause(ITypeSymbol type)
=> IsRefLikeType(type) ? "is a ref struct" : "admits a ref struct";
=> type.IsRefLikeType ? "is a ref struct" : "admits a ref struct";

/// <summary>
/// Which of the two rules applies. A ref struct is one the compiler can see, so the source cannot work; a
/// constraint that merely admits one is decided by the type argument, and one that is not by-ref-like reads
/// perfectly well - so the two are separate ids, configurable apart.
/// </summary>
public static DiagnosticDescriptor ByRefLikeRule(ITypeSymbol type)
=> IsRefLikeType(type) ? SourceElementMustNotBeByRefLikeRule : SourceElementMayBeByRefLikeRule;
=> type.IsRefLikeType ? SourceElementMustNotBeByRefLikeRule : SourceElementMayBeByRefLikeRule;

/// <summary>
/// Whether <paramref name="type"/> is <paramref name="baseType"/> or derives from it. BenchmarkDotNet resolves
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,7 @@ private static void Analyze(SyntaxNodeAnalysisContext context)
// `init` counts: the runnable assigns parameters through an object initializer.
var propertyAccessors = propertyDeclarationSyntax.AccessorList?.Accessors;
propertyIsMissingAssignableSetter = !HasAssignableAccessor(propertyAccessors, SyntaxKind.SetAccessorDeclaration)
#if CODE_ANALYSIS_3_8
&& !HasAssignableAccessor(propertyAccessors, SyntaxKind.InitAccessorDeclaration)
#endif
;
&& !HasAssignableAccessor(propertyAccessors, SyntaxKind.InitAccessorDeclaration);

fieldOrPropertyIdentifierLocation = propertyDeclarationSyntax.Identifier.GetLocation();
declaredNames = ImmutableArray.Create((fieldOrPropertyIdentifier, fieldOrPropertyIdentifierLocation));
Expand Down
11 changes: 6 additions & 5 deletions src/BenchmarkDotNet.Analyzers/BenchmarkDotNet.Analyzers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
<PropertyGroup>
<!-- Formatting in AnalyzerReleases.Unshipped.md -->
<NoWarn>$(NoWarn);RS2007</NoWarn>
<!-- Suppress false positives due to a bug in v3.8.0. -->
<NoWarn Condition="'$(MccVersion)' == '3.8'">$(NoWarn);RS2002</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MccPackageVersion)" />
<!-- A HashSet built with SymbolEqualityComparer.Default is what RS1024 asks for, but the rule as shipped in
Microsoft.CodeAnalysis.Analyzers 3.3.2 (bundled with 4.0.0) reports it anyway. -->
<NoWarn Condition="'$(MccVersion)' == '4.0'">$(NoWarn);RS1024</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MccPackageVersion)" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="AnalyzerReleases.Shipped.md" />
Expand Down
41 changes: 0 additions & 41 deletions src/BenchmarkDotNet.Analyzers/Polyfills/RefLikeTypePolyfill.cs

This file was deleted.

19 changes: 0 additions & 19 deletions src/BenchmarkDotNet.Analyzers/Polyfills/SymbolEqualityComparer.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,24 @@

<!-- The weaving logic is shared with BenchmarkDotNet.Weaver.targets. See the common file for details. -->
<Import Project="$(MSBuildThisFileDirectory)BenchmarkDotNet.Weaver.Common.targets" />

<Target Name="_BenchmarkDotNetGatherAnalyzers">
<ItemGroup>
<_BenchmarkDotNetAnalyzer Include="@(Analyzer)" Condition="'%(Analyzer.NuGetPackageId)' == 'BenchmarkDotNet.Annotations'" />
</ItemGroup>
</Target>

<!-- The analyzers ship one assembly per compiler version under analyzers/dotnet/roslyn<version>, the lowest being
Roslyn 4.0. Choosing among those folders needs SDK 6 or later; every older host is handed all of them at once
and, because they share an assembly name, resolves the whole set to one arbitrary path - so nothing loads and
every analyzer in it is reported as CS8032, which a consumer building with TreatWarningsAsErrors sees as a
build failure. Take them back out again rather than hand over a set that cannot work. -->
<Target Name="_BenchmarkDotNetRemoveAnalyzers"
Condition="'$(SupportsRoslynComponentVersioning)' != 'true'"
AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets"
DependsOnTargets="_BenchmarkDotNetGatherAnalyzers">
<ItemGroup>
<Analyzer Remove="@(_BenchmarkDotNetAnalyzer)" />
</ItemGroup>
</Target>
</Project>
Loading