-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[doc] Add an embryonic section on stdlib coding style #25810
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bf57cdc
[doc] Add an embryonic section on stdlib coding style
lorentey 01f3d29
Typo fix
lorentey 9eb943b
Update StandardLibraryProgrammersManual.md
lorentey 649b2db
Start merging information from AccessControlInStdlib.rst
lorentey ef93be2
Update StandardLibraryProgrammersManual.md
lorentey aadd5ef
Merge branch 'master' into stdlib-guide-update
lorentey 2c61f00
[doc] Update based on feedback; add short section on availabilty
lorentey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why? In general, or only if it's part of the ABI?
Uh oh!
There was an error while loading. Please reload this page.
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.
When the underscoring rule was introduced, everything in the stdlib was effectively inlinable.
This is no longer the case, but I see no reason to cease applying the rule. I find the underscores are a useful signal when I read the code.
On a practical level, it would be all too easy to accidentally slap on
@usableFromInlne
on an non-underscored internal method without renaming it.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.
Do members of internal types also need an underscore?
One the one hand, an internal type
_Foo
may become public at one point, but we want its ABI imprint to remain. We'd change_Foo
to public and saypublic typealias Foo = _Foo
. At that point, it has many violations of the underscore rule. On the other hand, I don't think this is the sort of scenario to design an entire convention around.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.
Internal types need to have an underscore in the type name. The members need not have an underscore themselves (and often cannot, because of protocol conformances).
The proper way to make a previously
@usableFromInline internal struct _Foo
public would be to keep the existing type and to wrap it in a new public struct. (Unless the internal API happens to be accepted verbatim as public. But that is exceedingly unlikely.)To make a previously internal/private (non-usableFromInline) type public, we remove the old type and replace it wholesale with the new public API, adjusting use-sites as necessary.