cda-group / arc

Programming Language for Continuous Deep Analytics
https://cda-group.github.io/arc/
44 stars 6 forks source link

Convert sharable types into sendable types (and vice versa) #299

Closed segeljakt closed 3 years ago

segeljakt commented 3 years ago

For once, I present to you some really dank code

frej commented 3 years ago

Oh, the tests failed, I guess we'll have to implement the annotations in the MLIR code generator.

segeljakt commented 3 years ago

LGTM. Is it limitations in the macro system that prevents you from inspecting the types of the struct fields? At the MLIR-level I don't think we'll have any problems generating the annotations by just looking at the types.

It is possible to inspect the types syntactically and map them to their categories. Primitives should probably be hard coded into the code generator. The distinction between algebraic and dynamic types is only about performance. We for example do not need box non-recursive types Box<String>. Still, maybe it is a good idea to box them to simplify the generated code. One thing we need to change in MLIR is to put std::rc::Rc<std::cell::RefCell<T>> around any type which is not a primitive. I have not decided yet what to do with function types.

Another thing is currently we have that impl From<Operable> for Sendable and impl From<Sendable> for Operable. Where

trait From<T> {
    fn from(x: T) -> Self;
}

This means multiple conversions could exist per type. I am going to change this to a new trait Convert:

trait Convert {
    type T;
    fn convert(self) -> Self::T;
}

And have impl Convert for Sendable { type T = Operable } and impl Convert for Operable { type T = Sendable }. This ensures only a single conversion exists per type. Because of this, we can also retrieve the corresponding type after conversion for any type. This however requires that all types, including primitives, implement the trait. I think it can be a good approach however since it gives us full control over which types are allowed and not allowed to run on our system.

segeljakt commented 3 years ago

Made some dank mods to the conversion code, now it should be way easier to generate

segeljakt commented 3 years ago

We can bring arc-mlir up-to-date next week

One thing we need is to place a use arcorn::*; at the top-level of the generated code to import all primitive types.

segeljakt commented 3 years ago

I added a macro for accessing values, val!(x) instead of (x.clone()). To make the generated code less verbose I removed the arcorn:: prefix from paths. If you prefer it the other more explicit way I could undo the last commit.