-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Adding the GSL as a dep + POC of its usefulness #23821
Conversation
/CC @nodejs/platform-windows @nodejs/fs This https://ci.nodejs.org/job/node-test-commit-windows-fanned/21700/ job should uncover the bug. |
25ef826 - hooking the GSL to our PTAL |
Can you update the |
Ack. (I did it before, lost it in this revision). |
BTW: does anyone have an idea what to do with: fields->SetValue(offset + 7, gsl::narrow<NativeT>(s->st_ino)); when My two ideas are either (seeking more):
If you feel like voting /CC @nodejs/fs @nodejs/platform-windows @nodejs/platform-macos |
@refack I'd suggest we leave them overflowed and recommend using the bigint version if they want to use that |
A headers only library to support following the C++ Core Guidelines. Rev: microsoft/GSL@c02ddae Refs: https://github.com/Microsoft/GSL Refs: http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-gsl
Documented unreliability of non BigInt PTAL |
01c7de7
to
5a95506
Compare
I’m feeling a bit uncomfortable with mixing in a valid documentation patch into a PR of this size? I think the fact that this PR has not received approvals after 24 days also says something about people’s feelings about it … you can try to get more people’s input, but I’m personally not convinced that the value added by the GSL is worth the added complexity of an extra library for us? |
We get bugs uncovered, almost for free. Real fail on smartOS:
Real fail on macOS
Real fail on AIX
|
@refack Uh… so what you’re saying is that this PR introduces hard crashes into Node? I was not aware of that – I don’t think we can change the current behaviour of the (i.e. The only solution I can currently see is documenting limitations, which I am totally on board with but don’t want to mix in here) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introducing new hard-crashes is a no-go, imo
I'm sorry if I didn't make myself clear about the crashes being an indication of the latent bug. Just like P.S. seems like it's not just |
ebc66ca
to
5e69527
Compare
Promoted to js tests for easier groking Line 641 in 01c7de7
smartOS: AssertionError [ERR_ASSERTION]: bigintStats.rdev: 18446744073709551615 is not equal to numStats.rdev: 18446744073709552000
at verifyStats (/home/iojs/build/workspace/node-test-commit-smartos/nodes/smartos16-64/test/parallel/test-fs-stat-ino-overflow.js:31:12)
at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-smartos/nodes/smartos16-64/test/parallel/test-fs-stat-ino-overflow.js:46:3)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:775:12)
at startup (internal/bootstrap/node.js:300:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:826:3) AIX: AssertionError [ERR_ASSERTION]: bigintStats.dev: 9223372191473598466 is not equal to numStats.dev: 9223372191473598000
at verifyStats (/home/iojs/build/workspace/node-test-commit-aix/nodes/aix61-ppc64/test/parallel/test-fs-stat-ino-overflow.js:31:12)
at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-aix/nodes/aix61-ppc64/test/parallel/test-fs-stat-ino-overflow.js:46:3)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:775:12)
at startup (internal/bootstrap/node.js:300:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:826:3) |
I've refactored the commits to exemplify the story:
|
Would be great to see some explicit 👍 and/or 👎 on this one so we can get an idea what to do with it... |
TBH it's hard for me to get past the addition of a new thing to deps/ that doesn't remove something else (at least llhttp is aiming to remove http_parser). A question I have is—if these are such good "guidelines", why did they not make it into the language? C++, and Stroustrup himself, have a strong record of throwing shiny stuff into the language and even celebrating doing so. ("Keep developers happy by adding new stuff" is a paraphrase of something I heard Stroustrup say once). |
Most of the stuff in this library are polyfills for C++11 to give us features that got to the language only C++17 and C++20 (and they degrade when the features are available from the compiler). So I'd say think of it more like a portable compiler plugin, then a library. As I understand it the language standard moves forward very slowly end rigorously, while this library is more agile. Also The standard committee is 1000% committed to backward compatibility, while the guidelines can say "this feature is a legacy footgun, prefer the alternative new safer feature". (e.g. The big difference between this vs something like Boost is that it's very minimal (4KLoc) and 95% of the features are compile time only, with 0 run-time cost. Maybe the best analog is |
So...I don't generally disagree about this, but I'd like to remind that just because a feature is compile-time only doesn't mean it does not have an impact on the runtime performance, as there is always cache-friendliness and micro-optimizations involved. I used to not worry about the cost of templates until a coworker of mine ran into performance regressions introduced by templates because somehow the way the templates were written resulted in less cache-friendly code, even though it looked harmless and functionally equivalent...just food for thought. In the end we still need to benchmark if we are going to touch a very hot code path (although I don't think the POC here does) |
But this library was specifically designed, implemented, and coordinated with compiler writers to guarantee 0 run-time cost.
💯 agree! Which reminds me, upgrading our compilers "should" give us some "free" performance improvements, or at least it's worth evaluating (nodejs/build#1543) |
|
@@ -3,14 +3,13 @@ | |||
const common = require('../common'); | |||
const assert = require('assert'); | |||
|
|||
if (!common.isWindows) | |||
if (!(common.isWindows || common.isSunOS || common.isAIX)) | |||
assert.fail('Code should fail only on Windows.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be updated to include mention of the other operating systems.
Should a different PR be opened for the content of the last two commits in this PR? (Has it already?) |
564123b deps: add the GSL
Refs: https://github.com/Microsoft/GSL
Refs: http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-gsl
A headers only library to support following the C++ Core Guidelines. Most APIs are compile-time only (zero runtime cost) types such as:
span
- which is size awareT[]
string_span
- same but specialized forchar[]
at()
- bounds safe access toT[]
copy()
- bounds safememcpy
forspan
andT[]
owner
- declarative ownership for naked pointersnot_null
- a wrapper for pointers that does not compile if assignednullptr
or not initializednarrow_cast
- agrap
ablestatic_cast
for numeric types castsnarrow
(has runtime cost) - a static_cast that throws on truncation.finally
- an arbitrary RAII lambda wrapper[[expects]]
and[[ensures]]
176b82d src: example use of
gsl::narrow
to uncover a bug infs::LStat
on WindowsUsing
gsl::narrow
uncovered a numeric truncation ofstats.ino
on Windows.CI: https://ci.nodejs.org/job/node-test-pull-request/18048/
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes