-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add the scope of definition to its constructor #997
Comments
I think I am against making this change. As for showing or jumping to a definition site, I don't think it is that hard. For locally-bound variables, we can keep a |
Good points @byorgey. 👍 Just to clarify, my issue is that except for a few shallowly nested defs, they already do kind of “have their scope nested inside”. To me it seems like a waste to not use the Def directly and get more sensible structure. After all the “future uses” of the def will only be in REPL or once we have import in the file that imports it. So it will make sense for its AST. |
@byorgey what about redefinition though? (move; def m = make end); m "board"; def m = move end In this example the result of the processing pipeline that the OnHover uses will look something like this: Bind
(Bind
move
(Def m make))
(Bind
(m "board")
(Def m move)) If we straighten the Binds which I arranged in this silly way in the example, we get: Bind
move
(Bind
(Def m make)
(Bind
(m "board")
(Def m move))) Here the extra Bind
move
(Def m make
(Bind
(m "board")
(Def m move noop))) TLDR The result in context is that I would prefer just recursing down the tree, not doing an in-order traversal to find if any redefinition occurred. |
Btw. this would be less performant than in-order traversal unless we keep the pipeline result for an unchanged file. I.e. if the developer stops writing and starts hovering over stuff to figure it out. |
I still don't really see the benefit. In theory this might make dealing with name scoping slightly easier (though I am not even sure that's true, because of the need to return information about defined names back to the outside after processing a term). But on the other hand, doing this refactoring would be a ton of work and would introduce some weird special cases we have to deal with. For example, the parser would become more complex, due to the need to "cap off" definitions with dummy terms while parsing them, and then fix them up by reassociating them later. The typechecker and pretty-printer would need refactoring. And I don't even want to think about the complexity of the changes that would be needed for the evaluation engine; dealing with binds and definitions is already fiddly enough. This might be worth it if it could drastically simplify evaluation but I don't think that is the case. It could also lead to some code duplication since essentially now every I don't understand your point about redefinition. Of course the Also, performance is not really an issue here. Remember that we run the entire parsing-typechecking-requirements checking-elaboration pipeline on every keypress at the REPL! As long as we are not doing anything that is O(n^2) or O(2^n) it should be totally fine. |
Well considering all this it would definitely not be a Low Hanging Fruit. 😄 Thanks for the detailed explanations, they will soon come handy. 👍 |
Reopening this since it's actually a great idea, I just didn't know how to accomplish it back at the beginning of 2023 --- and I think I have actually accomplished it as part of #1928, so hopefully this will be closed again shortly, but this time actually completed. 😄 |
Currently, the types of
let
anddef
differ:The last argument of
let
is code in which the variable can be used, whiledef
:It would be useful to unify
let
/def
parameters to simplify usage analysis and enable editor features like:As is, the code providing those features would have to search the AST for the definition.
Solution
Add
Syntax
parameter toSDef
and initialise it withTConst Noop
.Then do a second pass on the AST and put the scope into
SDef
:Notes
We restrict the definitions to be used only at the top level, so at worst this can happen:
The text was updated successfully, but these errors were encountered: