On the topic of reframing UB, I was reminded of an article about the mechanics of oaths and vows in historical cultures.
When a programmer writes
get_unchecked, we can imagine them wanting to promise the compiler that they uphold its preconditions. But since the compiler is normally not so trusting of unproven assertions, the programmer swears an oath that their argument is in bounds.
The compiler, seeing such a solemn commitment, treats the programmer's word as true and optimizes accordingly. The compiler is so thoroughly convinced that it never even entertains the possibility of doubting the programmer's oath.
But if the programmer has sworn falsely, then they might well suffer divine retribution in the form of nasal demons — or worse, subtly baffling program behaviour.
unsafe is an oath by u/scook0 (
I solemnly swear as a keyword when?)