Skip to content

Commit 909f40b

Browse files
authored
Merge pull request github#12918 from github/sashabu/absl
Swift: Fix some TODOs with Abseil.
2 parents 84ddfe9 + c88f9bf commit 909f40b

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

misc/bazel/workspace.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,13 @@ def codeql_workspace(repository_name = "codeql"):
4343
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
4444
],
4545
)
46+
47+
maybe(
48+
repo_rule = http_archive,
49+
name = "absl",
50+
sha256 = "cec2e5bf780532bd0ac672eb8d43c0f8bbe84ca5df8718320184034b7f59a398",
51+
urls = [
52+
"https://github.com/abseil/abseil-cpp/archive/d2c5297a3c3948de765100cb7e5cccca1210d23c.tar.gz",
53+
],
54+
strip_prefix = "abseil-cpp-d2c5297a3c3948de765100cb7e5cccca1210d23c",
55+
)

swift/extractor/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ swift_cc_binary(
1616
"//swift/extractor/remapping",
1717
"//swift/extractor/translators",
1818
"//swift/third_party/swift-llvm-support",
19+
"@absl//absl/strings",
1920
],
2021
)
2122

swift/extractor/main.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <swift/FrontendTool/FrontendTool.h>
1010
#include <swift/Basic/InitializeSwiftModules.h>
1111

12+
#include "absl/strings/str_join.h"
13+
1214
#include "swift/extractor/SwiftExtractor.h"
1315
#include "swift/extractor/infra/TargetDomains.h"
1416
#include "swift/extractor/remapping/SwiftFileInterception.h"
@@ -184,18 +186,13 @@ codeql::SwiftExtractorConfiguration configure(int argc, char** argv) {
184186
return configuration;
185187
}
186188

187-
// TODO: use `absl::StrJoin` or `boost::algorithm::join`
188189
static auto argDump(int argc, char** argv) {
189-
std::string ret;
190-
for (auto arg = argv + 1; arg < argv + argc; ++arg) {
191-
ret += *arg;
192-
ret += ' ';
190+
if (argc < 2) {
191+
return ""s;
193192
}
194-
ret.pop_back();
195-
return ret;
193+
return absl::StrJoin(argv + 1, argv + argc, " ");
196194
}
197195

198-
// TODO: use `absl::StrJoin` or `boost::algorithm::join`
199196
static auto envDump(char** envp) {
200197
std::string ret;
201198
for (auto env = envp; *env; ++env) {

swift/extractor/trap/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ swift_cc_library(
5050
deps = [
5151
"//swift/extractor/infra/file",
5252
"//swift/extractor/infra/log",
53+
"@absl//absl/numeric:bits",
5354
],
5455
)

swift/extractor/trap/TrapLabel.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <iostream>
66
#include <string>
77
#include <vector>
8+
#include "absl/numeric/bits.h"
89
#include <binlog/binlog.hpp>
910
#include <cmath>
1011
#include <charconv>
@@ -53,10 +54,9 @@ class UntypedTrapLabel {
5354

5455
private:
5556
size_t strSize() const {
56-
if (id_ == undefined) return 17; // #ffffffffffffffff
57-
if (id_ == 0) return 2; // #0
58-
// TODO: use absl::bit_width or C+20 std::bit_width instead of this ugly formula
59-
return /* # */ 1 + /* hex digits */ static_cast<size_t>(ceil(log2(id_ + 1) / 4));
57+
if (id_ == 0) return 2; // #0
58+
// Number of hex digits is ceil(bit_width(id) / 4), but C++ integer division can only do floor.
59+
return /* # */ 1 + /* hex digits */ 1 + (absl::bit_width(id_) - 1) / 4;
6060
}
6161
};
6262

0 commit comments

Comments
 (0)