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
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
<PackageVersion Include="Basic.Reference.Assemblies.Net80" Version="1.8.3" />
<PackageVersion Include="System.Buffers" Version="4.6.1" />
<PackageVersion Include="System.Collections.Immutable" Version="9.0.8" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta7.25380.108" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-rc.2.25502.107" />

<!-- Security vulnerability overrides -->
<!-- Workaround(2): https://github.com/dotnet/roslyn-sdk/issues/1191 -->
<PackageVersion Include="System.Formats.Asn1" Version="9.0.10" />

Expand Down
33 changes: 33 additions & 0 deletions src/Analyzers/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Repository Analyzers
This folder contains the analyzers that are specific to this repository. They are not
generalized to a package as they are very specific to the code in this repo.

## Extension Keyword Analyzer
This repository does NOT use the new C# 14 extension syntax due to several reasons.
1) Code lens does not work https://github.com/dotnet/roslyn/issues/79006
1. Sadly marked as "not planned" - e.g., dead-end
1. [New issue created](https://developercommunity.visualstudio.com/t/VS2026-Codelens-does-not-appearwork-f/10988233)
2) MANY analyzers get things wrong and need to be supressed
1. (CA1000, CA1034, and many others [SAxxxx])
3) Many tools (like docfx) don't support the new syntax yet.
4) No clear support for Caller* attributes on the extended symbol
1. Example: `[CallerArgumentExpression(...)]`.

Bottom line it's a good idea with an incomplete implementation lacking support in the
overall ecosystem. Don't use it unless you absolutely have to until all of that is sorted
out.

>[!IMPORTANT]
>Due to a [bug](https://developercommunity.visualstudio.com/t/VS2026--NET-10-Cant-test-analyzer-fo/10989212),
>the extension keyword banned analyzer doesn't actually run and is not testable. Hopefully,
>this is fixed soon as it's a major PITA not to work correctly for any new syntax. For now,
>a Regex search using `extension(?([^\r\n])\s)*\(` is all that can be done...

# Reference Equality Analyzer
Reference equality is usually the wrong behavior for comparing wrapped LLVM types. This, is
a significant breaking change from older releases of this library. However, due to issues
with cacheing (and more importantly, resolving) the correct thing (disposable or just an
alias?) - the behavior had to change and reference equality is broken. This analyzer reports
issues if the code contains a reference equality (operator == on a ref type) when the type
implements `IEquatable<T>`. This eliminates source use assumptions in this library making
the transition easier and preventing new cases of problems.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Ubiquity.NET Contributors. All rights reserved.
// Licensed under the Apache-2.0 WITH LLVM-exception license. See the LICENSE.md file in the project root for full license information.

// due to bug in Nuget publication, this can't be tested yet...
// see: https://developercommunity.visualstudio.com/t/VS2026--NET-10-Cant-build-analyzier/10989212
#if NET10_0_OR_GREATER
// This isn't a normal built-in define; but follows the pattern for built-in defines and expresses the intent.
// There is no Known way to "light up" at runtime for functionality available in newer versions
#if COMPILER_5_OR_GREATER
using System.Threading.Tasks;

using Microsoft.CodeAnalysis;
Expand All @@ -25,7 +25,7 @@ public class ExtensionsKeywordAnalyzerTests
public async Task EmptySourceAnalyzesClean( )
{
var analyzerTest = CreateTestRunner(string.Empty);
await analyzerTest.RunAsync( TestContext.CancellationTokenSource.Token );
await analyzerTest.RunAsync( TestContext.CancellationToken );
}

[TestMethod]
Expand All @@ -34,11 +34,11 @@ public async Task UsingKeywordReportsDiagnostic( )
var analyzerTest = CreateTestRunner(ExtensionKeywordUsed);
analyzerTest.ExpectedDiagnostics.AddRange(
[
new DiagnosticResult("UNL002", DiagnosticSeverity.Error).WithLocation(5, 5)
new DiagnosticResult("UNL002", DiagnosticSeverity.Error).WithLocation( 5, 5 ),
]
);

await analyzerTest.RunAsync( TestContext.CancellationTokenSource.Token );
await analyzerTest.RunAsync( TestContext.CancellationToken );
}

[TestMethod]
Expand All @@ -47,7 +47,7 @@ public async Task StructEquatableIsNotReferenceEquality( )
var analyzerTest = CreateTestRunner(NoExtensionKeywordUsed);

// no diagnostics expected
await analyzerTest.RunAsync( TestContext.CancellationTokenSource.Token );
await analyzerTest.RunAsync( TestContext.CancellationToken );
}

private static AnalyzerTest<DefaultVerifier> CreateTestRunner( string source )
Expand All @@ -62,17 +62,17 @@ private static AnalyzerTest<DefaultVerifier> CreateTestRunner( string source )
};
}

private class ExtensionKeywordAnalyzerTest
: CSharpAnalyzerTest<ExtensionKeywordAnalyzer, DefaultVerifier>
private class ExtensionKeywordAnalyzerTest
: CSharpAnalyzerTest<ExtensionKeywordAnalyzer, DefaultVerifier>
{
protected override ParseOptions CreateParseOptions( )
{
// Until C# 14 and .NET SDK 10 is formally released, it is considered "Preview"
return new CSharpParseOptions(LanguageVersion.Preview, DocumentationMode.Diagnose);
// Until C# 14 and .NET SDK 10 is formally released, the language version is considered "Preview"
return new CSharpParseOptions( LanguageVersion.Preview, DocumentationMode.Diagnose );
}
}

private const string ExtensionKeywordUsed = """
private const string ExtensionKeywordUsed = """
using System;

public static class TestExtension
Expand All @@ -85,9 +85,13 @@ public string MyExtension()
}
}
}

file class Foo
{
}
""";

private const string NoExtensionKeywordUsed = """
private const string NoExtensionKeywordUsed = """
using System;

public static class TestExtension
Expand Down
6 changes: 5 additions & 1 deletion src/Analyzers/RepositoryVerifier/ExtensionKeywordAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) Ubiquity.NET Contributors. All rights reserved.
// Licensed under the Apache-2.0 WITH LLVM-exception license. See the LICENSE.md file in the project root for full license information.

// This isn't a normal built-in define; but follows the pattern for built-in defines and expresses the intent.
// There is no Known way to "light up" at runtime for functionality available in newer versions
#if COMPILER_5_OR_GREATER
using System.Collections.Immutable;

using Microsoft.CodeAnalysis;
Expand All @@ -23,7 +26,7 @@ public override void Initialize( AnalysisContext context )
// ignore generated code
context.ConfigureGeneratedCodeAnalysis( GeneratedCodeAnalysisFlags.None );
context.EnableConcurrentExecution();
context.RegisterSyntaxNodeAction( OnExtensionKeyword, SyntaxKind.ExtensionKeyword, SyntaxKind.ExtensionDeclaration );
context.RegisterSyntaxNodeAction( OnExtensionKeyword, SyntaxKind.ExtensionKeyword, SyntaxKind.ExtensionBlockDeclaration );
}

private void OnExtensionKeyword( SyntaxNodeAnalysisContext context )
Expand All @@ -32,3 +35,4 @@ private void OnExtensionKeyword( SyntaxNodeAnalysisContext context )
}
}
}
#endif
2 changes: 1 addition & 1 deletion src/Analyzers/RepositoryVerifier/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ C# 14 `extension` keyword used. This is currently blocked in this repository. Ho
this is short term but is not allowed. This prevents any current/experimental use and any
future use. The experiments with using it have unveiled a lot of issues that make that an
incomplete feature. "Complete" requires proper support in the majority of analyzers and
third party tools.
third party tools. That support does not exist yet.

## ReferenceEqualityAnalyzer
This analyzer was designed to identify places within the Ubiquity.NET.Llvm library where the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void BinaryOpAction( OperationAnalysisContext context )
{
try
{
if(!(context.Operation is IBinaryOperation op))
if(context.Operation is not IBinaryOperation op)
{
throw new InvalidOperationException( "Unknown case; non-binary operation..." );
}
Expand Down
8 changes: 0 additions & 8 deletions src/Analyzers/RepositoryVerifier/RepositoryVerifier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>

<!-- Avoid ID conflicts with the package project. -->
<PackageId>*$(MSBuildProjectFile)*</PackageId>
<NeutralLanguage>en-US</NeutralLanguage>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
</ItemGroup>

Expand Down
13 changes: 6 additions & 7 deletions src/Interop/LlvmBindingsGenerator/LlvmBindingsGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
<PackageReference Include="CppSharp" PrivateAssets="all" />
<PackageReference Include="System.CodeDom" PrivateAssets="all" />

<!-- Sadly, the version range syntax doesn't work for Directory.Package.props so it must be provided here-->
<!-- Sadly, the version range syntax doesn't work for Directory.Package.props so it must be provided here -->
<!--
NOTE: This isn't directly used by this project. However, it allows for scripts to restore this project, which
guarantees the package is available, so they can use the contained headers as input to the application built
by this project.
guarantees the package is available, so that running it can use the contained headers as input.
-->
<PackageReference Include="Ubiquity.NET.LibLLVM" VersionOverride="20.1.*-*" GeneratePathProperty="true" PrivateAssets="all" />
</ItemGroup>
Expand Down Expand Up @@ -57,10 +56,10 @@
<!--
This target is triggered externally to generate the response file for an invocation of the generator.
The response file provides the paths for the headers based on the location of the package used by
the build. Restoring this project will download and cache the package. This target allows creation
of the response file to use for involving the application built by this project so that it has the
actual headers from the package as input to the generator. This is all automated by the developer
facing script to generate the headers.
the build. Restoring this project will download and cache the LLVM package that includes the headers.
This target allows creation of the response file to use for invoking the application built by this
project so that it has the actual headers from the package as input to the generator. This is all
automated by the developer facing script to generate the headers.
SEE: Generate-HandleWrappers.ps1
-->
<Target Name="GenerateResponseFile">
Expand Down
10 changes: 10 additions & 0 deletions src/Interop/Ubiquity.NET.Llvm.Interop/ArchitectureExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

namespace Ubiquity.NET.Llvm.Interop
{
// This does NOT use the new C# 14 extension syntax due to several reasons
// 1) Code lens does not work https://github.com/dotnet/roslyn/issues/79006 [Sadly, marked as "not planned" - e.g., dead-end]
// 2) MANY analyzers get things wrong and need to be supressed (CA1000, CA1034, and many others [SAxxxx])
// 3) Many tools (like docfx) don't support the new syntax yet and it isn't clear if they will in the future.
// 4) No clear support for Caller* attributes ([CallerArgumentExpression(...)]).
//
// Bottom line it's a good idea with an incomplete implementation lacking support
// in the overall ecosystem. Don't use it unless you absolutely have to until all
// of that is sorted out.

/// <summary>Utility class to implement extensions of <see cref="Architecture"/></summary>
public static class ArchitectureExtensions
{
Expand Down
10 changes: 10 additions & 0 deletions src/Interop/Ubiquity.NET.Llvm.Interop/ContextHandleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

namespace Ubiquity.NET.Llvm.Interop
{
// This does NOT use the new C# 14 extension syntax due to several reasons
// 1) Code lens does not work https://github.com/dotnet/roslyn/issues/79006 [Sadly, marked as "not planned" - e.g., dead-end]
// 2) MANY analyzers get things wrong and need to be supressed (CA1000, CA1034, and many others [SAxxxx])
// 3) Many tools (like docfx) don't support the new syntax yet and it isn't clear if they will in the future.
// 4) No clear support for Caller* attributes ([CallerArgumentExpression(...)]).
//
// Bottom line it's a good idea with an incomplete implementation lacking support
// in the overall ecosystem. Don't use it unless you absolutely have to until all
// of that is sorted out.

/// <summary>Utility class to host extensions for an <see cref="IWrappedHandle{THandle}"/></summary>
public static class ContextHandleExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool. [LlvmBindingsGenerator]
// Tool Version: 20.1.9-epsilon.0.0.ci.617180375.ZZZ
// Tool Version: 20.1.9-epsilon.0.0.ci.618108218.ZZZ
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand Down Expand Up @@ -31,7 +31,7 @@ namespace Ubiquity.NET.Llvm.Interop
/// behavior, including, and most likely, memory access violations.
/// </note>
/// </remarks>
[GeneratedCode("LlvmBindingsGenerator","20.1.9-epsilon.0.0.ci.617180375.ZZZ")]
[GeneratedCode("LlvmBindingsGenerator","20.1.9-epsilon.0.0.ci.618108218.ZZZ")]
[NativeMarshalling(typeof(WrappedHandleMarshaller<LLVMAttributeRef>))]
public readonly record struct LLVMAttributeRef
: IWrappedHandle<LLVMAttributeRef>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool. [LlvmBindingsGenerator]
// Tool Version: 20.1.9-epsilon.0.0.ci.617180375.ZZZ
// Tool Version: 20.1.9-epsilon.0.0.ci.618108218.ZZZ
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand Down Expand Up @@ -31,7 +31,7 @@ namespace Ubiquity.NET.Llvm.Interop
/// behavior, including, and most likely, memory access violations.
/// </note>
/// </remarks>
[GeneratedCode("LlvmBindingsGenerator","20.1.9-epsilon.0.0.ci.617180375.ZZZ")]
[GeneratedCode("LlvmBindingsGenerator","20.1.9-epsilon.0.0.ci.618108218.ZZZ")]
[NativeMarshalling(typeof(WrappedHandleMarshaller<LLVMBasicBlockRef>))]
public readonly record struct LLVMBasicBlockRef
: IWrappedHandle<LLVMBasicBlockRef>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool. [LlvmBindingsGenerator]
// Tool Version: 20.1.9-epsilon.0.0.ci.617180375.ZZZ
// Tool Version: 20.1.9-epsilon.0.0.ci.618108218.ZZZ
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand Down Expand Up @@ -35,7 +35,7 @@ namespace Ubiquity.NET.Llvm.Interop
/// correct usage.
/// </note>
/// </remarks>
[GeneratedCode("LlvmBindingsGenerator","20.1.9-epsilon.0.0.ci.617180375.ZZZ")]
[GeneratedCode("LlvmBindingsGenerator","20.1.9-epsilon.0.0.ci.618108218.ZZZ")]
[NativeMarshalling(typeof(WrappedHandleMarshaller<LLVMBinaryRef>))]
public readonly record struct LLVMBinaryRef
: IWrappedHandle<LLVMBinaryRef>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool. [LlvmBindingsGenerator]
// Tool Version: 20.1.9-epsilon.0.0.ci.617180375.ZZZ
// Tool Version: 20.1.9-epsilon.0.0.ci.618108218.ZZZ
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand Down Expand Up @@ -35,7 +35,7 @@ namespace Ubiquity.NET.Llvm.Interop
/// correct usage.
/// </note>
/// </remarks>
[GeneratedCode("LlvmBindingsGenerator","20.1.9-epsilon.0.0.ci.617180375.ZZZ")]
[GeneratedCode("LlvmBindingsGenerator","20.1.9-epsilon.0.0.ci.618108218.ZZZ")]
[NativeMarshalling(typeof(WrappedHandleMarshaller<LLVMBuilderRef>))]
public readonly record struct LLVMBuilderRef
: IWrappedHandle<LLVMBuilderRef>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool. [LlvmBindingsGenerator]
// Tool Version: 20.1.9-epsilon.0.0.ci.617180375.ZZZ
// Tool Version: 20.1.9-epsilon.0.0.ci.618108218.ZZZ
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand Down Expand Up @@ -31,7 +31,7 @@ namespace Ubiquity.NET.Llvm.Interop
/// behavior, including, and most likely, memory access violations.
/// </note>
/// </remarks>
[GeneratedCode("LlvmBindingsGenerator","20.1.9-epsilon.0.0.ci.617180375.ZZZ")]
[GeneratedCode("LlvmBindingsGenerator","20.1.9-epsilon.0.0.ci.618108218.ZZZ")]
[NativeMarshalling(typeof(WrappedHandleMarshaller<LLVMComdatRef>))]
public readonly record struct LLVMComdatRef
: IWrappedHandle<LLVMComdatRef>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool. [LlvmBindingsGenerator]
// Tool Version: 20.1.9-epsilon.0.0.ci.617180375.ZZZ
// Tool Version: 20.1.9-epsilon.0.0.ci.618108218.ZZZ
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand Down Expand Up @@ -35,7 +35,7 @@ namespace Ubiquity.NET.Llvm.Interop
/// correct usage.
/// </note>
/// </remarks>
[GeneratedCode("LlvmBindingsGenerator","20.1.9-epsilon.0.0.ci.617180375.ZZZ")]
[GeneratedCode("LlvmBindingsGenerator","20.1.9-epsilon.0.0.ci.618108218.ZZZ")]
[NativeMarshalling(typeof(WrappedHandleMarshaller<LLVMContextRef>))]
public readonly record struct LLVMContextRef
: IWrappedHandle<LLVMContextRef>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool. [LlvmBindingsGenerator]
// Tool Version: 20.1.9-epsilon.0.0.ci.617180375.ZZZ
// Tool Version: 20.1.9-epsilon.0.0.ci.618108218.ZZZ
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand Down Expand Up @@ -31,7 +31,7 @@ namespace Ubiquity.NET.Llvm.Interop
/// behavior, including, and most likely, memory access violations.
/// </note>
/// </remarks>
[GeneratedCode("LlvmBindingsGenerator","20.1.9-epsilon.0.0.ci.617180375.ZZZ")]
[GeneratedCode("LlvmBindingsGenerator","20.1.9-epsilon.0.0.ci.618108218.ZZZ")]
[NativeMarshalling(typeof(WrappedHandleMarshaller<LLVMContextRefAlias>))]
public readonly record struct LLVMContextRefAlias
: IWrappedHandle<LLVMContextRefAlias>
Expand Down
Loading
Loading