Problems dumping AST for an iOS app

I'm having trouble dumping the AST of some swift files in an iOS app using the current Swift version on master. When I use the toolchain that came with Xcode 10 it works fine, but the local build prints this error several times (once for each file):

<unknown>:0: error: this mode does not support emitting reference dependency files

As far as I can tell, this happens because swift thinks I'm using the -dump-ast and -emit-dependencies options at the same time. However, I removed -emit-dependencies from the command, as well as all other -emit-... arguments, according to instructions from this stack overflow post.

Basically, I wanted to know: is this intentional new behavior that was introduced in recent builds, and does it make it impossible to get an AST dump from an iOS app? If it's not intentional (which seems to be the case) should I file a bug?

PS: For reference, I'm trying to run the second swiftc call in the Wire iOS app. This is the command being executed:

/Users/vini/Desktop/swiftSrouce2/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-x86_64/Debug/bin/swiftc \
    -incremental -module-name Wire_Share_Extension -Onone -enable-batch-mode -enforce-exclusivity=checked -DDEBUG \
    -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.0.sdk \
    -target x86_64-apple-ios10.0-simulator \
    -g -module-cache-path /Users/vini/Library/Developer/Xcode/DerivedData/ModuleCache.noindex \
    -Xfrontend -serialize-debugging-options -application-extension -profile-coverage-mapping -profile-generate -enable-testing -warnings-as-errors \
    -index-store-path /Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Index/DataStore \
    -swift-version 4.2 \
    -I /Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Build/Products/Debug-iphonesimulator \
    -F /Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Build/Products/Debug-iphonesimulator \
    -F /Users/vini/Desktop/wire-ios/Carthage/Build/iOS \
    -j8 /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/ShareExtensionNetworkObserver.swift /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/NSExtensionContext+Attachments.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/ExtensionBackupExcluder.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/UnsentSendable.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/PreviewImageView.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/SLComposeServiceViewController+Preview.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/Error+Logging.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/NotSignedInViewController.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/NSItemProvider+Fetching.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/CrashReporter.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/ShareExtensionViewController.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/AccountSelectionViewController.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/SendingProgressViewController.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/Account+ShareExtensionDisplayName.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/ShareExtensionAnalytics.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/SendController.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/PostContent.swift \
    /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/ConversationSelectionViewController.swift \
    -output-file-map /Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Build/Intermediates.noindex/Wire-iOS.build/Debug-iphonesimulator/Wire\ Share\ Extension.build/Objects-normal/x86_64/Wire\ Share\ Extension-OutputFileMap.json \
    -serialize-diagnostics -Xcc \
    -I/Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Build/Intermediates.noindex/Wire-iOS.build/Debug-iphonesimulator/Wire\ Share\ Extension.build/swift-overrides.hmap \
    -Xcc -iquote \
    -Xcc /Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Build/Intermediates.noindex/Wire-iOS.build/Debug-iphonesimulator/Wire\ Share\ Extension.build/Wire\ Share\ Extension-generated-files.hmap \
    -Xcc -I/Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Build/Intermediates.noindex/Wire-iOS.build/Debug-iphonesimulator/Wire\ Share\ Extension.build/Wire\ Share\ Extension-own-target-headers.hmap \
    -Xcc -I/Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Build/Intermediates.noindex/Wire-iOS.build/Debug-iphonesimulator/Wire\ Share\ Extension.build/Wire\ Share\ Extension-all-non-framework-target-headers.hmap \
    -Xcc -ivfsoverlay \
    -Xcc /Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Build/Intermediates.noindex/Wire-iOS.build/all-product-headers.yaml \
    -Xcc -iquote \
    -Xcc /Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Build/Intermediates.noindex/Wire-iOS.build/Debug-iphonesimulator/Wire\ Share\ Extension.build/Wire\ Share\ Extension-project-headers.hmap \
    -Xcc -I/Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Build/Products/Debug-iphonesimulator/include \
    -Xcc -I/Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Build/Intermediates.noindex/Wire-iOS.build/Debug-iphonesimulator/Wire\ Share\ Extension.build/../Wire-iOS.build/DerivedSources \
    -Xcc -I/Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Build/Intermediates.noindex/Wire-iOS.build/Debug-iphonesimulator/Wire\ Share\ Extension.build/DerivedSources/x86_64 \
    -Xcc -I/Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Build/Intermediates.noindex/Wire-iOS.build/Debug-iphonesimulator/Wire\ Share\ Extension.build/DerivedSources \
    -Xcc -DNDEBUG -Xcc -DNVALGRIND -Xcc -DDEBUG=1 -Xcc -DUSE_HOCKEY=0 -Xcc -DDYNAMIC_ANNOTATIONS_ENABLED=1 -Xcc -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -Xcc -D_DEBUG -Xcc -DNDEBUG -Xcc -DNVALGRIND -Xcc -DIOS -Xcc -DUSE_HOCKEY=0 -Xcc -DENABLE_DEVELOPER_MENU=1 -Xcc -DLOG_LEVEL_CONFIG=0xFFFFFFFF -Xcc -DWIRESTAN=1 -Xcc -DHOCKEY_APP_ID_KEY= -Xcc -DWIRE_SSO_URL_SCHEME=wire-sso-alpha -Xcc -DUSE_ANALYTICS=0 \
    -import-objc-header /Users/vini/Desktop/wire-ios/Wire-iOS\ Share\ Extension/Wire-iOS\ Share\ Extension-Bridging-Header.h -pch-output-dir /Users/vini/Library/Developer/Xcode/DerivedData/Wire-iOS-ctqjkccwgxhwlldjpyrrwddbxkak/Build/Intermediates.noindex/PrecompiledHeaders \
    -Xcc -working-directory/Users/vini/Desktop/wire-ios \
    -dump-ast > /Users/vini/Desktop/wire-ios/buildScripts/outputAst.ast 2>&1
1 Like

Its quiet unfortunate to see that you didn't get an answer. I am facing the exact same issue. Were you able to find a solution for this?

Sorry, I can't really remember what exactly solved this problem for me. I can, however, tell you what I do now, which is working fine for my use case. Starting with the Swift compiler call from Xcode:

  • Remove the arguments: -incremental, -whole-module-optimization, -c, -parseable-output, -output-file-map, -serialize-diagnostics.
  • Remove anything that ends in .swiftmodule, Swift.h and OutputFileMap.json.
  • Remove anything that starts with -emit.
  • Add -dump-ast.
  • If you want to add an output file map of your own, add -output-file-map /path/to/outputFileMap.json.

Hope it helps!

1 Like

Here's a small tool I made a while ago to help with this https://github.com/keith/xcode-ast-dump I'm not sure if it still works but please file an issue if it doesn't!

2 Likes

@Vinicius_Vendramini Thanks a lot. What you suggested worked for me.
@Keith I have reported the issue on your repo.

1 Like

Hi @Vinicius_Vendramini @Keith
I just noticed that the SIL we are dumping doesn't contain debug information. As described here: https://github.com/apple/swift/blob/master/docs/SIL.rst#debug-information
Is there a way to get that kind of information? I tried with a few arguments but couldn't get the right results.

Sorry, I’ve only ever used the AST dump, I don’t know anything about SIL...

1 Like