-
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
Add --prefetch flag for deps prefetch without running #1475
Conversation
if (is_prefetch) { | ||
return true; | ||
} | ||
|
||
auto result = module->Evaluate(context); |
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.
The only modified part of this PR: module->Evaluate
is not run and short circuited by is_prefetch
Great - very glad you took this on! I will review after #1460 has landed |
@ry Found a mysterious issue that I am not quite sure about during debugging:
The 3 lines marked are completely unexpected (since they download the files but not compiling them, and is duplicate with later downloads). Line 405 in bc2c808
which surprised me since this is a TypeScript compiler builtin. Notice that resolveModule is the only part where we have the codeFetch logic injected and is used in resolveModuleNames
When I renamed I would assume that we unexpectedly overwrote a TypeScript API? It seems that cc @kitsonk since I don't really know things about the Language Service API... (It feels like both TypeScript compiler and v8 ES modules are trying to gather all the dependencies, or at least recursively evaluating and resolving files for the import statements... ideally only one of them should happen |
@kevinkassimo I would run the whole thing with the debug flag to validate that this is actually what is happening. |
@kevinkassimo could you please rebase? |
395b73e
to
141b02f
Compare
@ry Rebased. @kitsonk I'm pretty sure it is the problem. Also days ago TimothyGu (former Node TSC who also worked on WHATWG standards) mentioned that browsers resolve modules when doing parsing and before actual module instantiation (before |
libdeno/binding.cc
Outdated
@@ -530,7 +530,7 @@ void DenoIsolate::ResolveOk(const char* filename, const char* source) { | |||
} | |||
|
|||
bool ExecuteMod(v8::Local<v8::Context> context, const char* js_filename, | |||
const char* js_source) { | |||
const char* js_source, int is_prefetch) { |
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.
Maybe the name of this argument should be changed at this level level of abstraction, because in libdeno we don't know about "prefetching" ...
What do you think about "resolve_only" or "without_execute"... something like that?
Also you may use a bool
here as this is C++.
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.
Adopting resolve_only
(execute_mod
that without_execute
sounds weird...)
libdeno/deno.h
Outdated
@@ -76,7 +76,7 @@ int deno_execute(Deno* d, void* user_data, const char* js_filename, | |||
// Return value: 0 = fail, 1 = success | |||
// Get error text with deno_last_exception(). | |||
int deno_execute_mod(Deno* d, void* user_data, const char* js_filename, | |||
const char* js_source); | |||
const char* js_source, int is_prefetch); |
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.
Same comment as above regarding the name of this argument
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 am making them all bools now instead (C++, extern C and Rust)
libdeno/libdeno_test.cc
Outdated
@@ -294,7 +294,7 @@ TEST(LibDenoTest, ModuleResolutionFail) { | |||
// Do not call deno_resolve_ok(); | |||
}; | |||
Deno* d = deno_new(deno_config{0, empty, empty, nullptr, resolve_cb}); | |||
EXPECT_FALSE(deno_execute_mod(d, d, "a.js", mod_a)); | |||
EXPECT_FALSE(deno_execute_mod(d, d, "a.js", mod_a, 0)); |
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 would be nice to have a libdeno test exercising the is_prefetch
option (or whatever you end up naming it)
Suggest something like this (please change naming)
TEST(LibDenoTest, ModuleResolutionPrefetch) {
static int count = 0;
auto resolve_cb = [](void* user_data, const char* specifier,
const char* referrer) {
EXPECT_STREQ(specifier, "b.js");
EXPECT_STREQ(referrer, "a.js");
count++;
auto d = reinterpret_cast<Deno*>(user_data);
deno_resolve_ok(d, "b.js", mod_b);
};
Deno* d = deno_new(deno_config{0, empty, empty, nullptr, resolve_cb});
EXPECT_TRUE(deno_execute_mod(d, d, "a.js",
"import { retb } from 'b.js'\n"
"throw Error('unreachable');" , 1));
EXPECT_EQ(count, 1);
deno_delete(d);
}
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.
Nice! I'm happy to see how simply done this was.
The one problem that I have is that it doesn't have a test for the actual behavior - it seems it would need some custom bits of python.
@kevinkassimo I think it is a problem too and yes, browser do a two pass instantiation, it was something that we dealt with in the runner... In chatting with Ryan I am going to take a look at the whole thing and see if we can get things to behave a bit cleaner. |
@ry Hmm the diff test currently at least proves that the files are downloaded (due to logs). Probably we should double check by walking into the |
@kitsonk Cool... Also, since we are having 2 independent dependency graphs without any communications at this moment, we might need to add on Rust/C++ side another function/map that resolves referrer and specifier to filenames (and possibly some metadata) and store the mappings, to make recompile/reload function correctly again... |
libdeno/deno.h
Outdated
@@ -76,7 +76,7 @@ int deno_execute(Deno* d, void* user_data, const char* js_filename, | |||
// Return value: 0 = fail, 1 = success | |||
// Get error text with deno_last_exception(). | |||
int deno_execute_mod(Deno* d, void* user_data, const char* js_filename, | |||
const char* js_source); | |||
const char* js_source, bool resolve_only); |
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.
Don't use bool
here. deno.h
is supposed to be ANSI C to support linking to Rust. Even if this isn't a problem currently, it is in Go, and we might be conservative.
Add a line of documentation regarding this parameter, please.
@kevinkassimo I've added |
@ry The test looks good (although I'm investigating why it fails on Appveyor...) (I actually just noticed that I used to have an integration test for |
c68f2ce
to
d4ce9c8
Compare
tests/prefetch.ts.out
Outdated
Downloading http://localhost:4545/tests/subdir/subdir3/mod1.ts... | ||
Downloading http://localhost:4545/tests/subdir/subdir3/mod2.ts... | ||
Downloading http://localhost:4545/tests/subdir/subdir3/mod3.ts... | ||
Downloading http://localhost:4545/tests/subdir/subdir3/mod1.ts... |
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.
Hrm. I guess this is #1496
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.
They should have the same underlying problem...
3a4eeb1
to
1516135
Compare
FYI we are looking into the windows failures here. |
@ry Great... (annoying since I have no way of reproducing it on a non-Windows machine...) |
b8e87d9
to
f4e5759
Compare
f4e5759
to
49c4759
Compare
@ry, @kevinkassimo I added a commit that fixes windows. |
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 - thanks @kevinkassimo and @piscisaureus
Aiming to close #1386. This is built on top of #1460
The only difference from running is that the modules are compiled but NOT evaluated