Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Simplify hugr-model #1893

Merged
merged 4 commits into from
Feb 4, 2025
Merged
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
286 changes: 127 additions & 159 deletions hugr-core/src/export.rs

Large diffs are not rendered by default.

901 changes: 499 additions & 402 deletions hugr-core/src/import.rs

Large diffs are not rendered by default.

25 changes: 11 additions & 14 deletions hugr-core/tests/snapshots/model__roundtrip_add.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,21 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-add.
---
(hugr 0)

(import arithmetic.int.iadd)

(import arithmetic.int.types.int)

(define-func example.add
[(@ arithmetic.int.types.int) (@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
(ext)
(core.fn
[arithmetic.int.types.int arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext))
(dfg
[%0 %1] [%2]
(signature
(->
[(@ arithmetic.int.types.int) (@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
(core.fn
[arithmetic.int.types.int arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext)))
((@ arithmetic.int.iadd) [%0 %1] [%2]
(arithmetic.int.iadd [%0 %1] [%2]
(signature
(->
[(@ arithmetic.int.types.int) (@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
(core.fn
[arithmetic.int.types.int arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext arithmetic.int))))))
8 changes: 3 additions & 5 deletions hugr-core/tests/snapshots/model__roundtrip_alias.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-alia
---
(hugr 0)

(import arithmetic.int.types.int)
(declare-alias local.float core.type)

(declare-alias local.float type)
(define-alias local.int core.type arithmetic.int.types.int)

(define-alias local.int type (@ arithmetic.int.types.int))

(define-alias local.endo type (-> [] [] (ext)))
(define-alias local.endo core.type (core.fn [] [] (ext)))
80 changes: 41 additions & 39 deletions hugr-core/tests/snapshots/model__roundtrip_call.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,68 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-call
---
(hugr 0)

(import compat.meta-json)

(import arithmetic.int.types.int)

(declare-func example.callee
(forall ?0 ext-set)
[(@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
(ext ?0 ... arithmetic.int)
(meta
(@ compat.meta-json "description" "\"This is a function declaration.\""))
(meta (@ compat.meta-json "title" "\"Callee\"")))
(param ?0 core.ext_set)
(core.fn
[arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext ?0 ... arithmetic.int))
(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)
(core.fn
[arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext arithmetic.int))
(meta
(@
compat.meta-json
(compat.meta_json
"description"
"\"This defines a function that calls the function which we declared earlier.\""))
(meta (@ compat.meta-json "title" "\"Caller\""))
(meta (compat.meta_json "title" "\"Caller\""))
(dfg
[%0] [%1]
(signature
(->
[(@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
(core.fn
[arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext arithmetic.int)))
(call (@ example.callee (ext)) [%0] [%1]
((core.call_indirect
[arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext arithmetic.int)
(example.callee (ext)))
[%0] [%1]
(signature
(->
[(@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
(core.fn
[arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext arithmetic.int))))))

(define-func example.load
[]
[(->
[(@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
(ext arithmetic.int))]
(ext)
(core.fn
[]
[(core.fn
[arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext arithmetic.int))]
(ext))
(dfg
[] [%0]
(signature
(->
(core.fn
[]
[(->
[(@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
[(core.fn
[arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext arithmetic.int))]
(ext)))
(load-func (@ example.caller) [] [%0]
((core.load_const _ _ example.caller) [] [%0]
(signature
(->
(core.fn
[]
[(->
[(@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
[(core.fn
[arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext arithmetic.int))]
(ext))))))
31 changes: 17 additions & 14 deletions hugr-core/tests/snapshots/model__roundtrip_cfg.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,31 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cfg.
(hugr 0)

(define-func example.cfg
(forall ?0 type)
[?0] [?0] (ext)
(param ?0 core.type)
(core.fn [?0] [?0] (ext))
(dfg
[%0] [%1]
(signature (-> [?0] [?0] (ext)))
(signature (core.fn [?0] [?0] (ext)))
(cfg [%0] [%1]
(signature (-> [?0] [?0] (ext)))
(signature (core.fn [?0] [?0] (ext)))
(cfg
[%2] [%3]
(signature (-> [(ctrl [?0])] [(ctrl [?0])] (ext)))
(signature (core.fn [(core.ctrl [?0])] [(core.ctrl [?0])] (ext)))
(block [%2] [%6]
(signature (-> [(ctrl [?0])] [(ctrl [?0])] (ext)))
(signature (core.fn [(core.ctrl [?0])] [(core.ctrl [?0])] (ext)))
(dfg
[%4] [%5]
(signature (-> [?0] [(adt [[?0]])] (ext)))
(tag 0 [%4] [%5] (signature (-> [?0] [(adt [[?0]])] (ext))))))
(signature (core.fn [?0] [(core.adt [[?0]])] (ext)))
((core.make_adt _ _ 0) [%4] [%5]
(signature (core.fn [?0] [(core.adt [[?0]])] (ext))))))
(block [%6] [%3 %6]
(signature (-> [(ctrl [?0])] [(ctrl [?0]) (ctrl [?0])] (ext)))
(signature
(core.fn
[(core.ctrl [?0])]
[(core.ctrl [?0]) (core.ctrl [?0])]
(ext)))
(dfg
[%7] [%8]
(signature (-> [?0] [(adt [[?0] [?0]])] (ext)))
(tag
0
[%7] [%8]
(signature (-> [?0] [(adt [[?0] [?0]])] (ext))))))))))
(signature (core.fn [?0] [(core.adt [[?0] [?0]])] (ext)))
((core.make_adt _ _ 0) [%7] [%8]
(signature (core.fn [?0] [(core.adt [[?0] [?0]])] (ext))))))))))
42 changes: 18 additions & 24 deletions hugr-core/tests/snapshots/model__roundtrip_cond.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,39 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cond
---
(hugr 0)

(import arithmetic.int.types.int)

(import arithmetic.int.ineg)

(define-func example.cond
[(adt [[] []]) (@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
(ext)
(core.fn
[(core.adt [[] []]) arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext))
(dfg
[%0 %1] [%2]
(signature
(->
[(adt [[] []]) (@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
(core.fn
[(core.adt [[] []]) arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext)))
(cond
[%0 %1] [%2]
(signature
(->
[(adt [[] []]) (@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
(core.fn
[(core.adt [[] []]) arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext)))
(dfg
[%3] [%3]
(signature
(->
[(@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
(core.fn
[arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext))))
(dfg
[%4] [%5]
(signature
(->
[(@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
(ext)))
((@ arithmetic.int.ineg) [%4] [%5]
(core.fn [arithmetic.int.types.int] [arithmetic.int.types.int] (ext)))
(arithmetic.int.ineg [%4] [%5]
(signature
(->
[(@ arithmetic.int.types.int)]
[(@ arithmetic.int.types.int)]
(core.fn
[arithmetic.int.types.int]
[arithmetic.int.types.int]
(ext arithmetic.int))))))))
Loading
Loading