Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.
This repository was archived by the owner on May 29, 2025. It is now read-only.

Make std fully pluggable #4

@jethrogb

Description

@jethrogb

@Ericson2314 do you want to write the text for this one?


@Ericson2314 taking a stab at it per @jethrogb's request:

Much the various abstractions in std require different implementations on different platforms. Currently, they are implemented for linux, windows, and macos in situ. The advantage of this is dispatch is fully static (done at compile time). The disadvantages of this is

  1. It is not modular: it is often necessary to fork std to implement an additional platform, which ties one to a specific version of Rust with the costs of rebases. Even though the Rust team is willing to upstream ports of std to obscure platforms, avoiding the rebase penalty, that work-around will never be totally sufficient because many of us want to develop the platform and the std port simultaneously (e.g. std userland over kernel, or std directly against os-as-a-library).

  2. The interface is not checked: There is no automatic verification that the implementations present the same interface (at least the portion we wish to be the same).

As it turns out, these goals are fairly harmonious. As we better define the platform-specific "input interfaces" which are abstracted into std's "output interface", we get both the intended interface for platform-specific crate(s) that can live outside of std, and a mechanism for enforcing that the std interfaces are maintained.

The problem is a a fully perfect solution solution probably requires a lot of language work. The https://github.com/rust-lang/rfcs/blob/master/text/1868-portability-lint.md is needed when different parts of the same crate have different portability requirements, which at least will be the case with std itself but possibly also various platform-specific infra. [Imagine a general "Unix filesystem" implementation which is augmented with linux- or macos-specific functionality.] Also, if we need to "weave" together platform-specific and platform-agnostic functionality in increasingly complex (higher-order, in particular) ways, we will need a more expressive module system like ML's (read about "ML functors" if you are unfamiliar with this.)

Historically, our biggest problem in solving this are that

  • library refactors bit-rot quickly, yet require decent buy-in
  • language features require even more buy-in
  • difficulty in incremental progress makes it hard to build up momentum needed for more ambitious changes

Taking a step back, requirements are

  • No dynamic dispatch. That rules out trait objects.
  • No complicating user-facing types (even if back-compat is preserved). That rules out traits without functions wrapping their methods.
  • Platform-specific types, not just functions (e.g. file descriptors). That rules low-level linking tricks on their own.
  • No platform-specific panicking on missing behavior. If it builds, it should work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions