Implementation of union-type-descriptor #113
-
This discussion is open to finalize the design on union-type-descriptor implementation. I have presented a couple of bal codes, BIRs and expected shapes of LLVM IR. If I am wrong on the expected shapes of LLVM IR, please correct me. ex : 1
In this case, since there is not a variable initialization we can simply represent ex : 2
In this case, we have to do the type checking on the rust side(we need to send member types as destination type and type of 3% as source type) and should return a value of i64*. ex : 3
In this case, we have to do the type checking twice.
Highly appreciated your feedback in order to proceed with the implementations. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 22 replies
-
In ex 2, we still don't need a type check, since form compile time information we can see casting becase :
|
Beta Was this translation helpful? Give feedback.
-
@ayonam , do you have any suggestions or corrections? |
Beta Was this translation helpful? Give feedback.
-
@KavinduZoysa @manuranga I'm not sure I got this right. Our current method of boxing has the following format: +-----------------+ Now, for the Union, say ( +-----------------+ Now, an assignment operation of an integer to this union will come with a structure like the first one above with the 'Data' being an integer and the Current TypeStr showing an Integer Type as per our name mangling mechanism. Looking at the Current Type of the RHS, the LLVM code should load the Data portion of the RHS and assign it to the "Integer Value" in the structure above. Likewise, if the RHS is a string, it should assign it to the String Object. Here, there will be a typecheck needed before this operation, if the current type shows as "Any". In that case, the Original Type of the RHS and the current type of the LHS (union in this case), should be sent to Rust side for type checking. If the rust side returns true, then the assignment logic mentioned above should be executed. One more case would be if there is an operation between two such objects. Like say an addition operation. Unless the current type is Any, the front-end would have ensured that the types are matching. But one or both the types are Any, then we should first do a typecheck from the Rust side using the original types. Then if both are integers, we perform an add operation. If both are strings, we call Rust to concatenate them. If one is a string and another an integer, we throw an exception (call abort for now). You need to check with @ramakotareddy about how we are doing this. |
Beta Was this translation helpful? Give feedback.
@KavinduZoysa @manuranga I'm not sure I got this right. Our current method of boxing has the following format:
+-----------------+
| Current TypeStr |
+-----------------+
| Original TypeStr |
+-----------------+
| Data |
+-----------------+
Now, for the Union, say (
int | string
), I would envisage it as follows:+-----------------+
| Current TypeStr |
+-----------------+
| Original TypeStr |
+-----------------+
| Integer Value |
+-----------------+
| String Object |
+-----------------+
Now, an assignment operation of an integer to this union will come with a structure like the first one above with the 'Data' being an integer and the Current TypeStr showing an Integer Type as per our name m…