A bit further update... For the sake of trying it, I changed my standard library to really force inlining on the method that was being lowered and causing the assertion failure...
@_transparent // unsafe-performance
public var baseAddress: UnsafeMutablePointer<Element>? {
return _position
}
Changed from @inlinable
to @_transparent
, which shouldn't make any difference in Swift Embedded mode but it stopped the crash! And instead it asserted somewhere else...
0. Program arguments: /Users/petoc01/Documents/Code/swift/build/Ninja-DebugAssert+stdlib-ReleaseAssert/swift-macosx-x86_64/bin/swift-frontend -frontend -emit-bc serials.swift utils.swift i2c.swift spi.swift asyncs.swift timers.swift stringBuffer.swift stringOther.swift version.swift -supplementary-output-file-map /var/folders/p9/dy3nmf315svbkqpz9z78jxmc0000gn/T/supplementaryOutputs-df6284 -target avr-atmel-linux-gnueabihf -disable-objc-interop -color-diagnostics -I ../uSwift/bin/AVR -I ../uSwift -I . -I AVR/bin -I "/Applications/Swift For Arduino.app/Contents/XPCServices/BuildEngine.xpc/Contents/Resources/gpl-tools-avr/lib/avr-libgcc/include" -I "/Applications/Swift For Arduino.app/Contents/XPCServices/BuildEngine.xpc/Contents/Resources/gpl-tools-avr/lib/avr-libc/include" -enable-experimental-feature Embedded -import-underlying-module -nostdimport -enforce-exclusivity=unchecked -Osize -D AVR_LIBC_DEFINED_SWIFT -disable-reflection-metadata -plugin-path /Users/petoc01/Documents/Code/swift/build/Ninja-DebugAssert+stdlib-ReleaseAssert/swift-macosx-x86_64/lib/swift/host/plugins -plugin-path /Users/petoc01/Documents/Code/swift/build/Ninja-DebugAssert+stdlib-ReleaseAssert/swift-macosx-x86_64/local/lib/swift/host/plugins -Xcc -DAVR_LIBC_DEFINED -Xcc -DLIBC_DEFINED -parse-as-library -module-name AVR -num-threads 4 -o bin/serials.bc -o bin/utils.bc -o bin/i2c.bc -o bin/spi.bc -o bin/asyncs.bc -o bin/timers.bc -o bin/stringBuffer.bc -o bin/stringOther.bc -o bin/version.bc
1. Swift version 5.11-dev (LLVM 30fc8acdf272b61, Swift 28672100783c417)
2. Compiling with the current language version
3. While emitting IR SIL function "@$s3AVR5print6buffer10addNewlineyAA15AVRStringBufferV_SbtF".
for 'print(buffer:addNewline:)' (at serials.swift:88:8)
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 0x000000010c037ffd llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 61
1 swift-frontend 0x000000010c0384cb PrintStackTraceSignalHandler(void*) + 27
2 swift-frontend 0x000000010c036746 llvm::sys::RunSignalHandlers() + 134
3 swift-frontend 0x000000010c0390ff SignalHandler(int) + 223
4 libsystem_platform.dylib 0x00007ff814e245ed _sigtramp + 29
5 libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603370230561328
6 libsystem_c.dylib 0x00007ff814d1db45 abort + 123
7 libsystem_c.dylib 0x00007ff814d1ce5e err + 0
8 swift-frontend 0x0000000100abdf4d swift::irgen::IRGenerator::addLazyFunction(swift::SILFunction*) + 173
9 swift-frontend 0x0000000100ac1971 swift::irgen::IRGenModule::getAddrOfSILFunction(swift::SILFunction*, swift::ForDefinition_t, bool, bool) + 1809
10 swift-frontend 0x0000000100e578fe (anonymous namespace)::IRGenSILFunction::visitFunctionRefBaseInst(swift::FunctionRefBaseInst*) + 254
11 swift-frontend 0x0000000100e355cd (anonymous namespace)::IRGenSILFunction::visitFunctionRefInst(swift::FunctionRefInst*) + 29
12 swift-frontend 0x0000000100e30587 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 391
13 swift-frontend 0x0000000100e1958e (anonymous namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) + 1422
14 swift-frontend 0x0000000100e0e457 (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 2791
15 swift-frontend 0x0000000100e0d898 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 328
16 swift-frontend 0x0000000100aba805 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&) + 1397
17 swift-frontend 0x0000000100d09782 performParallelIRGeneration(swift::IRGenDescriptor) + 1218
18 swift-frontend 0x0000000100d0917a swift::performIRGeneration(swift::ModuleDecl*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, llvm::GlobalVariable**) + 554
19 swift-frontend 0x0000000100178b2e 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>>>) + 542
20 swift-frontend 0x0000000100172bb3 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*) + 2179
21 swift-frontend 0x0000000100171c64 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 388
22 swift-frontend 0x00000001001a1413 performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*)::$_30::operator()(swift::CompilerInstance&) const + 147
23 swift-frontend 0x00000001001a136d bool llvm::function_ref<bool (swift::CompilerInstance&)>::callback_fn<performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*)::$_30>(long, swift::CompilerInstance&) + 29
24 swift-frontend 0x00000001001a0731 llvm::function_ref<bool (swift::CompilerInstance&)>::operator()(swift::CompilerInstance&) const + 33
25 swift-frontend 0x000000010019f798 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 392
26 swift-frontend 0x0000000100198105 performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1349
27 swift-frontend 0x0000000100175086 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 262
28 swift-frontend 0x0000000100173a66 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2822
29 swift-frontend 0x0000000100046324 run_driver(llvm::StringRef, llvm::ArrayRef<char const*>, llvm::ArrayRef<char const*>) + 388
This time the function being lowered is...
(lldb) e fn->dump()
// FixedWidthInteger.bitWidth.getter
sil @$ss17FixedWidthIntegerPsE03bitB0Sivg : $@convention(method) <Self where Self : FixedWidthInteger> (@in_guaranteed Self) -> Int {
bb0(%0 : $*Self):
%1 = metatype $@thick Self.Type // user: %3
%2 = witness_method $Self, #FixedWidthInteger.bitWidth!getter : <Self where Self : FixedWidthInteger> (Self.Type) -> () -> Int : $@convention(witness_method: FixedWidthInteger) <τ_0_0 where τ_0_0 : FixedWidthInteger> (@thick τ_0_0.Type) -> Int // user: %3
%3 = apply %2<Self>(%1) : $@convention(witness_method: FixedWidthInteger) <τ_0_0 where τ_0_0 : FixedWidthInteger> (@thick τ_0_0.Type) -> Int // user: %4
return %3 : $Int // id: %4
} // end sil function '$ss17FixedWidthIntegerPsE03bitB0Sivg'
I moved up a few frames to try and get some context. this is the SIL that's being lowered in IRGen and causing the crash. Again, it seems wrong to me because the bitWidth
getter should have been inlined by the SIL Optimiser long before it reached IRGen shouldn't it?
SWITCH TO FRAME 15
(lldb) e f->dump()
// print(buffer:addNewline:)
sil @$s3AVR5print6buffer10addNewlineyAA15AVRStringBufferV_SbtF : $@convention(thin) (AVRStringBuffer, Bool) -> () {
// %0 "stringBuffer" // users: %4, %58, %2
// %1 "addNewline" // users: %70, %3
bb0(%0 : $AVRStringBuffer, %1 : $Bool):
debug_value %0 : $AVRStringBuffer, let, name "stringBuffer", argno 1 // id: %2
debug_value %1 : $Bool, let, name "addNewline", argno 2 // id: %3
%4 = struct_extract %0 : $AVRStringBuffer, #AVRStringBuffer.buffer // user: %5
%5 = struct_extract %4 : $UnsafeMutableBufferPointer<Int8>, #UnsafeMutableBufferPointer._position // user: %6
switch_enum %5 : $Optional<UnsafeMutablePointer<Int8>>, case #Optional.some!enumelt: bb2, case #Optional.none!enumelt: bb1 // id: %6
bb1: // Preds: bb0
br bb13 // id: %7
// %8 // user: %9
bb2(%8 : $UnsafeMutablePointer<Int8>): // Preds: bb0
%9 = struct_extract %8 : $UnsafeMutablePointer<Int8>, #UnsafeMutablePointer._rawValue // users: %10, %56
%10 = builtin "ptrtoint_Word"(%9 : $Builtin.RawPointer) : $Builtin.Word // user: %11
%11 = builtin "truncOrBitCast_Word_Int16"(%10 : $Builtin.Word) : $Builtin.Int16 // users: %53, %34, %51, %13, %15
%12 = integer_literal $Builtin.Int16, 0 // users: %51, %13
%13 = builtin "cmp_slt_Int16"(%11 : $Builtin.Int16, %12 : $Builtin.Int16) : $Builtin.Int1 // user: %14
cond_br %13, bb4, bb3 // id: %14
bb3: // Preds: bb2
%15 = struct $Int (%11 : $Builtin.Int16) // users: %38, %19
%16 = integer_literal $Builtin.Int8, 0 // users: %54, %35, %17
%17 = struct $UInt8 (%16 : $Builtin.Int8) // users: %41, %23
%18 = alloc_stack [lexical] $Int // users: %19, %29, %21
store %15 to %18 : $*Int // id: %19
// function_ref FixedWidthInteger.bitWidth.getter
%20 = function_ref @$ss17FixedWidthIntegerPsE03bitB0Sivg : $@convention(method) <τ_0_0 where τ_0_0 : FixedWidthInteger> (@in_guaranteed τ_0_0) -> Int // users: %42, %39, %24, %21
%21 = apply %20<Int>(%18) : $@convention(method) <τ_0_0 where τ_0_0 : FixedWidthInteger> (@in_guaranteed τ_0_0) -> Int // user: %25
%22 = alloc_stack [lexical] $UInt8 // users: %23, %28, %24
store %17 to %22 : $*UInt8 // id: %23
%24 = apply %20<UInt8>(%22) : $@convention(method) <τ_0_0 where τ_0_0 : FixedWidthInteger> (@in_guaranteed τ_0_0) -> Int // user: %26
%25 = struct_extract %21 : $Int, #Int._value // user: %27
%26 = struct_extract %24 : $Int, #Int._value // user: %27
%27 = builtin "cmp_slt_Int16"(%25 : $Builtin.Int16, %26 : $Builtin.Int16) : $Builtin.Int1 // user: %30
dealloc_stack %22 : $*UInt8 // id: %28
dealloc_stack %18 : $*Int // id: %29
cond_br %27, bb7, bb8 // id: %30
bb4: // Preds: bb2
br bb12 // id: %31
bb5: // Preds: bb9
br bb12 // id: %32
bb6: // Preds: bb9
br bb13 // id: %33
bb7: // Preds: bb3
%34 = builtin "truncOrBitCast_Int16_Int8"(%11 : $Builtin.Int16) : $Builtin.Int8 // user: %35
%35 = builtin "cmp_eq_Int8"(%34 : $Builtin.Int8, %16 : $Builtin.Int8) : $Builtin.Int1 // user: %36
br bb9(%35 : $Builtin.Int1) // id: %36
bb8: // Preds: bb3
%37 = alloc_stack [lexical] $Int // users: %38, %47, %39
store %15 to %37 : $*Int // id: %38
%39 = apply %20<Int>(%37) : $@convention(method) <τ_0_0 where τ_0_0 : FixedWidthInteger> (@in_guaranteed τ_0_0) -> Int // user: %44
%40 = alloc_stack [lexical] $UInt8 // users: %41, %46, %42
store %17 to %40 : $*UInt8 // id: %41
%42 = apply %20<UInt8>(%40) : $@convention(method) <τ_0_0 where τ_0_0 : FixedWidthInteger> (@in_guaranteed τ_0_0) -> Int // user: %43
%43 = struct_extract %42 : $Int, #Int._value // user: %45
%44 = struct_extract %39 : $Int, #Int._value // user: %45
%45 = builtin "cmp_slt_Int16"(%43 : $Builtin.Int16, %44 : $Builtin.Int16) : $Builtin.Int1 // user: %48
dealloc_stack %40 : $*UInt8 // id: %46
dealloc_stack %37 : $*Int // id: %47
cond_br %45, bb10, bb11 // id: %48
// %49 // user: %50
bb9(%49 : $Builtin.Int1): // Preds: bb11 bb10 bb7
cond_br %49, bb6, bb5 // id: %50
bb10: // Preds: bb8
%51 = builtin "cmp_eq_Int16"(%11 : $Builtin.Int16, %12 : $Builtin.Int16) : $Builtin.Int1 // user: %52
br bb9(%51 : $Builtin.Int1) // id: %52
bb11: // Preds: bb8
%53 = builtin "truncOrBitCast_Int16_Int8"(%11 : $Builtin.Int16) : $Builtin.Int8 // user: %54
%54 = builtin "cmp_eq_Int8"(%53 : $Builtin.Int8, %16 : $Builtin.Int8) : $Builtin.Int1 // user: %55
br bb9(%54 : $Builtin.Int1) // id: %55
bb12: // Preds: bb5 bb4
%56 = struct $UnsafePointer<Int8> (%9 : $Builtin.RawPointer) // users: %57, %70
debug_value %56 : $UnsafePointer<Int8>, let, name "buffer" // id: %57
%58 = struct_extract %0 : $AVRStringBuffer, #AVRStringBuffer.currentIndex // user: %59
%59 = struct_extract %58 : $Int, #Int._value // users: %66, %61
%60 = alloc_stack $UInt // users: %64, %62, %65
%61 = struct $UInt (%59 : $Builtin.Int16) // user: %62
store %61 to %60 : $*UInt // id: %62
// function_ref FixedWidthInteger.bitWidth.getter
%63 = function_ref @$ss17FixedWidthIntegerPsE03bitB0Sivg : $@convention(method) <τ_0_0 where τ_0_0 : FixedWidthInteger> (@in_guaranteed τ_0_0) -> Int // user: %64
%64 = apply %63<UInt>(%60) : $@convention(method) <τ_0_0 where τ_0_0 : FixedWidthInteger> (@in_guaranteed τ_0_0) -> Int
dealloc_stack %60 : $*UInt // id: %65
%66 = struct $UInt16 (%59 : $Builtin.Int16) // user: %70
%67 = integer_literal $Builtin.Int1, 0 // user: %68
%68 = struct $Bool (%67 : $Builtin.Int1) // user: %70
// function_ref _sendBuffer
%69 = function_ref @_sendBuffer : $@convention(c) (UInt16, UnsafePointer<Int8>, Bool, Bool) -> () // user: %70
%70 = apply %69(%66, %56, %1, %68) : $@convention(c) (UInt16, UnsafePointer<Int8>, Bool, Bool) -> ()
br bb13 // id: %71
bb13: // Preds: bb1 bb6 bb12
%72 = tuple () // user: %73
return %72 : $() // id: %73
} // end sil function '$s3AVR5print6buffer10addNewlineyAA15AVRStringBufferV_SbtF'
Hoping this gives a bit more context on what I'm doing wrong?
Might -Osize
be contributing to the problem?
Tagging @kubamracek to see if he's got any ideas too?
Thanks for any help you can give.
Regards,
Carl