Skip to content

resolve() touch ups#286

Merged
ktbarrett merged 5 commits into
devfrom
resolve-touch-ups
Jun 21, 2026
Merged

resolve() touch ups#286
ktbarrett merged 5 commits into
devfrom
resolve-touch-ups

Conversation

@ktbarrett

@ktbarrett ktbarrett commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Supersedes #283.

I decided that we are going to handle metavlue resolving in the handles and not on the datatypes themselves since that makes for some truly strange semantics. But I did keep some good ideas from the old PR:

  • WEAK resolve method now throws on metavlues.
  • Logic.is_resolvable and LogicArray.is_resolvable now take a resolve method.
  • Logic.resolve and LogicArray.resolve now return a Bit and BitArray, respectively.

Python is left unchanged to make this mergeable now.

@ktbarrett ktbarrett changed the title Resolve touch ups resolve() touch ups Jun 17, 2026
@ktbarrett ktbarrett force-pushed the resolve-touch-ups branch from 3935b6c to f10f4a9 Compare June 21, 2026 00:30
@ktbarrett ktbarrett requested a review from ZiaCheemaGit June 21, 2026 00:30
@ktbarrett ktbarrett marked this pull request as ready for review June 21, 2026 00:31
@ktbarrett ktbarrett force-pushed the resolve-touch-ups branch from f10f4a9 to 406218c Compare June 21, 2026 00:34
The WEAK resolve method used to map W to X and pass U/X/Z/- through
unchanged. That left WEAK as a "best effort" pass that quietly returned
non-resolvable values, which is at odds with the obvious reading of "the
method either resolves to 0/1 or fails."

After this change, WEAK accepts only 0/1/L/H (the strengths that have a
meaningful 0/1 interpretation) and throws std::invalid_argument on
everything else. Callers that want X/Z/U/W/- to silently pick a value
already have ZEROS/ONES/RANDOM. Callers that want strict 0/1 already
have ERROR. WEAK now slots between them as "accept HDL weak strengths,
reject metavalues."
is_resolvable() previously hard-coded WEAK. This makes it not
particularly useful as a predicate for "will resolve() throw?" Also it
wasn't a good predicate for WEAK either since WEAK still returned a
value when it got an unresolvable metavalue.
Previously this returned Self, now since all methods resolve to 0/1 this
can return Bit and BitArray/BitVector. These types have implicit casts
to bool and Bit has an implicit int cast. This also is a good jumping
off point to cast to Unsigned, Signed, Sfixed, Ufixed, or Float.
@ktbarrett ktbarrett force-pushed the resolve-touch-ups branch from 406218c to a6624d3 Compare June 21, 2026 00:40
@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.88%. Comparing base (e6ca37e) to head (ea7d2bb).

Files with missing lines Patch % Lines
nanobind/src/types/bind_logic.cpp 80.76% 4 Missing and 1 partial ⚠️
cpp/include/coconext/types/logic.hpp 0.00% 1 Missing ⚠️
cpp/src/logic.cpp 95.45% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #286      +/-   ##
==========================================
- Coverage   92.05%   91.88%   -0.18%     
==========================================
  Files          23       23              
  Lines        1309     1318       +9     
  Branches      316      330      +14     
==========================================
+ Hits         1205     1211       +6     
- Misses         43       45       +2     
- Partials       61       62       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

resolve(method) now returns std::optional<Bit> (Logic/Bit) or
std::optional<Array<Bit, R>> / std::optional<Vector<Bit>>
(LogicArrayMixin). This was done because the previous method required a
two-pass approach which is usually a performance smell.
@ktbarrett ktbarrett force-pushed the resolve-touch-ups branch from a6624d3 to ea7d2bb Compare June 21, 2026 00:52
@ktbarrett

Copy link
Copy Markdown
Owner Author

The remaining coverage holes will be covered by upstream PRs.

@ktbarrett ktbarrett merged commit 241a21d into dev Jun 21, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant