[RFC]: disable floating-point contraction when building native add-ons for local tests
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 35/100
- Type d'issue
- Fonctionnalité
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- cmake, javascript, node.js
- Domaine
- build-system, testing
Piste de recherche
Start with tools/make/lib/install/addons.mk, tools/make/lib/test/README.md, and the contributing FAQ entry on compiling native add-ons; compare the add-on detection in .github/workflows/scripts/run_affected_tests/run. The RFC leaves several policy questions open, including default behavior, CI flags, stale builds, and C examples. Done means an agreed approach updates test builds and documents the behavior while preserving release flags.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Description
This RFC proposes updating make test so that it rebuilds the native add-ons of the packages under test with -ffp-contract=off, so local native test results match CI.
The approach was agreed on in Office Hours (2026-09-29). The open item from that meeting was how to handle packages which don't have a native add-on.
Problem
On Apple Silicon, clang fuses a*b + c into a single FMA instruction by default. The result can differ by 1 ulp from the JavaScript implementation, which rounds after each operation. Native tests using t.strictEqual then fail locally even though they pass in CI.
Reproduction on current develop (macOS arm64, Apple clang 21.0.0, node-gyp 12.4.0):
$ make install-node-addons NODE_ADDONS_PATTERN="stats/base/ndarray/dvariancech"
$ node lib/node_modules/@stdlib/stats/base/ndarray/dvariancech/test/test.native.js
not ok 11 returns expected value
expected: 6.25
actual: 6.249999999999999
# tests 12
# pass 11
# fail 1
The same package with contraction disabled:
$ CFLAGS="-ffp-contract=off" make install-node-addons NODE_ADDONS_PATTERN="stats/base/ndarray/dvariancech"
$ node lib/node_modules/@stdlib/stats/base/ndarray/dvariancech/test/test.native.js
# tests 12
# pass 12
Findings
- No
binding.gypchanges are needed (there are 1,719 of them). gyp's Makefile generator readsCFLAGSfrom the environment on both Linux and macOS (CFLAGS.target ?= $(CPPFLAGS) $(CFLAGS), appended incmd_ccingyp/pylib/gyp/generator/make.py).install-node-addonsintools/make/lib/install/addons.mkalready passes the environment through tonode-gyp rebuild, which is why the command above works today. - CI already solves "packages without add-ons".
.github/workflows/scripts/run_affected_tests/runonly builds an add-on whenlib/node_modules/${pkg}/binding.gypexists. I suggestmake testreuse that check rather than swallow a non-zero exit code from the rebuild step. Swallowing the exit code would also hide real compile errors. - Release builds should keep their current flags. FMA is faster and is usually at least as accurate. Only the test build needs to match the JavaScript reference.
Proposed changes
- Add a variable to
tools/make/lib/install/addons.mk(e.g.,NODE_ADDONS_CFLAGS) which, when set, is passed asCFLAGSandCXXFLAGStonode-gyp rebuild. - Before
make testruns tests, resolve the packages matched byTESTS_FILTER. For each one that has abinding.gyp, runinstall-node-addonswithNODE_ADDONS_CFLAGS="-ffp-contract=off". - Document the behavior in
tools/make/lib/test/README.mdand in the contributing FAQ entry on compiling native add-ons.
Related Issues
- stdlib-js/meetings #162
Questions
- Should the rebuild be on by default for
make test, or opt-in (e.g.,TEST_NATIVE=1)? Rebuilding adds compile time to every run, so a filter-lessmake testmay need to skip it. - Should CI also pass
-ffp-contract=offexplicitly? CI passes today because it builds onubuntu-latest(x86-64). As far as I can tell, that's only because baseline x86-64 has no FMA instructions to fuse into, not because contraction is turned off. If CI ever moves to arm64 runners, the same 1-ulp failures would show up there. - Should the flag be recorded (e.g., in a stamp file next to the built add-on) so that a test run doesn't use a stale add-on built with different flags?
- Do C examples and C benchmarks (
make examples-c,make benchmark-c) need the same treatment, or is this only about tests?
Other
The 1-ulp cases have been showing up in the ULP-assertion migration PRs. Several native tests have moved to isAlmostSameValue( actual, expected, 1 ) to tolerate this difference. With contraction disabled in test builds, strictEqual would work again for kernels where the JavaScript and C implementations are meant to match exactly.
Checklist
- I have read and understood the Code of Conduct.
- Searched for existing issues and pull requests.
- The issue name begins with
RFC:.
- Langage dominant
- JavaScript
- Étoiles
- 6k
- Forks
- 1.3k
- Merge moyen
- 1 j 21 h
- PR mergées (30 j)
- 224
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de stdlib-js/stdlib
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
stdlib-js/stdlib#16655 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Fix JavaScript lint errorsPeut-être pris @protestershankar l’a pris il y a 5 jours. OuverteGood First Issue
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
stdlib-js/stdlib#16563 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Fix C lint errorsPeut-être pris @raus7n l’a pris il y a 14 jours. OuverteGood First Issue
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
stdlib-js/stdlib#16454 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Fix JavaScript lint errorsPeut-être pris @Devansh-18155 l’a pris il y a 39 jours. OuverteGood First Issue
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
stdlib-js/stdlib#15970 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Fix JavaScript lint errorsPeut-être pris @lb1192176991-lab l’a pris il y a 44 jours. OuverteGood First Issue
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
stdlib-js/stdlib#15831 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de stdlib-js/stdlib
Issues similaires
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 69/100
Les mainteneurs répondent en général sous 1 jour
-
automation chore ci-cd consistency developer-experience difficulty: easy discoverability documentation enhancement github-actions good first issue help wanted hygiene priority: P3 seo shell yaml
Difficulté 1/5 Moins d'une heure Accessibilité débutants 76/100
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
swc-project/swc-next-issues#394 ·
-
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
githubnext/gh-aw-workshop#5790 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
adobe/helix-tools-website#480 ·
Les mainteneurs répondent en général sous 1 jour