Conditional optional ports#510
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements “conditional optional ports” by allowing Block.Port(..., optional=...) to accept BoolLike, and refactors several microcontroller parts to use conditional optionality instead of separate require((~_model).implies(...)) constraints. This aligns with issue #507’s goal of making conditional optional ports a first-class pattern in the core API.
Changes:
- Updated core
Port(...)API to acceptoptional: BoolLikeand encode conditional required-port constraints as implications in the generated proto. - Refactored several microcontroller device definitions (RP2040, ESP32 variants) to use
optional=_modelinstead of explicit conditionalrequire(...). - Removed an unused
deprecatedimport from the STM32F303 part.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| edg/core/Blocks.py | Core support for optional: BoolLike and conditional required-port constraint emission. |
| edg/core/HierarchyBlock.py | Updates HierarchyBlock.Port signature to match the new optional: BoolLike API. |
| edg/parts/microcontroller/Rp2040.py | Replaces explicit “SPI memory required” conditional require with conditional optional ports. |
| edg/parts/microcontroller/Esp32.py | Converts chip_pu to conditional optional via _model. |
| edg/parts/microcontroller/Esp32s3.py | Converts chip_pu to conditional optional via _model. |
| edg/parts/microcontroller/Esp32c3.py | Converts crystal/strapping/LNA ports to conditional optional via _model. |
| edg/parts/microcontroller/Stm32f303.py | Removes unused deprecated import. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| self._ports: SubElementDict[BasePort] = self.manager.new_dict(BasePort) | ||
| self._required_ports = IdentitySet[BasePort]() | ||
| self._required_ports = IdentityDict[BasePort, Optional[BoolExpr]]() # port -> optional expr for required |
Comment on lines
+552
to
+555
| elif isinstance(optional, BoolExpr): | ||
| self._required_ports[elt] = ~optional | ||
| else: | ||
| raise EdgTypeError(f"optional flag to Port(...)", optional, (bool, BoolExpr)) |
Comment on lines
+406
to
+409
| precondition = self._required_ports[port] | ||
| if precondition is not None: | ||
| connected_condition = precondition.implies(connected_condition) | ||
|
|
Comment on lines
291
to
293
| self._ports: SubElementDict[BasePort] = self.manager.new_dict(BasePort) | ||
| self._required_ports = IdentitySet[BasePort]() | ||
| self._required_ports = IdentityDict[BasePort, Optional[BoolExpr]]() # port -> expr for not-required | ||
| self._port_docs = IdentityDict[BasePort, str]() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Simplifies some of the model port-optional from the wrapper microcontroller refactors.
Resolves #507