-
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:
|
|
|
||
| let (unexpectedBeforeIntroducer, introducer) = self.expect(kind.spec) | ||
|
|
||
| // Map `yielding borrow` => `read`, etc. |
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.
This breaks round-tripping, so I can't do this mapping here.
|
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.
| var look = self.lookahead() | ||
| let _ = look.consumeAttributeList() | ||
| let hasModifier = look.consume(ifAnyIn: AccessorModifier.self) != nil | ||
| let hasYielding = look.consume(if: TokenSpec(.yielding)) != nil |
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.
These changes to Declarations.swift seem to make sense to me. This should verify the basic syntax.
| struct AccessorIntroducer { | ||
| var attributes: RawAttributeListSyntax | ||
| var modifier: RawDeclModifierSyntax? | ||
| var yielding: RawAccessorYieldingModifierSyntax? |
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.
I need to either add a new field here or change modifier to an array. No idea which is more appropriate.
|
What does this mean? |
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.