Skip to content

Commit 79801da

Browse files
authored
bitnot op refactoring (#143)
1 parent f4bdce0 commit 79801da

File tree

5 files changed

+3
-17
lines changed

5 files changed

+3
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
178178

179179
### Compiler
180180

181+
- ast: Remove dead `OperatorKind::BitNot` variant — `~x` is always parsed as `UnaryOperatorKind::BitNot` in a `PrefixUnaryExpression`; the binary enum variant was never produced by the AST builder ([#142])
181182
- ast: Introduce `SimpleTypeKind` enum for primitive types, replacing string-based type matching ([#50])
182183
- ast: Simplify Builder API to return `Arena` directly instead of using state machine pattern ([#50])
183184
- ast: Add error collection in Builder with `collect_errors()` for better parse error reporting ([#50])
@@ -329,3 +330,4 @@ Initial tagged release.
329330
[#136]: https://github.com/Inferara/inference/pull/136
330331
[#138]: https://github.com/Inferara/inference/pull/138
331332
[#140]: https://github.com/Inferara/inference/pull/140
333+
[#142]: https://github.com/Inferara/inference/pull/142

core/ast/docs/nodes.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,6 @@ pub enum OperatorKind {
602602
BitAnd, // &
603603
BitOr, // |
604604
BitXor, // ^
605-
BitNot, // design inconsistency — never produced for BinaryExpression;
606-
// the ~ token is always a PrefixUnaryExpression (UnaryOperatorKind::BitNot)
607605
Shl, // <<
608606
Shr, // >>
609607
}
@@ -613,10 +611,6 @@ pub enum OperatorKind {
613611

614612
- `Pow` (`**`) is not yet implemented in the WASM backend. Attempting to lower a
615613
binary expression with this operator will panic with a `todo!()`.
616-
- `BitNot` should not appear in any `BinaryExpression` node. The `~` token is
617-
always parsed as a prefix unary expression and stored as
618-
`UnaryOperatorKind::BitNot`. The `OperatorKind::BitNot` variant is a design
619-
inconsistency that will be removed in a future cleanup.
620614
- `And` and `Or` lower to WebAssembly `i32.and`/`i32.or` bitwise instructions.
621615
Both operands are always evaluated — there is no short-circuit evaluation.
622616

@@ -649,7 +643,7 @@ pub enum UnaryOperatorKind {
649643
```
650644

651645
Note: `~` always produces a `PrefixUnaryExpression` with `UnaryOperatorKind::BitNot`.
652-
It is never stored as `OperatorKind::BitNot` in a `BinaryExpression`.
646+
It is never stored as a `BinaryExpression`.
653647

654648
**Example source:**
655649
```inference

core/ast/src/nodes.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,6 @@ pub enum OperatorKind {
405405
BitOr,
406406
/// Bitwise XOR: `a ^ b`
407407
BitXor,
408-
/// Bitwise NOT: `~a` (Note: This is actually a unary operator in most contexts)
409-
BitNot,
410408
/// Bitwise left shift: `a << b`
411409
Shl,
412410
/// Bitwise right shift: `a >> b`

core/type-checker/src/type_checker.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,6 @@ impl TypeChecker {
14361436
| OperatorKind::BitAnd
14371437
| OperatorKind::BitOr
14381438
| OperatorKind::BitXor
1439-
| OperatorKind::BitNot
14401439
| OperatorKind::Shl
14411440
| OperatorKind::Shr => {
14421441
if !left_type.is_number() || !right_type.is_number() {

core/wasm-codegen/src/compiler.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -889,13 +889,6 @@ impl Compiler {
889889
see .claude/plans/codegen/new-pow-operator/master_plan.md"
890890
)
891891
}
892-
OperatorKind::BitNot => {
893-
todo!(
894-
"OperatorKind::BitNot in binary context — the AST builder never produces \
895-
this; OperatorKind::BitNot is a design inconsistency and should be removed \
896-
from OperatorKind and the type-checker binary arm cleaned up in a separate issue"
897-
)
898-
}
899892
};
900893

901894
func.instruction(&instruction);

0 commit comments

Comments
 (0)