This is an attempt to work around #1136 in a principled, but ugly, way.
A shorter fix is possible (8cee258) but this approach delays fixing the mismatch between closure variable and environment until the point FunctionPtr is called. Since we are already looking up the function info there and checking various things, that's no real problem, but I don't like this way of doing things because it delays the point where we make things right to the point where something is about to go wrong, rather than the point where we create the FunctionPtr value representing a server-side call request received from the client.
An approach that is both clean and principled would be nicer, but might take a lot more work. For example, fully closure-converting the IR functions so that the environment is passed as an ordinary variable, all function bodies are closed, and IR code does the bureaucracy of passing around environment variables would potentially fix this, but it woudl also be a lot more work (possibly including adding existentials to the IR if we want to be able to typecheck after closure conversion ala Minamide et al.)
This is an attempt to work around #1136 in a principled, but ugly, way. A shorter fix is possible (8cee258) but this approach delays fixing the mismatch between closure variable and environment until the point FunctionPtr is called. Since we are already looking up the function info there and checking various things, that's no real problem, but I don't like this way of doing things because it delays the point where we make things right to the point where something is about to go wrong, rather than the point where we create the FunctionPtr value representing a server-side call request received from the client.
An approach that is both clean and principled would be nicer, but might take a lot more work. For example, fully closure-converting the IR functions so that the environment is passed as an ordinary variable, all function bodies are closed, and IR code does the bureaucracy of passing around environment variables would potentially fix this, but it woudl also be a lot more work (possibly including adding existentials to the IR if we want to be able to typecheck after closure conversion ala Minamide et al.)