-
Notifications
You must be signed in to change notification settings - Fork 78
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
Interpreter does not distinguish the run-time type from the static type of functions and closures #1468
Comments
A fix to this issue would entail a separation of the Currently the static and dynamic perspective on Rascal are completely tangled in these four classes and it will be quite a challenge to extract the two perspectives while maintaining functional correctness w.r.t. the current test set. Separating the static from the dynamic semantics for functions will allow us to implement both perspectives correctly, and especially the hygiene (non leakage) of recursive function application and higher-order self-application can be fixed if function instances will be allowed to have different (more concrete) run-time types while their actual code, declaration scope and variable bindings remain the same. I expect this to be a major destabilizing operation for the current interpreter. Since this interpreter is also used to bootstrap the compiler which is nearly finished, there is the question: "is this really the right time?" to fix this enormous bug. |
So there is
|
…t.getType to Result.getStaticType and added missing IValue.getType implementations where needed after that. This means that all function implementations now explicitly implement IValue.getType by forwarding to Result.getStaticType. This is obviously wrong (see #1468), but now at least it is explicitly clear in the code without introducing a semantic change (yet)
Note that simply implementing the new IValue.getType for all function classes will not work. A lot of other related things will have to be fixed. The initial new functionality would be is that function instances must receive their "instantiated" run-time type at construction time. After that, there are consequences:
|
having separated the dynamic types from the static types and also separated tuple type instantiation from function type instantiation has fixed many issues on the current unstable master. However, self-application of curry is still broken. The quest has lead to the match method of ParameterType in vallang; I'm recording my current findings here, for later reference or contradiction:
|
resolving usethesource/vallang#99 improved the situation significantly:
but we're not done yet. As we see uninstantiated types in the final two commands. There is some instantiation missing in the interpreter's code? |
And, the new semantics of vallang after fixing usethesource/vallang#99 results in many failing tests in Rascal: https://ci.usethesource.io/job/usethesource/job/rascal/job/master/1718/#showFailuresLink |
all existing tests are working again after fixes in both vallang and rascal. but we're still stuck here:
|
Almost there!
Some test in vallang is failing; have to fix before calling it a day. |
thanks to @rodinaarssen for the help |
Describe the bug
This is a continuation of issue #1467;
When a generic function returns a (partially instantiated) function value, the interpreter does not properly instantiate the run-time type of the given closure. (For example when applying the curry function to itself). The result that the interpreter both reports erroneous static types, as well as fails to instantiate the dynamic type of the returned closure (it remains carrying a renamed static type instead).
The root cause is a very basic (and wrong) assumption in the code of the interpreter: for functions (closures and/or generic or otherwise) the static type is equal to their dynamic type. This is because each function instance extends
Result<IValue>
(which tuples a static type with a dynamic value), as well as implementsIFunction
andICalleableValue
which are dynamic value implementations. Both Result and IValue implementgetType()
but their intended semantics is quite different. Fixing this entails a significant rewrite of the function calling semantics in the interpreter.To Reproduce
reports:
here we see too many uninstantiated and renamed type variables.
The text was updated successfully, but these errors were encountered: