Skip to content

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

Merged
merged 28 commits into from
Apr 4, 2020
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 31, 2020

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 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.

@odersky odersky force-pushed the change-ctx branch 5 times, most recently from 560afa1 to d04df74 Compare April 2, 2020 17:21
@odersky
Copy link
Contributor Author

odersky commented Apr 2, 2020

On hold until #8654 is completed.

@odersky odersky force-pushed the change-ctx branch 2 times, most recently from 9dc5480 to ac14eb2 Compare April 3, 2020 14:57
@odersky
Copy link
Contributor Author

odersky commented Apr 3, 2020

New state: unblocked, since #8654 is merged. We are using ctx as the global "current" context identifier now. This means that ctx should be bound as a name elsewhere only if it means "current context" in all of its scope. That is, no nested (using Context) clauses that could bind to something else are allowed.

By now, all files in typer are refactored to use the new scheme.

@odersky
Copy link
Contributor Author

odersky commented Apr 4, 2020

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.

odersky added 20 commits April 4, 2020 11:14
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`.
@odersky odersky force-pushed the change-ctx branch 3 times, most recently from ef0e7e0 to 7641518 Compare April 4, 2020 16:10
@odersky odersky merged commit 3d26c53 into scala:master Apr 4, 2020
@odersky odersky deleted the change-ctx branch April 4, 2020 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant