Skip to content

[Self-Hosting Phase 2] Port Field and Physics DSL Lowering to Flow #682

Closed

Description

@godofecht

Scope

Port spatial field and physics constraint transformations from src/flow/field_dsl.py and src/flow/physics_dsl.py to native Flow compiler passes.

Deliverables

  • Spatial field allocation, discrete grid indexing, and boundary condition expansion.
  • Laplacian and differential operator desugaring.
  • Physics constraint equation solving passes.
  • Validate with examples/dynamics/heat_equation.flow and physics demos.

Activity

  1. added
    self-hosting
    P2-medium
    on Aug 21, 2026
  2. godofecht commented on Aug 22, 2026

    @godofecht
    ContributorAuthor

    Progress: #707 already moved the first Field DSL parsing primitives into Flow. #710 now starts the Physics DSL side with native directive classification, simplified field grammar validation, Vec2 recognition, and the exact currently-shipped field stride/offset arithmetic. This does not satisfy the lowering issue yet: remaining work is native spatial allocation/indexing and boundary expansion, differential/Laplacian desugaring, and physics rule/constraint lowering. I am keeping the regex/source-assembly host boundary in Python until those transformations can consume native AST/data rather than re-parsing strings in Flow.

  3. godofecht commented on Aug 22, 2026

    @godofecht
    ContributorAuthor

    After merged #710, the next AST-independent Physics DSL slice is now concrete from compile_physics_to_flow:

    1. Rule rewriting primitives: name += expr -> name = name + expr; name *= expr -> name = name * (expr).
    2. Constraint projection rewriting: position.x/y and velocity.x/y -> flattened SoA scalar names.
    3. clamp( -> clamp_f64( substitution.
    4. Vec2 constant splitting (Vec2(x, y) -> <name>_x, <name>_y) can follow as another deterministic helper.

    These can move to native Flow without yet porting the PhysicsWorld Python object graph or code-generation assembly. The broader world/entity/rule regex parser and complete generated-code emission remain later #682 work.

  4. godofecht commented on Sep 16, 2026

    @godofecht
    ContributorAuthor

    Implemented the next rewrite slice in src/flow/physics_dsl.py: statement-bounded compound assignment lowering (+=, -=, *=, /=), projection flattening for position/velocity x/y, and clamp -> clamp_f64 in both rules and constraints. Added regressions in tests/unit/test_physics_dsl.py. Full suite: 1814 passed, 4 skipped.

  5. godofecht commented on Sep 16, 2026

    @godofecht
    ContributorAuthor

    Follow-up generator correctness fix: compile_physics_to_flow no longer silently drops valid rule statements. Added component-wise expansion for non-hard-coded Vec2 scale/translation rules and preserves scalar/generated Flow statements. Regression coverage includes damping plus constraint projection/clamp lowering. Full suite: 1814 passed, 4 skipped.

  6. godofecht commented on Sep 16, 2026

    @godofecht
    ContributorAuthor

    Additional parity fix: generated update loops now load and store scalar entity fields (their accessors were previously emitted but unused), so scalar rules such as compile to valid executable Flow. Added regression coverage. Full suite remains 1814 passed, 4 skipped.

  7. godofecht commented on Sep 16, 2026

    @godofecht
    ContributorAuthor

    Correction: generated update loops now load and store scalar entity fields (their accessors were previously emitted but unused), so scalar rules such as mass *= damping compile to valid executable Flow. Added regression coverage. Full suite remains 1814 passed, 4 skipped.

  8. godofecht commented on Sep 16, 2026

    @godofecht
    ContributorAuthor

    Correctness follow-up: tightened vector-rule recognition so only the exact canonical gravity/friction/forward-motion forms use specialized lowering. Other position/velocity operations now go through component expansion, so position -= velocity * dt preserves subtraction instead of being miscompiled as addition. Focused physics/shader/dynamics tests: 41 passed.

  9. godofecht commented on Sep 16, 2026

    @godofecht
    ContributorAuthor

    Implemented the documented pairwise collision interaction lowering. An interaction with distance(a, b) guard, normalize(b.position - a.position), and dot(a.velocity - b.velocity, normal) now generates an executable a<b SoA pass with equal-and-opposite velocity impulses and is invoked by the update loop. Unsupported interaction shapes fail explicitly. Physics/shader/dynamics/field focused checks: 48 passed.

  10. godofecht commented on Sep 16, 2026

    @godofecht
    ContributorAuthor

    Validation follow-up: the interaction block-boundary parser fix prevents later constraints/interactions from being swallowed into an earlier block. The generated canonical collision pass now parses through Flow and C generation. Full suite: 1815 passed, 4 skipped.

  11. godofecht commented on Sep 16, 2026

    @godofecht
    ContributorAuthor

    End-to-end validation: the module EXAMPLE_DSL now parses into 3 rules and 4 independent constraints, compiles to generated Flow, and passes the Flow parser plus C generator. The canonical interaction fixture also passes that pipeline. Full suite: 1815 passed, 4 skipped.

  12. godofecht commented on Sep 16, 2026

    @godofecht
    ContributorAuthor

    Added native executable coverage for the bundled field DSL core import path. The bootstrap compiler emits, compiles, and runs tests/lang/test_field_dsl_core.flow successfully; focused native field/pattern tests pass.

  13. godofecht commented on Sep 30, 2026

    @godofecht
    ContributorAuthor

    State on main (ee5048d):

    Remaining: decide whether a physics DSL front end is wanted. If not, this can close; if so, it is a new feature and should get its own issue.

  14. godofecht commented on Oct 2, 2026

    @godofecht
    ContributorAuthor

    Closing as obsolete. The Field DSL and dynamics lowering are native in Flow, and the retired Python physics lowering had no caller outside its tests. A future physics DSL front end would be a new feature with a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-mediumcompilerself-hosting

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions