-
Notifications
You must be signed in to change notification settings - Fork 10.5k
NFC: [CodeCompletion] Use enums in bit fields as-is #40163
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
@swift-ci Please smoke test |
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.
Wow, I can’t believe that we didn’t do this before. LGTM, I think it might be worth also static_assert
ing that the values actually fit inside the specified number of bits.
CodeCompletionOperatorKind KnownOperatorKind : 6; | ||
SemanticContextKind SemanticContext : 3; | ||
unsigned char Flair : 8; | ||
NotRecommendedReason NotRecommended : 4; |
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 we have static_assert
s that e.g. NotRecommendedReason
doesn’t contain more then 2^4 elements?
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.
No. Good idea. I added a commit.
@swift-ci Please smoke test |
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.
Much nicer! Note that the build is failing on:
SwiftEditor.cpp(611,1): error: static_assert failed due to requirement 'sizeof((anonymous namespace)::SwiftSemanticToken) == 8' "Too big"
static_assert(sizeof(SwiftSemanticToken) == 8, "Too big");
SemanticContextKind SemanticContext : 3; | ||
unsigned char Flair : 8; | ||
NotRecommendedReason NotRecommended : 4; | ||
bool IsSystem : 1; |
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.
Not really related to this PR but in libSyntax’s RawSyntax
, I saw measurable performance improvements when not compressing bitfields into the minimum number of bits but having them byte-aligned. I think this was because the CPU doesn’t need to do bitshifts/masks to retrieve the value.
The bits inside RawSyntax
were probably accessed a lot more frequently than these, but it might be worth investigating if byte-aligning these might also be beneficial performance-wise, even though it increases the memory footprint.
We don't need to convert them from/to integer
e1f2d7a
to
bc57eaf
Compare
@swift-ci Please smoke test |
bc57eaf
to
4c39c90
Compare
@swift-ci Please smoke test |
MSVC doens't pack diffrent underlying int types into a bitfield. e.g. struct S { int a: 1; char b: 1; int c: 1; }; These fields are considered three sparate bitfields.
4c39c90
to
f17671c
Compare
@swift-ci Please smoke test |
@swift-ci Please smoke test Windows |
@swift-ci Please smoke test Windows |
@swift-ci Please smoke test |
I got this to pass by changing - #if !SWIFT_COMPILER_IS_MSVC
+ #if !defined(_MSC_VER) AFAICT |
Makes sense! Merged. |
We don't need to convert them from/to integer