aboutsummaryrefslogtreecommitdiff
path: root/src/cache.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-12-30 21:12:32 -0800
committerGravatar GitHub <noreply@github.com> 2021-12-30 21:12:32 -0800
commite75c711c68896f5952793601f156c921c814caab (patch)
treef3b30e2281c7231d480bb84503d17b2370866ff9 /src/cache.zig
parent8d031f13c0e04629d431176e211a31224b7618c0 (diff)
downloadbun-e75c711c68896f5952793601f156c921c814caab.tar.gz
bun-e75c711c68896f5952793601f156c921c814caab.tar.zst
bun-e75c711c68896f5952793601f156c921c814caab.zip
Upgrade to latest Zig, remove dependency on patched version of Zig (#96)
* Prepare to upgrade zig * zig fmt * AllocGate * Update data_url.zig * wip * few files * just headers now? * I think everything works? * Update mimalloc * Update hash_map.zig * Perf improvements to compensate for Allocgate * Bump * :camera: * Update bun.lockb * Less branching * [js parser] Slightly reduce memory usage * Update js_parser.zig * WIP remove unused * [JS parser] WIP support for `with` keyword * Remove more dead code * Fix all the build errors! * cleanup * Move `network_thread` up * Bump peechy * Update README.md
Diffstat (limited to 'src/cache.zig')
-rw-r--r--src/cache.zig56
1 files changed, 33 insertions, 23 deletions
diff --git a/src/cache.zig b/src/cache.zig
index 869c083f0..3a3429105 100644
--- a/src/cache.zig
+++ b/src/cache.zig
@@ -1,4 +1,15 @@
-usingnamespace @import("global.zig");
+const _global = @import("global.zig");
+const string = _global.string;
+const Output = _global.Output;
+const StoredFileDescriptorType = _global.StoredFileDescriptorType;
+const Global = _global.Global;
+const Environment = _global.Environment;
+const strings = _global.strings;
+const MutableString = _global.MutableString;
+const stringZ = _global.stringZ;
+const FeatureFlags = _global.FeatureFlags;
+const default_allocator = _global.default_allocator;
+const C = _global.C;
const js_ast = @import("./js_ast.zig");
const logger = @import("./logger.zig");
@@ -12,13 +23,14 @@ const sync = @import("sync.zig");
const Mutex = @import("./lock.zig").Lock;
const import_record = @import("./import_record.zig");
+
const ImportRecord = import_record.ImportRecord;
pub const FsCacheEntry = struct {
contents: string,
fd: StoredFileDescriptorType = 0,
- pub fn deinit(entry: *FsCacheEntry, allocator: *std.mem.Allocator) void {
+ pub fn deinit(entry: *FsCacheEntry, allocator: std.mem.Allocator) void {
if (entry.contents.len > 0) {
allocator.free(entry.contents);
entry.contents = "";
@@ -31,7 +43,7 @@ pub const Set = struct {
fs: Fs,
json: Json,
- pub fn init(allocator: *std.mem.Allocator) Set {
+ pub fn init(allocator: std.mem.Allocator) Set {
return Set{
.js = JavaScript.init(allocator),
.fs = Fs{
@@ -55,10 +67,10 @@ pub const Fs = struct {
}
pub fn readFileShared(
- c: *Fs,
+ _: *Fs,
_fs: *fs.FileSystem,
path: [:0]const u8,
- dirname_fd: StoredFileDescriptorType,
+ _: StoredFileDescriptorType,
_file_handle: ?StoredFileDescriptorType,
shared: *MutableString,
) !Entry {
@@ -76,7 +88,7 @@ pub const Fs = struct {
}
const file = rfs.readFileWithHandle(path, null, file_handle, true, shared) catch |err| {
- if (comptime isDebug) {
+ if (comptime Environment.isDebug) {
Output.printError("{s}: readFile error -- {s}", .{ path, @errorName(err) });
}
return err;
@@ -127,7 +139,7 @@ pub const Fs = struct {
}
const file = rfs.readFileWithHandle(path, null, file_handle, use_shared_buffer, &c.shared_buffer) catch |err| {
- if (isDebug) {
+ if (Environment.isDebug) {
Output.printError("{s}: readFile error -- {s}", .{ path, @errorName(err) });
}
return err;
@@ -146,7 +158,7 @@ pub const Css = struct {
ok: bool,
value: void,
};
- pub fn parse(cache: *@This(), log: *logger.Log, source: logger.Source) !Result {
+ pub fn parse(_: *@This(), _: *logger.Log, _: logger.Source) !Result {
Global.notimpl();
}
};
@@ -154,21 +166,21 @@ pub const Css = struct {
pub const JavaScript = struct {
pub const Result = js_ast.Result;
- pub fn init(allocator: *std.mem.Allocator) JavaScript {
+ pub fn init(_: std.mem.Allocator) JavaScript {
return JavaScript{};
}
// For now, we're not going to cache JavaScript ASTs.
// It's probably only relevant when bundling for production.
pub fn parse(
- cache: *@This(),
- allocator: *std.mem.Allocator,
+ _: *const @This(),
+ allocator: std.mem.Allocator,
opts: js_parser.Parser.Options,
defines: *Define,
log: *logger.Log,
source: *const logger.Source,
) anyerror!?js_ast.Ast {
var temp_log = logger.Log.init(allocator);
- var parser = js_parser.Parser.init(opts, &temp_log, source, defines, allocator) catch |err| {
+ var parser = js_parser.Parser.init(opts, &temp_log, source, defines, allocator) catch {
temp_log.appendToMaybeRecycled(log, source) catch {};
return null;
};
@@ -187,8 +199,8 @@ pub const JavaScript = struct {
}
pub fn scan(
- cache: *@This(),
- allocator: *std.mem.Allocator,
+ _: *@This(),
+ allocator: std.mem.Allocator,
scan_pass_result: *js_parser.ScanPassResult,
opts: js_parser.Parser.Options,
defines: *Define,
@@ -198,19 +210,17 @@ pub const JavaScript = struct {
var temp_log = logger.Log.init(allocator);
defer temp_log.appendToMaybeRecycled(log, source) catch {};
- var parser = js_parser.Parser.init(opts, &temp_log, source, defines, allocator) catch |err| {
- return;
- };
+ var parser = js_parser.Parser.init(opts, &temp_log, source, defines, allocator) catch return;
return try parser.scanImports(scan_pass_result);
}
};
pub const Json = struct {
- pub fn init(allocator: *std.mem.Allocator) Json {
+ pub fn init(_: std.mem.Allocator) Json {
return Json{};
}
- fn parse(cache: *@This(), log: *logger.Log, source: logger.Source, allocator: *std.mem.Allocator, is_tsconfig: bool, func: anytype) anyerror!?js_ast.Expr {
+ fn parse(_: *@This(), log: *logger.Log, source: logger.Source, allocator: std.mem.Allocator, comptime func: anytype) anyerror!?js_ast.Expr {
var temp_log = logger.Log.init(allocator);
defer {
temp_log.appendToMaybeRecycled(log, &source) catch {};
@@ -219,11 +229,11 @@ pub const Json = struct {
break :handler null;
};
}
- pub fn parseJSON(cache: *@This(), log: *logger.Log, source: logger.Source, allocator: *std.mem.Allocator) anyerror!?js_ast.Expr {
- return try parse(cache, log, source, allocator, false, json_parser.ParseJSON);
+ pub fn parseJSON(cache: *@This(), log: *logger.Log, source: logger.Source, allocator: std.mem.Allocator) anyerror!?js_ast.Expr {
+ return try parse(cache, log, source, allocator, json_parser.ParseJSON);
}
- pub fn parseTSConfig(cache: *@This(), log: *logger.Log, source: logger.Source, allocator: *std.mem.Allocator) anyerror!?js_ast.Expr {
- return try parse(cache, log, source, allocator, true, json_parser.ParseTSConfig);
+ pub fn parseTSConfig(cache: *@This(), log: *logger.Log, source: logger.Source, allocator: std.mem.Allocator) anyerror!?js_ast.Expr {
+ return try parse(cache, log, source, allocator, json_parser.ParseTSConfig);
}
};