r/Compilers • • Oct 20 '26

How I solved the object identity for NaN-boxed values?

Post image

Something new about my runtime 🐱.

With NaN boxing, x = 1.5 and y = float("1.5") are the same 64 bits. CPython says x is y is False, and there is no room left in the value to tell them apart.

Edge's design treats identity as history instead of bits. SSA already gives every definition its own number, so is just compares versions at compile time.

If the value went through the heap, the VM is deterministic, so it replays that stretch once and records where each value came from.

Normal code pays nothing for this optimization.

Right now I'm working on the next big challenge, inferring a few of types with RVSDG and compiling Python to LLVM to get close to C speed.

0 Upvotes

2 comments sorted by

2

u/AustinVelonaut Oct 20 '26

I hadn't heard of RVSDG (Regionalized Value State Dependence Graph) before, so I looked up the paper. Coming from a functional-programming background, it looks to me like they are taking an SSA representation and recreating what the equivalent functional language "core" graph representation would be:

  • lambda nodes correspond to lambda expressions
  • delta nodes are "thunks" (memoized expressions calculated once)
  • gamma nodes are case expressions
  • theta nodes are recursive functions
  • phi nodes are mutually-recursive functions in a "let"
  • edges are function parameters or free variables
  • omega nodes are top-level functions / thunks

1

u/RevengerWizard Oct 21 '26

Do you also handle integers in your NaN boxing scheme? Python's int can get pretty large