Does anyone use the push/pop_unsafe! macros?


#1

Are they pulling their weight? Can we remove them? (Obviously, we’d need a crater run to do this, but checking to see if anyone can just tell me ‘yes’ first).


#2

cc @pnkfelix


#3

Since things like placement-in need them to work correctly, how are you planning to replace them (just curious)?


#4

@nrc yes, how are you planning to recover “unsafety hygiene” without these macros?


#5

Maybe the use of unsafe can become more precise? (Not sure if that’ll quite retain the right semantics.)

E.g. I believe in p { f() } becomes something like:

let mut place = p.make_place();
let ptr = place.pointer();
unsafe {
     ptr::write(ptr, f());
     place.finalize()
}

but maybe it could become

let mut place = p.make_place();
let ptr = place.pointer();
let val = f(); // pulled out of the `unsafe`
unsafe {
     ptr::write(ptr, val);
     place.finalize()
}

#6

The reason we didn’t do this is because the generated code results in a temporary. We might, however, be able to optimize this away once the transition to MIR is done.


#7

To be clear I’m not proposing removing the AST nodes*, only the actual macros. So placement in and whatever will still be able to generate the code, it’s just you won’t be able to actually use the macros as an author.

  • I do actually want to remove the AST nodes, I’ve moved the desugaring to the HIR lowering step, so I will keep the HIR nodes, but I want to remove the AST ones. But I can’t do that because of the macros - which is why I want to remove them.