-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Don't write (using ctx: Context)
#8639
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
Conversation
560afa1
to
d04df74
Compare
On hold until #8654 is completed. |
9dc5480
to
ac14eb2
Compare
New state: unblocked, since #8654 is merged. We are using By now, all files in |
I am going to merge this later today. The footprint of changes makes it very hard to keep up-to-date. So I think it's better to merge this quickly. |
The new way we organize context passing has one downside. We start with `(using Context)` because it is less cluttered, but then if in the body we have to refer to the current context we go back to `(using ctx: Context)`. I havealso seen occurrences of `(using ctx: Context)` without an actual usage of `ctx` in the body. This going back and forth is awkward. Fortnately, there's an alternative: `Contexts` contains a method `curCtx` which summons the current context. We should always use `curCtx` instead of `ctx`, which means we never need to write `(using ctx: Context)`. Or maybe we can even go back renaming `curCtx` to `ctx`? Then we could simply drop all `ctx` names in parameters and hopefully get the same meaning and performance.
Prefer this over defining contexts locally. It's less sensitive to accidental recursions. Rename withContext -> withCompilerContext in compilerSupport
Explicit declarations is `ctx` are risky since after changing all usaages of `(implicit ctx: Context)` to `(using Context)` they risk accidental rebindings. Before the change, `ctx` might have referred to an implicit parameter, but after the change it might refer to an outer binding of `ctx`. Systematically renaming all `ctx` bindings (except the one in `Contexts`) avoids this trap.
DocStrings failed -Ytest-pickler, since a `given _` in an importy clause started with a position that spanned the whole string, and ended after unpickling with a position that just contained the `given`.
Plus other refactorings
ef0e7e0
to
7641518
Compare
The new way we organize context passing has one downside. We start with
(using Context)
because it is less cluttered, but then if in the body we have to refer to the current
context we go back to
(using ctx: Context)
. I have also seen occurrences of(using ctx: Context)
without an actual usage of
ctx
in the body.This going back and forth is awkward. Fortunately, there's an alternative:
Contexts
containsa method
curCtx
which summons the current context. We should always usecurCtx
instead ofctx
, which means we never need to write(using ctx: Context)
.Or maybe we can even go back renaming
curCtx
toctx
? Then we could simply drop allctx
namesin parameters and hopefully get the same meaning and performance.