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

If behaviour on stuck terms #239

Open
o-santi opened this issue Nov 19, 2022 · 4 comments
Open

If behaviour on stuck terms #239

o-santi opened this issue Nov 19, 2022 · 4 comments

Comments

@o-santi
Copy link
Contributor

o-santi commented Nov 19, 2022

Currently, the (If ...) rule on the genesis block evaluates everything that is strictly not #0 to the true branch. This includes terms that cannot reduce any further, which can cause some very unexpected behaviour when comparing objects of different types.

For example, the following code:

fun (Test x) {
  (Test x) = (If (== x #5) (Done 'yay') (Fail #0))
}

run {
  ask test = (Call 'Test' [#4])
  (Done test)
}

will silently fail. It will always evaluate to (Done 'yay') even though it clearly is not the intended semantics, because the following comparison (== {T1 #4} #5) gets stuck, and If evaluates that to true.

I do believe that we should change it match only on #0 and #1, in order to avoid javascript-esque errors like these. But I think that this raises a bigger question: what should be the norm/expected behaviour on treating stuck terms?

cc @steinerkelvin @developedby

@developedby
Copy link
Contributor

Changing the If like this would break compatibility with normal HVM's if function, which implements it like the current version of the function in Kindelia's HVM.

@developedby
Copy link
Contributor

I think that many people will expect thgat If behaves like C's ìf` statement does. This is not a hard barrier, but is something to consider.

Besides, having a non-complete function can bring other misterious errors. This masks the original function that got stuck and can be hard to debug. It's better than just swallowing the error without any traces, but is still not great

@steinerkelvin
Copy link
Contributor

The real question here is if we should emit errors on stuck function redexes. If there are no use cases that would be made impossible we should probably do it.
@VictorTaelin

@VictorTaelin
Copy link
Contributor

We did that on that other issue and it was problematic, no? I must remember the context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants