- 
                Notifications
    You must be signed in to change notification settings 
- Fork 11
Align with the original Demangler #14
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
Conversation
There was a problem hiding this 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 contentsandchildrenproperties in theNodeclass 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 nonIsolatedCallerFunctionTypeand updated logic to handle function type attributes like@Sendable,globalActor, anddifferentiableconsistently.
- Associated Type Demangling: Introduced popAssocTypePathandpopAssocTypeNamemethods 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 FrameworkToolboxas a dependency to theDemangletarget.
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
- 
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. ↩ 
There was a problem hiding this 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 isEnabledSearchMetadatafrom individual test structs in favor of a default implementation inDumpableTest.
- Added new test suites for symbol demangling and node printing.
- Updated Node,NodePrinter, andDemanglerto support the newnonIsolatedCallerFunctionTypecase 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 isEnabledSearchMetadataproperty | 
| Tests/SwiftDumpTests/MachOFileDumpTests.swift | Removed redundant isEnabledSearchMetadataproperty | 
| Tests/SwiftDumpTests/DyldCacheDumpTests.swift | Removed redundant isEnabledSearchMetadataproperty | 
| Tests/MachOSwiftSectionTests/SymbolDemangleTests.swift | Added symbol demangling tests | 
| Tests/DemangleTests/NodeTests.swift | Added basic node printing test | 
| Sources/MachOTestingSupport/DumpableTest.swift | Introduced default isEnabledSearchMetadataextension | 
| Sources/SwiftDump/Extensions/GenericContext+Dump.swift | Refactored dump methods and added semantic builders | 
| Sources/MachOSwiftSection/Utils/MetadataReader.swift | Corrected Nodeinitializer argument order | 
| Sources/Demangle/Main/NodePrinter.swift | Added handling for nonIsolatedCallerFunctionType | 
| Sources/Demangle/Main/Node/Node.swift | Reordered initparameters and removed old printable extension | 
| Sources/Demangle/Main/Node/Node+Kind.swift | Introduced .nonIsolatedCallerFunctionTypekind | 
| Sources/Demangle/Main/Node/Node+CustomStringConvertible.swift | Moved CustomStringConvertibleconformance 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 Nodeconstructor calls and added new mangling case | 
| Package.swift | Added FrameworkToolboxdependency | 
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 returnedNodematches 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 Sequencetypes (e.g.,PreorderSequence) still referencePreorderIteratorinmakeIterator(), butPreorderIteratorhas been replaced byIterator. UpdatemakeIterator()to return the newIteratortype and ensure all sequence implementations (PreorderSequence,InorderSequence, etc.) use consistent iterator names.
        public struct Iterator: IteratorProtocol {
There was a problem hiding this 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) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| name.addChild(sendingResult) | ||
| } | ||
| if let isFunctionIsolation = pop(where: { $0 == .globalActorFunctionType || $0 == .isolatedAnyFunctionType }) { | ||
| if let isFunctionIsolation = pop(where: { $0 == .globalActorFunctionType || $0 == .isolatedAnyFunctionType || $0 == .nonIsolatedCallerFunctionType }) { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful to add a comment explaining why nonIsolatedCallerFunctionType is being added to this condition.
| 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 | 
| if funcType.children.at(firstChildIndex)?.kind == .nonIsolatedCallerFunctionType { | ||
| firstChildIndex += 1 | ||
| } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider grouping the checks for function type kinds together for better readability.
| 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 } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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 } | 
No description provided.