refactor: Separate compile code into a pipeline #1268
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.
This PR is a refactor that makes no changes to functionality but reorganizes the "compile" procedure into a pipeline of steps.
Below is the implementation of the "compile" procedure in `compileApplicationToWasm.ts" before this PR:
js-compute-runtime/src/compileApplicationToWasm.ts
Lines 159 to 279 in e12ab47
As more functionality was added to this procedure it became harder to reason about, and it became desirable to have a way to separate out the steps into logical units.
The new class
CompilerContextcontains the state of the pipeline and exposes a functionctx.addCompilerPipelineStep(step). Astepis expected to implement the typeCompilerPipelineStepwhich contains an output filename for that step, as well as a function that is passed theCompilerContextand the step number, and is expected to return aPromise<void>.The following steps are separated into files in the
/src/compiler-stepsdirectory for easier maintenance and added to this pipeline.bundle.tsbundleStepprecompileRegexes.tsprecompileRegexesStep*1addStackMappingHelpers.tsaddStackMappingHelpersStepaddFastlyHelpers.tsaddFastlyHelpersStep*1composeSourcemaps.tscomposeSourcemapsStep*1- Add this step only when--enable-stack-tracesis enabledAfter all steps are added,
await ctx.applyCompilerPipeline()is called, which applies the steps in order, awaiting on each step and using the output of each step as the input of the next step.Below is the updated implementation that utilizes the pipeline to perform the "compile" procedure:
js-compute-runtime/src/compileApplicationToWasm.ts
Lines 168 to 187 in b8628ed