Skip to content

Enforce explicit control-flow modeling across SML machine code#31

Merged
gabewillen merged 4 commits into
mainfrom
compliance/explicit-control-flow-modeling
Mar 3, 2026
Merged

Enforce explicit control-flow modeling across SML machine code#31
gabewillen merged 4 commits into
mainfrom
compliance/explicit-control-flow-modeling

Conversation

@gabewillen

Copy link
Copy Markdown
Contributor

Summary

  • updates the SML rules contract to require explicit modeling for all runtime control flow (if/switch/?:) and mirrors that wording in project policy docs
  • adds docs/compliance-report.md and docs/runtime-conditionals-todo.md from the full compliance audit
  • refactors machine action/detail/sm implementation surfaces to remove runtime branching statements and replace them with explicit modeled control flow across planner, kernel, gbnf, tokenizer, detokenizer, docs, tensor, and shared wrappers
  • completes a full repository re-audit over src/emel/**/*{actions,detail,sm}.hpp for runtime if, switch, and ?: offenders and resolves remaining hits

Validation

  • scripts/quality_gates.sh passes
  • targeted and exhaustive rg compliance scans for runtime if (...), switch (...), and ternary operators on machine implementation files pass

Notes

  • benchmark snapshot regression warnings are currently ignored by the quality gate and are unchanged policy-wise

Copilot AI review requested due to automatic review settings March 3, 2026 14:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enforces the project’s updated SML policy requiring explicit modeling of runtime control flow by removing runtime if/switch/?: constructs from action/member-method/helper surfaces and updating the accompanying compliance documentation.

Changes:

  • Updates SML rules/policy language to explicitly ban runtime branching statements and require modeled control flow (guards/choice states).
  • Refactors multiple runtime/helper implementations to replace branching with explicit/branchless control-flow modeling patterns.
  • Adds compliance audit artifacts (docs/compliance-report.md, docs/runtime-conditionals-todo.md) and updates generated architecture docs.

Reviewed changes

Copilot reviewed 47 out of 47 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/emel/token/batcher/guards.hpp Switches includes to use the new action/detail surface arrangement.
src/emel/token/batcher/detail.hpp Collapses former helper implementation into the actions surface via include indirection.
src/emel/token/batcher/actions.hpp Migrates/rewrites batcher detail helpers into actions.hpp with branch-model constructs.
src/emel/text/tokenizer/preprocessor/detail.hpp Rewrites tokenizer preprocessor helpers to avoid runtime branching statements.
src/emel/text/tokenizer/actions.hpp Replaces ternary-based capacity computation with branchless arithmetic.
src/emel/text/renderer/actions.hpp Introduces branchless optional callback dispatch and replaces conditional error mapping.
src/emel/text/detokenizer/detail.hpp Collapses former helper implementation into the actions surface via include indirection.
src/emel/text/detokenizer/actions.hpp Moves former detail helpers into actions.hpp and rewrites control flow to comply.
src/emel/tensor/view/detail.hpp Replaces ternary pointer selection with array-index selection.
src/emel/tensor/detail.hpp Replaces ternary pointer selection with array-index selection.
src/emel/sm.hpp Normalizes acceptance/error checks and removes runtime if patterns in helper utilities.
src/emel/model/weight_loader/sm.hpp Rewrites wrapper callback dispatch to avoid runtime branching statements.
src/emel/kernel/x86_64/guards.hpp Switches includes to use the new action/detail surface arrangement.
src/emel/kernel/x86_64/detail.hpp Collapses former helper implementation into the actions surface via include indirection.
src/emel/kernel/x86_64/context.hpp Moves runtime feature detection into an inline helper in context.hpp.
src/emel/kernel/aarch64/guards.hpp Switches includes to use the new action/detail surface arrangement.
src/emel/kernel/aarch64/detail.hpp Collapses former helper implementation into the actions surface via include indirection.
src/emel/kernel/aarch64/context.hpp Moves runtime feature detection into an inline helper in context.hpp.
src/emel/kernel/aarch64/actions.hpp Moves former detail helpers into actions.hpp and rewrites SIMD routing/branches to comply.
src/emel/gguf/loader/sm.hpp Removes wrapper if by rewriting the post-process assignment into explicit control flow.
src/emel/gbnf/sampler/actions.hpp Replaces multiple ternaries/ifs with LUT-based mapping and branchless compaction.
src/emel/gbnf/rule_parser/lexer/actions.hpp Rewrites lexer scanning logic to avoid runtime branching statements.
src/emel/gbnf/rule_parser/detail.hpp Rewrites multiple parsing utilities to avoid runtime branching statements.
src/emel/gbnf/rule_parser/actions.hpp Rewrites parser actions’ branching/quantifier logic into modeled/branchless constructs.
src/emel/gbnf/detail.hpp Rewrites grammar::rule() validation/selection into masked/branchless constructs.
src/emel/docs/detail.hpp Rewrites doc helpers to avoid runtime branching statements while preserving behavior.
src/emel/batch/planner/modes/simple/actions.hpp Delegates to a detail helper (presumably compliant) instead of inline branching logic.
src/emel/batch/planner/modes/sequential/actions.hpp Delegates to a detail helper (presumably compliant) instead of inline branching logic.
src/emel/batch/planner/modes/equal/actions.hpp Delegates to detail helpers (including fast path) instead of inline branching logic.
src/emel/batch/planner/actions.hpp Removes ternary in batch normalization by switching to LUT-based selection.
docs/runtime-conditionals-todo.md Adds a TODO tracker for the runtime-conditional removal audit.
docs/rules/sml.rules.md Updates SML rules contract to explicitly ban if/else if/switch/?: at runtime.
docs/compliance-report.md Adds a static-analysis compliance report snapshot and violation inventory.
docs/compliance-checklist.md Updates checklist wording to match the new explicit branching-statement ban.
docs/architecture/mermaid/batch_planner_modes_simple.mmd Updates generated mermaid references after refactors.
docs/architecture/mermaid/batch_planner_modes_sequential.mmd Updates generated mermaid references after refactors.
docs/architecture/mermaid/batch_planner_modes_equal.mmd Updates generated mermaid references after refactors.
docs/architecture/batch_planner_modes_simple.md Updates generated architecture markdown references after refactors.
docs/architecture/batch_planner_modes_sequential.md Updates generated architecture markdown references after refactors.
docs/architecture/batch_planner_modes_equal.md Updates generated architecture markdown references after refactors.
README.md Adds a project re-architecture warning block and minor formatting tweak.
AGENTS.md Updates agent guidance to explicitly ban runtime branching statements and require modeled flow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/emel/token/batcher/actions.hpp

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec121b02da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/emel/kernel/detail.hpp Outdated
Comment thread src/emel/sm.hpp Outdated
@gabewillen gabewillen merged commit 29743d5 into main Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants