Skip to content

Make std functions patchable on unsupported platforms #140451

Closed
@quininer

Description

@quininer

Currently std generates dummy functions and panics on unsupported platforms. using binary patch to replace dummy functions is a practical way to implement support externally. but since dummy functions are currently inlined and optimized away, this is not possible.

Make dummy functions more patch-friendly would be helpful to ecosystem. I did some experimentation to prove this is possible. see #140440

The main motivation for this change is to support std time on wasm without intrusive dependencies. see #48564

This does not require std to guarantee the stability of dummy functions, and it is always the responsibility of the person doing the binary patch to check that the patch is correct.

There are still some unresolved issues

  1. inline(never) is not enough to prevent all optimizations, other compiler flags are needed to prevent places where Instant::now() is used from being optimized away.
  2. binary patch does not work on other std functions. for example, the File type is actually ! on unsupported platforms.

cc @bjorn3 @ChrisDenton

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions