LadybirdBrowser / ladybird

Truly independent web browser
https://ladybird.org
BSD 2-Clause "Simplified" License
21.71k stars 961 forks source link

Swift: Using un-namespaced 'String' type after importing AK crashes swift frontend #1102

Open ADKaster opened 2 months ago

ADKaster commented 2 months ago

A swift file with the contents:

import AK

func f(_ x: String) {}

Crashes the swift frontend due to ambiguity about which type "String" is referring to.

Changing the function to take an AK.String or a Swift.String resolves the error.

I could not reproduce this with an empty AK library that just has a definition for namespace AK { class String{}; }, so there's something else going on.

Needs a reduction and upstream swiftc bug report.

The crash looks like so:

[27/31] Building Swift Module 'TestAKBindings' with 1 source
FAILED: Lagom/Tests/AK/CMakeFiles/TestAKBindings.dir/TestAKBindings.swift.o 
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -target arm64-apple-macosx14.6 -j 12 -num-threads 12 -c -DENABLE_COMPILETIME_FORMAT_CHECK -module-name TestAKBindings -O -g -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -incremental -color-diagnostics -Xcc -std=c++23 -cxx-interoperability-mode=default -Xcc -Wall -Xcc -Wextra -Xcc -fno-exceptions -Xcc -ffp-contract=off -Xcc -Wcast-qual -Xcc -Wformat=2 -Xcc -Wimplicit-fallthrough -Xcc -Wmissing-declarations -Xcc -Wsuggest-override -Xcc -Wno-invalid-offsetof -Xcc -Wno-unknown-warning-option -Xcc -Wno-unused-command-line-argument -Xcc -Werror -Xcc -fconstexpr-steps=16777216 -Xcc -Wmissing-prototypes -Xcc -Wno-implicit-const-int-float-conversion -Xcc -Wno-user-defined-literals -Xcc -Wno-vla-cxx-extension -Xcc -Wno-unqualified-std-cast-call -Xcc -fstack-protector-strong -Xcc -fstrict-flex-arrays=2 -Xcc -Wno-maybe-uninitialized -Xcc -Wno-shorten-64-to-32 -Xcc -fsigned-char -Xcc -ggnu-pubnames -Xcc -fPIC -Xcc -O2 -Xcc -g1 -Xcc -Wno-overloaded-virtual -Xcc -Wno-unused-private-field -parse-as-library -Xcc -ivfsoverlay/Users/andrew/Source/ladybird-browser/Build/ladybird/Lagom/AK/vfs_overlay.yaml -output-file-map Lagom/Tests/AK/CMakeFiles/TestAKBindings.dir/RelWithDebInfo/output-file-map.json -I /Users/andrew/Source/ladybird-browser -I /Users/andrew/Source/ladybird-browser/Userland/Services -I /Users/andrew/Source/ladybird-browser/Userland/Libraries -I /Users/andrew/Source/ladybird-browser/Build/ladybird/Lagom -I /Users/andrew/Source/ladybird-browser/Build/ladybird/Lagom/Userland/Services -I /Users/andrew/Source/ladybird-browser/Build/ladybird/Lagom/Userland/Libraries -I /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I /Users/andrew/Source/ladybird-browser/Meta/Lagom/../.. -I /Users/andrew/Source/ladybird-browser/Meta/Lagom/../../Userland -I /Users/andrew/Source/ladybird-browser/Meta/Lagom/../../Userland/Libraries -I /Users/andrew/Source/ladybird-browser/Meta/Lagom/../../Userland/Services -I /Users/andrew/Source/ladybird-browser/Build/ladybird /Users/andrew/Source/ladybird-browser/Tests/AK/TestAKBindings.swift
error: compile command failed due to signal 11 (use -v to see invocation)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/andrew/Source/ladybird-browser/Tests/AK/TestAKBindings.swift -emit-reference-dependencies-path Lagom/Tests/AK/CMakeFiles/TestAKBindings.dir/TestAKBindings.swift.o.swiftdeps -target arm64-apple-macosx14.6 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -cxx-interoperability-mode=default -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -I /Users/andrew/Source/ladybird-browser -I /Users/andrew/Source/ladybird-browser/Userland/Services -I /Users/andrew/Source/ladybird-browser/Userland/Libraries -I /Users/andrew/Source/ladybird-browser/Build/ladybird/Lagom -I /Users/andrew/Source/ladybird-browser/Build/ladybird/Lagom/Userland/Services -I /Users/andrew/Source/ladybird-browser/Build/ladybird/Lagom/Userland/Libraries -I /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I /Users/andrew/Source/ladybird-browser -I /Users/andrew/Source/ladybird-browser/Userland -I /Users/andrew/Source/ladybird-browser/Userland/Libraries -I /Users/andrew/Source/ladybird-browser/Userland/Services -I /Users/andrew/Source/ladybird-browser/Build/ladybird -color-diagnostics -g -debug-info-format=dwarf -dwarf-version=4 -O -D ENABLE_COMPILETIME_FORMAT_CHECK -new-driver-path /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -file-compilation-dir /Users/andrew/Source/ladybird-browser/Build/ladybird -Xcc -std=c++23 -Xcc -Wall -Xcc -Wextra -Xcc -fno-exceptions -Xcc -ffp-contract=off -Xcc -Wcast-qual -Xcc -Wformat=2 -Xcc -Wimplicit-fallthrough -Xcc -Wmissing-declarations -Xcc -Wsuggest-override -Xcc -Wno-invalid-offsetof -Xcc -Wno-unknown-warning-option -Xcc -Wno-unused-command-line-argument -Xcc -Werror -Xcc -fconstexpr-steps=16777216 -Xcc -Wmissing-prototypes -Xcc -Wno-implicit-const-int-float-conversion -Xcc -Wno-user-defined-literals -Xcc -Wno-vla-cxx-extension -Xcc -Wno-unqualified-std-cast-call -Xcc -fstack-protector-strong -Xcc -fstrict-flex-arrays=2 -Xcc -Wno-maybe-uninitialized -Xcc -Wno-shorten-64-to-32 -Xcc -fsigned-char -Xcc -ggnu-pubnames -Xcc -fPIC -Xcc -O2 -Xcc -g1 -Xcc -Wno-overloaded-virtual -Xcc -Wno-unused-private-field -Xcc -ivfsoverlay/Users/andrew/Source/ladybird-browser/Build/ladybird/Lagom/AK/vfs_overlay.yaml -module-name TestAKBindings -disable-clang-spi -target-sdk-version 15.0 -target-sdk-name macosx15.0 -external-plugin-path /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -enable-default-cmo -parse-as-library -num-threads 12 -o Lagom/Tests/AK/CMakeFiles/TestAKBindings.dir/TestAKBindings.swift.o
1.  Apple Swift version 6.0 (swiftlang-6.0.0.7.6 clang-1600.0.24.1)
2.  Compiling with effective version 5.10
3.  While evaluating request IRGenRequest(IR Generation for file "/Users/andrew/Source/ladybird-browser/Tests/AK/TestAKBindings.swift")
4.  While emitting IR SIL function "@$s14TestAKBindings1fyySo2AKO6StringVF".
 for 'f(_:)' (at /Users/andrew/Source/ladybird-browser/Tests/AK/TestAKBindings.swift:9:1)
5.  While mangling type for debugger type 'String'
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           0x0000000107e79194 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000107e773e8 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000107e79760 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x00000001944de584 _sigtramp + 56
4  swift-frontend           0x0000000103efeae8 swift::Mangle::ASTMangler::appendAnyGenericType(swift::GenericTypeDecl const*, swift::Mangle::ASTMangler::BaseEntitySignature&) + 1884
5  swift-frontend           0x0000000103ef0a20 swift::Mangle::ASTMangler::appendAnyGenericType(swift::GenericTypeDecl const*) + 60
6  swift-frontend           0x0000000103ef2fcc swift::Mangle::ASTMangler::appendType(swift::Type, swift::GenericSignature, swift::ValueDecl const*) + 3276
7  swift-frontend           0x0000000103ef61d8 swift::Mangle::ASTMangler::mangleTypeForDebugger(swift::Type, swift::GenericSignature) + 496
8  swift-frontend           0x0000000102e32bf0 (anonymous namespace)::IRGenDebugInfoImpl::getOrCreateType(swift::irgen::DebugTypeInfo) + 988
9  swift-frontend           0x0000000102e2d228 (anonymous namespace)::IRGenDebugInfoImpl::emitVariableDeclaration(swift::irgen::IRBuilder&, llvm::ArrayRef<llvm::Value*>, swift::irgen::DebugTypeInfo, swift::SILDebugScope const*, std::__1::optional<swift::SILLocation>, swift::SILDebugVariable, swift::irgen::IndirectionKind, swift::irgen::ArtificialKind, swift::irgen::AddrDbgInstrKind) + 400
10 swift-frontend           0x0000000102e2d068 swift::irgen::IRGenDebugInfo::emitVariableDeclaration(swift::irgen::IRBuilder&, llvm::ArrayRef<llvm::Value*>, swift::irgen::DebugTypeInfo, swift::SILDebugScope const*, std::__1::optional<swift::SILLocation>, swift::SILDebugVariable, swift::irgen::IndirectionKind, swift::irgen::ArtificialKind, swift::irgen::AddrDbgInstrKind) + 268
11 swift-frontend           0x0000000102e8bb40 (anonymous namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) + 136960
12 swift-frontend           0x0000000102e69124 (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 13220
13 swift-frontend           0x0000000102e658dc swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 2088
14 swift-frontend           0x0000000102cb18b4 swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&) + 3364
15 swift-frontend           0x0000000102e1d118 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 4700
16 swift-frontend           0x0000000102e64e28 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 176
17 swift-frontend           0x0000000102e26010 swift::IRGenRequest::OutputType swift::Evaluator::getResultUncached<swift::IRGenRequest, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()>(swift::IRGenRequest const&, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()) + 784
18 swift-frontend           0x0000000102e1fa48 swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 180
19 swift-frontend           0x0000000102830d5c generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>) + 156
20 swift-frontend           0x000000010282c588 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*) + 2176
21 swift-frontend           0x000000010282b474 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 984
22 swift-frontend           0x000000010282e728 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1680
23 swift-frontend           0x000000010282d458 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
24 swift-frontend           0x00000001027b450c swift::mainEntry(int, char const**) + 3680
25 dyld                     0x0000000194123154 start + 2476
ADKaster commented 2 months ago

swift discourse post https://forums.swift.org/t/frontend-crash-when-c-library-exports-type-string/74026