Static generics


#1

Allow statics in function generics:

fn post_event<T: Event + ?Sized, static STUFF: AtomicUsize = ATOMIC_USIZE_INIT, static STUFF_INIT: Once = ONCE_INIT>(bus: &EventBus, event: &mut T) -> bool {
STUFF_INIT.call_once(|| initialization routine that uses STUFF);
let id = STUFF.load(Relaxed);
let downcasted_any = EVERYTHING[id].downcast_ref::<Handlers<T>>().expect("something");
// skipped
}

If the caller doesn’t specify where the statics are stored, and the default values are consts, they will be created at the call site with the specified const initializers. This allows a little code generation that’s not as powerful as macros and as such doesn’t need the ! at the end and can actually interact with the type system for once.

This allows high-performance code without adding “macro fns” like I suggested elsewhere.


" Rust is a systems programming language that runs blazingly fast, […] " - rust-lang.org

(* unless you’re trying to write high-performance code in 100% safe rust.)


[WIP, Pre-RFC] statics inside <...> and fixing unsoundness bugs
[WIP, Pre-RFC] statics inside <...> and fixing unsoundness bugs
#2

This syntax does not look like it creates statics at the calls site,maybe you could change the syntax to be more evocative of what it’s doing.

I think it would be more obvious if the syntax was out static STUFF: AtomicUsize = ATOMIC_USIZE_INIT,and the syntax you have now was reserved for passing pre-existing statics.


#3

hmm, fair enough. I’m not sure I like that syntax tho.

and you can still specify your own statics, for further optimization. (in the event example, if you’re posting the same event in many places)


#4

Sooo, how would a function call be an expression if the “return value” simultaneously needs to be an item (declaration) too?


#6
let foo = fn_call();
// becomes
let foo = {
static FOO: ... = ...;
static BAR: ... = ...;
fn_call<FOO, BAR>()
}

?