Bug 147353 - [ES6] Add ES6 Modules preparsing phase to collect the dependencies
Summary: [ES6] Add ES6 Modules preparsing phase to collect the dependencies
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords:
Depends on: 147422
Blocks: 147340
  Show dependency treegraph
 
Reported: 2015-07-27 22:20 PDT by Yusuke Suzuki
Modified: 2019-05-02 16:18 PDT (History)
7 users (show)

See Also:


Attachments
Patch (42.12 KB, patch)
2015-07-29 13:08 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (68.60 KB, patch)
2015-08-10 18:06 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (73.90 KB, patch)
2015-08-10 20:55 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (73.93 KB, patch)
2015-08-10 21:06 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (70.90 KB, patch)
2015-08-13 12:59 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (71.04 KB, patch)
2015-08-13 13:53 PDT, Yusuke Suzuki
saam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2015-07-27 22:20:41 PDT
Before executing the body of the modules, we need to collect the dependencies. (import / export)
This issue involves modules parsing change.
Comment 1 Yusuke Suzuki 2015-07-28 12:08:52 PDT
My plan is,

1. adding some option to JSC shell (maybe, leveraging the existing --xxx=yyy system is preferable)
2. with this option, parse the module syntax
3. just parsing it currently and ensure the parsing correctness by the test
Comment 2 Yusuke Suzuki 2015-07-28 12:10:22 PDT
After collecting the information from the module,

1. introducing the sort of loader into JSC shell (jsc.cpp), it's synchronous loader
2. test modules semantics under it

And after that, we'll implement asynchronous loader in the WebCore side.
Comment 3 Yusuke Suzuki 2015-07-29 13:08:04 PDT
Created attachment 257764 [details]
Patch

WIP, parsing module related syntax
Comment 4 Yusuke Suzuki 2015-07-29 14:56:47 PDT
Before landing the preparing system (I'm planning to create the new builder that inherits SyntaxChecker), just creating the patch to add parsing functionality.
Comment 5 Yusuke Suzuki 2015-08-10 18:06:52 PDT
Created attachment 258679 [details]
Patch

WIP
Comment 6 Yusuke Suzuki 2015-08-10 20:55:45 PDT
Created attachment 258696 [details]
Patch
Comment 7 Yusuke Suzuki 2015-08-10 20:58:57 PDT
Comment on attachment 258696 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=258696&action=review

The patch is ready.

> Source/JavaScriptCore/runtime/Completion.cpp:78
> +    return true;

Since this patch just implements analyzing part, we don't have tests for this patch.
Comment 8 WebKit Commit Bot 2015-08-10 20:59:28 PDT
Attachment 258696 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp:27:  You should add a blank line after implementation file's own header.  [build/include_order] [4]
ERROR: Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp:29:  Alphabetical sorting problem.  [build/include_order] [4]
ERROR: Source/JavaScriptCore/parser/Parser.h:839:  Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.  [readability/comparison_to_zero] [5]
ERROR: Source/JavaScriptCore/parser/ModuleRecord.h:122:  This { should be at the end of the previous line  [whitespace/braces] [4]
Total errors found: 4 in 23 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Yusuke Suzuki 2015-08-10 21:06:42 PDT
Created attachment 258697 [details]
Patch
Comment 10 WebKit Commit Bot 2015-08-10 21:08:31 PDT
Attachment 258697 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp:27:  You should add a blank line after implementation file's own header.  [build/include_order] [4]
ERROR: Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp:29:  Alphabetical sorting problem.  [build/include_order] [4]
ERROR: Source/JavaScriptCore/parser/Parser.h:839:  Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.  [readability/comparison_to_zero] [5]
ERROR: Source/JavaScriptCore/parser/ModuleRecord.h:122:  This { should be at the end of the previous line  [whitespace/braces] [4]
Total errors found: 4 in 23 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 11 Yusuke Suzuki 2015-08-11 12:27:33 PDT
Comment on attachment 258697 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=258697&action=review

Added comments for the ease of reviewing.

> Source/JavaScriptCore/parser/ModuleAnalyzer.cpp:142
> +    //     export * from "mod"

These information is required for

1. requesting dependent modules.
2. constructing the module environment before executing the module body.

For (2), we collect the exported/imported binding informations; Exported variable should be allocated in the module's environment (as a heap variable). And imported bindings should be handled in the module's environment.
Comment 12 Geoffrey Garen 2015-08-12 13:18:13 PDT
Comment on attachment 258697 [details]
Patch

r=me
Comment 13 Yusuke Suzuki 2015-08-12 13:35:24 PDT
(In reply to comment #12)
> Comment on attachment 258697 [details]
> Patch
> 
> r=me

Thank you. In the meantime, I'll land this patch.
But, Saam is also reviewing this, so please feel free to comment it, I'll reflect your comments at any time :)
Comment 14 Yusuke Suzuki 2015-08-12 13:39:05 PDT
Committed r188355: <http://trac.webkit.org/changeset/188355>
Comment 15 Saam Barati 2015-08-13 01:23:43 PDT
Comment on attachment 258697 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=258697&action=review

Nice work. Some comments below.

> Source/JavaScriptCore/builtins/BuiltinNames.h:34
> +#define INITIALISE_BUILTIN_NAMES(name) , m_##name(Identifier::fromString(vm, #name)), m_##name##PrivateName(Identifier::fromUid(PrivateName(PrivateName::Description, ASCIILiteral("PrivateSymbol." #name))))

What is this doing?
Should this be in this patch?

> Source/JavaScriptCore/parser/ModuleAnalyzer.cpp:38
> +    , m_declaredVariables(declaredVariables)

I like the use of VariableEnvironment here. I'm glad this is being used as the way to speak about variables in the parser.

> Source/JavaScriptCore/parser/ModuleAnalyzer.cpp:100
> +Ref<ModuleRecord> ModuleAnalyzer::analyze(ModuleProgramNode& moduleProgramNode)

The comments in this function are really helpful.

> Source/JavaScriptCore/parser/ModuleAnalyzer.cpp:103
> +    // 1. Import entries

super Nit: This isn't an ordered list, these could just be bullet points using "-" or "*" instead of "1/2/3/4"

> Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp:43
> +    for (StatementNode* statement = m_head; statement; statement = statement->next())

I know we ensure the Analyze phase only collects ModuleDeclarationNodes, but it would be nice to have an assert verifying this.
We could have StatementNode have a virtual function "isModuleDeclarationNode" and assert against that.

> Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp:51
> +        analyzer.moduleRecord().addImportEntry({

I think having the name of the struct before "{" is useful here.

> Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp:80
> +        if (m_moduleSpecifier) {

Nit: I know in an earlier patch I said it's good to use the names the spec uses, but I think I was maybe wrong.
I'm not in love with the name m_moduleSpecifier. That name doesn't really mean anything to me.
Maybe we can give this a better name, like m_moduleFileName (even though it's not just files) or m_moduleName or something similar.

> Source/JavaScriptCore/parser/Parser.cpp:238
> +String Parser<LexerType>::parseInner(const Identifier& calleeName, FunctionParseMode parseMode, ModuleParseMode moduleParseMode)

Can we just join FunctionParseMode and ModuleParseMode into one thing and give it a different name? Maybe SourceParseMode or another name?
Or even better, we can also unify this with JSParserCodeType. Or get rid of JSParserCodeType if needed.
Maybe we should open a separate bug to unify all of these into one type in another patch.

> Source/JavaScriptCore/parser/Parser.cpp:2475
> +            // const *default* = expr;

*default* is not visible to the actual JS code, right?
I think we should make that explicit in this comment.

> Source/JavaScriptCore/parser/Parser.cpp:2484
> +                internalFailWithMessage(false, "Cannot export 'default' name twice: '");

nit: should be: "Only one 'default' export is allowed"

> Source/JavaScriptCore/parser/Parser.cpp:2494
> +        semanticFailIfFalse(exportName(m_vm->propertyNames->defaultKeyword), "Cannot export 'default' name twice.");

ditto.
Comment 16 Yusuke Suzuki 2015-08-13 11:13:31 PDT
Comment on attachment 258697 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=258697&action=review

Thank you for your review, Saam. Your comments are so helpful.
I'll upload the follow-up patch to this issue. You can review it :)

>> Source/JavaScriptCore/builtins/BuiltinNames.h:34
>> +#define INITIALISE_BUILTIN_NAMES(name) , m_##name(Identifier::fromString(vm, #name)), m_##name##PrivateName(Identifier::fromUid(PrivateName(PrivateName::Description, ASCIILiteral("PrivateSymbol." #name))))
> 
> What is this doing?
> Should this be in this patch?

It adds the [[Description]] string into the private symbol to make the debug functionality of the ModuleRecord (dumping the Symbol names in ModuleRecord::dump) useful.

>> Source/JavaScriptCore/parser/ModuleAnalyzer.cpp:103
>> +    // 1. Import entries
> 
> super Nit: This isn't an ordered list, these could just be bullet points using "-" or "*" instead of "1/2/3/4"

Thanks. I'll fix it :)

>> Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp:43
>> +    for (StatementNode* statement = m_head; statement; statement = statement->next())
> 
> I know we ensure the Analyze phase only collects ModuleDeclarationNodes, but it would be nice to have an assert verifying this.
> We could have StatementNode have a virtual function "isModuleDeclarationNode" and assert against that.

Sounds nice! I'll fix it.

>> Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp:51
>> +        analyzer.moduleRecord().addImportEntry({
> 
> I think having the name of the struct before "{" is useful here.

Reasonable. I'll add the type name, ImportEntry.

>> Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp:80
>> +        if (m_moduleSpecifier) {
> 
> Nit: I know in an earlier patch I said it's good to use the names the spec uses, but I think I was maybe wrong.
> I'm not in love with the name m_moduleSpecifier. That name doesn't really mean anything to me.
> Maybe we can give this a better name, like m_moduleFileName (even though it's not just files) or m_moduleName or something similar.

Make sense.
m_moduleName looks nice because the module's name will be resolved by the loader and it might not be the file name.
I'll rename them.

>> Source/JavaScriptCore/parser/Parser.cpp:2475
>> +            // const *default* = expr;
> 
> *default* is not visible to the actual JS code, right?
> I think we should make that explicit in this comment.

Yes. I'll add the comment.

>> Source/JavaScriptCore/parser/Parser.cpp:2484
>> +                internalFailWithMessage(false, "Cannot export 'default' name twice: '");
> 
> nit: should be: "Only one 'default' export is allowed"

Looks nice to me. I'll fix it.

>> Source/JavaScriptCore/parser/Parser.cpp:2494
>> +        semanticFailIfFalse(exportName(m_vm->propertyNames->defaultKeyword), "Cannot export 'default' name twice.");
> 
> ditto.

Fixed.
Comment 17 Yusuke Suzuki 2015-08-13 11:18:44 PDT
Comment on attachment 258697 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=258697&action=review

>> Source/JavaScriptCore/parser/Parser.cpp:238
>> +String Parser<LexerType>::parseInner(const Identifier& calleeName, FunctionParseMode parseMode, ModuleParseMode moduleParseMode)
> 
> Can we just join FunctionParseMode and ModuleParseMode into one thing and give it a different name? Maybe SourceParseMode or another name?
> Or even better, we can also unify this with JSParserCodeType. Or get rid of JSParserCodeType if needed.
> Maybe we should open a separate bug to unify all of these into one type in another patch.

I'll try it. Maybe, we can.
Comment 18 Yusuke Suzuki 2015-08-13 12:59:39 PDT
Reopening to attach new patch.
Comment 19 Yusuke Suzuki 2015-08-13 12:59:40 PDT
Created attachment 258918 [details]
Patch
Comment 20 WebKit Commit Bot 2015-08-13 13:00:53 PDT
Attachment 258918 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/ChangeLog:11:  Need whitespace between colon and description  [changelog/filechangedescriptionwhitespace] [5]
ERROR: Source/JavaScriptCore/ChangeLog:12:  Need whitespace between colon and description  [changelog/filechangedescriptionwhitespace] [5]
ERROR: Source/JavaScriptCore/ChangeLog:13:  Need whitespace between colon and description  [changelog/filechangedescriptionwhitespace] [5]
ERROR: Source/JavaScriptCore/ChangeLog:14:  Need whitespace between colon and description  [changelog/filechangedescriptionwhitespace] [5]
Total errors found: 4 in 20 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 21 Yusuke Suzuki 2015-08-13 13:03:28 PDT
Comment on attachment 258918 [details]
Patch

The follow-up patch comes here now!
Comment 22 Yusuke Suzuki 2015-08-13 13:53:48 PDT
Created attachment 258928 [details]
Patch
Comment 23 Yusuke Suzuki 2015-08-13 13:54:01 PDT
Just tweak the ChangeLog.
Comment 24 Saam Barati 2015-08-13 16:40:42 PDT
Comment on attachment 258928 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=258928&action=review

r=me

> Source/JavaScriptCore/parser/ParserModes.h:58
> +inline bool isFunctionParseMode(SourceParseMode parseMode)

nice.
Comment 25 Yusuke Suzuki 2015-08-13 16:53:00 PDT
Comment on attachment 258928 [details]
Patch

Thank you for your review :D
Comment 26 Yusuke Suzuki 2015-08-13 16:55:57 PDT
Committed r188417: <http://trac.webkit.org/changeset/188417>