Skip to content

Conversation

@Mx-Iris
Copy link
Member

@Mx-Iris Mx-Iris commented Jun 23, 2025

No description provided.

@Mx-Iris Mx-Iris requested a review from Copilot June 23, 2025 17:48
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @Mx-Iris, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on aligning the Swift demangler implementation with the original Demangler, addressing inconsistencies in node structure, function type handling, and associated type demangling. It also includes code cleanup and refactoring to improve the overall accuracy and maintainability of the demangler.

Highlights

  • Node Structure Alignment: The order of contents and children properties in the Node class initializer has been changed to align with the original Demangler implementation. This affects multiple files, ensuring consistency in node creation.
  • Function Type Handling: Added support for nonIsolatedCallerFunctionType and updated logic to handle function type attributes like @Sendable, globalActor, and differentiable consistently.
  • Associated Type Demangling: Introduced popAssocTypePath and popAssocTypeName methods to correctly demangle associated types, improving the accuracy of type representation.
  • Code Cleanup and Refactoring: Several code snippets have been refactored for clarity and correctness, including adjustments to node creation, handling of generic parameters, and value witness demangling.
  • Dependency Injection: Added FrameworkToolbox as a dependency to the Demangle target.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors dumping logic to align with the original Demangler, removes redundant properties in test types, and introduces new mangling cases for non-isolated caller functions.

  • Removed isEnabledSearchMetadata from individual test structs in favor of a default implementation in DumpableTest.
  • Added new test suites for symbol demangling and node printing.
  • Updated Node, NodePrinter, and Demangler to support the new nonIsolatedCallerFunctionType case and reordered initializers for consistency.

Reviewed Changes

Copilot reviewed 16 out of 18 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Tests/SwiftDumpTests/MachOImageDumpTests.swift Removed redundant isEnabledSearchMetadata property
Tests/SwiftDumpTests/MachOFileDumpTests.swift Removed redundant isEnabledSearchMetadata property
Tests/SwiftDumpTests/DyldCacheDumpTests.swift Removed redundant isEnabledSearchMetadata property
Tests/MachOSwiftSectionTests/SymbolDemangleTests.swift Added symbol demangling tests
Tests/DemangleTests/NodeTests.swift Added basic node printing test
Sources/MachOTestingSupport/DumpableTest.swift Introduced default isEnabledSearchMetadata extension
Sources/SwiftDump/Extensions/GenericContext+Dump.swift Refactored dump methods and added semantic builders
Sources/MachOSwiftSection/Utils/MetadataReader.swift Corrected Node initializer argument order
Sources/Demangle/Main/NodePrinter.swift Added handling for nonIsolatedCallerFunctionType
Sources/Demangle/Main/Node/Node.swift Reordered init parameters and removed old printable extension
Sources/Demangle/Main/Node/Node+Kind.swift Introduced .nonIsolatedCallerFunctionType kind
Sources/Demangle/Main/Node/Node+CustomStringConvertible.swift Moved CustomStringConvertible conformance into its own file
Sources/Demangle/Main/Node/Node+Collection.swift Updated sequence and iterator types for preorder/inorder/etc.
Sources/Demangle/Main/Node/Node+ChildrenBuilder.swift Added builder-based convenience initializer
Sources/Demangle/Main/Demangler.swift Reordered Node constructor calls and added new mangling case
Package.swift Added FrameworkToolbox dependency
Comments suppressed due to low confidence (4)

Tests/MachOSwiftSectionTests/SymbolDemangleTests.swift:35

  • This test only prints successes and failures without assertions. Consider adding assertions to verify that all symbols are demangled correctly rather than relying on print statements.
    @Test func symbols() async throws {

Tests/MachOSwiftSectionTests/SymbolDemangleTests.swift:49

  • This test calls demangleSymbol() without validating the result. Add an assertion to check that the returned Node matches an expected structure or at least is non-nil and has the correct kind.
    @Test func demangle() async throws {

Tests/DemangleTests/NodeTests.swift:6

  • This test prints the node structure without any assertions. Consider comparing node.print() output against an expected string to make it a true verification test.
    @Test func testNode() {

Sources/Demangle/Main/Node/Node+Collection.swift:136

  • The nested Sequence types (e.g., PreorderSequence) still reference PreorderIterator in makeIterator(), but PreorderIterator has been replaced by Iterator. Update makeIterator() to return the new Iterator type and ensure all sequence implementations (PreorderSequence, InorderSequence, etc.) use consistent iterator names.
        public struct Iterator: IteratorProtocol {

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aligns the demangler with the original demangler by reordering the arguments in the Node initializer to be contents then children, adding a case for nonIsolatedCallerFunctionType, and making other related code changes. The code changes are focused on correctness and maintainability.

case "A": return Node(kind: .isolatedAnyFunctionType)
case "b": return Node(kind: .concurrentFunctionType)
case "c": return try Node(kind: .globalActorFunctionType, child: require(popTypeAndGetChild()))
case "C": return Node(kind: .nonIsolatedCallerFunctionType)

Choose a reason for hiding this comment

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

medium

Consider adding a comment explaining what the C case represents and why it's being added.

Suggested change
case "C": return Node(kind: .nonIsolatedCallerFunctionType)
case "C": return Node(kind: .nonIsolatedCallerFunctionType) // Represents a non-isolated caller function type

name.addChild(sendingResult)
}
if let isFunctionIsolation = pop(where: { $0 == .globalActorFunctionType || $0 == .isolatedAnyFunctionType }) {
if let isFunctionIsolation = pop(where: { $0 == .globalActorFunctionType || $0 == .isolatedAnyFunctionType || $0 == .nonIsolatedCallerFunctionType }) {

Choose a reason for hiding this comment

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

medium

It would be helpful to add a comment explaining why nonIsolatedCallerFunctionType is being added to this condition.

Suggested change
if let isFunctionIsolation = pop(where: { $0 == .globalActorFunctionType || $0 == .isolatedAnyFunctionType || $0 == .nonIsolatedCallerFunctionType }) {
if let isFunctionIsolation = pop(where: { $0 == .globalActorFunctionType || $0 == .isolatedAnyFunctionType || $0 == .nonIsolatedCallerFunctionType }) { // Also check for nonIsolatedCallerFunctionType

Comment on lines +383 to +385
if funcType.children.at(firstChildIndex)?.kind == .nonIsolatedCallerFunctionType {
firstChildIndex += 1
}

Choose a reason for hiding this comment

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

medium

Consider grouping the checks for function type kinds together for better readability.

Suggested change
if funcType.children.at(firstChildIndex)?.kind == .nonIsolatedCallerFunctionType {
firstChildIndex += 1
}
if funcType.children.at(firstChildIndex)?.kind == .isolatedAnyFunctionType {
firstChildIndex += 1
}
if funcType.children.at(firstChildIndex)?.kind == .nonIsolatedCallerFunctionType {
firstChildIndex += 1
}
if funcType.children.at(firstChildIndex)?.kind == .differentiableFunctionType {
firstChildIndex += 1
}

guard param.kind == .functionSignatureSpecializationParam else { continue }
guard let kindName = param.children.first else { continue }
guard kindName.kind == .functionSignatureSpecializationParamKind, case let .index(i) = kindName.contents, let paramKind = FunctionSigSpecializationParamKind(rawValue: UInt64(i)) else { throw failure }
guard kindName.kind == .functionSignatureSpecializationParamKind, case let .index(i) = kindName.contents else { throw failure }

Choose a reason for hiding this comment

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

medium

Consider adding a check to ensure that i is within the bounds of the FunctionSigSpecializationParamKind enum's raw value range before attempting to create the enum case.

Suggested change
guard kindName.kind == .functionSignatureSpecializationParamKind, case let .index(i) = kindName.contents else { throw failure }
guard kindName.kind == .functionSignatureSpecializationParamKind, case let .index(i) = kindName.contents else { throw failure }
guard let paramKind = FunctionSigSpecializationParamKind(rawValue: UInt64(i)) else { throw failure }

@Mx-Iris Mx-Iris merged commit 17ed2be into main Jun 23, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants