pschachte / wybe

A programming language supporting most of both declarative and imperative programming
MIT License
43 stars 6 forks source link

Implement automatic parameter/argument globalisation #37

Open pschachte opened 4 years ago

pschachte commented 4 years ago

Using some suitable heuristic, automatically pass some procedure input and output arguments in global variables. This will be beneficial for arguments passed around widely through the program, and probably detrimental for arguments that change frequently.

It would probably be best to actually store all these in allocated heap memory, so that each thread can have its own set, when we support multithreading.

PaulBone commented 2 years ago

It would probably be best to actually store all these in allocated heap memory, so that each thread can have its own set, when we support multithreading.

Mercury has a 'tupling' pass that looks for a set of arguments passed through a group of predicates. it then creates a structure for those arguments as a set and allocates them on the heap, then it passes a single pointer to that structure in their place. So it reduces the amount of parameters each call needs to manipulate, and frees registers, at the cost of adding an indirection when you wish to read/write one of the parameters.

I think what you're suggesting is tracking pointers to your heap-allocated things in thread-local storage (TLS) (I've been chatting with "jimbob"). it would almost be the same thing except TLS storage has more pointer following but avoids passing an argument. The other difference is that the mercury tupling solution is more dynamic, not needing to allocate TLS space (whether that's something you let the OS manage or you manage yourself).

jimbxb commented 2 years ago

I'm "jimbob" :)

pschachte commented 5 months ago

Since resources are now actually passed through global variables, that could be used to implement this.