diff --git a/hugr-core/src/export.rs b/hugr-core/src/export.rs index 8c864fa6c..645a7a0e6 100644 --- a/hugr-core/src/export.rs +++ b/hugr-core/src/export.rs @@ -18,9 +18,6 @@ use std::fmt::Write; pub(crate) const OP_FUNC_CALL_INDIRECT: &str = "func.call-indirect"; const TERM_PARAM_TUPLE: &str = "param.tuple"; -const TERM_JSON: &str = "prelude.json"; -const META_DESCRIPTION: &str = "docs.description"; -const TERM_JSON_CONST: &str = "prelude.const-json"; /// Export a [`Hugr`] graph to its representation in the model. pub fn export_hugr<'a>(hugr: &'a Hugr, bump: &'a Bump) -> model::Module<'a> { @@ -558,15 +555,12 @@ impl<'a> Context<'a> { let mut meta = BumpVec::with_capacity_in(meta_len, self.bump); if let Some(description) = description { - let name = META_DESCRIPTION; let value = self.make_term(model::Term::Str(self.bump.alloc_str(description))); - meta.push(model::MetaItem { name, value }) + meta.push(self.make_term_apply(model::CORE_META_DESCRIPTION, &[value])); } for (name, value) in opdef.iter_misc() { - let name = self.bump.alloc_str(name); - let value = self.export_json_meta(value); - meta.push(model::MetaItem { name, value }); + meta.push(self.export_json_meta(name, value)); } self.bump.alloc_slice_copy(&meta) @@ -1036,7 +1030,7 @@ impl<'a> Context<'a> { let args = self .bump .alloc_slice_copy(&[runtime_type, json, extensions]); - let symbol = self.resolve_symbol(TERM_JSON_CONST); + let symbol = self.resolve_symbol(model::COMPAT_CONST_JSON); self.make_term(model::Term::ApplyFull { symbol, args }) } @@ -1075,30 +1069,21 @@ impl<'a> Context<'a> { } } - pub fn export_node_metadata( - &mut self, - metadata_map: &NodeMetadataMap, - ) -> &'a [model::MetaItem<'a>] { + pub fn export_node_metadata(&mut self, metadata_map: &NodeMetadataMap) -> &'a [model::TermId] { let mut meta = BumpVec::with_capacity_in(metadata_map.len(), self.bump); for (name, value) in metadata_map { - let name = self.bump.alloc_str(name); - let value = self.export_json_meta(value); - meta.push(model::MetaItem { name, value }); + meta.push(self.export_json_meta(name, value)); } meta.into_bump_slice() } - pub fn export_json_meta(&mut self, value: &serde_json::Value) -> model::TermId { + pub fn export_json_meta(&mut self, name: &str, value: &serde_json::Value) -> model::TermId { let value = serde_json::to_string(value).expect("json values are always serializable"); let value = self.make_term(model::Term::Str(self.bump.alloc_str(&value))); - let value = self.bump.alloc_slice_copy(&[value]); - let symbol = self.resolve_symbol(TERM_JSON); - self.make_term(model::Term::ApplyFull { - symbol, - args: value, - }) + let name = self.make_term(model::Term::Str(self.bump.alloc_str(name))); + self.make_term_apply(model::COMPAT_META_JSON, &[name, value]) } fn resolve_symbol(&mut self, name: &'a str) -> model::NodeId { @@ -1114,6 +1099,12 @@ impl<'a> Context<'a> { }), } } + + fn make_term_apply(&mut self, name: &'a str, args: &[model::TermId]) -> model::TermId { + let symbol = self.resolve_symbol(name); + let args = self.bump.alloc_slice_copy(args); + self.make_term(model::Term::ApplyFull { symbol, args }) + } } #[cfg(test)] diff --git a/hugr-core/src/import.rs b/hugr-core/src/import.rs index 650d585a2..f542ac695 100644 --- a/hugr-core/src/import.rs +++ b/hugr-core/src/import.rs @@ -28,9 +28,6 @@ use itertools::Either; use smol_str::{SmolStr, ToSmolStr}; use thiserror::Error; -const TERM_JSON: &str = "prelude.json"; -const TERM_JSON_CONST: &str = "prelude.const-json"; - /// Error during import. #[derive(Debug, Clone, Error)] pub enum ImportError { @@ -174,8 +171,8 @@ impl<'a> Context<'a> { for meta_item in node_data.meta { // TODO: For now we expect all metadata to be JSON since this is how // it is handled in `hugr-core`. - let value = self.import_json_meta(meta_item.value)?; - self.hugr.set_metadata(node, meta_item.name, value); + let (name, value) = self.import_json_meta(*meta_item)?; + self.hugr.set_metadata(node, name, value); } Ok(node) @@ -949,6 +946,7 @@ impl<'a> Context<'a> { | model::Term::NonLinearConstraint { .. } | model::Term::ConstFunc { .. } | model::Term::Bytes { .. } + | model::Term::Meta | model::Term::ConstAdt { .. } => Err(model::ModelError::TypeError(term_id).into()), model::Term::ControlType => { @@ -1016,7 +1014,9 @@ impl<'a> Context<'a> { Ok(TypeArg::Type { ty }) } - model::Term::Control { .. } | model::Term::NonLinearConstraint { .. } => { + model::Term::Control { .. } + | model::Term::Meta + | model::Term::NonLinearConstraint { .. } => { Err(model::ModelError::TypeError(term_id).into()) } } @@ -1137,6 +1137,7 @@ impl<'a> Context<'a> { | model::Term::Bytes { .. } | model::Term::BytesType | model::Term::ConstFunc { .. } + | model::Term::Meta | model::Term::ConstAdt { .. } => Err(model::ModelError::TypeError(term_id).into()), } } @@ -1275,7 +1276,7 @@ impl<'a> Context<'a> { fn import_json_meta( &mut self, term_id: model::TermId, - ) -> Result { + ) -> Result<(&'a str, serde_json::Value), ImportError> { let (global, args) = match self.get_term(term_id)? { model::Term::Apply { symbol, args } | model::Term::ApplyFull { symbol, args } => { (symbol, args) @@ -1284,11 +1285,15 @@ impl<'a> Context<'a> { }; let global = self.get_symbol_name(*global)?; - if global != TERM_JSON { + if global != model::COMPAT_META_JSON { return Err(model::ModelError::TypeError(term_id).into()); } - let [json_arg] = args else { + let [name_arg, json_arg] = args else { + return Err(model::ModelError::TypeError(term_id).into()); + }; + + let model::Term::Str(name) = self.get_term(*name_arg)? else { return Err(model::ModelError::TypeError(term_id).into()); }; @@ -1299,7 +1304,7 @@ impl<'a> Context<'a> { let json_value = serde_json::from_str(json_str).map_err(|_| model::ModelError::TypeError(term_id))?; - Ok(json_value) + Ok((name, json_value)) } fn import_value( @@ -1319,7 +1324,7 @@ impl<'a> Context<'a> { model::Term::ApplyFull { symbol, args } => { let symbol_name = self.get_symbol_name(*symbol)?; - if symbol_name == TERM_JSON_CONST { + if symbol_name == model::COMPAT_CONST_JSON { let value = args.get(1).ok_or(model::ModelError::TypeError(term_id))?; let model::Term::Str(json) = self.get_term(*value)? else { @@ -1375,6 +1380,7 @@ impl<'a> Context<'a> { | model::Term::Type | model::Term::Bytes { .. } | model::Term::BytesType + | model::Term::Meta | model::Term::NonLinearConstraint { .. } => { Err(model::ModelError::TypeError(term_id).into()) } diff --git a/hugr-core/tests/snapshots/model__roundtrip_call.snap b/hugr-core/tests/snapshots/model__roundtrip_call.snap index 7ade416d1..c9d735ba0 100644 --- a/hugr-core/tests/snapshots/model__roundtrip_call.snap +++ b/hugr-core/tests/snapshots/model__roundtrip_call.snap @@ -4,7 +4,7 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-call --- (hugr 0) -(import prelude.json) +(import compat.meta-json) (import arithmetic.int.types.int) @@ -13,18 +13,20 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-call [(@ arithmetic.int.types.int)] [(@ arithmetic.int.types.int)] (ext ?0 ... arithmetic.int) - (meta doc.description (@ prelude.json "\"This is a function declaration.\"")) - (meta doc.title (@ prelude.json "\"Callee\""))) + (meta + (@ compat.meta-json "description" "\"This is a function declaration.\"")) + (meta (@ compat.meta-json "title" "\"Callee\""))) (define-func example.caller [(@ arithmetic.int.types.int)] [(@ arithmetic.int.types.int)] (ext arithmetic.int) - (meta doc.description + (meta (@ - prelude.json + compat.meta-json + "description" "\"This defines a function that calls the function which we declared earlier.\"")) - (meta doc.title (@ prelude.json "\"Caller\"")) + (meta (@ compat.meta-json "title" "\"Caller\"")) (dfg [%0] [%1] (signature diff --git a/hugr-core/tests/snapshots/model__roundtrip_const.snap b/hugr-core/tests/snapshots/model__roundtrip_const.snap index 6b6bc1464..2b934fb46 100644 --- a/hugr-core/tests/snapshots/model__roundtrip_const.snap +++ b/hugr-core/tests/snapshots/model__roundtrip_const.snap @@ -4,7 +4,7 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cons --- (hugr 0) -(import prelude.const-json) +(import compat.const-json) (import arithmetic.float.types.float64) @@ -34,12 +34,12 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cons (tag 0 [(@ - prelude.const-json + compat.const-json (@ arithmetic.float.types.float64) "{\"c\":\"ConstF64\",\"v\":{\"value\":2.0}}" (ext arithmetic.float.types)) (@ - prelude.const-json + compat.const-json (@ arithmetic.float.types.float64) "{\"c\":\"ConstF64\",\"v\":{\"value\":3.0}}" (ext arithmetic.float.types))]) @@ -63,7 +63,7 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cons (ext))) (const (@ - prelude.const-json + compat.const-json (@ arithmetic.float.types.float64) "{\"c\":\"ConstF64\",\"v\":{\"value\":1.0}}" (ext arithmetic.float.types)) @@ -71,7 +71,7 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cons (signature (-> [] [(@ arithmetic.float.types.float64)] (ext)))) (const (@ - prelude.const-json + compat.const-json (@ arithmetic.float.types.float64) "{\"c\":\"ConstUnknown\",\"v\":{\"value\":1.0}}" (ext)) diff --git a/hugr-model/capnp/hugr-v0.capnp b/hugr-model/capnp/hugr-v0.capnp index a06665d1d..23d356791 100644 --- a/hugr-model/capnp/hugr-v0.capnp +++ b/hugr-model/capnp/hugr-v0.capnp @@ -31,7 +31,7 @@ struct Node { outputs @2 :List(LinkIndex); params @3 :List(TermId); regions @4 :List(RegionId); - meta @5 :List(MetaItem); + meta @5 :List(TermId); signature @6 :OptionalTermId; } @@ -105,7 +105,7 @@ struct Region { sources @1 :List(LinkIndex); targets @2 :List(LinkIndex); children @3 :List(NodeId); - meta @4 :List(MetaItem); + meta @4 :List(TermId); signature @5 :OptionalTermId; scope @6 :RegionScope; } @@ -124,11 +124,6 @@ enum RegionKind { module @2; } -struct MetaItem { - name @0 :Text; - value @1 :UInt32; -} - struct Term { union { wildcard @0 :Void; @@ -159,6 +154,7 @@ struct Term { constAdt @23 :ConstAdt; bytes @24 :Data; bytesType @25 :Void; + meta @26 :Void; } struct Apply { diff --git a/hugr-model/src/v0/binary/read.rs b/hugr-model/src/v0/binary/read.rs index 69ef45b14..8f0c9a50d 100644 --- a/hugr-model/src/v0/binary/read.rs +++ b/hugr-model/src/v0/binary/read.rs @@ -75,7 +75,7 @@ fn read_node<'a>(bump: &'a Bump, reader: hugr_capnp::node::Reader) -> ReadResult let outputs = read_scalar_list!(bump, reader, get_outputs, model::LinkIndex); let params = read_scalar_list!(bump, reader, get_params, model::TermId); let regions = read_scalar_list!(bump, reader, get_regions, model::RegionId); - let meta = read_list!(bump, reader, get_meta, read_meta_item); + let meta = read_scalar_list!(bump, reader, get_meta, model::TermId); let signature = reader.get_signature().checked_sub(1).map(model::TermId); Ok(model::Node { @@ -217,7 +217,7 @@ fn read_region<'a>( let sources = read_scalar_list!(bump, reader, get_sources, model::LinkIndex); let targets = read_scalar_list!(bump, reader, get_targets, model::LinkIndex); let children = read_scalar_list!(bump, reader, get_children, model::NodeId); - let meta = read_list!(bump, reader, get_meta, read_meta_item); + let meta = read_scalar_list!(bump, reader, get_meta, model::TermId); let signature = reader.get_signature().checked_sub(1).map(model::TermId); let scope = if reader.has_scope() { @@ -256,6 +256,7 @@ fn read_term<'a>(bump: &'a Bump, reader: hugr_capnp::term::Reader) -> ReadResult Which::NatType(()) => model::Term::NatType, Which::ExtSetType(()) => model::Term::ExtSetType, Which::ControlType(()) => model::Term::ControlType, + Which::Meta(()) => model::Term::Meta, Which::Variable(reader) => { let node = model::NodeId(reader.get_variable_node()); @@ -343,15 +344,6 @@ fn read_term<'a>(bump: &'a Bump, reader: hugr_capnp::term::Reader) -> ReadResult }) } -fn read_meta_item<'a>( - bump: &'a Bump, - reader: hugr_capnp::meta_item::Reader, -) -> ReadResult> { - let name = bump.alloc_str(reader.get_name()?.to_str()?); - let value = model::TermId(reader.get_value()); - Ok(model::MetaItem { name, value }) -} - fn read_list_part( _: &Bump, reader: hugr_capnp::term::list_part::Reader, diff --git a/hugr-model/src/v0/binary/write.rs b/hugr-model/src/v0/binary/write.rs index 56511ba12..74dc763ab 100644 --- a/hugr-model/src/v0/binary/write.rs +++ b/hugr-model/src/v0/binary/write.rs @@ -33,7 +33,7 @@ fn write_node(mut builder: hugr_capnp::node::Builder, node: &model::Node) { write_operation(builder.reborrow().init_operation(), &node.operation); let _ = builder.set_inputs(model::LinkIndex::unwrap_slice(node.inputs)); let _ = builder.set_outputs(model::LinkIndex::unwrap_slice(node.outputs)); - write_list!(builder, init_meta, write_meta_item, node.meta); + let _ = builder.set_meta(model::TermId::unwrap_slice(node.meta)); let _ = builder.set_params(model::TermId::unwrap_slice(node.params)); let _ = builder.set_regions(model::RegionId::unwrap_slice(node.regions)); builder.set_signature(node.signature.map_or(0, |t| t.0 + 1)); @@ -117,11 +117,6 @@ fn write_param(mut builder: hugr_capnp::param::Builder, param: &model::Param) { }); } -fn write_meta_item(mut builder: hugr_capnp::meta_item::Builder, meta_item: &model::MetaItem) { - builder.set_name(meta_item.name); - builder.set_value(meta_item.value.0) -} - fn write_region(mut builder: hugr_capnp::region::Builder, region: &model::Region) { builder.set_kind(match region.kind { model::RegionKind::DataFlow => hugr_capnp::RegionKind::DataFlow, @@ -132,7 +127,7 @@ fn write_region(mut builder: hugr_capnp::region::Builder, region: &model::Region let _ = builder.set_sources(model::LinkIndex::unwrap_slice(region.sources)); let _ = builder.set_targets(model::LinkIndex::unwrap_slice(region.targets)); let _ = builder.set_children(model::NodeId::unwrap_slice(region.children)); - write_list!(builder, init_meta, write_meta_item, region.meta); + let _ = builder.set_meta(model::TermId::unwrap_slice(region.meta)); builder.set_signature(region.signature.map_or(0, |t| t.0 + 1)); if let Some(scope) = ®ion.scope { @@ -225,6 +220,10 @@ fn write_term(mut builder: hugr_capnp::term::Builder, term: &model::Term) { model::Term::BytesType => { builder.set_bytes_type(()); } + + model::Term::Meta => { + builder.set_meta(()); + } } } diff --git a/hugr-model/src/v0/mod.rs b/hugr-model/src/v0/mod.rs index a5c98c8fb..32d79f7dc 100644 --- a/hugr-model/src/v0/mod.rs +++ b/hugr-model/src/v0/mod.rs @@ -90,6 +90,35 @@ use smol_str::SmolStr; use thiserror::Error; +/// Constructor for documentation metadata. +/// +/// - **Parameter:** `?description : str` +/// - **Result:** `meta` +pub const CORE_META_DESCRIPTION: &str = "core.meta.description"; + +/// Constructor for JSON encoded metadata. +/// +/// This is included in the model to allow for compatibility with `hugr-core`. +/// The intention is to deprecate this in the future in favor of metadata +/// expressed with custom constructors. +/// +/// - **Parameter:** `?name : str` +/// - **Parameter:** `?json : str` +/// - **Result:** `meta` +pub const COMPAT_META_JSON: &str = "compat.meta-json"; + +/// Constructor for JSON encoded constants. +/// +/// This is included in the model to allow for compatibility with `hugr-core`. +/// The intention is to deprecate this in the future in favor of constants +/// expressed with custom constructors. +/// +/// - **Parameter:** `?type : type` +/// - **Parameter:** `?json : str` +/// - **Parameter:** `?exts : ext-set` +/// - **Result:** `(const ?type ?exts)` +pub const COMPAT_CONST_JSON: &str = "compat.const-json"; + pub mod binary; pub mod scope; pub mod text; @@ -252,7 +281,7 @@ pub struct Node<'a> { /// The regions of the node. pub regions: &'a [RegionId], /// The meta information attached to the node. - pub meta: &'a [MetaItem<'a>], + pub meta: &'a [TermId], /// The signature of the node. /// /// Can be `None` to indicate that the node's signature should be inferred, @@ -411,7 +440,7 @@ pub struct Region<'a> { /// The nodes in the region. The order of the nodes is not significant. pub children: &'a [NodeId], /// The metadata attached to the region. - pub meta: &'a [MetaItem<'a>], + pub meta: &'a [TermId], /// The signature of the region. /// /// Can be `None` to indicate that the region signature should be inferred. @@ -501,15 +530,6 @@ pub struct OperationDecl<'a> { pub r#type: TermId, } -/// A metadata item. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct MetaItem<'a> { - /// Name of the metadata item. - pub name: &'a str, - /// Value of the metadata item. - pub value: TermId, -} - /// An index of a variable within a node's parameter list. pub type VarIndex = u16; @@ -695,6 +715,9 @@ pub enum Term<'a> { /// The type of byte strings. BytesType, + + /// The type of metadata. + Meta, } /// A part of a list term. diff --git a/hugr-model/src/v0/text/hugr.pest b/hugr-model/src/v0/text/hugr.pest index 1e12b1839..57229bce2 100644 --- a/hugr-model/src/v0/text/hugr.pest +++ b/hugr-model/src/v0/text/hugr.pest @@ -14,7 +14,7 @@ base64_string = { "\"" ~ (ASCII_ALPHANUMERIC | "+" | "/")* ~ "="* ~ "\"" } module = { "(" ~ "hugr" ~ "0" ~ ")" ~ meta* ~ node* ~ EOI } -meta = { "(" ~ "meta" ~ symbol ~ term ~ ")" } +meta = { "(" ~ "meta" ~ term ~ ")" } edge_name = @{ "%" ~ (ASCII_ALPHANUMERIC | "_" | "-")* } port = { edge_name } @@ -101,6 +101,7 @@ term = { | term_const_adt | term_bytes_type | term_bytes + | term_meta } term_wildcard = { "_" } @@ -128,5 +129,6 @@ term_const_func = { "(" ~ "fn" ~ term ~ ")" } term_const_adt = { "(" ~ "tag" ~ tag ~ term* ~ ")" } term_bytes_type = { "bytes" } term_bytes = { "(" ~ "bytes" ~ base64_string ~ ")" } +term_meta = { "meta" } spliced_term = { term ~ "..." } diff --git a/hugr-model/src/v0/text/parse.rs b/hugr-model/src/v0/text/parse.rs index 09d6413c9..40692b67e 100644 --- a/hugr-model/src/v0/text/parse.rs +++ b/hugr-model/src/v0/text/parse.rs @@ -9,8 +9,8 @@ use thiserror::Error; use crate::v0::{ scope::{LinkTable, SymbolTable, UnknownSymbolError, VarTable}, - AliasDecl, ConstructorDecl, ExtSetPart, FuncDecl, LinkIndex, ListPart, MetaItem, Module, Node, - NodeId, Operation, OperationDecl, Param, ParamSort, Region, RegionId, RegionKind, RegionScope, + AliasDecl, ConstructorDecl, ExtSetPart, FuncDecl, LinkIndex, ListPart, Module, Node, NodeId, + Operation, OperationDecl, Param, ParamSort, Region, RegionId, RegionKind, RegionScope, ScopeClosure, Term, TermId, }; @@ -126,6 +126,7 @@ impl<'a> ParseContext<'a> { Rule::term_nat_type => Term::NatType, Rule::term_ctrl_type => Term::ControlType, Rule::term_ext_set_type => Term::ExtSetType, + Rule::term_meta => Term::Meta, Rule::term_var => { let name_token = inner.next().unwrap(); @@ -880,14 +881,13 @@ impl<'a> ParseContext<'a> { Ok(self.links.use_link(name)) } - fn parse_meta(&mut self, pairs: &mut Pairs<'a, Rule>) -> ParseResult<&'a [MetaItem<'a>]> { + fn parse_meta(&mut self, pairs: &mut Pairs<'a, Rule>) -> ParseResult<&'a [TermId]> { let mut items = Vec::new(); for meta in filter_rule(pairs, Rule::meta) { let mut inner = meta.into_inner(); - let name = self.parse_symbol(&mut inner)?; let value = self.parse_term(inner.next().unwrap())?; - items.push(MetaItem { name, value }) + items.push(value) } Ok(self.bump.alloc_slice_copy(&items)) diff --git a/hugr-model/src/v0/text/print.rs b/hugr-model/src/v0/text/print.rs index 53bcc37b7..0a8ed4929 100644 --- a/hugr-model/src/v0/text/print.rs +++ b/hugr-model/src/v0/text/print.rs @@ -3,8 +3,8 @@ use pretty::{Arena, DocAllocator, RefDoc}; use std::borrow::Cow; use crate::v0::{ - ExtSetPart, LinkIndex, ListPart, MetaItem, ModelError, Module, NodeId, Operation, Param, - ParamSort, RegionId, RegionKind, Term, TermId, VarId, + ExtSetPart, LinkIndex, ListPart, ModelError, Module, NodeId, Operation, Param, ParamSort, + RegionId, RegionKind, Term, TermId, VarId, }; type PrintError = ModelError; @@ -608,6 +608,10 @@ impl<'p, 'a: 'p> PrintContext<'p, 'a> { this.print_byte_string(data); Ok(()) }), + Term::Meta => { + self.print_text("meta"); + Ok(()) + } } } @@ -683,14 +687,11 @@ impl<'p, 'a: 'p> PrintContext<'p, 'a> { Ok(()) } - fn print_meta(&mut self, meta: &'a [MetaItem<'a>]) -> PrintResult<()> { + fn print_meta(&mut self, meta: &'a [TermId]) -> PrintResult<()> { for item in meta { self.print_parens(|this| { - this.print_group(|this| { - this.print_text("meta"); - this.print_text(item.name); - }); - this.print_term(item.value) + this.print_text("meta"); + this.print_term(*item) })?; } diff --git a/hugr-model/tests/fixtures/model-call.edn b/hugr-model/tests/fixtures/model-call.edn index 839fb278a..c757658fc 100644 --- a/hugr-model/tests/fixtures/model-call.edn +++ b/hugr-model/tests/fixtures/model-call.edn @@ -3,13 +3,13 @@ (declare-func example.callee (forall ?ext ext-set) [(@ arithmetic.int.types.int)] [(@ arithmetic.int.types.int)] (ext arithmetic.int ?ext ...) - (meta doc.title (prelude.json "\"Callee\"")) - (meta doc.description (prelude.json "\"This is a function declaration.\""))) + (meta (compat.meta-json "title" "\"Callee\"")) + (meta (compat.meta-json "description" "\"This is a function declaration.\""))) (define-func example.caller [(@ arithmetic.int.types.int)] [(@ arithmetic.int.types.int)] (ext arithmetic.int) - (meta doc.title (prelude.json "\"Caller\"")) - (meta doc.description (prelude.json "\"This defines a function that calls the function which we declared earlier.\"")) + (meta (compat.meta-json "title" "\"Caller\"")) + (meta (compat.meta-json "description" "\"This defines a function that calls the function which we declared earlier.\"")) (dfg [%3] [%4] (signature (-> [(@ arithmetic.int.types.int)] [(@ arithmetic.int.types.int)] (ext))) (call (@ example.callee (ext)) [%3] [%4] diff --git a/hugr-model/tests/fixtures/model-const.edn b/hugr-model/tests/fixtures/model-const.edn index 025e77043..5e66a3c11 100644 --- a/hugr-model/tests/fixtures/model-const.edn +++ b/hugr-model/tests/fixtures/model-const.edn @@ -24,8 +24,8 @@ (const (tag 0 - [(@ prelude.const-json (@ arithmetic.float.types.float64) "{\"c\":\"ConstF64\",\"v\":{\"value\":2.0}}" (ext)) - (@ prelude.const-json (@ arithmetic.float.types.float64) "{\"c\":\"ConstF64\",\"v\":{\"value\":3.0}}" (ext))]) + [(@ compat.const-json (@ arithmetic.float.types.float64) "{\"c\":\"ConstF64\",\"v\":{\"value\":2.0}}" (ext)) + (@ compat.const-json (@ arithmetic.float.types.float64) "{\"c\":\"ConstF64\",\"v\":{\"value\":3.0}}" (ext))]) [] [%pair] (signature (-> @@ -40,11 +40,11 @@ (dfg [] [%0 %1] (signature (-> [] [(@ arithmetic.float.types.float64) (@ arithmetic.float.types.float64)] (ext))) (const - (@ prelude.const-json (@ arithmetic.float.types.float64) "{\"c\":\"ConstF64\",\"v\":{\"value\":1.0}}" (ext)) + (@ compat.const-json (@ arithmetic.float.types.float64) "{\"c\":\"ConstF64\",\"v\":{\"value\":1.0}}" (ext)) [] [%0] (signature (-> [] [(@ arithmetic.float.types.float64)] (ext)))) ; The following const is to test that import/export can deal with unknown constants. (const - (@ prelude.const-json (@ arithmetic.float.types.float64) "{\"c\":\"ConstUnknown\",\"v\":{\"value\":1.0}}" (ext)) + (@ compat.const-json (@ arithmetic.float.types.float64) "{\"c\":\"ConstUnknown\",\"v\":{\"value\":1.0}}" (ext)) [] [%1] (signature (-> [] [(@ arithmetic.float.types.float64)] (ext)))))) diff --git a/hugr-model/tests/fixtures/model-decl-exts.edn b/hugr-model/tests/fixtures/model-decl-exts.edn index bee0d68fc..253f480db 100644 --- a/hugr-model/tests/fixtures/model-decl-exts.edn +++ b/hugr-model/tests/fixtures/model-decl-exts.edn @@ -4,10 +4,10 @@ (param ?t type) (param ?n nat) type - (meta docs.description "Fixed size array.")) + (meta (core.meta.description "Fixed size array."))) (declare-operation array.Init (param ?t type) (param ?n nat) (-> [?t] [(array.Array ?t ?n)] (ext array)) - (meta docs.description "Initialize an array of size ?n with copies of a default value.")) + (meta (core.meta.description "Initialize an array of size ?n with copies of a default value."))) diff --git a/hugr-model/tests/snapshots/text__declarative_extensions.snap b/hugr-model/tests/snapshots/text__declarative_extensions.snap index 852c5bdac..40f7cbeb1 100644 --- a/hugr-model/tests/snapshots/text__declarative_extensions.snap +++ b/hugr-model/tests/snapshots/text__declarative_extensions.snap @@ -8,11 +8,14 @@ expression: "roundtrip(include_str!(\"fixtures/model-decl-exts.edn\"))" (param ?t type) (param ?n nat) type - (meta docs.description "Fixed size array.")) + (meta (core.meta.description "Fixed size array."))) (declare-operation array.Init (param ?t type) (param ?n nat) (-> [?t] [(array.Array ?t ?n)] (ext array)) - (meta docs.description - "Initialize an array of size ?n with copies of a default value.")) + (meta + (core.meta.description + "Initialize an array of size ?n with copies of a default value."))) + +(import core.meta.description)