Frequent "An internal error occurred..." in Xcode with development snapshot

Is it "normal" for a development snapshot to frequently show the

An internal error occurred. Source editor functionality is limited. Attempting to restore...

warning in Xcode? I'm using the trunk development (main) snapshot 2021-01-19 and the banner shows when working with ill-defined property wrappers (e.g. property wrappers lacking initializers).

An example
@propertyWrapper enum A<T> {
  case some(T)
  case none
  
  var wrappedValue: T? {
    if case .some(let value) = self { return value }
    return nil
  }

  // missing init here
}

struct S {
  @A var x = 7
}

That banner usually indicates a SourceKit failure/crash. One good thing to check is what happens when you try to build the project in that state. Often, a SourceKit failure is a manifestation of a compiler crash during type checking. Does the compiler give a proper error message when you build the invalid code?

Thank you for replying! For the specific example in the first post, I'm getting an Abort trap: 6 and a "Bad base type" failed assertion at lib/AST/Type.cpp#L4063:

Contents of the error
Assertion failed: (0 && "Bad base type"), function getContextSubstitutions, file /Users/buildnode/jenkins/workspace/oss-swift-package-macos/swift/lib/AST/Type.cpp, line 4063.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.	Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-01-19-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/xalien95/Downloads/CommandLineTesting/CommandLineTesting/main.swift /Users/xalien95/Downloads/CommandLineTesting/CommandLineTesting/Length.swift -emit-module-path /Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/Objects-normal/x86_64/main~partial.swiftmodule -emit-module-doc-path /Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/Objects-normal/x86_64/main~partial.swiftdoc -emit-module-source-info-path /Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/Objects-normal/x86_64/main~partial.swiftsourceinfo -serialize-diagnostics-path /Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/Objects-normal/x86_64/main.swiftdeps -target x86_64-apple-macos11.1 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -I /Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Products/Debug -F /Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Products/Debug -enable-testing -g -module-cache-path /Users/xalien95/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -enable-anonymous-context-mangled-names -Xcc -I/Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/CommandLineTesting-generated-files.hmap -Xcc -I/Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/CommandLineTesting-own-target-headers.hmap -Xcc -I/Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/CommandLineTesting-all-target-headers.hmap -Xcc -iquote -Xcc /Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/CommandLineTesting-project-headers.hmap -Xcc -I/Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Products/Debug/include -Xcc -I/Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/DerivedSources-normal/x86_64 -Xcc -I/Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/DerivedSources/x86_64 -Xcc -I/Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/xalien95/Downloads/CommandLineTesting -target-sdk-version 11.1 -module-name CommandLineTesting -o /Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Build/Intermediates.noindex/CommandLineTesting.build/Debug/CommandLineTesting.build/Objects-normal/x86_64/main.o -index-store-path /Users/xalien95/Library/Developer/Xcode/DerivedData/CommandLineTesting-bxncsogedvbhvtalcusdpuhhherx/Index/DataStore -index-system-modules 
1.	Apple Swift version 5.4-dev (LLVM a9b8270702a974a, Swift 1d7d28206555caf)
2.	While evaluating request TypeCheckSourceFileRequest(source_file "/Users/xalien95/Downloads/CommandLineTesting/CommandLineTesting/main.swift")
3.	While type-checking 'S' (at /Users/xalien95/Downloads/CommandLineTesting/CommandLineTesting/main.swift:20:1)
4.	While evaluating request StoredPropertiesRequest(CommandLineTesting.(file).S@/Users/xalien95/Downloads/CommandLineTesting/CommandLineTesting/main.swift:20:8)
5.	While evaluating request PropertyWrapperBackingPropertyInfoRequest(CommandLineTesting.(file).S.x@/Users/xalien95/Downloads/CommandLineTesting/CommandLineTesting/main.swift:21:10)
6.	While evaluating request PropertyWrapperBackingPropertyTypeRequest(CommandLineTesting.(file).S.x@/Users/xalien95/Downloads/CommandLineTesting/CommandLineTesting/main.swift:21:10)
7.	While evaluating request InterfaceTypeRequest(CommandLineTesting.(file).S.x@/Users/xalien95/Downloads/CommandLineTesting/CommandLineTesting/main.swift:21:10)
8.	While evaluating request NamingPatternRequest(CommandLineTesting.(file).S.x@/Users/xalien95/Downloads/CommandLineTesting/CommandLineTesting/main.swift:21:10)
9.	While evaluating request PatternBindingEntryRequest((unknown decl), 0)
10.	While type-checking expression at [/Users/xalien95/Downloads/CommandLineTesting/CommandLineTesting/main.swift:21:4 - line:21:14] RangeText="A var x = "
0  swift-frontend           0x0000000104db79b5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift-frontend           0x0000000104db6c15 llvm::sys::RunSignalHandlers() + 85
2  swift-frontend           0x0000000104db7f86 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff20357d7d _sigtramp + 29
4  swift-frontend           0x000000010134f900 swift::constraints::ConstraintSystem::addOverloadSet(llvm::ArrayRef<swift::constraints::Constraint*>, swift::constraints::ConstraintLocator*) + 128
5  libsystem_c.dylib        0x00007fff20266720 abort + 120
6  libsystem_c.dylib        0x00007fff202659d6 err + 0
7  swift-frontend           0x000000010535c9e3 swift::TypeBase::getContextSubstitutions(swift::DeclContext const*, swift::GenericEnvironment*) (.cold.15) + 35
8  swift-frontend           0x00000001018ee5b0 swift::TypeBase::getContextSubstitutions(swift::DeclContext const*, swift::GenericEnvironment*) + 1440
9  swift-frontend           0x00000001018ee73c swift::TypeBase::getMemberSubstitutions(swift::ValueDecl const*, swift::GenericEnvironment*) + 124
10 swift-frontend           0x00000001018eead7 swift::TypeBase::getTypeOfMember(swift::ModuleDecl*, swift::ValueDecl const*, swift::Type) + 359
11 swift-frontend           0x0000000101290677 generateWrappedPropertyTypeConstraints(swift::constraints::ConstraintSystem&, swift::Type, swift::VarDecl*, swift::Type) + 743
12 swift-frontend           0x000000010128f6b4 swift::constraints::ConstraintSystem::generateConstraints(swift::constraints::SolutionApplicationTarget&, swift::FreeTypeVariableBinding) + 2100
13 swift-frontend           0x00000001012e38b2 swift::constraints::ConstraintSystem::solveImpl(swift::constraints::SolutionApplicationTarget&, swift::FreeTypeVariableBinding) + 370
14 swift-frontend           0x00000001012e321a swift::constraints::ConstraintSystem::solve(swift::constraints::SolutionApplicationTarget&, swift::FreeTypeVariableBinding) + 106
15 swift-frontend           0x00000001013f9f23 swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 531
16 swift-frontend           0x00000001013fa340 swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*, swift::Type, swift::PatternBindingDecl*, unsigned int) + 112
17 swift-frontend           0x00000001013fa5bb swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int, swift::Type) + 363
18 swift-frontend           0x00000001014b79aa swift::PatternBindingEntryRequest::evaluate(swift::Evaluator&, swift::PatternBindingDecl*, unsigned int) const + 650
19 swift-frontend           0x00000001014e879a llvm::Expected<swift::PatternBindingEntryRequest::OutputType> swift::Evaluator::getResultUncached<swift::PatternBindingEntryRequest>(swift::PatternBindingEntryRequest const&) + 426
20 swift-frontend           0x00000001014e8517 llvm::Expected<swift::PatternBindingEntryRequest::OutputType> swift::Evaluator::getResultCached<swift::PatternBindingEntryRequest, (void*)0>(swift::PatternBindingEntryRequest const&) + 119
21 swift-frontend           0x00000001014e3eb6 swift::PatternBindingEntryRequest::OutputType swift::evaluateOrDefault<swift::PatternBindingEntryRequest>(swift::Evaluator&, swift::PatternBindingEntryRequest, swift::PatternBindingEntryRequest::OutputType) + 54
22 swift-frontend           0x000000010140b218 swift::NamingPatternRequest::evaluate(swift::Evaluator&, swift::VarDecl*) const + 120
23 swift-frontend           0x00000001017c22b1 llvm::Expected<swift::NamingPatternRequest::OutputType> swift::Evaluator::getResultUncached<swift::NamingPatternRequest>(swift::NamingPatternRequest const&) + 417
24 swift-frontend           0x00000001017c2037 llvm::Expected<swift::NamingPatternRequest::OutputType> swift::Evaluator::getResultCached<swift::NamingPatternRequest, (void*)0>(swift::NamingPatternRequest const&) + 119
25 swift-frontend           0x000000010174f6d3 swift::NamingPatternRequest::OutputType swift::evaluateOrDefault<swift::NamingPatternRequest>(swift::Evaluator&, swift::NamingPatternRequest, swift::NamingPatternRequest::OutputType) + 51
26 swift-frontend           0x000000010140a881 swift::InterfaceTypeRequest::evaluate(swift::Evaluator&, swift::ValueDecl*) const + 593
27 swift-frontend           0x00000001017838c1 llvm::Expected<swift::InterfaceTypeRequest::OutputType> swift::Evaluator::getResultUncached<swift::InterfaceTypeRequest>(swift::InterfaceTypeRequest const&) + 417
28 swift-frontend           0x0000000101783647 llvm::Expected<swift::InterfaceTypeRequest::OutputType> swift::Evaluator::getResultCached<swift::InterfaceTypeRequest, (void*)0>(swift::InterfaceTypeRequest const&) + 119
29 swift-frontend           0x00000001017424e3 swift::InterfaceTypeRequest::OutputType swift::evaluateOrDefault<swift::InterfaceTypeRequest>(swift::Evaluator&, swift::InterfaceTypeRequest, swift::InterfaceTypeRequest::OutputType) + 51
30 swift-frontend           0x0000000101737c20 swift::ValueDecl::getInterfaceType() const + 64
31 swift-frontend           0x00000001014646d2 swift::PropertyWrapperBackingPropertyTypeRequest::evaluate(swift::Evaluator&, swift::VarDecl*) const + 162
32 swift-frontend           0x00000001017ccdf1 llvm::Expected<swift::PropertyWrapperBackingPropertyTypeRequest::OutputType> swift::Evaluator::getResultUncached<swift::PropertyWrapperBackingPropertyTypeRequest>(swift::PropertyWrapperBackingPropertyTypeRequest const&) + 417
33 swift-frontend           0x00000001017ccb1e llvm::Expected<swift::PropertyWrapperBackingPropertyTypeRequest::OutputType> swift::Evaluator::getResultCached<swift::PropertyWrapperBackingPropertyTypeRequest, (void*)0>(swift::PropertyWrapperBackingPropertyTypeRequest const&) + 414
34 swift-frontend           0x0000000101750780 swift::PropertyWrapperBackingPropertyTypeRequest::OutputType swift::evaluateOrDefault<swift::PropertyWrapperBackingPropertyTypeRequest>(swift::Evaluator&, swift::PropertyWrapperBackingPropertyTypeRequest, swift::PropertyWrapperBackingPropertyTypeRequest::OutputType) + 64
35 swift-frontend           0x00000001014ba652 swift::PropertyWrapperBackingPropertyInfoRequest::evaluate(swift::Evaluator&, swift::VarDecl*) const + 34
36 swift-frontend           0x00000001014aa651 swift::SimpleRequest<swift::PropertyWrapperBackingPropertyInfoRequest, swift::PropertyWrapperBackingPropertyInfo (swift::VarDecl*), (swift::RequestFlags)2>::evaluateRequest(swift::PropertyWrapperBackingPropertyInfoRequest const&, swift::Evaluator&) + 17
37 swift-frontend           0x00000001017cf11e llvm::Expected<swift::PropertyWrapperBackingPropertyInfoRequest::OutputType> swift::Evaluator::getResultUncached<swift::PropertyWrapperBackingPropertyInfoRequest>(swift::PropertyWrapperBackingPropertyInfoRequest const&) + 430
38 swift-frontend           0x00000001017cee15 llvm::Expected<swift::PropertyWrapperBackingPropertyInfoRequest::OutputType> swift::Evaluator::getResultCached<swift::PropertyWrapperBackingPropertyInfoRequest, (void*)0>(swift::PropertyWrapperBackingPropertyInfoRequest const&) + 485
39 swift-frontend           0x0000000101750960 swift::PropertyWrapperBackingPropertyInfoRequest::OutputType swift::evaluateOrDefault<swift::PropertyWrapperBackingPropertyInfoRequest>(swift::Evaluator&, swift::PropertyWrapperBackingPropertyInfoRequest, swift::PropertyWrapperBackingPropertyInfoRequest::OutputType) + 64
40 swift-frontend           0x0000000101750d16 swift::VarDecl::getPropertyWrapperBackingProperty() const + 102
41 swift-frontend           0x00000001014b71e2 computeLoweredStoredProperties(swift::NominalTypeDecl*) + 162
42 swift-frontend           0x00000001014b6e02 swift::StoredPropertiesRequest::evaluate(swift::Evaluator&, swift::NominalTypeDecl*) const + 162
43 swift-frontend           0x0000000101786eeb llvm::Expected<swift::StoredPropertiesRequest::OutputType> swift::Evaluator::getResultUncached<swift::StoredPropertiesRequest>(swift::StoredPropertiesRequest const&) + 427
44 swift-frontend           0x0000000101786c02 llvm::Expected<swift::StoredPropertiesRequest::OutputType> swift::Evaluator::getResultCached<swift::StoredPropertiesRequest, (void*)0>(swift::StoredPropertiesRequest const&) + 434
45 swift-frontend           0x00000001017458d8 swift::StoredPropertiesRequest::OutputType swift::evaluateOrDefault<swift::StoredPropertiesRequest>(swift::Evaluator&, swift::StoredPropertiesRequest, swift::StoredPropertiesRequest::OutputType) + 56
46 swift-frontend           0x000000010142f363 swift::ASTVisitor<(anonymous namespace)::DeclChecker, void, void, void, void, void, void>::visit(swift::Decl*) + 1427
47 swift-frontend           0x000000010142e5ef (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 159
48 swift-frontend           0x000000010142e532 swift::TypeChecker::typeCheckDecl(swift::Decl*) + 130
49 swift-frontend           0x00000001014e3778 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 184
50 swift-frontend           0x00000001014e474d llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 429
51 swift-frontend           0x00000001014e44d2 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 114
52 swift-frontend           0x00000001014e35be swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 46
53 swift-frontend           0x0000000100717fea swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<void (swift::SourceFile&)>) + 90
54 swift-frontend           0x0000000100717eda swift::CompilerInstance::performSema() + 74
55 swift-frontend           0x00000001005f18f3 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5091
56 swift-frontend           0x000000010058dc32 main + 866
57 libdyld.dylib            0x00007fff2032e621 start + 1
58 libdyld.dylib            0x000000000000004a start + 18446603339975957034
error: Abort trap: 6 (in target 'CommandLineTesting' from project 'CommandLineTesting')

So the answer to my question is "no, it's not normal for a development snapshot to have the type checker to abort the build process and you should file a bug"?

Yes, that's right. It's not normal, and in this case you've found another property wrapper bug for us to fix - please continue to file bugs when you hit these issues. Thank you!

2 Likes

Will do! I wish I had the skills to also fix what I file, but at the moment I can't even build the compiler due to SR-13635 (if I use --skip-test-cmark as suggested in the last comment, the process ends up with various failed tests). I can build it with no issue using Ninja, but then I would need an appropriate IDE and Visual Studio Code complains about missing headers.
Do you have suggestions in that regard? Should I ignore the failed build and still use the generated Xcode project?

If you're interested in fixing some of these property wrapper bugs, I can certainly help you with that :slightly_smiling_face: in my experience, knowing how property wrappers are supposed to work is much more valuable than knowing any specifics about the implementation when you first start working in this area.

If you ran build script with --xcode or -x and it failed, but it got far enough to generate the Swift.xcodeproj, you can usually still use the Xcode project

1 Like

Filed as SR-14080

Thank you!

1 Like