Skip to content

Conversation

@guybedford
Copy link

This PR moves the graph algorithms of module instantiation and evaluation and their associated fields from Source Text Module record down to Abstract Module Record.

This allows new module record types like Web Assembly or Dynamic Modules to share the same graph algorithms. This enables circular references for WASM<->JS, while avoiding the need to rewrite the entire graph algorithm and module status handling for each module type.

The following fields are moved to Abstract Module Record: [[RequestedModules]], [[Status]], [[EvaluationError]], [[DFSIndex]] and [[DFSAncestorIndex]].

The Instantiate and Evaluate concrete methods of Source Text Module Record are renamed InstantiateAll and EvaluateAll and moved to Abstract Module Record as well.

Individual module records then define the concrete methods Instantiate() and Evaluate() as per-module instantiation and evaluation routines which are called once and provide the individual module type implementations, providing a convenient specification boundary for these new module records.

Initial review by @littledan.

//cc @bmeck @allenwb

Supports specs for other module record types such as Web Assembly
to share the module graph depth-first search algorithm, module
state and error handling thereby enabling cross-module-record linking.
Instantiate and Evaluate on module records are treated as per-module
operations with InstantiateAll and EvaluateAll lowered as the shared
abstract graph operations on Abstract Module Record.
@ljharb ljharb added the normative change Affects behavior required to correctly evaluate some ECMAScript source text label Sep 10, 2018
@ljharb ljharb requested review from a team, allenwb, bmeck and bterlson September 10, 2018 23:04
@linclark
Copy link
Member

I did something pretty similar in #1199 (which I regrettably did not update in a timely fashion, so apologies).

I presented about that change at the May meeting. Instead of pulling this logic into the Abstract Module Record, I had created a separate Cyclic Module Record. This was based on discussions with a few people, including @domenic and Georg, who had worked on the original factoring. The reasoning was that we still want module types that don't allow cycles to be able to participate in these graphs.

Does aligning it with that design—moving the DFS fields and methods to a Cyclic Module Record class that's a subclass of Abstract Module Record—work for you? (Note: There was also some logic in my PR to add a "subphase". That is no longer necessary.)

@guybedford
Copy link
Author

I missed that there was already work being done by the Web Assembly teams towards this. Will close for a more unified approach from that side, also incorporating potential issues with the "Instantiate" naming.

@guybedford guybedford closed this Sep 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

normative change Affects behavior required to correctly evaluate some ECMAScript source text

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants