Skip to content
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

Fix msvc build errors in block_cache_trace_analyzer.cc (#5746) #5838

Closed
wants to merge 3 commits into from

Conversation

ccaughie
Copy link

Use a dynamically allocated array for reuse_table, since msvc does not
support stack-allocated arrays whose size is unknown at compile time.
Add a couple of explicit casts to avoid numeric conversion warnings.

N.B. I have not been able to test this change properly since I can't get the tests to run successfully using "make check" on Linux. Please let me know if there is a better way to do this.

Use a dynamically allocated array for reuse_table, since msvc does not
support stack-allocated arrays whose size is unknown at compile time.
Add a couple of explicit casts to avoid numeric conversion warnings.
Copy link
Contributor

@riversand963 riversand963 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ccaughie for the fix. Since I don't have MSVC environment, can @hliu18 and/or @burtonli verify this? Thanks

@@ -650,7 +651,8 @@ void BlockCacheTraceAnalyzer::WriteCorrelationFeaturesToFile(
const std::map<std::string, Features>& label_features,
const std::map<std::string, Predictions>& label_predictions,
uint32_t max_number_of_values) const {
std::default_random_engine rand_engine(env_->NowMicros());
std::default_random_engine rand_engine(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation. Can you build_tools/format-diff.sh as described in https://github.com/facebook/rocksdb/wiki/RocksDB-Contribution-Guide?

@@ -14,6 +14,7 @@
#include <fstream>
#include <iomanip>
#include <iostream>
#include <memory>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<memory> is already included by including other headers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I originally thought that was why the xcode build was failing. But it turns out xcode clang doesn't like std::make_unique at all, at least with the compiler options that are being used here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we can use #if defined() to enclose this include?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just remove it altogether. If I had looked more closely I would have realized that std::unique_ptr is already used in several other places in this file, so including is clearly not necessary for this new use of it.
Alternatively you could keep it in; some people would argue that each file should explicitly include the headers for what it uses so that it is not dependent on other header files including them first. All of those headers will have include guards so the impact on compile time should be negligible.

@@ -1209,11 +1211,14 @@ void BlockCacheTraceAnalyzer::WriteBlockReuseTimeline(
TraverseBlocks(block_callback);

// A cell is the number of blocks accessed in a reuse window.
uint64_t reuse_table[reuse_vector_size][reuse_vector_size];
const std::unique_ptr<uint64_t[]> reuse_table(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, MSVC forbids two-dimensional arrays now? Can @hliu18 or @burtonli verify this behavior?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MSVC supports two-dimensional arrays, but does not support variable length arrays, i.e. dimension sizes need to be known at compile time. Variable length array is not part of recent versions of C++ standard.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the following compile and run on MSVC?

#include <cstdio>

int main(int argc, char** argv) {
  const size_t sz = argc;
  int test_arr[sz];
  fprintf(stdout, "size is %d\n", sizeof(test_arr));
  return 0;
}

If not, this change is necessary.
It probably won't, according to your previous comment about compile-time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not compile: "error C2131: expression did not evaluate to a constant"
The compiler complains about [sz].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @hliu18 for verifying this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this PR was imported but not checked in due to conflicts. Can someone help move this PR forward? I was going to fix a couple of build break on MSVC and noticed this.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@riversand963 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@riversand963
Copy link
Contributor

Fixed by #6081

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants