Skip to content

Roadmap: support full SEP-0004 cost expression grammar #132

Description

@zrr1999

Problem / current limitation

SEP-0004 specifies cost expressions with +, *, ^const, log, max, min, and projection-style measures such as len(xs). The implementation exposes a richer internal sporec_typeck::cost::CostExpr, but the parser AST only accepts literals, variables, and O(n)/linear notation, so user-written cost clauses cannot express the SEP grammar.

Evidence

  • spore-evolution/seps/SEP-0004-cost-analysis.md:19 and :31 require +, *, ^const, log, max, and min.
  • spore-evolution/seps/SEP-0004-cost-analysis.md:116-121 shows cost <= len(list) * log(len(list)) * 5 + len(list).
  • crates/sporec-parser/src/ast.rs:198-206 limits parser-level CostExpr to Literal, Var, and Linear.
  • crates/sporec-typeck/src/cost.rs:12-29 already defines the target internal expression variants.
  • crates/sporec-typeck/src/cost.rs:598-605 drops parser cost clauses into the limited internal subset.

Target behavior

Users can write the SEP-0004 cost grammar in signatures, including arithmetic composition, log, max, min, exponent-by-constant, and simple projections such as len(xs) / xs.len where supported by syntax. The type checker preserves those expressions in cost vectors and diagnostics.

Acceptance tests

  • Parser tests accept cost clauses for n + 1, n * log(n), max(len(xs), 1), min(a, b), and n^2/the selected exponent syntax.
  • Type-checker tests verify the parsed expression is preserved in CostResult::Declared and CostVector.
  • CLI JSON/check output prints the declared symbolic cost without degrading it to a placeholder.
  • Negative parser tests reject division, subtraction, conditionals, and non-constant exponents in cost expressions.

Release priority

P1 / language correctness before broader cost-contract adoption

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