Skip to content

Commit

Permalink
Merge branch 'trunk' into toolchain-format-tuple-value
Browse files Browse the repository at this point in the history
  • Loading branch information
zygoloid committed Dec 12, 2024
2 parents 3551884 + 3ce0df6 commit 06e401d
Show file tree
Hide file tree
Showing 106 changed files with 3,260 additions and 326 deletions.
2 changes: 1 addition & 1 deletion common/array_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ArrayStack {
auto AppendToTop(llvm::ArrayRef<ValueT> values) -> void {
CARBON_CHECK(!array_offsets_.empty(),
"Must call PushArray before PushValues.");
values_.append(values.begin(), values.end());
llvm::append_range(values_, values);
}

// Returns the current number of values in all arrays.
Expand Down
7 changes: 3 additions & 4 deletions common/command_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,10 +1070,9 @@ auto Parser::FinalizeParsedOptions() -> ErrorOr<Success> {
// Sort the missing arguments by name to provide a stable and deterministic
// error message. We know there can't be duplicate names because these came
// from a may keyed on the name, so this provides a total ordering.
std::sort(missing_options.begin(), missing_options.end(),
[](const Arg* lhs, const Arg* rhs) {
return lhs->info.name < rhs->info.name;
});
llvm::sort(missing_options, [](const Arg* lhs, const Arg* rhs) {
return lhs->info.name < rhs->info.name;
});

std::string error_str = "required options not provided: ";
llvm::raw_string_ostream error(error_str);
Expand Down
33 changes: 14 additions & 19 deletions common/hashing_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,9 @@ auto FindBitRangeCollisions(llvm::ArrayRef<HashedValue<T>> hashes)

// Now we sort by the extracted bit sequence so we can efficiently scan for
// colliding bit patterns.
std::sort(
bits_and_indices.begin(), bits_and_indices.end(),
[](const auto& lhs, const auto& rhs) { return lhs.bits < rhs.bits; });
llvm::sort(bits_and_indices, [](const auto& lhs, const auto& rhs) {
return lhs.bits < rhs.bits;
});

// Scan the sorted bit sequences we've extracted looking for collisions. We
// count the total collisions, but we also track the number of individual
Expand Down Expand Up @@ -635,16 +635,15 @@ auto FindBitRangeCollisions(llvm::ArrayRef<HashedValue<T>> hashes)
}

// Sort by collision count for each hash.
std::sort(bits_and_indices.begin(), bits_and_indices.end(),
[&](const auto& lhs, const auto& rhs) {
return collision_counts[collision_map[lhs.index]] <
collision_counts[collision_map[rhs.index]];
});
llvm::sort(bits_and_indices, [&](const auto& lhs, const auto& rhs) {
return collision_counts[collision_map[lhs.index]] <
collision_counts[collision_map[rhs.index]];
});

// And compute the median and max.
int median = collision_counts
[collision_map[bits_and_indices[bits_and_indices.size() / 2].index]];
int max = *std::max_element(collision_counts.begin(), collision_counts.end());
int max = *llvm::max_element(collision_counts);
CARBON_CHECK(max ==
collision_counts[collision_map[bits_and_indices.back().index]]);
return {.total = total, .median = median, .max = max};
Expand Down Expand Up @@ -672,11 +671,9 @@ auto AllByteStringsHashedAndSorted() {
hashes.push_back({HashValue(s, TestSeed), s});
}

std::sort(hashes.begin(), hashes.end(),
[](const HashedString& lhs, const HashedString& rhs) {
return static_cast<uint64_t>(lhs.hash) <
static_cast<uint64_t>(rhs.hash);
});
llvm::sort(hashes, [](const HashedString& lhs, const HashedString& rhs) {
return static_cast<uint64_t>(lhs.hash) < static_cast<uint64_t>(rhs.hash);
});
CheckNoDuplicateValues(hashes);

return hashes;
Expand Down Expand Up @@ -832,11 +829,9 @@ struct SparseHashTest : ::testing::Test {
}
}

std::sort(hashes.begin(), hashes.end(),
[](const HashedString& lhs, const HashedString& rhs) {
return static_cast<uint64_t>(lhs.hash) <
static_cast<uint64_t>(rhs.hash);
});
llvm::sort(hashes, [](const HashedString& lhs, const HashedString& rhs) {
return static_cast<uint64_t>(lhs.hash) < static_cast<uint64_t>(rhs.hash);
});
CheckNoDuplicateValues(hashes);

return hashes;
Expand Down
5 changes: 3 additions & 2 deletions common/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#ifndef CARBON_COMMON_OSTREAM_H_
#define CARBON_COMMON_OSTREAM_H_

// Libraries should include this header instead of raw_ostream.

#include <concepts>
#include <ostream>
#include <type_traits>

#include "llvm/Support/raw_os_ostream.h"
// Libraries should include this header instead of raw_ostream.
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_os_ostream.h"
#include "llvm/Support/raw_ostream.h" // IWYU pragma: export

namespace Carbon {
Expand Down
8 changes: 4 additions & 4 deletions common/raw_hashtable_benchmark_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ auto DumpHashStatistics(llvm::ArrayRef<T> keys) -> void {
grouped_key_indices[hash_index].push_back(i);
}
ssize_t max_group_index =
std::max_element(grouped_key_indices.begin(), grouped_key_indices.end(),
[](const auto& lhs, const auto& rhs) {
return lhs.size() < rhs.size();
}) -
llvm::max_element(grouped_key_indices,
[](const auto& lhs, const auto& rhs) {
return lhs.size() < rhs.size();
}) -
grouped_key_indices.begin();

// If the max number of collisions on the index is less than or equal to the
Expand Down
Loading

0 comments on commit 06e401d

Please sign in to comment.