Skip to content

refactor(Global): mark more error code as cold and introduce new internal exit API - #542

Closed
ghost wants to merge 4 commits into
mainfrom
unknown repository
Closed

ghost wants to merge 4 commits into
mainfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Jul 10, 2022 •

Copy link
Copy Markdown

It's slightly different from what I described in the PR description of #535. Now Global.exit() means successful exit, Global.crash() retains its meaning of unsuccessful exit, and Global.exitOther(n) is used for any other specific exit code, with the latter two having @setCold(true) set for hints to the compiler.

While looking over the diff I notice that a lot of times the success-indicating Global.exit() is used after an error was printed. It seems like it's not well defined when exactly Global.crash() should be used and when Global.exit().
It'd probably be better if there was an error printing function that prints both a message and also exits with 1.

r00ster91 added 4 commits July 10, 2022 16:33
I'm not sure these messages ever printed until now.
Due to the @setCold(true) in Global.crash, this could improve performance as well.
This is part 1 of a new exit API that is supposed to make it harder to choose the wrong exit code and forgetting to mark paths as cold.
This finishes the new exit API.
@ghost ghost changed the title Mark more error code as cold and introduce new internal exit API refactor(Global): mark more error code as cold and introduce new internal exit API Jul 10, 2022
Comment thread src/__global.zig
}

/// Flushes output and exits otherwise unsuccessfully with a specific exit code.
pub fn exitOther(exit_code: u8) noreturn {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about renaming this to existCustom or exitCode to have more exact naming?

@ghost ghost Jul 10, 2022 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about using the word "custom" but "other" is shorter and not a less "exact" name IMO. It's the exit function you use for any other exit code or especially in any other case.

@ghost ghost Jul 10, 2022 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could also be named crashOther though.
I do think this API could still be improved. I still think an API consisting of exit(.failure), exit(.success), and exit(.{ .other = 50 }) would be better but I wasn't sure if @setCold(true) would work properly (it seems to mark the whole function as cold instead of only that one code path? I think this could be fixed by using functions within the one exit function and putting the @setCold(true)s there though) and I haven't received any feedback from @Jarred-Sumner yet.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I can agree on that, good point. But wouldn't making exist_code optional in exit more sens? so by default it would exist with 0 and if you pass any number in an argument it would use it 🤔

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SerekKiri one problem with that is that Zig does not have optional parameters.

@SerekKiri SerekKiri Jul 10, 2022 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so I read wrong thread in zig repo then, nvm! No more comments 👍🏼

@SerekKiri SerekKiri Jul 10, 2022 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't see the comment about crashOther but that's the best option I think with exist(.failure) etc. but I guess @Jarred-Sumner feedback would help here. I'm not experienced with zig yet so I can't help with that too much. :godmode:

@ghost

ghost commented Dec 23, 2022

Copy link
Copy Markdown
Author

For now it's probably best to close. This is low-priority anyway.

@ghost ghost closed this Dec 23, 2022
robobun added a commit that referenced this pull request Sep 1, 2026
oven-sh/WebKit#545 completes oven-sh/WebKit#155. NativeExecutable,
builtin functions written in JavaScript, bound functions and remote
functions now print `function name() { [native code] }`, the same
one-line shape as InternalFunction constructors and V8. lodash's
isNative() builds a RegExp from hasOwnProperty's source and tests Map
against it. With one shape the RegExp matches, so cloneDeep, memoize,
uniq and isEqual use a native Map instead of a linear-scan ListCache
under Bun. cloneDeep of 8 000 objects: 1 971 ms before, linear after.

The pin moves from the oven-sh/WebKit#541 preview to the fork's main at
01de4c1d, which also carries oven-sh/WebKit#529, #542 and #543. #543
moved the dynamic-import TLA deadlock check into the engine and removed
JSModuleLoader::asyncEvaluationOrderForKey and the referrerAsyncOrder
parameter of JSC::importModule, so moduleLoaderImportModule no longer
computes or passes it.

Tests: test/js/bun/jsc/function-prototype-tostring.test.ts and the
oven-sh/WebKit#545 stress file as a jsc-stress fixture. Both fail on
Bun 1.4.1.
Jarred-Sumner added a commit that referenced this pull request Sep 1, 2026
…e release + CodeBlock aging, #543 #548 module loader, #545, #529)
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant