Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hydro_lang/src/compile/built.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ impl<'a> BuiltFlow<'a> {
}

/// Serialize the IR as JSON.
#[cfg(feature = "runtime_support")]
#[cfg(feature = "viz")]
pub fn ir_json(&self) -> Result<String, serde_json::Error> {
super::ir::serialize_dedup_shared(|| serde_json::to_string_pretty(&self.ir))
super::ir::ir_to_json(&self.ir)
}

/// Returns all raw location ID -> location name mappings.
Expand Down
6 changes: 6 additions & 0 deletions hydro_lang/src/compile/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1991,6 +1991,12 @@ pub fn serialize_dedup_shared<T>(f: impl FnOnce() -> T) -> T {
f()
}

/// Serialize a slice of [`HydroRoot`]s to a JSON string with shared-node deduplication.
#[cfg(feature = "viz")]
pub fn ir_to_json(ir: &[HydroRoot]) -> Result<String, serde_json::Error> {
serialize_dedup_shared(|| serde_json::to_string(ir))
}

/// RAII guard that saves/restores the `SERIALIZED_SHARED` thread-local,
/// making `serialize_dedup_shared` re-entrant and panic-safe.
struct SerializedSharedGuard {
Expand Down
3 changes: 3 additions & 0 deletions hydro_lang/src/viz/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ impl<'a> GraphApi<'a> {
crate::viz::config::GraphType::Mermaid => render_hydro_ir_mermaid(self.ir, config),
crate::viz::config::GraphType::Dot => render_hydro_ir_dot(self.ir, config),
crate::viz::config::GraphType::Json => render_hydro_ir_json(self.ir, config),
crate::viz::config::GraphType::IrJson => {
crate::compile::ir::ir_to_json(self.ir).expect("failed to serialize IR to JSON")
}
Comment on lines +43 to +45
}
}

Expand Down
3 changes: 3 additions & 0 deletions hydro_lang/src/viz/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub enum GraphType {
Dot,
/// JSON format for Hydroscope interactive viewer.
Json,
/// Raw serialized IR as JSON (full intermediate representation).
IrJson,
}

impl GraphType {
Expand All @@ -18,6 +20,7 @@ impl GraphType {
GraphType::Mermaid => "mmd",
GraphType::Dot => "dot",
GraphType::Json => "json",
GraphType::IrJson => "ir.json",
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions hydro_test/src/cluster/paxos_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,40 @@ mod tests {
});
}

#[test]
fn paxos_ir_json() {
let mut builder = hydro_lang::compile::builder::FlowBuilder::new();
let proposers = builder.cluster();
let acceptors = builder.cluster();
let clients = builder.cluster();
let client_aggregator = builder.process();
let replicas = builder.cluster();

create_paxos(
&proposers,
&acceptors,
&clients,
&client_aggregator,
&replicas,
);
let built = builder.finalize();

let json = hydro_lang::compile::ir::serialize_dedup_shared(|| {
serde_json::to_string_pretty(built.ir()).unwrap()
});
Comment on lines +261 to +263

// Redact absolute paths for CI portability.
let workspace_root = env!("CARGO_MANIFEST_DIR")
.strip_suffix("/hydro_test")
.or_else(|| env!("CARGO_MANIFEST_DIR").strip_suffix("\\hydro_test"))
.unwrap_or(env!("CARGO_MANIFEST_DIR"));
let json_escaped_root = workspace_root.replace('\\', "\\\\");
let json = json.replace(&json_escaped_root, "[workspace]");
let json = json.replace("\\\\", "/");

hydro_build_utils::assert_snapshot!(json);
}

#[tokio::test]
async fn paxos_some_throughput() {
let mut builder = hydro_lang::compile::builder::FlowBuilder::new();
Expand Down
Loading
Loading