aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-02-21 16:27:44 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-02-21 16:27:44 -0800
commit931670b7cb0e0c85504c171732b98bc0ad568d46 (patch)
tree17e0d6358f9c6f6d9a94becb12c56805ad29b2c3
parent427de617028872a7055b41c61776ef5c965d567a (diff)
downloadbun-931670b7cb0e0c85504c171732b98bc0ad568d46.tar.gz
bun-931670b7cb0e0c85504c171732b98bc0ad568d46.tar.zst
bun-931670b7cb0e0c85504c171732b98bc0ad568d46.zip
Wrap some usages of `assert` in a conditional
See https://github.com/ziglang/zig/issues/10942
-rw-r--r--src/http/async_message.zig4
-rw-r--r--src/http/async_socket.zig4
-rw-r--r--src/install/npm.zig2
-rw-r--r--src/install/repository.zig3
-rw-r--r--src/javascript/jsc/node/node_fs.zig4
-rw-r--r--src/javascript/jsc/webcore/response.zig6
-rw-r--r--src/js_parser/js_parser.zig27
-rw-r--r--src/query_string_map.zig9
-rw-r--r--src/resolver/data_url.zig2
-rw-r--r--src/resolver/resolver.zig2
-rw-r--r--src/router.zig4
11 files changed, 36 insertions, 31 deletions
diff --git a/src/http/async_message.zig b/src/http/async_message.zig
index 3e204455f..45c581bbb 100644
--- a/src/http/async_message.zig
+++ b/src/http/async_message.zig
@@ -5,7 +5,7 @@ const AsyncIO = @import("io");
pub const buffer_pool_len = std.math.maxInt(u16);
pub const BufferPoolBytes = [buffer_pool_len]u8;
pub const BufferPool = ObjectPool(BufferPoolBytes, null, false, 4);
-
+const Environment = @import("../env.zig");
const AsyncMessage = @This();
used: u32 = 0,
@@ -49,7 +49,7 @@ var _first: ?*AsyncMessage = null;
pub fn get(allocator: std.mem.Allocator) *AsyncMessage {
if (_first) |first| {
var prev = first;
- std.debug.assert(prev.released);
+ if (Environment.allow_assert) std.debug.assert(prev.released);
prev.released = false;
if (first.next) |next| {
diff --git a/src/http/async_socket.zig b/src/http/async_socket.zig
index 080654e0a..d841d1b0c 100644
--- a/src/http/async_socket.zig
+++ b/src/http/async_socket.zig
@@ -405,7 +405,7 @@ pub const SSL = struct {
_ = boring.SSL_clear_mode(ssl, mode);
var alpns = &[_]u8{ 8, 'h', 't', 't', 'p', '/', '1', '.', '1' };
- std.debug.assert(boring.SSL_set_alpn_protos(this.ssl, alpns, alpns.len) == 0);
+ if (Environment.allow_assert) std.debug.assert(boring.SSL_set_alpn_protos(this.ssl, alpns, alpns.len) == 0);
boring.SSL_enable_signed_cert_timestamps(ssl);
boring.SSL_enable_ocsp_stapling(ssl);
@@ -744,7 +744,7 @@ pub const SSL = struct {
this.first_post_handshake_write = false;
if (boring.SSL_version(this.ssl) == boring.TLS1_3_VERSION) {
- std.debug.assert(boring.SSL_key_update(this.ssl, boring.SSL_KEY_UPDATE_REQUESTED) == 0);
+ if (Environment.allow_assert) std.debug.assert(boring.SSL_key_update(this.ssl, boring.SSL_KEY_UPDATE_REQUESTED) == 0);
continue;
}
}
diff --git a/src/install/npm.zig b/src/install/npm.zig
index 55ce92171..d5122c001 100644
--- a/src/install/npm.zig
+++ b/src/install/npm.zig
@@ -1010,7 +1010,7 @@ pub const PackageManifest = struct {
}
const parsed_version = Semver.Version.parse(sliced_string, allocator);
- std.debug.assert(parsed_version.valid);
+ if (Environment.allow_assert) std.debug.assert(parsed_version.valid);
if (!parsed_version.valid) {
log.addErrorFmt(&source, prop.value.?.loc, allocator, "Failed to parse dependency {s}", .{version_name}) catch unreachable;
diff --git a/src/install/repository.zig b/src/install/repository.zig
index 7ea9ce470..109e24ce9 100644
--- a/src/install/repository.zig
+++ b/src/install/repository.zig
@@ -5,6 +5,7 @@ const String = Semver.String;
const std = @import("std");
const GitSHA = String;
const string = @import("../string_types.zig").string;
+const Environment = @import("../env.zig");
pub const Repository = extern struct {
owner: String = String{},
@@ -50,7 +51,7 @@ pub const Repository = extern struct {
buf: []const u8,
repository: Repository,
pub fn format(formatter: Formatter, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
- std.debug.assert(formatter.label.len > 0);
+ if (Environment.allow_assert) std.debug.assert(formatter.label.len > 0);
try writer.writeAll(formatter.label);
try writer.writeAll(":");
diff --git a/src/javascript/jsc/node/node_fs.zig b/src/javascript/jsc/node/node_fs.zig
index 42058f1d3..a53c7d172 100644
--- a/src/javascript/jsc/node/node_fs.zig
+++ b/src/javascript/jsc/node/node_fs.zig
@@ -2918,7 +2918,7 @@ pub const NodeFS = struct {
working_mem[i] = std.fs.path.sep;
switch (err.getErrno()) {
.EXIST => {
- std.debug.assert(false);
+ if (Environment.allow_assert) std.debug.assert(false);
continue;
},
else => return .{ .err = err },
@@ -3024,7 +3024,7 @@ pub const NodeFS = struct {
_ = args;
_ = this;
_ = flavor;
- std.debug.assert(args.position == null);
+ if (Environment.allow_assert) std.debug.assert(args.position == null);
switch (comptime flavor) {
// The sync version does no allocation except when returning the path
diff --git a/src/javascript/jsc/webcore/response.zig b/src/javascript/jsc/webcore/response.zig
index 70b87b53a..e161a3119 100644
--- a/src/javascript/jsc/webcore/response.zig
+++ b/src/javascript/jsc/webcore/response.zig
@@ -27,7 +27,7 @@ const castObj = @import("../base.zig").castObj;
const getAllocator = @import("../base.zig").getAllocator;
const JSPrivateDataPtr = @import("../base.zig").JSPrivateDataPtr;
const GetJSPrivateData = @import("../base.zig").GetJSPrivateData;
-
+const Environment = @import("../../../env.zig");
const ZigString = JSC.ZigString;
const JSInternalPromise = JSC.JSInternalPromise;
const JSPromise = JSC.JSPromise;
@@ -1230,9 +1230,9 @@ pub const Headers = struct {
else => str.len,
},
);
- std.debug.assert(ptr.length > 0);
+ if (Environment.allow_assert) std.debug.assert(ptr.length > 0);
- std.debug.assert(this.buf.items.len >= ptr.offset + ptr.length);
+ if (Environment.allow_assert) std.debug.assert(this.buf.items.len >= ptr.offset + ptr.length);
var slice = this.buf.items[ptr.offset..][0..ptr.length];
switch (comptime StringType) {
js.JSStringRef => {
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig
index dbb92fc2e..ef114cd25 100644
--- a/src/js_parser/js_parser.zig
+++ b/src/js_parser/js_parser.zig
@@ -39,7 +39,11 @@ pub const ExprNodeList = js_ast.ExprNodeList;
pub const StmtNodeList = js_ast.StmtNodeList;
pub const BindingNodeList = js_ast.BindingNodeList;
-pub const assert = std.debug.assert;
+fn _disabledAssert(_: bool) void {
+ unreachable;
+}
+
+const assert = if (Environment.allow_assert) std.debug.assert else _disabledAssert;
pub const LocRef = js_ast.LocRef;
pub const S = js_ast.S;
@@ -2639,7 +2643,7 @@ pub const Parser = struct {
p.recordUsage(p.jsx_refresh_runtime.ref);
if (!p.options.jsx.use_embedded_refresh_runtime) {
- std.debug.assert(!p.options.enable_bundling);
+ if (Environment.allow_assert) assert(!p.options.enable_bundling);
var declared_symbols = try p.allocator.alloc(js_ast.DeclaredSymbol, 1);
const loc = logger.Loc.Empty;
const import_record_id = p.addImportRecord(.require, loc, p.options.jsx.refresh_runtime);
@@ -3826,7 +3830,7 @@ fn NewParser_(
// during minification. These counts shouldn't include references inside dead
// code regions since those will be culled.
if (!p.is_control_flow_dead) {
- std.debug.assert(p.symbols.items.len > ref.innerIndex());
+ if (Environment.allow_assert) assert(p.symbols.items.len > ref.innerIndex());
p.symbols.items[ref.innerIndex()].use_count_estimate += 1;
var result = p.symbol_uses.getOrPut(p.allocator, ref) catch unreachable;
if (!result.found_existing) {
@@ -4336,7 +4340,7 @@ fn NewParser_(
// errors if a statement in the function body tries to re-declare any of the
// arguments.
if (comptime kind == js_ast.Scope.Kind.function_body) {
- assert(parent.kind == js_ast.Scope.Kind.function_args);
+ if (Environment.allow_assert) assert(parent.kind == js_ast.Scope.Kind.function_args);
var iter = scope.parent.?.members.iterator();
while (iter.next()) |entry| {
@@ -7704,7 +7708,7 @@ fn NewParser_(
// If we end with a .t_close_paren, that's a bug. It means we aren't following the last parenthese
if (Environment.isDebug) {
- std.debug.assert(p.lexer.token != .t_close_paren);
+ if (Environment.allow_assert) assert(p.lexer.token != .t_close_paren);
}
}
@@ -8423,7 +8427,7 @@ fn NewParser_(
if (ref.isSourceContentsSlice()) {
return p.source.contents[ref.sourceIndex() .. ref.sourceIndex() + ref.innerIndex()];
} else if (ref.sourceIndex() == std.math.maxInt(Ref.Int)) {
- assert(ref.innerIndex() < p.allocated_names.items.len);
+ if (Environment.allow_assert) assert(ref.innerIndex() < p.allocated_names.items.len);
return p.allocated_names.items[ref.innerIndex()];
} else {
return p.symbols.items[ref.innerIndex()].original_name;
@@ -9289,7 +9293,7 @@ fn NewParser_(
try p.lexer.next();
break :parseTemplatePart;
}
- if (comptime Environment.allow_assert) std.debug.assert(p.lexer.token != .t_end_of_file);
+ if (comptime Environment.allow_assert) if (Environment.allow_assert) assert(p.lexer.token != .t_end_of_file);
}
p.allow_in = oldAllowIn;
@@ -10625,7 +10629,7 @@ fn NewParser_(
var propertyOpts = PropertyOpts{};
if (try p.parseProperty(.normal, &propertyOpts, &self_errors)) |prop| {
if (comptime Environment.allow_assert) {
- std.debug.assert(prop.key != null or prop.value != null);
+ if (Environment.allow_assert) assert(prop.key != null or prop.value != null);
}
properties.append(prop) catch unreachable;
}
@@ -13269,7 +13273,7 @@ fn NewParser_(
var scope = p.current_scope;
while (!scope.kindStopsHoisting()) {
- std.debug.assert(scope.parent != null);
+ if (Environment.allow_assert) assert(scope.parent != null);
scope = scope.parent.?;
}
@@ -13792,7 +13796,7 @@ fn NewParser_(
// we do not attempt to preserve all the semantics of with
data.value = p.visitExpr(data.value);
// This stmt should be a block
- if (comptime Environment.allow_assert) std.debug.assert(data.body.data == .s_block);
+ if (comptime Environment.allow_assert) if (Environment.allow_assert) assert(data.body.data == .s_block);
data.body = p.visitSingleStmt(data.body, StmtsKind.none);
},
.s_while => |data| {
@@ -15566,7 +15570,7 @@ fn NewParser_(
curr_stmts = curr_stmts[export_all_function_body_stmts.len..];
// This is the original part statements + 1
var part_stmts = curr_stmts;
- std.debug.assert(part_stmts.len == end_iife_stmts_count);
+ if (Environment.allow_assert) assert(part_stmts.len == end_iife_stmts_count);
var part_stmts_i: usize = 0;
var import_list_i: usize = 0;
@@ -15632,7 +15636,6 @@ fn NewParser_(
p.runtime_imports.__HMRModule.?;
const hmr_import_ref = hmr_import_module_.ref;
-
first_decl[0] = G.Decl{
.binding = p.b(B.Identifier{ .ref = p.hmr_module.ref }, logger.Loc.Empty),
.value = p.e(E.New{
diff --git a/src/query_string_map.zig b/src/query_string_map.zig
index 292e581b0..b9713214b 100644
--- a/src/query_string_map.zig
+++ b/src/query_string_map.zig
@@ -361,7 +361,7 @@ pub const URL = struct {
'@' => {
// we found a password, everything before this point in the slice is a password
url.password = str[0..i];
- std.debug.assert(str[i..].len < 2 or std.mem.readIntNative(u16, str[i..][0..2]) != std.mem.readIntNative(u16, "//"));
+ if (Environment.allow_assert) std.debug.assert(str[i..].len < 2 or std.mem.readIntNative(u16, str[i..][0..2]) != std.mem.readIntNative(u16, "//"));
return i + 1;
},
// if we reach a slash, there's no password
@@ -562,7 +562,8 @@ pub const QueryStringMap = struct {
count += 1;
}
- std.debug.assert(count > 0); // We should not call initWithScanner when there are no path params
+ if (Environment.allow_assert)
+ std.debug.assert(count > 0); // We should not call initWithScanner when there are no path params
while (scanner.query.next()) |result| {
if (result.name_needs_decoding or result.value_needs_decoding) {
@@ -677,8 +678,8 @@ pub const QueryStringMap = struct {
if (nothing_needs_decoding) {
scanner = Scanner.init(query_string);
while (scanner.next()) |result| {
- std.debug.assert(!result.name_needs_decoding);
- std.debug.assert(!result.value_needs_decoding);
+ if (Environment.allow_assert) std.debug.assert(!result.name_needs_decoding);
+ if (Environment.allow_assert) std.debug.assert(!result.value_needs_decoding);
var name = result.name;
var value = result.value;
diff --git a/src/resolver/data_url.zig b/src/resolver/data_url.zig
index 8a9186bf8..486f60608 100644
--- a/src/resolver/data_url.zig
+++ b/src/resolver/data_url.zig
@@ -32,7 +32,7 @@ pub const PercentEncoding = struct {
/// returns true if str starts with a valid path character or a percent encoded octet
pub fn isPchar(str: []const u8) bool {
- assert(str.len > 0);
+ if (Environment.allow_assert) assert(str.len > 0);
return switch (str[0]) {
'a'...'z', 'A'...'Z', '0'...'9', '-', '.', '_', '~', '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=', ':', '@' => true,
'%' => str.len > 3 and isHex(str[1]) and isHex(str[2]),
diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig
index c07d65133..f153db65a 100644
--- a/src/resolver/resolver.zig
+++ b/src/resolver/resolver.zig
@@ -1503,7 +1503,7 @@ pub const Resolver = struct {
}
var queue_slice: []DirEntryResolveQueueItem = _dir_entry_paths_to_resolve[0..@intCast(usize, i)];
- std.debug.assert(queue_slice.len > 0);
+ if (Environment.allow_assert) std.debug.assert(queue_slice.len > 0);
var open_dir_count: usize = 0;
// When this function halts, any item not processed means it's not found.
diff --git a/src/router.zig b/src/router.zig
index 3dba0b0d7..73a7d9987 100644
--- a/src/router.zig
+++ b/src/router.zig
@@ -698,8 +698,8 @@ pub const Route = struct {
match_name = name[1..];
}
- std.debug.assert(match_name[0] != '/');
- std.debug.assert(name[0] == '/');
+ if (Environment.allow_assert) std.debug.assert(match_name[0] != '/');
+ if (Environment.allow_assert) std.debug.assert(name[0] == '/');
} else {
name = Route.index_route_name;
match_name = Route.index_route_name;