Skip to content

Commit 7280f07

Browse files
authored
Merge pull request github#13336 from github/sashabu/c++20-todos
Swift: Fix some C++20 todos.
2 parents f5d6f50 + 9ec0900 commit 7280f07

File tree

7 files changed

+45
-61
lines changed

7 files changed

+45
-61
lines changed

swift/extractor/trap/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,5 @@ swift_cc_library(
5353
deps = [
5454
"//swift/extractor/infra/file",
5555
"//swift/logging",
56-
"@absl//absl/numeric:bits",
5756
],
5857
)

swift/extractor/trap/TrapLabel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#pragma once
22

3+
#include <bit>
34
#include <cassert>
45
#include <iomanip>
56
#include <iostream>
67
#include <string>
78
#include <vector>
8-
#include "absl/numeric/bits.h"
99
#include <binlog/binlog.hpp>
1010
#include <cmath>
1111
#include <charconv>
@@ -52,7 +52,7 @@ class UntypedTrapLabel {
5252
size_t strSize() const {
5353
if (id_ == 0) return 2; // #0
5454
// Number of hex digits is ceil(bit_width(id) / 4), but C++ integer division can only do floor.
55-
return /* # */ 1 + /* hex digits */ 1 + (absl::bit_width(id_) - 1) / 4;
55+
return /* # */ 1 + /* hex digits */ 1 + (std::bit_width(id_) - 1) / 4;
5656
}
5757

5858
friend bool operator!=(UntypedTrapLabel lhs, UntypedTrapLabel rhs) { return lhs.id_ != rhs.id_; }

swift/logging/SwiftDiagnostics.h

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,6 @@ struct SwiftDiagnostic {
6262

6363
std::optional<SwiftDiagnosticsLocation> location{};
6464

65-
// optional arguments can be either Severity or Visibility to set the corresponding field.
66-
// TODO(C++20) this constructor won't really be necessary anymore with designated initializers
67-
template <typename... OptionalArgs>
68-
constexpr SwiftDiagnostic(std::string_view id,
69-
std::string_view name,
70-
std::string_view action,
71-
OptionalArgs... optionalArgs)
72-
: id{id}, name{name}, action{action} {
73-
(setOptionalArg(optionalArgs), ...);
74-
}
75-
7665
// create a JSON diagnostics for this source with the given `timestamp` and Markdown `message`
7766
// A markdownMessage is emitted that includes both the message and the action to take. The id is
7867
// used to construct the source id in the form `swift/<prog name>/<id>`
@@ -94,13 +83,6 @@ struct SwiftDiagnostic {
9483

9584
private:
9685
bool has(Visibility v) const;
97-
98-
constexpr void setOptionalArg(Visibility v) { visibility = v; }
99-
constexpr void setOptionalArg(Severity s) { severity = s; }
100-
101-
// intentionally left undefined
102-
template <typename T>
103-
constexpr void setOptionalArg(T);
10486
};
10587

10688
inline constexpr SwiftDiagnostic::Visibility operator|(SwiftDiagnostic::Visibility lhs,
@@ -116,14 +98,15 @@ inline constexpr SwiftDiagnostic::Visibility operator&(SwiftDiagnostic::Visibili
11698
}
11799

118100
constexpr SwiftDiagnostic internalError{
119-
"internal-error",
120-
"Internal error",
121-
"Some or all of the Swift analysis may have failed.\n"
122-
"\n"
123-
"If the error persists, contact support, quoting the error message and describing what "
124-
"happened, or [open an issue in our open source repository][1].\n"
125-
"\n"
126-
"[1]: https://github.com/github/codeql/issues/new?labels=bug&template=ql---general.md",
127-
SwiftDiagnostic::Severity::warning,
101+
.id = "internal-error",
102+
.name = "Internal error",
103+
.action =
104+
"Some or all of the Swift analysis may have failed.\n"
105+
"\n"
106+
"If the error persists, contact support, quoting the error message and describing what "
107+
"happened, or [open an issue in our open source repository][1].\n"
108+
"\n"
109+
"[1]: https://github.com/github/codeql/issues/new?labels=bug&template=ql---general.md",
110+
.severity = SwiftDiagnostic::Severity::warning,
128111
};
129112
} // namespace codeql

swift/logging/SwiftLogging.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,14 @@
5555
#define DIAGNOSE_CRITICAL(ID, ...) DIAGNOSE_WITH_LEVEL(critical, ID, __VA_ARGS__)
5656

5757
#define CODEQL_DIAGNOSTIC_LOG_FORMAT_PREFIX "[{}] "
58-
// TODO(C++20) replace non-standard , ##__VA_ARGS__ with __VA_OPT__(,) __VA_ARGS__
5958
#define DIAGNOSE_WITH_LEVEL(LEVEL, ID, FORMAT, ...) \
6059
do { \
6160
auto _now = ::binlog::clockNow(); \
6261
const ::codeql::SwiftDiagnostic& _id = ID; \
6362
::codeql::Log::diagnose(_id, std::chrono::nanoseconds{_now}, \
64-
fmt::format(FORMAT, ##__VA_ARGS__)); \
63+
fmt::format(FORMAT __VA_OPT__(, ) __VA_ARGS__)); \
6564
LOG_WITH_LEVEL_AND_TIME(LEVEL, _now, CODEQL_DIAGNOSTIC_LOG_FORMAT_PREFIX FORMAT, \
66-
_id.abbreviation(), ##__VA_ARGS__); \
65+
_id.abbreviation() __VA_OPT__(, ) __VA_ARGS__); \
6766
} while (false)
6867

6968
// avoid calling into binlog's original macros

swift/tools/autobuilder-diagnostics/IncompatibleOs.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@
99
const std::string_view codeql::programName = "autobuilder";
1010

1111
constexpr codeql::SwiftDiagnostic incompatibleOs{
12-
"incompatible-os",
13-
"Incompatible operating system (expected macOS)",
14-
"[Change the Actions runner][1] to run on macOS.\n"
15-
"\n"
16-
"You may be able to run analysis on Linux by setting up a [manual build command][2].\n"
17-
"\n"
18-
"[1]: "
19-
"https://docs.github.com/en/actions/using-workflows/"
20-
"workflow-syntax-for-github-actions#jobsjob_idruns-on\n"
21-
"[2]: "
22-
"https://docs.github.com/en/enterprise-server/code-security/code-scanning/"
23-
"automatically-scanning-your-code-for-vulnerabilities-and-errors/"
24-
"configuring-the-codeql-workflow-for-compiled-languages#adding-build-steps-for-a-compiled-"
25-
"language",
12+
.id = "incompatible-os",
13+
.name = "Incompatible operating system (expected macOS)",
14+
.action =
15+
"[Change the Actions runner][1] to run on macOS.\n"
16+
"\n"
17+
"You may be able to run analysis on Linux by setting up a [manual build command][2].\n"
18+
"\n"
19+
"[1]: "
20+
"https://docs.github.com/en/actions/using-workflows/"
21+
"workflow-syntax-for-github-actions#jobsjob_idruns-on\n"
22+
"[2]: "
23+
"https://docs.github.com/en/enterprise-server/code-security/code-scanning/"
24+
"automatically-scanning-your-code-for-vulnerabilities-and-errors/"
25+
"configuring-the-codeql-workflow-for-compiled-languages#adding-build-steps-for-a-compiled-"
26+
"language",
2627
};
2728

2829
static codeql::Logger& logger() {

swift/xcode-autobuilder/XcodeBuildRunner.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
#include "swift/xcode-autobuilder/CustomizingBuildLink.h"
1010

1111
constexpr codeql::SwiftDiagnostic buildCommandFailed{
12-
"build-command-failed", "Detected build command failed",
13-
"Set up a [manual build command][1] or [check the logs of the autobuild step][2].\n"
14-
"\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK "\n[2]: " CHECK_LOGS_HELP_LINK};
12+
.id = "build-command-failed",
13+
.name = "Detected build command failed",
14+
.action = "Set up a [manual build command][1] or [check the logs of the autobuild step][2].\n"
15+
"\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK "\n[2]: " CHECK_LOGS_HELP_LINK};
1516

1617
static codeql::Logger& logger() {
1718
static codeql::Logger ret{"build"};

swift/xcode-autobuilder/xcode-autobuilder.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@ static constexpr std::string_view unknownType = "<unknown_target_type>";
1313

1414
const std::string_view codeql::programName = "autobuilder";
1515

16-
constexpr codeql::SwiftDiagnostic noProjectFound{"no-project-found",
17-
"No Xcode project or workspace found",
18-
"Set up a [manual build command][1].\n"
19-
"\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};
16+
constexpr codeql::SwiftDiagnostic noProjectFound{
17+
.id = "no-project-found",
18+
.name = "No Xcode project or workspace found",
19+
.action = "Set up a [manual build command][1].\n\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};
2020

2121
constexpr codeql::SwiftDiagnostic noSwiftTarget{
22-
"no-swift-target", "No Swift compilation target found",
23-
"To analyze a custom set of source files, set up a [manual build command][1].\n"
24-
"\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};
22+
.id = "no-swift-target",
23+
.name = "No Swift compilation target found",
24+
.action = "To analyze a custom set of source files, set up a [manual build "
25+
"command][1].\n\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};
2526

2627
constexpr codeql::SwiftDiagnostic spmNotSupported{
27-
"spm-not-supported", "Swift Package Manager is not supported",
28-
"Swift Package Manager builds are not currently supported by `autobuild`. Set up a [manual "
29-
"build command][1].\n"
30-
"\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};
28+
.id = "spm-not-supported",
29+
.name = "Swift Package Manager is not supported",
30+
.action = "Swift Package Manager builds are not currently supported by `autobuild`. Set up a "
31+
"[manual build command][1].\n\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};
3132

3233
static codeql::Logger& logger() {
3334
static codeql::Logger ret{"main"};

0 commit comments

Comments
 (0)