Changeset 223894 in webkit


Ignore:
Timestamp:
Oct 24, 2017 10:11:39 AM (6 years ago)
Author:
Yusuke Suzuki
Message:

[JSC] modules can be visited more than once when resolving bindings through "star" exports as long as the exportName is different each time
https://bugs.webkit.org/show_bug.cgi?id=178308

Reviewed by Mark Lam.

JSTests:

  • test262.yaml:

Source/JavaScriptCore:

With the change of the spec[1], we now do not need to remember star resolution modules.
We reflect this change to our implementation. Since this change is covered by test262,
this patch improves the score of test262.

We also add logging to ResolveExport to debug it easily.

[1]: https://github.com/tc39/ecma262/commit/a865e778ff0fc60e26e3e1c589635103710766a1

  • runtime/AbstractModuleRecord.cpp:

(JSC::AbstractModuleRecord::ResolveQuery::dump const):
(JSC::AbstractModuleRecord::resolveExportImpl):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r223834 r223894  
     12017-10-15  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] modules can be visited more than once when resolving bindings through "star" exports as long as the exportName is different each time
     4        https://bugs.webkit.org/show_bug.cgi?id=178308
     5
     6        Reviewed by Mark Lam.
     7
     8        * test262.yaml:
     9
    1102017-10-23  Yusuke Suzuki  <utatane.tea@gmail.com>
    211
  • trunk/JSTests/test262.yaml

    r223724 r223894  
    8579185791  cmd: prepareTest262Fixture
    8579285792- path: test262/test/language/module-code/instn-iee-star-cycle.js
    85793   cmd: runTest262 :fail, "NoException", ["../../../harness/assert.js", "../../../harness/sta.js"], [:module]
     85793  cmd: runTest262 :normal, "NoException", ["../../../harness/assert.js", "../../../harness/sta.js"], [:module]
    8579485794- path: test262/test/language/module-code/instn-iee-trlng-comma.js
    8579585795  cmd: runTest262 :normal, "NoException", ["../../../harness/assert.js", "../../../harness/sta.js"], [:module]
     
    8589385893  cmd: prepareTest262Fixture
    8589485894- path: test262/test/language/module-code/instn-named-star-cycle.js
    85895   cmd: runTest262 :fail, "NoException", ["../../../harness/assert.js", "../../../harness/sta.js"], [:module]
     85895  cmd: runTest262 :normal, "NoException", ["../../../harness/assert.js", "../../../harness/sta.js"], [:module]
    8589685896- path: test262/test/language/module-code/instn-once.js
    8589785897  cmd: runTest262 :normal, "NoException", ["../../../harness/assert.js", "../../../harness/sta.js"], [:module]
     
    8599985999  cmd: prepareTest262Fixture
    8600086000- path: test262/test/language/module-code/instn-star-star-cycle.js
    86001   cmd: runTest262 :fail, "NoException", ["../../../harness/assert.js", "../../../harness/sta.js"], [:module]
     86001  cmd: runTest262 :normal, "NoException", ["../../../harness/assert.js", "../../../harness/sta.js"], [:module]
    8600286002- path: test262/test/language/module-code/instn-uniq-env-rec-other_FIXTURE.js
    8600386003  cmd: prepareTest262Fixture
  • trunk/Source/JavaScriptCore/ChangeLog

    r223892 r223894  
     12017-10-15  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] modules can be visited more than once when resolving bindings through "star" exports as long as the exportName is different each time
     4        https://bugs.webkit.org/show_bug.cgi?id=178308
     5
     6        Reviewed by Mark Lam.
     7
     8        With the change of the spec[1], we now do not need to remember star resolution modules.
     9        We reflect this change to our implementation. Since this change is covered by test262,
     10        this patch improves the score of test262.
     11
     12        We also add logging to ResolveExport to debug it easily.
     13
     14        [1]: https://github.com/tc39/ecma262/commit/a865e778ff0fc60e26e3e1c589635103710766a1
     15
     16        * runtime/AbstractModuleRecord.cpp:
     17        (JSC::AbstractModuleRecord::ResolveQuery::dump const):
     18        (JSC::AbstractModuleRecord::resolveExportImpl):
     19
    1202017-10-24  Yusuke Suzuki  <utatane.tea@gmail.com>
    221
  • trunk/Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp

    r223331 r223894  
    3636
    3737namespace JSC {
     38namespace AbstractModuleRecordInternal {
     39static const bool verbose = false;
     40} // namespace AbstractModuleRecordInternal
    3841
    3942const ClassInfo AbstractModuleRecord::s_info = { "AbstractModuleRecord", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(AbstractModuleRecord) };
     
    178181        static const bool safeToCompareToEmptyOrDeleted = true;
    179182    };
     183    using HashTraits = WTF::CustomHashTraits<ResolveQuery>;
    180184
    181185    ResolveQuery(AbstractModuleRecord* moduleRecord, UniquedStringImpl* exportName)
     
    212216    }
    213217
     218    void dump(PrintStream& out) const
     219    {
     220        if (!moduleRecord) {
     221            out.print("<empty>");
     222            return;
     223        }
     224        out.print(moduleRecord->moduleKey(), " \"", exportName.get(), "\"");
     225    }
     226
    214227    // The module record is not marked from the GC. But these records are reachable from the JSGlobalObject.
    215228    // So we don't care the reachability to this record.
     
    246259    auto scope = DECLARE_THROW_SCOPE(vm);
    247260
    248     // http://www.ecma-international.org/ecma-262/6.0/#sec-resolveexport
     261    if (AbstractModuleRecordInternal::verbose)
     262        dataLog("Resolving ", root, "\n");
     263
     264    // https://tc39.github.io/ecma262/#sec-resolveexport
    249265
    250266    // How to avoid C++ recursion in this function:
     
    481497    //  5. Once we see star links, even if we have not yet traversed that star link path, we should disable caching.
    482498
    483     typedef WTF::HashSet<ResolveQuery, ResolveQuery::Hash, WTF::CustomHashTraits<ResolveQuery>> ResolveSet;
     499    using ResolveSet = WTF::HashSet<ResolveQuery, ResolveQuery::Hash, ResolveQuery::HashTraits>;
    484500    enum class Type { Query, IndirectFallback, GatherStars };
    485501    struct Task {
     
    488504    };
    489505
     506    auto typeString = [] (Type type) -> const char* {
     507        switch (type) {
     508        case Type::Query:
     509            return "Query";
     510        case Type::IndirectFallback:
     511            return "IndirectFallback";
     512        case Type::GatherStars:
     513            return "GatherStars";
     514        }
     515        RELEASE_ASSERT_NOT_REACHED();
     516        return nullptr;
     517    };
     518
    490519    Vector<Task, 8> pendingTasks;
    491520    ResolveSet resolveSet;
    492     HashSet<AbstractModuleRecord*> starSet;
    493521
    494522    Vector<Resolution, 8> frames;
     
    501529    // It will enqueue the star resolution requests. Return "false" if the error occurs.
    502530    auto resolveNonLocal = [&](const ResolveQuery& query) -> bool {
    503         // http://www.ecma-international.org/ecma-262/6.0/#sec-resolveexport
     531        // https://tc39.github.io/ecma262/#sec-resolveexport
    504532        // section 15.2.1.16.3, step 6
    505533        // If the "default" name is not resolved in the current module, we need to throw an error and stop resolution immediately,
     
    510538            return false;
    511539
    512         // step 7, If exportStarSet contains module, then return null.
    513         if (!starSet.add(query.moduleRecord).isNewEntry)
    514             return true;
    515 
    516540        // Enqueue the task to gather the results of the stars.
    517541        // And append the new Resolution frame to gather the local result of the stars.
     
    519543        foundStarLinks = true;
    520544        frames.append(Resolution::notFound());
    521 
    522545
    523546        // Enqueue the tasks in reverse order.
     
    563586        const Task task = pendingTasks.takeLast();
    564587        const ResolveQuery& query = task.query;
     588
     589        if (AbstractModuleRecordInternal::verbose)
     590            dataLog("    ", typeString(task.type), " ", task.query, "\n");
    565591
    566592        switch (task.type) {
Note: See TracChangeset for help on using the changeset viewer.