Skip to content

Instantly share code, notes, and snippets.

@norio-nomura
Created July 22, 2015 03:25
Show Gist options
  • Save norio-nomura/1bd0d61dfa3400d2cadc to your computer and use it in GitHub Desktop.
Save norio-nomura/1bd0d61dfa3400d2cadc to your computer and use it in GitHub Desktop.
xcrun swiftc -emit-sil indirect.swift -o -|xcrun swift-demangle > indirect.sil
sil_stage canonical
import Builtin
import Swift
import SwiftShims
// static Swift.Process._argc : Swift.Int32
sil_global [fragile] @static Swift.Process._argc : Swift.Int32 : $Int32
// globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5
sil_global private_external [fragile] @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5 : $Builtin.Word
// static Swift.Process._unsafeArgv : Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>>
sil_global [fragile] @static Swift.Process._unsafeArgv : Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>> : $UnsafeMutablePointer<UnsafeMutablePointer<Int8>>
// main
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<UnsafeMutablePointer<Int8>>) -> Int32 {
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<UnsafeMutablePointer<Int8>>):
%2 = global_addr @static Swift.Process._argc : Swift.Int32 : $*Int32 // user: %3
store %0 to %2 : $*Int32 // id: %3
%4 = global_addr @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5 : $*Builtin.Word // user: %5
%5 = address_to_pointer %4 : $*Builtin.Word to $Builtin.RawPointer // user: %7
// function_ref globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func5
%6 = function_ref @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func5 : $@convention(thin) () -> () // user: %7
%7 = builtin "once"(%5 : $Builtin.RawPointer, %6 : $@convention(thin) () -> ()) : $()
%8 = global_addr @static Swift.Process._unsafeArgv : Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>> : $*UnsafeMutablePointer<UnsafeMutablePointer<Int8>> // user: %9
store %1 to %8 : $*UnsafeMutablePointer<UnsafeMutablePointer<Int8>> // id: %9
%10 = tuple ()
%11 = integer_literal $Builtin.Int32, 0 // user: %12
%12 = struct $Int32 (%11 : $Builtin.Int32) // user: %13
return %12 : $Int32 // id: %13
}
// Swift._didEnterMain (Swift.Int32, argv : Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>>) -> ()
sil [transparent] [fragile] @Swift._didEnterMain (Swift.Int32, argv : Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>>) -> () : $@convention(thin) (Int32, UnsafeMutablePointer<UnsafeMutablePointer<Int8>>) -> ()
// main.NoIndirect.A <A> (main.NoIndirect<A>.Type)(A) -> main.NoIndirect<A>
sil hidden [transparent] @main.NoIndirect.A <A> (main.NoIndirect<A>.Type)(A) -> main.NoIndirect<A> : $@convention(thin) <T> (@out NoIndirect<T>, @in T, @thin NoIndirect<T>.Type) -> () {
bb0(%0 : $*NoIndirect<T>, %1 : $*T, %2 : $@thin NoIndirect<T>.Type):
%3 = init_enum_data_addr %0 : $*NoIndirect<T>, #NoIndirect.A!enumelt.1 // user: %4
copy_addr [take] %1 to [initialization] %3 : $*T // id: %4
inject_enum_addr %0 : $*NoIndirect<T>, #NoIndirect.A!enumelt.1 // id: %5
%6 = tuple () // user: %7
return %6 : $() // id: %7
}
// main.NoIndirect.B <A> (main.NoIndirect<A>.Type)(A) -> main.NoIndirect<A>
sil hidden [transparent] @main.NoIndirect.B <A> (main.NoIndirect<A>.Type)(A) -> main.NoIndirect<A> : $@convention(thin) <T> (@out NoIndirect<T>, @in T, @thin NoIndirect<T>.Type) -> () {
bb0(%0 : $*NoIndirect<T>, %1 : $*T, %2 : $@thin NoIndirect<T>.Type):
%3 = init_enum_data_addr %0 : $*NoIndirect<T>, #NoIndirect.B!enumelt.1 // user: %4
copy_addr [take] %1 to [initialization] %3 : $*T // id: %4
inject_enum_addr %0 : $*NoIndirect<T>, #NoIndirect.B!enumelt.1 // id: %5
%6 = tuple () // user: %7
return %6 : $() // id: %7
}
// main.NoIndirect.C <A> (main.NoIndirect<A>.Type)(A) -> main.NoIndirect<A>
sil hidden [transparent] @main.NoIndirect.C <A> (main.NoIndirect<A>.Type)(A) -> main.NoIndirect<A> : $@convention(thin) <T> (@out NoIndirect<T>, @in T, @thin NoIndirect<T>.Type) -> () {
bb0(%0 : $*NoIndirect<T>, %1 : $*T, %2 : $@thin NoIndirect<T>.Type):
%3 = init_enum_data_addr %0 : $*NoIndirect<T>, #NoIndirect.C!enumelt.1 // user: %4
copy_addr [take] %1 to [initialization] %3 : $*T // id: %4
inject_enum_addr %0 : $*NoIndirect<T>, #NoIndirect.C!enumelt.1 // id: %5
%6 = tuple () // user: %7
return %6 : $() // id: %7
}
// main.Indirect.A <A> (main.Indirect<A>.Type)(A) -> main.Indirect<A>
sil hidden [transparent] @main.Indirect.A <A> (main.Indirect<A>.Type)(A) -> main.Indirect<A> : $@convention(thin) <T> (@in T, @thin Indirect<T>.Type) -> @owned Indirect<T> {
bb0(%0 : $*T, %1 : $@thin Indirect<T>.Type):
%2 = alloc_box $T // users: %3, %4
copy_addr [take] %0 to [initialization] %2#1 : $*T // id: %3
%4 = enum $Indirect<T>, #Indirect.A!enumelt.1, %2#0 : $@box T // user: %5
return %4 : $Indirect<T> // id: %5
}
// main.Indirect.B <A> (main.Indirect<A>.Type)(A) -> main.Indirect<A>
sil hidden [transparent] @main.Indirect.B <A> (main.Indirect<A>.Type)(A) -> main.Indirect<A> : $@convention(thin) <T> (@in T, @thin Indirect<T>.Type) -> @owned Indirect<T> {
bb0(%0 : $*T, %1 : $@thin Indirect<T>.Type):
%2 = alloc_box $T // users: %3, %4
copy_addr [take] %0 to [initialization] %2#1 : $*T // id: %3
%4 = enum $Indirect<T>, #Indirect.B!enumelt.1, %2#0 : $@box T // user: %5
return %4 : $Indirect<T> // id: %5
}
// main.Indirect.C <A> (main.Indirect<A>.Type)(A) -> main.Indirect<A>
sil hidden [transparent] @main.Indirect.C <A> (main.Indirect<A>.Type)(A) -> main.Indirect<A> : $@convention(thin) <T> (@in T, @thin Indirect<T>.Type) -> @owned Indirect<T> {
bb0(%0 : $*T, %1 : $@thin Indirect<T>.Type):
%2 = alloc_box $T // users: %3, %4
copy_addr [take] %0 to [initialization] %2#1 : $*T // id: %3
%4 = enum $Indirect<T>, #Indirect.C!enumelt.1, %2#0 : $@box T // user: %5
return %4 : $Indirect<T> // id: %5
}
// main.NoIndirectA () -> ()
sil hidden @main.NoIndirectA () -> () : $@convention(thin) () -> () {
bb0:
%0 = integer_literal $Builtin.Int64, 1 // user: %1
%1 = struct $Int (%0 : $Builtin.Int64) // user: %4
%2 = alloc_stack $NoIndirect<Int> // users: %3, %5, %7, %16, %19
%3 = init_enum_data_addr %2#1 : $*NoIndirect<Int>, #NoIndirect.A!enumelt.1 // user: %4
store %1 to %3 : $*Int // id: %4
inject_enum_addr %2#1 : $*NoIndirect<Int>, #NoIndirect.A!enumelt.1 // id: %5
%6 = tuple ()
%7 = load %2#1 : $*NoIndirect<Int> // user: %8
switch_enum %7 : $NoIndirect<Int>, case #NoIndirect.A!enumelt.1: bb1, default bb2 // id: %8
bb1(%9 : $Int): // Preds: bb0
debug_value %9 : $Int // let a // id: %10
// function_ref Swift.print <A> (A) -> ()
%11 = function_ref @Swift.print <A> (A) -> () : $@convention(thin) <τ_0_0> (@in τ_0_0) -> () // user: %14
%12 = alloc_stack $Int // users: %13, %14, %15
store %9 to %12#1 : $*Int // id: %13
%14 = apply %11<Int>(%12#1) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
dealloc_stack %12#0 : $*@local_storage Int // id: %15
dealloc_stack %2#0 : $*@local_storage NoIndirect<Int> // id: %16
br bb4 // id: %17
bb2: // Preds: bb0
br bb3 // id: %18
bb3: // Preds: bb2
dealloc_stack %2#0 : $*@local_storage NoIndirect<Int> // id: %19
br bb4 // id: %20
bb4: // Preds: bb1 bb3
%21 = tuple () // user: %22
return %21 : $() // id: %22
}
// Swift.Int.init (Swift.Int.Type)(_builtinIntegerLiteral : Builtin.Int2048) -> Swift.Int
sil [transparent] [fragile] @Swift.Int.init (Swift.Int.Type)(_builtinIntegerLiteral : Builtin.Int2048) -> Swift.Int : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
// Swift.print <A> (A) -> ()
sil [noinline] [_semantics "stdlib_binary_only"] @Swift.print <A> (A) -> () : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
// main.IndirectA () -> ()
sil hidden @main.IndirectA () -> () : $@convention(thin) () -> () {
bb0:
%0 = integer_literal $Builtin.Int64, 1 // user: %1
%1 = struct $Int (%0 : $Builtin.Int64) // user: %3
%2 = alloc_box $Int // users: %3, %5, %13
store %1 to %2#1 : $*Int // id: %3
br bb1 // id: %4
bb1: // Preds: bb0
%5 = project_box %2#0 : $@box Int // user: %6
%6 = load %5 : $*Int // users: %7, %10
debug_value %6 : $Int // let a // id: %7
// function_ref Swift.print <A> (A) -> ()
%8 = function_ref @Swift.print <A> (A) -> () : $@convention(thin) <τ_0_0> (@in τ_0_0) -> () // user: %11
%9 = alloc_stack $Int // users: %10, %11, %12
store %6 to %9#1 : $*Int // id: %10
%11 = apply %8<Int>(%9#1) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
dealloc_stack %9#0 : $*@local_storage Int // id: %12
strong_release %2#0 : $@box Int // id: %13
br bb2 // id: %14
bb2: // Preds: bb1
%15 = tuple () // user: %16
return %15 : $() // id: %16
}
// globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func5
sil private_external [fragile] @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func5 : $@convention(thin) () -> ()
enum NoIndirect<T> {
case A(T)
case B(T)
case C(T)
}
indirect enum Indirect<T> {
case A(T)
case B(T)
case C(T)
}
func NoIndirectA() {
switch NoIndirect.A(1) {
case .A(let a):
print(a)
default:()
}
}
func IndirectA() {
switch Indirect.A(1) {
case .A(let a):
print(a)
default:()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment