Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide internals of values #663

Merged
merged 11 commits into from
Feb 17, 2024
Merged

Hide internals of values #663

merged 11 commits into from
Feb 17, 2024

Conversation

udoprog
Copy link
Collaborator

@udoprog udoprog commented Feb 16, 2024

This is the big change for the next major release of Rune.

  • The internals of the Value type will be made private, so there will be no way to match over variants.
  • Cloning a Value doesn't clone the interior value, effectively meaning that numbers and other primitives are no longer implicitly copy.

Internals of Value are private

This means that we can internally use any signature, giving us more freedom in how the language is evolved in the future. So we eat the breakage now instead.

As a result of this change, Shared is private.

All values are structurally shared

For converting to and from Value, you should prefer to use rune::to_value and rune::from_value.

The second change is necessary to implement many future compiler optimizations, such as this:

let a = expr1;
let b = expr2;
let (a, b) = (b, a);

Preferably a compiler should convert this to:

let a = expr2;
let b = expr1;

However, in a dynamic language the semantics of the tuple assignment depends on whether a and / or b are copy types. The assignment would either copy the underlying values or structurally share the values. This matters if such assignments are later mutated.

This change ensures that the language has a single semantic; all values unless they are explicitly cloned with the clone method are structurally shared. Even numerical values.

@udoprog udoprog force-pushed the interior-shared-value branch 2 times, most recently from 252ca22 to 45156b8 Compare February 17, 2024 00:00
@udoprog udoprog force-pushed the interior-shared-value branch from 45156b8 to 2992cc0 Compare February 17, 2024 00:02
@udoprog udoprog merged commit 1c23f2e into main Feb 17, 2024
19 checks passed
@udoprog udoprog deleted the interior-shared-value branch February 17, 2024 00:34
@udoprog udoprog restored the interior-shared-value branch February 17, 2024 00:34
@udoprog udoprog deleted the interior-shared-value branch February 17, 2024 00:34
@udoprog udoprog mentioned this pull request Jul 26, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant