Skip to content

Fix lookup into macros that can introduce members into types and extensions #64840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 2, 2023

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Apr 1, 2023

Fix and improve lookup for macro-introduced members within types and their extensions:

  • Find members introduced by peer macros within extensions (before, they only worked within nominal type definitions)
  • Find members introduced by member macros on extensions (before, they only worked on nominal type definitions)
  • Only expand member macros during name lookup if they can produce the name in question.
  • Avoid reference cycles for freestanding macros by using the simpler macro resolution approach we've employed for attached macros
  • Ensure that we instantiate member and peer macros for extensions and members thereof before visible name lookup

Fixes rdar://107530389

When populating the name lookup tables for a nominal type, we were only
visiting declarations with peer macros within the nominal type
declaration itself. Also visit the members of extensions of the
nominal type.

Without this change, peer-macro-defined members of extensions are not
visible.
…isible.

Ensure that name lookup triggers the expansion of member macros on
extensions, so we can find those names. And fix a bug that caused
expansion of member macros to crash.
…kup.

Rather than eagerly expanding all member macros when doing any name
lookup into a type, use the same introduced-name-tracking logic we
apply to peer macros to only expand those member macros that can
produce the requested name. This makes the compiler lazier.
When populating the name lookup tables with macro-expanded declarations,
we were careful to avoid full macro resolution for attached macros, but
freestanding macros were will doing full resolution. Switch
freestanding macros over to the same partial resolution mechanism to
avoid reference cycles.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

Some lookups, such as the ones used for protocol conformance checking,
provide full names (with arguments). Drop everything down to simple names
so they we don't skip macro expansions when we might need them.
@DougGregor
Copy link
Member Author

The Observation failure was a useful one; I've now fixed an issue with compound names dodging macro expansions.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor merged commit 7dca692 into swiftlang:main Apr 2, 2023
@DougGregor DougGregor deleted the macro-lookup-in-types branch April 2, 2023 14:24
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