Please test branch no-local-references

I’ve made massive changes to the internals that I would like to see tested.


The change prepares further VM (Virtual Machine) updates. For those with a background in these matters, SWI-Prolog uses stack based argument passing. Reference pointers (which result from unifying two variables) could exist between environment stack frames, as well as from environment stack frames to the global stack and internally on the global stack. The changes prevent reference links between variables on the local (environment) stack by always creating a variable on the global stack and have both environment variables share with this new variable. Having only reference links to and inside the global stack has two advantages: (1) is simplifies dereferencing, but most importantly (2) it makes it easy to copy environment slots and arguments around. The latter simplifies LCO (Last Call Optimization) (done) and most importantly, allows for properly optimized LCO calls (not done).

This change has been proposed by Bart Demoen several years ago.


This should have no compatibility consequences, except that the foreign API PL_put_term() return type changed from void to int and this function can now fail due to a stack overflow when putting a term reference that is a fresh variable. Applications should check the return value, though in most use cases overflows are not possible.

Without the last step the resource implications (time and space) seem minimal. Space is barely measurable worse (unavoidable) and time seems marginally better (a few percent).


I’ve tested this on all my internal tests and Logtalk. If you can build from a branch and have a program with a test suite, please try this branch. Issues should probably surface as crashes or wrong answers due to incorrectly functioning variable sharing. Please also report significant performance implications or space usage.


Given a working git build environment, this is as simple as

 git pull
 git checkout -b no-local-references --track origin/no-local-references
 ninja (or make)
 ninja (or make) install

To go back, simply do git checkout master and rebuild as above.


If no problems are reported in the coming days I’ll merge this into master