-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Problems related to scopedImport
#8024
Comments
It has existed for almost a decade, so I don't think we're going to remove it, possibly ever. We might disallow it in a new language version, but that's a new feature that we're not pursuing at this time. Is that something you're interested in doing? I can't promise that For a more immediately actionable improvement, perhaps you could contribute to the primop's documentation? |
Yeah I've seen the commit message and the RFC before 🙂. I don't have any time to dedicate towards this right now though, I only opened this issue to write down the results of my investigation and track these problems. |
Confusing free variables
A bit more problematic is the fact that files called with a
scopedImport
have free variables, which can be confusing as to where they're actually defined, compared to a function argument at the top where it's clear that the variables are passed in by a function call.This is in my opinion the main reason we might consider removing it.
Doesn't allow file evaluation to be cached
Here's an example where
scopedImport
can't cache files the same wayimport
can. This is how evaluation is cached withimport
:Note how
calculating b
is only printed once:Trying the same with
scopedImport
:Now
calculating b
is printed twice:But this still makes sense if you think of
scopedImport
as just importing the file as the function body, prepending an attribute argument to it and then calling it, so like this:which will also calculate
b
twice:So I don't think these semantics are problematic, as long as the docs clearly explain them.
Very related is #6228 for caching function application.
Combined with the ability to shadow builtins
However another more fundamental problem is that builtins can be shadowed:
Which when combined with
scopedImport
can make allimport
's not be able to cache evaluation anymore:This will automatically become impossible once we fix the problem of being able to shadow builtins, so it's not a problem with
scopedImport
specifically.The text was updated successfully, but these errors were encountered: