Skip to content

Instantly share code, notes, and snippets.

View norio-nomura's full-sized avatar

Norio Nomura norio-nomura

View GitHub Profile
@norio-nomura
norio-nomura / update-alternatives.terminal.sh-session
Last active April 17, 2018 02:28
[one-liner] update-alternatives for llvm on ubuntu
LLVM_VERSION=`cd /usr/bin; ls llvm-config-*|sed 's/llvm-config-//'` && \
(cd /usr/bin; ls -1 llvm*-$LLVM_VERSION) | sed -e '/llvm-config/d' -e "s/-$LLVM_VERSION//"| \
awk -v LLVM_VERSION=$LLVM_VERSION 'BEGIN{print "update-alternatives --force --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-"LLVM_VERSION" 200 \\"}{print "--slave /usr/bin/"$0, $0, "/usr/bin/"$0"-"LLVM_VERSION" \\" }'|sh
@norio-nomura
norio-nomura / symbolicate-crash.terminal.sh-session
Last active April 16, 2018 15:25
Symbolicate crash from core on Linux
$ docker run --privileged -it -v `pwd`:`pwd` -w `pwd` --rm norionomura/swift:41
root@e8fbffcc2ed0:~# ulimit -c unlimited
root@e8fbffcc2ed0:~# echo 'let i: Int? = nil; i!'>main.swift
root@e8fbffcc2ed0:~# swift main.swift
main.swift:1:21: warning: expression of type 'Int' is unused
let i: Int? = nil; i!
~^
Fatal error: Unexpectedly found nil while unwrapping an Optional value
Current stack trace:
0 libswiftCore.so 0x00007fcc7bd96750 _swift_stdlib_reportFatalError + 171
@norio-nomura
norio-nomura / sourcekit-crash.terminal.sh-session
Created February 5, 2018 06:37
SourceKit crashes with Assertion `(!value || Kind == tok::identifier) && "only identifiers can be escaped identifiers"' failed. on Swift 4.1 for Linux
$ docker run --privileged -it --rm norionomura/swift:4120180201a
root@ed1c03d3a776:/# git clone https://github.com/realm/SwiftLint.git -b nn-swift-4.1
Cloning into 'SwiftLint'...
remote: Counting objects: 23681, done.
remote: Compressing objects: 100% (165/165), done.
remote: Total 23681 (delta 95), reused 145 (delta 74), pack-reused 23440
Receiving objects: 100% (23681/23681), 6.16 MiB | 1.70 MiB/s, done.
Resolving deltas: 100% (16180/16180), done.
Checking connectivity... done.
root@ed1c03d3a776:/# cd SwiftLint
@norio-nomura
norio-nomura / OffsetMapTests.testOffsetMapContainsDeclarationOffsetWithDocCommentButNotAlreadyDocumented()-on-Swift-4.1
Created February 3, 2018 07:16
Result of `OffsetMapTests.testOffsetMapContainsDeclarationOffsetWithDocCommentButNotAlreadyDocumented()`
{
key.offset: 0,
key.length: 105,
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
key.syntaxmap: [
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 0,
key.length: 6
},
import Foundation
enum Error: CustomStringConvertible, Swift.Error {
case failed(subcommand: String, message: String, status: Int32)
var description: String {
switch self {
case let .failed(subcommand: subcommand, message: message, status: status):
return "`\(subcommand)` failed with status: \(status)\n\(message)"
}
}
class Mario {
enum State: RawState {
case normal = "normal"
case big = "big"
case fire = "fire"
case dead = "dead"
}
var state: State = .normal
var name: String { return "\(state.rawValue.name)マリオ" }
func hitEnemy() { state.rawValue.hitEnemy(self) }
$ cat <<EOF|swiftc -emit-sil -O -|swift demangle
import CoreFoundation
import Foundation
protocol Factory {}
extension Factory {
init(_ f: () -> Self) {
self = f()
}
}
// `-O`あり
// Factory.init(() -> A) -> A
sil hidden @(extension in main):main.Factory.init (() -> A) -> A : $@convention(method) <Self where Self : Factory> (@owned @callee_owned () -> @out Self, @thick Self.Type) -> @out Self {
// %0 // user: %4
// %1 // users: %4, %3
bb0(%0 : $*Self, %1 : $@callee_owned () -> @out Self, %2 : $@thick Self.Type):
debug_value %1 : $@callee_owned () -> @out Self, let, name "f", argno 1, loc "<stdin>":3:12, scope 13 // id: %3
%4 = apply %1(%0) : $@callee_owned () -> @out Self, loc "<stdin>":4:18, scope 14
%5 = tuple (), scope 14 // user: %6
return %5 : $(), loc "<stdin>":5:5, scope 14 // id: %6
$ git submodule update --init --recursive
Submodule 'ext/xcode-build-test-aaa' (https://github.com/omochi/xcode-build-test-aaa) registered for path 'ext/xcode-build-test-aaa'
Submodule 'ext/xcode-build-test-bbb' (https://github.com/omochi/xcode-build-test-bbb) registered for path 'ext/xcode-build-test-bbb'
Submodule 'ext/xcode-build-test-ccc' (https://github.com/omochi/xcode-build-test-ccc) registered for path 'ext/xcode-build-test-ccc'
Cloning into '/Users/norio/github/xcode-build-test-ddd/ext/xcode-build-test-aaa'...
Cloning into '/Users/norio/github/xcode-build-test-ddd/ext/xcode-build-test-bbb'...
Cloning into '/Users/norio/github/xcode-build-test-ddd/ext/xcode-build-test-ccc'...
Submodule path 'ext/xcode-build-test-aaa': checked out '2d6a3207c649c348133222910e6209832c423950'
Submodule path 'ext/xcode-build-test-bbb': checked out '054193df0080280cd3df03d88bf0a16acf7e8444'
Submodule 'ext/xcode-build-test-aaa' (github.com:omochi/xcode-build-test-aaa) registered for path 'ext/xcode-build-test-bbb/ext/xcode-
//
// CheckNSNumberTests.swift
// CheckNSNumberTests
//
import XCTest
class CheckNSNumberTests: XCTestCase {
func test_objCTypeFromCFNumber() {