Skip to content

Replace LightExpression TryEmit parent flags plumbing with compiler-context emit stack#524

Closed
Copilot wants to merge 3 commits intomasterfrom
copilot/replace-parentflags-with-stack-expressions
Closed

Replace LightExpression TryEmit parent flags plumbing with compiler-context emit stack#524
Copilot wants to merge 3 commits intomasterfrom
copilot/replace-parentflags-with-stack-expressions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

TryEmit only received a reduced ParentFlags view plus the immediate expression, which made custom emitters context-poor and forced parent-state plumbing through many call sites. This change centralizes emit context in CompilerContext by tracking the active expression stack so emitters can inspect the full parent chain directly.

  • Compiler emit context

    • Added an emit-time stack to CompilerContext for:
      • active expressions
      • corresponding parent flags
    • Exposed lightweight accessors for the current node and ancestor lookup:
      • CurrentEmitExpression
      • CurrentParentFlags
      • EmitExpressionCount
      • GetEmitExpression(int indexFromCurrent)
  • Emitter flow

    • Updated EmittingVisitor.TryEmit(...) to push/pop emit context around each expression emission.
    • This makes full parent context available at every emit level without threading extra state through custom emitters.
  • LightExpression intrinsic API

    • Removed the ParentFlags parent parameter from LightExpression intrinsic Expression.TryEmit(...).
    • Updated intrinsic implementations to read parent context from CompilerContext instead of relying on a caller-supplied flag snapshot.
    • This reduces TryEmit parameter surface and aligns intrinsic emitters with centralized context access.
  • Regression coverage

    • Added a focused LightExpression issue test using a custom intrinsic node to verify that emit-time context exposes:
      • the current expression
      • its immediate parent
      • higher-level ancestors in order
public override bool TryEmit(ref ExpressionCompiler.CompilerContext context, ILGenerator il, int byRefIndex = -1)
{
    Asserts.AreSame(this, context.CurrentEmitExpression);
    Asserts.AreEqual(ExpressionType.Convert, context.GetEmitExpression(1).NodeType);
    Asserts.AreEqual(ExpressionType.Add, context.GetEmitExpression(2).NodeType);

    il.Emit(OpCodes.Ldc_I4, 41);
    return true;
}

Copilot AI changed the title [WIP] Replace ParentFlags with stack of Expressions in TryEmit methods Replace LightExpression TryEmit parent flags plumbing with compiler-context emit stack Apr 20, 2026
Copilot AI requested a review from dadhi April 20, 2026 20:05
@dadhi
Copy link
Copy Markdown
Owner

dadhi commented Apr 21, 2026

Bads

@dadhi dadhi closed this Apr 21, 2026
@dadhi dadhi deleted the copilot/replace-parentflags-with-stack-expressions branch April 21, 2026 06:30
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.

2 participants