swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.49k stars 10.35k forks source link

Compiler crash on using internal import (AccessLevelOnImport feature) #70920

Open mr-swifter opened 9 months ago

mr-swifter commented 9 months ago

Description

When I start using AccessLevelOnImport and do public / internal import the compiler crash time to time. It really depends on project structure and some times disappears when I restructure dependencies.

Reproduction

Small project reproducing the crash: https://github.com/ordo-one/external-reproducers/tree/main/swift/swift-crash-on-access-level-import.

If .enableExperimentalFeature("AccessLevelOnImport") is removed and internal import is replaced to @_implementationOnly import, then crash is gone.

Stack dump

Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/ordo/Dev/Test/external-reproducers/swift/swift-crash-on-access-level-import/Sources/Process/BundleManager.swift /Users/ordo/Dev/Test/external-reproducers/swift/swift-crash-on-access-level-import/Sources/Process/PluginLoader.swift -primary-file /Users/ordo/Dev/Test/external-reproducers/swift/swift-crash-on-access-level-import/Sources/Process/Process.swift -emit-dependencies-path /Users/ordo/Dev/Test/external-reproducers/swift/swift-crash-on-access-level-import/.build/arm64-apple-macosx/debug/Process.build/Process.d -emit-reference-dependencies-path /Users/ordo/Dev/Test/external-reproducers/swift/swift-crash-on-access-level-import/.build/arm64-apple-macosx/debug/Process.build/Process.swiftdeps -target arm64-apple-macosx14.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -I /Users/ordo/Dev/Test/external-reproducers/swift/swift-crash-on-access-level-import/.build/arm64-apple-macosx/debug -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -module-cache-path /Users/ordo/Dev/Test/external-reproducers/swift/swift-crash-on-access-level-import/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -entry-point-function-name Process_main -enable-experimental-feature AccessLevelOnImport -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -fmodule-map-file=/Users/ordo/Dev/Test/external-reproducers/swift/swift-crash-on-access-level-import/.build/checkouts/swift-system/Sources/CSystem/include/module.modulemap -Xcc -I -Xcc /Users/ordo/Dev/Test/external-reproducers/swift/swift-crash-on-access-level-import/.build/checkouts/swift-system/Sources/CSystem/include -Xcc -isysroot -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -module-name Process -package-name swift_crash_on_access_level_import -disable-clang-spi -target-sdk-version 14.2 -target-sdk-name macosx14.2 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /Users/ordo/Dev/Test/external-reproducers/swift/swift-crash-on-access-level-import/.build/arm64-apple-macosx/debug/Process.build/Process.swift.o -index-store-path /Users/ordo/Dev/Test/external-reproducers/swift/swift-crash-on-access-level-import/.build/arm64-apple-macosx/debug/index/store -index-system-modules
1.  Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
2.  Compiling with the current language version
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000103245abc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000105eabcb0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000105c15054 SignalHandler(int) + 352
3  libsystem_platform.dylib 0x000000018de45a24 _sigtramp + 56
4  swift-frontend           0x0000000104a7cfcc (anonymous namespace)::IndexSwiftASTWalker::visitImports((anonymous namespace)::SourceFileOrModule, llvm::SmallPtrSetImpl<swift::ModuleDecl*>&) + 764
5  swift-frontend           0x0000000104a7cfcc (anonymous namespace)::IndexSwiftASTWalker::visitImports((anonymous namespace)::SourceFileOrModule, llvm::SmallPtrSetImpl<swift::ModuleDecl*>&) + 764
6  swift-frontend           0x0000000104a7d294 (anonymous namespace)::IndexSwiftASTWalker::visitImports((anonymous namespace)::SourceFileOrModule, llvm::SmallPtrSetImpl<swift::ModuleDecl*>&) + 1476
7  swift-frontend           0x00000001048852ec (anonymous namespace)::IndexSwiftASTWalker::visitModule(swift::ModuleDecl&) + 160
8  swift-frontend           0x000000010487d480 swift::index::indexSourceFile(swift::SourceFile*, swift::index::IndexDataConsumer&) + 392
9  swift-frontend           0x0000000104aa6bbc recordSourceFileUnit(swift::SourceFile*, llvm::StringRef, llvm::StringRef, bool, bool, bool, bool, bool, llvm::StringRef, llvm::ArrayRef<clang::FileEntry const*>, clang::CompilerInstance const&, swift::PathRemapper const&, swift::DiagnosticEngine&) (.llvm.10923870649257887114) + 1636
10 swift-frontend           0x0000000104a9afe4 swift::index::indexAndRecord(swift::SourceFile*, llvm::StringRef, llvm::StringRef, bool, bool, bool, bool, bool, llvm::StringRef, swift::DependencyTracker const&, swift::PathRemapper const&) + 440
11 swift-frontend           0x0000000105e6da34 emitIndexDataForSourceFile(swift::SourceFile*, swift::CompilerInstance const&) + 520
12 swift-frontend           0x0000000105e75614 performEndOfPipelineActions(swift::CompilerInstance&) + 7888
13 swift-frontend           0x000000010083de34 generateCode(swift::CompilerInstance&, llvm::StringRef, llvm::Module*, llvm::GlobalVariable*) + 184
14 swift-frontend           0x000000010578d744 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1708
15 swift-frontend           0x0000000105788a08 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1748
16 swift-frontend           0x000000010578c854 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4568
17 swift-frontend           0x00000001057f3d44 swift::mainEntry(int, char const**) + 4408
18 dyld                     0x000000018da9d058 start + 2224

Expected behavior

Successful compilation or compilation error

Environment

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5) Target: arm64-apple-macosx14.0

Swift Package Manager - Swift 5.9.0

Additional information

No response

mr-swifter commented 8 months ago

It seems it actually doesn't depend on project structure. It starts to reproduce as soon as I enable library evolution mode.