Avatar
omochimetaru 7/12/2017 4:28 AM
おっ・・・
4:28 AM
except that copy_addr may be used even if %0 is of an address-only type. The copy_addr may be given one or both of the [take] or [initialization] attributes: [take] destroys the value at the source address in the course of the copy. [initialization] indicates that the destination address is uninitialized. Without the attribute, the destination address is treated as already initialized, and the existing value will be destroyed before the new value is stored.
4:29 AM
SIL命令copy_addr にオプションがつけられて、takeなら破壊、initializationなら初期化
4:30 AM
@norio_nomura の貼ったSILコードを抜粋すると (edited)
4:30 AM
... copy_addr [take] %6 to [initialization] %3 : $*Self, loc "<stdin>":4:14, scope 3 // id: %8 ... copy_addr %3 to [initialization] %0 : $*Self, loc "<stdin>":5:5, scope 3 // id: %10 ... (edited)
4:31 AM
%0はメソッドのレシーバ、%3はローカル変数のself、%6はf()の戻り値の格納先なので
4:32 AM
f()は完全なオブジェクトを返して、それを破壊しながらローカル変数のselfに初期化代入、つまりムーブ そのselfを、レシーバの真のselfに 初期化代入、そのあとdesstroy_addrで%3を破壊してるんで、ここはコピー
4:33 AM
結論として、allocはされてるけど、initはされてない形で全部回ってますね
4:33 AM
ちゃんとコンパイラはわかっているっぽい