salient-lang / salient

http://salient-lang.dev/
MIT License
0 stars 0 forks source link

Floating value problem #17

Open AjaniBilby opened 3 months ago

AjaniBilby commented 3 months ago

Since we can have {} almost anywhere as a new block scope which can then resolve to a value which, so that entire block can be used as an expression.

This lead to a potential issue with early exit?

For instance with the line:

foo(a, {
  if randBool() return;
  b
})

There is a potential situation where a is either consumed by foo, or nothing is done, because during the evaluation of the second argument the function returns. What then happens to a?

We need to be able to track floating values, so that in the event on an early return, these floating values are safely disposed. This also must account for nesting, i.e.

bar(c, foo(...), d) // c and d should also be disposed of
AjaniBilby commented 3 months ago

This is currently a low priority issue as there is no concept of disposing or droping a value currently in the language, however it is a conceptual problem with the current direction that must be considered

AjaniBilby commented 3 months ago

This should also be accounted for in structure production:

let a: Foo = [
  .bar = "thing",
  .baz = { if maybe() return; else lift "valid"; }
  .bing = "more
];

If it returns during the construction of baz then bar needs to be cleaned up, but not bing. This also needs to account for nesting