Can we support stackful coroutines / fibers?

Aperta
#602 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
20/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
rust

Direzione di ricerca

Start with the issue and its linked LLVM discussion about TLS variables, then review how Rust currently handles thread-local storage and stack switching. No implementation entry point or test is named; the work would need an agreed support design and a defined way to validate that stackful coroutines avoid the described unsoundness.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

A-missing

Rust has no official support for using stackful coroutines (such as the fiber APIs on Windows, or doing the same with inline asm stack switching on Linux) -- but people do it anyway so there's clearly a demand (Cc @Amanieu). However, this means that the addresses of TLS variables can change basically any time, which is unsound as LLVM assumes the opposite (https://github.com/llvm/llvm-project/issues/98479). Cc @nikic

So, right now doing stack switching or using the Windows fiber API in Rust is pretty much UB (at least if the code also uses thread-local variables, which std does so that's basically a given). There's little we can do about that until LLVM has a way of avoiding that UB, but it seems worth tracking this on the Rust side and maybe brainstorming ideas about how stackful coroutines could be supported without pessimizing all optimizations everywhere: the fundamental issue is that any function call might change the thread this function runs on, so all thread-local variables have to be re-loaded, but most function calls don't actually do that so usually this is a pointless pessimization.

Lingua principale
Nessun dato sulla lingua
Stelle
760
Fork
68
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/unsafe-code-guidelines

Tutte le issue di rust-lang/unsafe-code-guidelines

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.