Skip to content

Commit 3f26698

Browse files
Copilotdadhi
andauthored
fix: use (long)nodeType cast directly in PackData, add 7-bit range assert
Agent-Logs-Url: https://github.com/dadhi/FastExpressionCompiler/sessions/65d4ff94-c1db-4fb1-8ea7-2f71df94d205 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
1 parent 6cdd023 commit 3f26698

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/FastExpressionCompiler/FlatExpression.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,22 @@ public ref ExpressionNode NodeAt(Idx idx)
160160
}
161161

162162
// Packs NodeType + ChildIdx + ChildCount + ExtraIdx + ExtraCount into the 64-bit _data word.
163+
// ExpressionType max value is 83 (IsFalse), well within the 7-bit (0–127) field.
163164
[MethodImpl(MethodImplOptions.AggressiveInlining)]
164165
private static long PackData(
165166
ExpressionType nodeType,
166167
short childIdx = 0,
167168
short childCount = 0,
168169
short extraIdx = 0,
169-
byte extraCount = 0) =>
170-
((long)(int)nodeType << 57) | // 7 bits at [63:57]
171-
((long)(ushort)childIdx << 41) | // 16 bits at [56:41]
172-
((long)(ushort)childCount << 25) | // 16 bits at [40:25]
173-
((long)(ushort)extraIdx << 9) | // 16 bits at [24:9]
174-
((long)extraCount << 1); // 8 bits at [8:1]
170+
byte extraCount = 0)
171+
{
172+
Debug.Assert((int)nodeType >= 0 && (int)nodeType <= 127, "ExpressionType must fit in 7 bits");
173+
return ((long)nodeType << 57) | // 7 bits at [63:57] — ExpressionType max 83, fits in 7 bits
174+
((long)(ushort)childIdx << 41) | // 16 bits at [56:41]
175+
((long)(ushort)childCount << 25) | // 16 bits at [40:25]
176+
((long)(ushort)extraIdx << 9) | // 16 bits at [24:9]
177+
((long)extraCount << 1); // 8 bits at [8:1]
178+
}
175179

176180
[MethodImpl(MethodImplOptions.AggressiveInlining)]
177181
private Idx AddNode(

0 commit comments

Comments
 (0)