-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Semantics attribute definition file #28037
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
Conversation
cc @gottesmm |
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 think this is a reasonable refactor, but someone more familiar with @_semantics
should take a look as well. In the meantime I just have a few small comments.
include/swift/Basic/Semantics.h
Outdated
#include "llvm/ADT/StringRef.h" | ||
|
||
namespace swift { | ||
#define SEMA_ATTR(NAME, C_STR) constexpr static const StringLiteral NAME = #C_STR; |
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 should probably go in their own namespace so they don't clutter the top level swift namespace, similar to how diagnostic definitions are in swift::diag::
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'm not opposed to this but let's see what others think.
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 am also tending to think we should put this into a namespace like semantics or perhaps strings? Not sure. @atrick @jrose-apple any ideas?
I added a |
* add namespace * fix block comment style * SEMA_ATTR -> SEMANTICS_ATTR * error when SEMANTICS_ATTR isn't defined
@swift-ci Please test |
This looks good to me. Since nobody else has commented on this in 2 weeks, I think we can merge it if the tests pass. |
If you want, you can remove the semantics not used by the stdlib in a subsequent PR. |
Build failed |
Build failed |
Looks like a few test failures snuck in since this was last tested:
Hopefully it's a simple typo somewhere. |
Ha! I'm surprised those are the only ones that failed. I accidentally initialized all the semantics as |
@swift-ci Please test |
1 similar comment
@swift-ci Please test |
@slavapestov looks like the bots maybe didn't get triggered? |
Thank you @slavapestov! |
This patch creates a definition file for all non-specialized semantics attributes. Its the first in what will probably be three patches. The goal is to enforce that all semantics attributes are constant string literals that are defined in one place which will reduce the possibility for error and create a centralized place for all semantics attributes to live.
The next patch will add a category so that we can replace code such as the following:
with something like
Last, it might be nice to have some way to enforce that
hasSemanticsAttr
is passed a defined attribute.Additionally, here are some semantics that I found references to in the compiler but could not find references to in the standard library: