-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Add AggressiveInliningMode and implement the functionality
- Loading branch information
1 parent
05ab18c
commit 40654d2
Showing
11 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Riok.Mapperly.Abstractions; | ||
|
||
/// <summary> | ||
/// Indicates how AggressiveInlining should be applied to methods. | ||
/// </summary> | ||
public enum AggressiveInliningMode | ||
{ | ||
/// <summary> | ||
/// Does not apply AggressiveInlining | ||
/// </summary> | ||
None, | ||
|
||
/// <summary> | ||
/// Applies AggressiveInlining to value types | ||
/// </summary> | ||
ValueTypes, | ||
|
||
/// <summary> | ||
/// Applies AggressiveInlining to reference types | ||
/// </summary> | ||
ReferenceTypes, | ||
|
||
/// <summary> | ||
/// Applies AggressiveInlining to all types | ||
/// </summary> | ||
All, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.MethodImpl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Runtime.CompilerServices; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
namespace Riok.Mapperly.Emit.Syntax; | ||
|
||
public partial struct SyntaxFactoryHelper | ||
{ | ||
private const string MethodImplAttributeName = "global::System.Runtime.CompilerServices.MethodImpl"; | ||
|
||
public SyntaxList<AttributeListSyntax> MethodImplAttributeList() | ||
{ | ||
return AttributeList(MethodImplAttributeName, EnumLiteral(MethodImplOptions.AggressiveInlining)); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Riok.Mapperly/Helpers/MethodDeclarationSyntaxExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
namespace Riok.Mapperly.Helpers; | ||
|
||
public static class MethodDeclarationSyntaxExtensions | ||
{ | ||
public static bool HasAttribute<TAttribute>(this MethodDeclarationSyntax methodDeclarationSyntax) | ||
where TAttribute : Attribute | ||
{ | ||
var csharpCompilation = CSharpCompilation.Create( | ||
assemblyName: null, | ||
syntaxTrees: [methodDeclarationSyntax!.SyntaxTree], | ||
references: [MetadataReference.CreateFromFile(typeof(TAttribute).Assembly.Location)] | ||
); | ||
|
||
var semanticModel = csharpCompilation.GetSemanticModel(methodDeclarationSyntax.SyntaxTree); | ||
|
||
var attributes = methodDeclarationSyntax.AttributeLists.SelectMany(p => p.Attributes); | ||
|
||
return attributes.Any(attributeSyntax => | ||
{ | ||
var symbols = semanticModel.GetSymbolInfo(attributeSyntax).CandidateSymbols.OfType<IMethodSymbol>(); | ||
return symbols.Any(p => string.Equals(p.ContainingType.ToString(), typeof(TAttribute).FullName, StringComparison.Ordinal)); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters