Skip to content
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: module loading in EsIsolate #3615

Merged
merged 18 commits into from Jan 8, 2020

Conversation

bartlomieju
Copy link
Member

No description provided.

@bartlomieju
Copy link
Member Author

bartlomieju commented Jan 8, 2020

Summary of changes:

  • refactored RecursiveLoad - it was renamed to RecursiveModuleLoad, it does not take ownership of isolate anymore - it's just a simple struct implementing Stream that yields SourceCodeInfo
  • untangled module loading logic between RecursiveLoad and isolate - that logic is encapsulated in EsIsolate and RecursiveModuleLoad where isolate just consumes modules as they become available - does not require to pass Arc<Mutex<Isolate>> around anymore!
  • removed EsIsolate.mods_ in favor of Modules and moved them inside EsIsolate
  • EsIsolate requires new argument during construction - loader - a struct that implements Loader trait - it's way easier to get a copy of loader when you create isolate than pass it around later during module loading
  • first methods on isolate rewritten as async methods

All in all this PR moves us forward greatly in terms of having Isolate living on a single thread.

CC @ry

@bartlomieju bartlomieju changed the title [WIP] refactor: merge Modules into EsIsolate refactor: module loading in EsIsolate Jan 8, 2020
@ry
Copy link
Member

ry commented Jan 8, 2020

Great work - these are the sort of refactors that really help us move forward

refactored RecursiveLoad - it does not take ownership of isolate anymore

Awesome!

removed EsIsolate.mods_ in favor of Modules and moved them inside EsIsolate

What does this mean?

core/es_isolate.rs Show resolved Hide resolved

mods_: HashMap<ModuleId, ModuleInfo>,
loader: Arc<Box<dyn Loader + Unpin>>,
pub modules: Modules,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see Modules is basically a wrapper around the previous HashMap ?

) -> Result<(), ErrBox> {
let ctx = ResolveContext { resolve_fn };
self.mod_instantiate2(ctx, id);
fn mod_instantiate(&mut self, id: ModuleId) -> Result<(), ErrBox> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not pub ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not pub - use Isolate::load_module 🎉

by_name: ModuleNameMap,
pub(crate) specifier_cache: HashMap<(String, String), ModuleSpecifier>,
}
Copy link
Member

@ry ry Jan 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I glossed over the creation of this struct in your previous PR - but LGTM 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why pub(crate) here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specifier_cache is used to simplify module resolve callback - it is no longer needed to create closures (which were wrong anyway...) and pass pointers to them when you instantiate module. Everything is now encapsulated in Isolate::module_resolve_cb method

// asynchronous module loading.
// This module provides higher level implementation of Isolate that
// supports asynchronous loading and executution of ES Modules.
// The isolate.rs should never depend on this module.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some triple slash comments on EsIsolate would be good for docs.rs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll add in follow-up PR 👍

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bartlomieju bartlomieju merged commit cbdf9c5 into denoland:master Jan 8, 2020
@bartlomieju bartlomieju deleted the es_isolate_modules branch January 8, 2020 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants