Title: [253314] trunk/Source/_javascript_Core
Revision
253314
Author
[email protected]
Date
2019-12-09 17:54:07 -0800 (Mon, 09 Dec 2019)

Log Message

[WebAssembly] Remove WasmValidate
https://bugs.webkit.org/show_bug.cgi?id=205037

Reviewed by Saam Barati.

It's currently only used when JSC_useWasmLLInt is false and it creates an additional instantiation
of Wasm::FunctionParser, which adds about 100kb to the binary size. This does not introduce any
behavior changes with the default options, but it means that we'll generate bytecode when calling
WebAssembly.validate/new WebAssembly.Module even when the WasmLLInt is disabled.

* _javascript_Core.xcodeproj/project.pbxproj:
* Sources.txt:
* wasm/WasmBBQPlan.cpp:
(JSC::Wasm::BBQPlan::didReceiveFunctionData):
* wasm/WasmEntryPlan.cpp:
* wasm/WasmLLIntPlan.cpp:
* wasm/WasmModule.cpp:
(JSC::Wasm::makeValidationResult):
(JSC::Wasm::makeValidationCallback):
(JSC::Wasm::Module::validateSync):
(JSC::Wasm::Module::validateAsync):
* wasm/WasmModule.h:
* wasm/WasmOMGForOSREntryPlan.cpp:
(JSC::Wasm::OMGForOSREntryPlan::work):
* wasm/WasmOMGPlan.cpp:
(JSC::Wasm::OMGPlan::work):
* wasm/WasmPlan.cpp:
* wasm/WasmValidate.cpp: Removed.
* wasm/WasmValidate.h: Removed.

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (253313 => 253314)


--- trunk/Source/_javascript_Core/ChangeLog	2019-12-10 01:50:00 UTC (rev 253313)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-12-10 01:54:07 UTC (rev 253314)
@@ -1,5 +1,37 @@
 2019-12-09  Tadeu Zagallo  <[email protected]>
 
+        [WebAssembly] Remove WasmValidate
+        https://bugs.webkit.org/show_bug.cgi?id=205037
+
+        Reviewed by Saam Barati.
+
+        It's currently only used when JSC_useWasmLLInt is false and it creates an additional instantiation
+        of Wasm::FunctionParser, which adds about 100kb to the binary size. This does not introduce any
+        behavior changes with the default options, but it means that we'll generate bytecode when calling
+        WebAssembly.validate/new WebAssembly.Module even when the WasmLLInt is disabled.
+
+        * _javascript_Core.xcodeproj/project.pbxproj:
+        * Sources.txt:
+        * wasm/WasmBBQPlan.cpp:
+        (JSC::Wasm::BBQPlan::didReceiveFunctionData):
+        * wasm/WasmEntryPlan.cpp:
+        * wasm/WasmLLIntPlan.cpp:
+        * wasm/WasmModule.cpp:
+        (JSC::Wasm::makeValidationResult):
+        (JSC::Wasm::makeValidationCallback):
+        (JSC::Wasm::Module::validateSync):
+        (JSC::Wasm::Module::validateAsync):
+        * wasm/WasmModule.h:
+        * wasm/WasmOMGForOSREntryPlan.cpp:
+        (JSC::Wasm::OMGForOSREntryPlan::work):
+        * wasm/WasmOMGPlan.cpp:
+        (JSC::Wasm::OMGPlan::work):
+        * wasm/WasmPlan.cpp:
+        * wasm/WasmValidate.cpp: Removed.
+        * wasm/WasmValidate.h: Removed.
+
+2019-12-09  Tadeu Zagallo  <[email protected]>
+
         REGRESSION(r253140): WebAssembly validation should check for unmatched else before calling addElse/addElseToUnreachable
         https://bugs.webkit.org/show_bug.cgi?id=205022
         <rdar://problem/57748159>

Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (253313 => 253314)


--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2019-12-10 01:50:00 UTC (rev 253313)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2019-12-10 01:54:07 UTC (rev 253314)
@@ -1115,7 +1115,6 @@
 		53F6BF6D1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F6BF6C1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		53FA2AE11CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 53FA2AE01CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		53FD04D41D7AB291003287D3 /* WasmCallingConvention.h in Headers */ = {isa = PBXBuildFile; fileRef = 53FD04D21D7AB187003287D3 /* WasmCallingConvention.h */; settings = {ATTRIBUTES = (Private, ); }; };
-		53FF7F991DBFCD9000A26CCC /* WasmValidate.h in Headers */ = {isa = PBXBuildFile; fileRef = 53FF7F981DBFCD9000A26CCC /* WasmValidate.h */; };
 		5B70CFDE1DB69E6600EC23F9 /* JSAsyncFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = 5B70CFD81DB69E5C00EC23F9 /* JSAsyncFunction.h */; };
 		5B70CFE01DB69E6600EC23F9 /* AsyncFunctionPrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = 5B70CFDA1DB69E5C00EC23F9 /* AsyncFunctionPrototype.h */; };
 		5B70CFE21DB69E6600EC23F9 /* AsyncFunctionConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = 5B70CFDC1DB69E5C00EC23F9 /* AsyncFunctionConstructor.h */; };
@@ -3819,8 +3818,6 @@
 		53FA2AE21CF380390022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp; sourceTree = "<group>"; };
 		53FD04D11D7AB187003287D3 /* WasmCallingConvention.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmCallingConvention.cpp; sourceTree = "<group>"; };
 		53FD04D21D7AB187003287D3 /* WasmCallingConvention.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmCallingConvention.h; sourceTree = "<group>"; };
-		53FF7F981DBFCD9000A26CCC /* WasmValidate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmValidate.h; sourceTree = "<group>"; };
-		53FF7F9A1DBFD2B900A26CCC /* WasmValidate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmValidate.cpp; sourceTree = "<group>"; };
 		5B70CFD81DB69E5C00EC23F9 /* JSAsyncFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAsyncFunction.h; sourceTree = "<group>"; };
 		5B70CFD91DB69E5C00EC23F9 /* JSAsyncFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSAsyncFunction.cpp; sourceTree = "<group>"; };
 		5B70CFDA1DB69E5C00EC23F9 /* AsyncFunctionPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsyncFunctionPrototype.h; sourceTree = "<group>"; };
@@ -6868,8 +6865,6 @@
 				5250D2D01E8DA05A0029A932 /* WasmThunks.h */,
 				E3C694B223026874006FBE42 /* WasmTierUpCount.cpp */,
 				53E9E0AE1EAEC45700FEE251 /* WasmTierUpCount.h */,
-				53FF7F9A1DBFD2B900A26CCC /* WasmValidate.cpp */,
-				53FF7F981DBFCD9000A26CCC /* WasmValidate.h */,
 				530FB3031E7A1146003C19DD /* WasmWorklist.cpp */,
 				530FB3011E7A0B6E003C19DD /* WasmWorklist.h */,
 			);
@@ -10298,7 +10293,6 @@
 				5250D2D21E8DA05A0029A932 /* WasmThunks.h in Headers */,
 				53E9E0AF1EAEC45700FEE251 /* WasmTierUpCount.h in Headers */,
 				AD5C36EC1F75AD7C000BCAAF /* WasmToJS.h in Headers */,
-				53FF7F991DBFCD9000A26CCC /* WasmValidate.h in Headers */,
 				530FB3021E7A0B6E003C19DD /* WasmWorklist.h in Headers */,
 				FED94F2F171E3E2300BE77A4 /* Watchdog.h in Headers */,
 				0F919D2615853CE3004A4E7D /* Watchpoint.h in Headers */,

Modified: trunk/Source/_javascript_Core/Sources.txt (253313 => 253314)


--- trunk/Source/_javascript_Core/Sources.txt	2019-12-10 01:50:00 UTC (rev 253313)
+++ trunk/Source/_javascript_Core/Sources.txt	2019-12-10 01:54:07 UTC (rev 253314)
@@ -1038,7 +1038,6 @@
 wasm/WasmTable.cpp
 wasm/WasmThunks.cpp
 wasm/WasmTierUpCount.cpp
-wasm/WasmValidate.cpp
 wasm/WasmWorklist.cpp
 
 wasm/js/JSToWasm.cpp

Modified: trunk/Source/_javascript_Core/wasm/WasmBBQPlan.cpp (253313 => 253314)


--- trunk/Source/_javascript_Core/wasm/WasmBBQPlan.cpp	2019-12-10 01:50:00 UTC (rev 253313)
+++ trunk/Source/_javascript_Core/wasm/WasmBBQPlan.cpp	2019-12-10 01:54:07 UTC (rev 253314)
@@ -40,7 +40,6 @@
 #include "WasmMemory.h"
 #include "WasmSignatureInlines.h"
 #include "WasmTierUpCount.h"
-#include "WasmValidate.h"
 #include <wtf/DataLog.h>
 #include <wtf/Locker.h>
 #include <wtf/MonotonicTime.h>
@@ -222,7 +221,6 @@
     const Signature& signature = SignatureInformation::get(signatureIndex);
     unsigned functionIndexSpace = m_moduleInformation->importFunctionCount() + functionIndex;
     ASSERT_UNUSED(functionIndexSpace, m_moduleInformation->signatureIndexFromFunctionIndexSpace(functionIndexSpace) == signatureIndex);
-    ASSERT(validateFunction(function, signature, m_moduleInformation.get()));
     Expected<std::unique_ptr<InternalFunction>, String> parseAndCompileResult;
     unsigned osrEntryScratchBufferSize = 0;
 
@@ -317,24 +315,9 @@
     }
 }
 
-bool BBQPlan::didReceiveFunctionData(unsigned functionIndex, const FunctionData& function)
+bool BBQPlan::didReceiveFunctionData(unsigned, const FunctionData&)
 {
-    dataLogLnIf(WasmBBQPlanInternal::verbose, "Processing function starting at: ", function.start, " and ending at: ", function.end);
-    size_t functionLength = function.end - function.start;
-    ASSERT(functionLength == function.data.size());
-    SignatureIndex signatureIndex = m_moduleInformation->internalFunctionSignatureIndices[functionIndex];
-    const Signature& signature = SignatureInformation::get(signatureIndex);
-
-    auto validationResult = validateFunction(function, signature, m_moduleInformation.get());
-    if (!validationResult) {
-        if (WasmBBQPlanInternal::verbose) {
-            for (unsigned i = 0; i < functionLength; ++i)
-                dataLog(RawPointer(reinterpret_cast<void*>(function.data[i])), ", ");
-            dataLogLn();
-        }
-        fail(holdLock(m_lock), makeString(validationResult.error(), ", in function at index ", String::number(functionIndex))); // FIXME make this an Expected.
-    }
-    return !!validationResult;
+    return true;
 }
 
 } } // namespace JSC::Wasm

Modified: trunk/Source/_javascript_Core/wasm/WasmEntryPlan.cpp (253313 => 253314)


--- trunk/Source/_javascript_Core/wasm/WasmEntryPlan.cpp	2019-12-10 01:50:00 UTC (rev 253313)
+++ trunk/Source/_javascript_Core/wasm/WasmEntryPlan.cpp	2019-12-10 01:54:07 UTC (rev 253314)
@@ -30,7 +30,6 @@
 #include "WasmFaultSignalHandler.h"
 #include "WasmMemory.h"
 #include "WasmSignatureInlines.h"
-#include "WasmValidate.h"
 #include <wtf/CrossThreadCopier.h>
 #include <wtf/DataLog.h>
 #include <wtf/Locker.h>

Modified: trunk/Source/_javascript_Core/wasm/WasmLLIntPlan.cpp (253313 => 253314)


--- trunk/Source/_javascript_Core/wasm/WasmLLIntPlan.cpp	2019-12-10 01:50:00 UTC (rev 253313)
+++ trunk/Source/_javascript_Core/wasm/WasmLLIntPlan.cpp	2019-12-10 01:54:07 UTC (rev 253314)
@@ -37,7 +37,6 @@
 #include "WasmCallee.h"
 #include "WasmLLIntGenerator.h"
 #include "WasmSignatureInlines.h"
-#include "WasmValidate.h"
 
 namespace JSC { namespace Wasm {
 

Modified: trunk/Source/_javascript_Core/wasm/WasmModule.cpp (253313 => 253314)


--- trunk/Source/_javascript_Core/wasm/WasmModule.cpp	2019-12-10 01:50:00 UTC (rev 253313)
+++ trunk/Source/_javascript_Core/wasm/WasmModule.cpp	2019-12-10 01:54:07 UTC (rev 253314)
@@ -42,11 +42,6 @@
 {
 }
 
-Module::Module(BBQPlan& plan)
-    : m_moduleInformation(plan.takeModuleInformation())
-{
-}
-
 Module::~Module() { }
 
 Wasm::SignatureIndex Module::signatureIndexFromFunctionIndexSpace(unsigned functionIndexSpace) const
@@ -54,8 +49,7 @@
     return m_moduleInformation->signatureIndexFromFunctionIndexSpace(functionIndexSpace);
 }
 
-template<typename Plan>
-static Module::ValidationResult makeValidationResult(Plan& plan)
+static Module::ValidationResult makeValidationResult(LLIntPlan& plan)
 {
     ASSERT(!plan.hasWork());
     if (plan.failed())
@@ -63,38 +57,26 @@
     return Module::ValidationResult(Module::create(plan));
 }
 
-template<typename PlanT>
 static Plan::CompletionTask makeValidationCallback(Module::AsyncValidationCallback&& callback)
 {
     return createSharedTask<Plan::CallbackType>([callback = WTFMove(callback)] (Plan& plan) {
         ASSERT(!plan.hasWork());
-        callback->run(makeValidationResult(static_cast<PlanT&>(plan)));
+        callback->run(makeValidationResult(static_cast<LLIntPlan&>(plan)));
     });
 }
 
 Module::ValidationResult Module::validateSync(Context* context, Vector<uint8_t>&& source)
 {
-    if (Options::useWasmLLInt()) {
-        Ref<LLIntPlan> plan = adoptRef(*new LLIntPlan(context, WTFMove(source), EntryPlan::Validation, Plan::dontFinalize()));
-        Wasm::ensureWorklist().enqueue(plan.get());
-        plan->waitForCompletion();
-        return makeValidationResult(plan.get());
-    }
-
-    Ref<BBQPlan> plan = adoptRef(*new BBQPlan(context, WTFMove(source), EntryPlan::Validation, Plan::dontFinalize()));
-    plan->parseAndValidateModule();
+    Ref<LLIntPlan> plan = adoptRef(*new LLIntPlan(context, WTFMove(source), EntryPlan::Validation, Plan::dontFinalize()));
+    Wasm::ensureWorklist().enqueue(plan.get());
+    plan->waitForCompletion();
     return makeValidationResult(plan.get());
 }
 
 void Module::validateAsync(Context* context, Vector<uint8_t>&& source, Module::AsyncValidationCallback&& callback)
 {
-    if (Options::useWasmLLInt()) {
-        Ref<Plan> plan = adoptRef(*new LLIntPlan(context, WTFMove(source), EntryPlan::Validation, makeValidationCallback<LLIntPlan>(WTFMove(callback))));
-        Wasm::ensureWorklist().enqueue(WTFMove(plan));
-    } else {
-        Ref<Plan> plan = adoptRef(*new BBQPlan(context, WTFMove(source), EntryPlan::Validation, makeValidationCallback<BBQPlan>(WTFMove(callback))));
-        Wasm::ensureWorklist().enqueue(WTFMove(plan));
-    }
+    Ref<Plan> plan = adoptRef(*new LLIntPlan(context, WTFMove(source), EntryPlan::Validation, makeValidationCallback(WTFMove(callback))));
+    Wasm::ensureWorklist().enqueue(WTFMove(plan));
 }
 
 Ref<CodeBlock> Module::getOrCreateCodeBlock(Context* context, MemoryMode mode)

Modified: trunk/Source/_javascript_Core/wasm/WasmModule.h (253313 => 253314)


--- trunk/Source/_javascript_Core/wasm/WasmModule.h	2019-12-10 01:50:00 UTC (rev 253313)
+++ trunk/Source/_javascript_Core/wasm/WasmModule.h	2019-12-10 01:54:07 UTC (rev 253314)
@@ -37,7 +37,6 @@
 
 namespace JSC { namespace Wasm {
 
-class BBQPlan;
 class LLIntPlan;
 struct Context;
 struct ModuleInformation;
@@ -53,11 +52,6 @@
     static ValidationResult validateSync(Context*, Vector<uint8_t>&& source);
     static void validateAsync(Context*, Vector<uint8_t>&& source, Module::AsyncValidationCallback&&);
 
-    static Ref<Module> create(BBQPlan& plan)
-    {
-        return adoptRef(*new Module(plan));
-    }
-
     static Ref<Module> create(LLIntPlan& plan)
     {
         return adoptRef(*new Module(plan));
@@ -75,7 +69,6 @@
 private:
     Ref<CodeBlock> getOrCreateCodeBlock(Context*, MemoryMode);
 
-    Module(BBQPlan&);
     Module(LLIntPlan&);
     Ref<ModuleInformation> m_moduleInformation;
     RefPtr<CodeBlock> m_codeBlocks[Wasm::NumberOfMemoryModes];

Modified: trunk/Source/_javascript_Core/wasm/WasmOMGForOSREntryPlan.cpp (253313 => 253314)


--- trunk/Source/_javascript_Core/wasm/WasmOMGForOSREntryPlan.cpp	2019-12-10 01:50:00 UTC (rev 253313)
+++ trunk/Source/_javascript_Core/wasm/WasmOMGForOSREntryPlan.cpp	2019-12-10 01:54:07 UTC (rev 253314)
@@ -40,7 +40,6 @@
 #include "WasmMemory.h"
 #include "WasmNameSection.h"
 #include "WasmSignatureInlines.h"
-#include "WasmValidate.h"
 #include "WasmWorklist.h"
 #include <wtf/DataLog.h>
 #include <wtf/Locker.h>
@@ -79,7 +78,6 @@
 
     SignatureIndex signatureIndex = m_moduleInformation->internalFunctionSignatureIndices[m_functionIndex];
     const Signature& signature = SignatureInformation::get(signatureIndex);
-    ASSERT(validateFunction(function, signature, m_moduleInformation.get()));
 
     Vector<UnlinkedWasmToWasmCall> unlinkedCalls;
     CompilationContext context;

Modified: trunk/Source/_javascript_Core/wasm/WasmOMGPlan.cpp (253313 => 253314)


--- trunk/Source/_javascript_Core/wasm/WasmOMGPlan.cpp	2019-12-10 01:50:00 UTC (rev 253313)
+++ trunk/Source/_javascript_Core/wasm/WasmOMGPlan.cpp	2019-12-10 01:54:07 UTC (rev 253314)
@@ -40,7 +40,6 @@
 #include "WasmMemory.h"
 #include "WasmNameSection.h"
 #include "WasmSignatureInlines.h"
-#include "WasmValidate.h"
 #include "WasmWorklist.h"
 #include <wtf/DataLog.h>
 #include <wtf/Locker.h>
@@ -77,7 +76,6 @@
 
     SignatureIndex signatureIndex = m_moduleInformation->internalFunctionSignatureIndices[m_functionIndex];
     const Signature& signature = SignatureInformation::get(signatureIndex);
-    ASSERT(validateFunction(function, signature, m_moduleInformation.get()));
 
     Vector<UnlinkedWasmToWasmCall> unlinkedCalls;
     unsigned osrEntryScratchBufferSize;

Modified: trunk/Source/_javascript_Core/wasm/WasmPlan.cpp (253313 => 253314)


--- trunk/Source/_javascript_Core/wasm/WasmPlan.cpp	2019-12-10 01:50:00 UTC (rev 253313)
+++ trunk/Source/_javascript_Core/wasm/WasmPlan.cpp	2019-12-10 01:54:07 UTC (rev 253314)
@@ -35,7 +35,6 @@
 #include "WasmCallingConvention.h"
 #include "WasmFaultSignalHandler.h"
 #include "WasmMemory.h"
-#include "WasmValidate.h"
 #include <wtf/DataLog.h>
 #include <wtf/Locker.h>
 #include <wtf/MonotonicTime.h>

Deleted: trunk/Source/_javascript_Core/wasm/WasmValidate.cpp (253313 => 253314)


--- trunk/Source/_javascript_Core/wasm/WasmValidate.cpp	2019-12-10 01:50:00 UTC (rev 253313)
+++ trunk/Source/_javascript_Core/wasm/WasmValidate.cpp	2019-12-10 01:54:07 UTC (rev 253314)
@@ -1,396 +0,0 @@
-/*
- * Copyright (C) 2016-2019 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "WasmValidate.h"
-
-#if ENABLE(WEBASSEMBLY)
-
-#include "JSCJSValueInlines.h"
-#include "WasmFunctionParser.h"
-#include "WasmSignature.h"
-#include <wtf/CommaPrinter.h>
-
-namespace JSC { namespace Wasm {
-
-class Validate {
-public:
-    class ControlData {
-    public:
-        ControlData() = default;
-        ControlData(BlockType type, BlockSignature signature)
-            : m_blockType(type)
-            , m_signature(signature)
-        {
-        }
-
-        static bool isIf(const ControlData& control) { return control.blockType() == BlockType::If; }
-        static bool isTopLevel(const ControlData& control) { return control.blockType() == BlockType::TopLevel; }
-
-        BlockType blockType() const { return m_blockType; }
-        BlockSignature signature() const { return m_signature; }
-
-        unsigned branchTargetArity() const { return blockType() == BlockType::Loop ? signature()->argumentCount() : signature()->returnCount(); }
-        Type branchTargetType(unsigned i) const
-        {
-            ASSERT(i < branchTargetArity());
-            return blockType() == BlockType::Loop ? signature()->argument(i) : signature()->returnType(i);
-        }
-
-        void dump(PrintStream& out) const
-        {
-            switch (blockType()) {
-            case BlockType::If:
-                out.print("If:       ");
-                break;
-            case BlockType::Block:
-                out.print("Block:    ");
-                break;
-            case BlockType::Loop:
-                out.print("Loop:     ");
-                break;
-            case BlockType::TopLevel:
-                out.print("TopLevel: ");
-                break;
-            }
-            const Signature& sig = *signature();
-            out.print(sig);
-        }
-
-    private:
-        BlockType m_blockType;
-        BlockSignature m_signature;
-    };
-
-    enum ExpressionType { EmptyExpression };
-
-    using ErrorType = String;
-    using UnexpectedResult = Unexpected<ErrorType>;
-    using Result = Expected<void, ErrorType>;
-    using ControlType = ControlData;
-
-    using ControlEntry = FunctionParser<Validate>::ControlEntry;
-    using ControlStack = FunctionParser<Validate>::ControlStack;
-    using ResultList = FunctionParser<Validate>::ResultList;
-    using Stack = FunctionParser<Validate>::Stack;
-
-    static ExpressionType emptyExpression() { return EmptyExpression; };
-
-    template <typename ...Args>
-    NEVER_INLINE UnexpectedResult WARN_UNUSED_RETURN fail(const Args&... args) const
-    {
-        using namespace FailureHelper; // See ADL comment in WasmParser.h.
-        if (UNLIKELY(!ASSERT_DISABLED && Options::crashOnFailedWebAssemblyValidate()))
-            WTFBreakpointTrap();
-
-        StringPrintStream out;
-        out.print("WebAssembly.Module doesn't validate: "_s, args...);
-        return UnexpectedResult(out.toString());
-    }
-#define WASM_VALIDATOR_FAIL_IF(condition, ...) do { \
-        if (UNLIKELY(condition))                    \
-            return fail(__VA_ARGS__);               \
-    } while (0)
-
-    Result WARN_UNUSED_RETURN addArguments(const Signature&);
-    Result WARN_UNUSED_RETURN addLocal(Type, uint32_t);
-    ExpressionType addConstant(Type, uint64_t) { return EmptyExpression; }
-
-    // References
-    Result WARN_UNUSED_RETURN addRefIsNull(ExpressionType value, ExpressionType& result);
-    Result WARN_UNUSED_RETURN addRefFunc(uint32_t index, ExpressionType& result);
-
-    // Tables
-    Result WARN_UNUSED_RETURN addTableGet(unsigned, ExpressionType index, ExpressionType& result);
-    Result WARN_UNUSED_RETURN addTableSet(unsigned, ExpressionType index, ExpressionType value);
-    Result WARN_UNUSED_RETURN addTableSize(unsigned, ExpressionType& result);
-    Result WARN_UNUSED_RETURN addTableGrow(unsigned, ExpressionType fill, ExpressionType delta, ExpressionType& result);
-    Result WARN_UNUSED_RETURN addTableFill(unsigned, ExpressionType offset, ExpressionType fill, ExpressionType count);
-    // Locals
-    Result WARN_UNUSED_RETURN getLocal(uint32_t index, ExpressionType& result);
-    Result WARN_UNUSED_RETURN setLocal(uint32_t index, ExpressionType value);
-
-    // Globals
-    Result WARN_UNUSED_RETURN getGlobal(uint32_t index, ExpressionType& result);
-    Result WARN_UNUSED_RETURN setGlobal(uint32_t index, ExpressionType value);
-
-    // Memory
-    Result WARN_UNUSED_RETURN load(LoadOpType, ExpressionType pointer, ExpressionType& result, uint32_t offset);
-    Result WARN_UNUSED_RETURN store(StoreOpType, ExpressionType pointer, ExpressionType value, uint32_t offset);
-
-    // Basic operators
-    template<OpType>
-    Result WARN_UNUSED_RETURN addOp(ExpressionType arg, ExpressionType& result);
-    template<OpType>
-    Result WARN_UNUSED_RETURN addOp(ExpressionType left, ExpressionType right, ExpressionType& result);
-    Result WARN_UNUSED_RETURN addSelect(ExpressionType condition, ExpressionType nonZero, ExpressionType zero, ExpressionType& result);
-
-    // Control flow
-    ControlData WARN_UNUSED_RETURN addTopLevel(BlockSignature);
-    Result WARN_UNUSED_RETURN addBlock(BlockSignature, Stack& enclosingStack, ControlType& newBlock, Stack& newStack);
-    Result WARN_UNUSED_RETURN addLoop(BlockSignature, Stack& enclosingStack, ControlType& block, Stack& newStack, uint32_t loopIndex);
-    Result WARN_UNUSED_RETURN addIf(ExpressionType condition, BlockSignature, Stack& enclosingStack, ControlType& result, Stack& newStack);
-    Result WARN_UNUSED_RETURN addElse(ControlData&, const Stack&);
-    Result WARN_UNUSED_RETURN addElseToUnreachable(ControlData&);
-
-    Result WARN_UNUSED_RETURN addReturn(ControlData& topLevel, const Stack& returnValues);
-    Result WARN_UNUSED_RETURN addBranch(ControlData&, ExpressionType condition, const Stack& expressionStack);
-    Result WARN_UNUSED_RETURN addSwitch(ExpressionType condition, const Vector<ControlData*>& targets, ControlData& defaultTarget, const Stack& expressionStack);
-    Result WARN_UNUSED_RETURN endBlock(ControlEntry&, Stack& expressionStack);
-    Result WARN_UNUSED_RETURN addEndToUnreachable(ControlEntry&);
-    Result WARN_UNUSED_RETURN addGrowMemory(ExpressionType delta, ExpressionType& result);
-    Result WARN_UNUSED_RETURN addCurrentMemory(ExpressionType& result);
-
-    Result WARN_UNUSED_RETURN addUnreachable() { return { }; }
-    Result WARN_UNUSED_RETURN endTopLevel(BlockSignature, const Stack&) { return { }; }
-
-    // Calls
-    Result WARN_UNUSED_RETURN addCall(unsigned calleeIndex, const Signature&, const Vector<ExpressionType>& args, ResultList&);
-    Result WARN_UNUSED_RETURN addCallIndirect(unsigned tableIndex, const Signature&, const Vector<ExpressionType>& args, ResultList&);
-
-    Validate()
-    {
-    }
-
-    void dump(const ControlStack&, const Stack*);
-    void setParser(FunctionParser<Validate>*) { }
-    void didFinishParsingLocals() { }
-    void didPopValueFromStack() { }
-
-private:
-    Result WARN_UNUSED_RETURN unify(const Stack&, const ControlData&);
-};
-
-auto Validate::addArguments(const Signature&) -> Result
-{
-    return { };
-}
-
-auto Validate::addTableGet(unsigned, ExpressionType, ExpressionType&) -> Result
-{
-    return { };
-}
-
-auto Validate::addTableSet(unsigned, ExpressionType, ExpressionType) -> Result
-{
-    return { };
-}
-
-auto Validate::addTableSize(unsigned, ExpressionType&) -> Result
-{
-    return { };
-}
-
-auto Validate::addTableGrow(unsigned, ExpressionType, ExpressionType, ExpressionType&) -> Result
-{
-    return { };
-}
-
-auto Validate::addTableFill(unsigned, ExpressionType, ExpressionType, ExpressionType) -> Result
-{
-    return { };
-}
-
-auto Validate::addRefIsNull(ExpressionType, ExpressionType&) -> Result
-{
-    return { };
-}
-
-auto Validate::addRefFunc(uint32_t, ExpressionType&) -> Result
-{
-    return { };
-}
-
-auto Validate::addLocal(Type, uint32_t) -> Result
-{
-    return { };
-}
-
-auto Validate::getLocal(uint32_t, ExpressionType&) -> Result
-{
-    return { };
-}
-
-auto Validate::setLocal(uint32_t, ExpressionType) -> Result
-{
-    return { };
-}
-
-auto Validate::getGlobal(uint32_t, ExpressionType&) -> Result
-{
-    return { };
-}
-
-auto Validate::setGlobal(uint32_t, ExpressionType) -> Result
-{
-    return { };
-}
-
-Validate::ControlType Validate::addTopLevel(BlockSignature signature)
-{
-    return ControlData(BlockType::TopLevel, signature);
-}
-
-auto Validate::addBlock(BlockSignature signature, Stack& enclosingStack, ControlType& newBlock, Stack& newStack) -> Result
-{
-    splitStack(signature, enclosingStack, newStack);
-    newBlock = ControlData(BlockType::Block, signature);
-    return { };
-}
-
-auto Validate::addLoop(BlockSignature signature, Stack& enclosingStack, ControlType& loop, Stack& newStack, uint32_t) -> Result
-{
-    splitStack(signature, enclosingStack, newStack);
-    loop = ControlData(BlockType::Loop, signature);
-    return { };
-}
-
-auto Validate::addSelect(ExpressionType, ExpressionType, ExpressionType, ExpressionType&) -> Result
-{
-    return { };
-}
-
-auto Validate::addIf(ExpressionType, BlockSignature signature, Stack& enclosingStack, ControlType& result, Stack& newStack) -> Result
-{
-    splitStack(signature, enclosingStack, newStack);
-    result = ControlData(BlockType::If, signature);
-    return { };
-}
-
-auto Validate::addElse(ControlType& current, const Stack&) -> Result
-{
-    return addElseToUnreachable(current);
-}
-
-auto Validate::addElseToUnreachable(ControlType& current) -> Result
-{
-    current = ControlData(BlockType::Block, current.signature());
-    return { };
-}
-
-auto Validate::addReturn(ControlType&, const Stack&) -> Result
-{
-    return { };
-}
-
-auto Validate::addBranch(ControlType&, ExpressionType, const Stack&) -> Result
-{
-    return { };
-}
-
-auto Validate::addSwitch(ExpressionType, const Vector<ControlData*>&, ControlData&, const Stack&) -> Result
-{
-    return { };
-}
-
-auto Validate::addGrowMemory(ExpressionType, ExpressionType&) -> Result
-{
-    return { };
-}
-
-auto Validate::addCurrentMemory(ExpressionType&) -> Result
-{
-    return { };
-}
-
-auto Validate::endBlock(ControlEntry& entry, Stack&) -> Result
-{
-    return addEndToUnreachable(entry);
-}
-
-auto Validate::addEndToUnreachable(ControlEntry& entry) -> Result
-{
-    auto block = entry.controlData;
-    for (unsigned i = 0; i < block.signature()->returnCount(); ++i)
-        entry.enclosedExpressionStack.constructAndAppend(block.signature()->returnType(i), EmptyExpression);
-    return { };
-}
-
-auto Validate::addCall(unsigned, const Signature& signature, const Vector<ExpressionType>&, ResultList& results) -> Result
-{
-    for (unsigned i = 0; i < signature.returnCount(); ++i)
-        results.append(EmptyExpression);
-    return { };
-}
-
-auto Validate::addCallIndirect(unsigned, const Signature& signature, const Vector<ExpressionType>&, ResultList& results) -> Result
-{
-    for (unsigned i = 0; i < signature.returnCount(); ++i)
-        results.append(EmptyExpression);
-    return { };
-}
-
-auto Validate::load(LoadOpType, ExpressionType, ExpressionType&, uint32_t) -> Result
-{
-    return { };
-}
-
-auto Validate::store(StoreOpType, ExpressionType, ExpressionType, uint32_t) -> Result
-{
-    return { };
-}
-
-template<OpType>
-auto Validate::addOp(ExpressionType, ExpressionType&) -> Result
-{
-    return { };
-}
-
-template<OpType>
-auto Validate::addOp(ExpressionType, ExpressionType, ExpressionType&) -> Result
-{
-    return { };
-}
-
-static void dumpExpressionStack(const CommaPrinter& comma, const Validate::Stack& expressionStack)
-{
-    dataLog(comma, " ExpressionStack:");
-    for (const auto& _expression_ : expressionStack)
-        dataLog(comma, makeString(_expression_.type()));
-}
-
-void Validate::dump(const ControlStack& controlStack, const Stack* expressionStack)
-{
-    for (size_t i = controlStack.size(); i--;) {
-        dataLog("  ", controlStack[i].controlData);
-        CommaPrinter comma(", ", "");
-        dumpExpressionStack(comma, *expressionStack);
-        expressionStack = &controlStack[i].enclosedExpressionStack;
-        dataLogLn();
-    }
-    dataLogLn();
-}
-
-Expected<void, String> validateFunction(const FunctionData& function, const Signature& signature, const ModuleInformation& module)
-{
-    Validate context;
-    FunctionParser<Validate> validator(context, function.data.data(), function.data.size(), signature, module);
-    WASM_FAIL_IF_HELPER_FAILS(validator.parse());
-    return { };
-}
-
-} } // namespace JSC::Wasm
-
-#endif // ENABLE(WEBASSEMBLY)

Deleted: trunk/Source/_javascript_Core/wasm/WasmValidate.h (253313 => 253314)


--- trunk/Source/_javascript_Core/wasm/WasmValidate.h	2019-12-10 01:50:00 UTC (rev 253313)
+++ trunk/Source/_javascript_Core/wasm/WasmValidate.h	2019-12-10 01:54:07 UTC (rev 253314)
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if ENABLE(WEBASSEMBLY)
-
-#include "WasmModuleInformation.h"
-#include <wtf/Expected.h>
-
-namespace JSC {
-
-namespace Wasm {
-
-Expected<void, String> validateFunction(const FunctionData&, const Signature&, const ModuleInformation&);
-
-} } // namespace JSC::Wasm
-
-#endif // ENABLE(WEBASSEMBLY)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to