2 ms·
> This inline type field is key for fast and effective type checks for all casts, similar to other type-safe languages (e.g., Java or Rust). I am not a Java ex
by tialaramex 2y ago
> This inline type field is key for fast and effective type checks for all casts, similar to other type-safe languages (e.g., Java or Rust).
I am not a Java expert but I know enough Rust to detect a problem here. Maybe it just needs clarification?
Rust is often not in fact storing the "inline type field", so presumably they're thinking of some very particular cast and not "all casts". But what cast?
some_f64 as i32 // Nope, that's going to emit code to work out the closest integer
<&str>::try_from(filename).unwrap() // Nope, that's just going to check the filename is UTF-8 encoded
OK, they talk about "down casts" Rust doesn't have inheritance, but presumably they're thinking of e.g how you go from an IpAddr to an Ipv4Addr ? And now at last it makes a little sense, yes we do need to store the difference between v4 and v6 in the data structure. But, what I do not understand is, how can the equivalent C++ (without type++) do anything reasonable here? Why would this be a bug people repeatedly trip? I know C++ is famously the language for footguns, but this is some gets() level stuff if the "no type info YOLO cast" is a thing people actually write.
- wakawaka28 2y agoI think what they are proposing is to replace existing RTTI with their version that actually supports ALL objects, not just directly allocated ones. I assume there is some complex RTTI analysis that goes into determining whether a thing can be cast at runtime, and that check may be omitted if it's not possible to do it. If you pass a stack-allocated variable somewhere by reference, for example, is there any RTTI available on the original object to check a cast? I really don't know.
- gannimo 2y agoWe are forcing RTTI for all classes used in casts, some light code changes are required for this that our compiler will hint at.