-
Notifications
You must be signed in to change notification settings - Fork 40
Refactor TransformerOps into a helper to operate on state in Context #1214
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
base: master
Are you sure you want to change the base?
Conversation
|
Disclaimer: I won't have a lot of time to review the next week, but here is a remark about how to go about it: A lot of phases, other than the frontend, use phase-specific contexts that are defined in the same file and passed around via implicits. Maybe one way of getting rid of the cake pattern is to do this for one file in the frontend-phase after another. Before we do this, we need to figure out
Maybe you could start by looking at the other phases and summarize how we to it there? This would help to identify a single pattern that we can then apply. What do you think? |
|
Thanks for the feedback.
I already refactored
I also took a look at
The changes i suggest for now would only focus on the main When you, and your team, have more time on you hands, i would suggest tightly controlling the context each stage requires and produces: Details
Right now the Phases are defined like this: enum PhaseResult {
/**
* The result of [[Namer]] resolving all names in a given syntax tree. The resolved symbols are
* annotated in the [[Context]] using [[effekt.context.Annotations]].
*/
case NameResolved(source: Source, tree: ModuleDecl, mod: symbols.Module)
// etc
}Why not just move all the DB's into the phase result?, so like this: case NameResolved(source: Source, tree: ModuleDecl, mod: symbols.Module, scopeDB: ScopeDP, errorDB: ErrorDB, etc..)And then just create a new class to operate on these DB's as the phase-specific context and then just pass the new context out as part of the phase result... This would clearly show and control what each phase needs and produces. This change would exactly start of where my suggested changes end. Maybe i dont see the greater picture here or just dont get something else entirely. |
|
Maybe I didn't make myself clear. When I said
I meant something like
or
We have at many different compiler passes and many of them need to maintain contextual information. I purposefully said "other than the frontend", since the frontend (lexer, parser, namer, typer, etc.) is the only part where we use the cake pattern context. So gathering how
could be helpful since it would inform us in our decisions. |
|
I am sorry that I missed your point I will take a look tomorrow. |
I think it makes sense to collect this in a GitHub discussion. |
|
Regarding this PR: I think we need some target design that describes where we want to end up with this, otherwise it's hard to judge if the changes in this PR move us towards this target. I think looking at the patterns in the compiler backend and drafting a new design for separate disentangled contexts for the frontend would be a good starting point. |
|
If I would dream up a design, I would suggest separate contexts for all phases, e.g. My current intuition would be to start by splitting up
Big disclaimer: This is not meant as a concrete plan for you to follow (perhaps it doesn't even make sense); it is just to give you an idea on what my current mental model looks like. I would advocate for doing the following:
|
I want to remove the Cake Pattern from the Context class, starting with
TransformerOpsIn this PR i only did 3 simple things:
bindingslist into a separateBindingDBclass.(1 new file, 1 line modified)
TransformerOpsinto a helper that operates on theBindingDB.(~8 lines modified)
Context.F(..)withTransformerOps.F(...)(~27 single words modified)
This paves the way to refactor all the remaining 10 traits and to improve handling of state later on, which should improve the onboarding process of new contributors.
I have many arguments on why this refactoring should be done, but just consider this:
There are 245 methods accessible through the
Contextclass and 18 of them are just calledbindwith different signatures