Uploaded image for project: 'Swift'
  1. Swift
  2. SR-11302

REPL: Triggering autocomplete on imported type leads to crash

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Labels:
      None
    • Environment:

      Apple Swift version 5.1 (swiftlang-1100.0.266.1 clang-1100.0.32.1).

      Description

      When triggering autocomplete in the REPL on a value, whose type is not defined in the Swift standard library or in the session itself, the REPL crashes.

      Steps to reproduce:

      1. Start the Swift REPL
      2. execute import Foundation
      3. execute let a: NSArray = []
      4. type inĀ a
      5. press tab to trigger autocomplete

      This crashes the REPL and the following error is emitted:

      0  lldb                     0x0000000103b8e705 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
      1  lldb                     0x0000000103b8dd77 llvm::sys::RunSignalHandlers() + 39
      2  lldb                     0x0000000103b8ed58 SignalHandler(int) + 264
      3  libsystem_platform.dylib 0x00007fff663dbb1d _sigtramp + 29
      4  libsystem_platform.dylib 0x00007fdf6d6c5630 _sigtramp + 120494896
      5  LLDB                     0x0000000104db9651 swift::ClangImporter::Implementation::importAccessorMethodType(swift::DeclContext const*, clang::ObjCPropertyDecl const*, clang::ObjCMethodDecl const*, bool, swift::importer::ImportedName, swift::ParameterList**) + 641
      6  LLDB                     0x0000000104d90c58 (anonymous namespace)::SwiftDeclConverter::importObjCMethodDecl(clang::ObjCMethodDecl const*, swift::DeclContext*, bool, llvm::Optional<(anonymous namespace)::AccessorInfo>) + 1848
      7  LLDB                     0x0000000104d8ca5b (anonymous namespace)::SwiftDeclConverter::importObjCPropertyDecl(clang::ObjCPropertyDecl const*, swift::DeclContext*) + 1323
      8  LLDB                     0x0000000104d8a009 clang::declvisitor::Base<llvm::make_const_ptr, (anonymous namespace)::SwiftDeclConverter, swift::Decl*>::Visit(clang::Decl const*) + 4089
      9  LLDB                     0x0000000104d88bc3 swift::ClangImporter::Implementation::importDeclImpl(clang::NamedDecl const*, swift::importer::ImportNameVersion, bool&, bool&) + 163
      10 LLDB                     0x0000000104d8bfc6 swift::ClangImporter::Implementation::importDeclAndCacheImpl(clang::NamedDecl const*, swift::importer::ImportNameVersion, bool) + 406
      11 LLDB                     0x0000000104da9f4a bool llvm::function_ref<bool (swift::importer::ImportedName, swift::importer::ImportNameVersion)>::callback_fn<swift::ClangImporter::Implementation::insertMembersAndAlternates(clang::NamedDecl const*, llvm::SmallVectorImpl<swift::Decl*>&)::$_3>(long, swift::importer::ImportedName, swift::importer::ImportNameVersion) + 42
      12 LLDB                     0x0000000104db4cf5 swift::importer::NameImporter::forEachDistinctImportName(clang::NamedDecl const*, swift::importer::ImportNameVersion, llvm::function_ref<bool (swift::importer::ImportedName, swift::importer::ImportNameVersion)>) + 229
      13 LLDB                     0x0000000104d8eac5 swift::ClangImporter::Implementation::collectMembersToAdd(clang::ObjCContainerDecl const*, swift::Decl*, swift::DeclContext*, llvm::SmallVectorImpl<swift::Decl*>&) + 277
      14 LLDB                     0x0000000104d8e500 swift::ClangImporter::Implementation::loadAllMembersOfObjcContainer(swift::Decl*, clang::ObjCContainerDecl const*) + 256
      15 LLDB                     0x0000000104d8e3f3 swift::ClangImporter::Implementation::loadAllMembers(swift::Decl*, unsigned long long) + 179
      16 LLDB                     0x0000000104efe980 swift::IterableDeclContext::loadAllMembers() const + 240
      17 LLDB                     0x0000000104efe87e swift::IterableDeclContext::getMembers() const + 14
      18 LLDB                     0x0000000104f626b9 swift::NominalTypeDecl::lookupDirect(swift::DeclName, swift::OptionSet<swift::NominalTypeDecl::LookupDirectFlags, unsigned int>) + 329
      19 LLDB                     0x0000000104f643a5 swift::DeclContext::lookupQualified(llvm::ArrayRef<swift::NominalTypeDecl*>, swift::DeclName, swift::NLOptions, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 1317
      20 LLDB                     0x0000000104d8c62e (anonymous namespace)::SwiftDeclConverter::importObjCPropertyDecl(clang::ObjCPropertyDecl const*, swift::DeclContext*) + 254
      21 LLDB                     0x0000000104d8a009 clang::declvisitor::Base<llvm::make_const_ptr, (anonymous namespace)::SwiftDeclConverter, swift::Decl*>::Visit(clang::Decl const*) + 4089
      22 LLDB                     0x0000000104d88bc3 swift::ClangImporter::Implementation::importDeclImpl(clang::NamedDecl const*, swift::importer::ImportNameVersion, bool&, bool&) + 163
      23 LLDB                     0x0000000104d8bfc6 swift::ClangImporter::Implementation::importDeclAndCacheImpl(clang::NamedDecl const*, swift::importer::ImportNameVersion, bool) + 406
      24 LLDB                     0x0000000104da9f4a bool llvm::function_ref<bool (swift::importer::ImportedName, swift::importer::ImportNameVersion)>::callback_fn<swift::ClangImporter::Implementation::insertMembersAndAlternates(clang::NamedDecl const*, llvm::SmallVectorImpl<swift::Decl*>&)::$_3>(long, swift::importer::ImportedName, swift::importer::ImportNameVersion) + 42
      25 LLDB                     0x0000000104db4cf5 swift::importer::NameImporter::forEachDistinctImportName(clang::NamedDecl const*, swift::importer::ImportNameVersion, llvm::function_ref<bool (swift::importer::ImportedName, swift::importer::ImportNameVersion)>) + 229
      26 LLDB                     0x0000000104d8eac5 swift::ClangImporter::Implementation::collectMembersToAdd(clang::ObjCContainerDecl const*, swift::Decl*, swift::DeclContext*, llvm::SmallVectorImpl<swift::Decl*>&) + 277
      27 LLDB                     0x0000000104d8e500 swift::ClangImporter::Implementation::loadAllMembersOfObjcContainer(swift::Decl*, clang::ObjCContainerDecl const*) + 256
      28 LLDB                     0x0000000104d8e3f3 swift::ClangImporter::Implementation::loadAllMembers(swift::Decl*, unsigned long long) + 179
      29 LLDB                     0x0000000104efe980 swift::IterableDeclContext::loadAllMembers() const + 240
      30 LLDB                     0x0000000104efe87e swift::IterableDeclContext::getMembers() const + 14
      31 LLDB                     0x0000000104f626b9 swift::NominalTypeDecl::lookupDirect(swift::DeclName, swift::OptionSet<swift::NominalTypeDecl::LookupDirectFlags, unsigned int>) + 329
      32 LLDB                     0x0000000104f643a5 swift::DeclContext::lookupQualified(llvm::ArrayRef<swift::NominalTypeDecl*>, swift::DeclName, swift::NLOptions, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 1317
      33 LLDB                     0x0000000104d8c62e (anonymous namespace)::SwiftDeclConverter::importObjCPropertyDecl(clang::ObjCPropertyDecl const*, swift::DeclContext*) + 254
      34 LLDB                     0x0000000104d8a009 clang::declvisitor::Base<llvm::make_const_ptr, (anonymous namespace)::SwiftDeclConverter, swift::Decl*>::Visit(clang::Decl const*) + 4089
      35 LLDB                     0x0000000104d88bc3 swift::ClangImporter::Implementation::importDeclImpl(clang::NamedDecl const*, swift::importer::ImportNameVersion, bool&, bool&) + 163
      36 LLDB                     0x0000000104d8bfc6 swift::ClangImporter::Implementation::importDeclAndCacheImpl(clang::NamedDecl const*, swift::importer::ImportNameVersion, bool) + 406
      37 LLDB                     0x0000000104da9f4a bool llvm::function_ref<bool (swift::importer::ImportedName, swift::importer::ImportNameVersion)>::callback_fn<swift::ClangImporter::Implementation::insertMembersAndAlternates(clang::NamedDecl const*, llvm::SmallVectorImpl<swift::Decl*>&)::$_3>(long, swift::importer::ImportedName, swift::importer::ImportNameVersion) + 42
      38 LLDB                     0x0000000104db4cf5 swift::importer::NameImporter::forEachDistinctImportName(clang::NamedDecl const*, swift::importer::ImportNameVersion, llvm::function_ref<bool (swift::importer::ImportedName, swift::importer::ImportNameVersion)>) + 229
      39 LLDB                     0x0000000104d8eac5 swift::ClangImporter::Implementation::collectMembersToAdd(clang::ObjCContainerDecl const*, swift::Decl*, swift::DeclContext*, llvm::SmallVectorImpl<swift::Decl*>&) + 277
      40 LLDB                     0x0000000104d8e500 swift::ClangImporter::Implementation::loadAllMembersOfObjcContainer(swift::Decl*, clang::ObjCContainerDecl const*) + 256
      41 LLDB                     0x0000000104d8e3f3 swift::ClangImporter::Implementation::loadAllMembers(swift::Decl*, unsigned long long) + 179
      42 LLDB                     0x0000000104efe980 swift::IterableDeclContext::loadAllMembers() const + 240
      43 LLDB                     0x0000000104efe87e swift::IterableDeclContext::getMembers() const + 14
      44 LLDB                     0x0000000104f626b9 swift::NominalTypeDecl::lookupDirect(swift::DeclName, swift::OptionSet<swift::NominalTypeDecl::LookupDirectFlags, unsigned int>) + 329
      45 LLDB                     0x0000000104f643a5 swift::DeclContext::lookupQualified(llvm::ArrayRef<swift::NominalTypeDecl*>, swift::DeclName, swift::NLOptions, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 1317
      46 LLDB                     0x0000000104d8c62e (anonymous namespace)::SwiftDeclConverter::importObjCPropertyDecl(clang::ObjCPropertyDecl const*, swift::DeclContext*) + 254
      47 LLDB                     0x0000000104d8a009 clang::declvisitor::Base<llvm::make_const_ptr, (anonymous namespace)::SwiftDeclConverter, swift::Decl*>::Visit(clang::Decl const*) + 4089
      48 LLDB                     0x0000000104d88bc3 swift::ClangImporter::Implementation::importDeclImpl(clang::NamedDecl const*, swift::importer::ImportNameVersion, bool&, bool&) + 163
      49 LLDB                     0x0000000104d8bfc6 swift::ClangImporter::Implementation::importDeclAndCacheImpl(clang::NamedDecl const*, swift::importer::ImportNameVersion, bool) + 406
      50 LLDB                     0x0000000104da9f4a bool llvm::function_ref<bool (swift::importer::ImportedName, swift::importer::ImportNameVersion)>::callback_fn<swift::ClangImporter::Implementation::insertMembersAndAlternates(clang::NamedDecl const*, llvm::SmallVectorImpl<swift::Decl*>&)::$_3>(long, swift::importer::ImportedName, swift::importer::ImportNameVersion) + 42
      51 LLDB                     0x0000000104db4cf5 swift::importer::NameImporter::forEachDistinctImportName(clang::NamedDecl const*, swift::importer::ImportNameVersion, llvm::function_ref<bool (swift::importer::ImportedName, swift::importer::ImportNameVersion)>) + 229
      52 LLDB                     0x0000000104d8eac5 swift::ClangImporter::Implementation::collectMembersToAdd(clang::ObjCContainerDecl const*, swift::Decl*, swift::DeclContext*, llvm::SmallVectorImpl<swift::Decl*>&) + 277
      53 LLDB                     0x0000000104d8e500 swift::ClangImporter::Implementation::loadAllMembersOfObjcContainer(swift::Decl*, clang::ObjCContainerDecl const*) + 256
      54 LLDB                     0x0000000104d8e3f3 swift::ClangImporter::Implementation::loadAllMembers(swift::Decl*, unsigned long long) + 179
      55 LLDB                     0x0000000104efe980 swift::IterableDeclContext::loadAllMembers() const + 240
      56 LLDB                     0x0000000104efe87e swift::IterableDeclContext::getMembers() const + 14
      57 LLDB                     0x0000000104be024a collectVisibleMemberDecls(swift::DeclContext const*, (anonymous namespace)::LookupState, swift::Type, swift::IterableDeclContext*, llvm::SmallVectorImpl<swift::ValueDecl*>&, swift::LazyResolver*) + 42
      58 LLDB                     0x0000000104bdf2b6 lookupTypeMembers(swift::Type, swift::Type, swift::VisibleDeclConsumer&, swift::DeclContext const*, (anonymous namespace)::LookupState, swift::DeclVisibilityKind, swift::LazyResolver*) + 134
      59 LLDB                     0x0000000104bde6ee lookupVisibleMemberDeclsImpl(swift::Type, swift::VisibleDeclConsumer&, swift::DeclContext const*, (anonymous namespace)::LookupState, swift::DeclVisibilityKind, swift::LazyResolver*, swift::GenericSignatureBuilder*, llvm::SmallPtrSet<swift::TypeDecl*, 8u>&) + 1598
      60 LLDB                     0x0000000104bdc020 lookupVisibleMemberAndDynamicMemberDecls(swift::Type, swift::VisibleDeclConsumer&, (anonymous namespace)::KeyPathDynamicMemberConsumer&, swift::DeclContext const*, (anonymous namespace)::LookupState, swift::DeclVisibilityKind, swift::LazyResolver*, swift::GenericSignatureBuilder*, llvm::SmallPtrSet<swift::TypeDecl*, 8u>&, llvm::DenseSet<swift::TypeBase*, llvm::DenseMapInfo<swift::TypeBase*> >&) + 64
      61 LLDB                     0x0000000104bdbdf5 lookupVisibleMemberDecls(swift::Type, swift::VisibleDeclConsumer&, swift::DeclContext const*, (anonymous namespace)::LookupState, swift::DeclVisibilityKind, swift::LazyResolver*, swift::GenericSignatureBuilder*) + 437
      62 LLDB                     0x0000000104bdbc2e swift::lookupVisibleMemberDecls(swift::VisibleDeclConsumer&, swift::Type, swift::DeclContext const*, swift::LazyResolver*, bool, swift::GenericSignatureBuilder*) + 46
      63 LLDB                     0x0000000104648b77 (anonymous namespace)::CodeCompletionCallbacksImpl::doneParsing() + 16199
      64 LLDB                     0x0000000104e2660a swift::performDelayedParsing(swift::DeclContext*, swift::PersistentParserState&, swift::CodeCompletionCallbacksFactory*) + 458
      65 LLDB                     0x000000010466c4de doCodeCompletion(swift::SourceFile&, llvm::StringRef, unsigned int*, swift::CodeCompletionCallbacksFactory*) + 494
      66 LLDB                     0x000000010466c080 swift::REPLCompletions::populate(swift::SourceFile&, llvm::StringRef) + 160
      67 LLDB                     0x00000001040abe59 lldb_private::SwiftREPL::CompleteCode(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, lldb_private::StringList&) + 569
      68 LLDB                     0x0000000103e5b4e9 lldb_private::REPL::IOHandlerComplete(lldb_private::IOHandler&, char const*, char const*, char const*, int, int, lldb_private::StringList&, lldb_private::StringList&) + 489
      69 LLDB                     0x0000000103dcf197 lldb_private::IOHandlerEditline::AutoCompleteCallback(char const*, char const*, char const*, int, int, lldb_private::StringList&, lldb_private::StringList&, void*) + 55
      70 LLDB                     0x0000000103e7223e lldb_private::Editline::TabCommand(int) + 110
      71 LLDB                     0x0000000103e74571 lldb_private::Editline::ConfigureEditor(bool)::$_13::__invoke(editline*, int) + 33
      72 libedit.3.dylib          0x00007fff63dba7db el_wgets + 484
      73 libedit.3.dylib          0x00007fff63dc58bb el_gets + 37
      74 LLDB                     0x0000000103e73d5e lldb_private::Editline::GetLines(int, lldb_private::StringList&, bool&) + 446
      75 LLDB                     0x0000000103dcfb43 lldb_private::IOHandlerEditline::Run() + 115
      76 LLDB                     0x0000000103db701b lldb_private::Debugger::ExecuteIOHandlers() + 123
      77 LLDB                     0x0000000103db9a63 lldb_private::Debugger::IOHandlerThread(void*) + 19
      78 LLDB                     0x0000000103e64317 lldb_private::HostNativeThreadBase::ThreadCreateTrampoline(void*) + 103
      79 libsystem_pthread.dylib  0x00007fff663e6d76 _pthread_start + 125
      80 libsystem_pthread.dylib  0x00007fff663e35ef thread_start + 15
      [1]    3774 segmentation fault  swift
      

      When running a package in the REPL with swift run --repl and then performing autocomplete on a type from that package, a different error is emitted:

      0  lldb                     0x000000010dd07705 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
      1  lldb                     0x000000010dd06d77 llvm::sys::RunSignalHandlers() + 39
      2  lldb                     0x000000010dd07d58 SignalHandler(int) + 264
      3  libsystem_platform.dylib 0x00007fff663dbb1d _sigtramp + 29
      4  libsystem_platform.dylib 0x00007f9bee484950 _sigtramp + 2282393168
      5  LLDB                     0x000000010ee3977e swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 1070
      6  LLDB                     0x000000010e7e24c6 doCodeCompletion(swift::SourceFile&, llvm::StringRef, unsigned int*, swift::CodeCompletionCallbacksFactory*) + 470
      7  LLDB                     0x000000010e7e2080 swift::REPLCompletions::populate(swift::SourceFile&, llvm::StringRef) + 160
      8  LLDB                     0x000000010e221e59 lldb_private::SwiftREPL::CompleteCode(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, lldb_private::StringList&) + 569
      9  LLDB                     0x000000010dfd14e9 lldb_private::REPL::IOHandlerComplete(lldb_private::IOHandler&, char const*, char const*, char const*, int, int, lldb_private::StringList&, lldb_private::StringList&) + 489
      10 LLDB                     0x000000010df45197 lldb_private::IOHandlerEditline::AutoCompleteCallback(char const*, char const*, char const*, int, int, lldb_private::StringList&, lldb_private::StringList&, void*) + 55
      11 LLDB                     0x000000010dfe823e lldb_private::Editline::TabCommand(int) + 110
      12 LLDB                     0x000000010dfea571 lldb_private::Editline::ConfigureEditor(bool)::$_13::__invoke(editline*, int) + 33
      13 libedit.3.dylib          0x00007fff63dba7db el_wgets + 484
      14 libedit.3.dylib          0x00007fff63dc58bb el_gets + 37
      15 LLDB                     0x000000010dfe9d5e lldb_private::Editline::GetLines(int, lldb_private::StringList&, bool&) + 446
      16 LLDB                     0x000000010df45b43 lldb_private::IOHandlerEditline::Run() + 115
      17 LLDB                     0x000000010df2d01b lldb_private::Debugger::ExecuteIOHandlers() + 123
      18 LLDB                     0x000000010df2fa63 lldb_private::Debugger::IOHandlerThread(void*) + 19
      19 LLDB                     0x000000010dfda317 lldb_private::HostNativeThreadBase::ThreadCreateTrampoline(void*) + 103
      20 libsystem_pthread.dylib  0x00007fff663e6d76 _pthread_start + 125
      21 libsystem_pthread.dylib  0x00007fff663e35ef thread_start + 15
      [1]    3030 segmentation fault  swift run --repl -c release
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              palle Palle Klewitz
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: