-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] Support additional args in @dynamicMemberLookup subscripts #81148
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
base: main
Are you sure you want to change the base?
[Sema] Support additional args in @dynamicMemberLookup subscripts #81148
Conversation
/// a default value | ||
/// | ||
/// Subscripts which don't meet these requirements strictly are not eligible. | ||
enum class DynamicMemberLookupSubscriptEligibility : uint8_t { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DynamicMemberLookupSubscriptEligibility
is... a mouthful — but it's the least-inaccurate name I could come up with. Happy to improve this with suggestions!
DynamicMemberLookupSubscriptEligibility | ||
getDynamicMemberLookupSubscriptEligibility(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of exposing this enum, I suppose it is also possible to restore isValidDynamicMemberLookupSubscript()
et. al., but I do think it's nicer to have a type-safe interface that's harder to typo.
@swift-ci please smoke test |
`SubscriptDecl`s may get checked multiple times for eligibility in fulfilling `@dynamicMemberLookup` requirements; since the checks are non-trivial and the result doesn't change, this eligibility can be cached in the decl's `Bits`.
`SubscriptDecl` exposes eligibility for `@dynamicMemberLookup` requirements directly, so the `TypeChecker` interface for these members can be replaced.
Adds support for `SubscriptDecl`s to fulfill `@dynamicMemberLookup` requirements if they have additional arguments after `dynamicMember:` so long as those arguments have default values, or are variadic. This allows exposing values like `#function`, `#fileID`, `#line`, etc. to dynamic member lookup.
Subscripts with `isolated` arguments currently do not pass a compiler assertion about the consistency of the function type w.r.t. isolation. This is because the `ExtInfo` for `SubscriptDecl`s doesn't currently have isolation information applied (though this works in practice); annotating the `ExtInfo` with isolation allows this assertion to pass.
725aeab
to
5e77bd2
Compare
Adds support for satisfying
@dynamicMemberLookup
requirements using subscripts which have arguments followingdynamicMember:
so long as they are either variadic or have default arguments. This allows transforming member references intox[dynamicMember:...]
calls which can pass in arguments such as#function
,#fileID
,#line
, etc.@dynamicMemberLookup
Subscripts swift-evolution#2814Main changes:
SubscriptDecl
s to satisfy@dynamicMemberLookup
requirements as long asdynamicMember:
remains the first explicitly-labeled argument, and all following arguments are eitherisDefaultArgument()
orisVariadic()
SubscriptDecl.Bits
; this was being checked multiple times per decl and it seems prudent to just store the info since we have the bitsExprRewriter
to produceArgumentList
s for these subscripts by filling inDefaultArgumentExpr
s as neededThe PR has been split into individual commits for (ideally) ease of review.