@@ -6,7 +6,7 @@ import MachOSwiftSection
66import  SwiftDump
77import  Semantic
88
9- struct  DumpCommand :  AsyncParsableCommand  { 
9+ final   actor  DumpCommand :  AsyncParsableCommand  { 
1010    static  let  configuration :  CommandConfiguration  =  . init( 
1111        commandName:  " dump " , 
1212        abstract:  " Dump Swift information from a Mach-O file or dyld shared cache. " , 
@@ -35,8 +35,7 @@ struct DumpCommand: AsyncParsableCommand {
3535    @Option ( name:  . shortAndLong,  help:  " The color scheme for the output. " )  
3636    var  colorScheme :  SemanticColorScheme  =  . none
3737
38-     @MainActor  
39-     mutating  func  run( )  async  throws  { 
38+     func  run( )  async  throws  { 
4039        let  machOFile  =  try MachOFile . load ( options:  machOOptions) 
4140
4241        if  searchMetadata { 
@@ -65,40 +64,36 @@ struct DumpCommand: AsyncParsableCommand {
6564    } 
6665
6766    @MainActor  
68-     private  mutating   func  dumpTypes( using options:  DemangleOptions ,  in machO:  MachOFile )  async  throws  { 
67+     private  func  dumpTypes( using options:  DemangleOptions ,  in machO:  MachOFile )  async  throws  { 
6968        let  typeContextDescriptors  =  try . swift. typeContextDescriptors
7069
7170        for  typeContextDescriptor  in  typeContextDescriptors { 
7271            switch  typeContextDescriptor { 
7372            case  . type( let  typeContextDescriptorWrapper) : 
7473                switch  typeContextDescriptorWrapper { 
7574                case  . enum( let  enumDescriptor) : 
76-                     do  { 
77-                         let  enumType  =  try Enum ( descriptor:  enumDescriptor,  in:  machO) 
78-                         try dumpOrPrint ( enumType. dump ( using:  options,  in:  machO) ) 
79-                     }  catch  { 
80-                         dumpError ( error) 
75+                     await  performDump  { 
76+                         try Enum ( descriptor:  enumDescriptor,  in:  machO) . dump ( using:  options,  in:  machO) 
8177                    } 
8278                case  . struct( let  structDescriptor) : 
83-                     do  { 
84-                         let  structType  =  try Struct ( descriptor:  structDescriptor,  in:  machO) 
85-                         try dumpOrPrint ( structType. dump ( using:  options,  in:  machO) ) 
86-                         if  let  metadata =  try ? . metadata ( for:  structDescriptor)  as  StructMetadata ? { 
87-                             try dumpOrPrint ( metadata. fieldOffsets ( for:  structDescriptor,  in:  machO) ) 
88-                         } 
89-                     }  catch  { 
90-                         dumpError ( error) 
79+                     await  performDump  { 
80+                         try Struct ( descriptor:  structDescriptor,  in:  machO) . dump ( using:  options,  in:  machO) 
9181                    } 
9282
83+                     if let  metadata:  StructMetadata  =  try await  metadataFinder? . metadata ( for:  structDescriptor)  { 
84+                         await  performDump  { 
85+                             try . fieldOffsets ( for:  structDescriptor,  in:  machO) 
86+                         } 
87+                     } 
9388                case . class ( let class Descriptor) : 
94-                     do  { 
95-                         let  classType  =  try Class ( descriptor:  classDescriptor,  in:  machO) 
96-                         try dumpOrPrint ( classType. dump ( using:  options,  in:  machO) ) 
97-                         if  let  metadata =  try ? . metadata ( for:  classDescriptor)  as  ClassMetadataObjCInterop ? { 
98-                             try dumpOrPrint ( metadata. fieldOffsets ( for:  classDescriptor,  in:  machO) ) 
89+                     await  performDump  { 
90+                         try Class ( descriptor:  classDescriptor,  in:  machO) . dump ( using:  options,  in:  machO) 
91+                     } 
92+ 
93+                     if let metadata =  try await  metadataFinder? . metadata ( for:  classDescriptor)  as  ClassMetadataObjCInterop ? { 
94+                         await  performDump  { 
95+                             try . fieldOffsets ( for:  classDescriptor,  in:  machO) 
9996                        } 
100-                     }  catch  { 
101-                         dumpError ( error) 
10297                    } 
10398                } 
10499            default : 
@@ -108,65 +103,63 @@ struct DumpCommand: AsyncParsableCommand {
108103    } 
109104
110105    @MainActor  
111-     private  mutating   func  dumpAssociatedTypes( using options:  DemangleOptions ,  in machO:  MachOFile )  async  throws  { 
106+     private  func  dumpAssociatedTypes( using options:  DemangleOptions ,  in machO:  MachOFile )  async  throws  { 
112107        let  associatedTypeDescriptors  =  try . swift. associatedTypeDescriptors
113108        for  associatedTypeDescriptor  in  associatedTypeDescriptors { 
114-             do  { 
115-                 try dumpOrPrint ( AssociatedType ( descriptor:  associatedTypeDescriptor,  in:  machO) . dump ( using:  options,  in:  machO)  as  SemanticString ) 
116-             }  catch  { 
117-                 dumpError ( error) 
109+             await  performDump  { 
110+                 try AssociatedType ( descriptor:  associatedTypeDescriptor,  in:  machO) . dump ( using:  options,  in:  machO) 
118111            } 
119112        } 
120113    } 
121114
122115    @MainActor  
123-     private  mutating   func  dumpProtocols( using options:  DemangleOptions ,  in machO:  MachOFile )  async  throws  { 
116+     private  func  dumpProtocols( using options:  DemangleOptions ,  in machO:  MachOFile )  async  throws  { 
124117        let  protocolDescriptors  =  try . swift. protocolDescriptors
125118        for  protocolDescriptor  in  protocolDescriptors { 
126-             do  { 
127-                 try dumpOrPrint ( Protocol ( descriptor:  protocolDescriptor,  in:  machO) . dump ( using:  options,  in:  machO) ) 
128-             }  catch  { 
129-                 dumpError ( error) 
119+             await  performDump  { 
120+                 try Protocol ( descriptor:  protocolDescriptor,  in:  machO) . dump ( using:  options,  in:  machO) 
130121            } 
131122        } 
132123    } 
133124
134125    @MainActor  
135-     private  mutating   func  dumpProtocolConformances( using options:  DemangleOptions ,  in machO:  MachOFile )  async  throws  { 
126+     private  func  dumpProtocolConformances( using options:  DemangleOptions ,  in machO:  MachOFile )  async  throws  { 
136127        let  protocolConformanceDescriptors  =  try . swift. protocolConformanceDescriptors
137128
138129        for  protocolConformanceDescriptor  in  protocolConformanceDescriptors { 
139-             do  { 
140-                 try dumpOrPrint ( ProtocolConformance ( descriptor:  protocolConformanceDescriptor,  in:  machO) . dump ( using:  options,  in:  machO) ) 
141-             }  catch  { 
142-                 dumpError ( error) 
130+             await  performDump  { 
131+                 try ProtocolConformance ( descriptor:  protocolConformanceDescriptor,  in:  machO) . dump ( using:  options,  in:  machO) 
143132            } 
144133        } 
145134    } 
146135
147-     private  mutating  func  dumpOrPrint< Value:  CustomStringConvertible > ( _ value:  Value )  { 
148-         dumpOrPrint ( value. description) 
136+     private  func  performDump( @SemanticStringBuilder   _ action:  ( )  async  throws  ->  SemanticString )  async  { 
137+         do  { 
138+             try await  dumpOrPrint ( action ( ) ) 
139+         }  catch  { 
140+             dumpError ( error) 
141+         } 
142+     } 
143+ 
144+     private  func  dumpError( _ error:  Swift . Error )  { 
145+         dumpOrPrint ( SemanticString ( components:  Error ( error. localizedDescription) ) ) 
149146    } 
150147
151-     private  mutating   func  dumpOrPrint( _ string :   String )  { 
148+     private  func  dumpOrPrint( _ semanticString :   SemanticString )  { 
152149        if  outputPath !=  nil  { 
153-             dumpedString. append ( string) 
150+             dumpedString. append ( semanticString . string) 
154151            dumpedString. append ( " \n " ) 
155152        }  else  { 
156-             print ( string) 
153+             print ( semanticString . components . map   {  $0 . string. withColor ( for :  $0 . type ,  colorScheme :  colorScheme )   } . joined ( ) ) 
157154        } 
158155    } 
159156
160-     private  mutating  func  dumpError( _ error:  Swift . Error )  { 
161-         dumpOrPrint ( SemanticString ( components:  Error ( error. localizedDescription) ) ) 
162-     } 
163-     
164-     private  mutating  func  dumpOrPrint( _ semanticString:  SemanticString )  { 
157+     private  func  dumpOrPrint( _ string:  String )  { 
165158        if  outputPath !=  nil  { 
166-             dumpedString. append ( semanticString . string) 
159+             dumpedString. append ( string) 
167160            dumpedString. append ( " \n " ) 
168161        }  else  { 
169-             print ( semanticString . components . map   {  $0 . string. withColor ( for :  $0 . type ,  colorScheme :  colorScheme )   } . joined ( ) ) 
162+             print ( string) 
170163        } 
171164    } 
172165} 
0 commit comments