Allow marking rust functions unsafe - #120
Conversation
602c479 to
af06dbc
Compare
| if is_safe { | ||
| let loops = (0..inputs.len()).map(|_| "loop {}").join(", "); | ||
| wln!( | ||
| self, | ||
| " const {{ let _verify_safety = || {{ #[allow(unreachable_code)] let _ = {}({}); }}; }};", | ||
| rust_name, | ||
| loops | ||
| ); | ||
| } |
There was a problem hiding this comment.
So no check for other direction?
There was a problem hiding this comment.
No, I don't want to force that since I think there are reasons you might want to define a function as unsafe for the bridge since C++ doesn't have a borrow checker. I understand it doesn't do anything technically, but it's still good documentation
| fn new() -> Vec<crate::KeyValuePair>; | ||
| fn push(&mut self, crate::KeyValuePair); | ||
| fn get(&self, usize) -> ::std::option::Option<&crate::KeyValuePair> deref [crate::KeyValuePair]; | ||
| fn get<usize>(&self, usize) -> ::std::option::Option<&crate::KeyValuePair> deref [crate::KeyValuePair]; |
There was a problem hiding this comment.
Now these are going to be template specialization in the C++ side instead of overloaded function? Can we still have multiple instantiation? IIRC there were some difficulties on template specialization of the methods. An example which uses multiple instantiations of a single function may help.
There was a problem hiding this comment.
Done. It works fine. Also, @hkalbasi, here's another situation you need to use __zngur_internal_assume_init since as far as I can tell there's no way to construct a RangeFull in C++ (the only constructor is RangeFull in rust which can't be mapped to C++'s)
af06dbc to
a55c02e
Compare
a55c02e to
66467a7
Compare
Note: This change requires that functions specializations are explicit on the Rust side, whereas before you could leave the specialized type out of the .zng declaration since the compiler was smart enough to figure out those specializations.