-
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
refactor: rewrite TS dependency analysis in Rust #5029
Conversation
@kitsonk I won't be able to finish this PR tonight 😞 feel free to pick up |
Note to self:
|
9b4ab2f
to
691715a
Compare
I did not change |
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.
LGTM - better to land this - it's clearly an improvement. I'm not super happy with the memory://
stuff, but that can be dealt with later.
FYI, I've got time to do a proper review right now. Hopefully a few minutes. |
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.
A few comments but LGTM, though hard to fully tell, but certainly something that can be iterated on.
One thing that is/was happening that we need to check after this is that sometimes we would have a miss with dynamic imports that TypeScript would get, but ts.preProcessFile()
would miss... like:
const spec = "./foo.ts";
const foo = await import(spec);
I don't know if this catches those or not. If not, we still need an op for TypeScript to pull in something we couldn't statically identify upfront.
@@ -1327,7 +1184,6 @@ async function compile( | |||
rootNames, | |||
options, | |||
host, | |||
oldProgram: TS_SNAPSHOT_PROGRAM, |
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.
👍 as I said above, we should document why we have an unused const above.
spec | ||
} else { | ||
ModuleSpecifier::resolve_url(&format!("memory://{}", specifier))? | ||
}; |
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.
Hrmmmm... yeah, don't like this easier, but yeah... maybe a TODO
so we remember to revisit.
pub fn init(i: &mut CoreIsolate, _s: &State) { | ||
let custom_assets = std::collections::HashMap::new(); | ||
// TODO(ry) use None. | ||
// TODO(bartlomieju): is this op even required? |
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 could not be required... but it means we need to catch these dependencies when using lib
with the runtime compiler APIs.
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.
Not sure I understand, I think if we loaded all available libs during snapshot it could be removed
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.
oh, yeah I forgot we did that...
So in my PR dynamic imports are only parsed in case of |
This is the commit that breaks EVT. |
This commit fixes a bug introduced in #5029 that caused bad handling of redirects during module analysis. Also ensured that duplicate modules are not downloaded.
This PR addresses many problems with module graph loading introduced in #5029, as well as many long standing issues. "ModuleGraphLoader" has been wired to "ModuleLoader" implemented on "State" - that means that dependency analysis and fetching is done before spinning up TS compiler worker. Basic dependency tracking for TS compilation has been implemented. Errors caused by import statements are now annotated with import location. Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
This PR addresses many problems with module graph loading introduced in denoland#5029, as well as many long standing issues. "ModuleGraphLoader" has been wired to "ModuleLoader" implemented on "State" - that means that dependency analysis and fetching is done before spinning up TS compiler worker. Basic dependency tracking for TS compilation has been implemented. Errors caused by import statements are now annotated with import location. Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
This PR completely overhauls how module analysis is performed in TS compiler by moving the logic to Rust.
In the current setup module analysis is performed using
ts.preProcessFile
API in a specialTS compiler
worker running on a separate thread.ts.preProcessFile
allowed us to build a lot of functionality in CLI includingX-TypeScript-Types
header support and@deno-types
directive support. Unfortunately at the same time complexity of the ops required to perform supporting tasks exploded and caused some hidden permission escapes.This PR introduces
ModuleGraphLoader
which can parse source and load recursively all dependent source files; as well as declaration files. All dependencies used in TS compiler and now fetched and collected upfront in Rust before spinning up TS compiler.To achieve feature parity with existing APIs this PR includes a lot of changes:
ModuleGraphLoader
cli/tsc.rs
to perform module analysis upfront and send all required source code to TS worker in one messageop_resolve_modules
andop_fetch_source_files
fromcli/ops/compiler.rs