Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Adding attributes to support Native AOT compiling #37734

Merged
merged 90 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
e347a6a
part 1
m-redding Jul 19, 2023
0c247da
Merge branch 'Azure:main' into resolve-aot-warnings-phase1
m-redding Jul 19, 2023
dacab57
additional changes
m-redding Jul 19, 2023
466ef7b
additional attributes
m-redding Jul 20, 2023
07b5ec6
additional attributes
m-redding Jul 20, 2023
2c15eec
Merge branch 'Azure:main' into resolve-aot-warnings-phase1
m-redding Jul 24, 2023
581d888
adding diagnosticscope attributes
m-redding Jul 28, 2023
d1d99e7
Merge branch 'Azure:main' into resolve-aot-warnings-phase1
m-redding Jul 28, 2023
e6fa1e4
Merge branch 'resolve-aot-warnings-phase1' of https://github.com/m-re…
m-redding Jul 28, 2023
9d0ae69
updating messages
m-redding Jul 31, 2023
653623c
more fixes
m-redding Jul 31, 2023
5d9b2dc
additional updates
m-redding Jul 31, 2023
ddf556b
updates
m-redding Aug 3, 2023
44f0da5
PR feedback
m-redding Aug 4, 2023
f17c266
API update
m-redding Aug 4, 2023
540619f
removing unnecessary warnings
m-redding Aug 4, 2023
bf185ec
reverting attribute on HttpPipelineSynchronousPolicy
m-redding Aug 4, 2023
fcb6488
update api
m-redding Aug 4, 2023
7623768
updates
m-redding Aug 8, 2023
bdf71e9
update
m-redding Aug 8, 2023
d95f014
API export
m-redding Aug 9, 2023
032c14f
WIP fix 1
m-redding Aug 9, 2023
47228e8
WIP
m-redding Aug 9, 2023
47981b3
Merge branch 'Azure:main' into resolve-aot-warnings-phase1
m-redding Aug 9, 2023
f00379d
attribute adjustments
m-redding Aug 9, 2023
2b64b23
adding compatibility test
m-redding Aug 10, 2023
ebcd377
WIP adding test
m-redding Aug 14, 2023
ba7bcfe
WIP API
m-redding Aug 14, 2023
b074259
WIP
m-redding Aug 14, 2023
2d53367
WIP
m-redding Aug 14, 2023
d1010d2
Merge branch 'Azure:main' into resolve-aot-warnings-phase1
m-redding Aug 14, 2023
f879d9c
updates
m-redding Aug 14, 2023
e9253a0
add test script and remove #if statements
m-redding Aug 15, 2023
5473799
fixing build
m-redding Aug 15, 2023
f2c2543
Merge branch 'main' into resolve-aot-warnings-phase1
m-redding Aug 15, 2023
93bdee1
Update Program.cs
m-redding Aug 15, 2023
edbe071
adding some compile statements
m-redding Aug 15, 2023
f050d2e
Update AzureCoreEventSource.cs
m-redding Aug 15, 2023
ec1d84e
build fix attempt
m-redding Aug 17, 2023
3579eea
fix built attempt 2
m-redding Aug 17, 2023
5817ccc
Update MutableJsonChange.cs
m-redding Aug 18, 2023
9fa60a5
Update MutableJsonChange.cs
m-redding Aug 18, 2023
1a589df
Update MutableJsonDocument.cs
m-redding Aug 18, 2023
1d6986b
Update HttpPipelineSynchronousPolicy.cs
m-redding Aug 18, 2023
d78b8ef
adding comments
m-redding Aug 18, 2023
176afe6
PR fb 1
m-redding Aug 18, 2023
461c072
test
m-redding Aug 22, 2023
496b809
test2
m-redding Aug 22, 2023
f596df5
test3
m-redding Aug 22, 2023
a1751ce
Merge branch 'main' into resolve-aot-warnings-phase1
m-redding Aug 24, 2023
ebfc02d
attempt
m-redding Aug 28, 2023
553148c
Merge branch 'resolve-aot-warnings-phase1' of https://github.com/m-re…
m-redding Aug 28, 2023
0b83cb8
additional build fixes
m-redding Aug 29, 2023
27085c0
Remove comment
m-redding Aug 29, 2023
44b1bee
PR feedback + fixing impacts of feedback changes
m-redding Sep 7, 2023
9ebbf94
fixes
m-redding Sep 7, 2023
f6fef75
Update GeoRedundantFallbackPolicy.cs
m-redding Sep 7, 2023
8e4b7bb
Update GeoRedundantFallbackPolicy.cs
m-redding Sep 7, 2023
69cf078
Update GeoRedundantFallbackPolicy.cs
m-redding Sep 7, 2023
be791c5
fix
m-redding Sep 7, 2023
917647e
Merge branch 'main' into resolve-aot-warnings-phase1
m-redding Sep 7, 2023
b2a25e2
add tests
m-redding Sep 7, 2023
41040dd
pipeline fixes
m-redding Sep 7, 2023
8c0aa83
update comments
m-redding Sep 7, 2023
e9c06b3
feedback
m-redding Sep 7, 2023
83c118f
adjustments
m-redding Sep 7, 2023
0f6e866
adjustment
m-redding Sep 7, 2023
b677aec
pipeline fix
m-redding Sep 7, 2023
a211515
PR feedback 1
m-redding Sep 8, 2023
1026bc1
Apply suggestions from code review
m-redding Sep 8, 2023
b212d9e
PR feedback updates 2
m-redding Sep 8, 2023
1a12f76
Update sdk/core/Azure.Core/src/Shared/DiagnosticScope.cs
m-redding Sep 8, 2023
6c86362
need one other suppression
m-redding Sep 8, 2023
c25e250
remove 2 annotations + update suppression message
m-redding Sep 11, 2023
83d4650
removing all attributes from RequestContentHelper
m-redding Sep 11, 2023
ac9c480
tweak justification
m-redding Sep 12, 2023
23eea94
removing test project from Azure.Core, will be adding feedback to gen…
m-redding Sep 13, 2023
1969119
WIP
m-redding Sep 14, 2023
cc4a4a8
feedback
m-redding Sep 14, 2023
004ced0
Update sdk/core/Azure.Core/src/Shared/DiagnosticScope.cs
m-redding Sep 14, 2023
af15022
fix attribute and add comments
m-redding Sep 15, 2023
9938471
Merge branch 'resolve-aot-warnings-phase1' of https://github.com/m-re…
m-redding Sep 15, 2023
992ef22
Addressing feedback
m-redding Sep 25, 2023
00d5db1
adding net 5 preprocessor directives
m-redding Sep 26, 2023
d5ac8ee
Update sdk/core/Azure.Core/src/DynamicData/MutableJsonElement.cs
m-redding Sep 27, 2023
12c34f3
remove unused const
m-redding Sep 27, 2023
d2c8865
Merge branch 'resolve-aot-warnings-phase1' of https://github.com/m-re…
m-redding Sep 27, 2023
60e4c86
Merge branch 'Azure:main' into resolve-aot-warnings-phase1
m-redding Sep 27, 2023
9838582
Merge branch 'Azure:main' into resolve-aot-warnings-phase1
m-redding Sep 27, 2023
be02829
pipeline fix
m-redding Sep 27, 2023
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
1 change: 1 addition & 0 deletions eng/Directory.Build.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
<Compile Include="$(AzureCoreSharedSources)FixedDelayWithNoJitterStrategy.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)OperationPoller.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)ClientDiagnostics.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)TrimmingAttribute.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)DiagnosticScope.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)DiagnosticScopeFactory.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)HttpMessageSanitizer.cs" LinkBase="Shared/Core" />
Expand Down
m-redding marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
m-redding marked this conversation as resolved.
Show resolved Hide resolved
<PublishAot>true</PublishAot>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
<IsTestSupportProject>true</IsTestSupportProject>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\src\Azure.Core.csproj" />
<ProjectReference Include="..\..\..\monitor\Azure.Monitor.OpenTelemetry.Exporter\src\Azure.Monitor.OpenTelemetry.Exporter.csproj" />

<TrimmerRootAssembly Include="Azure.Monitor.OpenTelemetry.Exporter" />

<!-- Update this dependency to its latest, which has all the annotations -->
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0-preview.7.23375.6" />
m-redding marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions sdk/core/Azure.Core/aotcompatibility/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Core;
using Azure.Core.Pipeline;
using Azure.Monitor.OpenTelemetry.Exporter;
using System;

namespace Azure.Core.Tests.AotCompatibility.TestApp
{
internal class Program
{
public static void Main(string[] args)
m-redding marked this conversation as resolved.
Show resolved Hide resolved
{
System.Console.WriteLine("Hello, World!");
}
}
}
28 changes: 28 additions & 0 deletions sdk/core/Azure.Core/aotcompatibility/test-aot-compat.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
param([string]$targetNetFramework)
m-redding marked this conversation as resolved.
Show resolved Hide resolved

$rootDirectory = Split-Path $PSScriptRoot -Parent
$publishOutput = dotnet publish -nodeReuse:false /p:UseSharedCompilation=false /p:ExposeExperimentalFeatures=true
m-redding marked this conversation as resolved.
Show resolved Hide resolved

$actualWarningCount = 0

foreach ($line in $($publishOutput -split "`r`n"))
{
if ($line -like "*analysis warning IL*")
{
Write-Host $line

$actualWarningCount += 1
}
}

Write-Host "Actual warning count is:", $actualWarningCount
$expectedWarningCount = 43

$testPassed = 0
if ($actualWarningCount -ne $expectedWarningCount)
{
$testPassed = 1
Write-Host "Actual warning count:", actualWarningCount, "is not as expected. Expected warning count is:", $expectedWarningCount
}

Exit $testPassed
3 changes: 3 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.net5.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,11 @@ protected RequestContent() { }
public static Azure.Core.RequestContent Create(byte[] bytes) { throw null; }
public static Azure.Core.RequestContent Create(byte[] bytes, int index, int length) { throw null; }
public static Azure.Core.RequestContent Create(System.IO.Stream stream) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("This method uses reflection-based serialization which is incompatible with trimming. Try using one of the 'Create' overloads that doesn't wrap a serialized version of an object.")]
annelo-msft marked this conversation as resolved.
Show resolved Hide resolved
public static Azure.Core.RequestContent Create(object serializable) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("This method uses reflection-based serialization which is incompatible with trimming. Try using one of the 'Create' overloads that doesn't wrap a serialized version of an object.")]
public static Azure.Core.RequestContent Create(object serializable, Azure.Core.Serialization.JsonPropertyNames propertyNameFormat, string dateTimeFormat = "o") { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("This method uses reflection-based serialization which is incompatible with trimming. Try using one of the 'Create' overloads that doesn't wrap a serialized version of an object.")]
public static Azure.Core.RequestContent Create(object serializable, Azure.Core.Serialization.ObjectSerializer? serializer) { throw null; }
public static Azure.Core.RequestContent Create(System.ReadOnlyMemory<byte> bytes) { throw null; }
public static Azure.Core.RequestContent Create(string content) { throw null; }
Expand Down
6 changes: 6 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.net6.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,11 @@ protected RequestContent() { }
public static Azure.Core.RequestContent Create(byte[] bytes) { throw null; }
public static Azure.Core.RequestContent Create(byte[] bytes, int index, int length) { throw null; }
public static Azure.Core.RequestContent Create(System.IO.Stream stream) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("This method uses reflection-based serialization which is incompatible with trimming. Try using one of the 'Create' overloads that doesn't wrap a serialized version of an object.")]
public static Azure.Core.RequestContent Create(object serializable) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("This method uses reflection-based serialization which is incompatible with trimming. Try using one of the 'Create' overloads that doesn't wrap a serialized version of an object.")]
public static Azure.Core.RequestContent Create(object serializable, Azure.Core.Serialization.JsonPropertyNames propertyNameFormat, string dateTimeFormat = "o") { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("This method uses reflection-based serialization which is incompatible with trimming. Try using one of the 'Create' overloads that doesn't wrap a serialized version of an object.")]
public static Azure.Core.RequestContent Create(object serializable, Azure.Core.Serialization.ObjectSerializer? serializer) { throw null; }
public static Azure.Core.RequestContent Create(System.ReadOnlyMemory<byte> bytes) { throw null; }
public static Azure.Core.RequestContent Create(string content) { throw null; }
Expand Down Expand Up @@ -1026,6 +1029,7 @@ protected HttpPipelinePolicy() { }
protected static void ProcessNext(Azure.Core.HttpMessage message, System.ReadOnlyMemory<Azure.Core.Pipeline.HttpPipelinePolicy> pipeline) { }
protected static System.Threading.Tasks.ValueTask ProcessNextAsync(Azure.Core.HttpMessage message, System.ReadOnlyMemory<Azure.Core.Pipeline.HttpPipelinePolicy> pipeline) { throw null; }
}
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicMethods)]
public abstract partial class HttpPipelineSynchronousPolicy : Azure.Core.Pipeline.HttpPipelinePolicy
{
protected HttpPipelineSynchronousPolicy() { }
Expand Down Expand Up @@ -1084,6 +1088,7 @@ public AbstractHierarchyDeserializerAttribute([System.Diagnostics.CodeAnalysis.D
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]
public System.Type TypeToActivate { get { throw null; } }
}
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("This class utilizes reflection-based JSON serialization and deserialization which is not compatible with trimming.")]
[System.Diagnostics.DebuggerDisplayAttribute("{DebuggerDisplay,nq}")]
public sealed partial class DynamicData : System.Dynamic.IDynamicMetaObjectProvider, System.IDisposable
{
Expand Down Expand Up @@ -1128,6 +1133,7 @@ public partial interface IModelSerializable<out T>
T Deserialize(System.BinaryData data, Azure.Core.Serialization.ModelSerializerOptions options);
System.BinaryData Serialize(Azure.Core.Serialization.ModelSerializerOptions options);
}
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("This class uses reflection-based JSON serialization and deserialization that is not compatible with trimming.")]
m-redding marked this conversation as resolved.
Show resolved Hide resolved
public partial class JsonObjectSerializer : Azure.Core.Serialization.ObjectSerializer, Azure.Core.Serialization.IMemberNameConverter
{
public JsonObjectSerializer() { }
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/Azure.Core/src/Diagnostics/AzureCoreEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Diagnostics.CodeAnalysis;
using System.Text;

namespace Azure.Core.Diagnostics
Expand Down Expand Up @@ -231,6 +232,7 @@ public void ErrorResponseContentTextBlock(string requestId, int blockNumber, str
}

[Event(RequestRetryingEvent, Level = EventLevel.Informational, Message = "Request [{0}] attempt number {1} took {2:00.0}s")]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "WriteEvent is used with primitive types.")]
public void RequestRetrying(string requestId, int retryNumber, double seconds)
{
WriteEvent(RequestRetryingEvent, requestId, retryNumber, seconds);
Expand Down
7 changes: 7 additions & 0 deletions sdk/core/Azure.Core/src/DynamicData/DynamicData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using System.Text.Json;
Expand All @@ -20,6 +21,9 @@ namespace Azure.Core.Serialization
/// This and related types are not intended to be mocked.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
#if !NET5_0
[RequiresUnreferencedCode("This class utilizes reflection-based JSON serialization and deserialization which is not compatible with trimming.")]
m-redding marked this conversation as resolved.
Show resolved Hide resolved
#endif
[JsonConverter(typeof(DynamicDataJsonConverter))]
public sealed partial class DynamicData : IDisposable
{
Expand Down Expand Up @@ -344,6 +348,9 @@ public override int GetHashCode()
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string DebuggerDisplay => _element.DebuggerDisplay;

#if !NET5_0
[RequiresUnreferencedCode("This class utilizes reflection-based JSON serialization and deserialization which is not compatible with trimming.")]
#endif
private class DynamicDataJsonConverter : JsonConverter<DynamicData>
{
public override DynamicData Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/Azure.Core/src/DynamicData/MutableJsonChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Buffers;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;

namespace Azure.Core.Json
Expand All @@ -11,6 +12,7 @@ internal struct MutableJsonChange
{
private JsonElement? _serializedValue;
private readonly JsonSerializerOptions _serializerOptions;
internal const string SerializationRequiresUnreferencedCode = "This method utilizes reflection-based JSON serialization which is not compatible with trimming.";

public MutableJsonChange(string path,
int index,
Expand Down Expand Up @@ -108,6 +110,7 @@ internal bool IsGreaterThan(ReadOnlySpan<char> otherPath)
return Path.AsSpan().SequenceCompareTo(otherPath) > 0;
}

[RequiresUnreferencedCode(SerializationRequiresUnreferencedCode)]
m-redding marked this conversation as resolved.
Show resolved Hide resolved
internal string AsString()
{
return GetSerializedValue().ToString() ?? "null";
Expand Down
7 changes: 7 additions & 0 deletions sdk/core/Azure.Core/src/DynamicData/MutableJsonDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Buffers;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
using System.Text.Json;
Expand All @@ -13,6 +14,9 @@ namespace Azure.Core.Json
/// <summary>
/// A mutable representation of a JSON value.
/// </summary>
#if !NET5_0
[RequiresUnreferencedCode("This class utilizes reflection-based JSON serialization and deserialization which is not compatible with trimming.")]
m-redding marked this conversation as resolved.
Show resolved Hide resolved
#endif
m-redding marked this conversation as resolved.
Show resolved Hide resolved
[JsonConverter(typeof(MutableJsonDocumentConverter))]
internal sealed partial class MutableJsonDocument : IDisposable
{
Expand Down Expand Up @@ -206,6 +210,9 @@ private MutableJsonDocument(JsonDocument document, ReadOnlyMemory<byte> utf8Json
_serializerOptions = serializerOptions ?? new JsonSerializerOptions();
}

#if !NET5_0
m-redding marked this conversation as resolved.
Show resolved Hide resolved
[RequiresUnreferencedCode("This class utilizes reflection-based JSON serialization and deserialization which is not compatible with trimming.")]
#endif
private class MutableJsonDocumentConverter : JsonConverter<MutableJsonDocument>
{
public override MutableJsonDocument Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
m-redding marked this conversation as resolved.
Show resolved Hide resolved
using System.Text.Json;

namespace Azure.Core.Json
{
internal partial struct MutableJsonElement
{
[RequiresUnreferencedCode(SerializationRequiresUnreferencedCode)]
internal void WriteTo(Utf8JsonWriter writer)
{
WriteElement(_path, _highWaterMark, _element, writer);
Expand All @@ -30,6 +32,7 @@ internal void WriteTo(Utf8JsonWriter writer, string format)
}
}

[RequiresUnreferencedCode(SerializationRequiresUnreferencedCode)]
private void WriteElement(string path, int highWaterMark, JsonElement element, Utf8JsonWriter writer)
{
if (Changes.TryGetChange(path, highWaterMark, out MutableJsonChange change))
Expand Down Expand Up @@ -84,6 +87,7 @@ private void WriteElement(string path, int highWaterMark, JsonElement element, U
element.WriteTo(writer);
}

[RequiresUnreferencedCode(SerializationRequiresUnreferencedCode)]
private void WriteObject(string path, int highWaterMark, JsonElement element, Utf8JsonWriter writer)
{
writer.WriteStartObject();
Expand Down Expand Up @@ -111,6 +115,7 @@ private void WriteObject(string path, int highWaterMark, JsonElement element, Ut
writer.WriteEndObject();
}

[RequiresUnreferencedCode(SerializationRequiresUnreferencedCode)]
private void WriteArray(string path, int highWaterMark, JsonElement element, Utf8JsonWriter writer)
{
writer.WriteStartArray();
Expand Down
Loading