Skip to content

Avoid using shared_ptrs to mutable state

In many places, ACTS uses shared_ptrs to mutable state. This construct is problematic in two ways:

  • It is const-incorrect. A const method of an object with a shared_ptr-to-mutable member can modify the data it points to, which makes code harder to reason about and opens opportunities of data races.
  • It introduces non-local side effects. When a given object modifies an object to which it has a shared_ptr, it affects other objects, which again makes code harder to reason about, especially in a multi-threaded context.

Taking this into account, I propose that we generally avoid the use of shared_ptr-to-mutable, and only keep it in tightly controlled contexts such as during object creation, where it is known that only one thread or object will have access to the mutable entity.

This MR also has a couple of side-effects on more minor const-correctness matters, for example it eliminates functions with "const T" return type (which is generally meaningless in C++) and clarifies that the current version of GenericApproachDescriptor can only operate on const surfaces.

This fixes ACTS-306.

Merge request reports