Skip to content

Precompute a has_while flag on Program instead of scanning at eval time #171

Description

@ausimian

Surfaced by the CM14 fused-while review (follow-up to #163).

The compiled eval path decides how to run a program by scanning its top-level instructions for a while at eval time, in two places:

// c_src/program.cpp:427  eval_program_nif — host-controlled-fused vs whole-program compile
if (contains_top_level_while(*prog)) { ... }

// c_src/program.cpp:215  the While arm — whether to fuse this body
const bool fuse_body = ctx.fuse_loops && !contains_top_level_while(body_p);

contains_top_level_while (c_src/program.cpp:106) is an O(instrs) scan, but whether a program contains a top-level while is a static property of the IR, known at compile_program time. Computing it once and storing a bool has_while (or a richer compilable/fusable property) on Program would:

Severity: low (refactor / altitude). Correctness is fine today; this is about deciding the "compilable" property once at the right layer rather than re-deriving it on every eval.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions