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

Layering: Enable cyclic dependencies with non-STMR module types #1311

Merged
merged 7 commits into from
Feb 26, 2019

Conversation

linclark
Copy link
Member

Currently, only Source Text Module Records (STMR) can participate in cycles. From my conversations with those who put that limitation in the spec, this restriction was only added because there wasn't an immediate need for cyclic dependencies with non-STMR modules.

This PR makes it possible for other languages to add module record types that can participate in cycles with Source Text Module Records. To do this, it moves the logic for managing cycles to a new module type, Cyclic Module Record (CMR). STMR are a subclass of the CMR, and other specs such as WebAssembly can also subclass this module record type.

To help with review, I've broken this into smaller commits, but can squash them before merge if that is preferred.

Note: This is an update to #1199. In this version, I removed the concept of "subphases" that was introduced there because they are no longer needed.

<emu-alg>
1. For each ExportEntry Record _e_ in _module_.[[IndirectExportEntries]], do
1. Let _resolution_ be ? _module_.ResolveExport(_e_.[[ExportName]], &laquo; &raquo;).
1. 1. _module_ be this Source Text Module Record.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"1." -> "Let"

@@ -21337,8 +21337,7 @@ <h1>Static Semantics: VarScopedDeclarations</h1>
<emu-clause id="sec-abstract-module-records">
<h1>Abstract Module Records</h1>
<p>A <dfn>Module Record</dfn> encapsulates structural information about the imports and exports of a single module. This information is used to link the imports and exports of sets of connected modules. A Module Record includes four fields that are only used when evaluating a module.</p>
<p>For specification purposes Module Record values are values of the Record specification type and can be thought of as existing in a simple object-oriented hierarchy where Module Record is an abstract class with concrete subclasses. This specification only defines a single Module Record concrete subclass named Source Text Module Record. Other specifications and implementations may define additional Module Record subclasses corresponding to alternative module definition facilities that they defined.</p>
<p>Module Record defines the fields listed in <emu-xref href="#table-36"></emu-xref>. All Module Definition subclasses include at least those fields. Module Record also defines the abstract method list in <emu-xref href="#table-37"></emu-xref>. All Module definition subclasses must provide concrete implementations of these abstract methods.</p>
<p>For specification purposes Module Record values are values of the Record specification type and can be thought of as existing in a simple object-oriented hierarchy where Module Record is an abstract class with both abstract and concrete subclasses. This specification defines the abstract subclass named Cyclic Module Record and its concrete subclass named Source Text Module Record. Other specifications and implementations may define additional Module Record subclasses corresponding to alternative module definition facilities that they defined.</p> <p>Module Record defines the fields listed in <emu-xref href="#table-36"></emu-xref>. All Module Definition subclasses include at least those fields. Module Record also defines the abstract method list in <emu-xref href="#table-37"></emu-xref>. All Module definition subclasses must provide concrete implementations of these abstract methods.</p>
Copy link
Collaborator

Choose a reason for hiding this comment

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

There should be a linebreak after the first </p>.

spec.html Show resolved Hide resolved
<emu-clause id="sec-moduledeclarationinstantiation">
<h1>Instantiate ( ) Concrete Method</h1>
<emu-clause id="sec-moduledeclarationenvironmentsetup" aoid="ModuleDeclarationEnvironmentSetup">
<h1>ModuleDeclarationEnvironmentSetup ( )</h1>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Clause header should end with "Concrete Method".

</emu-clause>

<emu-clause id="sec-moduleexecution" aoid="ModuleExecution">
<h1>ModuleExecution ( )</h1>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Clause header should end with "Concrete Method".


<p>The Instantiate concrete method of a Source Text Module Record implements the corresponding Module Record abstract method.</p>
<p>On success, Instantiate transitions this module's [[Status]] from `"uninstantiated"` to `"instantiated"`. On failure, an exception is thrown and this module's [[Status]] remains `"uninstantiated"`.</p>
<p>The ModuleDeclarationEnvironmentSetup concrete method implements the corresponding Cyclic Module Record abstract method.</p>
Copy link
Collaborator

Choose a reason for hiding this comment

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

After "concrete method", insert "of a Source Text Module Record".


<p>The Evaluate concrete method of a Source Text Module Record implements the corresponding Module Record abstract method.</p>
<p>Evaluate transitions this module's [[Status]] from `"instantiated"` to `"evaluated"`.</p>
<p>The ModuleExecution concrete method implements the corresponding Cyclic Module Record abstract method.</p>
Copy link
Collaborator

Choose a reason for hiding this comment

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

After "concrete method", insert "of a Source Text Module Record".

@littledan
Copy link
Member

This PR LGTM, modulo the nits from @jmdyck. Let's discuss this at the November 2018 TC39 meeting.

spec.html Show resolved Hide resolved
@littledan
Copy link
Member

PR to address the issues noted above: linclark#1

@littledan
Copy link
Member

BTW, as this is a layering change (and not normative), and all concerns raised have been addressed, do we need to discuss it in a TC39 meeting, or can it be merged without that? Asking just to know whether I should prepare a presentation for November.

@rwaldron rwaldron added the has consensus This has committee consensus. label Nov 28, 2018
@@ -21339,7 +21339,7 @@ <h1>Static Semantics: VarScopedDeclarations</h1>
<emu-clause id="sec-abstract-module-records">
<h1>Abstract Module Records</h1>
<p>A <dfn>Module Record</dfn> encapsulates structural information about the imports and exports of a single module. This information is used to link the imports and exports of sets of connected modules. A Module Record includes four fields that are only used when evaluating a module.</p>
<p>For specification purposes Module Record values are values of the Record specification type and can be thought of as existing in a simple object-oriented hierarchy where Module Record is an abstract class with concrete subclasses. This specification only defines a single Module Record concrete subclass named Source Text Module Record. Other specifications and implementations may define additional Module Record subclasses corresponding to alternative module definition facilities that they defined.</p>
<p>For specification purposes Module Record values are values of the Record specification type and can be thought of as existing in a simple object-oriented hierarchy where Module Record is an abstract class with both abstract and concrete subclasses. This specification defines the abstract subclass named Cyclic Module Record and its concrete subclass named Source Text Module Record. Other specifications and implementations may define additional Module Record subclasses corresponding to alternative module definition facilities that they defined.</p>
Copy link
Member

Choose a reason for hiding this comment

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

@bterlson We should correct this existing typo in a follow-up (defined => "define" or "suport").

@ljharb ljharb assigned bterlson and unassigned zenparsing Dec 13, 2018
@ljharb ljharb requested a review from a team December 13, 2018 23:12
@domenic
Copy link
Member

domenic commented Jan 17, 2019

I've noticed a lot of approved-but-not-merged PRs on this repository. This particular one is somewhat blocking to HTML modules work, and we'd love to see it land as soon as possible.

@ljharb
Copy link
Member

ljharb commented Jan 17, 2019

Most of those aren't approved by all the editors yet (specifically, the editor in chief), thus they're not actually mergeable yet. I'll make sure we address this one in the next editor's meeting.

dandclark added a commit to dandclark/webcomponents that referenced this pull request Feb 9, 2019
@ljharb ljharb added the es2019 label Feb 10, 2019
travisleithead pushed a commit to WICG/webcomponents that referenced this pull request Feb 15, 2019
…nt (#793)

* Rebasing ES spec changes on tc39/ecma262#1311.  Misc other fixes/refactorings.

* Update ParseHTMLModule to populate missing fields and update HTML MR InitializeEnvironment to create *default* binding for default export of document

* Add plumbing for ES spec to get the HTML Module's default export (the document) and set it to the *document* binding during module Evaluation.  Plus some other minor corrections.

* Update proposal to state that non-module scripts in HTML Module will cause error (rather than being silently coerced to type='module'

* Minor wording/typo fixes.  Eliminate disclaimer at the top about some parts being handwavy -- we've mostly progressed beyond that, I think.

* Add note that parser behavior needs further specification.  Change 'fetch a single module script' section to reflect that HTML Modules MIME type discussion is still ongoing.
@littledan
Copy link
Member

Another month has passed. What's the process from here?

@zenparsing
Copy link
Member

@bterlson This PR is labelled "es2019" but I don't know if we talked about whether you wanted to bring this one in for the 2019 branch. Thoughts?

@MylesBorins
Copy link
Member

quick ping to see where this is going. It seems like cyclic module records are going to be a very useful abstraction

@bterlson
Copy link
Member

Sorry for the delay, folks. This is good to go! Thanks for sticking with it.

@bterlson bterlson merged commit b012019 into tc39:master Feb 26, 2019
@jmdyck jmdyck mentioned this pull request Feb 27, 2019
@littledan
Copy link
Member

Thanks for landing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has consensus This has committee consensus.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants