You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This project encountered a compiler bug in Zig 0.14.x related to HashMap initialization with native `u256` types as keys. The error manifests as:
540
-
```
541
-
error: access of union field 'pointer' while field 'int' is active
542
-
at std/mem/Allocator.zig:425:45
543
-
```
544
-
545
-
**Root Cause**: The bug is in HashMap's `AutoContext` type introspection code when handling large integer types (`u256`). This is a compiler bug, not an issue with our code.
546
-
547
-
**Solution**: We implemented a custom `U256` struct using two `u128` fields with explicit `hash()` and `eql()` methods, along with custom HashMap contexts (`HashContext`, `AddressContext`). This bypasses the problematic `AutoContext` code path entirely.
548
-
549
-
**Implementation Details**:
550
-
- Custom `U256` struct in `src/core/types.zig` with two `u128` fields (`low`, `high`)
551
-
- Custom hash function combining both halves via XOR
552
-
- Custom equality comparison
553
-
- Custom HashMap contexts for `Hash` and `Address` types
554
-
- Full compatibility with 32-byte hashes and 20-byte addresses
555
-
556
-
**Performance**: No performance penalty - the struct is stack-allocated and operations are efficient.
557
-
558
-
See `src/core/types.zig` for detailed comments explaining the implementation.
559
-
560
-
### Zig 0.14.x Allocator Bug (Historical)
561
-
562
-
This project previously encountered allocator bugs in Zig 0.14.0 and 0.14.1 related to allocating arrays of structs containing slices. **Verified through testing**: The bug exists in both versions (at different line numbers: 400 vs 412). The issue was resolved by using a custom `U256` implementation instead of native `u256` types.
0 commit comments