-
Notifications
You must be signed in to change notification settings - Fork 395
Add a desugaring step in the base linker. #5096
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Desgar happens before optimizer 👍
scala-js/linker/shared/src/main/scala/org/scalajs/linker/frontend/LinkerFrontendImpl.scala
Lines 67 to 74 in 98e0875
val linkResult = logger.timeFuture("Linker") { | |
linker.link(irFiles, moduleInitializers, logger, | |
preOptimizerRequirements) | |
} | |
val optimizedResult = optOptimizer.fold(linkResult) { optimizer => | |
linkResult.flatMap(optimize(_, symbolRequirements, optimizer, logger)) | |
} |
LGTM from my side
I think formalizing desugaring as a phase / step makes sense. Essentially, IIUC, it would host transformations / lowerings that are necessary for later phases to work properly, so unlike the optimizer, they are required for correctness. What I'm wondering is if it makes sense to include these in the
It feels that both of these would be acceptable to do. What we would get from this:
As a natural follow-up (to my eyes at least), I wonder if it makes sense / is feasible to move method / class synthesis to such a phase as well. From what I can see, the main challenge is probably how encode this in |
IIUC, what you're proposing is:
That makes sense. Forwarding the In order for
I'm not so sure about that. The existing method synthesis is deeply linked to the reachability analysis. Arguably, it's what makes the job of the base linker actually a linker (and not just a dead code elimination pass, like the Writing the above actually makes me wonder: perhaps |
Yes.
For versions. But we ended up re-using the method's version field: #4772
my thoughts:
Does it? IIUC, the mapping from descriptor to class name is deterministic: scala-js/linker/shared/src/main/scala/org/scalajs/linker/frontend/SyntheticClassKind.scala Line 39 in aa39914
Ah, sorry, I wasn't clear. Determining what needs to be synthesized for sure must be part of the linker. However, actually synthesizing these things (what the method synthesizer does ATM) could (IIUC) happen later. I have looked into this a bit more specifically and it would change MethodSynthesizer quite a bit. But my hunch is this might be for the better: right now, MethodSynthesizer looks up targets via IR loader. This could (but should not) trigger an actual IR load. It is not entirely clear to me how we would forward synthetization information from the base linker. Something-something transient probably?
I think that depends on how we define correctness.
|
I did a PoC of the separate phase in #5101. That was while sick and on the train, so there's probably a lot to improve there. Being able to IR check before and after desugaring is definitely a nice perk of that approach. Also currently the desugaring itself (without the additional IR check pass) took less than 20 ms on my slow laptop, so it's basically free. That may change if we process |
Previously, the emitters and the optimizer all had to perform the same desugaring for `LinkTimeProperty` nodes. Instead, we now perform the desugaring in the `BaseLinker`, after the reachability analysis. The reachability analysis records whether each method needs desugaring or not. Methods that do not require desugaring are not processed, and so incur no additional cost. Since very few methods need desugaring, we do not cache the results. The machinery is heavy. It definitely outweighs the benefits in terms of duplication for `LinkTimeProperty` alone. However, the same machinery will be used to desugar `NewLambda` nodes. This commit serves as a stepping stone in that direction.
Superseded by #5101. |
Previously, the emitters and the optimizer all had to perform the same desugaring for
LinkTimeProperty
nodes. Instead, we now perform the desugaring in theBaseLinker
, after the reachability analysis.The reachability analysis records whether each method needs desugaring or not. For those that do, we cache the resulting desugaring. Methods that do not require desugaring are not processed, and so incur no additional cost.
The machinery is heavy. It definitely outweighs the benefits in terms of duplication for
LinkTimeProperty
alone. However, the same machinery will be used to desugarNewLambda
nodes. This commit serves as a stepping stone in that direction.This PR is meant as a stepping stone towards #5003, so that it is easier to review piecemeal. However, it makes no sense to actually merge this PR before we have consensus that this way of desugaring at
BaseLinker
time is the correct way to deal withNewLambda
in #5003.