Skip to content

Conversation

@omsherikar
Copy link
Contributor

Pull Request description

This PR adds support for declaring variables with struct types by introducing StructType, a type reference that resolves to previously defined structs. This enables Phase 2 of struct support, allowing struct variables to be declared and allocated on the stack with zero-initialization.

Changes:

  • Added StructType class in system.py that inherits from astx.DataType
  • Updated visit(VariableDeclaration) to detect and handle StructType instances
  • Struct variables are allocated using ir_builder.alloca() and zero-initialized
  • Added error handling for undefined struct references and unsupported value initialization
  • Added comprehensive test coverage (3 test cases)

Note: This PR depends on Phase 1 (StructDefStmt implementation) being merged first. The struct tests will fail until visit(astx.StructDefStmt) is available in the codebase.

How to test these changes

Run the struct type tests

pytest tests/test_struct_type.py -v

Run all tests (struct tests will fail if Phase 1 not merged)

pytest tests/ -v
**Example usage:**on
from irx.system import StructType
import astx

Define a struct

struct_def = astx.StructDefStmt(
name="Point",
attributes=[
astx.VariableDeclaration("x", astx.Int32()),
astx.VariableDeclaration("y", astx.Int32()),
],
)

Declare a struct variable

struct_var = astx.VariableDeclaration(
name="p",
type_=StructType(struct_name="Point"),
)## Pull Request checklists

This PR is a:

  • bug-fix
  • new feature
  • maintenance

About this PR:

  • it includes tests.
  • the tests are executed on CI.
  • the tests generate log file(s) (path).
  • pre-commit hooks were executed locally.
  • this PR requires a project documentation update.

Author's checklist:

  • I have reviewed the changes and it contains no misspelling.
  • The code is well commented, especially in the parts that contain more complexity.
  • New and old tests passed locally (struct tests require Phase 1 to be merged).

Additional information

Implementation details:

  • Struct variables are pointer-based and allocated on the stack
  • Zero-initialization is performed for all struct fields
  • Value initialization is not yet supported (raises clear error message)
  • Struct definitions must exist before variable declaration (compile-time check)

Dependencies:

  • Requires Phase 1 (StructDefStmt LLVM IR codegen) to be merged first
  • Uses self.struct_types dictionary populated by visit(astx.StructDefStmt)

Future work:

  • Struct value semantics (copying, passing by value)
  • Struct field access and assignment
  • Struct literals and field-by-field initialization

Copilot AI review requested due to automatic review settings January 9, 2026 14:26
@github-actions
Copy link

github-actions bot commented Jan 9, 2026

OSL ChatGPT Reviewer

NOTE: This is generated by an AI program, so some comments may not make sense.

src/irx/builders/llvmliteir.py

ChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

src/irx/system.py

ChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

tests/test_struct_type.py

ChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

@omsherikar omsherikar force-pushed the feat/struct-type-reference branch from a864bf6 to 7b55be5 Compare January 9, 2026 14:28
@github-actions
Copy link

github-actions bot commented Jan 9, 2026

OSL ChatGPT Reviewer

NOTE: This is generated by an AI program, so some comments may not make sense.

src/irx/builders/llvmliteir.py

ChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

src/irx/system.py

ChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

tests/test_struct_type.py

ChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

@omsherikar omsherikar force-pushed the feat/struct-type-reference branch from 7b55be5 to 12daeb6 Compare January 9, 2026 14:31
@github-actions
Copy link

github-actions bot commented Jan 9, 2026

OSL ChatGPT Reviewer

NOTE: This is generated by an AI program, so some comments may not make sense.

src/irx/builders/llvmliteir.py

ChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

src/irx/system.py

ChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

tests/test_struct_type.py

ChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for declaring variables with struct types, implementing Phase 2 of struct support. It introduces a new StructType class for type references and extends the LLVM IR visitor to handle struct variable declarations with stack allocation and zero-initialization.

  • Introduces StructType class as a type reference mechanism for previously defined structs
  • Extends visit(VariableDeclaration) to detect and handle struct types with allocation and zero-initialization
  • Adds comprehensive test coverage for struct variables, undefined struct errors, and unsupported value initialization

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/irx/system.py Adds StructType class for referencing previously defined structs
src/irx/builders/llvmliteir.py Extends visitor to handle struct variable declarations with stack allocation and zero-initialization; adds struct_types dictionary tracking
tests/test_struct_type.py Adds three test cases covering basic struct variable declaration, undefined struct error handling, and value initialization error handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Add StructType to reference defined structs in variable
declarations. Variables are allocated on stack and zero-initialized.
@omsherikar omsherikar force-pushed the feat/struct-type-reference branch from 12daeb6 to f9b4c9a Compare January 9, 2026 14:33
@github-actions
Copy link

github-actions bot commented Jan 9, 2026

OSL ChatGPT Reviewer

NOTE: This is generated by an AI program, so some comments may not make sense.

src/irx/builders/llvmliteir.py

ChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

src/irx/system.py

ChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

tests/test_struct_type.py

ChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

@yuvimittal
Copy link
Member

@omsherikar , the CI/CC seems to fail , please look into it

@omsherikar
Copy link
Contributor Author

@omsherikar , the CI/CC seems to fail , please look into it

@yuvimittal CI is failing because the tests create StructDefStmt nodes to define structs, but the visitor method for StructDefStmt is missing, which is in pr #150

@yuvimittal
Copy link
Member

@omsherikar , the CI/CC seems to fail , please look into it

@yuvimittal CI is failing because the tests create StructDefStmt nodes to define structs, but the visitor method for StructDefStmt is missing, which is in pr #150

Then please add these changes to PR #150 and push them there. Let’s keep this as a single PR rather than creating multiple ones.

@yuvimittal
Copy link
Member

@omsherikar , i am converting this to draft so we know alright!?

@yuvimittal yuvimittal marked this pull request as draft January 22, 2026 15:15
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