Replies: 5 comments 2 replies
-
A value that is a record is a map and vice-versa. Record types and map types are two ways of describing sets of mapping values. For closed records and a I would recommend using tagged pointers for unions: you can represent that by a Rust union. |
Beta Was this translation helpful? Give feedback.
-
Levels of optimizations we could start with:
In previous BVM we had approach 1, current jBallerina backend uses approach 2. |
Beta Was this translation helpful? Give feedback.
-
Few updates to the aforementioned design proposal.
|
Beta Was this translation helpful? Give feedback.
-
We should be designing this in terms of the memory layout of the representation, not in terms of Rust. The problem is not "to figure out an efficient solution to model a r.x type member access in Rust". Rust has low-level support (e.g. raw pointers) to do whatever is needed. The goal is not (at this low level) to have a solution that is elegant or convenient in Rust: it only needs to be possible to build a convenient/elegant Rust interface on top of the low-level layer. Before you get into designing specific basic types, there fundamental problem is how to represent values tagged with basic types. Here's an paper on that, which is old, but useful: https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.39.4394&rep=rep1&type=pdf We also need to have some idea of how we are going to approach GC. |
Beta Was this translation helpful? Give feedback.
-
You might find this interesting: https://github.com/rust-lang/hashbrown/blob/master/src/raw/mod.rs It's the low-level hash-table implementation that underlies (with several layers of abstraction) Rust's HashMap. It uses the algorithm described in this talk: https://www.youtube.com/watch?v=ncHmEUmJZf4 It's interesting both because of the algorithm and because it illustrates how Rust can be used for really low-level manipulation of raw memory. |
Beta Was this translation helpful? Give feedback.
-
Design proposal for Record data types
Overview
Similar to how we have modeled the Map data type, we can model the record type object in the Rust runtime and use an opaque pointer on the LLVM codegen side to hold it as its value. The implementation of runtime operations (like load and store) will pass the record object's opaque pointer back to the run time library to invoke the correct functionality.
Note:
Data model - C++/BIR representation
Type
class needs to hold or point to the record type information e.g. "record_fields" and the record init function. Instead of Extending the currentType
class to support this, I propose to create a standalone class calledTypeRecord
. TheType
class will have a new generic member calledtypeStructure
of type std::variant. This will hold any type specific values. For Record types thetypeStructure
will be a reference to aTypeRecord
object. The actualTypeRecord
object ownership will be with a std::map container in thePackage
class, similar to how we currently store global variables. This design will allow us to easily extend Type class to support other complex types in the future without having to resort to extending theType
class and having to use pointers and static_cast in theVariable
class to hold Type member information.The
TypeRecord
class will include members to hold all the relevant parameters like name, rest_field, record_fields and init_function as well.Codegen logic
Init logic
c_str()
method ofstd::string
;TypeRecord
will expose ac_struct()
method to expose the C style structure required for the Rust APIRuntime operations
Data model - Runtime (Rust)
BalRecord
BalRecord
will contain the properties from theTypeRecord
class, with additional information to map Ballerina types to Rust typesBIR parser updates
ShapeCpInfo::read()
to handle record typesBIRReader::readFunction()
to support the parsing of Record's init functionBeta Was this translation helpful? Give feedback.
All reactions