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

DRAFT: feat: Prototype dataflow analysis for static circuit extraction #1664

Draft
wants to merge 249 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
249 commits
Select commit Hold shift + click to select a range
c7a9d89
Just const_fold2 + inside that partial_value (taken from hugr_core)
acl-cqc Aug 6, 2024
ac45e53
merge/update+fmt (ValueName for ConstInt non-compiling as ConstInt no…
acl-cqc Sep 11, 2024
8adaa6e
Missing imports / lints. Now running, but failing w/StackOverflow
acl-cqc Aug 6, 2024
098c735
Fix tests...
acl-cqc Aug 6, 2024
706c892
ValueKey using MaybeHash
acl-cqc Aug 6, 2024
63bc944
tag() does not refer to self.is_compound
acl-cqc Aug 6, 2024
5fa7edb
ValueHandle::{is_compound,num_fields,index} => {variant_values, as_sum}
acl-cqc Aug 6, 2024
98bf94a
Rm ValueHandle::tag, use variant_values - inefficient, presume this i…
acl-cqc Aug 6, 2024
295ec32
add variant_values, rewrite one use of outputs_for_variant
acl-cqc Aug 6, 2024
5c8289e
...and the other two; remove outputs_for_variant
acl-cqc Aug 6, 2024
bf173ab
Rewrite tuple rule to avoid indexing
acl-cqc Aug 6, 2024
0ae4d19
GC unused (tuple,variant)_field_value, iter_with_ports
acl-cqc Aug 6, 2024
8608ba9
Common up via ValueRow.unpack_first
acl-cqc Aug 6, 2024
2dca3e9
No DeRef for ValueHandle, just add get_type()
acl-cqc Aug 6, 2024
51e68ea
ValueKey::{Select->Field,index->field}
acl-cqc Aug 6, 2024
8635474
(join/meet)_mut_unsafe => try_(join/meet)_mut with Err for conflictin…
acl-cqc Aug 7, 2024
80d5b86
Remove ValueHandle::variant_values - just have as_sum
acl-cqc Aug 8, 2024
1c8be99
Optimize as_sum() by returning impl Iterator not Vec
acl-cqc Aug 8, 2024
b0afa54
Machine uses PV not PartialValue
acl-cqc Aug 27, 2024
d09a1fe
Parametrize PartialValue+PV+Machine by AbstractValue/Into<Value>, Con…
acl-cqc Aug 28, 2024
af8827b
Move partial_value.rs inside datalog/
acl-cqc Aug 28, 2024
4b61436
Hide PartialSum/PartialValue
acl-cqc Aug 28, 2024
8b31d8c
refactor: ValueRow::single_among_bottoms
acl-cqc Aug 28, 2024
6a72961
Factor out propagate_leaf_op; add ValueRow::from_iter
acl-cqc Aug 28, 2024
780af9b
Add handling for Tag
acl-cqc Aug 28, 2024
cabcf04
Remove PV (use typedef in datalog.rs)
acl-cqc Aug 28, 2024
5e4a04f
Allow DFContext to interpret any leaf op (except MakeTuple/etc.); pub…
acl-cqc Aug 28, 2024
1453886
Also fold extension ops
acl-cqc Aug 28, 2024
221e96c
Comment as_sum
acl-cqc Aug 30, 2024
cd4e15c
Rename DataflowContext to HugrValueContext
acl-cqc Aug 30, 2024
c5ab2a9
Move {datalog=>value_handle}/context.rs - an impl, datalog uses only …
acl-cqc Aug 30, 2024
6c80acf
Comment re. propagate_leaf_op
acl-cqc Aug 30, 2024
636f14d
Hide PartialValue by abstracting DFContext::InterpretableVal: FromSum…
acl-cqc Aug 30, 2024
0acdcc5
Use Value::sum, adding FromSum::Err; fmt
acl-cqc Aug 30, 2024
1012e0a
Cargo.toml: use explicit git= tag for ascent
acl-cqc Sep 2, 2024
6bd8dba
Fix rebase: TryHash, UnpackTuple/MakeTuple now in prelude
acl-cqc Sep 2, 2024
f7d288f
pub ValueRow+Partial(Value/Sum); add TotalContext
acl-cqc Sep 2, 2024
a62eb0f
Remove DFContext::hugr(), as_ref() does just as well
acl-cqc Sep 2, 2024
f0ec237
Move partial_value out of datalog, combine tests; move ValueRow out o…
acl-cqc Sep 2, 2024
82a3f22
Move FromSum and try_into_value into total_context.rs
acl-cqc Sep 2, 2024
e6dc114
Separate mod dataflow from mod const_fold2
acl-cqc Sep 2, 2024
03ff165
fmt
acl-cqc Sep 2, 2024
25ed1fb
TailLoopTermination just examine whatever PartialValue's we have, rem…
acl-cqc Sep 2, 2024
09911df
Drop non-(Bounded)Lattice impls of (join/meet)(_mut),top,bottom
acl-cqc Sep 2, 2024
248fb07
doc fixes, remove missing-docs for partial_value...how does it still …
acl-cqc Sep 2, 2024
e2ad079
fix all warnings (inc Machine::new() -> impl Default)
acl-cqc Sep 2, 2024
95e2dd9
distribute utils.rs -> machine.rs
acl-cqc Sep 2, 2024
7f1e122
Move dataflow{/datalog=>}/test.rs
acl-cqc Sep 2, 2024
faff556
and more warnings
acl-cqc Sep 2, 2024
401354d
fix extension tests
acl-cqc Sep 2, 2024
c468387
Fix doclink, fix DefaultHasher pre-1.76
acl-cqc Sep 2, 2024
88db5b1
comment conditional test
acl-cqc Sep 11, 2024
738b61b
Clarify (TODO untested) branches of join_mut
acl-cqc Sep 11, 2024
8f9c1ed
Exploit invariant PartialValue::Value is not a sum (even single known…
acl-cqc Sep 11, 2024
a71ba97
Exploit invariant more, RIP join_mut_value_handle
acl-cqc Sep 11, 2024
05280a8
By similar logic, RIP meet_mut_value_handle; assert_(in)variants now …
acl-cqc Sep 11, 2024
96b0856
Rename TestSum(,Leaf)Type::assert_{invariants=>valid}
acl-cqc Sep 13, 2024
f21e278
Rename assert_(=>in)variants (i.e. to match); call in (join/meet)_mut…
acl-cqc Sep 13, 2024
ce53b1c
test unpacking constant tuple
acl-cqc Sep 13, 2024
13f29a9
try_into_value returns new enum ValueOrSum; TryFrom<ValueOrSum> repla…
acl-cqc Sep 12, 2024
9f1a5cd
Hide ValueRow (and move into datalog.rs)
acl-cqc Oct 2, 2024
15e642e
Remove PartialSum::unit()
acl-cqc Oct 2, 2024
514af13
PartialValue is private struct containing PVEnum (with ::Sum not ::Pa…
acl-cqc Oct 2, 2024
5d86f46
variant => new_variant, unit => new_unit
acl-cqc Oct 2, 2024
d8c8140
Simplify PartialOrd for PartialSum, keys(1,2) support cmp
acl-cqc Oct 2, 2024
1315685
PartialSum::variant_values does not take `len` (PartialValue:: still …
acl-cqc Oct 2, 2024
2aaaeb9
clippy
acl-cqc Oct 2, 2024
5619761
Machine::tail_loop_terminates + case_reachable return Option not panic
acl-cqc Oct 2, 2024
f3c175c
Machine::read_out_wire_value fails with ConstTypeError if there was one
acl-cqc Oct 2, 2024
aad2ef0
PartialValue::try_(join|meet)_mut are pub, don't mutate upon failure
acl-cqc Oct 2, 2024
0a8cc12
Remove some commented-out code
acl-cqc Oct 2, 2024
bfcd0a6
Expose PartialSum
acl-cqc Oct 2, 2024
248fb23
dataflow has docs! (enforced)
acl-cqc Oct 2, 2024
5b8654e
clippy
acl-cqc Oct 2, 2024
c40e718
Move PartialValue::join into impl Lattice for
acl-cqc Oct 7, 2024
8732a63
Machine::read_out_wire_value => PartialValue::try_into_wire_value
acl-cqc Oct 7, 2024
346187d
read_out_wire_partial_value => read_out_wire
acl-cqc Oct 7, 2024
a139f9e
Remove ValueOrSum (and add Sum) via complex parametrization of try_in…
acl-cqc Oct 7, 2024
7f2a91a
Datalog works on any AbstractValue; impl'd by PartialValue for a Base…
acl-cqc Oct 7, 2024
1680829
PartialValue proptests: rm TestSumLeafType, replace ValueHandle with …
acl-cqc Oct 8, 2024
2a57a15
tests: Rename type_check -> check_value
acl-cqc Oct 8, 2024
fcfcb6b
tidies
acl-cqc Oct 8, 2024
dcaa928
Add a couple more proptests, and a TEMPORARY FIX for a BUG pending be…
acl-cqc Oct 8, 2024
bcacbcc
Remove redundant test
acl-cqc Oct 8, 2024
5192ed8
Refactor TailLoopTermination::from_control_value
acl-cqc Oct 8, 2024
e21bbd7
pub TailLoopTermination, rename members, doc
acl-cqc Oct 8, 2024
22e0192
Test tidies (and some ALAN wtf? comments)
acl-cqc Oct 8, 2024
cae5e4f
Use Tag
acl-cqc Oct 8, 2024
3014827
Add TestContext (no interpret_leaf_op), propolutate, avoid HugrValueC…
acl-cqc Oct 8, 2024
64b9bb7
Avoid propolutate by interpreting LoadConstant (only)
acl-cqc Oct 8, 2024
8bc5e12
Revert "Avoid propolutate by interpreting LoadConstant (only)"
acl-cqc Oct 8, 2024
a3a6213
tiny const_fold2 doc tweaks
acl-cqc Oct 8, 2024
a96ab20
(TEMP) remove const_fold2 module
acl-cqc Oct 8, 2024
3051183
Merge remote-tracking branch 'origin/main' into acl/const_fold2
acl-cqc Oct 8, 2024
777694c
(TEMP) Rm total_context
acl-cqc Oct 8, 2024
9e47b7f
Revert "(TEMP) Rm total_context"
acl-cqc Oct 8, 2024
668c030
Revert "(TEMP) remove const_fold2 module"
acl-cqc Oct 8, 2024
5a16e6b
clippy
acl-cqc Oct 8, 2024
4f31178
Better fix for PartialSum::try_meet_mut
acl-cqc Oct 9, 2024
2b523c9
true_or_false uses pv_true+pv_false
acl-cqc Oct 9, 2024
1d2cb9b
Update to ascent 0.7.0, drop fn join/meet as these are now trait-default
acl-cqc Oct 9, 2024
ee91bbe
Cargo.toml: oops, remove obsolete comment
acl-cqc Oct 9, 2024
e67051f
ValueRow cleanups (remove misleading 'pub's)
acl-cqc Oct 9, 2024
94cee55
Refactor: rm tail_node, clone earlier in ValueRow::unpack_first, rm V…
acl-cqc Oct 9, 2024
5cf5ff0
Add datalog for CFG
acl-cqc Oct 9, 2024
7381087
refactor: follow unpack_first with enumerate
acl-cqc Oct 9, 2024
60e33db
Remove comments from test_tail_loop_(iterates_twice->two_iters)
acl-cqc Oct 9, 2024
ef4f433
Add a test of tail loop around conditional
acl-cqc Oct 9, 2024
5935489
improve that test - loop input is a sum and the variants have differe…
acl-cqc Oct 9, 2024
b198681
clippy/nth
acl-cqc Oct 10, 2024
ed30f80
revert accidental changes to hugr-core/src/types.rs (how?!)
acl-cqc Oct 10, 2024
3f7808a
Cleanup conditional, cfg, unpack_first
acl-cqc Oct 10, 2024
436b635
Complex CFG that does a not-XOR...but analysis generally says "true o…
acl-cqc Oct 9, 2024
0374d13
Propagate case results to conditional output only if case reached; so…
acl-cqc Oct 10, 2024
6a2dd9e
More test cases
acl-cqc Oct 10, 2024
a75fee9
refactor as fixture
acl-cqc Oct 10, 2024
151e571
clippy
acl-cqc Oct 10, 2024
e15b04d
Revert "Datalog works on any AbstractValue; impl'd by PartialValue fo…
acl-cqc Oct 14, 2024
ea10ed3
Merge branch 'acl/const_fold2' (early part) into acl/const_fold3
acl-cqc Oct 14, 2024
949ef70
Update const_fold2/value_handle.rs, dataflow/total_context.rs
acl-cqc Oct 14, 2024
dc08f0d
(Re-)remove PVEnum
acl-cqc Oct 14, 2024
436dcd2
Remove as_sum. AbstractValues are elements not sums
acl-cqc Oct 14, 2024
e817bbe
clippy
acl-cqc Oct 14, 2024
b06cfad
Refactor: remove 'fn input_count'
acl-cqc Oct 14, 2024
fd717be
Try to fix interpret_leaf_op: cannot use Bottom for output! But ascen…
acl-cqc Oct 14, 2024
9b17439
interpret_leaf_op for ExtensionOps only; LoadConstant via value_from_…
acl-cqc Oct 14, 2024
1d714c8
Merge branch 'acl/const_fold2' (early part) into acl/const_fold3
acl-cqc Oct 14, 2024
1f41056
Odd updates to total_context.rs - REVERT ??
acl-cqc Oct 14, 2024
846d1ee
Correct comment BaseValue -> AbstractValue
acl-cqc Oct 15, 2024
328e7f8
test Hugr now returns (XOR, AND) of two inputs, one case wrongly prod…
acl-cqc Oct 15, 2024
da3c05c
BB reachability, fixes!
acl-cqc Oct 10, 2024
6930ad4
Test cases with true_or_false/top, standardize naming (->test_)condit…
acl-cqc Oct 15, 2024
0a3e281
Try to common up by using case_reachable in conditional outputs - 6 t…
acl-cqc Oct 11, 2024
b1e0bfd
Make case_reachable a relation (dropping bool), not lattice - fixes t…
acl-cqc Oct 11, 2024
355e814
Call (+test)
acl-cqc Oct 15, 2024
22f3ce8
propolutate_out_wires => prepopulate and set in wires in run
acl-cqc Oct 15, 2024
68b1d48
Rm/inline value_inputs/value_outputs, use UnpackTuple, comments
acl-cqc Oct 15, 2024
77a5fa3
Merge remote-tracking branch 'origin/main' into acl/const_fold2
acl-cqc Oct 15, 2024
2cc62f0
clippy
acl-cqc Oct 15, 2024
8254771
docs
acl-cqc Oct 15, 2024
7e81b15
Separate AnalysisResults from Machine, use context.exactly_one() not …
acl-cqc Oct 21, 2024
34e82ed
Move try_into_wire_value => AnalysisResults.try_read_wire_value
acl-cqc Oct 21, 2024
015707f
doc fixes and fix comment
acl-cqc Oct 21, 2024
ff39f7d
Try to make clippy happy
acl-cqc Oct 21, 2024
0b71236
Merge branch 'acl/const_fold2' into acl/const_fold3
acl-cqc Oct 21, 2024
502d4a2
Fix/make-compile total_context.rs
acl-cqc Oct 21, 2024
25c4a82
total_context: return PartialValue, as need some repr of Sum
acl-cqc Oct 21, 2024
e7f6ad1
const_fold2: disable missing-docs warning
acl-cqc Oct 21, 2024
8a8db96
fix context, value_handle
acl-cqc Oct 21, 2024
ada7ee1
Use ascent_run to drop context from all the relations. Lots cleanup t…
acl-cqc Oct 22, 2024
7c02d41
DFContext does not Deref, pass Hugr separately
acl-cqc Oct 22, 2024
3d4f016
Massively reduce scope of clippy-allow to inside run_datalog
acl-cqc Oct 22, 2024
8bab4d5
Move ValueRow into own file
acl-cqc Oct 22, 2024
3eccadf
Move Machine into datalog.rs, pub(super) fields in AnalysisResults, r…
acl-cqc Oct 22, 2024
0f4fa52
Move machine.rs to results.rs
acl-cqc Oct 22, 2024
caa8aca
Remove enum IO, replace io_node -> input_child/output_child
acl-cqc Oct 22, 2024
e7f61fc
move docs
acl-cqc Oct 22, 2024
811802c
Remove/inline/dedup dfb_block
acl-cqc Oct 22, 2024
3713ea7
relation doc
acl-cqc Oct 22, 2024
d317809
datalog docs (each relation), move _cfg_succ_dest
acl-cqc Oct 22, 2024
69c3270
comment, use exactly_one
acl-cqc Oct 22, 2024
dc56686
Allow to handle LoadFunction
acl-cqc Oct 23, 2024
1810198
Merge branch 'acl/const_fold2' into acl/const_fold3
acl-cqc Oct 23, 2024
58f707a
TotalContext: don't get_optype, use the ExtensionOp via DataflowOpTrait
acl-cqc Oct 23, 2024
0566481
TotalContext: do not require Eq, Hash, etc.
acl-cqc Oct 23, 2024
a497723
HugrValueContext -> ConstFoldContext, empty, no need for Eq/Hash/etc.
acl-cqc Oct 23, 2024
33a8592
doc
acl-cqc Oct 23, 2024
b153ada
Separate out ConstLoader
acl-cqc Oct 23, 2024
5052ac0
value_from_(custom_const=>opaque), taking &OpaqueValue
acl-cqc Oct 23, 2024
8b83284
Merge branch 'acl/const_fold2' into acl/const_fold3
acl-cqc Oct 23, 2024
d14cc69
TotalContext requires ConstLoader
acl-cqc Oct 23, 2024
56b10f5
WIP implement ConstLoader, munge ValueHandle construction
acl-cqc Oct 23, 2024
dff52bd
Restructure ValueHandle: no keys for HashedConsts, add functions.
acl-cqc Oct 23, 2024
af651e0
(TEMP / to undo later?) Remove ValueHandle::Function
acl-cqc Oct 25, 2024
29d7e03
Tidy / fix tests
acl-cqc Oct 25, 2024
8b5f6b0
note about keying by outgoingport
acl-cqc Oct 26, 2024
9f9a218
(?to revert?) Handle some LoadFunction's by reading subgraphs from Hugr
acl-cqc Oct 25, 2024
ad0c6f2
Recombine DFContext with Hugr i.e. reinstate Deref constraint
acl-cqc Oct 28, 2024
16a18f4
Replace Deref with HugrView, trivially obtainable by implementing AsRef
acl-cqc Oct 28, 2024
99074e1
Merge branch 'acl/const_fold2' into HEAD
acl-cqc Oct 28, 2024
8058dab
Implement pass via MutRefCell (TODO: Combine with ConstFoldContext)
acl-cqc Oct 28, 2024
a766ed9
Combine ConstFoldContext with MutRefCell, context.rs -> test.rs
acl-cqc Oct 28, 2024
a0f2b2c
ValueRow Debug; ops default to PartialValue::Top less aggressively
acl-cqc Oct 28, 2024
53447fe
Reorder, make look more like original const_fold
acl-cqc Oct 28, 2024
e45a620
copy all old const_fold tests over
acl-cqc Oct 28, 2024
e64f519
tests: Fix test_add
acl-cqc Oct 28, 2024
58a1df2
fix: Improve find_needed_nodes
acl-cqc Oct 28, 2024
6687656
fix: Connect constant to use
acl-cqc Oct 28, 2024
c7ba482
Don't break LoadConstant out_wires; skip unnecessary cloning
acl-cqc Oct 28, 2024
294c8a7
Merge branch 'acl/const_fold2' into HEAD
acl-cqc Oct 28, 2024
7484fb9
Remove old const_fold and rename over
acl-cqc Oct 28, 2024
55f9700
Revert accidental changes to views.rs
acl-cqc Oct 28, 2024
494d849
Hide AnalysisResults::hugr via accessor,destructor,two-step transform
acl-cqc Oct 29, 2024
25f2bb7
Separate out DFContext::hugr(&self) -> &impl HugrView
acl-cqc Oct 29, 2024
522d159
Revert "Separate out DFContext::hugr(&self) -> &impl HugrView"
acl-cqc Oct 29, 2024
ebebb18
RIP TotalContext
acl-cqc Oct 29, 2024
46944f8
Two-stage transform means we don't need to extract HugrView from results
acl-cqc Oct 29, 2024
0b005e4
Go back to Deref, w/ type DFContext::View.
acl-cqc Oct 29, 2024
c4224fe
clippy+doc
acl-cqc Oct 29, 2024
87eb700
And back to Deref, should allow using a region view not the whole Hugr
acl-cqc Oct 29, 2024
1bb0756
Merge branch 'acl/const_fold2' into acl/const_fold3
acl-cqc Oct 29, 2024
a49221b
fix doclink
acl-cqc Oct 30, 2024
71ea55d
PartialSum::try_into_value also uses Option<...> as error-type
acl-cqc Oct 30, 2024
ea9db2e
Proper errors from try_into_value, Option<Extr...> from try_read_wire…
acl-cqc Oct 30, 2024
df31523
fmt
acl-cqc Oct 30, 2024
124bad2
Merge branch 'acl/const_fold2' into acl/const_fold3
acl-cqc Oct 30, 2024
e78c006
...and fix by using try_into_value(!)...
acl-cqc Oct 30, 2024
a490874
Add test running on region
acl-cqc Oct 30, 2024
3af39aa
fix: provide PartialValue::Top for unspecified Hugr inputs
acl-cqc Oct 30, 2024
dc15999
try_into_value allows TryFrom by giving ExtractValueError *2* errorty…
acl-cqc Oct 30, 2024
2d81264
improve docs
acl-cqc Oct 30, 2024
b61d252
Parametrize Machine::try_read_wire_value the same way
acl-cqc Oct 30, 2024
8cac194
tweaks
acl-cqc Oct 30, 2024
19ec62e
v1 test...fails: tuple can't be removed, nothing removed, but at leas…
acl-cqc Oct 30, 2024
72a3034
v2, discard unknown in middle
acl-cqc Oct 30, 2024
a339cb0
docs
acl-cqc Oct 30, 2024
b871f61
cfg
acl-cqc Oct 30, 2024
2c615c6
drop unused From<OpaqueValue> for Box<dyn-CustomConst>
acl-cqc Oct 30, 2024
514efc1
Merge remote-tracking branch 'origin/acl/const_fold2' into acl/const_…
acl-cqc Oct 31, 2024
5c880e4
...and patch up try_into_wire_value's with type annotations
acl-cqc Oct 31, 2024
ec2cc78
Add recursive might_diverge, assume true for all CFGs
acl-cqc Nov 4, 2024
6ba0b25
Clarify "non-exhaustive" in comment
acl-cqc Nov 4, 2024
e681602
ConstFoldContext needs only & not &mut
acl-cqc Nov 4, 2024
fc44ded
Test constant folding a TailLoop (cannot remove loop)
acl-cqc Nov 4, 2024
ae9cb7c
Add pub fn allow_increase_termination, test allows removing tail-loop
acl-cqc Nov 4, 2024
3a43ae1
Hide allow_increase_termination field now we have method
acl-cqc Nov 4, 2024
f0e84ac
Allow adding inputs (pub traverse_value), fix needing port-num to dis…
acl-cqc Nov 4, 2024
02262d6
traverse_value => partial_from_const, fix docs
acl-cqc Nov 4, 2024
81b8179
fixup! Allow adding inputs
acl-cqc Nov 4, 2024
a038608
Expand test by providing always-break input, refactor/split
acl-cqc Nov 4, 2024
d90190b
refactor: assert_fully_folded takes HugrView
acl-cqc Nov 5, 2024
8f89c88
refactor: find_needed_nodes works out root itself
acl-cqc Nov 5, 2024
a6bb507
CFG test (failing atm)
acl-cqc Nov 5, 2024
3e05639
fix/change-policy: don't break edges from root input
acl-cqc Nov 5, 2024
5b2a2c9
Fix: don't follow CFG edges, but don't panic either
acl-cqc Nov 5, 2024
dcf76a6
clippy, moving might_diverge outside ConstFoldPass+parametrize
acl-cqc Nov 5, 2024
92488fe
Improve const_fold module doc
acl-cqc Nov 5, 2024
45a9869
wip
doug-q Nov 15, 2024
d1172c7
wip
doug-q Nov 15, 2024
07efbb4
Merge remote-tracking branch 'origin/main' into doug/static-circuit
doug-q Nov 15, 2024
0b36617
wip
doug-q Nov 15, 2024
c60e2c7
wip
doug-q Nov 15, 2024
19589b0
wip
doug-q Nov 15, 2024
f6a6b65
wip
doug-q Nov 17, 2024
ae857a1
wip
doug-q Nov 17, 2024
9520633
wip
doug-q Nov 17, 2024
4a88d90
wip
doug-q Nov 18, 2024
35a7c6f
fmt
doug-q Nov 18, 2024
4f15ffa
works
doug-q Nov 18, 2024
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
Prev Previous commit
Next Next commit
traverse_value => partial_from_const, fix docs
acl-cqc committed Nov 4, 2024

Verified

This commit was signed with the committer’s verified signature. The key has been revoked.
eggplants haruna
commit 02262d67573037d6dd1017f86eeb673be9ffd59d
6 changes: 3 additions & 3 deletions hugr-passes/src/const_fold.rs
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ use value_handle::ValueHandle;

use crate::{
dataflow::{
traverse_value, AnalysisResults, ConstLoader, DFContext, Machine, PartialValue,
partial_from_const, AnalysisResults, ConstLoader, DFContext, Machine, PartialValue,
TailLoopTermination,
},
validation::{ValidatePassError, ValidationLevel},
@@ -61,7 +61,7 @@ impl ConstFoldPass {
let inputs = self.inputs.iter().map(|(p, v)| {
(
p.clone(),
traverse_value(&ConstFoldContext(hugr), fresh_node, &mut vec![p.index()], v),
partial_from_const(&ConstFoldContext(hugr), fresh_node, &mut vec![p.index()], v),
)
});

@@ -277,7 +277,7 @@ impl<'a, H: HugrView> DFContext<ValueHandle> for ConstFoldContext<'a, H> {
})
.collect::<Vec<_>>();
for (p, v) in op.constant_fold(&known_ins).unwrap_or_default() {
outs[p.index()] = traverse_value(self, node, &mut vec![p.index()], &v);
outs[p.index()] = partial_from_const(self, node, &mut vec![p.index()], &v);
}
}
}
15 changes: 8 additions & 7 deletions hugr-passes/src/dataflow.rs
Original file line number Diff line number Diff line change
@@ -47,12 +47,9 @@ pub trait DFContext<V>: ConstLoader<V> + std::ops::Deref<Target = Self::View> {
/// are "correct" but maximally conservative (minimally informative).
pub trait ConstLoader<V> {
/// Produces a [PartialValue] from a constant. The default impl (expected
/// to be appropriate in most cases) traverses [Sum](Value::Sum) constants
/// to their leaves ([Value::Extension] and [Value::Function]),
/// converts these using [Self::value_from_opaque] and [Self::value_from_const_hugr],
/// and builds nested [PartialValue::new_variant] to represent the structure.
/// to be appropriate in most cases) uses [partial_from_const].
fn value_from_const(&self, n: Node, cst: &Value) -> PartialValue<V> {
traverse_value(self, n, &mut Vec::new(), cst)
partial_from_const(self, n, &mut Vec::new(), cst)
}

/// Produces an abstract value from an [OpaqueValue], if possible.
@@ -79,7 +76,11 @@ pub trait ConstLoader<V> {
}
}

pub fn traverse_value<V>(
/// Converts a constant [Value] by traversing [Sum](Value::Sum) constants
/// to their leaves ([Value::Extension] and [Value::Function]),
/// converting these using [ConstLoader::value_from_opaque] and [ConstLoader::value_from_const_hugr],
/// and building nested [PartialValue::new_variant]s to represent the structure.
pub fn partial_from_const<V>(
s: &(impl ConstLoader<V> + ?Sized),
n: Node,
fields: &mut Vec<usize>,
@@ -89,7 +90,7 @@ pub fn traverse_value<V>(
Value::Sum(hugr_core::ops::constant::Sum { tag, values, .. }) => {
let elems = values.iter().enumerate().map(|(idx, elem)| {
fields.push(idx);
let r = traverse_value(s, n, fields, elem);
let r = partial_from_const(s, n, fields, elem);
fields.pop();
r
});