-
Notifications
You must be signed in to change notification settings - Fork 465
[SE-0474] Support yielding borrow and yielding mutate accessors
#3189
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?
Conversation
`yielding borrow` and `yielding mutate` are the final approved names for the accessors previously known as `read` and `modify` (which are themselves improvements over the earlier non-standard `_read` and `_modify` accessors). Since some people are already using these under the `read` and `modify` names, we want to support the old and new names as synonyms for a transition period until everyone has had a chance to migrate.
|
This isn't working out so well. There seem to be two basic problems:
|
|
It's not clear from SE-0474 whether If the former is accepted, then it might make sense to model |
|
Can anyone suggest how this should work? @bnbarham @rintaro @hamishknight ?? I'm completely stumped. What I have here seems entirely wrong, but I have no idea what approach should be used here. In particular:
|
|
Maybe I could expand and then I'd have to reverse-engineer the code generator to construct |
|
It would be so helpful if the generated code included comments indicating where the data came from for each particular generated type and/or file. |
I haven't been following the proposal closely, but from a quick read, it has eg.
Confusing set of terms IMO (nonmutating mutate?), but
Given the proposal mentions the possibility of a non-yielding borrow/mutate, seems that
The next question is whether there should be an order to these, ie. is |
to track the presence/absence of the `yielding` token.
|
What does this mean? |
|
@swift-ci Please test |
|
I ended up just making |
|
In the RFC discussion, @allevato suggested:
@hamishknight What's the right way to implement this? I suppose I could put back the |
|
We have a compatibility layer in |
|
Though even if we don't add a compatibility layer for |
|
Unless it's technically infeasible (e.g., in cases where the entire structure of a node must change), I don't think we should omit compatibility shims in general. Even if swift-syntax doesn't strictly offer source compatibility, it's still often the right thing to do when it's possible, because macro authors get the opportunity to migrate on their terms, and you don't have to pair this change with parallel changes to other swiftlang/swift-* projects that might to be updated, like swift-format and possibly sourcekit-lsp. In this case, I don't think there are any technical challenges here. The singular property can be marked deprecated but return either the first modifier or it could look through the list for |
Well that's the thing, I think we definitely want to make sure we update any uses in swiftlang projects since otherwise there's a good chance we're not handling this new language feature correctly. I think the same logic also extends to macros when they choose to adopt a new version of the language, as long as this isn't prevalent enough for that to be a burden. I'll let @bnbarham decide though. |
|
@allevato I implemented backwards-compatibility shims. Let me know if this looks right to you. |
The main issue I see is with the setter + initializer, since a macro that's intending to copy a whole node could now remove a modifier. Maybe best to discuss in the RFC thread? |
ahoppen
left a comment
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.
One minor suggestion, otherwise LGTM.
| attributes: RawAttributeListSyntax(elements: [], arena: arena), | ||
| modifier: nil, | ||
| modifiers: RawDeclModifierListSyntax(elements: [], arena: arena), |
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.
We can save a few bytes in the syntax tree by using a shared empty collection. Also for RawAttributeListSyntax now that I look at it.
| attributes: RawAttributeListSyntax(elements: [], arena: arena), | |
| modifier: nil, | |
| modifiers: RawDeclModifierListSyntax(elements: [], arena: arena), | |
| attributes: self.emptyCollection(RawAttributeListSyntax.self), | |
| modifiers: self.emptyCollection(RawDeclModifierListSyntax.sel), |
yielding borrowandyielding mutateare the final approved names for the accessors previously known asreadandmodify(which are themselves improvements over the earlier non-standard_readand_modifyaccessors).Since some people are already using these under the
readandmodifynames, we want to support the old and new names as synonyms for a transition period until everyone has had a chance to migrate.RFC discussion: https://forums.swift.org/t/rfc-multiple-modifiers-in-accessordeclsyntax-for-se-0474/83316