On Thu, Jan 14, 2010 at 9:25 PM, me22 <span dir="ltr"><<a href="http://me22.ca">me22.ca</a>@<a href="http://gmail.com">gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
2010/1/14 Talin <<a href="mailto:viridia@gmail.com">viridia@gmail.com</a>>:<br>
<div class="im">> The reason for doing it this way is that to construct a union, you really<br>
> need 4 pieces of information: The type of the union, the type and value of<br>
> the member to be initialized, and the index of which member is being<br>
> initialized.<br>
<br>
</div>Does requiring the index mean that uniquing the union type will have<br>
to re-write many of the corresponding insertvalue calls?<br>
<br>
For instance, how would this round-trip?<br>
<br>
@foo = constant union { float, i32 } insertvalue union { i32,<br>
<div class="im">float } undef, i32 4, 0<br>
</div> @bar = constant union { i32, float } insertvalue union { float,<br>
i32 } undef, i32 4, 1<br></blockquote><div><br></div><div>Well, the fact that union members have to be indexed by number means that the ordering has to be part of the type - so even though type-theoretically union { i32, float } is the same as union { float, i32 }, in my implementation they are distinct types. However, from the standpoint of a frontend, this is not a great concern, because the frontend will most likely sort the list of types before constructing the IR type. By always putting the types in a canonical order, regardless of the order that they appear in the source code, you can ensure that unions of equal types are always compatible. In other words, you can treat the members like an ordered set rather than like a list. </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
I'm very glad to see a non-bitcast method of using unions, BTW.<br>
</blockquote></div><br>-- <br>-- Talin<br>