ohua-lang / condrust

Repository for the Rust SharedMemory integration, codenamed `ConDRust` of the Ohua compiler.
Other
0 stars 0 forks source link

Rules for Data Sharing #3

Open Pagolin opened 7 months ago

Pagolin commented 7 months ago

This is less a coding and more a conceptual issue: Should we enforce a strict no-sharing i.e. no-variable-reuse policy in all integrations?

This is currently not done, meaning variables can be reused as argument to multiple function calls. This is sometimes appropriate e.g. for copy types in Rust and basically anything in the Python integration. BUT a) it is not generally valid (move semantics in Rust) and b) it leads to invalid output code in some test cases (see FAIL: results)

So the always correct but inconvenient solution would be to enforce explicit copies/duplication in the input code. Alternatively we could introduce a configuration flag to enable or disable sharing and leave it to the programmer (-> which will weaken our guarantees.)

sertel commented 7 months ago

I believe, we should not leave it to the programmer.

For now, we only assume the explicit copying that you mention. We only assume this because we do not define a type system for Rust and then show how this maps to Ohua's type system. The assumption in Ohua's type system, is that all state variables are mutable and all other variable are immutable. In an appropriate mapping of the Rust type system to Ohua's type system, we would define this aspect explicitly.

So this issue really is about a proper type system for Rust (with ownership semantics) and its mapping to Ohua's type system.