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

prolog? leaks pvars out of its context. #58

Open
NHALX opened this issue Jul 4, 2018 · 4 comments
Open

prolog? leaks pvars out of its context. #58

NHALX opened this issue Jul 4, 2018 · 4 comments

Comments

@NHALX
Copy link

NHALX commented Jul 4, 2018

(0-) (let PZ (prolog? (return Free)) \\ Free isn't derefed
       (prolog? (receive PZ)
                (unify PZ 1)         \\ Should fail because PZ should not be a logic variable in this context
                (return PZ)))
1

(1-) (shen.pvar? (prolog? (return Free)))
true

(2-) (symbol? (prolog? (return Free)))
false

It's more noticeable in larger code where the old pvar get's reclaimed before being used again:
"Exception in vector-ref: 19 is not a valid index for #(10 shen.-null- ...."

@tizoc
Copy link
Member

tizoc commented Jul 7, 2018

@NHALX how does this behave in SP?

@NHALX
Copy link
Author

NHALX commented Jul 7, 2018

@tizoc SP does the same thing.

This thread talks about it a bit https://groups.google.com/forum/#!topic/qilang/xE67c7o7zkk

It's unclear how it should best be handled, but the way it is now isn't so great.

@tizoc
Copy link
Member

tizoc commented Dec 12, 2019

@NHALX does SP with the new prolog still behave like this? if not, which decision was made?

@NHALX
Copy link
Author

NHALX commented Dec 12, 2019

@tizoc Not sure how SP handles this now, but I think the best choice is to either modify 'return' or create a variant which converts unbound pvars to normal variables with the same name (or some special 'dead' value). The full dereferencing which currently happens on return needs to traverse and re-build the whole term anyway so there would be no performance hit.

Making PVars reusable in different contexts is possible, but it adds extra constraints to the implementation which may have performance implications.

Anyway, the first option doesn't preclude the second, and is basically just a cut and paste job with minor modifications.

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

3 participants