Skip to content

Instantly share code, notes, and snippets.

@norio-nomura
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norio-nomura/1f2350e25878287703e5 to your computer and use it in GitHub Desktop.
Save norio-nomura/1f2350e25878287703e5 to your computer and use it in GitHub Desktop.
guessing Swift.find() implementation and verifying it by SIL / Swiftのfind()実装を推測してSILで検証
diff --git a/Swift.find.sil b/my_find.my_find.sil
index 279e71b..6689ff5 100644
--- a/Swift.find.sil
+++ b/my_find.my_find.sil
@@ -1,7 +1,7 @@
-// Swift.find <A : Swift.CollectionType>(A, A.Generator.Element) -> Swift.Optional<A.Index>
-sil public_external Swift.find <A : Swift.CollectionType>(A, A.Generator.Element) -> A.Index? : $@thin <C where C : CollectionType, C.Generator : GeneratorType, C.Generator.Element : Equatable, C.Index : ForwardIndexType, C.Index.Distance : _SignedIntegerType, C.Index.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<C.Index>, @in C, @in C.Generator.Element) -> () {
+// my_find.my_find <A : Swift.CollectionType>(A, A.Generator.Element) -> Swift.Optional<A.Index>
+sil my_find.my_find <A : Swift.CollectionType>(A, A.Generator.Element) -> A.Index? : $@thin <C where C : CollectionType, C.Generator : GeneratorType, C.Generator.Element : Equatable, C.Index : ForwardIndexType, C.Index.Distance : _SignedIntegerType, C.Index.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<C.Index>, @in C, @in C.Generator.Element) -> () {
bb0(%0 : $*Optional<C.Index>, %1 : $*C, %2 : $*C.Generator.Element):
- %3 = alloc_stack $RangeGenerator<C.Index> // users: %10, %16, %38, %51, %55, %61
+ %3 = alloc_stack $RangeGenerator<C.Index> // var $idx$generator // users: %10, %16, %45, %49, %53, %61
// function_ref Swift.Range.generate <A : Swift.ForwardIndexType>(Swift.Range<A>)() -> Swift.RangeGenerator<A>
%4 = function_ref Swift.Range.generate <A : Swift.ForwardIndexType>(Swift.Range<A>)() -> Swift.RangeGenerator<A> : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out RangeGenerator<τ_0_0>, @in Range<τ_0_0>) -> () // user: %10
%5 = alloc_stack $Range<C.Index> // users: %9, %10, %12
@@ -13,17 +13,17 @@ bb0(%0 : $*Optional<C.Index>, %1 : $*C, %2 : $*C.Generator.Element):
%10 = apply %4<C.Index, C.Index.Distance, C.Index.Distance.IntegerLiteralType, C.Index._DisabledRangeIndex>(%3#1, %5#1) : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out RangeGenerator<τ_0_0>, @in Range<τ_0_0>) -> ()
dealloc_stack %7#0 : $*@local_storage C // id: %11
dealloc_stack %5#0 : $*@local_storage Range<C.Index> // id: %12
- %13 = alloc_stack $Optional<C.Index> // users: %16, %17, %21, %37, %50, %55, %56
+ %13 = alloc_stack $Optional<C.Index> // users: %16, %17, %21, %44, %49, %50, %52
// function_ref Swift.RangeGenerator.next <A : Swift.ForwardIndexType>(inout Swift.RangeGenerator<A>)() -> Swift.Optional<A>
- %14 = function_ref Swift.RangeGenerator.next <A : Swift.ForwardIndexType>(inout Swift.RangeGenerator<A>)() -> A? : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<τ_0_0>, @inout RangeGenerator<τ_0_0>) -> () // users: %16, %55
+ %14 = function_ref Swift.RangeGenerator.next <A : Swift.ForwardIndexType>(inout Swift.RangeGenerator<A>)() -> A? : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<τ_0_0>, @inout RangeGenerator<τ_0_0>) -> () // users: %16, %49
// function_ref Swift._doesOptionalHaveValue <A>(inout Swift.Optional<A>) -> Builtin.Int1
- %15 = function_ref Swift._doesOptionalHaveValue <A>(inout A?) -> Builtin.Int1 : $@thin <τ_0_0> (@inout Optional<τ_0_0>) -> Builtin.Int1 // users: %17, %56
+ %15 = function_ref Swift._doesOptionalHaveValue <A>(inout A?) -> Builtin.Int1 : $@thin <τ_0_0> (@inout Optional<τ_0_0>) -> Builtin.Int1 // users: %17, %50
%16 = apply %14<C.Index, C.Index.Distance, C.Index.Distance.IntegerLiteralType, C.Index._DisabledRangeIndex>(%13#1, %3#1) : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<τ_0_0>, @inout RangeGenerator<τ_0_0>) -> ()
%17 = apply [transparent] %15<C.Index>(%13#1) : $@thin <τ_0_0> (@inout Optional<τ_0_0>) -> Builtin.Int1 // user: %18
- cond_br %17, bb1, bb2 // id: %18
+ cond_br %17, bb1, bb4 // id: %18
-bb1: // Preds: bb0 bb4
- %19 = alloc_stack $C.Index // users: %21, %26, %44, %48, %49, %53, %54
+bb1: // Preds: bb0 bb3
+ %19 = alloc_stack $C.Index // let idx // users: %21, %26, %38, %42, %43, %47, %48
// function_ref Swift._getOptionalValue <A>(Swift.Optional<A>) -> A
%20 = function_ref Swift._getOptionalValue <A>(A?) -> A : $@thin <τ_0_0> (@out τ_0_0, @in Optional<τ_0_0>) -> () // user: %21
%21 = apply [transparent] %20<C.Index>(%19#1, %13#1) : $@thin <τ_0_0> (@out τ_0_0, @in Optional<τ_0_0>) -> ()
@@ -41,38 +41,38 @@ bb1: // Preds: bb0 bb4
dealloc_stack %29#0 : $*@local_storage C.Generator.Element // id: %33
dealloc_stack %25#0 : $*@local_storage C.Index // id: %34
dealloc_stack %24#0 : $*@local_storage C.Generator.Element // id: %35
- cond_br %32, bb3, bb4 // id: %36
+ cond_br %32, bb2, bb3 // id: %36
-bb2: // Preds: bb0 bb4
- dealloc_stack %13#0 : $*@local_storage Optional<C.Index> // id: %37
- destroy_addr %3#1 : $*RangeGenerator<C.Index> // id: %38
+bb4: // Preds: bb0 bb3
+ dealloc_stack %13#0 : $*@local_storage Optional<C.Index> // id: %52
+ destroy_addr %3#1 : $*RangeGenerator<C.Index> // id: %53
// function_ref Swift.Optional.init <A>(Swift.Optional<A>.Type)(nilLiteral : ()) -> Swift.Optional<A>
- %39 = function_ref Swift.Optional.init <A>(A?.Type)(nilLiteral : ()) -> A? : $@thin <τ_0_0> (@out Optional<τ_0_0>, @thin Optional<τ_0_0>.Type) -> () // user: %41
- %40 = metatype $@thin Optional<C.Index>.Type // user: %41
- %41 = apply [transparent] %39<C.Index>(%0, %40) : $@thin <τ_0_0> (@out Optional<τ_0_0>, @thin Optional<τ_0_0>.Type) -> ()
- br bb5 // id: %42
+ %54 = function_ref Swift.Optional.init <A>(A?.Type)(nilLiteral : ()) -> A? : $@thin <τ_0_0> (@out Optional<τ_0_0>, @thin Optional<τ_0_0>.Type) -> () // user: %56
+ %55 = metatype $@thin Optional<C.Index>.Type // user: %56
+ %56 = apply [transparent] %54<C.Index>(%0, %55) : $@thin <τ_0_0> (@out Optional<τ_0_0>, @thin Optional<τ_0_0>.Type) -> ()
+ br bb5 // id: %57
-bb3: // Preds: bb1
- %43 = alloc_stack $C.Index // users: %44, %46, %47
- copy_addr %19#1 to [initialization] %43#1 : $*C.Index // id: %44
+bb2: // Preds: bb1
+ %37 = alloc_stack $C.Index // users: %38, %40, %41
+ copy_addr %19#1 to [initialization] %37#1 : $*C.Index // id: %38
// function_ref Swift._injectValueIntoOptional <A>(A) -> Swift.Optional<A>
- %45 = function_ref Swift._injectValueIntoOptional <A>(A) -> A? : $@thin <τ_0_0> (@out Optional<τ_0_0>, @in τ_0_0) -> () // user: %46
- %46 = apply [transparent] %45<C.Index>(%0, %43#1) : $@thin <τ_0_0> (@out Optional<τ_0_0>, @in τ_0_0) -> ()
- dealloc_stack %43#0 : $*@local_storage C.Index // id: %47
- destroy_addr %19#1 : $*C.Index // id: %48
- dealloc_stack %19#0 : $*@local_storage C.Index // id: %49
- dealloc_stack %13#0 : $*@local_storage Optional<C.Index> // id: %50
- destroy_addr %3#1 : $*RangeGenerator<C.Index> // id: %51
- br bb5 // id: %52
+ %39 = function_ref Swift._injectValueIntoOptional <A>(A) -> A? : $@thin <τ_0_0> (@out Optional<τ_0_0>, @in τ_0_0) -> () // user: %40
+ %40 = apply [transparent] %39<C.Index>(%0, %37#1) : $@thin <τ_0_0> (@out Optional<τ_0_0>, @in τ_0_0) -> ()
+ dealloc_stack %37#0 : $*@local_storage C.Index // id: %41
+ destroy_addr %19#1 : $*C.Index // id: %42
+ dealloc_stack %19#0 : $*@local_storage C.Index // id: %43
+ dealloc_stack %13#0 : $*@local_storage Optional<C.Index> // id: %44
+ destroy_addr %3#1 : $*RangeGenerator<C.Index> // id: %45
+ br bb5 // id: %46
-bb4: // Preds: bb1
- destroy_addr %19#1 : $*C.Index // id: %53
- dealloc_stack %19#0 : $*@local_storage C.Index // id: %54
- %55 = apply %14<C.Index, C.Index.Distance, C.Index.Distance.IntegerLiteralType, C.Index._DisabledRangeIndex>(%13#1, %3#1) : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<τ_0_0>, @inout RangeGenerator<τ_0_0>) -> ()
- %56 = apply [transparent] %15<C.Index>(%13#1) : $@thin <τ_0_0> (@inout Optional<τ_0_0>) -> Builtin.Int1 // user: %57
- cond_br %56, bb1, bb2 // id: %57
+bb3: // Preds: bb1
+ destroy_addr %19#1 : $*C.Index // id: %47
+ dealloc_stack %19#0 : $*@local_storage C.Index // id: %48
+ %49 = apply %14<C.Index, C.Index.Distance, C.Index.Distance.IntegerLiteralType, C.Index._DisabledRangeIndex>(%13#1, %3#1) : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<τ_0_0>, @inout RangeGenerator<τ_0_0>) -> ()
+ %50 = apply [transparent] %15<C.Index>(%13#1) : $@thin <τ_0_0> (@inout Optional<τ_0_0>) -> Builtin.Int1 // user: %51
+ cond_br %50, bb1, bb4 // id: %51
-bb5: // Preds: bb2 bb3
+bb5: // Preds: bb2 bb4
destroy_addr %2 : $*C.Generator.Element // id: %58
destroy_addr %1 : $*C // id: %59
%60 = tuple () // user: %62
// I have changed order of some blocks for diff.
// my_find.my_find <A : Swift.CollectionType>(A, A.Generator.Element) -> Swift.Optional<A.Index>
sil my_find.my_find <A : Swift.CollectionType>(A, A.Generator.Element) -> A.Index? : $@thin <C where C : CollectionType, C.Generator : GeneratorType, C.Generator.Element : Equatable, C.Index : ForwardIndexType, C.Index.Distance : _SignedIntegerType, C.Index.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<C.Index>, @in C, @in C.Generator.Element) -> () {
bb0(%0 : $*Optional<C.Index>, %1 : $*C, %2 : $*C.Generator.Element):
%3 = alloc_stack $RangeGenerator<C.Index> // var $idx$generator // users: %10, %16, %45, %49, %53, %61
// function_ref Swift.Range.generate <A : Swift.ForwardIndexType>(Swift.Range<A>)() -> Swift.RangeGenerator<A>
%4 = function_ref Swift.Range.generate <A : Swift.ForwardIndexType>(Swift.Range<A>)() -> Swift.RangeGenerator<A> : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out RangeGenerator<τ_0_0>, @in Range<τ_0_0>) -> () // user: %10
%5 = alloc_stack $Range<C.Index> // users: %9, %10, %12
// function_ref Swift.indices <A : Swift.CollectionType>(A) -> Swift.Range<A.Index>
%6 = function_ref Swift.indices <A : Swift.CollectionType>(A) -> Swift.Range<A.Index> : $@thin <τ_0_0 where τ_0_0 : CollectionType, τ_0_0.Generator : GeneratorType, τ_0_0.Index : ForwardIndexType, τ_0_0.Index.Distance : _SignedIntegerType, τ_0_0.Index.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Range<τ_0_0.Index>, @in τ_0_0) -> () // user: %9
%7 = alloc_stack $C // users: %8, %9, %11
copy_addr %1 to [initialization] %7#1 : $*C // id: %8
%9 = apply %6<C, C.Generator, C.Generator.Element, C.Index, C.Index.Distance, C.Index.Distance.IntegerLiteralType, C.Index._DisabledRangeIndex, C._Element>(%5#1, %7#1) : $@thin <τ_0_0 where τ_0_0 : CollectionType, τ_0_0.Generator : GeneratorType, τ_0_0.Index : ForwardIndexType, τ_0_0.Index.Distance : _SignedIntegerType, τ_0_0.Index.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Range<τ_0_0.Index>, @in τ_0_0) -> ()
%10 = apply %4<C.Index, C.Index.Distance, C.Index.Distance.IntegerLiteralType, C.Index._DisabledRangeIndex>(%3#1, %5#1) : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out RangeGenerator<τ_0_0>, @in Range<τ_0_0>) -> ()
dealloc_stack %7#0 : $*@local_storage C // id: %11
dealloc_stack %5#0 : $*@local_storage Range<C.Index> // id: %12
%13 = alloc_stack $Optional<C.Index> // users: %16, %17, %21, %44, %49, %50, %52
// function_ref Swift.RangeGenerator.next <A : Swift.ForwardIndexType>(inout Swift.RangeGenerator<A>)() -> Swift.Optional<A>
%14 = function_ref Swift.RangeGenerator.next <A : Swift.ForwardIndexType>(inout Swift.RangeGenerator<A>)() -> A? : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<τ_0_0>, @inout RangeGenerator<τ_0_0>) -> () // users: %16, %49
// function_ref Swift._doesOptionalHaveValue <A>(inout Swift.Optional<A>) -> Builtin.Int1
%15 = function_ref Swift._doesOptionalHaveValue <A>(inout A?) -> Builtin.Int1 : $@thin <τ_0_0> (@inout Optional<τ_0_0>) -> Builtin.Int1 // users: %17, %50
%16 = apply %14<C.Index, C.Index.Distance, C.Index.Distance.IntegerLiteralType, C.Index._DisabledRangeIndex>(%13#1, %3#1) : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<τ_0_0>, @inout RangeGenerator<τ_0_0>) -> ()
%17 = apply [transparent] %15<C.Index>(%13#1) : $@thin <τ_0_0> (@inout Optional<τ_0_0>) -> Builtin.Int1 // user: %18
cond_br %17, bb1, bb4 // id: %18
bb1: // Preds: bb0 bb3
%19 = alloc_stack $C.Index // let idx // users: %21, %26, %38, %42, %43, %47, %48
// function_ref Swift._getOptionalValue <A>(Swift.Optional<A>) -> A
%20 = function_ref Swift._getOptionalValue <A>(A?) -> A : $@thin <τ_0_0> (@out τ_0_0, @in Optional<τ_0_0>) -> () // user: %21
%21 = apply [transparent] %20<C.Index>(%19#1, %13#1) : $@thin <τ_0_0> (@out τ_0_0, @in Optional<τ_0_0>) -> ()
%22 = metatype $@thick C.Generator.Element.Type // user: %31
%23 = witness_method $C.Generator.Element, #Equatable."=="!1 : $@cc(witness_method) @thin <τ_0_0 where τ_0_0 : Equatable> (@in τ_0_0, @in τ_0_0, @thick τ_0_0.Type) -> Bool // user: %31
%24 = alloc_stack $C.Generator.Element // users: %28, %31, %35
%25 = alloc_stack $C.Index // users: %26, %28, %34
copy_addr %19#1 to [initialization] %25#1 : $*C.Index // id: %26
%27 = witness_method $C, #CollectionType.subscript!getter.1 : $@cc(witness_method) @thin <τ_0_0 where τ_0_0 : CollectionType, τ_0_0.Generator : GeneratorType, τ_0_0.Index : ForwardIndexType, τ_0_0.Index.Distance : _SignedIntegerType, τ_0_0.Index.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out τ_0_0.Generator.Element, @in τ_0_0.Index, @inout τ_0_0) -> () // user: %28
%28 = apply %27<C, C.Generator, C.Generator.Element, C.Index, C.Index.Distance, C.Index.Distance.IntegerLiteralType, C.Index._DisabledRangeIndex, C._Element>(%24#1, %25#1, %1) : $@cc(witness_method) @thin <τ_0_0 where τ_0_0 : CollectionType, τ_0_0.Generator : GeneratorType, τ_0_0.Index : ForwardIndexType, τ_0_0.Index.Distance : _SignedIntegerType, τ_0_0.Index.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out τ_0_0.Generator.Element, @in τ_0_0.Index, @inout τ_0_0) -> ()
%29 = alloc_stack $C.Generator.Element // users: %30, %31, %33
copy_addr %2 to [initialization] %29#1 : $*C.Generator.Element // id: %30
%31 = apply %23<C.Generator.Element>(%24#1, %29#1, %22) : $@cc(witness_method) @thin <τ_0_0 where τ_0_0 : Equatable> (@in τ_0_0, @in τ_0_0, @thick τ_0_0.Type) -> Bool // user: %32
%32 = struct_extract %31 : $Bool, #Bool.value // user: %36
dealloc_stack %29#0 : $*@local_storage C.Generator.Element // id: %33
dealloc_stack %25#0 : $*@local_storage C.Index // id: %34
dealloc_stack %24#0 : $*@local_storage C.Generator.Element // id: %35
cond_br %32, bb2, bb3 // id: %36
bb2: // Preds: bb1
%37 = alloc_stack $C.Index // users: %38, %40, %41
copy_addr %19#1 to [initialization] %37#1 : $*C.Index // id: %38
// function_ref Swift._injectValueIntoOptional <A>(A) -> Swift.Optional<A>
%39 = function_ref Swift._injectValueIntoOptional <A>(A) -> A? : $@thin <τ_0_0> (@out Optional<τ_0_0>, @in τ_0_0) -> () // user: %40
%40 = apply [transparent] %39<C.Index>(%0, %37#1) : $@thin <τ_0_0> (@out Optional<τ_0_0>, @in τ_0_0) -> ()
dealloc_stack %37#0 : $*@local_storage C.Index // id: %41
destroy_addr %19#1 : $*C.Index // id: %42
dealloc_stack %19#0 : $*@local_storage C.Index // id: %43
dealloc_stack %13#0 : $*@local_storage Optional<C.Index> // id: %44
destroy_addr %3#1 : $*RangeGenerator<C.Index> // id: %45
br bb5 // id: %46
bb3: // Preds: bb1
destroy_addr %19#1 : $*C.Index // id: %47
dealloc_stack %19#0 : $*@local_storage C.Index // id: %48
%49 = apply %14<C.Index, C.Index.Distance, C.Index.Distance.IntegerLiteralType, C.Index._DisabledRangeIndex>(%13#1, %3#1) : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<τ_0_0>, @inout RangeGenerator<τ_0_0>) -> ()
%50 = apply [transparent] %15<C.Index>(%13#1) : $@thin <τ_0_0> (@inout Optional<τ_0_0>) -> Builtin.Int1 // user: %51
cond_br %50, bb1, bb4 // id: %51
bb4: // Preds: bb0 bb3
dealloc_stack %13#0 : $*@local_storage Optional<C.Index> // id: %52
destroy_addr %3#1 : $*RangeGenerator<C.Index> // id: %53
// function_ref Swift.Optional.init <A>(Swift.Optional<A>.Type)(nilLiteral : ()) -> Swift.Optional<A>
%54 = function_ref Swift.Optional.init <A>(A?.Type)(nilLiteral : ()) -> A? : $@thin <τ_0_0> (@out Optional<τ_0_0>, @thin Optional<τ_0_0>.Type) -> () // user: %56
%55 = metatype $@thin Optional<C.Index>.Type // user: %56
%56 = apply [transparent] %54<C.Index>(%0, %55) : $@thin <τ_0_0> (@out Optional<τ_0_0>, @thin Optional<τ_0_0>.Type) -> ()
br bb5 // id: %57
bb5: // Preds: bb2 bb4
destroy_addr %2 : $*C.Generator.Element // id: %58
destroy_addr %1 : $*C // id: %59
%60 = tuple () // user: %62
dealloc_stack %3#0 : $*@local_storage RangeGenerator<C.Index> // id: %61
return %60 : $() // id: %62
}
func my_find<C : CollectionType where C.Generator.Element : Equatable>(domain: C, value: C.Generator.Element) -> C.Index? {
for idx in indices(domain) {
if domain[idx] == value {
return idx
}
}
return nil
}
// Swift.find <A : Swift.CollectionType>(A, A.Generator.Element) -> Swift.Optional<A.Index>
sil public_external Swift.find <A : Swift.CollectionType>(A, A.Generator.Element) -> A.Index? : $@thin <C where C : CollectionType, C.Generator : GeneratorType, C.Generator.Element : Equatable, C.Index : ForwardIndexType, C.Index.Distance : _SignedIntegerType, C.Index.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<C.Index>, @in C, @in C.Generator.Element) -> () {
bb0(%0 : $*Optional<C.Index>, %1 : $*C, %2 : $*C.Generator.Element):
%3 = alloc_stack $RangeGenerator<C.Index> // users: %10, %16, %38, %51, %55, %61
// function_ref Swift.Range.generate <A : Swift.ForwardIndexType>(Swift.Range<A>)() -> Swift.RangeGenerator<A>
%4 = function_ref Swift.Range.generate <A : Swift.ForwardIndexType>(Swift.Range<A>)() -> Swift.RangeGenerator<A> : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out RangeGenerator<τ_0_0>, @in Range<τ_0_0>) -> () // user: %10
%5 = alloc_stack $Range<C.Index> // users: %9, %10, %12
// function_ref Swift.indices <A : Swift.CollectionType>(A) -> Swift.Range<A.Index>
%6 = function_ref Swift.indices <A : Swift.CollectionType>(A) -> Swift.Range<A.Index> : $@thin <τ_0_0 where τ_0_0 : CollectionType, τ_0_0.Generator : GeneratorType, τ_0_0.Index : ForwardIndexType, τ_0_0.Index.Distance : _SignedIntegerType, τ_0_0.Index.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Range<τ_0_0.Index>, @in τ_0_0) -> () // user: %9
%7 = alloc_stack $C // users: %8, %9, %11
copy_addr %1 to [initialization] %7#1 : $*C // id: %8
%9 = apply %6<C, C.Generator, C.Generator.Element, C.Index, C.Index.Distance, C.Index.Distance.IntegerLiteralType, C.Index._DisabledRangeIndex, C._Element>(%5#1, %7#1) : $@thin <τ_0_0 where τ_0_0 : CollectionType, τ_0_0.Generator : GeneratorType, τ_0_0.Index : ForwardIndexType, τ_0_0.Index.Distance : _SignedIntegerType, τ_0_0.Index.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Range<τ_0_0.Index>, @in τ_0_0) -> ()
%10 = apply %4<C.Index, C.Index.Distance, C.Index.Distance.IntegerLiteralType, C.Index._DisabledRangeIndex>(%3#1, %5#1) : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out RangeGenerator<τ_0_0>, @in Range<τ_0_0>) -> ()
dealloc_stack %7#0 : $*@local_storage C // id: %11
dealloc_stack %5#0 : $*@local_storage Range<C.Index> // id: %12
%13 = alloc_stack $Optional<C.Index> // users: %16, %17, %21, %37, %50, %55, %56
// function_ref Swift.RangeGenerator.next <A : Swift.ForwardIndexType>(inout Swift.RangeGenerator<A>)() -> Swift.Optional<A>
%14 = function_ref Swift.RangeGenerator.next <A : Swift.ForwardIndexType>(inout Swift.RangeGenerator<A>)() -> A? : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<τ_0_0>, @inout RangeGenerator<τ_0_0>) -> () // users: %16, %55
// function_ref Swift._doesOptionalHaveValue <A>(inout Swift.Optional<A>) -> Builtin.Int1
%15 = function_ref Swift._doesOptionalHaveValue <A>(inout A?) -> Builtin.Int1 : $@thin <τ_0_0> (@inout Optional<τ_0_0>) -> Builtin.Int1 // users: %17, %56
%16 = apply %14<C.Index, C.Index.Distance, C.Index.Distance.IntegerLiteralType, C.Index._DisabledRangeIndex>(%13#1, %3#1) : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<τ_0_0>, @inout RangeGenerator<τ_0_0>) -> ()
%17 = apply [transparent] %15<C.Index>(%13#1) : $@thin <τ_0_0> (@inout Optional<τ_0_0>) -> Builtin.Int1 // user: %18
cond_br %17, bb1, bb2 // id: %18
bb1: // Preds: bb0 bb4
%19 = alloc_stack $C.Index // users: %21, %26, %44, %48, %49, %53, %54
// function_ref Swift._getOptionalValue <A>(Swift.Optional<A>) -> A
%20 = function_ref Swift._getOptionalValue <A>(A?) -> A : $@thin <τ_0_0> (@out τ_0_0, @in Optional<τ_0_0>) -> () // user: %21
%21 = apply [transparent] %20<C.Index>(%19#1, %13#1) : $@thin <τ_0_0> (@out τ_0_0, @in Optional<τ_0_0>) -> ()
%22 = metatype $@thick C.Generator.Element.Type // user: %31
%23 = witness_method $C.Generator.Element, #Equatable."=="!1 : $@cc(witness_method) @thin <τ_0_0 where τ_0_0 : Equatable> (@in τ_0_0, @in τ_0_0, @thick τ_0_0.Type) -> Bool // user: %31
%24 = alloc_stack $C.Generator.Element // users: %28, %31, %35
%25 = alloc_stack $C.Index // users: %26, %28, %34
copy_addr %19#1 to [initialization] %25#1 : $*C.Index // id: %26
%27 = witness_method $C, #CollectionType.subscript!getter.1 : $@cc(witness_method) @thin <τ_0_0 where τ_0_0 : CollectionType, τ_0_0.Generator : GeneratorType, τ_0_0.Index : ForwardIndexType, τ_0_0.Index.Distance : _SignedIntegerType, τ_0_0.Index.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out τ_0_0.Generator.Element, @in τ_0_0.Index, @inout τ_0_0) -> () // user: %28
%28 = apply %27<C, C.Generator, C.Generator.Element, C.Index, C.Index.Distance, C.Index.Distance.IntegerLiteralType, C.Index._DisabledRangeIndex, C._Element>(%24#1, %25#1, %1) : $@cc(witness_method) @thin <τ_0_0 where τ_0_0 : CollectionType, τ_0_0.Generator : GeneratorType, τ_0_0.Index : ForwardIndexType, τ_0_0.Index.Distance : _SignedIntegerType, τ_0_0.Index.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out τ_0_0.Generator.Element, @in τ_0_0.Index, @inout τ_0_0) -> ()
%29 = alloc_stack $C.Generator.Element // users: %30, %31, %33
copy_addr %2 to [initialization] %29#1 : $*C.Generator.Element // id: %30
%31 = apply %23<C.Generator.Element>(%24#1, %29#1, %22) : $@cc(witness_method) @thin <τ_0_0 where τ_0_0 : Equatable> (@in τ_0_0, @in τ_0_0, @thick τ_0_0.Type) -> Bool // user: %32
%32 = struct_extract %31 : $Bool, #Bool.value // user: %36
dealloc_stack %29#0 : $*@local_storage C.Generator.Element // id: %33
dealloc_stack %25#0 : $*@local_storage C.Index // id: %34
dealloc_stack %24#0 : $*@local_storage C.Generator.Element // id: %35
cond_br %32, bb3, bb4 // id: %36
bb2: // Preds: bb0 bb4
dealloc_stack %13#0 : $*@local_storage Optional<C.Index> // id: %37
destroy_addr %3#1 : $*RangeGenerator<C.Index> // id: %38
// function_ref Swift.Optional.init <A>(Swift.Optional<A>.Type)(nilLiteral : ()) -> Swift.Optional<A>
%39 = function_ref Swift.Optional.init <A>(A?.Type)(nilLiteral : ()) -> A? : $@thin <τ_0_0> (@out Optional<τ_0_0>, @thin Optional<τ_0_0>.Type) -> () // user: %41
%40 = metatype $@thin Optional<C.Index>.Type // user: %41
%41 = apply [transparent] %39<C.Index>(%0, %40) : $@thin <τ_0_0> (@out Optional<τ_0_0>, @thin Optional<τ_0_0>.Type) -> ()
br bb5 // id: %42
bb3: // Preds: bb1
%43 = alloc_stack $C.Index // users: %44, %46, %47
copy_addr %19#1 to [initialization] %43#1 : $*C.Index // id: %44
// function_ref Swift._injectValueIntoOptional <A>(A) -> Swift.Optional<A>
%45 = function_ref Swift._injectValueIntoOptional <A>(A) -> A? : $@thin <τ_0_0> (@out Optional<τ_0_0>, @in τ_0_0) -> () // user: %46
%46 = apply [transparent] %45<C.Index>(%0, %43#1) : $@thin <τ_0_0> (@out Optional<τ_0_0>, @in τ_0_0) -> ()
dealloc_stack %43#0 : $*@local_storage C.Index // id: %47
destroy_addr %19#1 : $*C.Index // id: %48
dealloc_stack %19#0 : $*@local_storage C.Index // id: %49
dealloc_stack %13#0 : $*@local_storage Optional<C.Index> // id: %50
destroy_addr %3#1 : $*RangeGenerator<C.Index> // id: %51
br bb5 // id: %52
bb4: // Preds: bb1
destroy_addr %19#1 : $*C.Index // id: %53
dealloc_stack %19#0 : $*@local_storage C.Index // id: %54
%55 = apply %14<C.Index, C.Index.Distance, C.Index.Distance.IntegerLiteralType, C.Index._DisabledRangeIndex>(%13#1, %3#1) : $@cc(method) @thin <τ_0_0 where τ_0_0 : ForwardIndexType, τ_0_0.Distance : _SignedIntegerType, τ_0_0.Distance.IntegerLiteralType : _BuiltinIntegerLiteralConvertible> (@out Optional<τ_0_0>, @inout RangeGenerator<τ_0_0>) -> ()
%56 = apply [transparent] %15<C.Index>(%13#1) : $@thin <τ_0_0> (@inout Optional<τ_0_0>) -> Builtin.Int1 // user: %57
cond_br %56, bb1, bb2 // id: %57
bb5: // Preds: bb2 bb3
destroy_addr %2 : $*C.Generator.Element // id: %58
destroy_addr %1 : $*C // id: %59
%60 = tuple () // user: %62
dealloc_stack %3#0 : $*@local_storage RangeGenerator<C.Index> // id: %61
return %60 : $() // id: %62
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment