Skip to content
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

internal: remove secret hidden internals and introduce new way to call native code from js #8166

Merged
merged 38 commits into from Mar 30, 2024

Conversation

paperdave
Copy link
Collaborator

@paperdave paperdave commented Jan 14, 2024

What does this PR do?

ooooh magic javascript preprocessor shenanigans.

This PR removes $lazy, and replaces it with two alternatives: $cpp and $zig. These both take a filename and a function name, and they will call the function defined with no arguments.

  • Preprocessor Transform
  • Codegen
  • New impl of @lazy

Examples:

image

image

With this done, I will also be removing the following definitions

  • globalThis[Symbol.for("Bun.lazy")]
  • Bun.fs
  • Bun._Path
  • Bun._Os()

The API Bun.DO_NOT_USE_OR_YOU_WILL_BE_FIRED_mimalloc_dump has been renamed to Bun.unsafe.dumpMimalloc(). While left undocumented, this will hopefully reduce the number of people fired from bun.

If internals are required for unit testing, two mechanisms will be provided. In order for either to work, the environment variables BUN_GARBAGE_COLLECTOR_LEVEL and BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING must be set, or you must be running in a debug build.

From there, runtime versions of $zig and $cpp will exist on the global object. These work the same as the bundled ones, but only map to symbols that have a used binding in the src/js. Perhaps we can add a way to add additional bindings that aren't used in src/js but able to be exposed for testing, such as the syntax highlighter.

From there, you can use bun:internal-for-testing, which currently contains three declarations:

image

Extra Tasks

  • Internal Typescript Definitions and Documentation
  • Merge bundle-functions and bundle-modules once and for all
  • Finish porting old code to new API

@Jarred-Sumner
Copy link
Collaborator

Exciting

We can keep DO_NOT_USE_OR_YOU_WILL_BE_FIRED_mimalloc_dump imo

@Jarred-Sumner
Copy link
Collaborator

v fancy

@paperdave paperdave marked this pull request as ready for review January 15, 2024 21:43
Copy link

github-actions bot commented Mar 9, 2024

❌🪟 @paperdave, there are 9 test regressions on Windows x86_64

  • test\cli\install\bunx.test.ts
  • test\cli\install\migration\migrate.test.ts
  • test\cli\install\registry\bun-install-registry.test.ts
  • test\js\node\dns\node-dns.test.js
  • test\js\third_party\esbuild\esbuild-child_process.test.ts
  • test\js\web\fetch\body-stream.test.ts
  • test\regression\issue\09041.test.ts
  • test\js\third_party\postgres\postgres.test.ts
  • test\js\web\workers\worker.test.ts

Full Test Output

@Jarred-Sumner
Copy link
Collaborator

merge conflicts

@paperdave
Copy link
Collaborator Author

this PR is marked breaking as it removes some hidden apis. we will merge this before 1.1 but before the last 1.0.x

Copy link

github-actions bot commented Mar 11, 2024

@paperdave
Copy link
Collaborator Author

test/js/bun/wasm/wasi.test.js test i think is real

paperdave added a commit that referenced this pull request Mar 14, 2024
Copy link

github-actions bot commented Mar 14, 2024

Jarred-Sumner added a commit that referenced this pull request Mar 23, 2024
* run-eval.test.ts

* transpiler-cache.test.ts

* node net

* some open things

* a

* a

* yikes

* incredible

* run it back

* a

* this code is what i like to call, incorrect

* ok its all worng

* remove an assertion that is wrong again

* update test things and rebase

* performance test

* mark filesink with mkfifo as todo. see #8166

* hehe

* not done

* awa

* fs test pass

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
zackradisic pushed a commit that referenced this pull request Mar 25, 2024
* run-eval.test.ts

* transpiler-cache.test.ts

* node net

* some open things

* a

* a

* yikes

* incredible

* run it back

* a

* this code is what i like to call, incorrect

* ok its all worng

* remove an assertion that is wrong again

* update test things and rebase

* performance test

* mark filesink with mkfifo as todo. see #8166

* hehe

* not done

* awa

* fs test pass

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
@Jarred-Sumner Jarred-Sumner merged commit d712254 into main Mar 30, 2024
26 of 31 checks passed
@Jarred-Sumner Jarred-Sumner deleted the dave/hide-internals branch March 30, 2024 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants