Bug 1320374: Remove numFuncDefs() from the ModuleGenerator; r=luke
authorBenjamin Bouvier <benj@benj.me>
Fri, 25 Nov 2016 13:59:40 +0100
changeset 324705 3e47198ee2eb8a03205e0817f6dea6151c5266f1
parent 324704 78f16019ce10c8a587501283e6bff54a838d8a8e
child 324706 636dbc0dc25613fb6b6f8ee670323f950b885942
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersluke
bugs1320374
milestone53.0a1
Bug 1320374: Remove numFuncDefs() from the ModuleGenerator; r=luke
js/src/wasm/WasmCompile.cpp
js/src/wasm/WasmGenerator.cpp
js/src/wasm/WasmGenerator.h
--- a/js/src/wasm/WasmCompile.cpp
+++ b/js/src/wasm/WasmCompile.cpp
@@ -67,31 +67,31 @@ DecodeCodeSection(Decoder& d, ModuleGene
     if (!mg.startFuncDefs())
         return false;
 
     uint32_t sectionStart, sectionSize;
     if (!d.startSection(SectionId::Code, &sectionStart, &sectionSize, "code"))
         return false;
 
     if (sectionStart == Decoder::NotStarted) {
-        if (mg.numFuncDefs() != 0)
+        if (mg.env().numFuncDefs() != 0)
             return d.fail("expected function bodies");
 
         return mg.finishFuncDefs();
     }
 
     uint32_t numFuncDefs;
     if (!d.readVarU32(&numFuncDefs))
         return d.fail("expected function body count");
 
-    if (numFuncDefs != mg.numFuncDefs())
+    if (numFuncDefs != mg.env().numFuncDefs())
         return d.fail("function body count does not match function signature count");
 
     for (uint32_t funcDefIndex = 0; funcDefIndex < numFuncDefs; funcDefIndex++) {
-        if (!DecodeFunctionBody(d, mg, mg.numFuncImports() + funcDefIndex))
+        if (!DecodeFunctionBody(d, mg, mg.env().numFuncImports() + funcDefIndex))
             return false;
     }
 
     if (!d.finishSection(sectionStart, sectionSize, "code"))
         return false;
 
     return mg.finishFuncDefs();
 }
--- a/js/src/wasm/WasmGenerator.cpp
+++ b/js/src/wasm/WasmGenerator.cpp
@@ -797,25 +797,16 @@ uint32_t
 ModuleGenerator::numFuncImports() const
 {
     // Until all functions have been validated, asm.js doesn't know the total
     // number of imports.
     MOZ_ASSERT_IF(isAsmJS(), finishedFuncDefs_);
     return metadata_->funcImports.length();
 }
 
-uint32_t
-ModuleGenerator::numFuncDefs() const
-{
-    // asm.js overallocates the length of funcSigs and in general does not know
-    // the number of function definitions until it's done compiling.
-    MOZ_ASSERT(!isAsmJS());
-    return env_->funcSigs.length() - numFuncImports();
-}
-
 const SigWithId&
 ModuleGenerator::funcSig(uint32_t funcIndex) const
 {
     MOZ_ASSERT(env_->funcSigs[funcIndex]);
     return *env_->funcSigs[funcIndex];
 }
 
 bool
@@ -970,17 +961,17 @@ ModuleGenerator::finishFuncDefs()
 #ifdef DEBUG
     if (isAsmJS()) {
         MOZ_ASSERT(numFuncImports() < AsmJSFirstDefFuncIndex);
         for (uint32_t i = 0; i < AsmJSFirstDefFuncIndex; i++)
             MOZ_ASSERT(funcToCodeRange_[i] == BAD_CODE_RANGE);
         for (uint32_t i = AsmJSFirstDefFuncIndex; i < numFinishedFuncDefs_; i++)
             MOZ_ASSERT(funcCodeRange(i).funcIndex() == i);
     } else {
-        MOZ_ASSERT(numFinishedFuncDefs_ == numFuncDefs());
+        MOZ_ASSERT(numFinishedFuncDefs_ == env_->numFuncDefs());
         for (uint32_t i = 0; i < env_->numFuncs(); i++)
             MOZ_ASSERT(funcCodeRange(i).funcIndex() == i);
     }
 #endif
 
     // Complete element segments with the code range index of every element, now
     // that all functions have been compiled.
 
--- a/js/src/wasm/WasmGenerator.h
+++ b/js/src/wasm/WasmGenerator.h
@@ -87,16 +87,19 @@ class MOZ_STACK_CLASS ModuleGenerator
     MOZ_MUST_USE bool finishLinkData(Bytes& code);
     MOZ_MUST_USE bool addFuncImport(const Sig& sig, uint32_t globalDataOffset);
     MOZ_MUST_USE bool allocateGlobalBytes(uint32_t bytes, uint32_t align, uint32_t* globalDataOff);
     MOZ_MUST_USE bool allocateGlobal(GlobalDesc* global);
 
     MOZ_MUST_USE bool initAsmJS(Metadata* asmJSMetadata);
     MOZ_MUST_USE bool initWasm();
 
+    // Functions declarations:
+    uint32_t numFuncImports() const;
+
   public:
     explicit ModuleGenerator();
     ~ModuleGenerator();
 
     MOZ_MUST_USE bool init(UniqueModuleEnvironment env, const CompileArgs& args,
                            Metadata* maybeAsmJSMetadata = nullptr);
 
     const ModuleEnvironment& env() const { return *env_; }
@@ -116,20 +119,16 @@ class MOZ_STACK_CLASS ModuleGenerator
     uint32_t numSigs() const { return numSigs_; }
     const SigWithId& sig(uint32_t sigIndex) const;
     const SigWithId& funcSig(uint32_t funcIndex) const;
     const SigWithIdPtrVector& funcSigs() const { return env_->funcSigs; }
 
     // Globals:
     const GlobalDescVector& globals() const { return env_->globals; }
 
-    // Functions declarations:
-    uint32_t numFuncImports() const;
-    uint32_t numFuncDefs() const;
-
     // Function definitions:
     MOZ_MUST_USE bool startFuncDefs();
     MOZ_MUST_USE bool startFuncDef(uint32_t lineOrBytecode, FunctionGenerator* fg);
     MOZ_MUST_USE bool finishFuncDef(uint32_t funcIndex, FunctionGenerator* fg);
     MOZ_MUST_USE bool finishFuncDefs();
 
     // asm.js lazy initialization:
     void initSig(uint32_t sigIndex, Sig&& sig);