print("hello channel")
Swift version 4.1 (swift-4.1-RELEASE) Target: x86_64-unknown-linux-gnu
hello channel
let hoge = "hoge" dump(hoge)
Swift version 4.1 (swift-4.1-RELEASE) Target: x86_64-unknown-linux-gnu
- "hoge"
print("\n``"+"`\n\n@swiftbot#4647 \n``"+"`swift\nprint(\"hello\")\n
") ```Swift version 4.1 (swift-4.1-RELEASE) Target: x86_64-unknown-linux-gnu
@swiftbot#4647 print("hello")
```print("hoge\n``"+"`\n\n@swiftbot#4647 \n``"+"`swift\nprint(\"hello\")\n``"+"`")
Swift version 4.1 (swift-4.1-RELEASE) Target: x86_64-unknown-linux-gnu
hoge
@swiftbot#4647 print("hello")
```pre texts
@swiftbot
print("hello")
Swift version 4.1 (swift-4.1-RELEASE) Target: x86_64-unknown-linux-gnu
hello
print("hoge\n``"+"`\n\n<@4647> \n``"+"`swift\nprint(\"hello\")\n``"+"`")
Swift version 4.1 (swift-4.1-RELEASE) Target: x86_64-unknown-linux-gnu
hoge
@Unknown
print("hello")
```"+"
\n\n<@!swiftbot> \n`"+"
swift\nprint("hello")\n`"+"
")print("hoge\n``"+"`\n\n<@!swiftbot> \n``"+"`swift\nprint(\"hello\")\n``"+"`")
print("hoge\n``"+"`\n\n<@!swiftbot> \n``"+"`swift\nprint(\"hello\")\n``"+"`")
Swift version 4.1 (swift-4.1-RELEASE) Target: x86_64-unknown-linux-gnu
hoge
<@!swiftbot> print("hello")
```import Foundation
がなくても良いように見えるのが気になってたんですが、これは Fundation
が import
できることを示すためとかでしょうか?Foundation
の何かを使ってたらわかりやすいかもしれません。 round
とかの関数だと使いやすそうです。exec
へ渡している様に見えるのですが、大丈夫ですか? https://github.com/kishikawakatsumi/swift-playground/blob/master/sandbox.js#L56 (edited)Usage: @swiftbot [--version=SWIFT_VERSION] [--command={swift, swiftc}] [--options=SWIFTC_OPTIONS] ``` [Swift Code] ``` @swiftbot versions: show available Swift toolchain versions @swiftbot contribute: show repository URLs @swiftbot help: show help
Usage: @swiftbot [--version=SWIFT_VERSION] [--command={swift, swiftc}] [--options=SWIFTC_OPTIONS] ``` [Swift Code] ``` Examples: @swiftbot ``` print("Hello world!") ``` @swiftbot --version=4.0.3 ``` print("Hello world!") ``` @swiftbot --command=swiftc --options=-dump-parse ``` print("Hello world!") ``` Subcommands: @swiftbot versions: show available Swift toolchain versions @swiftbot contribute: show repository URLs @swiftbot help: show help
let 🐣 = "hiyoko" print("🐣 = \(🐣)")
Swift version 4.1 (swift-4.1-RELEASE)
🐣 = hiyoko
2018-04-04-a 2018-04-03-a 2018-04-02-a 2018-04-01-a 2018-03-31-a 4.1 4.0.3 3.1.1 3.0.2
--version=latest
と--version=stable
というのを使えるようにしました。latest
は最新のスナップショット、stable
は最新のリリースバージョンが動きます。 (edited)func fibonacci(number: Int) -> Int { if number <= 1 { return number } else { return fibonacci(number: number - 1) + fibonacci(number: number - 2) } } print(fibonacci(number: 10))
Swift version 4.2-dev (LLVM 0d52728a8a, Clang b9ad4239d1, Swift a1eb1fe24c)
55
import Foundation func exec(_ cmd: [String]) -> String { let process = Process() process.executableURL = URL(fileURLWithPath: cmd[0]) let pipe = Pipe() process.standardOutput = pipe process.arguments = Array(cmd[1...]) try! process.run() let handle = pipe.fileHandleForReading let data = handle.readDataToEndOfFile() let str = String(data: data, encoding: .utf8) ?? "<binary>" return str } print(exec(["/bin/ls", "-al"]))
Swift version 4.1 (swift-4.1-RELEASE)
/usercode/main.swift:5:5: error: value of type 'Process' has no member 'executableURL' process.executableURL = URL(fileURLWithPath: cmd[0]) ^~~~~~~ ~~~~~~~~~~~~~ /usercode/main.swift:10:10: error: value of type 'Process' has no member 'run' try! process.run() ^~~~~~~ ~~~
import Foundation func exec(_ cmd: [String]) -> String { let process = Process() process.launchPath = cmd[0] let pipe = Pipe() process.standardOutput = pipe process.arguments = Array(cmd[1...]) process.launch() let handle = pipe.fileHandleForReading let data = handle.readDataToEndOfFile() process.waitUntilExit() let str = String(data: data, encoding: .utf8) ?? "<binary>" return str } print(exec(["/bin/ls", "-al"]))
Swift version 4.1 (swift-4.1-RELEASE)
total 76 drwxr-xr-x 1 root root 4096 Apr 5 21:15 . drwxr-xr-x 1 root root 4096 Apr 5 21:15 .. -rwxr-xr-x 1 root root 0 Apr 5 21:15 .dockerenv drwxr-xr-x 1 root root 4096 Apr 1 12:25 bin drwxr-xr-x 2 root root 4096 Apr 12 2016 boot drwxr-xr-x 5 root root 340 Apr 5 21:15 dev drwxr-xr-x 1 root root 4096 Apr 5 21:15 etc drwxr-xr-x 2 root root 4096 Apr 12 2016 home drwxr-xr-x 1 root root 4096 Apr 1 12:26 lib drwxr-xr-x 2 root root 4096 Feb 28 19:14 lib64 drwxr-xr-x 2 root root 4096 Feb 28 19:13 media drwxr-xr-x 2 root root 4096 Feb 28 19:13 mnt drwxr-xr-x 2 root root 4096 Feb 28 19:13 opt dr-xr-xr-x 130 root root 0 Apr 5 21:15 proc drwx------ 2 root root 4096 Feb 28 19:14 root drwxr-xr-x 1 root root 4096 Feb 28 19:14 run drwxr-xr-x 1 root root 4096 Apr 1 12:25 sbin drwxr-xr-x 2 root root 4096 Feb 28 19:13 srv dr-xr-xr-x 13 root root 0 Apr 5 21:15 sys drwxrwxrwt 1 root root 4096 Apr 5 21:15 tmp drwxrwxrwx 2 1000 1000 4096 Apr 5 21:15 usercode drwxr-xr-x 1 root root 4096 Mar 29 21:57 usr drwxr-xr-x 1 root root 4096 Feb 28 19:14 var
import Foundation func exec(_ cmd: [String]) -> String { let process = Process() process.launchPath = cmd[0] let pipe = Pipe() process.standardOutput = pipe process.arguments = Array(cmd[1...]) process.launch() let handle = pipe.fileHandleForReading let data = handle.readDataToEndOfFile() process.waitUntilExit() let str = String(data: data, encoding: .utf8) ?? "<binary>" return str } print(exec(["/bin/cat", ".dockerenv"]))
Swift version 4.1 (swift-4.1-RELEASE)
import Foundation func exec(_ cmd: [String]) -> String { let process = Process() process.launchPath = cmd[0] let pipe = Pipe() process.standardOutput = pipe process.arguments = Array(cmd[1...]) process.launch() let handle = pipe.fileHandleForReading let data = handle.readDataToEndOfFile() process.waitUntilExit() let str = String(data: data, encoding: .utf8) ?? "<binary>" return str } print(exec(["/bin/ls", "-alR", "usercode"]))
Swift version 4.1 (swift-4.1-RELEASE)
usercode: total 20 drwxrwxrwx 2 1000 1000 4096 Apr 5 21:16 . drwxr-xr-x 1 root root 4096 Apr 5 21:16 .. -rw-r--r-- 1 root root 0 Apr 5 21:16 errors -rw-r--r-- 1 root root 0 Apr 5 21:16 log -rw-rw-r-- 1 1000 1000 483 Apr 5 21:16 main.swift -rwxrwxr-x 1 1000 1000 164 Apr 5 21:16 script.sh -rw-r--r-- 1 root root 71 Apr 5 21:16 version
import Foundation func exec(_ cmd: [String]) -> String { let process = Process() process.launchPath = cmd[0] let pipe = Pipe() process.standardOutput = pipe process.arguments = Array(cmd[1...]) process.launch() let handle = pipe.fileHandleForReading let data = handle.readDataToEndOfFile() process.waitUntilExit() let str = String(data: data, encoding: .utf8) ?? "<binary>" return str } print(exec(["/bin/cat", "usercode/script.sh"]))
Swift version 4.1 (swift-4.1-RELEASE)
#!/bin/bash swift --version > /usercode/version exec 1> "/usercode/log" exec 2> "/usercode/errors" $@ /usercode/main.swift mv /usercode/log /usercode/completed
import Foundation let semaphore = DispatchSemaphore(value: 0) let url = URL(string: "http://httpbin.org/get")! let task = URLSession.shared.dataTask(with: url) { (data, response, error) in defer{ semaphore.signal() } if let error = error { print(error) return } print(response!.url!) print(String(data: data!, encoding: .utf8)!) }; task.resume() semaphore.wait()
Swift version 4.1 (swift-4.1-RELEASE)
http://httpbin.org/get { "args": {}, "headers": { "Accept": "*/*", "Accept-Encoding": "deflate, gzip", "Accept-Language": "en", "Connection": "close", "Host": "httpbin.org", "User-Agent": "swift (unknown version) curl/7.47.0" }, "origin": "138.68.23.220", "url": "http://httpbin.org/get" }
print(“hello iPad”)
Swift version 4.1 (swift-4.1-RELEASE)
/usercode/main.swift:1:20: error: unicode curly quote found, replace with '"' print(“hello iPad”) /usercode/main.swift:1:7: error: unicode curly quote found, replace with '"' print(“hello iPad”)
print("hello from iPad")
Swift version 4.1 (swift-4.1-RELEASE)
hello from iPad
if true { print("hello") }
Swift version 4.1 (swift-4.1-RELEASE)
if true { print("hello") }
import Foundation let semaphore = DispatchSemaphore(value: 0) let url = URL(string: "http://httpbin.org/get")! let task = URLSession.shared.dataTask(with: url) { (data, response, error) in defer{ semaphore.signal() } if let error = error { print(error) return } print(response!.url!) print(String(data: data!, encoding: .utf8)!) }; task.resume() semaphore.wait()
Swift version 4.1 (swift-4.1-RELEASE)
URLError(_nsError: Could not resolve host: httpbin.org)
import SwiftyMath
Swift version 4.1 (swift-4.1-RELEASE)
/usercode/main.swift:1:8: error: no such module 'SwiftyMath' import SwiftyMath ^
import SwiftyMath typealias F5 = IntegerQuotientRing<_5> F5.printAddTable() F5.printMulTable()
Swift version 4.1 (swift-4.1-RELEASE)
+ | 0 1 2 3 4 -------------------------- 0 | 0 1 2 3 4 1 | 1 2 3 4 0 2 | 2 3 4 0 1 3 | 3 4 0 1 2 4 | 4 0 1 2 3 * | 0 1 2 3 4 -------------------------- 0 | 0 0 0 0 0 1 | 0 1 2 3 4 2 | 0 2 4 1 3 3 | 0 3 1 4 2 4 | 0 4 3 2 1
import SwiftyTopology
Swift version 4.1 (swift-4.1-RELEASE)
/usercode/main.swift:1:8: error: no such module 'SwiftyTopology' import SwiftyTopology ^
import SwiftyMath let a = 𝐐(4, 5) // 4/5 let b = 𝐐(3, 2) // 3/2 print(a + b) // 23/10
Swift version 4.1 (swift-4.1-RELEASE)
23/10
import SwiftyMath import SwiftyTopology let S = SimplicialComplex.sphere(dim:3) print(S.detailDescription)
Swift version 4.1 (swift-4.1-RELEASE)
S^3 { 0: v₁, v₂, v₃, v₄, v₀ 1: (v₁, v₂), (v₁, v₃), (v₂, v₃), (v₁, v₄), (v₂, v₄), (v₃, v₄), (v₀, v₂), (v₀, v₃), (v₀, v₄), (v₀, v₁) 2: (v₁, v₂, v₃), (v₁, v₂, v₄), (v₁, v₃, v₄), (v₂, v₃, v₄), (v₀, v₂, v₃), (v₀, v₂, v₄), (v₀, v₃, v₄), (v₀, v₁, v₃), (v₀, v₁, v₄), (v₀, v₁, v₂) 3: (v₁, v₂, v₃, v₄), (v₀, v₂, v₃, v₄), (v₀, v₁, v₃, v₄), (v₀, v₁, v₂, v₄), (v₀, v₁, v₂, v₃) }
import SwiftyMath import SwiftyTopology let S = SimplicialComplex.sphere(dim:3) let H = Homology(S, Int.self) print(H.detailDescription)
Swift version 4.1 (swift-4.1-RELEASE)
H(S^3; 𝐙) = { 0 : 𝐙, [v₄], 1 : 0, [], 2 : 0, [], 3 : 𝐙, [-1(v₀, v₁, v₃, v₄) + -1(v₁, v₂, v₃, v₄) + (v₀, v₁, v₂, v₄) + -1(v₀, v₁, v₂, v₃) + (v₀, v₂, v₃, v₄)] }
import SwiftyMath import SwiftyTopology let S = SimplicialComplex.sphere(dim:3) let H = Homology(S, Int.self) print(H.detailDescription)
Swift version 4.1 (swift-4.1-RELEASE)
H(S^3; 𝐙) = { 0 : 𝐙, [v₄], 1 : 0, [], 2 : 0, [], 3 : 𝐙, [-1(v₁, v₂, v₃, v₄) + -1(v₀, v₁, v₃, v₄) + (v₀, v₁, v₂, v₄) + (v₀, v₂, v₃, v₄) + -1(v₀, v₁, v₂, v₃)] }
'rand()' is unavailable in Swift: Use arc4random
ってでますね…(それで arc4random
にしたんでした) (edited)DESCRIPTION These functions use a cryptographic pseudo-random number generator to generate high quality random bytes very quickly.
drand48()
は使えた。これなら Ubuntu でもビルドできるんですかね?print(drand48())
Swift version 4.1 (swift-4.1-RELEASE)
/usercode/main.swift:1:7: error: use of unresolved identifier 'drand48' print(drand48()) ^~~~~~~
import Foundation print(drand48())
Swift version 4.1 (swift-4.1-RELEASE)
3.90798504668055e-14
import Glibc print(drand48())
Swift version 4.1 (swift-4.1-RELEASE)
3.90798504668055e-14
HISTORY The original version of this random number generator used the RC4 (also known as ARC4) algorithm. In OS X 10.12 it was replaced with the NIST-approved AES cipher, and it may be replaced again in the future as cryptographic techniques advance. A good mnemonic is ``A Replacement Call for Random''.
訳すと RC4(ARC4とも言う)アルゴリズムの実装だけど OS10.12で AESに変わったし、後にまた変わるから、 A Replacement Call For Random の略として覚えると良いよ (edited)import Foundation srand48(time(nil)) print(drand48())
Swift version 4.1 (swift-4.1-RELEASE)
0.918770220204355
import Foundation srand48(time(nil)) print(drand48())
Swift version 4.1 (swift-4.1-RELEASE)
0.272781763532297
private var randInit = false private func rand() -> Double { if !randInit { srand48(time(nil)) randInit = true } return drand48() }
extension Never: ExpressibleByNilLiteral { public init(nilLiteral: ()) { self = unsafeBitCast((), to: Never.self) } } let a: Never = nil print(a)
Swift version 4.1 (swift-4.1-RELEASE)
/usercode/main.swift:9:7: warning: will never be executed print(a) ^ /usercode/main.swift:7:16: note: a call to a never-returning function let a: Never = nil ^ /usercode/main.swift:2:12: warning: will never be executed public init(nilLiteral: ()) { ^ /usercode/main.swift:2:12: note: a call to a never-returning function public init(nilLiteral: ()) { ^ Segmentation fault (core dumped)
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT) * frame #0: 0x00007fffaba7aa9b libobjc.A.dylib`_objc_msgSend_uncached + 11 frame #1: 0x00007fff9865d231 Foundation`-[NSPlaceholderString initWithString:] + 107 frame #2: 0x00000001036ca007 PlaygroundLogger`function signature specialization <Arg[0] = Dead> of static PlaygroundLogger.LoggingPolicyStack.get() -> PlaygroundLogger.LoggingPolicyStack + 151 frame #3: 0x00000001036c3f22 PlaygroundLogger`function signature specialization <Arg[1] = Owned To Guaranteed and Exploded> of playground_log_hidden + 98 frame #4: 0x00000001036c365b PlaygroundLogger`playground_log_hidden + 27 frame #5: 0x00000001041db0a7 $__lldb_expr158`Never.init(nilLiteral=() @ scalar) at MyPlayground.playground:4
extension Never: ExpressibleByNilLiteral { public init(nilLiteral: ()) { self = unsafeBitCast((), to: Never.self) print("わいわい") } } let a: Never = nil print(a)
Swift version 4.1 (swift-4.1-RELEASE)
/usercode/main.swift:10:7: warning: will never be executed print(a) ^ /usercode/main.swift:8:16: note: a call to a never-returning function let a: Never = nil ^ /usercode/main.swift:2:12: warning: will never be executed public init(nilLiteral: ()) { ^ /usercode/main.swift:2:12: note: a call to a never-returning function public init(nilLiteral: ()) { ^ /usr/bin/swift[0x3f24d54] /usr/bin/swift[0x3f25096] /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7fa0085a4390] /usr/lib/swift/linux/libswiftCore.so(swift_conformsToProtocol+0x30)[0x7fa004780730] /usr/lib/swift/linux/libswiftCore.so(+0x39c05f)[0x7fa00477205f] /usr/lib/swift/linux/libswiftCore.so(+0x39b82d)[0x7fa00477182d] /usr/lib/swift/linux/libswiftCore.so(+0x2e518a)[0x7fa0046bb18a] Stack dump: 0. Program arguments: /usr/bin/swift -frontend -interpret /usercode/main.swift -disable-objc-interop -I /usr/lib/swift/clang/include/ -I /vendor/SwiftyMath/.build/release/ -I /vendor/swift-package-libbsd/ -module-name main -ldSwiftyMath Segmentation fault (core dumped)
わいわい Playground execution failed: error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=EXC_I386_GPFLT). The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation. * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT) * frame #0: 0x00007fffaba7c64e libobjc.A.dylib`_object_remove_assocations + 24 frame #1: 0x00007fffaba7c603 libobjc.A.dylib`objc_destructInstance + 105 frame #2: 0x000000011048e398 libswiftCore.dylib`swift_deallocClassInstance + 24 frame #3: 0x000000011048e2f0 libswiftCore.dylib`_swift_release_dealloc + 16 frame #4: 0x000000010e437012 PlaygroundLogger`function signature specialization <Arg[0] = Dead> of static PlaygroundLogger.LoggingPolicyStack.get() -> PlaygroundLogger.LoggingPolicyStack + 162 frame #5: 0x000000010e430f22 PlaygroundLogger`function signature specialization <Arg[1] = Owned To Guaranteed and Exploded> of playground_log_hidden + 98 frame #6: 0x000000010e43065b PlaygroundLogger`playground_log_hidden + 27 frame #7: 0x000000010e4680af $__lldb_expr160`Never.init(nilLiteral=() @ scalar) at MyPlayground.playground:4
var foo: Foo { return x }
と func foo() -> Foo { return x }
の扱いが、前者はフィールドとして定義されているのでunsafeBitCastしても同じものが呼ばれるが、後者は実質的には第一引数にselfを与えるstatic funcなのでunsafeBitCastで違うものが呼ばれる、とか。var foo: Foo { return x }
じゃなくて let foo: Foo = x
だった。struct Cat { let face: String = "😺" func bark() -> String { return "にゃーん" } } struct Dog { let face: String = "🐶" func bark() -> String { return "わんわん" } } let cat = unsafeBitCast(Dog(), to: Cat.self) print(cat.face) print(cat.bark())
Swift version 4.1 (swift-4.1-RELEASE)
🐶 にゃーん
struct Cat { let face: String = "😺" func bark() -> String { return "\(face): にゃーん" } } struct Dog { let face: String = "🐶" func bark() -> String { return "\(face): わんわん" } } let cat = unsafeBitCast(Dog(), to: Cat.self) print(cat.face) print(cat.bark())
Swift version 4.1 (swift-4.1-RELEASE)
🐶 🐶: にゃーん
struct Cat { let face: String = "😺" func bark() -> String { return "\(face): にゃーん" } } struct Dog { let face: String = "🐶" func bark() -> String { return "\(face): わんわん" } } let cat = unsafeBitCast(Dog(), to: Cat.self) print(cat.bark())
Swift version 4.1 (swift-4.1-RELEASE)
🐶: にゃーん
cat.
の型に関係なく固定でcat用のメソッドが呼ばれてますね (edited)struct One { let one = 1 } struct OneTwoThree { let one = 1 let two = 2 let three = 3 } print(MemoryLayout.size(ofValue: One())) print(MemoryLayout.size(ofValue: OneTwoThree()))
Swift version 4.1 (swift-4.1-RELEASE)
8 24
struct Cat { let age: Int = 3 init() { self.age = 5 } } print(Cat())
Swift version 4.1 (swift-4.1-RELEASE)
/usercode/main.swift:5:18: error: immutable value 'self.age' may only be initialized once self.age = 5 ^ /usercode/main.swift:2:9: note: initial value already provided in 'let' declaration let age: Int = 3 ^ /usercode/main.swift:2:5: note: change 'let' to 'var' to make it mutable let age: Int = 3 ^~~ var
docker-compose
使ってローカルのDockerで岸川さんのswift-playgroundを実行できる様になった。docker-compose.yml
version: '3' services: playground: build: . environment: HOST_PWD: ${PWD} ports: - "80:8080" volumes: - /var/run/docker.sock:/var/run/docker.sock - .:/playground command: ["sh", "-c", "npm install && npm start"]
Dockerfile
FROM docker:latest RUN apk --update add bash nodejs && rm -rf /var/cache/apk/* WORKDIR /playground
HOST_PWD
にホストのディレクトリを持たせ、それをsandboxに渡してます。run.sh
の起動は/playground/run.sh 30 -v /Users/norio/github/swift-playground/temp/6e4fd5db976425e7d17a:/usercode -v /playground/vendor:/vendor:ro norionomura/swiftlint:swift-4.1 sh /usercode/script.sh swift
な感じに。docker:dind
にすればホストのパスは要らないけど、docker:dind
だとホストの/var/lib/docker/volumes
にデータが溜まっていくらしく、それを避けたかった。HOST_PWD
の自動取得くらいにしかdocker-compose
を活かせてないですね。options
がexec
へ文字列結合されて渡されてるところが心配。options="; docker run -v /:/host_root ubuntu cat /host_root/etc/passwd;"
とかすると、そのまま実行されてしまわないかな?docker pull norionomura/swiftlint:swift-4.1 # 利用するswiftイメージをあらかじめpull git clone https://github.com/norio-nomura/swift-playground.git -b docker-compose cd swift-playground docker-compose up
してブラウザで http://localhost を開く。func hoge() -> Never { return unsafeBitCast((), to: Never.self) } let voidNever = unsafeBitCast((), to: Never.self) // ① guard 1 == 0 else { hoge() } print("hello")
Swift version 4.1 (swift-4.1-RELEASE)
/usercode/main.swift:11:7: warning: will never be executed print("hello") ^ /usercode/main.swift:7:7: note: condition always evaluates to false guard 1 == 0 else { ^ Fatal error: Can't unsafeBitCast between types of different sizes Current stack trace: 0 libswiftCore.so 0x00007fcacbd63750 _swift_stdlib_reportFatalError + 171 1 libswiftCore.so 0x00007fcacbad1ad6 <unavailable> + 1366742 2 libswiftCore.so 0x00007fcacbd0c383 <unavailable> + 3703683 3 libswiftCore.so 0x00007fcacbad1ad6 <unavailable> + 1366742 4 libswiftCore.so 0x00007fcacbc3dd80 <unavailable> + 2858368 5 libswiftCore.so 0x00007fcacbad16b0 _fatalErrorMessage(_:_:file:line:flags:) + 19 7 swift 0x0000000000fed1ce <unavailable> + 12505550 8 swift 0x0000000000ff1692 <unavailable> + 12523154 9 swift 0x00000000004d9076 <unavailable> + 888950 10 swift 0x00000000004c35d3 <unavailable> + 800211 11 swift 0x00000000004beecc <unavailable> + 782028 12 swift 0x00000000004778c4 <unavailable> + 489668 13 libc.so.6 0x00007fcace27c740 __libc_start_main + 240 14 swift 0x0000000000475179 <unavailable> + 479609 /usr/bin/swift[0x3f24d54] /usr/bin/swift[0x3f25096] /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7fcacfb52390] /usr/lib/swift/linux/libswiftCore.so(+0x2b9d80)[0x7fcacbc3dd80] /usr/lib/swift/linux/libswiftCore.so(_T0s18_fatalErrorMessages5NeverOs12StaticStringV_A2E4fileSu4lines6UInt32V5flagstF+0x13)[0x7fcacbad16c3] [0x7fcacff820ec] /usr/bin/swift[0xfed1ce] /usr/bin/swift[0xff1692] /usr/bin/swift[0x4d9076] /usr/bin/swift[0x4c35d3] /usr/bin/swift[0x4beecc] /usr/bin/swift[0x4778c4] ...
func hoge() -> Never { return unsafeBitCast((), to: Never.self) } let voidNever = unsafeBitCast((), to: Never.self) // ① //guard 1 == 0 else { // hoge() //} print("hello")
Swift version 4.1 (swift-4.1-RELEASE)
hello
func hoge() -> Never { return unsafeBitCast((), to: Never.self) } let voidNever = unsafeBitCast((), to: Never.self) // ① hoge() print("hello")
Swift version 4.1 (swift-4.1-RELEASE)
/usercode/main.swift:9:7: warning: will never be executed print("hello") ^ /usercode/main.swift:7:1: note: a call to a never-returning function hoge() ^ Fatal error: Can't unsafeBitCast between types of different sizes Current stack trace: 0 libswiftCore.so 0x00007fc5595c8750 _swift_stdlib_reportFatalError + 171 1 libswiftCore.so 0x00007fc559336ad6 <unavailable> + 1366742 2 libswiftCore.so 0x00007fc559571383 <unavailable> + 3703683 3 libswiftCore.so 0x00007fc559336ad6 <unavailable> + 1366742 4 libswiftCore.so 0x00007fc5594a2d80 <unavailable> + 2858368 5 libswiftCore.so 0x00007fc5593366b0 _fatalErrorMessage(_:_:file:line:flags:) + 19 7 swift 0x0000000000fed1ce <unavailable> + 12505550 8 swift 0x0000000000ff1692 <unavailable> + 12523154 9 swift 0x00000000004d9076 <unavailable> + 888950 10 swift 0x00000000004c35d3 <unavailable> + 800211 11 swift 0x00000000004beecc <unavailable> + 782028 12 swift 0x00000000004778c4 <unavailable> + 489668 13 libc.so.6 0x00007fc55bae1740 __libc_start_main + 240 14 swift 0x0000000000475179 <unavailable> + 479609 /usr/bin/swift[0x3f24d54] /usr/bin/swift[0x3f25096] /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7fc55d3b7390] /usr/lib/swift/linux/libswiftCore.so(+0x2b9d80)[0x7fc5594a2d80] /usr/lib/swift/linux/libswiftCore.so(_T0s18_fatalErrorMessages5NeverOs12StaticStringV_A2E4fileSu4lines6UInt32V5flagstF+0x13)[0x7fc5593366c3] [0x7fc55d7e708c] /usr/bin/swift[0xfed1ce] /usr/bin/swift[0xff1692] /usr/bin/swift[0x4d9076] /usr/bin/swift[0x4c35d3] /usr/bin/swift[0x4beecc] /usr/bin/swift[0x4778c4] ...
let voidNever = unsafeBitCast((), to: Never.self) // ① print("hello")
Swift version 4.1 (swift-4.1-RELEASE)
hello
func f() { let voidNever = unsafeBitCast((), to: Never.self) // ① print("hello") } f()
Swift version 4.1 (swift-4.1-RELEASE)
hello
/usercode/main.swift:2:5: warning: initialization of immutable value 'voidNever' was never used; consider replacing with assignment to '_' or removing it let voidNever = unsafeBitCast((), to: Never.self) // ①
Usage: @swiftbot [--version=SWIFT_VERSION] [--command={swift, swiftc}] [--options=SWIFTC_OPTIONS] ``` [Swift Code] ``` Examples: @swiftbot ``` print("Hello world!") ``` @swiftbot --version=4.0.3 ``` print("Hello world!") ``` @swiftbot --command=swiftc --options=-dump-parse ``` print("Hello world!") ``` Subcommands: @swiftbot versions: show available Swift toolchain versions @swiftbot contribute: show repository URLs @swiftbot help: show help
func hoge() -> Never { return unsafeBitCast((), to: Never.self) // 落ちるならこっちじゃないの } _ = unsafeBitCast((), to: Never.self) // ここで落ちる hoge()
Swift version 4.1 (swift-4.1-RELEASE)
Fatal error: Can't unsafeBitCast between types of different sizes Current stack trace: 0 libswiftCore.so 0x00007f380f961750 _swift_stdlib_reportFatalError + 171 1 libswiftCore.so 0x00007f380f6cfad6 <unavailable> + 1366742 2 libswiftCore.so 0x00007f380f90a383 <unavailable> + 3703683 3 libswiftCore.so 0x00007f380f6cfad6 <unavailable> + 1366742 4 libswiftCore.so 0x00007f380f83bd80 <unavailable> + 2858368 5 libswiftCore.so 0x00007f380f6cf6b0 _fatalErrorMessage(_:_:file:line:flags:) + 19 7 swift 0x0000000000fed1ce <unavailable> + 12505550 8 swift 0x0000000000ff1692 <unavailable> + 12523154 9 swift 0x00000000004d9076 <unavailable> + 888950 10 swift 0x00000000004c35d3 <unavailable> + 800211 11 swift 0x00000000004beecc <unavailable> + 782028 12 swift 0x00000000004778c4 <unavailable> + 489668 13 libc.so.6 0x00007f3811e7a740 __libc_start_main + 240 14 swift 0x0000000000475179 <unavailable> + 479609 /usr/bin/swift[0x3f24d54] /usr/bin/swift[0x3f25096] /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7f3813750390] /usr/lib/swift/linux/libswiftCore.so(+0x2b9d80)[0x7f380f83bd80] /usr/lib/swift/linux/libswiftCore.so(_T0s18_fatalErrorMessages5NeverOs12StaticStringV_A2E4fileSu4lines6UInt32V5flagstF+0x13)[0x7f380f6cf6c3] [0x7f3813b80080] /usr/bin/swift[0xfed1ce] /usr/bin/swift[0xff1692] /usr/bin/swift[0x4d9076] /usr/bin/swift[0x4c35d3] /usr/bin/swift[0x4beecc] /usr/bin/swift[0x4778c4] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f3811e7a830] /usr/bin/swift[0x475179] Stack dump: ...
let voidNever = unsafeBitCast((), to: Never.self) // ① print("hello")
(edited)Swift version 4.1 (swift-4.1-RELEASE)
<unknown>:0: error: option '-emit-silgen' is not supported by 'swift'; did you mean to use 'swiftc'?
func hoge() -> Never { print(3) return unsafeBitCast((), to: Never.self) // 落ちるならこっちじゃないの } print(1) _ = unsafeBitCast((), to: Never.self) // ここで落ちる print(2) hoge() print(4)
Swift version 4.1 (swift-4.1-RELEASE)
/usercode/main.swift:10:7: warning: will never be executed print(4) ^ /usercode/main.swift:9:1: note: a call to a never-returning function hoge() ^ Fatal error: Can't unsafeBitCast between types of different sizes Current stack trace: 0 libswiftCore.so 0x00007fecfce05750 _swift_stdlib_reportFatalError + 171 1 libswiftCore.so 0x00007fecfcb73ad6 <unavailable> + 1366742 2 libswiftCore.so 0x00007fecfcdae383 <unavailable> + 3703683 3 libswiftCore.so 0x00007fecfcb73ad6 <unavailable> + 1366742 4 libswiftCore.so 0x00007fecfccdfd80 <unavailable> + 2858368 5 libswiftCore.so 0x00007fecfcb736b0 _fatalErrorMessage(_:_:file:line:flags:) + 19 7 swift 0x0000000000fed1ce <unavailable> + 12505550 8 swift 0x0000000000ff1692 <unavailable> + 12523154 9 swift 0x00000000004d9076 <unavailable> + 888950 10 swift 0x00000000004c35d3 <unavailable> + 800211 11 swift 0x00000000004beecc <unavailable> + 782028 12 swift 0x00000000004778c4 <unavailable> + 489668 13 libc.so.6 0x00007fecff31e740 __libc_start_main + 240 14 swift 0x0000000000475179 <unavailable> + 479609 /usr/bin/swift[0x3f24d54] /usr/bin/swift[0x3f25096] /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7fed00bf4390] /usr/lib/swift/linux/libswiftCore.so(+0x2b9d80)[0x7fecfccdfd80] /usr/lib/swift/linux/libswiftCore.so(_T0s18_fatalErrorMessages5NeverOs12StaticStringV_A2E4fileSu4lines6UInt32V5flagstF+0x13)[0x7fecfcb736c3] [0x7fed010241ae] /usr/bin/swift[0xfed1ce] /usr/bin/swift[0xff1692] /usr/bin/swift[0x4d9076] /usr/bin/swift[0x4c35d3] /usr/bin/swift[0x4beecc] /usr/bin/swift[0x4778c4] ...
let voidNever = unsafeBitCast((), to: Never.self) // ① print("hello")
Swift version 4.1 (swift-4.1-RELEASE)
sil_stage raw import Builtin import Swift import SwiftShims // voidNever sil_global hidden [let] @_T04main9voidNevers0C0Ovp : $Never // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): alloc_global @_T04main9voidNevers0C0Ovp // id: %2 %3 = global_addr @_T04main9voidNevers0C0Ovp : $*Never // user: %10 %4 = tuple () // user: %6 %5 = alloc_stack $() // users: %11, %10, %6 store %4 to [trivial] %5 : $*() // id: %6 %7 = metatype $@thin Never.Type %8 = metatype $@thick Never.Type // user: %10 // function_ref unsafeBitCast<A, B>(_:to:) %9 = function_ref @_T0s13unsafeBitCastq_x_q_m2totr0_lF : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0, @thick τ_0_1.Type) -> @out τ_0_1 // user: %10 %10 = apply %9<(), Never>(%3, %5, %8) : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0, @thick τ_0_1.Type) -> @out τ_0_1 dealloc_stack %5 : $*() // id: %11 %12 = integer_literal $Builtin.Word, 1 // user: %14 // function_ref _allocateUninitializedArray<A>(_:) %13 = function_ref @_T0s27_allocateUninitializedArraySayxG_BptBwlF : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer) // user: %14 %14 = apply %13<Any>(%12) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer) // users: %20, %19, %15 %15 = begin_borrow %14 : $(Array<Any>, Builtin.RawPointer) // users: %19, %18, %16 %16 = tuple_extract %15 : $(Array<Any>, Builtin.RawPointer), 0 // user: %17 %17 = copy_value %16 : $Array<Any> // user: %35 %18 = tuple_extract %15 : $(Array<Any>, Builtin.RawPointer), 1 // user: %21 ...
func hoge() -> Never { return unsafeBitCast((), to: Never.self) } let voidNever = unsafeBitCast((), to: Never.self) // ① hoge() print("hello")
Swift version 4.1 (swift-4.1-RELEASE)
<unknown>:0: error: unknown argument: '--emit-silgen'
func hoge() -> Never { return unsafeBitCast((), to: Never.self) } let voidNever = unsafeBitCast((), to: Never.self) // ① hoge() print("hello")
Swift version 4.1 (swift-4.1-RELEASE)
sil_stage raw import Builtin import Swift import SwiftShims // voidNever sil_global hidden [let] @_T04main9voidNevers0C0Ovp : $Never // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): alloc_global @_T04main9voidNevers0C0Ovp // id: %2 %3 = global_addr @_T04main9voidNevers0C0Ovp : $*Never // user: %10 %4 = tuple () // user: %6 %5 = alloc_stack $() // users: %11, %10, %6 store %4 to [trivial] %5 : $*() // id: %6 %7 = metatype $@thin Never.Type %8 = metatype $@thick Never.Type // user: %10 // function_ref unsafeBitCast<A, B>(_:to:) %9 = function_ref @_T0s13unsafeBitCastq_x_q_m2totr0_lF : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0, @thick τ_0_1.Type) -> @out τ_0_1 // user: %10 %10 = apply %9<(), Never>(%3, %5, %8) : $@convention(thin) <τ_0_0, τ_0_1> (@in τ_0_0, @thick τ_0_1.Type) -> @out τ_0_1 dealloc_stack %5 : $*() // id: %11 // function_ref hoge() %12 = function_ref @_T04main4hoges5NeverOyF : $@convention(thin) () -> Never // user: %13 %13 = apply %12() : $@convention(thin) () -> Never %14 = integer_literal $Builtin.Word, 1 // user: %16 // function_ref _allocateUninitializedArray<A>(_:) %15 = function_ref @_T0s27_allocateUninitializedArraySayxG_BptBwlF : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer) // user: %16 %16 = apply %15<Any>(%14) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer) // users: %22, %21, %17 %17 = begin_borrow %16 : $(Array<Any>, Builtin.RawPointer) // users: %21, %20, %18 %18 = tuple_extract %17 : $(Array<Any>, Builtin.RawPointer), 0 // user: %19 ...
print(MemoryLayout<()>.size) print(MemoryLayout<Never>.size)
Swift version 4.1 (swift-4.1-RELEASE)
0 0
enum Fruit { case apple } print(MemoryLayout<Fruit>.size)
Swift version 4.1 (swift-4.1-RELEASE)
0
func a() { func b(_ a: Int) {} func b(_ a: String) {} }
Swift version 4.1 (swift-4.1-RELEASE)
/usercode/main.swift:3:8: error: definition conflicts with previous value func b(_ a: String) {} ^ /usercode/main.swift:2:8: note: previous definition of 'b' is here func b(_ a: Int) {} ^
print("a")
execFile
でshell
オプションを使わないならサニタイズ不要にも思えます。 https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callbackprotocol Widget { func print() func clone() -> Self } extension Widget { func print() { Swift.print("a widget of type \(Self.self)") } func clone() -> Self { return self } } class Box<Element> : Widget { init(value: Element) { self.contents = value } let contents: Element // Default implementation of print() is OK! // You must define this, or conformance checking fails on Swift 4.0.x: // func clone() -> Self { return self } } class Crate<T> : Box<T> { override init(value: T) { super.init(value: value) } } let c = Crate<Int>(value: 3) c.print() // prints: a widget of type Crate<Int>
Swift version 4.0.3 (swift-4.0.3-RELEASE)
/usercode/main.swift:8:10: error: method 'clone()' in non-final class 'Box<Element>' must return `Self` to conform to protocol 'Widget' func clone() -> Self { return self } ^
protocol Widget { func print() func clone() -> Self } extension Widget { func print() { Swift.print("a widget of type \(Self.self)") } func clone() -> Self { return self } } class Box<Element> : Widget { init(value: Element) { self.contents = value } let contents: Element // Default implementation of print() is OK! // You must define this, or conformance checking fails on Swift 4.0.x: // func clone() -> Self { return self } } class Crate<T> : Box<T> { override init(value: T) { super.init(value: value) } } let c = Crate<Int>(value: 3) c.print() // prints: a widget of type Crate<Int>
Swift version 4.1 (swift-4.1-RELEASE)
a widget of type Crate<Int>
--version=stable...latest
や--version=3...4.1
のように書けたらいいのかな?...
だとその間のバージョンで対応してるもの全部って感じですか?カンマ区切りで明示的な配列指定を想像していましたけど--version="4.0.3, 4.1, latest"
こんな感じかな。 (edited)stable...latest
で上のように展開されるという思い込みと、カンマだとおそらくクオートで囲む必要がありそうで、それを避けたかった感じ。--version=4.0.3,4.1,latest
みたいにスペースなくしても "
っていりますっけ? (edited)--version=4.0.3,4.1
これがいけるとちょっと入力しやすくて嬉しいです[omochi@omochi-iMac-PC43 temp]$ cat a.bash for arg in "$@"; do echo "[$arg]" done [omochi@omochi-iMac-PC43 temp]$ ./a.bash --version=4.0.3,4.1 [--version=4.0.3,4.1]
--x
なのもこのライブラリのデフォルトによります。 https://github.com/kishikawakatsumi/swift-compiler-discord-bot/blob/master/app.js#L87execFile
を使っても、run.sh
の中でどう解釈されるか、によるかも。>サニタイズ要・不要docker run
コマンドの実行をオプションに渡す文字列で止めて、かつそのあとに任意の処理が実行できるんじゃないなということですよね。たぶんできたんじゃないかな。run.sh
とは別のプロセスが起動できそうだと思ったのです。>exec
使用 (edited)script.sh
を実行した上で別途test
ってファイルを作れます。 const exec = require('child_process').exec; const options = "& echo hello>test"; exec(['sh', 'script.sh', [options].join(' ')].join(' '));
join
でつなぐやり方はsandbox.js
で使われてるのと同じ。docker
に入れたnode
で実行しようと考えたきっかけです。execFile
を使えばサニタイズ無くても大丈夫かも? → しかしrun.sh
の中での扱いは大丈夫? といった流れ。 (edited)print("hello, discord!")
Swift version 4.1 (swift-4.1-RELEASE) Target: x86_64-unknown-linux-gnu hello, discord!
swift package generate-xcodeproj
すればXcodeでデバッグできるのがSwiftで書くメリットかな。protocol Widget { func print() func clone() -> Self } extension Widget { func print() { Swift.print("a widget of type \(Self.self)") } func clone() -> Self { return self } } class Box<Element> : Widget { init(value: Element) { self.contents = value } let contents: Element // Default implementation of print() is OK! // You must define this, or conformance checking fails on Swift 4.0.x: // func clone() -> Self { return self } } class Crate<T> : Box<T> { override init(value: T) { super.init(value: value) } } let c = Crate<Int>(value: 3) c.print() // prints: a widget of type Crate<Int>
main.swift:8:10: error: method 'clone()' in non-final class 'Box<Element>' must return `Self` to conform to protocol 'Widget' func clone() -> Self { return self } ^
a widget of type Crate<Int>
enum CustomString: ExpressibleByStringLiteral { typealias StringLiteralType = String init(stringLiteral value: StringLiteralType) { self = "hoge" } } let hoge: CustomString = "fuga" print(hoge)
Swift version 4.1 (swift-4.1-RELEASE)
/usercode/main.swift:8:26: warning: will never be executed let hoge: CustomString = "fuga" ^ /usercode/main.swift:8:26: note: a call to a never-returning function let hoge: CustomString = "fuga" ^ /usercode/main.swift:4:14: warning: will never be executed self = "hoge" ^ /usercode/main.swift:4:16: note: a call to a never-returning function self = "hoge" ^ /usercode/main.swift:3:5: warning: will never be executed init(stringLiteral value: StringLiteralType) { ^ /usercode/main.swift:3:5: note: a call to a never-returning function init(stringLiteral value: StringLiteralType) { ^ /usr/bin/swift[0x3f24d54] /usr/bin/swift[0x3f25096] /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7f8003430390] /usr/lib/swift/linux/libswiftCore.so(_T0S2SBp21_builtinStringLiteral_Bw17utf8CodeUnitCountBi1_7isASCIItcfC+0x4)[0x7f7fff39e424] [0x7f800385f0e4] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] [0x7f800385f0fa] ...
self = "hoge"
がinit(stringLiteral:)
を再起呼び出ししてますね。contents
の最大サイズか。enum CustomString: ExpressibleByStringLiteral { typealias StringLiteralType = String init(stringLiteral value: StringLiteralType) { self = "hoge" } } let hoge: CustomString = "fuga" print(hoge)
main.swift:8:26: warning: will never be executed let hoge: CustomString = "fuga" ^ main.swift:8:26: note: a call to a never-returning function let hoge: CustomString = "fuga" ^ main.swift:4:14: warning: will never be executed self = "hoge" ^ main.swift:4:16: note: a call to a never-returning function self = "hoge" ^ main.swift:3:5: warning: will never be executed init(stringLiteral value: StringLiteralType) { ^ main.swift:3:5: note: a call to a never-returning function init(stringLiteral value: StringLiteralType) { ^ 0 swift 0x0000000003ae91b8 1 swift 0x0000000003ae98f6 2 libpthread.so.0 0x00007f6a35029390 3 libpthread.so.0 0x00007f6a35458058 4 libpthread.so.0 0x00007f6a3545809a 5 libpthread.so.0 0x00007f6a3545809a 6 libpthread.so.0 0x00007f6a3545809a 7 libpthread.so.0 0x00007f6a3545809a 8 libpthread.so.0 0x00007f6a3545809a 9 libpthread.so.0 0x00007f6a3545809a 10 libpthread.so.0 0x00007f6a3545809a 11 libpthread.so.0 0x00007f6a3545809a 12 libpthread.so.0 0x00007f6a3545809a 13 libpthread.so.0 0x00007f6a3545809a 14 libpthread.so.0 0x00007f6a3545809a 15 libpthread.so.0 0x00007f6a3545809a 16 libpthread.so.0 0x00007f6a3545809a 17 libpthread.so.0 0x00007f6a3545809a 18 libpthread.so.0 0x00007f6a3545809a 19 libpthread.so.0 0x00007f6a3545809a 20 libpthread.so.0 0x00007f6a3545809a 21 libpthread.so.0 0x00007f6a3545809a 22 libpthread.so.0 0x00007f6a3545809a 23 libpthread.so.0 0x00007f6a3545809a 24 libpthread.so.0 0x00007f6a3545809a 25 libpthread.so.0 0x00007f6a3545809a 26 libpthread.so.0 0x00007f6a3545809a 27 libpthread.so.0 0x00007f6a3545809a 28 libpthread.so.0 0x00007f6a3545809a 29 libpthread.so.0 0x00007f6a3545809a 30 libpthread.so.0 0x00007f6a3545809a 31 libpthread.so.0 0x00007f6a3545809a 32 libpthread.so.0 0x00007f6a3545809a 33 libpthread.so.0 0x00007f6a3545809a 34 libpthread.so.0 0x0000
main.swift:8:26: warning: will never be executed let hoge: CustomString = "fuga" ^ main.swift:8:26: note: a call to a never-returning function let hoge: CustomString = "fuga" ^ main.swift:4:14: warning: will never be executed self = "hoge" ^ main.swift:4:16: note: a call to a never-returning function self = "hoge" ^ main.swift:3:5: warning: will never be executed init(stringLiteral value: StringLiteralType) { ^ main.swift:3:5: note: a call to a never-returning function init(stringLiteral value: StringLiteralType) { ^ /usr/bin/swift[0x3f24d54] /usr/bin/swift[0x3f25096] /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7f46186b8390] [0x7f4618ae70e2] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae70fa] [0x7f4618ae
import Foundation func execute(_ args: [String], in directory: URL? = nil) -> (stdout: String, stderr: String) { let process = Process() process.launchPath = "/usr/bin/env" process.arguments = args if let directory = directory { process.currentDirectoryPath = directory.path } let stdoutPipe = Pipe(), stderrPipe = Pipe() process.standardOutput = stdoutPipe process.standardError = stderrPipe process.launch() process.waitUntilExit() let stdout = String(data: stdoutPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? "" let stderr = String(data: stderrPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? "" return (stdout, stderr) } execute(["df", "-m"])
main.swift:19:1: warning: result of call to 'execute(_:in:)' is unused execute(["df", "-m"]) ^ ~~~~~~~~~~~~~~
main.swift:19:1: warning: result of call to 'execute(_:in:)' is unused execute(["df", "-m"]) ^ ~~~~~~~~~~~~~~
import Foundation func execute(_ args: [String], in directory: URL? = nil) -> (stdout: String, stderr: String) { let process = Process() process.launchPath = "/usr/bin/env" process.arguments = args if let directory = directory { process.currentDirectoryPath = directory.path } let stdoutPipe = Pipe(), stderrPipe = Pipe() process.standardOutput = stdoutPipe process.standardError = stderrPipe process.launch() process.waitUntilExit() let stdout = String(data: stdoutPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? "" let stderr = String(data: stderrPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? "" return (stdout, stderr) } print(execute(["df", "-m"]).stdout)
Filesystem 1M-blocks Used Available Use% Mounted on none 384019 79671 284825 22% / /dev/mapper/evg0-evol0 384019 79671 284825 22% /tmp udev 30709 1 30709 1% /dev/herokudev none 64 0 64 0% /dev/shm tmpfs 6145 1 6144 1% /etc/resolv.conf
Filesystem 1M-blocks Used Available Use% Mounted on none 384019 80516 283980 23% / /dev/mapper/evg0-evol0 384019 80516 283980 23% /tmp udev 30709 1 30709 1% /dev/herokudev none 64 0 64 0% /dev/shm tmpfs 6145 1 6144 1% /etc/resolv.conf
Usage: @swift403 [SWIFT_OPTIONS] ``` [Swift Code] ```
Usage: @swift41 [SWIFT_OPTIONS] ``` [Swift Code] ```
Swift version 4.1 (swift-4.1-RELEASE) Target: x86_64-unknown-linux-gnu
Swift version 4.0.3 (swift-4.0.3-RELEASE) Target: x86_64-unknown-linux-gnu
func f(){}
sil_stage canonical import Builtin import Swift import SwiftShims func f() // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): %2 = integer_literal $Builtin.Int32, 0 // user: %3 %3 = struct $Int32 (%2 : $Builtin.Int32) // user: %4 return %3 : $Int32 // id: %4 } // end sil function 'main' // f() sil hidden @_T04main1fyyF : $@convention(thin) () -> () { bb0: %0 = tuple () // user: %1 return %0 : $() // id: %1 } // end sil function '_T04main1fyyF'
sil_stage canonical import Builtin import Swift import SwiftShims func f() // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): %2 = integer_literal $Builtin.Int32, 0 // user: %3 %3 = struct $Int32 (%2 : $Builtin.Int32) // user: %4 return %3 : $Int32 // id: %4 } // end sil function 'main' // f() sil hidden @_T04main1fyyF : $@convention(thin) () -> () { bb0: %0 = tuple () // user: %1 return %0 : $() // id: %1 } // end sil function '_T04main1fyyF'
Usage: @swiftbot [--version=SWIFT_VERSION] [--command={swift, swiftc}] [--options=SWIFTC_OPTIONS] ``` [Swift Code] ``` Examples: @swiftbot ``` print("Hello world!") ``` @swiftbot --version=4.0.3 ``` print("Hello world!") ``` @swiftbot --command=swiftc --options=-dump-parse ``` print("Hello world!") ``` Subcommands: @swiftbot versions: show available Swift toolchain versions @swiftbot contribute: show repository URLs @swiftbot help: show help
2018-04-13-a 4.1 4.0.3 3.1.1 3.0.2
func f() {}
sil_stage canonical import Builtin import Swift import SwiftShims func f() // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): %2 = integer_literal $Builtin.Int32, 0 // user: %3 %3 = struct $Int32 (%2 : $Builtin.Int32) // user: %4 return %3 : $Int32 // id: %4 } // end sil function 'main' // f() sil hidden @_T04main1fyyF : $@convention(thin) () -> () { bb0: %0 = tuple () // user: %1 return %0 : $() // id: %1 } // end sil function '_T04main1fyyF'
sil_stage canonical import Builtin import Swift import SwiftShims func f() // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): %2 = integer_literal $Builtin.Int32, 0 // user: %3 %3 = struct $Int32 (%2 : $Builtin.Int32) // user: %4 return %3 : $Int32 // id: %4 } // end sil function 'main' // f() sil hidden @_T04main1fyyF : $@convention(thin) () -> () { bb0: %0 = tuple () // user: %1 return %0 : $() // id: %1 } // end sil function '_T04main1fyyF'
struct S: Hashable { var int: Int }
main.swift:1:8: error: type 'S' does not conform to protocol 'Hashable' struct S: Hashable { ^ main.swift:1:8: error: type 'S' does not conform to protocol 'Equatable' struct S: Hashable { ^ Swift.==:2:13: note: candidate has non-matching type '<Element where Element : Equatable> (ContiguousArray<Element>, ContiguousArray<Element>) -> Bool' public func ==<Element>(lhs: ContiguousArray<Element>, rhs: ContiguousArray<Element>) -> Bool where Element : Equatable ^ Swift.==:2:13: note: candidate has non-matching type '<Element where Element : Equatable> (ArraySlice<Element>, ArraySlice<Element>) -> Bool' public func ==<Element>(lhs: ArraySlice<Element>, rhs: ArraySlice<Element>) -> Bool where Element : Equatable ^ Swift.==:2:13: note: candidate has non-matching type '<Element where Element : Equatable> (Array<Element>, Array<Element>) -> Bool' public func ==<Element>(lhs: [Element], rhs: [Element]) -> Bool where Element : Equatable ^ Swift.==:3:13: note: candidate has non-matching type '(Any.Type?, Any.Type?) -> Bool' public func ==(t0: Any.Type?, t1: Any.Type?) -> Bool ^ Swift.==:6:13: note: candidate has non-matching type '<T where T : RawRepresentable, T.RawValue : Equatable> (T, T) -> Bool' public func ==<T>(lhs: T, rhs: T) -> Bool where T : RawRepresentable, T.RawValue : Equatable ^ Swift.==:45:13: note: candidate has non-matching type '<T where T : Equatable> (T?, T?) -> Bool' public func ==<T>(lhs: T?, rhs: T?) -> Bool where T : Equatable ^ Swift.==:22:13: note: candidate has non-matching type '<T> (T?, _OptionalNilComparisonType) -> Bool' public func ==<T>(lhs: T?, rhs: _OptionalNilComparisonType) -> Bool ^ Swift.==:22:13: note: candidate has non-matching type '<T> (_OptionalNilComparisonType, T?) -> Bool' public func ==<T>(lhs: _OptionalNilComparisonType, rhs: T?) -> Bool ^ Swift.==:9:13: note: candidate
func fibonacci(number: Int) -> Int { if number <= 1 { return number } else { return fibonacci(number: number - 1) + fibonacci(number: number - 2) } } print(fibonacci(number: 10))
Swift version 4.2-dev (LLVM 8a97de0e52, Clang 3c973cd6c1, Swift e0c091a012)
55
Swift version 4.1 (swift-4.1-RELEASE)
55
Swift version 4.0.3 (swift-4.0.3-RELEASE)
55
func fibonacci(number: Int) -> Int { if number <= 1 { return number } else { return fibonacci(number: number - 1) + fibonacci(number: number - 2) } } print(fibonacci(number: 10))
Swift version 4.2-dev (LLVM 8a97de0e52, Clang 3c973cd6c1, Swift e0c091a012)
55
Swift version 4.1 (swift-4.1-RELEASE)
55
Swift version 4.0.3 (swift-4.0.3-RELEASE)
55
GUILD_TEXT
の場合(通常のチャンネル)だけ受け付ける様にしました。 https://discordapp.com/developers/docs/resources/channel#channel-object-channel-typesprint("hello")
lldb swift -c core -o bt -b
でバックトレースを作れる。symbolicate-linux-fatal
の方は実際に成功していないけど、 symbolicate-linux-fatal app crash.log
的な使い方をするぽい。lldb
の実行に依存してる。lldb
を使えなかった。print("hello")
/usr/bin/swift[0x3f24d54] /usr/bin/swift[0x3f25096] /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7f2d23306390] /usr/bin/swift[0x4c55c0] /usr/bin/swift[0x4c3a83] /usr/bin/swift[0x4beecc] /usr/bin/swift[0x4778c4] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f2d21a30830] /usr/bin/swift[0x475179] Stack dump: 0. Program arguments: /usr/bin/swift -frontend -interpret main.swift -disable-objc-interop -debug-crash-after-parse -module-name main
llvm-symbolizer
が PATH に入っているともっとマシなトレースが出るはずです。#0 0x0000000003e318c4 PrintStackTraceSignalHandler(void*) (/home/rintaro/Documents/swift-oss/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swift+0x3e318c4) #1 0x0000000003e31c06 SignalHandler(int) (/home/rintaro/Documents/swift-oss/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swift+0x3e31c06) #2 0x00007fa3d67ae390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390) #3 0x00000000004c1710 debugFailWithCrash() (/home/rintaro/Documents/swift-oss/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swift+0x4c1710) #4 0x00000000004bfbd3 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) (/home/rintaro/Documents/swift-oss/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swift+0x4bfbd3) #5 0x00000000004bb013 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/home/rintaro/Documents/swift-oss/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swift+0x4bb013) #6 0x0000000000473a44 main (/home/rintaro/Documents/swift-oss/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swift+0x473a44) #7 0x00007fa3d4ed8830 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x20830) #8 0x0000000000471319 _start (/home/rintaro/Documents/swift-oss/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swift+0x471319) Stack dump: 0. Program arguments: /home/rintaro/Documents/swift-oss/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swift -frontend -interpret test.swift -disable-objc-interop -debug-crash-after-parse -color-diagnostics -module-name test Illegal instruction (core dumped)
llvm-symbolizer
は普通にapt-get
で入れるやつで構わないのですか?/usr/bin/llvm-symbolizer-3.8
として既に入ってた。apt-get install llvm
として明示的にインストールすれば、バージョンサフィックス無しのシンボリックリンクが作られるみたいですね。apt-get install llvm
として明示的にインストールすれば (edited)update-alternatives(8)
を使った。 https://gist.github.com/norio-nomura/505e5a5dce1502c774db51c9e3663700llvm-symbolizer
を使う様になりました。 @swift403 @swift-4.1.3 -Xfrontend -debug-crash-after-parse print("hello")
#0 0x0000000003ae91b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/bin/swift+0x3ae91b8) #1 0x0000000003ae98f6 SignalHandler(int) (/usr/bin/swift+0x3ae98f6) #2 0x00007f1fcf2b6390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390) #3 0x00000000004b0540 debugFailWithCrash() (/usr/bin/swift+0x4b0540) #4 0x00000000004aea28 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) (/usr/bin/swift+0x4aea28) #5 0x00000000004aa52b swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/usr/bin/swift+0x4aa52b) #6 0x0000000000465564 main (/usr/bin/swift+0x465564) #7 0x00007f1fcd9e0830 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x20830) #8 0x0000000000462e29 _start (/usr/bin/swift+0x462e29) Stack dump: 0. Program arguments: /usr/bin/swift -frontend -interpret main.swift -disable-objc-interop -debug-crash-after-parse -module-name main
#0 0x0000000003f24d54 PrintStackTraceSignalHandler(void*) (/usr/bin/swift+0x3f24d54) #1 0x0000000003f25096 SignalHandler(int) (/usr/bin/swift+0x3f25096) #2 0x00007fcd052c1390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390) #3 0x00000000004c55c0 debugFailWithCrash() (/usr/bin/swift+0x4c55c0) #4 0x00000000004c3a83 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) (/usr/bin/swift+0x4c3a83) #5 0x00000000004beecc swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/usr/bin/swift+0x4beecc) #6 0x00000000004778c4 main (/usr/bin/swift+0x4778c4) #7 0x00007fcd039eb830 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x20830) #8 0x0000000000475179 _start (/usr/bin/swift+0x475179) Stack dump: 0. Program arguments: /usr/bin/swift -frontend -interpret main.swift -disable-objc-interop -debug-crash-after-parse -module-name main
enum CustomString: ExpressibleByStringLiteral { typealias StringLiteralType = String init(stringLiteral value: StringLiteralType) { self = "hoge" } } let hoge: CustomString = "fuga" print(hoge)
main.swift:8:26: warning: will never be executed let hoge: CustomString = "fuga" ^ main.swift:8:26: note: a call to a never-returning function let hoge: CustomString = "fuga" ^ main.swift:4:14: warning: will never be executed self = "hoge" ^ main.swift:4:16: note: a call to a never-returning function self = "hoge" ^ main.swift:3:5: warning: will never be executed init(stringLiteral value: StringLiteralType) { ^ main.swift:3:5: note: a call to a never-returning function init(stringLiteral value: StringLiteralType) { ^ #0 0x0000000003f24d54 PrintStackTraceSignalHandler(void*) (/usr/bin/swift+0x3f24d54) #1 0x0000000003f25096 SignalHandler(int) (/usr/bin/swift+0x3f25096) #2 0x00007f2fb4579390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390) #3 0x00007f2fafce7424 _T0S2SBp21_builtinStringLiteral_Bw17utf8CodeUnitCountBi1_7isASCIItcfC (/usr/lib/swift/linux/libswiftCore.so+0x13c424) #4 0x00007f2fb49a80e4 #5 0x00007f2fb49a80fa #6 0x00007f2fb49a80fa #7 0x00007f2fb49a80fa #8 0x00007f2fb49a80fa #9 0x00007f2fb49a80fa #10 0x00007f2fb49a80fa #11 0x00007f2fb49a80fa #12 0x00007f2fb49a80fa #13 0x00007f2fb49a80fa #14 0x00007f2fb49a80fa #15 0x00007f2fb49a80fa #16 0x00007f2fb49a80fa #17 0x00007f2fb49a80fa #18 0x00007f2fb49a80fa #19 0x00007f2fb49a80fa #20 0x00007f2fb49a80fa #21 0x00007f2fb49a80fa #22 0x00007f2fb49a80fa #23 0x00007f2fb49a80fa #24 0x00007f2fb49a80fa #25 0x00007f2fb49a80fa #26 0x00007f2fb49a80fa #27 0x00007f2fb49a80fa #28 0x00007f2fb49a80fa #29 0x00007f2fb49a80fa #30 0x00007f2fb49a80fa #31 0x00007f2fb49a80fa #32 0x00007f2fb49a80fa #33 0x00007f2fb49a80fa #34 0x00007f2fb49a80fa #35 0x00007f2fb49a80fa #36 0x00007f2fb49a80fa #37 0x00007f2fb49a80fa #38 0x00007f2fb49a80fa #39 0x00007f2fb49a80fa #40 0x00007f2fb49a80fa #41 0x00007f2fb49a80fa #42 0x00007f2fb49a80fa #43 0x00007f2fb49a80fa #44 0x00007f2fb49a80fa #45
print("Hello SwiftBot")
Swift version 4.1 (swift-4.1-RELEASE)
Hello SwiftBot
swift-DEVELOPMENT-SNAPSHOT-2018-04-16-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang c38020c511, Swift da10607e45)
Hello SwiftBot
Swift version 4.1 (swift-4.1-RELEASE) Target: x86_64-unknown-linux-gnu
Swift version 4.2-dev (LLVM d14a2b25f2, Clang c38020c511, Swift da10607e45) Target: x86_64-unknown-linux-gnu
Swift version 4.0.3 (swift-4.0.3-RELEASE) Target: x86_64-unknown-linux-gnu
protocol DictionaryType { associatedtype Key associatedtype Value } protocol A: DictionaryType where Key == Value { static func foo() } extension A { static func foo() { print(type(of: self)) } } extension Dictionary: DictionaryType {} extension Dictionary: A where Key == Value { } extension Array where Element: A { static func foo() { Element.foo() } } [String: String].foo() // Dictionary<String, String> [[String: String]].foo() // Crash
Dictionary<String, String>.Type .Type
master
はこんな感じですよ。 $ ../build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift test.swift Dictionary<String, String>.Type Dictionary<String, String>.Type
import Foundation print(PorcessInfo.processInfo.enrionment["SWIFT_VERSION"])
main.swift:2:7: error: use of unresolved identifier 'PorcessInfo'; did you mean 'ProcessInfo'? print(PorcessInfo.processInfo.enrionment["SWIFT_VERSION"]) ^~~~~~~~~~~ ProcessInfo Foundation.ProcessInfo:1:12: note: 'ProcessInfo' declared here open class ProcessInfo : Foundation.NSObject { ^
import Foundation print(ProcessInfo.processInfo.enrionment["SWIFT_VERSION"])
main.swift:2:19: error: value of type 'ProcessInfo' has no member 'enrionment'; did you mean 'environment'? print(ProcessInfo.processInfo.enrionment["SWIFT_VERSION"]) ~~~~~~~~~~~~^~~~~~~~~~~ ~~~~~~~~~~ environment Foundation.ProcessInfo:3:14: note: 'environment' declared here open var environment: [String : String] { get } ^
import Foundation print(ProcessInfo.processInfo.environment["SWIFT_VERSION"])
Optional("DEVELOPMENT-SNAPSHOT-2018-04-17-a")
main.swift:2:7: warning: expression implicitly coerced from 'String?' to 'Any' print(ProcessInfo.processInfo.environment["SWIFT_VERSION"]) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.swift:2:42: note: provide a default value to avoid this warning print(ProcessInfo.processInfo.environment["SWIFT_VERSION"]) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ ?? <#default value#> main.swift:2:42: note: force-unwrap the value to avoid this warning print(ProcessInfo.processInfo.environment["SWIFT_VERSION"]) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ ! main.swift:2:42: note: explicitly cast to 'Any' with 'as Any' to silence this warning print(ProcessInfo.processInfo.environment["SWIFT_VERSION"]) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ as Any
import Foundation print(ProcessInfo.processInfo.environment["SWIFT_VERSION"] ?? "")
DEVELOPMENT-SNAPSHOT-2018-04-17-a
import Foundation print(ProcessInfo.processInfo.environment["SWIFT_VERSION"] ?? "")
Swift Versionを返すのはこれでいいのか!swift-DEVELOPMENT-SNAPSHOT-2018-04-16-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang c38020c511, Swift da10607e45)
swift-DEVELOPMENT-SNAPSHOT-2018-04-16-a
SWIFT_VERSION
を設定してますね。swift-
プリフィックスが無いです。swiftenv
の流儀かな?Usage: @swift41 [SWIFT_OPTIONS] ``` [Swift Code] ```
(edited)print("hello")
(edited)hello
(edited)print("あと、コマンド実行中に入力中インジケータを出す様にしました。")
あと、コマンド実行中に入力中インジケータを出す様にしました。
4.1
4.2
4.0.3
の絵文字を登録するとかEXPOSE
していません。 (edited)EXPOSE
サポートしてなかった。 https://devcenter.heroku.com/articles/container-registry-and-runtime#unsupported-dockerfile-commandsSwift version 4.1 (swift-4.1-RELEASE)
(edited)Hello world!!
(edited)swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
Hello world!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
Hello world!!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
Hello world!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
Hello world!!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
Hello world!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
Hello world!!
Swift version 4.1 (swift-4.1-RELEASE)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
Int?.none!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
a!
enum Hoge: CaseIterable { case hoge, fuga, piyo } Hoge.allCases.map { print($0) }
(edited)enum Hoge: CaseIterable { case hoge, fuga, piyo } Hoge.allCases.forEach { print($0) }
(edited)hoge fuga piyo
(edited)import Foundation print(ProcessInfo.processInfo.environment["SWIFT_VERSION"] ?? "")
(edited)DEVELOPMENT-SNAPSHOT-2018-04-19-a
(edited)DEVELOPMENT-SNAPSHOT-2018-04-20-a
import Foundation print(ProcessInfo.processInfo.environment["SWIFT_VERSION"] ?? "")
(edited)DEVELOPMENT-SNAPSHOT-2018-04-22-a
import Foundation let versionOfRxSwift = ProcessInfo.processInfo.environment["RXSWIFT_VERSION"] ?? "" print("RxSwift version: \(versionOfRxSwift)") import RxSwift _ = Observable<String>.create { observerOfString in print("Observable created") observerOfString.on(.next("😉")) observerOfString.on(.completed) return Disposables.create() } .subscribe { event in print(event) }
RxSwift version: 4.1.2 Observable created next(😉) completed
RxSwift version: 4.1.2 Observable created next(😉) completed
RxSwift version: 4.1.2 Observable created next(😉) completed
libRxSwift.so
を作るのにPackage.swift
内でlibrary typeをdynamicにしなくても、 swift build --target RxSwift -Xswiftc -emit-library -Xswiftc -o -Xswiftc `swift build --show-bin-path`/libRxSwift.so
とすれば作れることを知りました。let a: UInt32 = 0x80_00_00_00 let b: UInt32 = 0x80_00_00_00 let c = a.addingReportingOverflow(b) dump(c)
(edited)Swift version 4.1 (swift-4.1-RELEASE)
(edited)▿ (2 elements) - partialValue: 0 - overflow: true
let a: UInt32 = 0x80_00_00_00 let b: UInt32 = 0x7F_FF_FF_FF let c = a.addingReportingOverflow(b) dump(c)
Swift version 4.1 (swift-4.1-RELEASE)
▿ (2 elements) - partialValue: 4294967295 - overflow: false
import TensorFlow
import Python
は通るけど、動かない? @swift-tensorflow
import TensorFlow import Python // NumPy example: let np = Python.import("numpy") // import numpy as np let a = np.arange(15).reshape(3, 5) // a = np.arange(15).reshape(3, 5) let b = np.array([6, 7, 8]) // b = np.array([6, 7, 8])
main.swift:5:18: error: cannot call value of non-function type 'PyValue' let a = np.arange(15).reshape(3, 5) // a = np.arange(15).reshape(3, 5) ~~~~~~~~~^ main.swift:6:17: error: cannot call value of non-function type 'PyValue' let b = np.array([6, 7, 8]) // b = np.array([6, 7, 8]) ~~~~~~~~^
np.arange.call(with: 15)
じゃないと動かないみたいですねimport Foundation @objc protocol Hoge { func foobarbaz() } var x: AnyObject = "hoge" as NSString x.foobarbaz()
(edited)Swift version 4.1 (swift-4.1-RELEASE)
(edited)<unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log <unknown>:0: note: Program used external function 'sel_registerName' which could not be resolved! /usr/bin/swift[0x3f24d54] /usr/bin/swift[0x3f25096] /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7f12ac409390] /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x38)[0x7f12aab48428] /lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7f12aab4a02a] /usr/bin/swift[0x4c3f75] /usr/bin/swift[0x3eb851f] /usr/bin/swift[0xffeddb] /usr/bin/swift[0xffd626] /usr/bin/swift[0xfead79] /usr/bin/swift[0x4d8e48] /usr/bin/swift[0x4c35d3] /usr/bin/swift[0x4beecc] /usr/bin/swift[0x4778c4] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f12aab33830] /usr/bin/swift[0x475179] Stack dump: 0. Program arguments: /usr/bin/swift -frontend -interpret /usercode/main.swift -disable-objc-interop -I /usr/lib/swift/clang/include/ -I /vendor/SwiftyMath/.build/release/ -I /vendor/swift-package-libbsd/ -module-name main -ldSwiftyMath Aborted (core dumped)
(edited)swift-DEVELOPMENT-SNAPSHOT-2018-04-18-a Swift version 4.2-dev (LLVM d14a2b25f2, Clang da1edea3f7, Swift ac061632b2)
/usercode/main.swift:7:22: error: 'Int' is not convertible to 'AnyObject'; did you mean to use 'as!' to force downcast? var x: AnyObject = 1 as AnyObject ~~^~~~~~~~~~~~ as!
AnyObject
の何でもメソッド呼べちゃう性を Linux で試して見たかっただけなのですが、どこで落ちているのか分からないですねwimport Foundation @objc protocol Hoge { func foobarbaz() } var x: AnyObject = "hoge" as NSString x.foobarbaz()
(edited)<unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log <unknown>:0: note: Program used external function 'sel_registerName' which could not be resolved! #0 0x0000000003f24d54 PrintStackTraceSignalHandler(void*) (/usr/bin/swift+0x3f24d54) #1 0x0000000003f25096 SignalHandler(int) (/usr/bin/swift+0x3f25096) #2 0x00007f3b0201f390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390) #3 0x00007f3b0075e428 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x35428) #4 0x00007f3b0076002a abort (/lib/x86_64-linux-gnu/libc.so.6+0x3702a) #5 0x00000000004c3f75 (/usr/bin/swift+0x4c3f75) #6 0x0000000003eb851f llvm::report_fatal_error(llvm::Twine const&, bool) (/usr/bin/swift+0x3eb851f) #7 0x0000000000ffeddb llvm::RuntimeDyldImpl::resolveExternalSymbols() (/usr/bin/swift+0xffeddb) #8 0x0000000000ffd626 llvm::RuntimeDyldImpl::resolveRelocations() (/usr/bin/swift+0xffd626) #9 0x0000000000fead79 llvm::MCJIT::finalizeObject() (/usr/bin/swift+0xfead79) #10 0x00000000004d8e48 swift::RunImme