-
Notifications
You must be signed in to change notification settings - Fork 77
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
TC: name confusion #493
Comments
I think the problem here is that there is also an abstract type named |
@mahills you are completely right. In fact all problems in the
The current dilemma is:
We have written the type checker and the compiler mostly relying on concrete patterns, but we will occasionally want a bridge between concrete and abstract syntax. Has anyone ideas for a solution? |
@PaulKlint , at least for this it would work to be able to give a qualified name in the concrete pattern, but in general this is just painful because the types are separate. It probably works in the interpreter because the interpreter just does bizarre stuff with these scenarios, it is probably merging the two types and then picking the right one out when it needs to (but, on the other hand, potentially turning things to value in other places). One solution may be to say that these are both the same type, and just keep track of whether a type can have productions, constructors, or both. I'm not sure what other problems that would cause, though. |
@mahills Indeed, qualified names in concrete patterns are not the solution either. I like you idea about merging constructors and productions in a single type since that eliminates the current confusion. Find it hard to oversee the implications of this. |
This solution would imply that instead of
we can write
and that looks great! |
I'm not sure it has any problems, I just want to be careful. It would definitely simplify things. On Feb 11, 2014, at 5:43 PM, "Paul Klint" <notifications@github.commailto:notifications@github.com> wrote: @mahillshttps://github.com/mahills Indeed, qualified names in concrete patterns are not the solution either. I like you idea about merging constructors and productions in a single type since that eliminates the current confusion. Find it hard to oversee the implications of this. — |
Well, the subtyping of concrete nonterminal types with |
We have considered such option before and did not arrive at a good design yet. Indeed the Tree type is in the way, but also the fact that a parse tree is really different from an ast. We also need a common super type of all parse trees for language independent processing...— On Wed, Feb 12, 2014 at 4:39 PM, mahills notifications@github.com wrote:
|
Also there would be type safety problems where asts could suddenly be nested inside parse trees. — On Wed, Feb 12, 2014 at 6:17 PM, Jurgen J. Vinju notifications@github.com
|
Ah, good point, we really can't keep track of whether the type was
|
I am further exploring this issue and a bit simpler example is this:
which gives @mahills you said that "the abstract type knocks the concrete type out of scope", but would it in any way be possible to use the knocked out type in the case of |
I'm looking at this again, so it's probably best we restart the conversation on this topic :) Honestly, I'm still not sure the best approach here. The problem remains as before, even after the various changes -- because the current module would import two distinct types named |
We need a radical solution here, i.e. A language change. I believe a type constructor to separate the two name spaces would help or a different solution for implode which does not require the names to be equal or both..— On Wed, Jun 18, 2014 at 6:07 PM, mahills notifications@github.com wrote:
|
I agree. Given code like this:
where |
@mahills I agree that the current situation is unacceptable and that we need something better. I will discuss this the coming days with @jurgenvinju and @tvdstorm and maybe we can have a Skype session after that. Any ideas/suggestions appreciated. |
For now such ambiguity should be flagged as an error and resolvable using qualification. Is that possible without a big effort?— On Wed, Jun 18, 2014 at 6:54 PM, mahills notifications@github.com wrote:
|
We can flag it as an error, I'll just need to carry around information about which names were not added because they would have created ambiguities, like |
Not sure it was mentioned yet, but the current solution is to keep both ADT and grammar in separate modules, and use qualified names only in a custom Implode module. The other unfortunate thing is is that qualified non-terminal names don't work in |
start[X] could be an exception because X can only be a non-terminal. On Thu, Jun 19, 2014 at 1:25 PM, mahills notifications@github.com wrote:
Jurgen Vinju
|
@tvdstorm I thought that was the case, but wanted to check the grammar first to make sure my memory was accurate. @jurgenvinju we can do that in multiple places (we could say the same of the use of the names inside concrete syntax patterns, for instance), but that would still leave open the question of how we differentiate a concrete |
Agreed. We have a simple concept for the other names and conflicts, namely merging the functions, datatypes, whenever possible, but we don't know how to merge abstract and concrete syntax yet.. A solution could be in this direction, where we truly consider data A and syntax A to produce concrete terms of the same abstract sort. From the perspective of the liskov principle, embedding a concrete tree in an abstract one is fine, but vice versa is a problem. We need a step that automatically lifts an abstract tree to a concrete one to fix this.... Then we would always generate type safe trees and the abstract type and the syntax type could be unified. On Thu, Jun 19, 2014 at 3:48 PM, mahills notifications@github.com wrote:
|
This file is still pestering us, @mahills what are your current thoughts on this? Before delving into language changes (as suggested above and in the related issues) we need to get this one up and running. Currently the messages are:
|
I now have this as the message in all the places where
This could also do with some work (since it gives names for both concrete and abstract types), but at least it's more informative. It also gives a better description of the error -- |
That is certainly an improvement. We keep running in circles since, sadly, all roads to a solution are blocked by the fact that we can currently not use qualified names in certain places:
I propose therefore that we put this issue on hold and reenact it when we become more liberal in the use of qualified names. In the mean time I will rewrite/delete some of the demo that cause these problems. |
I'll see what I can do to handle those in the checker as well -- I may be able to handle all those cases without too much trouble. |
But this will also require changes to the Rascal syntax and I am reluctant to do that now since that will break things in various places. |
@PaulKlint for the three cases you mention the semantics is unambiguous; it can not be anything but a concrete syntax type. I suspect @mahills is planning to hard code this fact into the type checker as an intermediate solution. |
@jurgenvinju something like that -- I'm just trying to decide if I should look them up manually, using the information I already have, or add another map to the configuration (which would be slightly faster but would take up even more space, then, and require maintenance to keep it up to date) |
@mahills I guess you answered that one. Look up manually 👍 |
@PaulKlint I believe all 3 cases are now supported |
Super, will check this in a moment. |
But on second thoughts, how could I test this? Any example will be syntactically incorrect! Do you have an example where this works? Or should we just postpone testing this until we have syntactic support for the above 3 cases? |
What I've done is to allow cases like the above to work with unqualified names. For instance, if you import a concrete and an abstract version of |
All the checking also makes sure it was really imported, instead of somehow "leaking" through (since we bring in all the grammar info transitively anyway). |
Great! @PaulKlint so we need a test where |
The module that started this issue is a perfect example, since it does this (except for using |
Indeed, the above example (with disambiguated names) now works fine (I was under the assumption that more disambiguation was needed). I am inclined to close this issue for now. We end up with the following, quite ugly, but working code. I may remove this from the demos to avoid confronting Rascal novices with this.
|
One way to make the code look better is to choose different names for |
Actually, in this specific example we do the mapping manually and could rename as we like. However, to be compatible with the |
I guess we could also use aliases -- I haven't tried it here, but think it would work. |
certainly aliases should work as well to make the code look better. |
Right, then maybe add
and then use that for the return types, which would leave it well-typed while making it look better. That would at least take care of it for now. I'm happy to make the changes in a bit... |
Thanks @mahills, but I have some other changes in mind as well. So will do this. |
With 43 comments this is one of the longer discussions, nonetheless closing it now. |
Compiling
demo::lang::Exp::Combined::Manual::Load
:leads to a lot of name confusion:
The text was updated successfully, but these errors were encountered: