Skip to content

Add parser and semantic analysis support for when blocks (#504)#504

Open
daniellerozenblit wants to merge 4 commits intofacebook:devfrom
daniellerozenblit:export-D96342217
Open

Add parser and semantic analysis support for when blocks (#504)#504
daniellerozenblit wants to merge 4 commits intofacebook:devfrom
daniellerozenblit:export-D96342217

Conversation

@daniellerozenblit
Copy link
Contributor

@daniellerozenblit daniellerozenblit commented Mar 12, 2026

Summary:

Stack

The goal of this stack is to add support for conditional when blocks to sddl.

Diff

This diff adds parsing and semantic analysis support for when blocks in sddl..

Changes

  • ASTWhen node: New AST node type representing a conditional when block. Contains a condition expression and a body of statements.

  • WhenRule grammar: New grammar rule that parses when <expr> { <statements> } syntax.

  • SemanticAnalyzer: Added analyze(ASTWhen) to validate the condition is numeric and recursively analyze the body statements.

Differential Revision: D96342217

Summary:
Pull Request resolved: facebook#486

# Stack
The goal of this stack is to add support for Parameterized Records to sddl2.

# Diff
This diff adds parsing and semantic analysis support for parameterized records in SDDL2. Parameterized records allow record types to accept parameters that can be used within field definitions, enabling more flexible type definitions.

## Key Changes
- **ASTCall node:** New AST node type representing a parameterized record instantiation (e.g., `Entry(N)`). Contains a target (the record type) and arguments.

- **CallRule grammar:** New grammar rule that parses parenthesized argument lists after identifiers as function calls, enabling syntax like `Foo(3, 5)`.

- **SemanticAnalyzer updates:**
  - Extended `analyze(ASTRecord)` to validate record parameters are variable names and introduce them as NUMERIC types within the record scope.
  - Added `analyze(ASTCall)` to validate the target resolves to a record type, argument count matches parameter count, and all arguments are numeric.
  - Updated `analyzeMember()` to add record params to scope when accessing fields.

- **Optimizer passes:** Extended ConstFoldPass and DeadVarPass to handle the new ASTCall node type.

- **CodeGenerator:** Added stub for CALL handling (implementation in next diff).

Differential Revision: D95827616
Summary:
Pull Request resolved: facebook#487

# Stack
The goal of this stack is to add support for Parameterized Records to sddl2.

# Diff
This diff adds code generation support for parameterized records in SDDL2, allowing records to accept parameters that can be used in field definitions.

## Key Changes
- **bindParams():** New helper function that binds record parameters to registers before generating record body code. Parameters are temporarily assigned to registers so field expressions can reference them.

- **generateType() for CALL:** Added handling for ConvertedNodeType::CALL which resolves the target record type, binds parameters, generates the record body, then restores registers.

- **generateMember():** Extended to handle parameterized records by detecting CALL nodes and binding parameters before walking through record fields.

- **generateAssign():** Modified to detect parameterized records (records with non-empty params) and store them as type aliases without generating code, deferring code generation until instantiation.

- **generateAssume():** Extended to support CALL nodes alongside records for assume operations.

Differential Revision: D95827634
Summary:
## Stack
The goal of this stack is to add support for conditional `when` blocks to sddl.

## Diff
Refactor `ConstFoldPass` and `DeadVarPass` optimizer implementations to improve code organization, reduce duplication, and establish consistent naming conventions.

This is a pure refactor with no behavioral changes—prepares the optimizer infrastructure for upcoming `when` block support.

Differential Revision: D96342197
@meta-cla meta-cla bot added the cla signed label Mar 12, 2026
@meta-codesync
Copy link

meta-codesync bot commented Mar 12, 2026

@daniellerozenblit has exported this pull request. If you are a Meta employee, you can view the originating Diff in D96342217.

daniellerozenblit added a commit to daniellerozenblit/openzl-1 that referenced this pull request Mar 12, 2026
Summary:

## Stack
The goal of this stack is to add support for conditional `when` blocks to sddl.

## Diff
This diff adds parsing and semantic analysis support for `when` blocks in sddl..

### Changes

- **ASTWhen node:** New AST node type representing a conditional `when` block. Contains a condition expression and a body of statements.

- **WhenRule grammar:** New grammar rule that parses `when <expr> { <statements> }` syntax.

- **SemanticAnalyzer:** Added `analyze(ASTWhen)` to validate the condition is numeric and recursively analyze the body statements.

Differential Revision: D96342217
daniellerozenblit added a commit to daniellerozenblit/openzl-1 that referenced this pull request Mar 12, 2026
Summary:

## Stack
The goal of this stack is to add support for conditional `when` blocks to sddl.

## Diff
This diff adds parsing and semantic analysis support for `when` blocks in sddl..

### Changes

- **ASTWhen node:** New AST node type representing a conditional `when` block. Contains a condition expression and a body of statements.

- **WhenRule grammar:** New grammar rule that parses `when <expr> { <statements> }` syntax.

- **SemanticAnalyzer:** Added `analyze(ASTWhen)` to validate the condition is numeric and recursively analyze the body statements.

Differential Revision: D96342217
Summary:
Pull Request resolved: facebook#504

## Stack
The goal of this stack is to add support for conditional `when` blocks to sddl.

## Diff
This diff adds parsing and semantic analysis support for `when` blocks in sddl..

### Changes

- **ASTWhen node:** New AST node type representing a conditional `when` block. Contains a condition expression and a body of statements.

- **WhenRule grammar:** New grammar rule that parses `when <expr> { <statements> }` syntax.

- **SemanticAnalyzer:** Added `analyze(ASTWhen)` to validate the condition is numeric and recursively analyze the body statements.

Differential Revision: D96342217
@meta-codesync meta-codesync bot changed the title Add parser and semantic analysis support for when blocks Add parser and semantic analysis support for when blocks (#504) Mar 12, 2026
daniellerozenblit added a commit to daniellerozenblit/openzl-1 that referenced this pull request Mar 12, 2026
Summary:

## Stack
The goal of this stack is to add support for conditional `when` blocks to sddl.

## Diff
This diff adds parsing and semantic analysis support for `when` blocks in sddl..

### Changes

- **ASTWhen node:** New AST node type representing a conditional `when` block. Contains a condition expression and a body of statements.

- **WhenRule grammar:** New grammar rule that parses `when <expr> { <statements> }` syntax.

- **SemanticAnalyzer:** Added `analyze(ASTWhen)` to validate the condition is numeric and recursively analyze the body statements.

Differential Revision: D96342217
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant