feat(#247): implement set operations (union, intersection, difference, symmetric difference)#254
Merged
xmnlab merged 3 commits intoarxlang:mainfrom Apr 1, 2026
Merged
Conversation
Contributor
Author
|
@yuvimittal ,i also wrote a standalone demo script that exercises all 4 set operations through the LLVMLiteIRVisitor
the implementation does compile-time set algebra via _try_set_binary_op where both operands are constant integer arrays, so the result is computed during IR generation with zero runtime overhead.
|
…nsion Add compile-time set operations (union |, intersection &, difference -, symmetric difference ^) for LiteralSet operands. LiteralSet already lowers to a sorted constant integer array. When the BinaryOp visitor detects both operands are constant int arrays and the op_code is one of |, &, -, ^, it delegates to _try_set_binary_op which: - extracts Python set[int] values from each constant array - applies the Python set operation - emits the result as a new sorted constant ir.ArrayType No runtime IR is needed since both operands are always constant at IR-generation time. Promotes element type to widest width when operands have mixed integer widths. Add 5 tests to tests/test_set.py: - test_set_union - test_set_intersection - test_set_difference - test_set_symmetric_difference - test_set_disjoint_intersection_is_empty
f63f03c to
d39fcab
Compare
Contributor
|
thanks @Jaskirat-s7 |
|
🎉 This PR is included in version 1.9.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Closes #247
LiteralSetlowers to a sorted constant integer array but had no visitorfor any set operation — making sets write-only constructs. This PR adds
compile-time support for all four core set operations via the existing
BinaryOpnode.What changed
src/irx/builders/llvmliteir.py
_try_set_binary_op(lhs, rhs, op_code) → bool — new helper method:
Falseimmediately if op_code isn't|,&,-,^Falseif either operand isn't a constant integer arrayset[int]values from both operandsir.ArrayTypeontoresult_stackvisit(BinaryOp) — one-line hook added before the existing falsy guard: