-
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
src: refactor out some warnings from FillStatsArray
and node_file.h
#23793
Conversation
@addaleax, I believe |
This seems like a huge change for something that could be achieved through adding a couple of |
It's a refactor that makes sense. Besides eliminating the warnings, we take out a template was was instantiated twice in every translation unit it was included, while it's actually used in to. Plus reducing And the GSL is just a big bunch of free win. P.S. the second commit fe6cd36 is not that big... |
I’m totally on board with moving this out of |
I can add it in a separate PR, I thought this would be a nice POC... But it just found a bug on Windows: fields->SetValue(offset + 7, gsl::narrow<NativeT>(s->st_ino)) Where |
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.
Can you use static_cast in this PR, and leave the gsl part to another one as a follow up?
Anyway I am happy to see this out of node_internals.h!👍
FillStatsArray
FillStatsArray
and node_file.h
Took out the GSL, but added a second commit with few bug fixes found with clang-tidy. |
src/node_file.cc
Outdated
@@ -2319,6 +2319,8 @@ void Initialize(Local<Object> target, | |||
use_promises_symbol).FromJust(); | |||
} | |||
|
|||
|
|||
|
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.
Unrelated whitespace change
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.
Ack
@@ -30,7 +30,7 @@ class FSContinuationData : public MemoryRetainer { | |||
|
|||
uv_fs_t* req; | |||
int mode; | |||
std::vector<std::string> paths; | |||
std::vector<std::string> paths{}; |
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.
Unrelated?
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.
"ctor does not initialize paths
"
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.
That seems like something we should address on the compiler side, rather than starting to fix up all of our code… it’s not like something bad is happening 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.
The compiler can't tell if we want the default constructor or we forgot to initialize.
I'd rather be explicit, either here or in all the constructors.
src/node_file.h
Outdated
@@ -187,11 +263,12 @@ class FSReqPromise : public FSReqBase { | |||
object()->Get(env()->context(), | |||
env()->promise_string()).ToLocalChecked(); | |||
Local<Promise::Resolver> resolver = val.As<Promise::Resolver>(); | |||
resolver->Resolve(env()->context(), value).FromJust(); | |||
static_cast<void>(resolver->Resolve(env()->context(), value).FromJust()); |
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.
We use USE(…)
to serve this purpose (inspired by the same function in V8) rather than casting to void
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.
IMHO it is clearer...
- It's not a macro
- Reffered to explicitly in (4) at https://en.cppreference.com/w/cpp/language/static_cast
- Googling of static_cast<void>
- https://stackoverflow.com/questions/49273384/what-is-purpose-of-using-static-castvoid
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.
USE
isn’t a macro either, fwiw, just named that way because it used to be one in V8 I think.
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.
Ack
private: | ||
bool finished_ = false; | ||
AliasedBuffer<NativeT, V8T> stats_field_array_; | ||
DISALLOW_COPY_AND_ASSIGN(FSReqPromise); |
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.
Can you explain these changes? If we are getting warnings here, we might want to revert 97f1e94 instead?
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.
- It's a MACRO
- It in
private
- Does not delete the
move
s
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.
I think it's fine to use a macro if it reduces repetition, and it's also easier to search..about deleting move constructor&operator, why not just add another macro? (oops, I know)
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.
The move variants are implicitly deleted, according to #23092
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.
In this case I'm in favor being explicit over less-code-via-macros.
As for the move semantics, they are not generated, but are left undefined so it's a clang-tidy error, since the compiler can't say what we ment (not implement or forgot to implement).
#23092 is sort of Ok, since the MACRO is named DISALLOW_COPY_AND_ASSIGN
not DISALLOW_COPY_AND_ASSIGN_AND_MOVE
P.S. C++20 might solve this with metaclasses
src/node_file.h
Outdated
constexpr void FillStatsArrays(AliasedBuffer<NativeT, V8T>* fields, | ||
const uv_stat_t* s, | ||
const uv_stat_t* s2 = nullptr) { | ||
if (s2) { |
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.
We try to use explicit comparisons for pointers, i.e. if (s2 != nullptr)
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.
I thought I saw the opposite suggestions in a review this week 🤔
Anyway our styleguide has ES.87: Don’t add redundant == or != to conditions
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.
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.
Ack.
Reverted changes to grow_async_ids_stack in favor of #23808 |
Fixed bad |
src/node_file.h
Outdated
inline Local<Value> FillGlobalStatsArray(Environment* env, | ||
bool use_bigint, | ||
const uv_stat_t* s, | ||
const uv_stat_t* s2 = nullptr) { |
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.
Is there a reason the second call is encapsulated in node_file.h
? It should be easier to understand if the outmost caller just call it twice? (as that's only specific to watch methods, and only the JS part for those methods will make use of the additional fields)
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.
It made for a nice signature, also completely abstracted that we use the same AliasedArray
for both. But after I refactored it, I got rid of a function, so it's also nice. PTAL.
@@ -30,7 +30,7 @@ class FSContinuationData : public MemoryRetainer { | |||
|
|||
uv_fs_t* req; | |||
int mode; | |||
std::vector<std::string> paths; | |||
std::vector<std::string> paths{}; |
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.
That seems like something we should address on the compiler side, rather than starting to fix up all of our code… it’s not like something bad is happening here
src/node_file.h
Outdated
bool second = false) { | ||
ptrdiff_t offset = second ? kFsStatsFieldsNumber : 0; | ||
if (use_bigint) { | ||
const auto arr = env->fs_stats_field_bigint_array(); |
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.
I understand the desire to not spell out the full type here, but could you make it const auto*
? That way it’s obvious that no copy operations take place here, not knowing the type of arr
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.
I wanted to, but the compiler was being strange, I'll check again.
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.
error C2664: 'void node::fs::FillStatsArray<uint64_t,v8::BigUint64Array>(node::AliasedBuffer<uint64_t,v8::BigUint64Array> *,const uv_stat_t *,size_t)':
cannot convert argument 1 from 'const node::AliasedBuffer<uint64_t,v8::BigUint64Array> *' to 'node::AliasedBuffer<uint64_t,v8::BigUint64Array> *' [D:\code\node\node_lib.vcxproj]
It's a covariance const thing.
I could define a using for the two variants...
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.
It’s a const
thing – auto*
, not const auto*
is what I should have written.
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.
Ack. It's a const auto *
vs auto* const
.
Done.
src/node_file.h
Outdated
FillStatsArray(arr, s, offset); | ||
return arr->GetJSArray(); | ||
} else { | ||
const auto arr = env->fs_stats_field_array(); |
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.
ditto
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.
Done
src/node_file.h
Outdated
@@ -319,7 +411,7 @@ class FileHandle : public AsyncWrap, public StreamBase { | |||
ref_.Reset(env->isolate(), ref); | |||
} | |||
|
|||
~CloseReq() { | |||
virtual ~CloseReq() { |
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.
Wouldn’t override
do the job here? It’s what you used in other PRs, I think.
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.
Yep.
PR-URL: #23793 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
PR-URL: #23793 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
* explicitly delete move overloads * default initialize all members * explicitly discard unused return values * const some possibles PR-URL: #23793 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
Marking dont-land-on-v11.x until nodejs/build#1542 is fixed |
PR-URL: #23793 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
PR-URL: #23793 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
* explicitly delete move overloads * default initialize all members * explicitly discard unused return values * const some possibles PR-URL: #23793 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
PR-URL: #23793 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
PR-URL: #23793 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
* explicitly delete move overloads * default initialize all members * explicitly discard unused return values * const some possibles PR-URL: #23793 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
PR-URL: #23793 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
PR-URL: #23793 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
* explicitly delete move overloads * default initialize all members * explicitly discard unused return values * const some possibles PR-URL: #23793 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
This PR seems to be creating unexpected failures on v10.x BSD Can someone please backport? https://ci.nodejs.org/job/node-test-commit-freebsd/23692/nodes=freebsd10-64/console
|
#### adds a the Guideline Support Library to/deps/
:src: refactor out warnings from FillStatsArray
node_file.h
minimize number of template instantionsuv_timespec_t
FillGlobalStatsArray
FillGlobalStatsArray
signature to have one less default arginclude
ssrc: clean clang-tidy errors in node_file.h
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes