Repository navigation
analysis: reference analysis for squin qubits and jeff wires - #865
nathanieltornow merged 1 commit into
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
aa84617 to
2243f6c
Compare
david-pl
left a comment
There was a problem hiding this comment.
Neat PR, just some small issues with Bottom types and I'm not sure what happens when you nest return values. Otherwise looks good, so I'm approving to unblock merging, but it might make sense to address some things first.
| while node is not None: | ||
| if node is code: | ||
| return True | ||
| node = node.parent_stmt |
There was a problem hiding this comment.
Is there some walking logic in kirin that can already do this?
There was a problem hiding this comment.
yes, replaced
|
|
||
| keys = (KEY, "absint") | ||
| lattice = Ref | ||
| max_depth: int = field(default=64, kw_only=True) |
There was a problem hiding this comment.
What's the reason behind this lower default? InterpreterABC has default=800.
There was a problem hiding this comment.
it was because of the issue of the C-stack overflowing (QuEraComputing/kirin#743)
now, i removed the line and skip the tests that have recursive structure.
| returned: dict[Root, Root] = {} | ||
| outputs = result.refs if isinstance(result, Positions) else (result,) | ||
| for position, ref in enumerate(outputs): | ||
| if isinstance(ref, (Whole, Register)) and _inside(ref.root, code): |
There was a problem hiding this comment.
What happens if there is a nested return, e.g. return ((q, q), 1)?
There was a problem hiding this comment.
We now explicitly reject nested nodes as returns
|
|
||
| def kind(self, type_: types.TypeAttribute) -> type[Whole] | type[Register] | None: | ||
| """Return `Whole` for a wire, `Register` for a register, else None.""" | ||
| if type_.is_subseteq(QuregType): |
There was a problem hiding this comment.
Doesn't play nice when type_ is Bottom.
| if type_.is_subseteq(ilist.IListType[QubitType, types.Any]): | ||
| return Register | ||
| if type_.is_subseteq(QubitType): | ||
| return Whole |
There was a problem hiding this comment.
Another if where Bottom would lead to the wrong behavior.
2243f6c to
500adaf
Compare
6275ba3
into
QuEraComputing:feat/jeff
This PR adds a forward analysis that states which allocation or parameter each value refers to.
Design
The analysis is generic and lives in
bloqade/analysis/reference/, like the address analysis. A subclass implements:kind(type)says whether a type is one tracked item (Whole), a register of items (Register) or untracked, andregister_length(root, call)gives the static length of a register.QubitReferenceAnalysisinbloqade/squin/analysis/reference.pytracks squin qubits, andWireReferenceAnalysisinbloqade/jeff/analysis/wire.pytracks jeff wires.Example
Limits
The result of a recursive call, a slice of a register, an index into a list at a runtime index, and a root that a callee allocates without returning it are
Unknown.Also in this PR
bloqade/constants.py::constant_intreads an integer out of any statement with kirin'sConstantLiketrait. It replacesbloqade/jeff/constants.py::const_int.Calldeclares aStaticCalltrait.