-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(bundler): implement enum inlining / more constant folding #12144
base: main
Are you sure you want to change the base?
Conversation
❌ @paperdave, your commit has failing tests :( 💪 15 failing tests Darwin AARCH64
💻 15 failing tests Darwin x64 baseline
💻 15 failing tests Darwin x64
🐧💪 15 failing tests Linux AARCH64
🐧🖥 16 failing tests Linux x64 baseline
🐧🖥 15 failing tests Linux x64
🪟💻 22 failing tests Windows x64 baseline
🪟💻 22 failing tests Windows x64
|
76e7420
to
3aec7f1
Compare
This comment was marked as outdated.
This comment was marked as outdated.
/// by calling out to the APIs in WebKit which are responsible for this operation. | ||
/// | ||
/// This can return `null` in wasm builds to avoid linking JSC | ||
pub fn toString(this: Number, allocator: std.mem.Allocator) ?string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: this is renamed from toStringSafely
to toString
, not because it is now less safe, but because the original intent of "we are taking a safer approach" does not apply.
@@ -123,7 +123,7 @@ pub fn getOSGlibCVersion(os: OperatingSystem) ?Version { | |||
} | |||
|
|||
pub fn build(b: *Build) !void { | |||
std.debug.print("zig build v{s}\n", .{builtin.zig_version_string}); | |||
std.log.info("zig compiler v{s}", .{builtin.zig_version_string}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apologies for doing a ton of other random things in this pr. i fixed the banned.json linter which resulted in needing to apply a ton of small transformations. i did this because i was sick of std.debug.print
showing at all in my cmd+shift+f menu. this also resulted in the deletion of some old files, which some did not even past astgen.
additionally, i have been using a client side spell-checker, so it just becomes annoying to see a ton of yellow underlines. maybe i will upstream a ci check to keep spelling somewhat intact (i have been very impressed with the typos
cli and lsp, it is very low false positive).
@compileError("This function can only be called in comptime."); | ||
} | ||
var x = 0; // if you hit an error on this line, you are not in a comptime context | ||
_ = &x; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comptime @inComptime
is a compiler error in 0.14 and in 0.13 does not do what we want.
@@ -46,8 +46,6 @@ pub const allow_json_single_quotes = true; | |||
|
|||
pub const react_specific_warnings = true; | |||
|
|||
pub const log_allocations = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this behavior is now provided via BUN_DEBUG_mimalloc=1
const use = part.symbol_uses.getPtr(ref).?; | ||
|
||
// Rare path: this import is a TypeScript enum | ||
if (c.graph.meta.items(.imports_to_bind)[id].get(ref)) |import_data| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please hoist this .items[id]
call above the for loop
/// generated proxy symbols that represent the property access "x3.y". This | ||
/// map is unique per namespace block because "x3" is the argument symbol that | ||
/// is specific to that particular namespace block. | ||
property_accesses: std.StringArrayHashMapUnmanaged(Ref) = .{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
property_accesses: std.StringArrayHashMapUnmanaged(Ref) = .{}, | |
property_accesses: bun.StringArrayHashMapUnmanaged(Ref) = .{}, |
Fixes #11764
Fixes #2945
Fixes #2889
Draft TODO:
Initially was a PR to fix an enum bug, but it turned out the bug was due to a lack of a feature: enum inlining. So I decided to do it, since it was a feature I personally have a big use for (For example, the
bun.report
project has a regex hack workaround to force enum inlining, because the codegen otherwise is an abomination)Simple Sample
After:
Before:
If you reference the enum directly, you can get the two-way map. This even works with
const enum
, as it is TSC's job to prohibit such usage.The codegen of these enums have been improved. Projects with heavy enum usage should see smaller bundle sizes. Now:
Before:
It would be interesting as a future project to see if the size of these enums could be shrunk further, but
esbuild
doesn't do that, and I think personally it's fine to leaveenum
in the dust asconst enum
and inlining all values becomes the new norm.