Skip to content

[docs] Add documentation for underscored attributes. #37854

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

Conversation

varungandhi-apple
Copy link
Contributor

I figured I should at least start a PR instead of being lazy.

Fixes rdar://65258964.

@varungandhi-apple varungandhi-apple force-pushed the vg-underscored-attributes branch from ee0d46f to e9849be Compare June 9, 2021 22:25
@varungandhi-apple varungandhi-apple force-pushed the vg-underscored-attributes branch 2 times, most recently from 40b35c0 to b9ff577 Compare June 12, 2021 07:27
@varungandhi-apple
Copy link
Contributor Author

cc @benrimmington in case you have any suggestions.

Copy link
Contributor

@benrimmington benrimmington left a comment

Choose a reason for hiding this comment

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

Are there any underscored Objective-C attributes used by the Clang importer?

@varungandhi-apple varungandhi-apple force-pushed the vg-underscored-attributes branch from b9ff577 to b14f411 Compare June 12, 2021 16:16
@davidungar
Copy link
Contributor

Great idea to document these! Are there pointers to the document in the code where it implements these?

@varungandhi-apple
Copy link
Contributor Author

varungandhi-apple commented Jun 12, 2021

No, there are no such links as it's likely they would break when code gets moved around. Searching by the attribute strings and related types that come up seems to give good enough results, I think. For certain attributes, they are not implemented in a single place, they affects lots of things, so pointing to 1-2 places could potentially be misleading.

Are there specific attributes that you think would benefit from this treatment?

@varungandhi-apple
Copy link
Contributor Author

varungandhi-apple commented Jun 12, 2021

Are there any underscored Objective-C attributes used by the Clang importer?

Do you mean things like __attribute__((__swift_attr__("@MainActor")))? That does have an alternate spelling __attribute__((swift_attr("@MainActor"))) which I think should be accepted...

@davidungar
Copy link
Contributor

No, there are no such links as it's likely they would break when things get moved around. Searching by the attribute strings and related types that come up seems to give good enough results, I think. For certain attributes, they are not implemented in a single place, they affects lots of things, so pointing to 1-2 places could potentially be misleading.

Are there specific attributes that you think would benefit from this treatment?

Sorry--I wrote "link" but all I meant was a comment, say where these are parsed that would refer the reader to the document.

Good question about attributes. The one I hit was _spi, which you may already have documented.

Again, I'm really glad you are taking this on. It would have helped me to have this documentation.

@varungandhi-apple
Copy link
Contributor Author

Well, you said pointers -- which I mis-interpreted as links. With comments, I'm not sure of what the value-add is over searching... Consider the example of _spi. In Attr.def, it's named SPIAccessControl, searching for that gives a bunch of hits, including one in ParseDecl.cpp showing where it is parsed. In Module.cpp, there are a bunch of hits showing where it is used for filtering out declarations. And so on.

That said, I'm not super tied to not having links/comments. I'll try to gather feedback from other people to see what they think about the additional value of having comments about implementation.

I've added some notes for @_spi, but happy to add more details if you think something is unclear or could do with more explanation.

@benrimmington
Copy link
Contributor

Are there any underscored Objective-C attributes used by the Clang importer?

Do you mean things like __attribute__((__swift_attr__("@MainActor")))? That does have an alternate spelling __attribute__((swift_attr("@MainActor"))) which I think should be accepted...

I should have written undocumented Clang attributes, but I don't know if any exist, or if this is the right place to put them.

(swift_attr is documented at https://clang.llvm.org/docs/AttributeReference.html).

@davidungar
Copy link
Contributor

Well, you said pointers -- which I mis-interpreted as links. With comments, I'm not sure of what the value-add is over searching... Consider the example of _spi. In Attr.def, it's named SPIAccessControl, searching for that gives a bunch of hits, including one in ParseDecl.cpp showing where it is parsed. In Module.cpp, there are a bunch of hits showing where it is used for filtering out declarations. And so on.

That said, I'm not super tied to not having links/comments. I'll try to gather feedback from other people to see what they think about the additional value of having comments about implementation.

I've added some notes for @_spi, but happy to add more details if you think something is unclear or could do with more explanation.

Sounds good. In my case, I don't always think of searching the docs folder when I am reading the code. And then, there are a lot of docs in there. But if a search in Xcode for "_spi" finds your document, then a comment adds less.

@varungandhi-apple
Copy link
Contributor Author

I should have written undocumented Clang attributes, but I don't know if any exist, or if this is the right place to put them.

If there are undocumented Clang attributes (I don't recall any but in case you come up with something), IMO that should be a bug-fix in Clang's documentation, not adding those here (because it's less likely someone will search here).

Copy link
Contributor

@CodaFi CodaFi left a comment

Choose a reason for hiding this comment

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

Some additional entries.

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

Looks good so far. I added comments wherever I felt qualified to do so.

Copy link
Collaborator

@xwu xwu left a comment

Choose a reason for hiding this comment

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

Really excited about this. Learned a few things reading it! I'm made a few grammar/style-related suggestions, but there are also some substantive additions and suggestions thrown in.

@_implements(Q, foo())
func foo_q() {}
}
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

It was really cool to see a description of why @_disfavoredOverload was designed. Similarly here, reference could be made to its (earliest?) use in implementing synthesized conformances to Equatable and Hashable.

Copy link
Contributor

@beccadax beccadax Jul 27, 2021

Choose a reason for hiding this comment

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

It may not have come across, but I gave background on @_disfavoredOverload to try to illustrate when it should be used (i.e. to work around a known defect in overload resolution that can't be immediately fixed without breaking source, and particularly to work around that specific bug with literals). If that seemed like cool background info rather than a usage guideline, maybe it should be rephrased.


## `@_nonoverride`

Warns when a protocol restates a requirement from another protocol that
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about, "Marks a declaration that is not an override of another, required when compiling with the -warn-implicit-overrides flag, which warns when a protocol restates a requirement from another protocol that it refines without annotating the declaration with either override or @_nonoverride."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated wording.

@varungandhi-apple varungandhi-apple force-pushed the vg-underscored-attributes branch 2 times, most recently from 2ab51cd to e79f67b Compare July 23, 2021 19:48
@varungandhi-apple varungandhi-apple marked this pull request as ready for review July 29, 2021 01:08
@varungandhi-apple varungandhi-apple force-pushed the vg-underscored-attributes branch from 384d20c to cd13dad Compare July 29, 2021 01:12
@varungandhi-apple
Copy link
Contributor Author

Fixed merge conflict; this is ready for ~final review, in case anyone has other comments. Barring that, I will land this PR on Monday next week.

@varungandhi-apple
Copy link
Contributor Author

@swift-ci smoke test

@varungandhi-apple
Copy link
Contributor Author

@swift-ci smoke test Linux

@varungandhi-apple varungandhi-apple merged commit f42bde3 into swiftlang:main Aug 3, 2021
@varungandhi-apple varungandhi-apple deleted the vg-underscored-attributes branch August 3, 2021 01:20
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.

10 participants