Open
Description
Description
Compiler fails with
Command SwiftCompile failed with a nonzero exit code
When changing one line of code
Reproduction
Changing
@inlinable
static func _getFixedSizeCArrayAssumed<T, R>(source:T, boundToType:R.Type, withCount count:N? = nil) -> [R] {
return Swift.withUnsafeBytes(of: source) { (rawPointer) -> [R] in
let bufferPointer = rawPointer.assumingMemoryBound(to: boundToType)
return [R](bufferPointer)
}
}
to
@inlinable
static func _getFixedSizeCArrayAssumed<each T, R>(source:(repeat each T), boundToType:R.Type) -> [R] {
return Swift.withUnsafeBytes(of: source) { (rawPointer) -> [R] in
let bufferPointer = rawPointer.assumingMemoryBound(to: boundToType)
return [R](bufferPointer)
}
}
Stack dump
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/carlynorama/Developer/GitHub/FixedSizeCollection/Tests/FixedSizeCollectionTests/AccessNProvide.swift -primary-file /Users/carlynorama/Developer/GitHub/FixedSizeCollection/Tests/FixedSizeCollectionTests/InitsNStorage.swift /Users/carlynorama/Developer/GitHub/FixedSizeCollection/Tests/FixedSizeCollectionTests/ReplaceNUpdate.swift /Users/carlynorama/Developer/GitHub/FixedSizeCollection/Tests/FixedSizeCollectionTests/TestingWithC.swift -emit-dependencies-path /Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Intermediates.noindex/FixedSizeCollection.build/Debug/FixedSizeCollectionTests.build/Objects-normal/arm64/InitsNStorage.d -emit-const-values-path /Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Intermediates.noindex/FixedSizeCollection.build/Debug/FixedSizeCollectionTests.build/Objects-normal/arm64/InitsNStorage.swiftconstvalues -emit-reference-dependencies-path /Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Intermediates.noindex/FixedSizeCollection.build/Debug/FixedSizeCollectionTests.build/Objects-normal/arm64/InitsNStorage.swiftdeps -serialize-diagnostics-path /Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Intermediates.noindex/FixedSizeCollection.build/Debug/FixedSizeCollectionTests.build/Objects-normal/arm64/InitsNStorage.dia -target arm64-apple-macos13.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/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Products/Debug -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Products/Debug/PackageFrameworks -F /Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Products/Debug/PackageFrameworks -F /Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Products/Debug/PackageFrameworks -F /Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Products/Debug -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -module-cache-path /Users/carlynorama/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -profile-generate -profile-coverage-mapping -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -package-name fixedsizecollection -const-gather-protocols-file /Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Intermediates.noindex/FixedSizeCollection.build/Debug/FixedSizeCollectionTests.build/Objects-normal/arm64/FixedSizeCollectionTests_const_extract_protocols.json -empty-abi-descriptor -validate-clang-modules-once -clang-build-session-file /Users/carlynorama/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/carlynorama/Developer/GitHub/FixedSizeCollection -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -fmodule-map-file=/Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Intermediates.noindex/GeneratedModuleMaps/TestCSupport.modulemap -Xcc -ivfsstatcache -Xcc /Users/carlynorama/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx14.2-23C53-df0db8920d7ae99241a1bc0f08d2dced.sdkstatcache -Xcc -I/Users/carlynorama/Developer/GitHub/FixedSizeCollection/Sources/TestCSupport/include -Xcc -I/Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Products/Debug/include -Xcc -I/Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Intermediates.noindex/FixedSizeCollection.build/Debug/FixedSizeCollectionTests.build/DerivedSources-normal/arm64 -Xcc -I/Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Intermediates.noindex/FixedSizeCollection.build/Debug/FixedSizeCollectionTests.build/DerivedSources/arm64 -Xcc -I/Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Intermediates.noindex/FixedSizeCollection.build/Debug/FixedSizeCollectionTests.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name FixedSizeCollectionTests -frontend-parseable-output -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/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Build/Intermediates.noindex/FixedSizeCollection.build/Debug/FixedSizeCollectionTests.build/Objects-normal/arm64/InitsNStorage.o -index-unit-output-path /FixedSizeCollection.build/Debug/FixedSizeCollectionTests.build/Objects-normal/arm64/InitsNStorage.o -index-store-path /Users/carlynorama/Library/Developer/Xcode/DerivedData/FixedSizeCollection-aayoergxcfsejqdjlisiseqelvus/Index.noindex/DataStore -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
3. While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/carlynorama/Developer/GitHub/FixedSizeCollection/Tests/FixedSizeCollectionTests/InitsNStorage.swift")
4. While silgen emitFunction SIL function "@$s24FixedSizeCollectionTests13InitsNStorageC17testInitFromTupleyyKF".
for 'testInitFromTuple()' (at /Users/carlynorama/Developer/GitHub/FixedSizeCollection/Tests/FixedSizeCollectionTests/InitsNStorage.swift:64:5)
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 0x000000010320dabc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x0000000105e73cb0 llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x0000000105bdd054 SignalHandler(int) + 352
3 libsystem_platform.dylib 0x0000000182b1ba24 _sigtramp + 56
4 libsystem_pthread.dylib 0x0000000182aeccc0 pthread_kill + 288
5 libsystem_c.dylib 0x00000001829fca40 abort + 180
6 swift-frontend 0x0000000105e35124 std::__1::__shared_ptr_emplace<llvm::vfs::RedirectingFSDirIterImpl, std::__1::allocator<llvm::vfs::RedirectingFSDirIterImpl>>::__on_zero_shared() + 0
7 swift-frontend 0x00000001031ae340 llvm::report_fatal_error(llvm::Twine const&, bool) + 280
8 swift-frontend 0x0000000105d8bc34 clang::CodeGen::ConstantAggregateBuilderBase::getGEPIndicesTo(llvm::SmallVectorImpl<llvm::Constant*>&, unsigned long) const + 0
9 swift-frontend 0x0000000103b39a20 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) (.llvm.10993375518856827296) + 6980
10 swift-frontend 0x0000000101eea9c8 swift::Lowering::Conversion::emit(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::SGFContext) const + 508
11 swift-frontend 0x00000001036c87e4 swift::Lowering::ConvertingInitialization::copyOrInitValueInto(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, bool) + 108
12 swift-frontend 0x00000001034ddd60 void copyOrInitValuesInto<((anonymous namespace)::ImplodeKind)1>(swift::Lowering::Initialization*, llvm::ArrayRef<swift::Lowering::ManagedValue>&, swift::CanType, swift::SILLocation, swift::Lowering::SILGenFunction&) (.llvm.3474676367761844561) + 680
13 swift-frontend 0x000000010340082c swift::Lowering::ArgumentSource::getAsSingleValue(swift::Lowering::SILGenFunction&, swift::Lowering::SGFContext) && + 236
14 swift-frontend 0x00000001036c86c8 swift::Lowering::SILGenFunction::emitConvertedRValue(swift::SILLocation, swift::Lowering::Conversion const&, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>) + 256
15 swift-frontend 0x0000000103401438 swift::Lowering::ArgumentSource::getAsSingleValue(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::SILType, swift::Lowering::SGFContext) && + 360
16 swift-frontend 0x000000010340fa4c swift::Lowering::ArgumentSource::forwardInto(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::Lowering::Initialization*, swift::Lowering::TypeLowering const&) && + 628
17 swift-frontend 0x000000010340d930 swift::Lowering::ArgumentSource::materialize(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::SILType) && + 860
18 swift-frontend 0x000000010362fba4 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, llvm::Optional<swift::AnyFunctionType::Param>) + 2876
19 swift-frontend 0x0000000103634544 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 1088
20 swift-frontend 0x000000010363464c (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 1352
21 swift-frontend 0x000000010362f2f4 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, llvm::Optional<swift::AnyFunctionType::Param>) + 652
22 swift-frontend 0x00000001035b96fc (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, llvm::Optional<swift::AnyFunctionType::Param>) + 224
23 swift-frontend 0x000000010362b224 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 260
24 swift-frontend 0x0000000100d12e80 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, swift::ForeignInfo const&) && + 672
25 swift-frontend 0x0000000101e60880 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&) + 1000
26 swift-frontend 0x00000001035cdc1c (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 4048
27 swift-frontend 0x00000001035ca400 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3072
28 swift-frontend 0x00000001037bced8 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) + 128
29 swift-frontend 0x00000001013454e8 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 1980
30 swift-frontend 0x00000001012b6674 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 140
31 swift-frontend 0x0000000103c2359c swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) (.llvm.4739835489891634100) + 4708
32 swift-frontend 0x00000001038bd300 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 632
33 swift-frontend 0x000000010352d3e4 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 8004
34 swift-frontend 0x0000000101dc8eac emitOrDelayFunction(swift::Lowering::SILGenModule&, swift::SILDeclRef) (.llvm.1309553116846679183) + 168
35 swift-frontend 0x000000010352acd0 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 292
36 swift-frontend 0x0000000103c5c8fc (anonymous namespace)::SILGenType::emitType() (.llvm.10597655668001088627) + 876
37 swift-frontend 0x000000010352a63c swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 104
38 swift-frontend 0x000000010354f600 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 2908
39 swift-frontend 0x0000000103c1ef98 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 200
40 swift-frontend 0x00000001035759ac llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 584
41 swift-frontend 0x00000001057509c4 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1680
42 swift-frontend 0x0000000105754854 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4568
43 swift-frontend 0x00000001057bbd44 swift::mainEntry(int, char const**) + 4408
44 dyld 0x00000001827710e0 start + 2360
Expected behavior
I may in fact be doing something terrible. I would like a better error message ahead of time so I know what specifically is terrible about it.
I have an even riskier function that doesn't like that change either, but it does nicely give me an error message ahead of time even though I don't quite see a clear path to fix it.
(This is not a commonly used function, it's for VERY specific circumstances. )
@inlinable
func _memCopyToTuple<U, R>(tuple: inout U, count:Int, type:R.Type) throws {
precondition(count == self.count)
precondition(type == Element.self)
precondition(MemoryLayout.size(ofValue: tuple) == MemoryLayout<R>.stride * count)
precondition(MemoryLayout.size(ofValue: tuple) == MemoryLayout<R>.stride * self.count)
try Swift.withUnsafeMutablePointer(to: &tuple) { tuplePointer in
precondition(Int(bitPattern: tuplePointer).isMultiple(of: MemoryLayout<R>.alignment))
let _ = try self.withUnsafeBufferPointer { bufferPointer in
//Pack expansion requires that 'each U' and '' have the same shape
//on line below when switch from type erased
memcpy(tuplePointer, bufferPointer?.baseAddress, count * MemoryLayout<R>.stride)
}
}
}
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
Additional information
May be related: #68324