[RFC]: disable floating-point contraction when building native add-ons for local tests

オープン
#16,596 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
cmake, javascript, node.js

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

Feature Needs Discussion RFC
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.gyp changes are needed (there are 1,719 of them). gyp's Makefile generator reads CFLAGS from the environment on both Linux and macOS (CFLAGS.target ?= $(CPPFLAGS) $(CFLAGS), appended in cmd_cc in gyp/pylib/gyp/generator/make.py). install-node-addons in tools/make/lib/install/addons.mk already passes the environment through to node-gyp rebuild, which is why the command above works today.
  • CI already solves "packages without add-ons". .github/workflows/scripts/run_affected_tests/run only builds an add-on when lib/node_modules/${pkg}/binding.gyp exists. I suggest make test reuse 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
  1. Add a variable to tools/make/lib/install/addons.mk (e.g., NODE_ADDONS_CFLAGS) which, when set, is passed as CFLAGS and CXXFLAGS to node-gyp rebuild.
  2. Before make test runs tests, resolve the packages matched by TESTS_FILTER. For each one that has a binding.gyp, run install-node-addons with NODE_ADDONS_CFLAGS="-ffp-contract=off".
  3. Document the behavior in tools/make/lib/test/README.md and in the contributing FAQ entry on compiling native add-ons.
Related Issues
  • stdlib-js/meetings #162
Questions
  1. 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-less make test may need to skip it.
  2. Should CI also pass -ffp-contract=off explicitly? CI passes today because it builds on ubuntu-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.
  3. 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?
  4. 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:.
主要言語
JavaScript
スター
6k
フォーク
1.3k
平均マージ
1日 21時間
マージ済み PR(30日)
224

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

stdlib-js/stdlib のほかの issue

stdlib-js/stdlib の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。