cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[BUG] Assertion failure inside `find_definite_last_uses` in `sema.h` cppfront compiler.

Open germandiagogomez opened this issue 1 year ago • 4 comments
trafficstars

Describe the bug

Assertion failure inside find_definite_last_uses in sema.h cppfront compiler when using

boost::async and then continuations, not sure why exactly (could be order of evaluation when translating code? Just wild idea, not sure even if could be related).

There is a lambda created with different captures actually in each iteration of the loop, maybe that is troublesome?

To Reproduce

This piece of code seems to trigger it (go to the function the expression tasks.push_back(boost::async(:() = count_words(read_words(file$, stats*&$*, read_buf_size$))) triggers the assertion.


StringHash: @value type = {
    is_transparent : type == void;

    operator():(this, txt: * const char) = std::hash<std::string_view>()(txt);
    
    
    operator():(this, txt: std::string_view) = std::hash<std::string_view>()(txt);

    operator():(this, txt: std::string) -> std::size_t = {
        return std::hash<std::string_view>()(txt);
    }
}

OptionValueType: @union type = {
    intOpt: i32;
    stringOpt: std::string;
}

AlgorithmOptions: type == std::unordered_map<std::string, OptionValueType>;

WordsCountMap: type == phmap::parallel_flat_hash_map<std::string,
                                  std::uint64_t,
                                  StringHash,
                                  std::equal_to<>,
                                  std::allocator<std::pair<const std::string, std::uint64_t>>,
                                  7,
                                  std::mutex>;

CountWordsStats: @struct type = {
    bytes_read: std::atomic<std::int64_t> = 0;
    num_files_processed: std::atomic<std::size_t> = 0;
    average_files_size_bytes: std::atomic<std::size_t> = 0;
}

WordsViewCountMap: type == absl::flat_hash_map<std::string_view, std::uint64_t>;

WordsCountResult: type = {
    words_map: WordsCountMap;
    stats : std::unique_ptr<CountWordsStats>;

    operator=:(out this, forward wcm : WordsCountMap, 
               forward stts : std::unique_ptr<CountWordsStats>) = {
        words_map = wcm;
        stats = stts;
    }

}


count_words_with_boost_future:(rng: std::span<const std::filesystem::path>,
                     opts: AlgorithmOptions) -> WordsCountResult = {
  using namespace std;
  words_count : WordsCountMap = ();
  read_buf_size : int;
  if opts.contains("read-buffer-size") {
    read_buf_size = opts.at("read-buffer-size").intOpt();
  } else {
    read_buf_size = 4096;
  }
  words_count_mut: std::mutex = ();
  tasks: vector<boost::future<void>> = ();
  stats := new<CountWordsStats>();
  for rng do(file) {
      tasks.push_back(boost::async(:() = count_words(read_words(file$, stats*&$*, read_buf_size$)))..then(:(forward words: boost::future<WordsCountMap>) = {
              task_words := words.get();
              _ : std::lock_guard  = (words_count_mut&$*);
              for task_words do(wordtimes) {
                words_count&$*[wordtimes.first] += wordtimes.second;
              }
    }));
  }
  boost::when_all(tasks.begin(), tasks.end()).wait();
  return :WordsCountResult = (wrods_count, stats);
}

Additional context

The code has two dependencies but probably upon inspection it can be solved. Otherwise, please call me back, I will try to arrange something 100% usable without further config.

germandiagogomez avatar Aug 19 '24 12:08 germandiagogomez