diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-15 18:37:09 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-15 18:37:09 -0700 |
| commit | 682cdeceaa7f55a14ad88ce01030888a9c18960e (patch) | |
| tree | 1cc955c9090e9084509831491c70b3bcbdef02b3 /src/type.zig | |
| parent | 186126c2a4032424e1b1cdb8ac379fb2beab7429 (diff) | |
| download | zig-682cdeceaa7f55a14ad88ce01030888a9c18960e.tar.gz zig-682cdeceaa7f55a14ad88ce01030888a9c18960e.zip | |
stage2: optional comparison and 0-bit payloads
* Sema: implement peer type resolution for optionals and null.
* Rename `Module.optionalType` to `Type.optional`.
* LLVM backend: re-use anonymous values. This is especially useful when
isByRef()=true because it means re-using the same generated LLVM globals.
* LLVM backend: rework the implementation of is_null and is_non_null
AIR instructions. Generate slightly better LLVM code, and also fix
the behavior for optionals whose payload type is 0-bit.
* LLVM backend: improve `cmp` AIR instruction lowering to support
pointer-like optionals.
* `Value`: implement support for equality-checking optionals.
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig index a37a3bfc03..278b8af18d 100644 --- a/src/type.zig +++ b/src/type.zig @@ -4031,6 +4031,20 @@ pub const Type = extern union { }); } + pub fn optional(arena: *Allocator, child_type: Type) Allocator.Error!Type { + switch (child_type.tag()) { + .single_const_pointer => return Type.Tag.optional_single_const_pointer.create( + arena, + child_type.elemType(), + ), + .single_mut_pointer => return Type.Tag.optional_single_mut_pointer.create( + arena, + child_type.elemType(), + ), + else => return Type.Tag.optional.create(arena, child_type), + } + } + pub fn smallestUnsignedBits(max: u64) u16 { if (max == 0) return 0; const base = std.math.log2(max); |
