Compiler emits dead instructions (unreachable AccessOperation arm, dead JumpIfUndefined after required loads) #25

Open
opened 2026-08-07 13:33:16 +02:00 by Hemera · 0 comments
Owner

Two pieces of the compiler are unreachable dead code that make the required/safe-access logic harder to follow:

  1. The AccessOperation arm in inner_access_op (src/compiler/mod.rs:613-629), which is the only place that emits FailIfUndefined (it checks TokenOperator::Dot vs QuestionMark). The parser never produces an AccessOperation on a Dot's rhs (an infix rhs is always a plain operand), so this arm never runs. This is directly related to the missing required-access enforcement (see issue "? operator only guards the head of an access chain").

  2. JumpIfUndefined is emitted right after a LoadFromContextToSlot with fail_on_not_found: true (e.g. tests/cases/deep_access.3-instructions.snap, instructions 91-105). A fail: true load returns an error on missing, never Undefined, so that jump can never fire.

Suggest removing the dead arm (and emitting FailIfUndefined from the VariableAccess arm instead) and skipping the redundant JumpIfUndefined when the base load is required.

Two pieces of the compiler are unreachable dead code that make the required/safe-access logic harder to follow: 1. The `AccessOperation` arm in `inner_access_op` (`src/compiler/mod.rs:613-629`), which is the only place that emits `FailIfUndefined` (it checks `TokenOperator::Dot` vs `QuestionMark`). The parser never produces an `AccessOperation` on a Dot's rhs (an infix rhs is always a plain operand), so this arm never runs. This is directly related to the missing required-access enforcement (see issue "`?` operator only guards the head of an access chain"). 2. `JumpIfUndefined` is emitted right after a `LoadFromContextToSlot` with `fail_on_not_found: true` (e.g. `tests/cases/deep_access.3-instructions.snap`, instructions 91-105). A `fail: true` load returns an error on missing, never `Undefined`, so that jump can never fire. Suggest removing the dead arm (and emitting `FailIfUndefined` from the `VariableAccess` arm instead) and skipping the redundant `JumpIfUndefined` when the base load is required.
Sign in to join this conversation.
No labels
automated-🤖
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Hemera/nomo#25
No description provided.