feat(hydro_lang): Pr/ir export#2830
Conversation
- 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
There was a problem hiding this comment.
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::Irwith a default.ir.jsonfilename suffix. - Implements IR JSON rendering in
GraphApi::renderusingserialize_dedup_sharedfor cycle-safe serialization. - Re-gates
BuiltFlow::ir_json()to thevizfeature.
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.
| crate::viz::config::GraphType::Ir => { | ||
| crate::compile::ir::serialize_dedup_shared(|| { | ||
| serde_json::to_string_pretty(self.ir).expect("failed to serialize IR") | ||
| }) | ||
| } |
There was a problem hiding this comment.
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.
| crate::viz::config::GraphType::Ir => { | ||
| crate::compile::ir::serialize_dedup_shared(|| { | ||
| serde_json::to_string_pretty(self.ir).expect("failed to serialize IR") | ||
| }) | ||
| } |
There was a problem hiding this comment.
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.
|
|
||
| /// Serialize the IR as JSON. | ||
| #[cfg(feature = "runtime_support")] | ||
| #[cfg(feature = "viz")] |
There was a problem hiding this comment.
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.
| #[cfg(feature = "viz")] | |
| #[cfg(stageleft_runtime)] |
Deploying hydro with
|
| Latest commit: |
879a685
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://2881a633.hydroflow.pages.dev |
| Branch Preview URL: | https://pr-ir-export.hydroflow.pages.dev |
Adds a new
--graph iroption that exports the serialized Hydro IR as JSON, for use by standalone analysis tools (e.g.hydro-coord).Changes
GraphType::Irvariant inviz/config.rsGraphApi::renderusingserialize_dedup_sharedfor cycle-safe output.ir.jsonfile extension to distinguish from the Hydroscope viewer format (.json)ir_json()feature gate changed fromruntime_supporttoviz(it only needsserde_json, notdfir_rs)Usage
The output can be piped directly into
hydro-coord: