-
Notifications
You must be signed in to change notification settings - Fork 40
Compilation Pipeline #539
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
Compilation Pipeline #539
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e85e99c
Compilation pipeline
AnsonYeung b062ac0
Move optimization pass inside the pipeline
AnsonYeung 399ba42
Move all optimization configs
AnsonYeung f24b591
Make `passHook`
AnsonYeung 47eeeb9
Add object identity checking for passes
AnsonYeung 61b8ad0
Use List(...)
AnsonYeung a273ec7
Fix FirstClassFunctionTransformer
AnsonYeung 9f8b20e
Fix ClassParamFlattener
AnsonYeung 96f0bd6
Fix TailRecOpt
AnsonYeung e1b44af
Remove CompilationPass case class
AnsonYeung 2c2cfc5
Change the name
AnsonYeung 29c5657
Minor
AnsonYeung 75ab94b
clean up hook calls
AnsonYeung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
hkmc2/shared/src/main/scala/hkmc2/codegen/CompilationPipeline.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package hkmc2 | ||
| package codegen | ||
|
|
||
| import hkmc2.utils.*, shorthands.* | ||
| import utils.* | ||
|
|
||
| import hkmc2.Config | ||
| import hkmc2.semantics.Elaborator.{Ctx, State} | ||
| import hkmc2.semantics.SymbolPrinter | ||
| import hkmc2.utils.TL | ||
|
|
||
| class CompilationPipeline(using Config, Raise, State, Ctx, SymbolPrinter): | ||
|
|
||
| def preOptimizeHook(prog: Program): Program = | ||
| prog | ||
|
|
||
| def run(prog: Program, printer: Program => Str, symbolsToPreserve: Set[BoundSymbol], otl: TL)(using TL): Program = | ||
|
|
||
| var result = prog | ||
|
|
||
| result = LambdaRewriter.desugar(result) | ||
|
|
||
| result = | ||
| val outterTl = tl | ||
| config.deforest match | ||
| case None => result | ||
| case Some(dCfg) => | ||
| flowAnalysis.FlowAnalysis.mkTraceLogger(dCfg.config, "deforest > ", outterTl).givenIn: | ||
| deforest.Deforest(result) | ||
|
|
||
| result = EtaExpansion(result) | ||
|
|
||
| if config.liftDefns.isDefined then | ||
| result = Program(result.imports, Lifter(result.main).transform) | ||
|
|
||
| result = config.effectHandlers.fold(result): opt => | ||
| HandlerLowering(new HandlerPaths, opt).translateProgram(result) | ||
|
|
||
| result = Program(result.imports, result.main.flattened) | ||
|
|
||
| result = BufferableTransform().transform(result) | ||
|
|
||
| // * TODO[Anto]: Can we remove MergeMatchArmTransformer? Seems no longer necessary | ||
|
AnsonYeung marked this conversation as resolved.
Outdated
|
||
| result = Program(result.imports, MergeMatchArmTransformer.applyBlock(result.main)) | ||
|
|
||
| if config.funcToCls then | ||
| result = Program(result.imports, Lifter(FirstClassFunctionTransformer().transform(result.main)).transform) | ||
|
|
||
| result = ClassParamFlattener(result) | ||
|
|
||
| result = ReflectionInstrumenter(using summon).apply(result) | ||
|
|
||
| if config.tailRecOpt then | ||
| result = TailRecOpt().transform(result) | ||
|
|
||
| result = preOptimizeHook(result) | ||
|
|
||
| if !summon[Config].noOpt then | ||
| result = WorkerWrapper(symbolsToPreserve, otl, printer)(result) | ||
| result = BlockSimplifier(symbolsToPreserve, otl, printer)(result) | ||
| result = otl.givenIn(DeadParamElim(result)) | ||
|
|
||
| result | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.