Skip to content

Commit

Permalink
made ActorCell use nullable (#7475)
Browse files Browse the repository at this point in the history
* cleaning up `ActorCell` and enabling nullability

* working on nullability for `ActorCell`

* more nullability support

* finished with nullability warnings

* added API approvals

* added real XML-DOC comment

* Improve nullability implementation

* Add `NotNullWhen` compiler annotation attribute to all of the `bool TryX(out Y)` patterned functions
* Add assertions on all shebangs to make sure we document why the nullability check was overriden

* Update API Approval list

---------

Co-authored-by: Gregorius Soedharmo <[email protected]>
  • Loading branch information
Aaronontheweb and Arkatufus authored Jan 21, 2025
1 parent 429ebb2 commit 2ee5176
Show file tree
Hide file tree
Showing 13 changed files with 336 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,39 @@ namespace Akka.Actor
protected virtual void Unhandled(object message) { }
}
[System.Diagnostics.DebuggerDisplayAttribute("{Self,nq}")]
[System.Runtime.CompilerServices.NullableAttribute(0)]
public class ActorCell : Akka.Actor.IActorContext, Akka.Actor.IActorRefFactory, Akka.Actor.ICanWatch, Akka.Actor.ICell, Akka.Actor.IUntypedActorContext
{
public const int UndefinedUid = 0;
public ActorCell(Akka.Actor.Internal.ActorSystemImpl system, Akka.Actor.IInternalActorRef self, Akka.Actor.Props props, Akka.Dispatch.MessageDispatcher dispatcher, Akka.Actor.IInternalActorRef parent) { }
public Akka.Actor.Internal.IChildrenContainer ChildrenContainer { get; }
public int CurrentEnvelopeId { get; }
[System.Runtime.CompilerServices.NullableAttribute(2)]
public object CurrentMessage { get; }
public Akka.Dispatch.MessageDispatcher Dispatcher { get; }
public bool HasMessages { get; }
public bool IsLocal { get; }
protected bool IsNormal { get; }
public bool IsTerminated { get; }
protected bool IsTerminating { get; }
[System.Runtime.CompilerServices.NullableAttribute(2)]
public Akka.Dispatch.Mailbox Mailbox { get; }
public int NumberOfMessages { get; }
public Akka.Actor.IInternalActorRef Parent { get; }
public Akka.Actor.Props Props { get; }
public System.Nullable<System.TimeSpan> ReceiveTimeout { get; }
public Akka.Actor.IActorRef Self { get; }
[System.Runtime.CompilerServices.NullableAttribute(2)]
public Akka.Actor.IActorRef Sender { get; }
public Akka.Actor.ActorSystem System { get; }
public Akka.Actor.Internal.ActorSystemImpl SystemImpl { get; }
public virtual Akka.Dispatch.ActorTaskScheduler TaskScheduler { get; }
public virtual Akka.Actor.IActorRef ActorOf(Akka.Actor.Props props, string name = null) { }
public virtual Akka.Actor.IActorRef ActorOf(Akka.Actor.Props props, [System.Runtime.CompilerServices.NullableAttribute(2)] string name = null) { }
public Akka.Actor.ActorSelection ActorSelection(string path) { }
public Akka.Actor.ActorSelection ActorSelection(Akka.Actor.ActorPath path) { }
protected void AddWatcher(Akka.Actor.IActorRef watchee, Akka.Actor.IActorRef watcher) { }
protected void AddressTerminated(Akka.Actor.Address address) { }
public virtual Akka.Actor.IActorRef AttachChild(Akka.Actor.Props props, bool isSystemService, string name = null) { }
public virtual Akka.Actor.IActorRef AttachChild(Akka.Actor.Props props, bool isSystemService, [System.Runtime.CompilerServices.NullableAttribute(2)] string name = null) { }
protected virtual void AutoReceiveMessage(Akka.Actor.Envelope envelope) { }
public void Become(Akka.Actor.Receive receive) { }
public void BecomeStacked(Akka.Actor.Receive receive) { }
Expand All @@ -105,6 +109,7 @@ namespace Akka.Actor
public static Akka.Actor.IActorRef GetCurrentSenderOrNoSender() { }
public Akka.Actor.IInternalActorRef GetSingleChild(string name) { }
public void Init(bool sendSupervise, Akka.Dispatch.MailboxType mailboxType) { }
[return: System.Runtime.CompilerServices.NullableAttribute(2)]
public Akka.Actor.Internal.ChildRestartStats InitChild(Akka.Actor.IInternalActorRef actor) { }
public void Invoke(Akka.Actor.Envelope envelope) { }
protected virtual void PreStart() { }
Expand All @@ -113,14 +118,15 @@ namespace Akka.Actor
public void ReceiveMessageForTest(Akka.Actor.Envelope envelope) { }
protected void ReceivedTerminated(Akka.Actor.Terminated t) { }
protected void RemWatcher(Akka.Actor.IActorRef watchee, Akka.Actor.IActorRef watcher) { }
[return: System.Runtime.CompilerServices.NullableAttribute(2)]
protected Akka.Actor.Internal.SuspendReason RemoveChildAndGetStateChange(Akka.Actor.IActorRef child) { }
public void ReserveChild(string name) { }
public void Restart(System.Exception cause) { }
public void Resume(System.Exception causedByFailure) { }
public virtual void SendMessage(Akka.Actor.Envelope message) { }
public virtual void SendMessage(Akka.Actor.IActorRef sender, object message) { }
public virtual void SendSystemMessage(Akka.Dispatch.SysMsg.ISystemMessage systemMessage) { }
protected void SetActorFields(Akka.Actor.ActorBase actor) { }
protected static void SetActorFields(Akka.Actor.ActorBase actor) { }
protected bool SetChildrenTerminationReason(Akka.Actor.Internal.SuspendReason reason) { }
public void SetReceiveTimeout(System.Nullable<System.TimeSpan> timeout = null) { }
protected void SetTerminated() { }
Expand All @@ -135,7 +141,7 @@ namespace Akka.Actor
0,
1})] Akka.Util.Option<object> customMessage) { }
public bool TryGetChildStatsByName(string name, out Akka.Actor.Internal.IChildStats child) { }
protected bool TryGetChildStatsByRef(Akka.Actor.IActorRef actor, out Akka.Actor.Internal.ChildRestartStats child) { }
protected bool TryGetChildStatsByRef(Akka.Actor.IActorRef actor, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] [System.Runtime.CompilerServices.NullableAttribute(2)] out Akka.Actor.Internal.ChildRestartStats child) { }
public void UnbecomeStacked() { }
protected void UnreserveChild(string name) { }
public Akka.Actor.IActorRef Unwatch(Akka.Actor.IActorRef subject) { }
Expand Down Expand Up @@ -318,6 +324,7 @@ namespace Akka.Actor
}
public class static ActorRefs
{
[System.Runtime.CompilerServices.NullableAttribute(2)]
public static readonly Akka.Actor.IActorRef NoSender;
public static readonly Akka.Actor.Nobody Nobody;
}
Expand Down Expand Up @@ -2060,13 +2067,13 @@ namespace Akka.Actor.Internal
public virtual bool IsTerminating { get; }
public System.Collections.Generic.IReadOnlyCollection<Akka.Actor.Internal.ChildRestartStats> Stats { get; }
public abstract Akka.Actor.Internal.IChildrenContainer Add(string name, Akka.Actor.Internal.ChildRestartStats stats);
protected void ChildStatsAppender(System.Text.StringBuilder sb, System.Collections.Generic.KeyValuePair<string, Akka.Actor.Internal.IChildStats> kvp, int index) { }
protected static void ChildStatsAppender(System.Text.StringBuilder sb, System.Collections.Generic.KeyValuePair<string, Akka.Actor.Internal.IChildStats> kvp, int index) { }
public bool Contains(Akka.Actor.IActorRef actor) { }
public abstract Akka.Actor.Internal.IChildrenContainer Remove(Akka.Actor.IActorRef child);
public abstract Akka.Actor.Internal.IChildrenContainer Reserve(string name);
public abstract Akka.Actor.Internal.IChildrenContainer ShallDie(Akka.Actor.IActorRef actor);
public bool TryGetByName(string name, out Akka.Actor.Internal.IChildStats stats) { }
public bool TryGetByRef(Akka.Actor.IActorRef actor, out Akka.Actor.Internal.ChildRestartStats childRestartStats) { }
public bool TryGetByRef(Akka.Actor.IActorRef actor, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] [System.Runtime.CompilerServices.NullableAttribute(2)] out Akka.Actor.Internal.ChildRestartStats childRestartStats) { }
public abstract Akka.Actor.Internal.IChildrenContainer Unreserve(string name);
}
public class EmptyChildrenContainer : Akka.Actor.Internal.IChildrenContainer
Expand Down Expand Up @@ -2100,7 +2107,7 @@ namespace Akka.Actor.Internal
Akka.Actor.Internal.IChildrenContainer Reserve(string name);
Akka.Actor.Internal.IChildrenContainer ShallDie(Akka.Actor.IActorRef actor);
bool TryGetByName(string name, out Akka.Actor.Internal.IChildStats stats);
bool TryGetByRef(Akka.Actor.IActorRef actor, out Akka.Actor.Internal.ChildRestartStats stats);
bool TryGetByRef(Akka.Actor.IActorRef actor, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] [System.Runtime.CompilerServices.NullableAttribute(2)] out Akka.Actor.Internal.ChildRestartStats stats);
Akka.Actor.Internal.IChildrenContainer Unreserve(string name);
}
public interface IInitializableActor
Expand All @@ -2118,6 +2125,7 @@ namespace Akka.Actor.Internal
{
public static Akka.Actor.Internal.InternalActivateFsmLogging Instance { get; }
}
[System.Runtime.CompilerServices.NullableAttribute(0)]
public class static InternalCurrentActorCellKeeper
{
public static Akka.Actor.ActorCell Current { get; set; }
Expand Down Expand Up @@ -5646,7 +5654,9 @@ namespace Akka.Util.Internal
public static void AddOrSet<TKey, TValue>(this System.Collections.Generic.IDictionary<TKey, TValue> hash, TKey key, TValue value) { }
public static T AsInstanceOf<T>(this object self) { }
public static string BetweenDoubleQuotes(this string self) { }
public static System.Collections.Generic.IEnumerable<T> Concat<T>(this System.Collections.Generic.IEnumerable<T> enumerable, T item) { }
public static System.Collections.Generic.IEnumerable<T> Concat<[System.Runtime.CompilerServices.NullableAttribute(2)] T>([System.Runtime.CompilerServices.NullableAttribute(new byte[] {
2,
1})] this System.Collections.Generic.IEnumerable<T> enumerable, T item) { }
public static System.Collections.Generic.IEnumerable<T> Drop<T>(this System.Collections.Generic.IEnumerable<T> self, int count) { }
public static void ForEach<T>(this System.Collections.Generic.IEnumerable<T> source, System.Action<T> action) { }
public static TValue GetOrElse<TKey, TValue>(this System.Collections.Generic.IDictionary<TKey, TValue> hash, TKey key, TValue elseValue) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,39 @@ namespace Akka.Actor
protected virtual void Unhandled(object message) { }
}
[System.Diagnostics.DebuggerDisplayAttribute("{Self,nq}")]
[System.Runtime.CompilerServices.NullableAttribute(0)]
public class ActorCell : Akka.Actor.IActorContext, Akka.Actor.IActorRefFactory, Akka.Actor.ICanWatch, Akka.Actor.ICell, Akka.Actor.IUntypedActorContext
{
public const int UndefinedUid = 0;
public ActorCell(Akka.Actor.Internal.ActorSystemImpl system, Akka.Actor.IInternalActorRef self, Akka.Actor.Props props, Akka.Dispatch.MessageDispatcher dispatcher, Akka.Actor.IInternalActorRef parent) { }
public Akka.Actor.Internal.IChildrenContainer ChildrenContainer { get; }
public int CurrentEnvelopeId { get; }
[System.Runtime.CompilerServices.NullableAttribute(2)]
public object CurrentMessage { get; }
public Akka.Dispatch.MessageDispatcher Dispatcher { get; }
public bool HasMessages { get; }
public bool IsLocal { get; }
protected bool IsNormal { get; }
public bool IsTerminated { get; }
protected bool IsTerminating { get; }
[System.Runtime.CompilerServices.NullableAttribute(2)]
public Akka.Dispatch.Mailbox Mailbox { get; }
public int NumberOfMessages { get; }
public Akka.Actor.IInternalActorRef Parent { get; }
public Akka.Actor.Props Props { get; }
public System.Nullable<System.TimeSpan> ReceiveTimeout { get; }
public Akka.Actor.IActorRef Self { get; }
[System.Runtime.CompilerServices.NullableAttribute(2)]
public Akka.Actor.IActorRef Sender { get; }
public Akka.Actor.ActorSystem System { get; }
public Akka.Actor.Internal.ActorSystemImpl SystemImpl { get; }
public virtual Akka.Dispatch.ActorTaskScheduler TaskScheduler { get; }
public virtual Akka.Actor.IActorRef ActorOf(Akka.Actor.Props props, string name = null) { }
public virtual Akka.Actor.IActorRef ActorOf(Akka.Actor.Props props, [System.Runtime.CompilerServices.NullableAttribute(2)] string name = null) { }
public Akka.Actor.ActorSelection ActorSelection(string path) { }
public Akka.Actor.ActorSelection ActorSelection(Akka.Actor.ActorPath path) { }
protected void AddWatcher(Akka.Actor.IActorRef watchee, Akka.Actor.IActorRef watcher) { }
protected void AddressTerminated(Akka.Actor.Address address) { }
public virtual Akka.Actor.IActorRef AttachChild(Akka.Actor.Props props, bool isSystemService, string name = null) { }
public virtual Akka.Actor.IActorRef AttachChild(Akka.Actor.Props props, bool isSystemService, [System.Runtime.CompilerServices.NullableAttribute(2)] string name = null) { }
protected virtual void AutoReceiveMessage(Akka.Actor.Envelope envelope) { }
public void Become(Akka.Actor.Receive receive) { }
public void BecomeStacked(Akka.Actor.Receive receive) { }
Expand All @@ -105,6 +109,7 @@ namespace Akka.Actor
public static Akka.Actor.IActorRef GetCurrentSenderOrNoSender() { }
public Akka.Actor.IInternalActorRef GetSingleChild(string name) { }
public void Init(bool sendSupervise, Akka.Dispatch.MailboxType mailboxType) { }
[return: System.Runtime.CompilerServices.NullableAttribute(2)]
public Akka.Actor.Internal.ChildRestartStats InitChild(Akka.Actor.IInternalActorRef actor) { }
public void Invoke(Akka.Actor.Envelope envelope) { }
protected virtual void PreStart() { }
Expand All @@ -113,14 +118,15 @@ namespace Akka.Actor
public void ReceiveMessageForTest(Akka.Actor.Envelope envelope) { }
protected void ReceivedTerminated(Akka.Actor.Terminated t) { }
protected void RemWatcher(Akka.Actor.IActorRef watchee, Akka.Actor.IActorRef watcher) { }
[return: System.Runtime.CompilerServices.NullableAttribute(2)]
protected Akka.Actor.Internal.SuspendReason RemoveChildAndGetStateChange(Akka.Actor.IActorRef child) { }
public void ReserveChild(string name) { }
public void Restart(System.Exception cause) { }
public void Resume(System.Exception causedByFailure) { }
public virtual void SendMessage(Akka.Actor.Envelope message) { }
public virtual void SendMessage(Akka.Actor.IActorRef sender, object message) { }
public virtual void SendSystemMessage(Akka.Dispatch.SysMsg.ISystemMessage systemMessage) { }
protected void SetActorFields(Akka.Actor.ActorBase actor) { }
protected static void SetActorFields(Akka.Actor.ActorBase actor) { }
protected bool SetChildrenTerminationReason(Akka.Actor.Internal.SuspendReason reason) { }
public void SetReceiveTimeout(System.Nullable<System.TimeSpan> timeout = null) { }
protected void SetTerminated() { }
Expand All @@ -135,7 +141,7 @@ namespace Akka.Actor
0,
1})] Akka.Util.Option<object> customMessage) { }
public bool TryGetChildStatsByName(string name, out Akka.Actor.Internal.IChildStats child) { }
protected bool TryGetChildStatsByRef(Akka.Actor.IActorRef actor, out Akka.Actor.Internal.ChildRestartStats child) { }
protected bool TryGetChildStatsByRef(Akka.Actor.IActorRef actor, [System.Runtime.CompilerServices.NullableAttribute(2)] out Akka.Actor.Internal.ChildRestartStats child) { }
public void UnbecomeStacked() { }
protected void UnreserveChild(string name) { }
public Akka.Actor.IActorRef Unwatch(Akka.Actor.IActorRef subject) { }
Expand Down Expand Up @@ -318,6 +324,7 @@ namespace Akka.Actor
}
public class static ActorRefs
{
[System.Runtime.CompilerServices.NullableAttribute(2)]
public static readonly Akka.Actor.IActorRef NoSender;
public static readonly Akka.Actor.Nobody Nobody;
}
Expand Down Expand Up @@ -2058,13 +2065,13 @@ namespace Akka.Actor.Internal
public virtual bool IsTerminating { get; }
public System.Collections.Generic.IReadOnlyCollection<Akka.Actor.Internal.ChildRestartStats> Stats { get; }
public abstract Akka.Actor.Internal.IChildrenContainer Add(string name, Akka.Actor.Internal.ChildRestartStats stats);
protected void ChildStatsAppender(System.Text.StringBuilder sb, System.Collections.Generic.KeyValuePair<string, Akka.Actor.Internal.IChildStats> kvp, int index) { }
protected static void ChildStatsAppender(System.Text.StringBuilder sb, System.Collections.Generic.KeyValuePair<string, Akka.Actor.Internal.IChildStats> kvp, int index) { }
public bool Contains(Akka.Actor.IActorRef actor) { }
public abstract Akka.Actor.Internal.IChildrenContainer Remove(Akka.Actor.IActorRef child);
public abstract Akka.Actor.Internal.IChildrenContainer Reserve(string name);
public abstract Akka.Actor.Internal.IChildrenContainer ShallDie(Akka.Actor.IActorRef actor);
public bool TryGetByName(string name, out Akka.Actor.Internal.IChildStats stats) { }
public bool TryGetByRef(Akka.Actor.IActorRef actor, out Akka.Actor.Internal.ChildRestartStats childRestartStats) { }
public bool TryGetByRef(Akka.Actor.IActorRef actor, [System.Runtime.CompilerServices.NullableAttribute(2)] out Akka.Actor.Internal.ChildRestartStats childRestartStats) { }
public abstract Akka.Actor.Internal.IChildrenContainer Unreserve(string name);
}
public class EmptyChildrenContainer : Akka.Actor.Internal.IChildrenContainer
Expand Down Expand Up @@ -2098,7 +2105,7 @@ namespace Akka.Actor.Internal
Akka.Actor.Internal.IChildrenContainer Reserve(string name);
Akka.Actor.Internal.IChildrenContainer ShallDie(Akka.Actor.IActorRef actor);
bool TryGetByName(string name, out Akka.Actor.Internal.IChildStats stats);
bool TryGetByRef(Akka.Actor.IActorRef actor, out Akka.Actor.Internal.ChildRestartStats stats);
bool TryGetByRef(Akka.Actor.IActorRef actor, [System.Runtime.CompilerServices.NullableAttribute(2)] out Akka.Actor.Internal.ChildRestartStats stats);
Akka.Actor.Internal.IChildrenContainer Unreserve(string name);
}
public interface IInitializableActor
Expand All @@ -2116,6 +2123,7 @@ namespace Akka.Actor.Internal
{
public static Akka.Actor.Internal.InternalActivateFsmLogging Instance { get; }
}
[System.Runtime.CompilerServices.NullableAttribute(0)]
public class static InternalCurrentActorCellKeeper
{
public static Akka.Actor.ActorCell Current { get; set; }
Expand Down Expand Up @@ -5635,7 +5643,9 @@ namespace Akka.Util.Internal
public static void AddOrSet<TKey, TValue>(this System.Collections.Generic.IDictionary<TKey, TValue> hash, TKey key, TValue value) { }
public static T AsInstanceOf<T>(this object self) { }
public static string BetweenDoubleQuotes(this string self) { }
public static System.Collections.Generic.IEnumerable<T> Concat<T>(this System.Collections.Generic.IEnumerable<T> enumerable, T item) { }
public static System.Collections.Generic.IEnumerable<T> Concat<[System.Runtime.CompilerServices.NullableAttribute(2)] T>([System.Runtime.CompilerServices.NullableAttribute(new byte[] {
2,
1})] this System.Collections.Generic.IEnumerable<T> enumerable, T item) { }
public static System.Collections.Generic.IEnumerable<T> Drop<T>(this System.Collections.Generic.IEnumerable<T> self, int count) { }
public static void ForEach<T>(this System.Collections.Generic.IEnumerable<T> source, System.Action<T> action) { }
public static TValue GetOrElse<TKey, TValue>(this System.Collections.Generic.IDictionary<TKey, TValue> hash, TKey key, TValue elseValue) { }
Expand Down
Loading

0 comments on commit 2ee5176

Please sign in to comment.