Skip to content
Merged
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6b6d090
in progres
CyrusNajmabadi Feb 12, 2024
b2e4644
Flip
CyrusNajmabadi Feb 12, 2024
a7b0f5c
Drop in replacement
CyrusNajmabadi Feb 12, 2024
5c031d0
Merge branch 'main' into flags
CyrusNajmabadi Feb 12, 2024
b90d0fb
Update src/Compilers/Core/Portable/Syntax/GreenNode.cs
CyrusNajmabadi Feb 12, 2024
1b452b3
Merge remote-tracking branch 'upstream/main' into flags
CyrusNajmabadi Feb 13, 2024
ebd279d
fix
CyrusNajmabadi Feb 13, 2024
9e91de5
Add specific list test
CyrusNajmabadi Feb 13, 2024
f8c0aba
Add attribute flag
CyrusNajmabadi Feb 13, 2024
8e54ffb
generators
CyrusNajmabadi Feb 13, 2024
f6087f9
Better
CyrusNajmabadi Feb 13, 2024
2e10fc8
Better
CyrusNajmabadi Feb 13, 2024
37ffbe8
Better
CyrusNajmabadi Feb 13, 2024
4fd426b
fix
CyrusNajmabadi Feb 13, 2024
7658b22
Update vb
CyrusNajmabadi Feb 13, 2024
71d1c60
fix
CyrusNajmabadi Feb 13, 2024
7fb9f8e
extract type
CyrusNajmabadi Feb 13, 2024
ccd891a
Update src/Compilers/Core/Portable/Syntax/GreenNode.cs
CyrusNajmabadi Feb 13, 2024
bef9b62
Move into loop
CyrusNajmabadi Feb 13, 2024
7890a62
Keep both checks
CyrusNajmabadi Feb 13, 2024
47e93e3
Merge branch 'flags' of https://github.com/CyrusNajmabadi/roslyn into…
CyrusNajmabadi Feb 13, 2024
5f23cb5
Simplify
CyrusNajmabadi Feb 13, 2024
8f2bc75
Simplify
CyrusNajmabadi Feb 13, 2024
afe9ad1
docs
CyrusNajmabadi Feb 13, 2024
4ca709a
Setflags
CyrusNajmabadi Feb 13, 2024
9ef94fc
update code
CyrusNajmabadi Feb 13, 2024
fa6c04d
Add special constant
CyrusNajmabadi Feb 15, 2024
abe46cb
Docs
CyrusNajmabadi Feb 15, 2024
e597ad1
Pull out constant
CyrusNajmabadi Feb 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 78 additions & 3 deletions src/Compilers/Core/Portable/Syntax/GreenNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Copy link
Member Author

Choose a reason for hiding this comment

The 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
Copy link
Member Author

Choose a reason for hiding this comment

The 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 _slotCount is a challenge as we have both _slotCount and SlotCount already. I don't mind keeping these named as fields, as they are effectively still fields, jsut more efficiently stored.

{
get => _nodeFlagsAndSlotCount.NodeFlags;
set => _nodeFlagsAndSlotCount.NodeFlags |= value;
}

private byte _slotCount
{
get => _nodeFlagsAndSlotCount.SlotCount;
set => _nodeFlagsAndSlotCount.SlotCount = value;
}
Copy link
Member Author

Choose a reason for hiding this comment

The 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[]>();

Expand Down Expand Up @@ -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,
Expand Down