Repository navigation
AOT: resolve built-in actor ref providers from constant type names so the trimmer preserves them #8599
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
Merged
Aaronontheweb
merged 4 commits into
akkadotnet:dev
from
Aaronontheweb:fix/aot-provider-constant-type-names
Sep 22, 2026
Merged
AOT: resolve built-in actor ref providers from constant type names so the trimmer preserves them #8599
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c9dc876
Resolve built-in actor ref providers from constant type names so the …
Aaronontheweb dfc8e35
Map the local provider type name in ProviderSelection.GetProvider; ad…
Aaronontheweb e8928fd
Collapse the provider helpers into one annotated method; fold the pro…
Aaronontheweb f5a2419
Drop the provider spec rows that only restate the constants
Aaronontheweb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,40 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="ProviderTypeNameSpec.cs" company="Akka.NET Project"> | ||
| // Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com> | ||
| // Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
| // </copyright> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| #nullable enable | ||
|
|
||
| using System; | ||
| using Akka.Actor; | ||
| using FluentAssertions; | ||
| using Xunit; | ||
|
|
||
| namespace Akka.Cluster.Tests | ||
| { | ||
| /// <summary> | ||
| /// The <see cref="ProviderSelection"/> type-name constants are the only thing standing between | ||
| /// <c>akka.actor.provider</c> and the provider type now that <c>ActorSystemImpl.CreateProvider</c> resolves | ||
| /// them through an annotated string parameter. Renaming or moving a provider would not break the build -- | ||
| /// only the runtime lookup, and only in a trimmed or AOT-published app. This spec turns that into a test | ||
| /// failure. It lives in Akka.Cluster.Tests because that project references Akka.Remote as well, so both | ||
| /// constants resolve here. The local provider is constructed directly and never goes through its constant. | ||
| /// </summary> | ||
| public class ProviderTypeNameSpec | ||
| { | ||
| [Theory(DisplayName = "Should_resolve_an_IActorRefProvider_When_loading_a_ProviderSelection_type_name_constant")] | ||
| [InlineData(ProviderSelection.RemoteActorRefProvider)] | ||
| [InlineData(ProviderSelection.ClusterActorRefProvider)] | ||
| public void Should_resolve_an_IActorRefProvider_When_loading_a_ProviderSelection_type_name_constant(string typeName) | ||
| { | ||
| var providerType = Type.GetType(typeName); | ||
|
|
||
| providerType.Should().NotBeNull( | ||
| $"[{typeName}] must stay resolvable - ActorSystemImpl resolves built-in providers from these constants"); | ||
| typeof(IActorRefProvider).IsAssignableFrom(providerType).Should().BeTrue( | ||
| $"[{typeName}] must name an {nameof(IActorRefProvider)} implementation"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,43 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="ProviderSelectionSpec.cs" company="Akka.NET Project"> | ||
| // Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com> | ||
| // Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
| // </copyright> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| #nullable enable | ||
|
|
||
| using Akka.Actor; | ||
| using Akka.Configuration; | ||
| using FluentAssertions; | ||
| using Xunit; | ||
|
|
||
| namespace Akka.Tests.Actor | ||
| { | ||
| /// <summary> | ||
| /// <c>ActorSystemImpl.ConfigureProvider</c> only takes the trimmer-friendly | ||
| /// <see cref="LocalActorRefProvider"/> branch when <see cref="ProviderSelection.GetProvider"/> maps the | ||
| /// configured provider onto <see cref="ProviderSelection.Local"/>, so every spelling of the local provider | ||
| /// type name has to land there - including the bare one that ships in <c>akka.conf</c>. | ||
| /// </summary> | ||
| public class ProviderSelectionSpec | ||
| { | ||
| [Theory(DisplayName = "Should_return_Local_When_GetProvider_is_given_a_local_provider_type_name")] | ||
| [InlineData("local")] // the alias | ||
| [InlineData("Akka.Actor.LocalActorRefProvider")] // the bare type name that ships in akka.conf | ||
| [InlineData(ProviderSelection.LocalActorRefProvider)] // "Akka.Actor.LocalActorRefProvider, Akka" | ||
| public void Should_return_Local_When_GetProvider_is_given_a_local_provider_type_name(string providerClass) | ||
| { | ||
| ProviderSelection.GetProvider(providerClass) | ||
| .Should().BeSameAs(ProviderSelection.Local.Instance); | ||
| } | ||
|
|
||
| [Fact(DisplayName = "Should_report_the_assembly_qualified_local_provider_name_When_the_default_config_is_used")] | ||
| public void Should_report_the_assembly_qualified_local_provider_name_When_the_default_config_is_used() | ||
| { | ||
| var settings = new Settings(null, ConfigurationFactory.Default()); | ||
|
|
||
| settings.ProviderSelectionType.Should().BeSameAs(ProviderSelection.Local.Instance); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -79,6 +79,8 @@ internal static ProviderSelection GetProvider(string providerClass) | |
| switch (providerClass) | ||
| { | ||
| case "local": | ||
| case "Akka.Actor.LocalActorRefProvider": // additional case for the bare type name used by akka.conf | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good, adds a measure of backwards compat |
||
| case LocalActorRefProvider: // additional case for older configurations | ||
| return Local.Instance; | ||
| case "remote": | ||
| case RemoteActorRefProvider: // additional case for older configurations | ||
|
|
||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -97,11 +97,20 @@ public Settings(ActorSystem system, Config config, ActorSystemSetup setup) | |
| ProviderClass = ProviderSelectionType.Fqn; | ||
| HasCluster = ProviderSelectionType.HasCluster; | ||
|
|
||
| var providerType = Type.GetType(ProviderClass); | ||
| if (providerType == null) | ||
| throw new ConfigurationException($"'akka.actor.provider' is not a valid type name : '{ProviderClass}'"); | ||
| if (!typeof(IActorRefProvider).IsAssignableFrom(providerType)) | ||
| throw new ConfigurationException($"'akka.actor.provider' is not a valid actor ref provider: '{ProviderClass}'"); | ||
| // The three built-in providers do not need to be validated here: their type names are | ||
| // compile-time constants and ActorSystemImpl.ConfigureProvider resolves each one from | ||
| // its own constant so the trimmer / Native AOT compiler can keep the type. Validating | ||
| // them through the ProviderClass property would reintroduce a dynamic Type.GetType call | ||
| // that the trimmer cannot see through (IL2057), and under Native AOT it would fail here | ||
| // even though the provider itself is perfectly resolvable. | ||
| if (ProviderSelectionType is ProviderSelection.Custom) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM |
||
| { | ||
| var providerType = Type.GetType(ProviderClass); | ||
| if (providerType == null) | ||
| throw new ConfigurationException($"'akka.actor.provider' is not a valid type name : '{ProviderClass}'"); | ||
| if (!typeof(IActorRefProvider).IsAssignableFrom(providerType)) | ||
| throw new ConfigurationException($"'akka.actor.provider' is not a valid actor ref provider: '{ProviderClass}'"); | ||
| } | ||
|
|
||
| SupervisorStrategyClass = Config.GetString("akka.actor.guardian-supervisor-strategy", null); | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validates that the constant is correct - makes sense.