feat: extend LiteralDict lowering with runtime support (constant-path tests)#213
feat: extend LiteralDict lowering with runtime support (constant-path tests)#213m-akhil-reddy wants to merge 12 commits intoarxlang:mainfrom
Conversation
|
Hi @yuvimittal , can you review the PR and suggest any changes if needed . This PR extends the existing Approach The implementation first checks whether all keys and values lower to LLVM If all elements are constants, the dictionary is lowered using the existing constant fast-path to a constant LLVM array If non-constant values appear, the visitor switches to runtime lowering:
Safety Handling
Tests
|
Renamed test from 'test_literal_dict_runtime_lowering_fallback' to 'test_literal_dict_const_lowering'.
tests/test_literal_dict.py
Outdated
|
|
||
|
|
||
| @pytest.mark.parametrize("builder_class", [LLVMLiteIR]) | ||
| def test_literal_dict_const_lowering( |
There was a problem hiding this comment.
i have changed the test name as test never enters runtime lowering.Because
LiteralInt32 -> ir.Constant so this condition is always true: `all_constants = True
meaning all tests actually executes constant fast path , not run time lowering
There was a problem hiding this comment.
You're right that this path always hits the constant fast-path since LiteralInt32 lowers to ir.Constant. I updated the test name to test_literal_dict_const_lowering.
thanks.
| result = visitor.result_stack.pop() | ||
|
|
||
| # When no function context exists, runtime lowering falls back to constant | ||
| assert isinstance(result, ir.Constant) |
There was a problem hiding this comment.
better test assert result.type.count == 1
this verifies dictionary layout
There was a problem hiding this comment.
I added assert result.type.count == 1 so the test also verifies the dictionary layout.
thank.
tests/test_literal_dict.py
Outdated
|
|
||
|
|
||
| @pytest.mark.parametrize("builder_class", [LLVMLiteIR]) | ||
| def test_literal_dict_const_lowering( |
There was a problem hiding this comment.
You should ideally test a non-constant key/value. uh for example
x = 1 { x: 2 }
like the code functionality
There was a problem hiding this comment.
Thanks for the suggestions, @yuvimittal
Currently the tests run outside a function context, so runtime lowering cannot safely emit IR (no builder block). Because of that, the implementation falls back to constant lowering in tests.
I agree that ideally we should test a true non-constant case (e.g., using a variable like {x: 2} inside a function). I can add a function-based test for that in a follow-up PR's.
There was a problem hiding this comment.
@m-akhil-reddy , but the PR title and description doesnt align with existing tests
There was a problem hiding this comment.
@yuvimittal ,
thanks for pointing that out.
I'll update the PR title/description to clarify that the implementation includes the runtime lowering path, while the current tests cover the constant fast-path due to running outside a function context.
There was a problem hiding this comment.
I have updated the PR title and description to clarify that the implementation includes the runtime lowering path while the current tests cover the constant fast-path due to running outside a function context.
src/irx/builders/llvmliteir.py
Outdated
| builder.position_at_end(current_bb) | ||
|
|
||
| # i32 type used for GEP indexing | ||
| i32 = ir.IntType(32) |
There was a problem hiding this comment.
LLVM actually expects target pointer-sized integers for GEP indices on some targets. so the safer approach would be i32 = self._llvm.INT32_TYPE
There was a problem hiding this comment.
I replaced ir.IntType(32) with self._llvm.INT32_TYPE to follow the project's LLVM type definitions.
thanks.
|
@yuvimittal , i have made the changes according to your suggestion. |
|
This PR extends LiteralDict lowering with runtime construction support when keys/values are non-constant. |
uh i am not sure, how do we verify the current implenmentation |
|
Thanks for the feedback. I updated the tests to better reflect the current implementation. Since The test now verifies the fallback behavior when no function context exists (i.e., Please let me know if you would prefer a different testing approach. |
Notes
you work. When you’re ready for a review, change the status to Ready for
review to trigger a new review round. If you make additional changes and
don’t want to trigger the bot, switch the PR back to Draft.
share your feedback; it helps us improve the tool.
as possible to increase the chances of a timely review. Large PRs may not be
reviewed and may be closed.
self-documenting
(guidance).
our Discord to discuss ideas, blockers, or issues
(https://discord.gg/Nu4MdGj9jB).
sensitive data/PII in code, configs, logs, screenshots, or commit history. If
something leaks, rotate the credentials immediately, invalidate the old key,
and note it in the PR so maintainers can assist.
needed for tests, prefer small fixtures or programmatic downloads declared in
makim.yaml (e.g., a task that fetches data at test time). If a large binary is
unavoidable, discuss first and consider Git LFS.
Pull Request description
#30 #211
How to test these changes
...Pull Request checklists
This PR is a:
About this PR:
Author's checklist:
complexity.
Additional information
Reviewer's checklist
Copy and paste this template for your review's note: