remove assert builtin

This commit is contained in:
David Gonzalez Martin 2024-02-20 20:12:20 -06:00
parent 91038a2c65
commit ff21b7d698
8 changed files with 25 additions and 41 deletions

View File

@ -1520,35 +1520,6 @@ pub const Builder = struct {
_ = expected_type; // autofix
unreachable;
},
.assert => {
assert(argument_node_list.len == 1);
const boolean = try builder.resolveRuntimeValue(unit, context, Type.Expect{ .type = .bool }, argument_node_list[0], .right);
switch (boolean.value) {
.@"comptime" => |ct| switch (ct) {
.bool => |value| switch (value) {
true => {},
false => {
@panic("Assert failed at comptime");
},
},
else => |t| @panic(@tagName(t)),
},
.runtime => |instruction_index| {
const true_block = try builder.newBasicBlock(unit, context);
const false_block = try builder.newBasicBlock(unit, context);
try builder.branch(unit, context, instruction_index, true_block, false_block);
builder.current_basic_block = false_block;
try builder.buildTrap(unit, context);
builder.current_basic_block = true_block;
},
else => |t| @panic(@tagName(t)),
}
return undefined;
},
.@"error" => {
assert(argument_node_list.len == 1);
// TODO: type

View File

@ -1180,7 +1180,7 @@ pub const LLVM = struct {
for (sema_function_prototype.argument_types) |argument_type_index| {
switch (unit.types.get(argument_type_index).*) {
// TODO: ABI
.integer, .pointer, .@"enum", .@"struct", .slice => try parameter_types.append(context.allocator, try llvm.getType(unit, context, argument_type_index)),
.integer, .pointer, .@"enum", .@"struct", .slice, .bool, => try parameter_types.append(context.allocator, try llvm.getType(unit, context, argument_type_index)),
else => |t| @panic(@tagName(t)),
}
// arg_types.appendAssumeCapacity(llvm_argument_type);
@ -2878,7 +2878,8 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo
switch (unit.types.get(argument_type_index).*) {
.void, .noreturn, .type => unreachable,
.comptime_int => unreachable,
.bool => unreachable,
.bool => {},
// .bool => unreachable,
.@"struct" => {},
.@"enum" => {},
.function => unreachable,

View File

@ -1,5 +1,6 @@
const std = #import("std");
const Allocator = std.Allocator;
const assert = std.assert;
const current = #import("builtin").os;
const system = switch (current) {
.linux => linux,
@ -192,7 +193,7 @@ const current_executable_path = fn(buffer: [:0]u8) ?[]u8 {
}
i += 1;
}
#assert(i < buffer.len);
assert(i < buffer.len);
return result[0..i];
} else {

View File

@ -30,7 +30,7 @@ const format_usize = fn(n: usize, buffer: &[65]u8) []u8 {
index -= 1;
const ch = '0' + digit;
buffer[index] = ch;
#assert(buffer[index] == ch);
assert(buffer[index] == ch);
absolute /= 10;
if (absolute == 0) {
@ -44,7 +44,7 @@ const format_usize = fn(n: usize, buffer: &[65]u8) []u8 {
const print_usize = fn(n: usize) void {
var buffer: [65]u8 = undefined;
const bytes = format_usize(n, buffer = buffer.&);
#assert(bytes.len < buffer.len);
assert(bytes.len < buffer.len);
const file_descriptor = os.StdFileDescriptor.get(descriptor = .stdout);
const file_writer = FileWriter{
.descriptor = file_descriptor,

View File

@ -1,7 +1,10 @@
const std = #import("std");
const assert = std.assert;
const main = fn() s32 {
#assert(true);
assert(true);
var a: s32 = 1;
const is_not_one = a != 1;
#assert(!is_not_one);
assert(!is_not_one);
return 0;
}

View File

@ -1,3 +1,6 @@
const std = #import("std");
const assert = std.assert;
const BitStruct = struct(u8) {
a: bool,
b: bool,
@ -13,7 +16,7 @@ const main = fn () s32 {
.d = 0,
};
const bitcast_bs: u8 = #cast(bs);
#assert(bitcast_bs == 6);
assert(bitcast_bs == 6);
const const_bs = BitStruct{
.a = true,
@ -22,6 +25,6 @@ const main = fn () s32 {
.d = 0,
};
const bitcast_const_bs: u8 = #cast(const_bs);
#assert(bitcast_const_bs == 5);
assert(bitcast_const_bs == 5);
return 0;
}

View File

@ -1,3 +1,6 @@
const std = #import("std");
const assert = std.assert;
const A = struct(u8) {
a: u4,
b: u4,
@ -21,8 +24,8 @@ const main = fn () s32 {
};
const b = transform(a);
#assert(a.a == b.a);
#assert(a.b == b.b);
assert(a.a == b.a);
assert(a.b == b.b);
return 0;
}

View File

@ -1,8 +1,10 @@
const std = #import("std");
const assert = std.assert;
const main = fn() s32 {
var buffer: [65]u8 = undefined;
const slice = foo(5, buffer.&);
#assert(slice.len + 5 == buffer.len);
assert(slice.len + 5 == buffer.len);
const result: u32 = #cast(slice.len + 5 - buffer.len);
return #cast(result);
}