Skip to content

Prevent variable reassignment#485

Closed
daniellerozenblit wants to merge 7 commits into
facebook:devfrom
daniellerozenblit:export-D95802815
Closed

Prevent variable reassignment#485
daniellerozenblit wants to merge 7 commits into
facebook:devfrom
daniellerozenblit:export-D95802815

Conversation

@daniellerozenblit
Copy link
Copy Markdown
Contributor

Summary: This diff expands the SDDL semantic analyzer to prevent variable reassignment. This makes implementation of codegen much simpler in a lot of cases.

Differential Revision: D95802815

Summary:

This diff splits `CompilerTest.cpp` into separate test files per compiler stage. This makes it easier to test the functionality of each component in isolation; e.g making sure the parser produces the expected AST before optimizations.

Differential Revision: D95084293
Summary:

# Stack
The goal of this stack is to add support for variable assignments and assume operations to SDDL2.

# Diff
This diff implements variable assignment and reference support in the code generator. This enables SDDL2 programs to use global variables for parameterizing field sizes and reusing type definitions.

- Implemented `Op::ASSIGN` codegen: evaluates the RHS expression, allocates a VM register via `getOrAssignRegister()`, and emits `var.store`.
- Implemented `ASTVar` reference codegen: looks up the variable's register and emits `var.load`.  If this is the last reference to a particular variable, returns the register to the free pool.
- Added a register allocator (`var_registry_`, `free_registers_`, `next_register_`) that reuses freed registers and enforces the `SDDL2_VAR_REGISTER_COUNT` (256) limit at compile time.

Differential Revision: D94947414
Summary:

# Stack
The goal of this stack is to add support for variable assignments and assume operations to SDDL2.

# Diff
This diff adds a `MEMBER` op to the SDDL grammar, which can be used to access fields of consumed recrds. This operator (`.`) was already supported in the syntax.

Differential Revision: D95396139
Summary:

# Stack
The goal of this stack is to add support for variable assignments and assume operations to SDDL2.

# Diff
This diff handles the `MEMBER` op in the dead var optimizer.

Differential Revision: D95396507
Summary:

# Stack
The goal of this stack is to add support for variable assignments and assume operations to SDDL2.

# Diff
The diff updates the semantic analyzer to support the `MEMBER` operation. This mainly validates that operands are semantically correct (e.g., LHS is a consumed record, RHS is a field).

Differential Revision: D95430690
Summary:

# Stack
The goal of this stack is to add support for variable assignments and assume operations to SDDL2.

# Diff
This diff extracts register allocation logic from `CodeGenerator` into a dedicated `RegisterAllocator` utility class. This improves code organization.

Differential Revision: D95582393
Summary: This diff expands the SDDL semantic analyzer to prevent variable reassignment. This makes implementation of codegen much simpler in a lot of cases.

Differential Revision: D95802815
@meta-cla meta-cla Bot added the cla signed label Mar 9, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Mar 9, 2026

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

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

This diff expands the SDDL semantic analyzer to prevent variable reassignment. This makes implementation of codegen much simpler in a lot of cases.

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

This diff expands the SDDL semantic analyzer to prevent variable reassignment. This makes implementation of codegen much simpler in a lot of cases.

Differential Revision: D95802815
@meta-codesync meta-codesync Bot closed this in 014701c Mar 12, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Mar 12, 2026

This pull request has been merged in 014701c.

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.

2 participants