Skip to content

Conversation

z80dev
Copy link
Contributor

@z80dev z80dev commented Sep 2, 2025

Summary

This PR modifies the Flag type to allow explicit iteration through the __values__ attribute

Changes

  • Updated Flag iteration behavior to allow explicit access to __values__

Test plan

  • Existing tests pass
  • Manual testing of Flag iteration behavior

z80dev added 2 commits August 30, 2025 00:16
- Add Flag.__values__ type member returning SArray[Flag]
- Codegen: materialize Flag.__values__ as static array of flag bitmasks
- Analysis: remove iteration over Flag type; require array/list iterator
- Codegen: drop For-over-flag-type path; use list/array iteration only
- Docs: update iteration section to use Flag.__values__
- Tests: update flag iteration tests to use __values__

BREAKING CHANGE: Iterating a flag type now requires using Flag.__values__ rather than the type itself.\n
@z80dev z80dev changed the title feat(flag): require iteration via Flag.__values__ feat(flag): enable iteration over flag values via Flag.__values__ Sep 2, 2025
@z80dev z80dev changed the title feat(flag): enable iteration over flag values via Flag.__values__ feat(flag): require iteration via Flag.__values__ Sep 2, 2025
Move HashMapT and SArrayT imports to local scope to avoid circular dependency
Copy link

codecov bot commented Sep 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.20%. Comparing base (90c952c) to head (262af81).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4739      +/-   ##
==========================================
+ Coverage   93.06%   93.20%   +0.14%     
==========================================
  Files         131      131              
  Lines       19134    19180      +46     
  Branches     3323     3295      -28     
==========================================
+ Hits        17807    17877      +70     
+ Misses        894      884      -10     
+ Partials      433      419      -14     

☔ View full report in Codecov by Sentry.
📢 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.

there was the movement of an import that we might want to do, but is
unrelated to the changes introduced in this PR
@z80dev z80dev changed the title feat(flag): require iteration via Flag.__values__ feat(flag): enable iteration via Flag.__values__ Sep 3, 2025
def get_type_member(self, key: str, node: vy_ast.VyperNode) -> "VyperType":
# Special iterator helper for flags: `Flag.__values__`
# Returns a static array type of all flag values in declaration order.
if key == "__values__":
Copy link
Member

Choose a reason for hiding this comment

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

why don't we actually put it on the flag type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just thought this syntax looked weird

for f: Foo in Foo:
    ...

Copy link
Member

Choose a reason for hiding this comment

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

no i'm not talking about the user-facing semantics, i'm saying why don't we add it to the members dict on the flag type?

@z80dev
Copy link
Contributor Author

z80dev commented Sep 26, 2025

Thanks again for the nudge here. I have moved the flag constants (and __values__) into the FlagT.members dict so they are real type members. That lets the normal type lookup machinery handle iteration helpers instead of the bespoke branch we had before. Because instances also read through that namespace, I added a guard on FlagT.get_member that keeps the runtime surface the same as today—accessing p.A still errors with a pointer to Flag.A. Without that guard we would silently change instance semantics when we land this, so the override keeps the old behaviour while letting the type grow the new helper.


# set the name for exception handling in `get_member`
self._helper._id = name
from vyper.semantics.types.subscriptable import SArrayT

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
vyper.semantics.types.subscriptable
begins an import cycle.
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.

2 participants