-
Notifications
You must be signed in to change notification settings - Fork 58
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
Should Rust permit conversions between pointers to data and pointers to functions? #309
Comments
Disallowing data <-> function pointer/reference casting makes static (and in some cases, dynamic) analysis simpler. It would be easy to add an opaque Note that you probably don't want to have |
One of the other reasons for this limitation is the Harvard architecture. Any hardware using that architecture has two entirely separate namespaces for data and function pointers, which may be differing sizes, and may overlap each other. I'm not sure if there are any modern architectures that are designed like that, but the AVR and PIC are definitely architectures I could see Rust being used on. |
@Nemo157 I like what I understand is the LLVM approach of supporting multiple address spaces, where any type of object can go anywhere, and higher layers enforce if certain types are restricted to certain address spaces. |
If you write a JIT or use thunks in Rust, you'll need to do this. I think writing a JIT or using thunks is a pretty legitimate use case that Rust should support (unsafely). |
@jethrogb I would argue that falls under "implementation defined". I don't even think it's possible to write a cross-platform JIT. |
@ubsan: Sure, but that's distinct from it being UB. An implementation may take implementation-defined behavior and say it's undefined, but not vice-versa. Relying on UB is always wrong; relying on implementation-defined behavior is valid if you condition on the implementation. In C, this is UB, not implementation-defined behavior - if Rust makes it implementation-defined, that is itself a change. |
@eternaleye I don't believe it is. At least in C++:
(for |
Apparently, C and C++ differ here. I do not get C... |
From rust-lang/rfcs#1861 (comment)
Note that this requires having function pointer types, which we currently do not , and was something I thought RFC 1861 might make possible - the closest is a kind of "function reference of static lifetime" that is syntactically not a reference at all :(
The text was updated successfully, but these errors were encountered: