From 0d8461e780ef45d44f148b195a14b60df1b488ae Mon Sep 17 00:00:00 2001 From: Lucas Franceschino Date: Wed, 13 Nov 2024 10:05:19 +0100 Subject: [PATCH] fix(frontend/table_id): make `Node` and `NodeRepr` use the same field names Not doing so breaks the JsonSchema --- engine/names/extract/build.rs | 2 +- engine/utils/ocaml_of_json_schema/ocaml_of_json_schema.js | 4 ++-- frontend/exporter/src/id_table.rs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/engine/names/extract/build.rs b/engine/names/extract/build.rs index aeff4063b..75b5625aa 100644 --- a/engine/names/extract/build.rs +++ b/engine/names/extract/build.rs @@ -18,7 +18,7 @@ mod id_table { #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] pub struct Node { value: Arc, - cache_id: u32, + id: u32, } impl std::ops::Deref for Node { diff --git a/engine/utils/ocaml_of_json_schema/ocaml_of_json_schema.js b/engine/utils/ocaml_of_json_schema/ocaml_of_json_schema.js index 12ff7487d..2b6bf3b5c 100644 --- a/engine/utils/ocaml_of_json_schema/ocaml_of_json_schema.js +++ b/engine/utils/ocaml_of_json_schema/ocaml_of_json_schema.js @@ -582,11 +582,11 @@ let parse_table_id_node (type t) (name: string) (encode: t -> map_types) (decode let label = "parse_table_id_node:" ^ name ^ ": " in match o with | \`Assoc alist -> begin - let id = match List.assoc_opt "cache_id" alist with + let id = match List.assoc_opt "id" alist with | Some (\`Int id) -> Base.Int.to_int64 id | Some (\`Intlit lit) -> (try Base.Int64.of_string lit with | _ -> failwith (label ^ "Base.Int64.of_string failed for " ^ lit)) | Some bad_json -> failwith (label ^ "id was expected to be an int, got: " ^ Yojson.Safe.pretty_to_string bad_json ^ "\n\n\nfull json: " ^ Yojson.Safe.pretty_to_string o) - | None -> failwith (label ^ " could not find the key 'cache_id' in the following json: " ^ Yojson.Safe.pretty_to_string o) + | None -> failwith (label ^ " could not find the key 'id' in the following json: " ^ Yojson.Safe.pretty_to_string o) in let decode v = decode v |> Base.Option.value_exn ~message:(label ^ "could not decode value (wrong type)") in match List.assoc_opt "value" alist with diff --git a/frontend/exporter/src/id_table.rs b/frontend/exporter/src/id_table.rs index 569199eec..eace37ab9 100644 --- a/frontend/exporter/src/id_table.rs +++ b/frontend/exporter/src/id_table.rs @@ -272,7 +272,7 @@ mod serde_repr { #[derive(Serialize, Deserialize, JsonSchema, Debug)] pub(super) struct NodeRepr { - cache_id: Id, + id: Id, value: Option>, } @@ -290,8 +290,8 @@ mod serde_repr { } else { Some(self.value.clone()) }; - let cache_id = self.id; - NodeRepr { value, cache_id } + let id = self.id; + NodeRepr { value, id } } } @@ -301,7 +301,7 @@ mod serde_repr { fn try_from(cached: NodeRepr) -> Result { use serde::de::Error; let table = DESERIALIZATION_STATE.lock().unwrap(); - let id = cached.cache_id; + let id = cached.id; let kind = if let Some(kind) = cached.value { kind } else {