New Issue: Rework of the dynamic loading package module

29257, "dlongnecke-cray", "Rework of the dynamic loading package module", "2026-08-13T21:19:29Z"

This issue is a proposal for how to rework the dynamic loading package module.

It records the results of a deep dive that was held on Aug 13th.

Related issues are: #27687, #29216, #29217

Largely agreed on points

  • Rename the module from DynamicLoading to DynamicLibrary
  • Rename the type from binary to dynamicLibrary
  • Move the load procedure from a type method to a standalone procedure at module scope
  • Introduce a loadFromPath procedure that is low level and just attempts to dynamically load a given path
  • Rework the load procedure to be more high-level
  • Introduce a type method on dynamicLibrary that returns a platform-specific file extension

Points of question

  • Should the type method to get the file extension be called fileExtension, fileExt, suffix`?
  • Are we happy with symbol names?

Rename the module to DynamicLibrary

module DynamicLibrary {

This matches what we tend to do for other modules that primarily serve to contain a type, e.g., List/list, or Map/map.

Rename the type to dynamicLibrary

record dynamicLibrary {

This follows the above convention. It also more accurately describes the type than binary, which could be misconstrued as an arbitrary piece of binary data.

Move the load procedure(s) to module scope

module DynamicLibrary {
  // ...
  proc load(...): dynamicLibrary;

This matches the convention used for other OS-driven functions such as IO.open() that are too complicated to be considered a simple factory function.

This makes the procedures easier to invoke:

import DynamicLibrary;

var lib = DynamicLibrary.load(...);

It gives users flexibility to rename the procedure or bring it into global scope in a way that a type method would not allow.

Introduce a loadFromPath procedure to load from a given path

module DynamicLibrary {
  // ...
  proc loadFromPath(path: string): dynamicLibrary;

This procedure is lower-level and serves as an escape valve for power users. It simply tries to load a dynamic library given a path. It does no interpretation or sanitation of the provided path.

It is also at module scope.

Rework the load procedure to be more high level

proc load(name: `string`, directory: `string`='',
                 namePrefix='lib',
                 nameSuffix=dynamicLibrary.fileExt);

The load procedure now computes a path to load and takes additional arguments. Some of the formals have default values.

The load procedure will compute a path from the given arguments. For example, given the arguments foo and path/to, it will compute: path/to/libfoo.so.

Additionally, the load procedure will perform sanitation of its arguments.

  • It will check to make sure that no path separators are present in name.
  • Additional sanitation (I forgot :sob:) ???

Introduce a type method on dynamicLibrary to return a platform-specific file extension

proc type dynamicLibrary.fileExt param: string;

This is a type method that returns so on Linux and dylib on windows, which are the expected names of dynamic libraries on each respective platform.

The name fileExt matches the abbreviation we use in the Path module for pathSep, so we can use it instead of fileExtension if necessary to make it shorter.

The name of this procedure has not been decided yet.