Skip to content

feat(hydro_lang): Pr/ir export#2830

Draft
jhellerstein wants to merge 2 commits intomainfrom
pr/ir-export
Draft

feat(hydro_lang): Pr/ir export#2830
jhellerstein wants to merge 2 commits intomainfrom
pr/ir-export

Conversation

@jhellerstein
Copy link
Copy Markdown
Contributor

Adds a new --graph ir option that exports the serialized Hydro IR as JSON, for use by standalone analysis tools (e.g. hydro-coord).

Changes

  • New GraphType::Ir variant in viz/config.rs
  • IR serialization handled in GraphApi::render using serialize_dedup_shared for cycle-safe output
  • Uses .ir.json file extension to distinguish from the Hydroscope viewer format (.json)
  • ir_json() feature gate changed from runtime_support to viz (it only needs serde_json, not dfir_rs)

Usage

cargo run --example my_flow -- --graph ir
cargo run --example my_flow -- --graph ir -o my_flow.ir.json

The output can be piped directly into hydro-coord:

hydro-coord my_flow.ir.json

Joe Hellerstein added 2 commits April 30, 2026 14:37
- Gate ir_json() on viz feature (serde_json available there)
- Add GraphType::Ir variant for CLI: --graph ir -o output.json
- BuiltFlow::generate_graph intercepts Ir before delegating to viz
- Move IR serialization into GraphApi::render so all code paths work
- Remove special-case in BuiltFlow::generate_graph (now just delegates)
- Use .ir.json extension to distinguish from Hydroscope .json format
@jhellerstein jhellerstein changed the title Pr/ir export feat(hydro_lang): Pr/ir export May 1, 2026
@jhellerstein jhellerstein requested a review from Copilot May 1, 2026 06:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new visualization output mode to export Hydro’s serialized IR as JSON (--graph ir) for consumption by standalone analysis tools (e.g. hydro-coord), distinct from the existing Hydroscope viewer JSON.

Changes:

  • Introduces GraphType::Ir with a default .ir.json filename suffix.
  • Implements IR JSON rendering in GraphApi::render using serialize_dedup_shared for cycle-safe serialization.
  • Re-gates BuiltFlow::ir_json() to the viz feature.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
hydro_lang/src/viz/config.rs Adds GraphType::Ir and maps it to the ir.json extension/suffix.
hydro_lang/src/viz/api.rs Adds IR JSON rendering path using serde_json + shared-node dedup scope.
hydro_lang/src/compile/built.rs Moves ir_json() behind the viz feature gate.

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

Comment thread hydro_lang/src/viz/api.rs
Comment on lines +43 to +47
crate::viz::config::GraphType::Ir => {
crate::compile::ir::serialize_dedup_shared(|| {
serde_json::to_string_pretty(self.ir).expect("failed to serialize IR")
})
}
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

GraphApi::render panics on IR serialization failure via expect("failed to serialize IR"). Since this is user-facing CLI output and write_to_file already returns a Result, prefer propagating the serde_json error (e.g., make render return a Result<String, _> or handle the error in write_to_file/generate_graph) rather than aborting the process.

Copilot uses AI. Check for mistakes.
Comment thread hydro_lang/src/viz/api.rs
Comment on lines +43 to +47
crate::viz::config::GraphType::Ir => {
crate::compile::ir::serialize_dedup_shared(|| {
serde_json::to_string_pretty(self.ir).expect("failed to serialize IR")
})
}
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

A new GraphType::Ir format was added, but the existing test_string_generation test only exercises Mermaid/Dot/Json. Add an assertion covering the Ir branch (and ideally validate that it is valid JSON) to prevent regressions in the new output mode.

Copilot uses AI. Check for mistakes.

/// Serialize the IR as JSON.
#[cfg(feature = "runtime_support")]
#[cfg(feature = "viz")]
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

Changing ir_json() from runtime_support to viz makes this API require the viz feature, which pulls in additional dependencies (e.g., clap, itertools, and build) beyond serde_json. If the intent is to make IR JSON available without the full viz stack, consider gating this method on a narrower feature (e.g., a dedicated ir_json/serde_json feature) instead of viz.

Suggested change
#[cfg(feature = "viz")]
#[cfg(stageleft_runtime)]

Copilot uses AI. Check for mistakes.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying hydro with  Cloudflare Pages  Cloudflare Pages

Latest commit: 879a685
Status: ✅  Deploy successful!
Preview URL: https://2881a633.hydroflow.pages.dev
Branch Preview URL: https://pr-ir-export.hydroflow.pages.dev

View logs

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