Bug 1522075 part 1 - Simplify some module-related code. r=jonco
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 24 Jan 2019 17:35:09 +0000
changeset 515314 a2e14bfdfb0076b2bc425689873e36d5d3987ec2
parent 515312 ca8f8514f60dddc015b4a0644520cc1263479ae9
child 515315 59e188c6e83500abb433777237af9ba231901445
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1522075
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1522075 part 1 - Simplify some module-related code. r=jonco Differential Revision: https://phabricator.services.mozilla.com/D17365
js/src/builtin/ModuleObject.cpp
js/src/builtin/ModuleObject.h
js/src/jit/BaselineCompiler.cpp
js/src/jit/CodeGenerator.cpp
js/src/jit/IonBuilder.cpp
js/src/jit/MIR.h
js/src/vm/EnvironmentObject.cpp
js/src/vm/Interpreter.cpp
--- a/js/src/builtin/ModuleObject.cpp
+++ b/js/src/builtin/ModuleObject.cpp
@@ -1673,25 +1673,20 @@ JSObject* js::CallModuleResolveHook(JSCo
   if (!result->is<ModuleObject>()) {
     JS_ReportErrorASCII(cx, "Module resolve hook did not return Module object");
     return nullptr;
   }
 
   return result;
 }
 
-JSObject* js::StartDynamicModuleImport(JSContext* cx,
-                                       HandleObject referencingScriptSource,
+JSObject* js::StartDynamicModuleImport(JSContext* cx, HandleScript script,
                                        HandleValue specifierArg) {
-  RootedValue referencingPrivate(cx);
-  if (referencingScriptSource) {
-    ScriptSourceObject* sso =
-        &UncheckedUnwrap(referencingScriptSource)->as<ScriptSourceObject>();
-    referencingPrivate = sso->canonicalPrivate();
-  }
+  RootedValue referencingPrivate(cx,
+                                 script->sourceObject()->canonicalPrivate());
 
   RootedObject promiseConstructor(cx, JS::GetPromiseConstructor(cx));
   if (!promiseConstructor) {
     return nullptr;
   }
 
   RootedObject promiseObject(cx, JS::NewPromiseObject(cx, nullptr));
   if (!promiseObject) {
--- a/js/src/builtin/ModuleObject.h
+++ b/js/src/builtin/ModuleObject.h
@@ -401,18 +401,17 @@ class MOZ_STACK_CLASS ModuleBuilder {
   ArrayObject* createArray(const JS::Rooted<GCHashMap<K, V>>& map);
 };
 
 JSObject* GetOrCreateModuleMetaObject(JSContext* cx, HandleObject module);
 
 JSObject* CallModuleResolveHook(JSContext* cx, HandleValue referencingPrivate,
                                 HandleString specifier);
 
-JSObject* StartDynamicModuleImport(JSContext* cx,
-                                   HandleObject referencingScriptSource,
+JSObject* StartDynamicModuleImport(JSContext* cx, HandleScript script,
                                    HandleValue specifier);
 
 bool FinishDynamicModuleImport(JSContext* cx, HandleValue referencingPrivate,
                                HandleString specifier, HandleObject promise);
 
 }  // namespace js
 
 template <>
--- a/js/src/jit/BaselineCompiler.cpp
+++ b/js/src/jit/BaselineCompiler.cpp
@@ -891,24 +891,20 @@ bool BaselineCompiler::initEnvironmentCh
 
       masm.loadBaselineFramePtr(BaselineFrameReg, R0.scratchReg());
       pushArg(R0.scratchReg());
 
       if (!callVMNonOp(InitFunctionEnvironmentObjectsInfo, phase)) {
         return false;
       }
     }
-  } else if (handler.module()) {
-    // Modules use a pre-created scope object.
-    Register scope = R1.scratchReg();
-    masm.movePtr(ImmGCPtr(&handler.module()->initialEnvironment()), scope);
-    masm.storePtr(scope, frame.addressOfEnvironmentChain());
-  } else {
+  } else if (!handler.module()) {
     // EnvironmentChain pointer in BaselineFrame has already been initialized
-    // in prologue, but we need to check for redeclaration errors.
+    // in prologue, but we need to check for redeclaration errors in global and
+    // eval scripts.
 
     prepareVMCall();
 
     pushScriptArg();
     masm.loadPtr(frame.addressOfEnvironmentChain(), R0.scratchReg());
     pushArg(R0.scratchReg());
 
     if (!callVMNonOp(CheckGlobalOrEvalDeclarationConflictsInfo, phase)) {
@@ -5546,47 +5542,39 @@ bool BaselineCompilerCodeGen::emit_JSOP_
   return true;
 }
 
 template <>
 bool BaselineInterpreterCodeGen::emit_JSOP_IMPORTMETA() {
   MOZ_CRASH("NYI: interpreter JSOP_IMPORTMETA");
 }
 
-typedef JSObject* (*StartDynamicModuleImportFn)(JSContext*, HandleObject,
+typedef JSObject* (*StartDynamicModuleImportFn)(JSContext*, HandleScript,
                                                 HandleValue);
 static const VMFunction StartDynamicModuleImportInfo =
     FunctionInfo<StartDynamicModuleImportFn>(js::StartDynamicModuleImport,
                                              "StartDynamicModuleImport");
 
 template <typename Handler>
 bool BaselineCodeGen<Handler>::emit_JSOP_DYNAMIC_IMPORT() {
-  JSScript* script = handler.script();
-  RootedObject referencingScriptSource(cx, script->sourceObject());
-
   // Put specifier value in R0.
   frame.popRegsAndSync(1);
 
   prepareVMCall();
   pushArg(R0);
-  pushArg(ImmGCPtr(referencingScriptSource));
+  pushScriptArg();
   if (!callVM(StartDynamicModuleImportInfo)) {
     return false;
   }
 
   masm.tagValue(JSVAL_TYPE_OBJECT, ReturnReg, R0);
   frame.push(R0);
   return true;
 }
 
-template <>
-bool BaselineInterpreterCodeGen::emit_JSOP_DYNAMIC_IMPORT() {
-  MOZ_CRASH("NYI: interpreter JSOP_DYNAMIC_IMPORT");
-}
-
 bool BaselineCompiler::emitPrologue() {
 #ifdef JS_USE_LINK_REGISTER
   // Push link register from generateEnterJIT()'s BLR.
   masm.pushReturnAddress();
   masm.checkStackAlignment();
 #endif
   emitProfilerEnterFrame();
 
--- a/js/src/jit/CodeGenerator.cpp
+++ b/js/src/jit/CodeGenerator.cpp
@@ -2977,25 +2977,25 @@ static const VMFunction GetOrCreateModul
     FunctionInfo<GetOrCreateModuleMetaObjectFn>(js::GetOrCreateModuleMetaObject,
                                                 "GetOrCreateModuleMetaObject");
 
 void CodeGenerator::visitModuleMetadata(LModuleMetadata* lir) {
   pushArg(ImmPtr(lir->mir()->module()));
   callVM(GetOrCreateModuleMetaObjectInfo, lir);
 }
 
-typedef JSObject* (*StartDynamicModuleImportFn)(JSContext*, HandleObject,
+typedef JSObject* (*StartDynamicModuleImportFn)(JSContext*, HandleScript,
                                                 HandleValue);
 static const VMFunction StartDynamicModuleImportInfo =
     FunctionInfo<StartDynamicModuleImportFn>(js::StartDynamicModuleImport,
                                              "StartDynamicModuleImport");
 
 void CodeGenerator::visitDynamicImport(LDynamicImport* lir) {
   pushArg(ToValue(lir, LDynamicImport::SpecifierIndex));
-  pushArg(ImmGCPtr(lir->mir()->referencingScriptSource()));
+  pushArg(ImmGCPtr(current->mir()->info().script()));
   callVM(StartDynamicModuleImportInfo, lir);
 }
 
 typedef JSObject* (*LambdaFn)(JSContext*, HandleFunction, HandleObject);
 static const VMFunction LambdaInfo =
     FunctionInfo<LambdaFn>(js::Lambda, "Lambda");
 
 void CodeGenerator::visitLambdaForSingleton(LLambdaForSingleton* lir) {
--- a/js/src/jit/IonBuilder.cpp
+++ b/js/src/jit/IonBuilder.cpp
@@ -13546,22 +13546,19 @@ AbortReasonOr<Ok> IonBuilder::jsop_impor
 
   MModuleMetadata* meta = MModuleMetadata::New(alloc(), module);
   current->add(meta);
   current->push(meta);
   return resumeAfter(meta);
 }
 
 AbortReasonOr<Ok> IonBuilder::jsop_dynamic_import() {
-  JSObject* referencingScriptSource = script()->sourceObject();
-
   MDefinition* specifier = current->pop();
 
-  MDynamicImport* ins =
-      MDynamicImport::New(alloc(), referencingScriptSource, specifier);
+  MDynamicImport* ins = MDynamicImport::New(alloc(), specifier);
   current->add(ins);
   current->push(ins);
   return resumeAfter(ins);
 }
 
 MInstruction* IonBuilder::addConvertElementsToDoubles(MDefinition* elements) {
   MInstruction* convert = MConvertElementsToDoubles::New(alloc(), elements);
   current->add(convert);
--- a/js/src/jit/MIR.h
+++ b/js/src/jit/MIR.h
@@ -6592,35 +6592,25 @@ class MModuleMetadata : public MNullaryI
   AliasSet getAliasSet() const override { return AliasSet::None(); }
 
   bool appendRoots(MRootList& roots) const override {
     return roots.append(module_);
   }
 };
 
 class MDynamicImport : public MUnaryInstruction, public BoxInputsPolicy::Data {
-  CompilerObject referencingScriptSource_;
-
-  explicit MDynamicImport(JSObject* referencingScriptSource,
-                          MDefinition* specifier)
-      : MUnaryInstruction(classOpcode, specifier),
-        referencingScriptSource_(referencingScriptSource) {
+  explicit MDynamicImport(MDefinition* specifier)
+      : MUnaryInstruction(classOpcode, specifier) {
     setResultType(MIRType::Object);
   }
 
  public:
   INSTRUCTION_HEADER(DynamicImport)
   TRIVIAL_NEW_WRAPPERS
   NAMED_OPERANDS((0, specifier))
-
-  JSObject* referencingScriptSource() const { return referencingScriptSource_; }
-
-  bool appendRoots(MRootList& roots) const override {
-    return roots.append(referencingScriptSource_);
-  }
 };
 
 struct LambdaFunctionInfo {
   // The functions used in lambdas are the canonical original function in
   // the script, and are immutable except for delazification. Record this
   // information while still on the main thread to avoid races.
  private:
   CompilerFunction fun_;
--- a/js/src/vm/EnvironmentObject.cpp
+++ b/js/src/vm/EnvironmentObject.cpp
@@ -3613,16 +3613,18 @@ static bool CheckEvalDeclarationConflict
   }
 
   return true;
 }
 
 bool js::CheckGlobalOrEvalDeclarationConflicts(JSContext* cx,
                                                HandleObject envChain,
                                                HandleScript script) {
+  MOZ_ASSERT(script->isGlobalCode() || script->isForEval());
+
   RootedObject varObj(cx, &GetVariablesObject(envChain));
 
   if (script->isForEval()) {
     // Strict eval and eval in parameter default expressions have their
     // own call objects.
     //
     // Non-strict eval may introduce 'var' bindings that conflict with
     // lexical bindings in an enclosing lexical scope.
--- a/js/src/vm/Interpreter.cpp
+++ b/js/src/vm/Interpreter.cpp
@@ -4247,24 +4247,20 @@ static MOZ_NEVER_INLINE JS_HAZ_JSNATIVE_
         goto error;
       }
 
       PUSH_OBJECT(*metaObject);
     }
     END_CASE(JSOP_IMPORTMETA)
 
     CASE(JSOP_DYNAMIC_IMPORT) {
-      ReservedRooted<JSObject*> referencingScriptSource(&rootObject0);
-      referencingScriptSource = script->sourceObject();
-
       ReservedRooted<Value> specifier(&rootValue1);
       POP_COPY_TO(specifier);
 
-      JSObject* promise =
-          StartDynamicModuleImport(cx, referencingScriptSource, specifier);
+      JSObject* promise = StartDynamicModuleImport(cx, script, specifier);
       if (!promise) goto error;
 
       PUSH_OBJECT(*promise);
     }
     END_CASE(JSOP_DYNAMIC_IMPORT)
 
     CASE(JSOP_ENVCALLEE) {
       uint8_t numHops = GET_UINT8(REGS.pc);