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

Externalize Eventual Send in Endo Bundles #1625

Open
kriskowal opened this issue Jun 8, 2023 · 10 comments
Open

Externalize Eventual Send in Endo Bundles #1625

kriskowal opened this issue Jun 8, 2023 · 10 comments
Assignees
Labels
design kriskowal-review-2024-01 Issues that kriskowal wants to bring to the attention of the team for review as of January, 2024

Comments

@kriskowal
Copy link
Member

kriskowal commented Jun 8, 2023

Most Endo applications currently need to import @endo/far to get E and Far. The Endo runtime could instead inject these as global variables, but linters, type checkers, and the language server all like these to be imported for various reasons. We can reduce the weight of bundles and also keep these imports, using Compartment Mapper tricks.

  • Ensure that @endo/bundle-source uses the endo tag by default, or create a new endo:far bundle tag to indicate the external dependency on endo:far.
  • Alter the @endo/import-bundle importBundle such that it provides an endo:far builtin module that exports E and Far and ensure that it uses the endo tag.
  • And an entry to @endo/far’s package.json like { "exports": { "endo": "endo:far" } }.
@kriskowal kriskowal self-assigned this Jun 8, 2023
@kriskowal
Copy link
Member Author

cc @mfig for design review

@erights
Copy link
Contributor

erights commented Jun 9, 2023

Why? Generally globals are an anti-pattern.

OTOH, if these were global, could we avoid the Eval Twin problem #1583 , and know that @endo/pass-style (the origin of Far) is instantiated exactly once? Could passStyleOf then safely recognize fars its Far made simply by brand check in its own WeakMap, which would then no longer need to be only an unobservable memo?

@erights
Copy link
Contributor

erights commented Jun 9, 2023

At #1583 I imagined we could solve the Eval Twin problem with compartments without using globals. Is that as easy?

@kriskowal
Copy link
Member Author

Oh, I’ll edit above. The globals are not necessary in this design. Just threading an exit for builtin modules is. Also would degrade gracefully for other environments.

@kriskowal
Copy link
Member Author

As for motivation, this would remove a copy of far from every contract bundle and also reduce instances to one. I do not think this is sufficient to completely eliminate the need to mitigate Eval Twins.

@kriskowal
Copy link
Member Author

And the reason this is not sufficient to eliminate the need to anticipate encountering eval twins is that Endo is not the only environment we need to support. Eventual Send should work on stock node with npm eval twins as well.

@kriskowal
Copy link
Member Author

At #1583 I imagined we could solve the Eval Twin problem with compartments without using globals. Is that as easy?

This solution would certainly be applicable to other cases. The big deal is that these modules would fall thru to making eval twins on other platforms. I think we should still design these modules to anticipate encountering eval twins.

@mhofman
Copy link
Contributor

mhofman commented Jun 26, 2023

I'm not sure how exports play a role. I would expect something more along the lines of:

  • User code imports @endo/pass-style
  • The @endo/pass-style package.json uses a subpath import:
    "imports": {
      "#pass-style-impl": {
        "endo": "endo:pass-style",
        "default": "./pass-style.js"
      }
    },
    
  • The index.js of @endo/pass-style does something like:
    export { passStyleOf } from '#pass-style-impl';
    
  • The bundler automatically considers any endo:* package as an exit module
  • The bundle loader is responsible to provide a virtual module for the endo:pass-style exit module.

@kriskowal
Copy link
Member Author

I’ve created a general issue for surfacing host modules. #1653

@kriskowal kriskowal added kriskowal-review-2024-01 Issues that kriskowal wants to bring to the attention of the team for review as of January, 2024 design labels Jan 8, 2024
@erights erights self-assigned this Mar 4, 2024
@kriskowal
Copy link
Member Author

kriskowal commented Aug 20, 2024

Demonstration #2422

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design kriskowal-review-2024-01 Issues that kriskowal wants to bring to the attention of the team for review as of January, 2024
Projects
None yet
Development

No branches or pull requests

3 participants