Skip to content

fix(typecheck,compile): allow deferred parameter [:] dims and speed u…#162

Merged
jgoppert merged 1 commit into
CogniPilot:mainfrom
Xyntopia:main
May 13, 2026
Merged

fix(typecheck,compile): allow deferred parameter [:] dims and speed u…#162
jgoppert merged 1 commit into
CogniPilot:mainfrom
Xyntopia:main

Conversation

@yeus
Copy link
Copy Markdown
Member

@yeus yeus commented May 9, 2026

Summary

  • Fixes a compile correctness gap: parameter/constant [:] dimensions can now remain
    unresolved until later binding/instantiation (MLS-aligned), instead of failing early in
    typecheck.
  • Speeds up compile-heavy flows by optimizing clock timing precompute and strict path
    matching.
  • Adds compile/check timing metadata in source-root/WASM compile APIs for better
    diagnostics.
  • Adds a profiling utility script for reproducible perf/flamegraph and AI-readable profiling
    artifacts.
  • Measured impact on the target model
    WindPowerPlants.Components.GenericVariableSpeedGeneratorElectrical: compile-check wall
    time reduced from ~1m42s to ~12.7s (~8x faster).

Code Size Budget (required)

  • production_lines_added: 455
  • production_lines_deleted: 44
  • test_lines_added: 26
  • test_lines_deleted: 0
  • public_items_added: 12
  • public_items_removed: 0
  • files_touched: 10
  • net_added_lines: 437

If net_added_lines is positive, add:

  • Why this net growth is required.
    • The growth is primarily from two necessary additions: (1) timing instrumentation
      surfaces in compile APIs and (2) a reusable profiling script (scripts/
      profile_rumoca_model.sh). The performance fixes in clock precompute also require new
      indexing/data-structure code to avoid repeated scans.
  • Which code was removed/merged as part of the first compression pass.
    • Replaced repeated reverse-alias full scans with a precomputed reverse index in clock
      precompute.
    • Reused allocation/scratch paths instead of repeated per-iteration structures in hot
      code.
    • Replaced repeated path canonicalization calls with cached canonicalized keys in strict
      diagnostics.
  • Follow-up cleanup ticket/commit for remaining growth (if any).
    • Follow-up: collapse duplicated timing JSON construction between bind-wasm entry points
      into shared helpers and tighten script option parsing utilities (planned as a cleanup
      commit after merge).

Design Notes

  • Why each new abstraction was necessary.
    • StrictCheckTiming: needed to expose strict-check phase latency without mixing concerns
      into error payload formatting.
    • SourceMap reverse-alias index in clock precompute: needed to remove O(N) scans per
      lookup in hot inference loops.
    • Path canonicalization cache: needed to avoid repeated filesystem canonicalize calls in
      strict failure collection.
  • Why this was not solved by editing an existing module directly.
    • The bottlenecks crossed module boundaries: typecheck validation, DAE clock precompute,
      compile session strict-check path, and wasm/source-root API serialization. A single-
      module tweak would not address end-to-end compile latency and observability.
  • What duplicate/legacy paths were deleted.
    • Legacy repeated reverse-alias lookup behavior in clock inference was effectively
      replaced by indexed lookup.
    • Repeated ad-hoc canonicalization in strict path equality was replaced by centralized
      cached resolution.

Testing

  • Key command(s) run.
    • cargo fmt --all
    • cargo check -p rumoca-phase-dae -p rumoca-compile
    • ./target/release/rumoca check ... --model
      WindPowerPlants.Components.GenericVariableSpeedGeneratorElectrical ... (before/after
      timing comparison)
    • Workspace integration run (compile-only):
      • yarn modelica:compare run --compile-only --compile-debug --library-zip public/
        modelica-libraries/WindPowerPlants.zip --targets-prefix WindPowerPlants --target-
        class-types model,block --json
  • Files changed covered by tests.
    • crates/rumoca-phase-typecheck/src/typechecker/late_methods.rs is covered by new
      regression test in crates/rumoca-phase-typecheck/src/tests.rs
      (test_parameter_colon_dimension_without_binding_is_allowed).
    • Performance-related paths were validated by compile-only integration runs and direct
      model compile checks.
  • Updated a brittle WASM alias test to ignore only non-semantic timing metadata fields
    (__compile_phase_timing, __compile_check_timing) before comparing compile vs compile_to_json,
    while keeping strict equality for the full semantic payload.

Reviewer Checklist

  • Size budget section completed.
  • Positive net diff has explicit compression justification.
  • New APIs are required and minimal.
  • Old/new parallel paths were removed unless explicitly migrating.

…p clock/strict compile

  checks

- allow unresolved [:] for parameter/constant dimensions until binding/instantiation, add
    regression test
- optimize clock runtime precompute (reverse alias index + lower hot-path allocations)
- cache canonicalized paths in strict compile diagnostics to reduce repeated FS work
- add strict compile-check timing struct and expose timing in wasm/source-root compile APIs
- add profiling helper script for perf/flamegraph + folded AI-readable artifacts
- For WindPowerPlants.Components.GenericVariableSpeedGeneratorElectrical, compile-check wall
    time dropped from ~1m42s to ~12.7s (about 8x faster).

Signed-off-by: yeus <Thomas.Meschede@web.de>

change test to omit timing-related values for equality testing...

Signed-off-by: yeus <Thomas.Meschede@web.de>
@yeus yeus marked this pull request as ready for review May 10, 2026 19:17
@yeus yeus requested a review from jgoppert May 10, 2026 19:17
@@ -0,0 +1,198 @@
#!/usr/bin/env bash
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like this script, but it would be good if we could leverage the rum developer tool for things like this. So far I've managed to avoid bash/python scripts entirely, which helps with crossplatform support.

@jgoppert jgoppert merged commit 4dbfc0a into CogniPilot:main May 13, 2026
24 checks passed
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