Skip to content

Tighten FlatExpression naming and 16-bit index storage#548

Merged
dadhi merged 3 commits intomasterfrom
copilot/fix-flatexpression-anti-slop
May 5, 2026
Merged

Tighten FlatExpression naming and 16-bit index storage#548
dadhi merged 3 commits intomasterfrom
copilot/fix-flatexpression-anti-slop

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

FlatExpression had drifted in two places: comments were noisy/inconsistent, and index naming/storage conventions were not enforced uniformly. This change trims the file back to a single Idx vocabulary and makes the 16-bit storage contract explicit in code.

  • Comment cleanup

    • Rewrote FlatExpression.cs comments to plain technical prose.
    • Removed non-ASCII symbols and overly verbose/LLM-like phrasing.
    • Kept comments focused on layout, invariants, and identity semantics.
  • Naming normalization

    • Renamed the root field from RootIndex to RootIdx.
    • Normalized local/parameter naming across the file to Idx/Idxs where the file already used that convention.
    • Updated affected tests and property-test helpers to match the new API.
  • 16-bit index enforcement

    • Replaced implicit truncation with checked((ushort)...) when writing child/next metadata into packed node fields.
    • Preserves the existing compact layout while failing fast if a stored index exceeds the intended 16-bit range.
  • Focused regression coverage

    • Added a test that locks in the compact metadata sizes:
      • ExprNode remains 24 bytes
      • LambdaClosureParameterUsage remains 6 bytes
    • Added an overflow boundary check to verify that exceeding the 16-bit node-index range throws instead of silently wrapping.
var fe = default(ExprTree);
for (var i = 0; i < ushort.MaxValue; ++i)
    fe.Default(typeof(int));

Asserts.AreEqual(ushort.MaxValue, fe.Nodes.Count);
Asserts.Throws<OverflowException>(() => fe.ParameterOf<int>("overflow"));

Copilot AI linked an issue May 5, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix FlatExpression: anti-slop issues Tighten FlatExpression naming and 16-bit index storage May 5, 2026
Copilot finished work on behalf of dadhi May 5, 2026 12:05
Copilot AI requested a review from dadhi May 5, 2026 12:05
Copy link
Copy Markdown
Owner

@dadhi dadhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ci build is failing:
Error: /home/runner/work/FastExpressionCompiler/FastExpressionCompiler/test/FastExpressionCompiler.LightExpression.UnitTests/LightExpressionTests.cs(781,34): error CS0103: The name 'Unsafe' does not exist in the current context [/home/runner/work/FastExpressionCompiler/FastExpressionCompiler/test/FastExpressionCompiler.LightExpression.UnitTests/FastExpressionCompiler.LightExpression.UnitTests.csproj::TargetFramework=net472]
Error: /home/runner/work/FastExpressionCompiler/FastExpressionCompiler/test/FastExpressionCompiler.LightExpression.UnitTests/LightExpressionTests.cs(782,33): error CS0103: The name 'Unsafe' does not exist in the current context [/home/runner/work/FastExpressionCompiler/FastExpressionCompiler/test/FastExpressionCompiler.LightExpression.UnitTests/FastExpressionCompiler.LightExpression.UnitTests.csproj::TargetFramework=net472]

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

ci build is failing:
Error: /home/runner/work/FastExpressionCompiler/FastExpressionCompiler/test/FastExpressionCompiler.LightExpression.UnitTests/LightExpressionTests.cs(781,34): error CS0103: The nam...

Fixed in 15012aa. I replaced the Unsafe.SizeOf calls with a net472-compatible layout size check, then verified the affected project builds with dotnet build test/FastExpressionCompiler.LightExpression.UnitTests/FastExpressionCompiler.LightExpression.UnitTests.csproj -f net472 and the main net9.0 test runner still passes.

Copilot finished work on behalf of dadhi May 5, 2026 14:09
Copilot AI requested a review from dadhi May 5, 2026 14:09
@dadhi dadhi marked this pull request as ready for review May 5, 2026 15:19
@dadhi dadhi merged commit 949a859 into master May 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FlatExpression: anti-slop

2 participants