Skip to content

M5: extract render_compute_function to free functions; drop friend CodeEmitPass - #51

Merged
petlenz merged 1 commit into
mainfrom
phase-1.2-m5-recipe-render
Jun 1, 2026
Merged

M5: extract render_compute_function to free functions; drop friend CodeEmitPass#51
petlenz merged 1 commit into
mainfrom
phase-1.2-m5-recipe-render

Conversation

@petlenz

@petlenz petlenz commented Jun 1, 2026

Copy link
Copy Markdown
Member

Addresses M5 from tracking issue #48 (multi-lens review of stack #44-#47).

What

Promotes the function-frame rendering helpers (`render_compute_function`, `param_decl`, `output_decl`, `tensor_arg_count`) from private members of `ConstitutiveModel` to free functions in a new `include/numsim_codegen/recipe_render.h`. Drops the `friend class CodeEmitPass;` declaration.

Why

The friend declaration was a one-way ratchet: every future emit pass (`TangentEmitPass`, `MoosePropertyEmitPass`, `StateVarEmitPass`, `AbaqusEmitPass`) would either need to be friended on `ConstitutiveModel` or route through `CodeEmitPass`. O(passes) friends on the user-facing recipe class.

The render helpers only needed `ConstitutiveModel`'s read-only public accessors (`name()`, `symbols()`, `outputs()`) — they never touched private state. Friend access was leakage from the original single-emitter monolith. Promoting to free functions is a pure refactor with no API change for users.

Why M5 first in the issue #48 sequence

Pure refactor, no API change, smallest blast radius. Unlocks M4 (`RecipeView` to decouple `PassContext` from raw `ConstitutiveModel`) by establishing the public-accessor-only contract that emit passes use.

Verification

  • 105/105 tests pass, no regressions
  • No new tests needed — pure refactor; existing tests exercise the call path through `CodeEmitPass` (`CodeEmitPass.ProducesNonEmptyComputeFunctionSource` in particular)
  • Generated source is identical (same statement ordering, same template parameter naming)

Files

  • `include/numsim_codegen/recipe_render.h` (new) — declares `render_compute_function` as the public-API surface for emit passes
  • `include/numsim_codegen/recipe.h` — removes 4 member functions + `friend class CodeEmitPass`; adds inline definitions of the free functions in `namespace numsim::codegen` (with private helpers in `detail::`); updates `CodeEmitPass::run` to call the free function

Sequence

Per #48 follow-up plan: M5 → M4 → M3 → M2 → M6, all stacked on `main`. Each will be a small focused PR with verification.

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.

1 participant