-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Grab 4 more bits for use as node flags. Use additional bit to store if nodes contain attributes within them. #72070
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
Changes from 3 commits
6b6d090
b2e4644
a7b0f5c
5c031d0
b90d0fb
1b452b3
ebd279d
9e91de5
f8c0aba
8e54ffb
f6087f9
2e10fc8
37ffbe8
4fd426b
7658b22
71d1c60
7fb9f8e
ccd891a
bef9b62
7890a62
47e93e3
5f23cb5
8f2bc75
afe9ad1
4ca709a
9ef94fc
fa6c04d
abe46cb
e597ad1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,9 +15,68 @@ | |
|
|
||
| namespace Microsoft.CodeAnalysis | ||
| { | ||
|
|
||
| [DebuggerDisplay("{GetDebuggerDisplay(), nq}")] | ||
| internal abstract partial class GreenNode | ||
| { | ||
| /// <summary> | ||
| /// Combination of <see cref="NodeFlags"/> and <see cref="SlotCount"/> stored in a single 16bit value. | ||
| /// </summary> | ||
| internal struct NodeFlagsAndSlotCount | ||
| { | ||
| /// <summary> | ||
| /// 4 bits for the SlotCount. This allows slot counts of 0-14 to be stored as a direct byte. All 1s | ||
| /// indicates that the slot count must be computed. | ||
| /// </summary> | ||
| private const byte SlotCountMask = 0b1111; | ||
| private const int SlotCountShift = 12; | ||
|
|
||
| /// <summary> | ||
| /// 12 bits for the NodeFlags. This allows for up to 12 distinct bits to be stored to designate interesting | ||
| /// aspects of a node. | ||
| /// </summary> | ||
| private const ushort NodeFlagsMask = 0b0000111111111111; | ||
|
|
||
| /// <summary> | ||
| /// CCCCFFFFFFFFFFFF for Count bits then Flag bits. | ||
| /// </summary> | ||
| private ushort _data; | ||
|
|
||
| public byte SlotCount | ||
| { | ||
| readonly get | ||
| { | ||
| var shifted = _data >> SlotCountShift; | ||
| Debug.Assert(shifted <= SlotCountMask); | ||
| var result = (byte)shifted; | ||
| return result == SlotCountMask ? byte.MaxValue : result; | ||
| } | ||
|
|
||
| set | ||
| { | ||
| if (value == byte.MaxValue) | ||
| value = SlotCountMask; | ||
| Debug.Assert(value <= SlotCountMask); | ||
|
|
||
| _data = (ushort)(_data | (value << SlotCountShift)); | ||
| } | ||
| } | ||
|
|
||
| public NodeFlags NodeFlags | ||
| { | ||
| readonly get | ||
| { | ||
| return (NodeFlags)(_data & NodeFlagsMask); | ||
| } | ||
|
|
||
| set | ||
| { | ||
| Debug.Assert((ushort)value <= NodeFlagsMask); | ||
| _data = (ushort)(_data | (ushort)value); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private string GetDebuggerDisplay() | ||
| { | ||
| return this.GetType().Name + " " + this.KindText + " " + this.ToString(); | ||
|
|
@@ -26,10 +85,21 @@ private string GetDebuggerDisplay() | |
| internal const int ListKind = 1; | ||
|
|
||
| private readonly ushort _kind; | ||
| protected NodeFlags flags; | ||
| private byte _slotCount; | ||
| private NodeFlagsAndSlotCount _nodeFlagsAndSlotCount; | ||
| private int _fullWidth; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we wanted, we could likely grab more bits off of this as well. For example, we could say the max file size was 256MB, giving us 4 more bits here to store data. |
||
|
|
||
| protected NodeFlags flags | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to keep the impact of this pr low, i kept the names of the fields and hid them behind properties. If we do want to change these names we can. Note that |
||
| { | ||
| get => _nodeFlagsAndSlotCount.NodeFlags; | ||
| set => _nodeFlagsAndSlotCount.NodeFlags |= value; | ||
CyrusNajmabadi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private byte _slotCount | ||
| { | ||
| get => _nodeFlagsAndSlotCount.SlotCount; | ||
| set => _nodeFlagsAndSlotCount.SlotCount = value; | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bridge members to ensure nothing else needs to be updated. It would be good to rename these in the future to actually be properties. |
||
|
|
||
| private static readonly ConditionalWeakTable<GreenNode, DiagnosticInfo[]> s_diagnosticsTable = | ||
| new ConditionalWeakTable<GreenNode, DiagnosticInfo[]>(); | ||
|
|
||
|
|
@@ -234,8 +304,13 @@ public virtual int FindSlotIndexContainingOffset(int offset) | |
| #endregion | ||
|
|
||
| #region Flags | ||
|
|
||
| /// <summary> | ||
| /// Special flags a node can have. Note: while this is typed as being `ushort`, we can only practically use 12 | ||
| /// of those 16 bits as we use the remaining 4 bits to store the slot count of a node. | ||
| /// </summary> | ||
| [Flags] | ||
| internal enum NodeFlags : byte | ||
| internal enum NodeFlags : ushort | ||
| { | ||
| None = 0, | ||
| ContainsDiagnostics = 1 << 0, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.