Perfect your code
With built-in code review tools, GitHub makes it easy to raise the quality bar before you ship. Join the 36 million developers who've merged over 200 million pull requests.
Sign up for free See pricing for teams and enterprisessrc: refactor out some warnings from `FillStatsArray` and `node_file.h` #23793
Conversation
refack
requested review from
addaleax,
joyeecheung and
gireeshpunathil
Oct 21, 2018
This comment has been minimized.
This comment has been minimized.
nodejs-github-bot
added
the
meta
label
Oct 21, 2018
refack
self-assigned this
Oct 21, 2018
refack
added
C++
lib / src
labels
Oct 21, 2018
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@addaleax, I believe |
This comment has been minimized.
This comment has been minimized.
|
This seems like a huge change for something that could be achieved through adding a couple of |
This comment has been minimized.
This comment has been minimized.
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... |
This comment has been minimized.
This comment has been minimized.
|
I’m totally on board with moving this out of |
This comment has been minimized.
This comment has been minimized.
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 |
refack
force-pushed the
refack:GSL
branch
from
fe6cd36
to
86852c7
Oct 21, 2018
joyeecheung
reviewed
Oct 21, 2018
|
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! |
refack
force-pushed the
refack:GSL
branch
from
86852c7
to
ee63a3b
Oct 21, 2018
refack
changed the title
src: refactor out warnings from `FillStatsArray`
src: refactor out some warnings from `FillStatsArray` and `node_file.h`
Oct 21, 2018
This comment has been minimized.
This comment has been minimized.
|
Took out the GSL, but added a second commit with few bug fixes found with clang-tidy. |
refack
force-pushed the
refack:GSL
branch
from
ee63a3b
to
4194693
Oct 21, 2018
refack
removed
the
meta
label
Oct 21, 2018
addaleax
reviewed
Oct 21, 2018
| @@ -2319,6 +2319,8 @@ void Initialize(Local<Object> target, | |||
| use_promises_symbol).FromJust(); | |||
| } | |||
|
|
|||
|
|
|||
|
|
|||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| @@ -30,7 +30,7 @@ class FSContinuationData : public MemoryRetainer { | |||
|
|
|||
| uv_fs_t* req; | |||
| int mode; | |||
| std::vector<std::string> paths; | |||
| std::vector<std::string> paths{}; | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
addaleax
Oct 23, 2018
Member
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
This comment has been minimized.
This comment has been minimized.
refack
Oct 23, 2018
Author
Member
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.
| @@ -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()); | |||
This comment has been minimized.
This comment has been minimized.
addaleax
Oct 21, 2018
Member
We use USE(…) to serve this purpose (inspired by the same function in V8) rather than casting to void
This comment has been minimized.
This comment has been minimized.
refack
Oct 21, 2018
Author
Member
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
This comment has been minimized.
This comment has been minimized.
addaleax
Oct 21, 2018
Member
USE isn’t a macro either, fwiw, just named that way because it used to be one in V8 I think.
This comment has been minimized.
This comment has been minimized.
| private: | ||
| bool finished_ = false; | ||
| AliasedBuffer<NativeT, V8T> stats_field_array_; | ||
| DISALLOW_COPY_AND_ASSIGN(FSReqPromise); |
This comment has been minimized.
This comment has been minimized.
addaleax
Oct 21, 2018
Member
Can you explain these changes? If we are getting warnings here, we might want to revert 97f1e94 instead?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
joyeecheung
Oct 23, 2018
•
Member
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)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
refack
Oct 23, 2018
Author
Member
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
| constexpr void FillStatsArrays(AliasedBuffer<NativeT, V8T>* fields, | ||
| const uv_stat_t* s, | ||
| const uv_stat_t* s2 = nullptr) { | ||
| if (s2) { |
This comment has been minimized.
This comment has been minimized.
addaleax
Oct 21, 2018
Member
We try to use explicit comparisons for pointers, i.e. if (s2 != nullptr)
This comment has been minimized.
This comment has been minimized.
refack
Oct 21, 2018
Author
Member
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
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
refack
force-pushed the
refack:GSL
branch
from
edc9503
to
a8e1f04
Oct 21, 2018
This comment has been minimized.
This comment has been minimized.
|
Reverted changes to grow_async_ids_stack in favor of #23808 |
This comment has been minimized.
This comment has been minimized.
|
Fixed bad |
joyeecheung
reviewed
Oct 23, 2018
| inline Local<Value> FillGlobalStatsArray(Environment* env, | ||
| bool use_bigint, | ||
| const uv_stat_t* s, | ||
| const uv_stat_t* s2 = nullptr) { |
This comment has been minimized.
This comment has been minimized.
joyeecheung
Oct 23, 2018
Member
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)
This comment has been minimized.
This comment has been minimized.
refack
Oct 23, 2018
Author
Member
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.
addaleax
approved these changes
Oct 23, 2018
| @@ -30,7 +30,7 @@ class FSContinuationData : public MemoryRetainer { | |||
|
|
|||
| uv_fs_t* req; | |||
| int mode; | |||
| std::vector<std::string> paths; | |||
| std::vector<std::string> paths{}; | |||
This comment has been minimized.
This comment has been minimized.
addaleax
Oct 23, 2018
Member
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
| bool second = false) { | ||
| ptrdiff_t offset = second ? kFsStatsFieldsNumber : 0; | ||
| if (use_bigint) { | ||
| const auto arr = env->fs_stats_field_bigint_array(); |
This comment has been minimized.
This comment has been minimized.
addaleax
Oct 23, 2018
Member
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
This comment has been minimized.
This comment has been minimized.
refack
Oct 23, 2018
•
Author
Member
I wanted to, but the compiler was being strange, I'll check again.
This comment has been minimized.
This comment has been minimized.
refack
Oct 23, 2018
•
Author
Member
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...
This comment has been minimized.
This comment has been minimized.
addaleax
Oct 23, 2018
Member
It’s a const thing – auto*, not const auto* is what I should have written.
This comment has been minimized.
This comment has been minimized.
| FillStatsArray(arr, s, offset); | ||
| return arr->GetJSArray(); | ||
| } else { | ||
| const auto arr = env->fs_stats_field_array(); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
addaleax
approved these changes
Oct 23, 2018
| @@ -319,7 +411,7 @@ class FileHandle : public AsyncWrap, public StreamBase { | |||
| ref_.Reset(env->isolate(), ref); | |||
| } | |||
|
|
|||
| ~CloseReq() { | |||
| virtual ~CloseReq() { | |||
This comment has been minimized.
This comment has been minimized.
addaleax
Oct 23, 2018
Member
Wouldn’t override do the job here? It’s what you used in other PRs, I think.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
refack
merged commit 205b667
into
nodejs:master
Oct 24, 2018
1 check was pending
refack
deleted the
refack:GSL
branch
Oct 24, 2018
refack
removed their assignment
Oct 24, 2018
targos
added a commit
that referenced
this pull request
Oct 26, 2018
targos
added a commit
that referenced
this pull request
Oct 26, 2018
targos
added a commit
that referenced
this pull request
Oct 26, 2018
targos
added
the
dont-land-on-v11.x
label
Nov 1, 2018
This comment has been minimized.
This comment has been minimized.
|
Marking dont-land-on-v11.x until nodejs/build#1542 is fixed |
targos
added this to Don't land (for now)
in v11.x
Nov 1, 2018
targos
removed
the
dont-land-on-v11.x
label
Nov 18, 2018
targos
added a commit
that referenced
this pull request
Nov 18, 2018
targos
added a commit
that referenced
this pull request
Nov 18, 2018
targos
added a commit
that referenced
this pull request
Nov 18, 2018
rvagg
added a commit
that referenced
this pull request
Nov 28, 2018
rvagg
added a commit
that referenced
this pull request
Nov 28, 2018
rvagg
added a commit
that referenced
this pull request
Nov 28, 2018
This was referenced Dec 7, 2018
codebytere
added a commit
that referenced
this pull request
Jan 13, 2019
codebytere
added a commit
that referenced
this pull request
Jan 13, 2019
codebytere
added a commit
that referenced
this pull request
Jan 13, 2019
This comment has been minimized.
This comment has been minimized.
|
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
|
refack commentedOct 21, 2018
•
edited
#### adds a the Guideline Support Library to/deps/:src: refactor out warnings from FillStatsArray
node_file.hminimize number of template instantionsuv_timespec_tFillGlobalStatsArrayFillGlobalStatsArraysignature to have one less default argincludessrc: clean clang-tidy errors in node_file.h
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes