Skip to content

Commit

Permalink
Minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
zrho committed Oct 11, 2024
1 parent cddfeb0 commit 356763d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 31 deletions.
1 change: 1 addition & 0 deletions hugr-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ workspace = true
extension_inference = []
declarative = ["serde_yaml"]
model_unstable = ["hugr-model"]
default = ["model_unstable"]

[[test]]
name = "model"
Expand Down
77 changes: 46 additions & 31 deletions hugr-model/capnp/hugr-v0.capnp
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
@0xe02b32c528509601;

# The id of a `Term`.
using TermId = UInt32;

# Either `0` or the id of a `Term` incremented by one.
using OptionalTermId = UInt32;

# The id of a `Region`.
using RegionId = UInt32;

# The id of a `Node`.
using NodeId = UInt32;

# The id of a `Link`.
using LinkId = UInt32;

struct Module {
root @0 :UInt32;
root @0 :RegionId;
nodes @1 :List(Node);
regions @2 :List(Region);
terms @3 :List(Term);
Expand All @@ -11,10 +26,10 @@ struct Node {
operation @0 :Operation;
inputs @1 :List(LinkRef);
outputs @2 :List(LinkRef);
params @3 :List(UInt32);
regions @4 :List(UInt32);
params @3 :List(TermId);
regions @4 :List(RegionId);
meta @5 :List(MetaItem);
signature @6 :UInt32;
signature @6 :OptionalTermId;
}

struct Operation {
Expand All @@ -32,43 +47,43 @@ struct Operation {
tag @10 :UInt16;
tailLoop @11 :Void;
conditional @12 :Void;
callFunc @13 :UInt32;
loadFunc @14 :UInt32;
callFunc @13 :TermId;
loadFunc @14 :TermId;
}

struct FuncDefn {
name @0 :Text;
params @1 :List(Param);
signature @2 :UInt32;
signature @2 :TermId;
}

struct FuncDecl {
name @0 :Text;
params @1 :List(Param);
signature @2 :UInt32;
signature @2 :TermId;
}

struct AliasDefn {
name @0 :Text;
params @1 :List(Param);
type @2 :UInt32;
value @3 :UInt32;
type @2 :TermId;
value @3 :TermId;
}

struct AliasDecl {
name @0 :Text;
params @1 :List(Param);
type @2 :UInt32;
type @2 :TermId;
}
}

struct Region {
kind @0 :RegionKind;
sources @1 :List(LinkRef);
targets @2 :List(LinkRef);
children @3 :List(UInt32);
children @3 :List(NodeId);
meta @4 :List(MetaItem);
signature @5 :UInt32;
signature @5 :OptionalTermId;
}

enum RegionKind {
Expand All @@ -83,14 +98,14 @@ struct MetaItem {

struct LinkRef {
union {
id @0 :UInt32;
id @0 :LinkId;
named @1 :Text;
}
}

struct GlobalRef {
union {
node @0 :UInt32;
node @0 :NodeId;
named @1 :Text;
}
}
Expand All @@ -99,7 +114,7 @@ struct LocalRef {
union {
direct :group {
index @0 :UInt16;
node @1 :UInt32;
node @1 :NodeId;
}
named @2 :Text;
}
Expand All @@ -114,62 +129,62 @@ struct Term {
variable @4 :LocalRef;
apply @5 :Apply;
applyFull @6 :ApplyFull;
quote @7 :UInt32;
quote @7 :TermId;
list @8 :ListTerm;
listType @9 :UInt32;
listType @9 :TermId;
string @10 :Text;
stringType @11 :Void;
nat @12 :UInt64;
natType @13 :Void;
extSet @14 :ExtSet;
extSetType @15 :Void;
adt @16 :UInt32;
adt @16 :TermId;
funcType @17 :FuncType;
control @18 :UInt32;
control @18 :TermId;
controlType @19 :Void;
}

struct Apply {
global @0 :GlobalRef;
args @1 :List(UInt32);
args @1 :List(TermId);
}

struct ApplyFull {
global @0 :GlobalRef;
args @1 :List(UInt32);
args @1 :List(TermId);
}

struct ListTerm {
items @0 :List(UInt32);
tail @1 :UInt32;
items @0 :List(TermId);
tail @1 :OptionalTermId;
}

struct ExtSet {
extensions @0 :List(Text);
rest @1 :UInt32;
rest @1 :OptionalTermId;
}

struct FuncType {
inputs @0 :UInt32;
outputs @1 :UInt32;
extensions @2 :UInt32;
inputs @0 :TermId;
outputs @1 :TermId;
extensions @2 :TermId;
}
}

struct Param {
union {
implicit @0 :Implicit;
explicit @1 :Explicit;
constraint @2 :UInt32;
constraint @2 :TermId;
}

struct Implicit {
name @0 :Text;
type @1 :UInt32;
type @1 :TermId;
}

struct Explicit {
name @0 :Text;
type @1 :UInt32;
type @1 :TermId;
}
}
2 changes: 2 additions & 0 deletions hugr-model/src/v0/binary/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub fn read_from_slice<'a>(slice: &[u8], bump: &'a Bump) -> ReadResult<model::Mo
read_module(bump, root)
}

/// Read a list of structs from a reader into a slice allocated through the bump allocator.
macro_rules! read_list {
($bump:expr, $reader:expr, $get:ident, $read:expr) => {{
let mut __list_reader = $reader.$get()?;
Expand All @@ -24,6 +25,7 @@ macro_rules! read_list {
}};
}

/// Read a list of scalars from a reader into a slice allocated through the bump allocator.
macro_rules! read_scalar_list {
($bump:expr, $reader:expr, $get:ident, $wrap:path) => {{
let mut __list_reader = $reader.$get()?;
Expand Down
1 change: 1 addition & 0 deletions hugr-model/src/v0/binary/write.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::hugr_v0_capnp as hugr_capnp;
use crate::v0 as model;

/// Write a list of items into a list builder.
macro_rules! write_list {
($builder:expr, $init:ident, $write:expr, $list:expr) => {
let mut __list_builder = $builder.reborrow().$init($list.len() as _);
Expand Down
5 changes: 5 additions & 0 deletions hugr-model/src/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ pub struct Node<'a> {
/// The meta information attached to the node.
pub meta: &'a [MetaItem<'a>],
/// The signature of the node.
///
/// Can be `None` to indicate that the node's signature should be inferred,
/// or for nodes with operations that do not have a signature.
pub signature: Option<TermId>,
}

Expand Down Expand Up @@ -355,6 +358,8 @@ pub struct Region<'a> {
/// The metadata attached to the region.
pub meta: &'a [MetaItem<'a>],
/// The signature of the region.
///
/// Can be `None` to indicate that the region signature should be inferred.
pub signature: Option<TermId>,
}

Expand Down

0 comments on commit 356763d

Please sign in to comment.