Files
swift-mirror/test/SIL/Parser/indirect_enum.sil
Joe Groff 277608a69b Print and parse SILBoxTypes with a new syntax.
Use a syntax that declares the layout's generic parameters and fields,
followed by the generic arguments to apply to the layout:

  { var Int, let String } // A concrete box layout with a mutable Int
                          // and immutable String field
  <T, U> { var T, let U } <Int, String> // A generic box layout,
                                        // applied to Int and String
                                        // arguments
2016-12-02 13:44:22 -08:00

56 lines
1.5 KiB
Plaintext

// RUN: %target-swift-frontend -emit-sil -verify %s
sil_stage canonical
import Swift
indirect enum TreeA<T> {
case Nil
case Leaf(T)
case Branch(left: TreeA<T>, right: TreeA<T>)
}
enum TreeB<T> {
case Nil
case Leaf(T)
indirect case Branch(left: TreeB<T>, right: TreeB<T>)
}
enum TreeInt {
case Nil
case Leaf(Int)
indirect case Branch(left: TreeInt, right: TreeInt)
}
sil @indirect_enum : $@convention(thin) <T> (@owned TreeA<T>) -> () {
entry(%e : $TreeA<T>):
%a = unchecked_enum_data %e : $TreeA<T>, #TreeA.Leaf!enumelt.1
%b = project_box %a : $<τ_0_0> { var τ_0_0 } <T>, 0
%c = unchecked_enum_data %e : $TreeA<T>, #TreeA.Branch!enumelt.1
%d = project_box %c : $<τ_0_0> { var τ_0_0 } <(left: TreeA<T>, right: TreeA<T>)>, 0
return undef : $()
}
sil @indirect_enum_case_addr_only : $@convention(thin) <T> (@in TreeB<T>) -> () {
entry(%e : $*TreeB<T>):
%a = unchecked_take_enum_data_addr %e : $*TreeB<T>, #TreeB.Leaf!enumelt.1
%b = destroy_addr %a : $*T
%c = unchecked_take_enum_data_addr %e : $*TreeB<T>, #TreeB.Branch!enumelt.1
%d = load [take] %c : $*<τ_0_0> { var τ_0_0 } <(left: TreeB<T>, right: TreeB<T>)>
return undef : $()
}
sil @indirect_enum_case_loadable : $@convention(thin) (@owned TreeInt) -> () {
entry(%e : $TreeInt):
%a = unchecked_enum_data %e : $TreeInt, #TreeInt.Leaf!enumelt.1
store %a to [trivial] undef : $*Int
%c = unchecked_enum_data %e : $TreeInt, #TreeInt.Branch!enumelt.1
%d = project_box %c : $<τ_0_0> { var τ_0_0 } <(left: TreeInt, right: TreeInt)>, 0
return undef : $()
}