-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
[WIP] Refactor the compiler #6894
Conversation
Can you |
If I did that right now, it would break CLI, so I have simply hacked around it for now. |
ead32a6
to
97252ec
Compare
905f218
to
c03b273
Compare
ea84031
to
3fd14f0
Compare
It is getting closer and closer. Still to do:
Also, this will provide even more fixes: |
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.
@kitsonk here are some of my initial questions, I need to go over this PR a few more times as it's very compilated. Also what's your plan regarding integration with CLI?
compiler/Cargo.toml
Outdated
serde = { version = "1.0.115", features = ["derive"] } | ||
sourcemap = "6.0.1" | ||
swc_common = { version = "=0.9.1", features = ["sourcemap"] } | ||
swc_ecma_transforms = { version = "=0.19.7", features = ["react"] } |
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.
That's already part of swc_ecmascript
given "transforms"
feature
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.
It wasn't... It was panic'ing. I will try again.
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.
Yeah, validated it again, if I remove that, I get:
error[E0432]: unresolved import `swc_ecmascript::transforms::react`
--> compiler/ast.rs:40:5
|
40 | use swc_ecmascript::transforms::react;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `react` in `transforms`
So it appears to not be included in swc_ecmascript
and you have to include the other crate to have it be available.
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.
CC @kdy1 is there a better way to this?
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.
Sorry, I forgot adding cargo features to swc_ecmascript. I'm too good at forgotting thngs :(
I'll publish a patch soon.
compiler/bundler.rs
Outdated
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. | ||
|
||
use crate::source_map_bundler::SourceMapBundler; | ||
use crate::Result; | ||
|
||
use deno_core::ErrBox; | ||
use std::error::Error; | ||
use std::fmt; | ||
use std::path::PathBuf; | ||
|
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.
Sooo... swc_bundler
is now available and I wanted to try and incorporate it into our workflow, but I guess we'll start with your version first and then try to switch to it. WDYT?
use crate::msg::MediaType; | ||
use crate::Result; | ||
|
||
use deno_core::ErrBox; |
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.
Note to self, most of the contents of this file are used in cli/
(mainly for compiler purposes but also for deno doc
) as well as in deno_lint
. It should be made into a utility crate that is shared between the other crates.
compiler/module_graph.rs
Outdated
use crate::ast::parse; | ||
use crate::ast::Location; | ||
use crate::ast::ParsedModule; | ||
use crate::compiler::CompileOptions; | ||
use crate::compiler::CompilerEmit; | ||
use crate::compiler::CompilerIsolate; | ||
use crate::compiler::TranspileOptions; | ||
use crate::import_map::ImportMap; | ||
use crate::msg::EmittedFile; |
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.
Note to self: ModuleGraph
/Graph
should be used for deno info
, investigate if this struct could be made into two separate structs - one for loading and parsing of dependencies (think collecting module tree), second for integration with TS compiler cache (think utilizing the graph that collects module tree to process the tree further). See #6786 for reference
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.
While it sort of overloads it a bit, I sort of like them together... In that Graph
contains all the information that ops need to access files, you just wire it into that... I like having all the "what you can do with a graph" on the surface API of the graph...
For GraphBuilder
there is only:
- insert - Add a specifier as a "root".
- get_graph - Move the graph out.
For Graph
it currently is:
Updating a graph:
- compile (update the graph with type checked code)
- transpile (update the graph with type stripped code)
Things I need to refactor out/make non-public:
- update (take emitted files and update the graph... I need to refactor this out, as compile and transpile should automatically do this, making the compiler less dependent)
- flush (flush any "dirty" modules to the cache, again this should be refactored out as it need to be handled by compiler and transpile)
- get_root_names (this was used by compiler.compile but needs to be passed)
- get_sources (this was used by transpile but need to be passed)
Then needed for compiler ops:
- pub modules (the Hashmap of modules)
- resolve (takes a string specifier and a base module specifier and returns the module specifier in the graph, abstracting out all the logic for
@deno-types
andX-TypeScript-Types
and triple-slash reference) - get_build_info/set_build_info
But talking that through here sounds like I should refactor that last group as a trait (and abstract out the public access to the hashmap of module).
Adding in info()
to the Graph
makes a lot of sense, and/or have the Display of a Graph be the output we need for info.
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.
Ok, I have done a refactor... I still want to do some fine tuning of it, but basically the compiler and the graph are better decoupled, and the compiler ops only depend upon to methods in a trait. It means in practice, the only thing that needs to be interfaced with is the GraphBuilder
and the Graph
.
|
||
use crate::Result; | ||
|
||
use deno_core::ModuleSpecifier; | ||
use indexmap::IndexMap; |
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.
ImportMap
implementation hasn't really changed since it was introduced last year in May, maybe it would make more sense to make it a separate crate as well? It would still depend on deno_core
for the sake of ModuleSpecifier
, but could limit complexity by having a clear boundary between the crates. @kitsonk @ry what do you think?
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.
I think it will "move" here, it shouldn't be needed by the CLI anywhere else. Though of course compiler
is sort of becoming a bad name for this crate... but basically it is the all the higher order logic of dependency/handling/transforming/type checking of ES Modules under Deno, abstracted away from the fetching/caching/persistence/runtime execution considerations.
At the moment I can't see any handling of redirects, I think we can punt on this issue for a bit longer. We need to take holistic approach and coordinate redirect handling in Lines 40 to 44 in 684eddc
|
d75cb1d
to
3f04a42
Compare
In chatting with @ry and @bartlomieju we agreed that we need to break this up into seperate things and for right now, moving this logic out to a seperate crate doesn't make sense... I will use this branch though as a reference implementation for myself (and for @bartlomieju) to land some/all of these changes over a period of time. |
This is a major refactor of the TypeScript compilation infrastructure. Raising for early visibility, but it is still very much a work in progress. It totally rewrites how the compilations are handled to abstract out the logic, which should make it easier to move parts and pieces in the future, at the same time leveraging more Rust infrastructure and signficantly "dumbing" down the interface to the TypeScript compiler.
Currently it is a seperate crate as that has been easier for me to work on it without having to deal with merge conflicts and other changes.
Currently I have the following working:
deno.ns
).Things that I need to do:
When finished this will:
Fixes #5606
Fixes #5607
Fixes #6686