-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Remove runtime system, and move libgreen into an external library #230
Conversation
From a library standpoint: From an embedded systems standpoint: |
@mcpherrinm: You lose the ability to swap out the runtime dynamically but you could still provide a different implementation for a kernel and build high-level libraries against it. I think the vast majority of code that's interesting for a kernel will live at a lower level than a dependency on the full standard library though. |
I agree that this is a downside. But note that these pitfalls already exist with the current runtime system -- there are many innocent-looking ways to invoke blocking computation on a green thread that will block the underlying worker.
I also agree with the downside you point out for embedded systems. It's the usual tradeoff: having a layer of indirection as we do today is more flexible, but comes at a performance and binary size cost, and straps us to an abstraction of system capabilities that is often too limiting. I don't see any way out of this tradeoff, sadly. |
Great job on the writeup @aturon! |
Hmm? I'd think would be good for embedded / exokernel rust. Libnative will contain the bulk of the posix-, libc- or os- specific code backing the |
@Ericson2314 I think what @mcpherrinm was getting at is that, in today's setup, the By contrast, this RFC proposes to make I don't think that's a huge deal in terms of the actual programing involved (it should be roughly equivalent), but it means you can't just use an external crate. |
While we're at it renaming |
Why rename |
Oof, I should've spelled that out in the RFC. The crate includes a lot of (platform-specific) stuff beyond libc, and under the RFC the set of bindings would certainly grow. The idea was just to move all system bindings that are needed into one place. There's some relationship to this earlier RFC that proposed to more aggressively centralize all platform-specific code, which is something we might want to consider as part of this refactoring. |
@retep998 I could imagine breaking up the current |
Ah I see. I was just thinking: it would be very nice if one could specify that their crate or cargo package provides the functionality of another crate or package. This would make linking the rest of std with a custom
Well, not to be a broken record, but I'd love any facade system that differentiated between C/POSIX standard C bindings, and kernel syscalls (even if for now the syscalls are just called via C). |
Because |
6357402
to
e0acdf4
Compare
Things like logging do concern me a bit when trying to use alternative threading libraries instead of This approach has a few benefits:
If it weren't for liblog, I'd say this should just be provided by cargo as the RFC suggests, but I can't think of any good way for liblog to integrate with the cargo package unless liblog itself actually defines the TLS key and the I/O API. Not only is that out of scope for liblog, but that's functionally identical to just keeping this minimal renamed rustrt crate. I'm not sure right now what it should be renamed to, but I do think it should be renamed if it's no longer actually the "rust runtime". Note that I'm not advocating for keeping libgreen as well. That can still be moved to cargo. |
It should be shown to be useful on a real world workload before the standard library expends any effort trying to support it. It doesn't make sense to add complexity and a maintenance burden without getting anything useful out of it. A good logging library needs to support flexible targets anyway. |
@kballard I agree with @thestinger here: for now we should strive for maximal simplicity, and wait until it's clear what form of green threads, if any, is actually desired in the long run. My sense at the moment is that we will definitely want to support truly lightweight threads (as laid out in this RFC), but it's much less clear that we'll want anything like Rust's current notion of green threads in the future. This will mean that, if we want |
Ok, fair enough. I'm still hoping we can get basic support back in the standard libraries so code using liblog will behave acceptably in a green-threading situation (notably, because the standard libraries themselves use liblog), but I can accept that this is something that can be done later after experimenting with it as a cargo package. |
Logging in particular needs higher level configuration about where the I/O has to go to (whether network, shared memory, logfiles, the terminal, etc) if we want a robust and useful logging framework. Maybe we should just roll the lower level concerns (how to do that I/O) into some mechanism like that. It's really just moving the dynamic dispatch for I/O into the liblog though, which feels kinda bad. |
We already have the ability to change the logging implementation. Log calls route through a task local I think we can slightly expand that system (we'd want some ability to have subtasks inherit their parent tasks's logger in some way) and that should provide enough flexibility for third party logging frameworks to hook in. Trying to turn |
Merged as RFC 62. Discussion. Tracking. |
This PR includes a sequence of commits that gradually dismantles the `librustrt` `rtio` system -- the main trait previously used to abstract over green and native io. It also largely dismantles `libnative`, moving much of its code into `libstd` and refactoring as it does so. TL;DR: * Before this PR: `rustc hello.rs && wc -c hello` produces 715,996 * After this PR: `rustc hello.rs && wc -c hello` produces 368,100 That is, this PR reduces the footprint of hello world by ~50%. This is a major step toward #17325 (i.e. toward implementing the [runtime removal RFC](rust-lang/rfcs#230).) What remains is to pull out the scheduling, synchronization and task infrastructure, and to remove `libgreen`. These will be done soon in a follow-up PR. Part of the work here is eliminating the `rtio` abstraction, which in many cases means bringing the implementation of io closer to the actual API presented in `std::io`. Another aspect of this PR is the creation of two new, *private* modules within `std` that implement io: * The `sys` module, which represents a platform-specific implementation of a number of low-level abstractions that are used directly within `std::io` and `std::os`. These "abstractions" are left largely the same as they were in `libnative` (except for the removal of `Arc` in file descriptors), but they are expected to evolve greatly over time. Organizationally, there are `sys/unix/` and `sys/windows/` directories which both implement the entire `sys` module hierarchy; this means that nearly all of the platform-specific code is isolated and you can get a handle on each platform in isolation. * The `sys_common` module, which is rooted at `sys/common`, and provides a few pieces of private, low-level, but cross-platform functionality. In the long term, the `sys` modules will provide hooks for exposing high-level platform-specific APIs as part of `libstd`. The first such API will be access to file descriptors from `std::io` abstractions, but a bit of design work remains before that step can be taken. The `sys_common` module includes some traits (like `AsFileDesc`) which allow communication of private details between modules in disparate locations in the hierarchy; this helps overcome the relatively simple hierarchical privacy system in Rust. To emphasize: the organization in `sys` is *very preliminary* and the main goal was to migrate away from `rtio` as quickly and simply as possible. The design will certainly evolve over time, and all of the details are currently private. Along the way, this PR also entirely removes signal handling, since it was only supported on `librustuv` which was removed a while ago. Because of the removal of APIs from `libnative` and `librustrt`, and the removal of signal handling, this is a: [breaking-change] Some of these APIs will return in public from from `std` over time. r? @alexcrichton
This PR includes a sequence of commits that gradually dismantles the `librustrt` `rtio` system -- the main trait previously used to abstract over green and native io. It also largely dismantles `libnative`, moving much of its code into `libstd` and refactoring as it does so. TL;DR: * Before this PR: `rustc hello.rs && wc -c hello` produces 715,996 * After this PR: `rustc hello.rs && wc -c hello` produces 368,100 That is, this PR reduces the footprint of hello world by ~50%. This is a major step toward #17325 (i.e. toward implementing the [runtime removal RFC](rust-lang/rfcs#230).) What remains is to pull out the scheduling, synchronization and task infrastructure, and to remove `libgreen`. These will be done soon in a follow-up PR. Part of the work here is eliminating the `rtio` abstraction, which in many cases means bringing the implementation of io closer to the actual API presented in `std::io`. Another aspect of this PR is the creation of two new, *private* modules within `std` that implement io: * The `sys` module, which represents a platform-specific implementation of a number of low-level abstractions that are used directly within `std::io` and `std::os`. These "abstractions" are left largely the same as they were in `libnative` (except for the removal of `Arc` in file descriptors), but they are expected to evolve greatly over time. Organizationally, there are `sys/unix/` and `sys/windows/` directories which both implement the entire `sys` module hierarchy; this means that nearly all of the platform-specific code is isolated and you can get a handle on each platform in isolation. * The `sys_common` module, which is rooted at `sys/common`, and provides a few pieces of private, low-level, but cross-platform functionality. In the long term, the `sys` modules will provide hooks for exposing high-level platform-specific APIs as part of `libstd`. The first such API will be access to file descriptors from `std::io` abstractions, but a bit of design work remains before that step can be taken. The `sys_common` module includes some traits (like `AsFileDesc`) which allow communication of private details between modules in disparate locations in the hierarchy; this helps overcome the relatively simple hierarchical privacy system in Rust. To emphasize: the organization in `sys` is *very preliminary* and the main goal was to migrate away from `rtio` as quickly and simply as possible. The design will certainly evolve over time, and all of the details are currently private. Along the way, this PR also entirely removes signal handling, since it was only supported on `librustuv` which was removed a while ago. Because of the removal of APIs from `libnative` and `librustrt`, and the removal of signal handling, this is a: [breaking-change] Some of these APIs will return in public from from `std` over time. r? @alexcrichton
This PR completes the removal of the runtime system and green-threaded abstractions as part of implementing [RFC 230](rust-lang/rfcs#230). Specifically: * It removes the `Runtime` trait, welding the scheduling infrastructure directly to native threads. * It removes `libgreen` and `libnative` entirely. * It rewrites `sync::mutex` as a trivial layer on top of native mutexes. Eventually, the two modules will be merged. * It hides the vast majority of `std::rt`. This completes the basic task of removing the runtime system (I/O and scheduling) and components that depend on it. After this lands, a follow-up PR will pull the `rustrt` crate back into `std`, turn `std::task` into `std::thread` (with API changes to go along with it), and completely cut out the remaining startup/teardown sequence. Other changes, including new [TLS](rust-lang/rfcs#461) and synchronization are in the RFC or pre-RFC phase. Closes #17325 Closes #18687 [breaking-change] r? @alexcrichton
1. `libnative` has been removed from the rust standard library. Please consult rust-lang/rfcs#230 2. Updated project dependencies.
1. `libnative` has been removed from the rust standard library Please consult rust-lang/rfcs#230 2. Updated project dependencies 3. Apply `glfw-rs` API update
Also rename done => result, and add a bunch of reexports for all the old names. For now the `Result` type is exported as `FutureResult` to prevent conflict with the `Result` type (very likely to happen), but we should change that as part of 0.2. Closes rust-lang#230
This RFC proposes to remove the runtime system that is currently part of the
standard library, which currently allows the standard library to support both
native and green threading. In particular:
libgreen
crate and associated support will be moved out of tree, into aseparate Cargo package.
librustrt
(the runtime) crate will be removed entirely.std::io
implementation will be directly welded to native threads andsystem calls.
std::io
module will remain completely cross-platform, though separateplatform-specific modules may be added at a later time.
Rendered
This is a follow-up to an earlier RFC.