r/ProgrammingLanguages • • Aug 22 '26

Programming Language Semantics and Memory Safety

https://burakemir.ch/post/formal-semantics/
45 Upvotes

9 comments sorted by

View all comments

Show parent comment

2

u/matthieum Aug 23 '26

the semantics of the object code generated by a compiler is always a subset of the semantics of the source code

Absent compiler bugs, of course. The latest Rust release (1.98) contains a bug which you can see here where:

fn main() {
    if std::hint::black_box(true) {
        (&(inspect_websocket_message, PhantomData) as &dyn Trait).method();
    } else {
        println!("impossible");
    }
}

Prints impossible... due to the compiler introducing UB.