Skip to content

runtime: move internals to internal/runtime #65355

Open
@prattmic

Description

@prattmic

Right now package runtime appears to serve two purposes:

  • It contains most of the implementation of the Go runtime.
  • And, it exposes the world-public API for various runtime-related functionality (runtime.GOMAXPROCS, etc).

At first glance, this seems perfectly normal and reasonable, however there is actually a third purpose:

  • Expose std-internal APIs that should not be world-public. e.g., runtime.semacquire for sync.Mutex or runtime.netpollopen for os and net.

These APIs should not be public to the whole world as they are implementation details that may change. However, with the current layout there is no good way to expose these internal APIs, so we must use //go:linkname between packages, and in some cases copy entire type definitions between packages (#64549).

If we move most of the runtime implementation to internal/runtime, then it could expose a richer API surface useful to other packages in std, but nothing outside of std would be able to access them due to the rules of internal. Package runtime would remain to provide the same API, but it would be much smaller and simply import internal/runtime for most functionality.

In moving, there are also opportunities for cleanup along the lines of #51087. e.g., perhaps the timer implementation is in internal/runtime/timer, etc. Though this move isn't really a prerequisite for that; we could do that in runtime/internal/timer as well.

This change would technically be solely an implementation detail, though in practice there are likely symbols that folks depend on anyway, either via linkname (https://go.dev/cl/548235) or implicitly by looking for in profiles, stack traces, etc.

cc @golang/runtime

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    In Progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions