-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Feature Request
There is a semantic mismatch between Rune and Python regarding parameter handling. Rune expects functions to be side-effect free, effectively treating parameters as immutable or passed-by-value.
In contrast, Python uses pass-by-assignment. When mutable objects (like lists or classes) are passed into a generated Python function, any modification to those objects reflects in the caller's scope, violating Rune’s functional integrity.
The Java implementation solves this by:
- Using "Holders" and "Builders."
- Performing a .toBuilder() call on assignment (effectively cloning).
- Returning a .build() result.
Current Failure Case:
In the following Rune snippet, the holder should remain unchanged in the calling scope. In the current Python generator, updated would simply be a reference to holder, and add would mutate the original object.
type IntHolder:
items int (0..*)
func AddItemToHolder:
inputs:
holder IntHolder (1..1)
value int (1..1)
output:
updated IntHolder (1..1)
set updated: holder
add updated -> items: value
Potential Solutions:
The Python Runtime and Generator must replicate "pass-by-value" behavior. There are two primary alternatives:
- Eager Copying: Deep-copy all mutable inputs upon function entry.
- Copy-on-Write (CoW): Use a wrapper that only clones the underlying data if a mutation (like add or set) is attempted.