csantanapr commented on issue #60: Swift 4.1 issue discovered around Structs with two Strings URL: https://github.com/apache/incubator-openwhisk-runtime-swift/issues/60#issuecomment-389019758 Create the two following files ``` ./Package.swift ./Sources/Action/main.swift ``` Content of `Package.swift` ```swift // swift-tools-version:4.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "Action", products: [ .executable( name: "Action", targets: ["Action"] ) ], targets: [ .target( name: "Action" ) ] ) ``` Create `Sources/Action/main.swift` ```swift import Foundation func _run_main<Out: Encodable>(mainFunction: ( @escaping (Out?, Error?) -> Void) -> Void) { let resultHandler = { (out: Out?, error: Error?) in let encoder = JSONEncoder() do { let jsonData = try encoder.encode(out) let jsonString = String(data: jsonData, encoding: .utf8) print("\(jsonString!)") } catch { print("{\"error\":\"Error encoding result\"}") } } let _ = mainFunction(resultHandler) } struct Output: Codable { let greeting: String let group: String } func main(completion: (Output?, Error?) -> Void) -> Void { let result = Output(greeting: "Hello OpenWhisk!", group: "Avoid") completion(result, nil) } _run_main(mainFunction:main) ``` Use Swift Docker image to compile ``` docker run --rm -it -v $(pwd):/owexec swift:4.1 bash root@15fe743675c1:/# cd /owexec ``` Try to compile in debug mode ``` root@15fe743675c1:/owexec# swift build Compile Swift Module 'Action' (1 sources) Linking ./.build/x86_64-unknown-linux/debug/Action ``` As you can see no issues Then try to compile in release mode ``` root@15fe743675c1:/owexec# swift build -c release Compile Swift Module 'Action' (1 sources) swift: /home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/lib/IRGen/IRGenSIL.cpp:1928: void emitApplyArgument((anonymous namespace)::IRGenSILFunction &, swift::SILValue, swift::SILType, swift::irgen::Explosion &): Assertion `arg->getType().isObject()' failed. /usr/bin/swift[0x3f24d54] /usr/bin/swift[0x3f25096] /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7f721a60d390] /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x38)[0x7f7218d4c428] /lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7f7218d4e02a] /lib/x86_64-linux-gnu/libc.so.6(+0x2dbd7)[0x7f7218d44bd7] /lib/x86_64-linux-gnu/libc.so.6(+0x2dc82)[0x7f7218d44c82] /usr/bin/swift[0x5f2bd1] /usr/bin/swift[0x5f1873] /usr/bin/swift[0x5d6202] /usr/bin/swift[0x5d3cfb] /usr/bin/swift[0x4e5ae5] /usr/bin/swift[0x5ac229] /usr/bin/swift[0x4c3780] /usr/bin/swift[0x4beecc] /usr/bin/swift[0x4778c4] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f7218d37830] /usr/bin/swift[0x475179] Stack dump: 0. Program arguments: /usr/bin/swift -frontend -c /owexec/Sources/Action/main.swift -target x86_64-unknown-linux -disable-objc-interop -sdk / -I /owexec/.build/x86_64-unknown-linux/release -module-cache-path /owexec/.build/x86_64-unknown-linux/release/ModuleCache -swift-version 4 -O -D SWIFT_PACKAGE -color-diagnostics -emit-module-doc-path /owexec/.build/x86_64-unknown-linux/release/Action.swiftdoc -module-name Action -emit-module-path /owexec/.build/x86_64-unknown-linux/release/Action.swiftmodule -emit-dependencies-path /owexec/.build/x86_64-unknown-linux/release/Action.build/Action.d -num-threads 4 -o /owexec/.build/x86_64-unknown-linux/release/Action.build/main.swift.o 1. While emitting IR SIL function "@main". <unknown>:0: error: unable to execute command: Aborted <unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation) error: terminated(1): /usr/bin/swift-build-tool -f /owexec/.build/release.yaml main output: ``` Now try to workaround by compiling with Optimization off, and compiles with no errors ``` root@15fe743675c1:/owexec# swift build -c release -Xswiftc -Onone Compile Swift Module 'Action' (1 sources) Linking ./.build/x86_64-unknown-linux/release/Action ```
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services