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

node-api: include experimental feature flags in add-on version reported at runtime #52935

Open
gabrielschulhof opened this issue May 10, 2024 · 3 comments
Labels
feature request Issues that request new features to be added to Node.js. node-api Issues and PRs related to the Node-API.

Comments

@gabrielschulhof
Copy link
Contributor

gabrielschulhof commented May 10, 2024

This only applies to features that change the behaviour of existing APIs.

We currently have two flags for each experimental behaviour-changing API:

  1. A feature flag indicating that it is available within the NAPI_EXPERIMENTAL portion of the API.
  2. An opt-out flag indicating that, although the add-on chose to use NAPI_EXPERIMENTAL it does not wish to use this particular feature of the experimental bundle.

In order to avoid going down the experimental code path when running an add-on that chose to opt out of an experimental feature, we need to encode that choice in the version reported to the add-on loader.

If NAPI_EXPERIMENTAL is defined, all experimental features are turned on, unless, for any given feature, its opt-out flag is given.

We can include experimental flags in the version number reported at runtime as follows:

highest 16 bits lowest 16 bits
feature 1 feature 2 ... feature 16 NAPI_VERSION (latest released, i.e. 8, 9, 10, etc.)
or
NAPI_VERSION_EXPERIMENTAL (2147483647) All experimental features are requested

This value ends up on napi_env. At runtime we can check against the bits of this value to decide on the code path. We should probably create a family of macros for making decisions based on the feature flags.

At our Node-API meeting we concluded that we should introduce behaviour-changing features extremely sparingly, because, in order to ensure we do not break our users, even those that have opted into NAPI_EXPERIMENTAL, the testing complexity doubles with each feature we introduce.

@gabrielschulhof gabrielschulhof added feature request Issues that request new features to be added to Node.js. abortcontroller Issues and PRs related to the AbortController API node-api Issues and PRs related to the Node-API. and removed abortcontroller Issues and PRs related to the AbortController API labels May 10, 2024
@gabrielschulhof
Copy link
Contributor Author

@nodejs/node-api

@KevinEady
Copy link
Contributor

KevinEady commented May 11, 2024

Hi @gabrielschulhof ,

Just wanted a clarification with an example. Say we add a new Node-API, node_api_x(). Since this is not a behavior change, we would continue with our current flow (ie. guard declaration via #ifdef NAPI_EXPERIMENTAL, then update to #if NAPI_VERSION >= x on stable release, etc etc following https://github.com/nodejs/node/blob/main/doc/contributing/adding-new-napi-api.md), correct?

@gabrielschulhof
Copy link
Contributor Author

@KevinEady that's a good question. I think we would still add a feature flag, so we'd know the feature was available, though not an opt-out flag. I think assembling the version to report would be encoded using a series of macro calls starting with NAPI_VERSION and adding each successive feature bit. Thus we could, for non-behaviour-changing features, avoid updating this series of macro calls with a call to setting the feature bit for the non-behaviour-changing feature. That way, a feature bit would not be reserved for the feature, since it's not needed at runtime anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. node-api Issues and PRs related to the Node-API.
Projects
Development

No branches or pull requests

2 participants