Native Reflection in Rust
jack.wrenn.fyi
Native Reflection in Rust
1–10 of 68 posts
Re: Native Reflection in Rust
#2Very impressive work!
Re: Native Reflection in Rust
#3Re: Native Reflection in Rust
#4This is a beautiful (hacky) demo of something that I didn't think was possible in Rust (yet). I hope other applications don't accidentally start using it just to discover that it doesn't work in release mode. Very impressive work!
Re: Native Reflection in Rust
#5Today I learn that Rust does not have reflection.
Re: Native Reflection in Rust
#6Today I learn that Rust does not have reflection.
Reflection is usually not available in AoT compiled languages. The prevalent Rust coding styles rely heavily on monomorphic data types and functions, meaning there's nothing left to reflect at runtime. But if you want to deal with trait objects and need to access the underlying type, you need to use Any::downcast or rely on annotations on every type you want to reflect on. Or now, leverage DWARF info on Linux with de…
Re: Native Reflection in Rust
#7Today I learn that Rust does not have reflection.
Re: Native Reflection in Rust
#8Today I learn that Rust does not have reflection.
Reflection is typically provided by a runtime, and languages that don't have runtimes usually don't have it. You shouldn't expect a low-level systems language to have reflection. There is no zero-cost way of implementing it.
Re: Native Reflection in Rust
#9Earlier quoted context omitted.
Reflection is usually not available in AoT compiled languages. The prevalent Rust coding styles rely heavily on monomorphic data types and functions, meaning there's nothing left to reflect at runtime. But if you want to deal with trait objects and need to access the underlying type, you need to use Any::downcast or rely on annotations on every type you want to reflect on. Or now, leverage DWARF info on Linux with de…
What are monomorphic data types? What should be my first read on the subject?
struct Foo(T);
And you create Foo(42i32) and Foo(0.0f64), the compiler will create the equivalent to struct Fooi32(i32);
struct Foof64(f64);
In other languages like Java, generics are implemented the way that Rust does "trait objects" (&dyn Trait).Rust is not the only language that does this, to be clear.
If you're interested in a quick intro on the compiler side of this, you can read https://rustc-dev-guide.rust-lang.org/backend/monomorph.html
Re: Native Reflection in Rust
#10Regardless, quite an ingenious use of standard ELF features, I didn't think this would be possible in Rust without adding some kind of VM around reflection code.