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

feat(demangle): Update Swift demangler to Swift 5.10 #854

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion symbolic-demangle/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
"vendor/swift/lib/Demangling/Punycode.cpp",
"vendor/swift/lib/Demangling/Remangler.cpp",
])
.flag_if_supported("-std=c++14")
.flag_if_supported("-std=c++17")
.flag("-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1")
.warnings(false)
.include("vendor/swift/include")
Expand Down
5 changes: 3 additions & 2 deletions symbolic-demangle/src/swiftdemangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ extern "C" int symbolic_demangle_swift(const char *symbol,

if (features < SYMBOLIC_SWIFT_FEATURE_ALL) {
opts = swift::Demangle::DemangleOptions::SimplifiedUIDemangleOptions();
bool return_type = features & SYMBOLIC_SWIFT_FEATURE_RETURN_TYPE;
// bool return_type = features & SYMBOLIC_SWIFT_FEATURE_RETURN_TYPE;
bool argument_types = features & SYMBOLIC_SWIFT_FEATURE_PARAMETERS;

opts.ShowFunctionReturnType = return_type;
// No ShowFunctionReturnType property in DemangleOptions any more
// opts.ShowFunctionReturnType = return_type;
opts.ShowFunctionArgumentTypes = argument_types;
}

Expand Down
3 changes: 3 additions & 0 deletions symbolic-demangle/tests/test_swift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,8 @@ fn test_demangle_swift_no_args() {

// Swift 5.5.1
"$s10Speediness17NetworkQualityCLIO3run10sequentialAC6ResultVSb_tYaKFZTf4nd_nTQ0_" => "(1) await resume partial function for specialized static NetworkQualityCLI.run",

// Swift 5.10
"_$s16HDFileDownloader14HDFDURLSessionC11postRequest11request_url6params12headerFields9callBlockySS_SDySSypGSDyS2SGy10Foundation4DataVSg_s5Error_pSgtctFyAN_So13NSURLResponseCSgAPtYbcfU_TATm" => "partial apply for closure #1 @Sendable (Foundation.Data?, __C.NSURLResponse?, Swift.Error?) -> () in HDFileDownloader.HDFDURLSession.postRequest(request_url: Swift.String, params: [Swift.String : Any], headerFields: [Swift.String : Swift.String], callBlock: (Foundation.Data?, Swift.Error?) -> ()) -> ()",
});
}
174 changes: 132 additions & 42 deletions symbolic-demangle/vendor/swift/1-arguments.patch
Original file line number Diff line number Diff line change
@@ -1,45 +1,135 @@
commit 43fca7dd2617ac93f338b5257a2e57c43dcb8154
Author: Sebastian Zivota <[email protected]>
Date: Thu Dec 2 16:15:35 2021 +0100
commit eaae91fd522031a2aaafed367414f942f1c83d22
Author: fantexi023 <[email protected]>
Date: Thu Jul 18 17:04:45 2024 +0800

Apply patch
pass cargo build

diff --git a/symbolic-demangle/vendor/swift/include/swift/Demangling/Demangle.h b/symbolic-demangle/vendor/swift/include/swift/Demangling/Demangle.h
index db32dbd..f48e1c2 100644
--- a/symbolic-demangle/vendor/swift/include/swift/Demangling/Demangle.h
+++ b/symbolic-demangle/vendor/swift/include/swift/Demangling/Demangle.h
@@ -59,6 +59,7 @@ struct DemangleOptions {
bool ShortenArchetype = false;
bool ShowPrivateDiscriminators = true;
bool ShowFunctionArgumentTypes = true;
+ bool ShowFunctionReturnType = true;
bool DisplayDebuggerGeneratedModule = true;
Copy link
Member

Choose a reason for hiding this comment

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

You mentioned this in the changed swiftdemangle.cpp file. This option is indeed not part of upstream Swift, but we patched that in via this small patch here.

Copy link
Author

@fantexi023 fantexi023 Jul 19, 2024

Choose a reason for hiding this comment

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

Thank you for your reply.
I also saw that the CI process gave five errors, among which the problem of Rust Test on macos-latest should be that the SWIFT_STDLIB_HAS_TYPE_PRINTING did not take effect, which may be caused by the passing exception of CMakeLists.txt. I cancelled the restriction of SWIFT_STDLIB_HAS_TYPE_PRINTING this macro locally. The other four problems correspond to the same error, but I did not encounter this error on my own Mac.

Copy link
Author

Choose a reason for hiding this comment

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

You mentioned this in the changed swiftdemangle.cpp file. This option is indeed not part of upstream Swift, but we patched that in via this small patch here.

yeah, I do understand your explanation for ShowFunctionReturnType. TXS!

bool DisplayStdlibModule = true;
bool DisplayObjCModule = true;
@@ -90,6 +91,7 @@ struct DemangleOptions {
Opt.ShortenArchetype = true;
Opt.ShowPrivateDiscriminators = false;
Opt.ShowFunctionArgumentTypes = false;
+ Opt.ShowFunctionReturnType = false;
return Opt;
};
diff --git a/symbolic-demangle/build.rs b/symbolic-demangle/build.rs
index 4ce782eb..15246da7 100644
--- a/symbolic-demangle/build.rs
+++ b/symbolic-demangle/build.rs
@@ -15,7 +15,7 @@ fn main() {
"vendor/swift/lib/Demangling/Punycode.cpp",
"vendor/swift/lib/Demangling/Remangler.cpp",
])
- .flag_if_supported("-std=c++14")
+ .flag_if_supported("-std=c++17")
.flag("-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1")
.warnings(false)
.include("vendor/swift/include")
diff --git a/symbolic-demangle/src/swiftdemangle.cpp b/symbolic-demangle/src/swiftdemangle.cpp
index 843a2a59..85c1fecc 100644
--- a/symbolic-demangle/src/swiftdemangle.cpp
+++ b/symbolic-demangle/src/swiftdemangle.cpp
@@ -12,10 +12,11 @@ extern "C" int symbolic_demangle_swift(const char *symbol,

if (features < SYMBOLIC_SWIFT_FEATURE_ALL) {
opts = swift::Demangle::DemangleOptions::SimplifiedUIDemangleOptions();
- bool return_type = features & SYMBOLIC_SWIFT_FEATURE_RETURN_TYPE;
+ // bool return_type = features & SYMBOLIC_SWIFT_FEATURE_RETURN_TYPE;
bool argument_types = features & SYMBOLIC_SWIFT_FEATURE_PARAMETERS;

- opts.ShowFunctionReturnType = return_type;
+ // No ShowFunctionReturnType property in DemangleOptions any more
+ // opts.ShowFunctionReturnType = return_type;
opts.ShowFunctionArgumentTypes = argument_types;
}

diff --git a/symbolic-demangle/vendor/swift/include/llvm/Support/type_traits.h b/symbolic-demangle/vendor/swift/include/llvm/Support/type_traits.h
index 3fd158de..a6046de8 100644
--- a/symbolic-demangle/vendor/swift/include/llvm/Support/type_traits.h
+++ b/symbolic-demangle/vendor/swift/include/llvm/Support/type_traits.h
@@ -32,11 +32,11 @@ template <typename T> class is_integral_or_enum {

public:
static const bool value =
- !std::is_class_v<UnderlyingT> && // Filter conversion operators.
- !std::is_pointer_v<UnderlyingT> &&
- !std::is_floating_point_v<UnderlyingT> &&
- (std::is_enum_v<UnderlyingT> ||
- std::is_convertible_v<UnderlyingT, unsigned long long>);
+ !std::is_class<UnderlyingT>::value && // Filter conversion operators.
+ !std::is_pointer<UnderlyingT>::value &&
+ !std::is_floating_point<UnderlyingT>::value &&
+ (std::is_enum<UnderlyingT>::value ||
+ std::is_convertible<UnderlyingT, unsigned long long>::value);
};

/// If T is a pointer, just return it. If it is not, return T&.
@@ -45,7 +45,7 @@ struct add_lvalue_reference_if_not_pointer { using type = T &; };

template <typename T>
struct add_lvalue_reference_if_not_pointer<
- T, std::enable_if_t<std::is_pointer_v<T>>> {
+ T, std::enable_if_t<std::is_pointer<T>::value>> {
using type = T;
};

@@ -55,7 +55,7 @@ template<typename T, typename Enable = void>
struct add_const_past_pointer { using type = const T; };

template <typename T>
-struct add_const_past_pointer<T, std::enable_if_t<std::is_pointer_v<T>>> {
+struct add_const_past_pointer<T, std::enable_if_t<std::is_pointer<T>::value>> {
using type = const std::remove_pointer_t<T> *;
};

@@ -64,11 +64,27 @@ struct const_pointer_or_const_ref {
using type = const T &;
};
diff --git a/symbolic-demangle/vendor/swift/lib/Demangling/NodePrinter.cpp b/symbolic-demangle/vendor/swift/lib/Demangling/NodePrinter.cpp
index 2a9c0dc..34fa785 100644
--- a/symbolic-demangle/vendor/swift/lib/Demangling/NodePrinter.cpp
+++ b/symbolic-demangle/vendor/swift/lib/Demangling/NodePrinter.cpp
@@ -863,10 +863,11 @@ private:
if (isSendable)
Printer << "@Sendable ";

- printFunctionParameters(LabelList, node->getChild(startIndex),
- Options.ShowFunctionArgumentTypes);
+ if (Options.ShowFunctionArgumentTypes) {
+ printFunctionParameters(LabelList, node->getChild(startIndex), true);
+ }

- if (!Options.ShowFunctionArgumentTypes)
+ if (!Options.ShowFunctionReturnType)
return;

if (isAsync)
template <typename T>
-struct const_pointer_or_const_ref<T, std::enable_if_t<std::is_pointer_v<T>>> {
+struct const_pointer_or_const_ref<T,
+ std::enable_if_t<std::is_pointer<T>::value>> {
using type = typename add_const_past_pointer<T>::type;
};

namespace detail {
+/// Internal utility to detect trivial copy construction.
+template<typename T> union copy_construction_triviality_helper {
+ T t;
+ copy_construction_triviality_helper() = default;
+ copy_construction_triviality_helper(const copy_construction_triviality_helper&) = default;
+ ~copy_construction_triviality_helper() = default;
+};
+/// Internal utility to detect trivial move construction.
+template<typename T> union move_construction_triviality_helper {
+ T t;
+ move_construction_triviality_helper() = default;
+ move_construction_triviality_helper(move_construction_triviality_helper&&) = default;
+ ~move_construction_triviality_helper() = default;
+};
+
template<class T>
union trivial_helper {
T t;
@@ -76,6 +92,29 @@ union trivial_helper {

} // end namespace detail

+/// An implementation of `std::is_trivially_copy_constructible` since we have
+/// users with STLs that don't yet include it.
+template <typename T>
+struct is_trivially_copy_constructible
+ : std::is_copy_constructible<
+ ::llvm::detail::copy_construction_triviality_helper<T>> {};
+template <typename T>
+struct is_trivially_copy_constructible<T &> : std::true_type {};
+template <typename T>
+struct is_trivially_copy_constructible<T &&> : std::false_type {};
+
+/// An implementation of `std::is_trivially_move_constructible` since we have
+/// users with STLs that don't yet include it.
+template <typename T>
+struct is_trivially_move_constructible
+ : std::is_move_constructible<
+ ::llvm::detail::move_construction_triviality_helper<T>> {};
+template <typename T>
+struct is_trivially_move_constructible<T &> : std::true_type {};
+template <typename T>
+struct is_trivially_move_constructible<T &&> : std::true_type {};
+
+
template <typename T>
struct is_copy_assignable {
template<class F>
4 changes: 2 additions & 2 deletions symbolic-demangle/vendor/swift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This folder contains a vendored subset of the [Swift Programming Language]. The Swift library is
reduced to the demangler only to reduce the size of this package.

The current version is **Swift 5.5.1**.
The current version is **Swift 5.10**.

## Sentry Modifications

Expand All @@ -28,7 +28,7 @@ patch is maintained in `1-arguments.patch`.
4. Check out the release branch of the latest release:
```
$ cd swift
$ git checkout swift-5.5.1-RELEASE
$ git checkout swift-5.10-RELEASE
```
5. Build the complete swift project (be very patient, this may take long):
```
Expand Down
103 changes: 103 additions & 0 deletions symbolic-demangle/vendor/swift/include/llvm/ADT/ADL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//===- llvm/ADT/ADL.h - Argument dependent lookup utilities -----*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_ADT_ADL_H
#define LLVM_ADT_ADL_H

#include <type_traits>
#include <iterator>
#include <utility>

namespace llvm {

// Only used by compiler if both template types are the same. Useful when
// using SFINAE to test for the existence of member functions.
template <typename T, T> struct SameType;

namespace adl_detail {

using std::begin;

template <typename RangeT>
constexpr auto begin_impl(RangeT &&range)
-> decltype(begin(std::forward<RangeT>(range))) {
return begin(std::forward<RangeT>(range));
}

using std::end;

template <typename RangeT>
constexpr auto end_impl(RangeT &&range)
-> decltype(end(std::forward<RangeT>(range))) {
return end(std::forward<RangeT>(range));
}

using std::swap;

template <typename T>
constexpr void swap_impl(T &&lhs,
T &&rhs) noexcept(noexcept(swap(std::declval<T>(),
std::declval<T>()))) {
swap(std::forward<T>(lhs), std::forward<T>(rhs));
}

using std::size;

template <typename RangeT>
constexpr auto size_impl(RangeT &&range)
-> decltype(size(std::forward<RangeT>(range))) {
return size(std::forward<RangeT>(range));
}

} // end namespace adl_detail

/// Returns the begin iterator to \p range using `std::begin` and
/// function found through Argument-Dependent Lookup (ADL).
template <typename RangeT>
constexpr auto adl_begin(RangeT &&range)
-> decltype(adl_detail::begin_impl(std::forward<RangeT>(range))) {
return adl_detail::begin_impl(std::forward<RangeT>(range));
}

/// Returns the end iterator to \p range using `std::end` and
/// functions found through Argument-Dependent Lookup (ADL).
template <typename RangeT>
constexpr auto adl_end(RangeT &&range)
-> decltype(adl_detail::end_impl(std::forward<RangeT>(range))) {
return adl_detail::end_impl(std::forward<RangeT>(range));
}

/// Swaps \p lhs with \p rhs using `std::swap` and functions found through
/// Argument-Dependent Lookup (ADL).
template <typename T>
constexpr void adl_swap(T &&lhs, T &&rhs) noexcept(
noexcept(adl_detail::swap_impl(std::declval<T>(), std::declval<T>()))) {
adl_detail::swap_impl(std::forward<T>(lhs), std::forward<T>(rhs));
}

/// Returns the size of \p range using `std::size` and functions found through
/// Argument-Dependent Lookup (ADL).
template <typename RangeT>
constexpr auto adl_size(RangeT &&range)
-> decltype(adl_detail::size_impl(std::forward<RangeT>(range))) {
return adl_detail::size_impl(std::forward<RangeT>(range));
}

namespace detail {

template <typename RangeT>
using IterOfRange = decltype(adl_begin(std::declval<RangeT &>()));

template <typename RangeT>
using ValueOfRange =
std::remove_reference_t<decltype(*adl_begin(std::declval<RangeT &>()))>;

} // namespace detail
} // namespace llvm

#endif // LLVM_ADT_ADL_H
Loading
Loading