Skip to content

Evaluate const expressions in dependency order #95

Description

@Rigidity

Summary

Const expressions are currently evaluated in HIR allocation order. Directly nested const expressions are allocated inner-first, but a const expression reached through a referenced function or constant may still be unevaluated when its caller is evaluated.

The lowerer currently handles this by transparently lowering the inner Hir::Const value. Successful evaluation remains semantically correct, but the inner expression can be evaluated repeatedly and as part of the caller's cost budget.

Problems

  • Nested const work can be repeated rather than using the cached HIR result.
  • Inner evaluation cost is charged to the outer const expression.
  • Recursive calls can multiply the repeated work.
  • Failures can produce duplicate or misleading diagnostics at both inner and outer source locations.

Proposed direction

  • Track const nodes as pending, evaluating, or done.
  • Evaluate const markers reachable through referenced symbols before evaluating their dependents.
  • Detect dependency cycles through the evaluating state.
  • Once ordering is guaranteed, treat an unevaluated Hir::Const reaching lowering as an invariant violation rather than transparently unwrapping it.

This is not currently a final-program correctness issue for successfully evaluated expressions; it is primarily a compiler performance, cost-accounting, and diagnostics improvement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions