Skip to content
Merged
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
12 changes: 12 additions & 0 deletions .claude/hooks/block-manglings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

FILE_PATH=$(jq -r '.tool_input.file_path' < /dev/stdin)

case "$FILE_PATH" in
*/Resources/manglings*)
echo "BLOCKED: test resource file" >&2
exit 2
;;
esac

exit 0
14 changes: 12 additions & 2 deletions .claude/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
"PostToolUse": [
{
"matcher": "Edit|Write",
"command": "swift build 2>&1 | tail -20"
"hooks": [
{
"type": "command",
"command": "swift build 2>&1 | tail -20"
}
]
}
],
"PreToolUse": [
{
"matcher": "Edit|Write",
"command": "case \"$CLAUDE_FILE_PATH\" in */Resources/manglings*) echo 'BLOCKED: test resource file'; exit 1;; esac"
"hooks": [
{
"type": "command",
"command": ".claude/hooks/block-manglings.sh"
}
]
}
]
}
Expand Down
13 changes: 13 additions & 0 deletions Diff.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,17 @@
- [x] Integer - integer node
- [x] NegativeInteger - negative integer node
- [x] DependentGenericParamValueMarker
// Added in Swift 6.2.3
- [x] CompileTimeLiteral (renamed from CompileTimeConst)
- [x] ConstValue - @const type annotation
- [x] CoroFunctionPointer - coro function pointer thunk
- [x] DefaultOverride - default override thunk
- [x] DependentProtocolConformanceOpaque - dependent opaque protocol conformance
- [x] ImplParameterIsolated - SIL isolated parameter
- [x] ImplParameterImplicitLeading - SIL implicit leading parameter
- [x] KeyPathUnappliedMethodThunkHelper - key path unapplied method thunk
- [x] KeyPathAppliedMethodThunkHelper - key path applied method thunk
- [x] NonIsolatedCallerFunctionType - @nonisolated(nonsending) function type
- [x] OutlinedInitializeWithTakeNoValueWitness - outlined init with take no value witness
- [x] SugaredInlineArray - sugared inline array type [N of T]

80 changes: 67 additions & 13 deletions Sources/SwiftDemangle/Demangler/Demangler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,15 @@ class Demangler: Demanglerable, Mangling {
case "K":
return createWithChild(.TypedThrowsAnnotation, popTypeAndGetChild())
case "t":
return createType(createWithChild(.CompileTimeConst, popTypeAndGetChild()))
return createType(createWithChild(.CompileTimeLiteral, popTypeAndGetChild()))
case "T":
return createNode(.SendingResultFunctionType)
case "u":
return createType(createWithChild(.Sending, popTypeAndGetChild()))
case "C":
return createNode(.NonIsolatedCallerFunctionType)
case "g":
return createType(createWithChild(.ConstValue, popTypeAndGetChild()))
default:
return nil
}
Expand Down Expand Up @@ -224,6 +228,7 @@ class Demangler: Demanglerable, Mangling {
case "C": return demangleConcreteProtocolConformance()
case "D": return demangleDependentProtocolConformanceRoot()
case "I": return demangleDependentProtocolConformanceInherited()
case "O": return demangleDependentProtocolConformanceOpaque()
case "P":
return createWithChild(.ProtocolConformanceRefInTypeModule, popProtocol())
case "p":
Expand Down Expand Up @@ -620,6 +625,8 @@ class Demangler: Demanglerable, Mangling {
Ty = createNode(.BuiltinTypeName, .BUILTIN_TYPE_NAME_PACKINDEX)
case "T":
Ty = createNode(.BuiltinTupleType)
case "A":
Ty = createNode(.BuiltinTypeName, .BUILTIN_TYPE_NAME_IMPLICITACTOR)
default:
return nil
}
Expand Down Expand Up @@ -745,6 +752,12 @@ class Demangler: Demanglerable, Mangling {
let nested = popDependentProtocolConformance()
return createWithChildren(.DependentProtocolConformanceAssociated, nested, associatedConformance, index)
}

func demangleDependentProtocolConformanceOpaque() -> Node? {
let type = popNode(.Type)
let conformance = popDependentProtocolConformance()
return createWithChildren(.DependentProtocolConformanceOpaque, conformance, type)
}

func demangleDependentConformanceIndex() -> Node? {
let index = demangleIndex()
Expand Down Expand Up @@ -958,6 +971,16 @@ class Demangler: Demanglerable, Mangling {
}
return createNode(.ImplParameterSending, "sending")
}

func demangleImplParameterIsolated() -> Node? {
if !nextIf("I") { return nil }
return createNode(.ImplParameterIsolated, "isolated")
}

func demangleImplParameterImplicitLeading() -> Node? {
if !nextIf("L") { return nil }
return createNode(.ImplParameterImplicitLeading, "sil_implicit_leading_param")
}

func demangleImplParameterResultDifferentiability() -> Node? {
// Empty string represents default differentiability.
Expand Down Expand Up @@ -1095,9 +1118,13 @@ class Demangler: Demanglerable, Mangling {
if nextIf("H") {
type.addChild(createNode(.ImplFunctionAttribute, "@async"))
}


if nextIf("T") {
type.addChild(createNode(.ImplSendingResult))
}

addChild(type, GenSig)

var NumTypesToAdd = 0
var Param: Node?
while let param = demangleImplParamConvention(.ImplParameter) {
Expand All @@ -1109,13 +1136,15 @@ class Demangler: Demanglerable, Mangling {
if let Sending = demangleImplParameterSending() {
Param = addChild(Param, Sending)
}
if let Isolated = demangleImplParameterIsolated() {
Param = addChild(Param, Isolated)
}
if let ImplicitLeading = demangleImplParameterImplicitLeading() {
Param = addChild(Param, ImplicitLeading)
}
NumTypesToAdd += 1
}

if nextIf("T") {
type.addChild(createNode(.ImplSendingResult))
}

var Result: Node?
while let result = demangleImplResultConvention(.ImplResult) {
type = addChild(type, result)
Expand Down Expand Up @@ -1492,8 +1521,15 @@ class Demangler: Demanglerable, Mangling {
case"f":
return demangleFunctionSpecialization()
case "K", "k":
let nodeKind: Node.Kind = c == "K" ? .KeyPathGetterThunkHelper : .KeyPathSetterThunkHelper

let nodeKind: Node.Kind
if nextIf("mu") {
nodeKind = .KeyPathUnappliedMethodThunkHelper
} else if nextIf("MA") {
nodeKind = .KeyPathAppliedMethodThunkHelper
} else {
nodeKind = c == "K" ? .KeyPathGetterThunkHelper : .KeyPathSetterThunkHelper
}

let isSerialized = nextIf("q")

var types: [Node] = []
Expand Down Expand Up @@ -1633,6 +1669,8 @@ class Demangler: Demanglerable, Mangling {
switch (nextChar()) {
case "b": return createNode(.BackDeploymentThunk)
case "B": return createNode(.BackDeploymentFallback)
case "c": return createNode(.CoroFunctionPointer)
case "d": return createNode(.DefaultOverride)
case "S": return createNode(.HasSymbolQuery)
default:
return nil
Expand Down Expand Up @@ -2041,6 +2079,11 @@ class Demangler: Demanglerable, Mangling {
return createWithChildren(.BaseWitnessTableAccessor, Conf, ProtoTy)
case "O":
switch nextChar() {
case "B":
if let sig = popNode(.DependentGenericSignature) {
return createWithChildren(.OutlinedInitializeWithTakeNoValueWitness, popNode(.Type), sig)
}
return createWithChild(.OutlinedInitializeWithTakeNoValueWitness, popNode(.Type))
case "C":
if let sig = popNode(.DependentGenericSignature) {
return createWithChildren(.OutlinedInitializeWithCopyNoValueWitness, popNode(.Type), sig)
Expand Down Expand Up @@ -2274,6 +2317,10 @@ class Demangler: Demanglerable, Mangling {
return createType(createWithChildren(.SugaredDictionary, key, value))
case "p":
return createType(createWithChild(.SugaredParen, popNode(.Type)))
case "A":
let element = popNode(.Type)
let count = popNode(.Type)
return createType(createWithChildren(.SugaredInlineArray, count, element))
default:
return nil
}
Expand Down Expand Up @@ -3040,9 +3087,12 @@ class Demangler: Demanglerable, Mangling {
ClangType = demangleClangType()
}
addChild(FuncType, ClangType)
addChild(FuncType, popNode(.GlobalActorFunctionType))
addChild(FuncType, popNode(.IsolatedAnyFunctionType))
addChild(FuncType, popNode(.SendingResultFunctionType))
addChild(FuncType, popNode({ kind in
kind == .GlobalActorFunctionType ||
kind == .IsolatedAnyFunctionType ||
kind == .NonIsolatedCallerFunctionType
}))
addChild(FuncType, popNode(.DifferentiableFunctionType))
addChild(FuncType, popNode({ kind in
return kind == .ThrowsAnnotation ||
Expand Down Expand Up @@ -3083,13 +3133,16 @@ class Demangler: Demanglerable, Mangling {
}

var FirstChildIdx = 0
if FuncType.getChild(FirstChildIdx).getKind() == .SendingResultFunctionType {
++FirstChildIdx
}
if FuncType.getChild(FirstChildIdx).getKind() == .GlobalActorFunctionType {
++FirstChildIdx
}
if FuncType.getChild(FirstChildIdx).getKind() == .IsolatedAnyFunctionType {
++FirstChildIdx
}
if FuncType.getChild(FirstChildIdx).getKind() == .SendingResultFunctionType {
if FuncType.getChild(FirstChildIdx).getKind() == .NonIsolatedCallerFunctionType {
++FirstChildIdx
}
if FuncType.getChild(FirstChildIdx).getKind() == .DifferentiableFunctionType {
Expand Down Expand Up @@ -3302,7 +3355,8 @@ class Demangler: Demanglerable, Mangling {
.PackProtocolConformance,
.DependentProtocolConformanceRoot,
.DependentProtocolConformanceInherited,
.DependentProtocolConformanceAssociated:
.DependentProtocolConformanceAssociated,
.DependentProtocolConformanceOpaque:
return true
default:
return false
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftDemangle/Demangler/Mangling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extension Mangling {
"_T0", // Swift 4
"$S", "_$S", // Swift 4.*
"$s", "_$s", // Swift 5+.*
"$e", "_$e", // Embedded Swift
"@__swiftmacro_" // Swift 5+ for filenames
]
for prefix in prefixes where mangled.hasPrefix(prefix){
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftDemangle/Node/Names.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ extension String {
static let BUILTIN_TYPE_NAME_WORD = "Builtin.Word"
/// The name of the Builtin type for PackIndex
static let BUILTIN_TYPE_NAME_PACKINDEX = "Builtin.PackIndex"
/// The name of the Builtin type for ImplicitActor
static let BUILTIN_TYPE_NAME_IMPLICITACTOR = "Builtin.ImplicitActor"
}
30 changes: 28 additions & 2 deletions Sources/SwiftDemangle/Node/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ extension Node {
.SugaredArray,
.SugaredDictionary,
.SugaredParen,
.SugaredInlineArray,
.Integer,
.NegativeInteger:
return true
Expand Down Expand Up @@ -471,11 +472,19 @@ extension Node {
.Initializer,
.Isolated,
.Sending,
.CompileTimeConst,
.CompileTimeLiteral,
.ConstValue,
.CoroFunctionPointer,
.DefaultOverride,
.DependentProtocolConformanceOpaque,
.ImplParameterIsolated,
.ImplParameterImplicitLeading,
.PropertyWrapperBackingInitializer,
.PropertyWrapperInitFromProjectedValue,
.KeyPathGetterThunkHelper,
.KeyPathSetterThunkHelper,
.KeyPathUnappliedMethodThunkHelper,
.KeyPathAppliedMethodThunkHelper,
.KeyPathEqualsThunkHelper,
.KeyPathHashThunkHelper,
.LazyProtocolWitnessTableAccessor,
Expand Down Expand Up @@ -591,6 +600,7 @@ extension Node {
.DifferentiableFunctionType,
.GlobalActorFunctionType,
.IsolatedAnyFunctionType,
.NonIsolatedCallerFunctionType,
.SendingResultFunctionType,
.AsyncAnnotation,
.ThrowsAnnotation,
Expand All @@ -604,6 +614,7 @@ extension Node {
.OutlinedRetain,
.OutlinedRelease,
.OutlinedInitializeWithTake,
.OutlinedInitializeWithTakeNoValueWitness,
.OutlinedInitializeWithCopy,
.OutlinedAssignWithTake,
.OutlinedAssignWithCopy,
Expand Down Expand Up @@ -1243,7 +1254,7 @@ extension Node {

// Added in Swift 5.6
case AccessibleFunctionRecord
case CompileTimeConst
case CompileTimeLiteral

// Added in Swift 5.7
case BackDeploymentThunk
Expand Down Expand Up @@ -1279,6 +1290,19 @@ extension Node {
case Integer
case NegativeInteger
case DependentGenericParamValueMarker

// Added in Swift 6.2.3
case ConstValue
case CoroFunctionPointer
case DefaultOverride
case DependentProtocolConformanceOpaque
case ImplParameterIsolated
case ImplParameterImplicitLeading
case KeyPathUnappliedMethodThunkHelper
case KeyPathAppliedMethodThunkHelper
case NonIsolatedCallerFunctionType
case OutlinedInitializeWithTakeNoValueWitness
case SugaredInlineArray

public func `in`(_ kinds: Self...) -> Bool {
kinds.contains(self)
Expand Down Expand Up @@ -1564,6 +1588,8 @@ extension Node.Kind {
.AccessibleFunctionRecord,
.BackDeploymentThunk,
.BackDeploymentFallback,
.CoroFunctionPointer,
.DefaultOverride,
.HasSymbolQuery,
]

Expand Down
Loading