Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upGlobal resource handling #3
Comments
This comment has been minimized.
This comment has been minimized.
|
The perfect general solution need be ML modules, or something else that's just as big a change. But there is a more incremental solution on top of rust-lang/rust#27389 . Basically the pattern there is there is some ZST which implements a trait by calling the methods on the user-defined static. We could replace |
Ericson2314
referenced this issue
Mar 7, 2018
Closed
Tracking issue for changing the global, default allocator (RFC 1974) #27389
This comment has been minimized.
This comment has been minimized.
|
@aturon In our meeting you mentioned event loops are a global resource. Why? If you are currently a task running on an event loop, you should be able to figure that out somehow (e.g. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Missing from the current allocator API design is a good way to hook into the selected global singleton. There's a lot of compiler magic to make it work for what's tagged See https://github.com/rust-lang/rust/blob/master/src/librustc_allocator/expand.rs and https://github.com/rust-lang/rust/blob/master/src/librustc/middle/allocator.rs I guess the only way to do this kind of dependency inversion in Rust today is with a |
This comment has been minimized.
This comment has been minimized.
|
How about leveraging // liballoc
pub mod allocator {
pub unsafe trait Alloc { /* ... */ }
}
pub mod heap {
extern {
#[global="allocator"]
static HEAP: impl ::allocator:Alloc;
}
}// liballoc_system
use alloc::allocator::Alloc;
struct System;
impl Alloc for System { /* ... */ }
#[global="allocator"]
static SYSTEM_ALLOCATOR: System = System; |
This comment has been minimized.
This comment has been minimized.
|
Is there an issue using existing/"boring" pub mod heap {
extern {
// Static trait object because an anonymous `impl` type can't be simply linked
static HEAP_IMPL: &::allocator::Alloc;
}
}#[no_mangle]
static HEAP_IMPL: &Alloc = &System;Naively this looks like it would have some runtime overhead from the vtable, but... it's static? I would hope it would be eligible for inlining or LTO or whatever. Not sure if we can do good error reporting if someone includes two global allocators, though. |
This comment has been minimized.
This comment has been minimized.
|
I guess that's possible. I'm not a big fan because:
|
This comment has been minimized.
This comment has been minimized.
|
Yeah, fair enough. What's your vision on how the compiler should see an |
This comment has been minimized.
This comment has been minimized.
|
rust-lang/rfcs#2492 is an RFC for this. |
This comment has been minimized.
This comment has been minimized.
|
(@pitdicker I'm sorry to say I didn't include the |
jethrogb commentedMar 7, 2018
•
edited
Often, global decisions affecting the entire dependency tree need to be made.
Current examples of this in
stdare panic behavior and the global allocator.Outside of
stdthere are logging and event loops, standard RNG.This issue proposes to come up with a generic system that works for all such cases.