-
-
Notifications
You must be signed in to change notification settings - Fork 805
[RFC]: add support for eager evaluation of side-effect free code in the REPL #2073
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
Comments
@kgryte, we need to trigger the Is this the correct high-level idea? |
Or we need method which tell us weather the command is complete or not . cases like
and on the bases of this method we can go forward to process line and show the ghost output |
@MeastroZI as mentioned in the RFC, we should not be evaluating things which might trigger stuff like HTTP requests or any other stuff that can have side effects (ref). Hence, directly trying to execute the input is not the way. |
@Snehil-Shah so we need to check that weather the input is pure have no side effect , then after that we have to go further ? , And what about the context should we have to use the other context ? so it not pollute the global one as a side effect ? |
And have to implement something similar to the constantinople or to use it ? |
I think we would have to consider the global context. In devtools console, when you define a global variable, let's say a string. And in a later statement, you run a "pure" function on that string, it still eagerly evaluates. So, no, the context shouldn't be confined to that very input. I would suggest playing around with the chrome devtools console to get an idea of expected behavior. You might even find patterns that can help you understand the underlying implementation. |
@MeastroZI We would want to avoid additional dependencies. Maybe it can act as a reference literature for our implementation? And yes, we should execute the expression only after we are sure it has no side effects. |
I have researched a bit and play with the devtool and interested to go forward , i have one doubt that how can we find weather the function or method we have called from terminal is side effect free means , i have one way in my mind like this .
@Snehil-Shah and @kgryte can u tell me am i on correct path or not If not then i will greatly appreciate your guide |
@MeastroZI Can you explain better with some examples? Cases like mentioned in the OP and with global variables like:
|
sure
NOTE : in this case we require to maintain the local context as here we define the local variable and changing it
NOTE : in this case we need to context map need to be nested as there can be a variable define in like in this case this same example is impure
|
If i am in very wrong direction ! then please tell me , please don't just ignore me here. 😢 |
@MeastroZI you misunderstood my example
Plus also the examples in the RFC:
|
No i underdtood it and Completly agree with that to , but my question is how we can algorithmically we can define weather the method is side effect free or not ? Please refer this for completely understand my question. https://stackoverflow.com/questions/10662477/is-there-a-way-to-determine-if-a-javascript-function-has-side-effects# |
Specially if function is calling other funcrion and have nested call expression |
@MeastroZI I don't know (haven't dived into this yet), I'll leave that for you to figure out. |
As discussed during office hours today, the plan is to punt AST analysis for side effects to future work. Instead, at least for Before building such a database, the aim should be to implement the logic and UX for displaying result previews. As a test case, the implementation should assume that a single API (e.g., |
PR-URL: #4277 Ref: #2073 Co-authored-by: Athan Reines <[email protected]> Co-authored-by: Snehil Shah <[email protected]> Reviewed-by: Athan Reines <[email protected]> Reviewed-by: Snehil Shah <[email protected]>
@Vinit-Pandit It looks like the eager evaluation logic isn't handling unary expressions. E.g., However, it does handle binary expressions |
Yeah, I just realized this yesterday. I’ll work on it. I also kind of miss the logic for eager evaluation of array and object literals 😅, like this: [1, 3, 3] and { "ss": 6 } |
PR-URL: stdlib-js#4277 Ref: stdlib-js#2073 Co-authored-by: Athan Reines <[email protected]> Co-authored-by: Snehil Shah <[email protected]> Reviewed-by: Athan Reines <[email protected]> Reviewed-by: Snehil Shah <[email protected]>
Regarding the database for eager evaluation, in the current logic, I rely on the function call's code within the REPL. However, this has one drawback: if we store a reference to the function in another variable, eager evaluation does not occur—even if the API is pure. I believe we need some read-only metadata that always remains attached to the function API, something similar to this: This way, whenever a function is called in the REPL, we can check its metadata before execution and ensure eager evaluation happens when applicable . |
I think that's fine. The problem with attaching metadata directly to the function is, it can be hacked pretty easily, knowingly or unknowingly. What if the user defines their own impure function with the metadata set to Plus its kinda weird mutating stdlib functions itself to support a REPL feature.. |
I agree with Snehil. If a user aliases a known alias, it is fine that we wouldn't perform eager evaluation. Plus, this has the added benefit that, if a user does not want to perform eager evaluation (e.g., due to a large |
PR-URL: #5053 Ref: #2073 (comment) Reviewed-by: Athan Reines <[email protected]>
BTW: @Vinit-Pandit and @Snehil-Shah Thanks for your efforts on this. Playing around with it in the REPL is pretty cool and definitely quite handy. I'm looking forward to rolling this out more widely once we get the database up and running. |
PR-URL: stdlib-js#4277 Ref: stdlib-js#2073 Co-authored-by: Athan Reines <[email protected]> Co-authored-by: Snehil Shah <[email protected]> Reviewed-by: Athan Reines <[email protected]> Reviewed-by: Snehil Shah <[email protected]>
PR-URL: stdlib-js#5053 Ref: stdlib-js#2073 (comment) Reviewed-by: Athan Reines <[email protected]>
PR-URL: stdlib-js#4277 Ref: stdlib-js#2073 Co-authored-by: Athan Reines <[email protected]> Co-authored-by: Snehil Shah <[email protected]> Reviewed-by: Athan Reines <[email protected]> Reviewed-by: Snehil Shah <[email protected]>
PR-URL: stdlib-js#5053 Ref: stdlib-js#2073 (comment) Reviewed-by: Athan Reines <[email protected]>
Description
This RFC proposes adding support for eager evaluation of side-effect free code in the REPL. E.g.,
would trigger a preview below the input command, where
<|>
represents the cursor. Upon hitting ENTER, the command would execute with the result displayed after the output prompt, as normal.This feature is now implemented in browser devtools, such as Chrome (see https://developer.chrome.com/blog/new-in-devtools-68/#eagerevaluation).
The tricky bit with implementing this is detecting side effects. And we'd likely want to avoid eagerly evaluating things like HTTP requests. Additionally, we'd like want to exclude things which are not idempotent (e.g., PRNGs,
Date
constructor, etc).There is also the concern as to how to handle eager evaluation of computationally expensive commands or commands returning large outputs.
As this feature may not be desired by all users, we should presumably support an option for enabling/disabling this on REPL instantiation. And we should disable eager evaluation when not in TTY mode.
Related Issues
Questions
No.
Other
Resources:
Checklist
RFC:
.The text was updated successfully, but these errors were encountered: