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

exitModuleImportHook alongside synchronous exit module linking #1506

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

naugtur
Copy link
Member

@naugtur naugtur commented Mar 3, 2023

Abandoned in favor of #1507

This is a PoC exitModuleImportHook.

It works, but not necessarily the way we want it to work.

Notes:

  • It seems to make sense for the exitModuleImportHook to return a ThirdPartyStaticModuleInterface
  • I am exploring replacing exitModules with the exitModuleImportHook entirely, which removes a lot of complications from linking, changes module attenuation slightly (might be for the better, not sure yet) but it changes how modules from external assemblies or compartments could get included. I don't see a lot of use for that though.
  • I don't yet see a way to properly attenuate on top of exitModuleImportHook - I just discovered that attenuation would only run once per builtin and then it gets cached by the specifier, so attenuation would have to return a unique alias record at least. I'm not sure if that's enough.

@@ -264,6 +285,7 @@ export const parseArchive = async (
archiveLocation,
computeSha512,
computeSourceLocation,
exitModuleImportHook,
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't enjoy passing the hook to the archive making part of the archive flow.
It should not be necessary before runtime.

Solutions:

  1. A boolean configuration value saying to "expectExitModuleImportHook" would be enough to omit the archive-time errors where exit import hook would kick in.
    pros: no unnecessary importing and hook mechanics before runtime
    cons: no early errors if exitModuleImportHook doesn't provide a module, another config item

  2. exitModuleImportHook accepts options, including archiveOnly and if that's truthy, it can avoid importing actual modules while still returning undefined where it originally would (eg. if checking against a list of known builtins it wishes to support)
    pros: no additional option, no need to import actual modules during archiving
    cons: more complexity in exitModuleImportHook

Copy link
Member

Choose a reason for hiding this comment

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

I would rename this parameter to isExitModuleImportAllowed, since the logic for it may be distinct from the logic of exitModuleImportHook, and it only needs to return truthy or falsy (default: () => false). Using myExitModuleImportHook for the parameter is a degenerate case that works, but isn't ideal (it does too much work, as you point out above).

@@ -239,6 +245,7 @@ export {};
* @property {Array<Transform>} [transforms]
* @property {Array<Transform>} [__shimTransforms__]
* @property {Record<string, object>} [modules]
* @property {ExitModuleImportHook} [exitModuleImportHook]
Copy link
Member Author

@naugtur naugtur Mar 3, 2023

Choose a reason for hiding this comment

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

I'm wondering if

* @property {Record<string, object> | ExitModuleImportHook} [modules]

would be frowned upon.

I don't see a reasonable usecase for passing both. If passing a function, wrapping it in an object lookup of sorts is pretty much a necessity anyway.

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer not to mix types in this way in the API (policy description type mixing as you've done in the past is a different matter, for reasons of needing to be concise). I'd rather have just an assertion around !modules || !exitModuleImportHook.

Copy link
Member

Choose a reason for hiding this comment

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

I'm willing to remove the modules option entirely if you mark it as a breaking change, and update any uses within endo that depend on it to use the exitModuleImportHook instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see you're assuming this is more ready than it really is.
I experimented with removing the modules option entirely and it does improve a bunch of things, but also has some interesting consequences. I'll talk about it in the meeting.

@@ -78,6 +78,7 @@ export function scaffold(
tags = undefined,
searchSuffixes = undefined,
commonDependencies = undefined,
additionalOptions = {},
Copy link
Member Author

Choose a reason for hiding this comment

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

Can't extend scaffold with new minor bits of logic forever...

@naugtur naugtur force-pushed the naugtur-exit-import-hook branch 2 times, most recently from 23dd12b to 31ab2f9 Compare March 3, 2023 14:28
@naugtur naugtur force-pushed the naugtur-exit-import-hook branch from 31ab2f9 to 5cd0309 Compare March 3, 2023 14:43
@naugtur naugtur requested review from michaelfig and kumavis March 6, 2023 09:47
@@ -97,6 +100,16 @@ const makeArchiveImportHookMaker = (
// per-module:
const module = modules[moduleSpecifier];
if (module === undefined) {
if (exitModuleImportHook) {
console.error('#################x');
Copy link
Member

Choose a reason for hiding this comment

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

Leftover debug message.

@@ -156,6 +158,21 @@ export const makeImportHookMaker = (
// Archived compartments are not executed.
return freeze({ imports: [], exports: [], execute() {} });
}
if (exitModuleImportHook) {
console.error('#################i');
Copy link
Member

Choose a reason for hiding this comment

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

Here again.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it's still early in the implementation and these are useful for showing when and what happens. I'll need them for the meeting.

@@ -239,6 +245,7 @@ export {};
* @property {Array<Transform>} [transforms]
* @property {Array<Transform>} [__shimTransforms__]
* @property {Record<string, object>} [modules]
* @property {ExitModuleImportHook} [exitModuleImportHook]
Copy link
Member

Choose a reason for hiding this comment

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

I'm willing to remove the modules option entirely if you mark it as a breaking change, and update any uses within endo that depend on it to use the exitModuleImportHook instead.

// note it's not being marked as exit in sources
// it could get marked and the second pass, when the archive is being executed, would have the data
// to enforce which exits can be dynamically imported
return record;
Copy link
Member Author

Choose a reason for hiding this comment

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

Introducing attenuation by policy in here is going to be difficult, because each time a builtin is imported it'd have to get a new instance for different attenuations and here it'll get memoized.

@naugtur naugtur changed the title exitModuleImportHook exitModuleImportHook alongside synchronous exit module linking Mar 29, 2023
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.

2 participants