Skip to content

Conditional optional ports#510

Merged
ducky64 merged 5 commits into
masterfrom
conditional-require
Jun 1, 2026
Merged

Conditional optional ports#510
ducky64 merged 5 commits into
masterfrom
conditional-require

Conversation

@ducky64

@ducky64 ducky64 commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Simplifies some of the model port-optional from the wrapper microcontroller refactors.

Resolves #507

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 accept optional: BoolLike and encode conditional required-port constraints as implications in the generated proto.
  • Refactored several microcontroller device definitions (RP2040, ESP32 variants) to use optional=_model instead of explicit conditional require(...).
  • Removed an unused deprecated import 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.

Comment thread edg/core/Blocks.py Outdated

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 thread edg/core/Blocks.py
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 thread edg/core/Blocks.py
Comment on lines +406 to +409
precondition = self._required_ports[port]
if precondition is not None:
connected_condition = precondition.implies(connected_condition)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread edg/core/Blocks.py
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]()
@ducky64 ducky64 merged commit 3d4f75f into master Jun 1, 2026
12 checks passed
@ducky64 ducky64 deleted the conditional-require branch June 1, 2026 06:46
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.

Port(..., optional) should take a BoolLike

2 participants