arai-a / smoosh-sync

Automation to make jsparagus and SpiderMonkey bytecode in sync
2 stars 0 forks source link

/js/src/frontend/CompilationStencil.h and one more file have been updated (77899a08) #335

Open github-actions[bot] opened 1 year ago

github-actions[bot] commented 1 year ago

Files

Changesets

Diffs

/js/src/frontend/CompilationStencil.h

--- 4237dd5e43b924921005426e13c0d55e7b436c83/js/src/frontend/CompilationStencil.h
+++ 77899a08642e9af8d4b7bd62e33f794b87923051/js/src/frontend/CompilationStencil.h
@@ -626,16 +626,35 @@ struct CompilationAtomCache {

   void trace(JSTracer* trc);

   size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const {
     return atoms_.sizeOfExcludingThis(mallocSizeOf);
   }
 };

+// Information associated with an extra binding provided to a global script.
+// See frontend::CompileGlobalScriptWithExtraBindings.
+struct ExtraBindingInfo {
+  // UTF-8 encoded name of the binding.
+  UniqueChars nameChars;
+
+  TaggedParserAtomIndex nameIndex;
+
+  // If the binding conflicts with global variable or global lexical variable,
+  // the binding is shadowed.
+  bool isShadowed = false;
+
+  ExtraBindingInfo(UniqueChars&& nameChars, bool isShadowed)
+      : nameChars(std::move(nameChars)), isShadowed(isShadowed) {}
+};
+
+using ExtraBindingInfoVector =
+    js::Vector<ExtraBindingInfo, 0, js::SystemAllocPolicy>;
+
 // Input of the compilation, including source and enclosing context.
 struct CompilationInput {
   enum class CompilationTarget {
     Global,
     SelfHosting,
     StandaloneFunction,
     StandaloneFunctionInNonSyntacticScope,
     Eval,
@@ -646,16 +665,19 @@ struct CompilationInput {

   const JS::ReadOnlyCompileOptions& options;

   CompilationAtomCache atomCache;

  private:
   InputScript lazy_ = InputScript(nullptr);

+  // Extra bindings for the global script.
+  ExtraBindingInfoVector* maybeExtraBindings_ = nullptr;
+
  public:
   RefPtr<ScriptSource> source;

   //  * If the target is Global, null.
   //  * If the target is SelfHosting, null. Instantiation code for self-hosting
   //    will ignore this and use the appropriate empty global scope instead.
   //  * If the target is StandaloneFunction, an empty global scope.
   //  * If the target is StandaloneFunctionInNonSyntacticScope, the non-null
@@ -674,16 +696,24 @@ struct CompilationInput {
   bool initScriptSource(FrontendContext* fc);

  public:
   bool initForGlobal(FrontendContext* fc) {
     target = CompilationTarget::Global;
     return initScriptSource(fc);
   }

+  bool initForGlobalWithExtraBindings(
+      FrontendContext* fc, ExtraBindingInfoVector* maybeExtraBindings) {
+    MOZ_ASSERT(maybeExtraBindings);
+    target = CompilationTarget::Global;
+    maybeExtraBindings_ = maybeExtraBindings;
+    return initScriptSource(fc);
+  }
+
   bool initForSelfHostingGlobal(FrontendContext* fc) {
     target = CompilationTarget::SelfHosting;
     return initScriptSource(fc);
   }

   bool initForStandaloneFunction(JSContext* cx, FrontendContext* fc) {
     target = CompilationTarget::StandaloneFunction;
     if (!initScriptSource(fc)) {
@@ -786,16 +816,23 @@ struct CompilationInput {
   // Whether this CompilationInput is parsing the top-level of a script, or
   // false if we are parsing an inner function.
   bool isInitialStencil() { return lazy_.isNull(); }

   // Whether this CompilationInput is parsing a specific function with already
   // pre-parsed contextual information.
   bool isDelazifying() { return target == CompilationTarget::Delazification; }

+  bool hasExtraBindings() const { return !!maybeExtraBindings_; }
+  ExtraBindingInfoVector& extraBindings() { return *maybeExtraBindings_; }
+  const ExtraBindingInfoVector& extraBindings() const {
+    return *maybeExtraBindings_;
+  }
+  bool internExtraBindings(FrontendContext* fc, ParserAtomsTable& parserAtoms);
+
   void trace(JSTracer* trc);

   // Size of dynamic data. Note that GC data is counted by GC and not here. We
   // also ignore ScriptSource which is a shared RefPtr.
   size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const {
     return atomCache.sizeOfExcludingThis(mallocSizeOf);
   }
   size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const {

/js/src/frontend/Stencil.cpp

--- 4237dd5e43b924921005426e13c0d55e7b436c83/js/src/frontend/Stencil.cpp
+++ 77899a08642e9af8d4b7bd62e33f794b87923051/js/src/frontend/Stencil.cpp
@@ -11,24 +11,26 @@
 #include "mozilla/Maybe.h"                  // mozilla::Maybe
 #include "mozilla/OperatorNewExtensions.h"  // mozilla::KnownNotNull
 #include "mozilla/PodOperations.h"          // mozilla::PodCopy
 #include "mozilla/RefPtr.h"                 // RefPtr
 #include "mozilla/ScopeExit.h"              // mozilla::ScopeExit
 #include "mozilla/Sprintf.h"                // SprintfLiteral

 #include <algorithm>  // std::fill
+#include <string.h>   // strlen

 #include "ds/LifoAlloc.h"               // LifoAlloc
 #include "frontend/AbstractScopePtr.h"  // ScopeIndex
 #include "frontend/BytecodeCompiler.h"  // CompileGlobalScriptToStencil, InstantiateStencils, CanLazilyParse, ParseModuleToStencil
 #include "frontend/BytecodeSection.h"   // EmitScriptThingsVector
 #include "frontend/CompilationStencil.h"  // CompilationStencil, CompilationState, ExtensibleCompilationStencil, CompilationGCOutput, CompilationStencilMerger
 #include "frontend/FrontendContext.h"
 #include "frontend/NameAnalysisTypes.h"  // EnvironmentCoordinate
+#include "frontend/ParserAtom.h"  // ParserAtom, ParserAtomIndex, TaggedParserAtomIndex, ParserAtomsTable, Length{1,2,3}StaticParserString, InstantiateMarkedAtoms, InstantiateMarkedAtomsAsPermanent, GetWellKnownAtom
 #include "frontend/ScopeBindingCache.h"  // ScopeBindingCache
 #include "frontend/SharedContext.h"
 #include "frontend/StencilXdr.h"        // XDRStencilEncoder, XDRStencilDecoder
 #include "gc/AllocKind.h"               // gc::AllocKind
 #include "gc/Tracer.h"                  // TraceNullableRoot
 #include "js/CallArgs.h"                // JSNative
 #include "js/CompileOptions.h"          // JS::DecodeOptions
 #include "js/experimental/JSStencil.h"  // JS::Stencil
@@ -1387,16 +1389,38 @@ FunctionSyntaxKind CompilationInput::fun
     return FunctionSyntaxKind::Setter;
   }
   if (functionFlags().isArrow()) {
     return FunctionSyntaxKind::Arrow;
   }
   return FunctionSyntaxKind::Statement;
 }

+bool CompilationInput::internExtraBindings(FrontendContext* fc,
+                                           ParserAtomsTable& parserAtoms) {
+  MOZ_ASSERT(hasExtraBindings());
+
+  for (auto& bindingInfo : *maybeExtraBindings_) {
+    if (bindingInfo.isShadowed) {
+      continue;
+    }
+
+    const char* chars = bindingInfo.nameChars.get();
+    auto index = parserAtoms.internUtf8(
+        fc, reinterpret_cast<const mozilla::Utf8Unit*>(chars), strlen(chars));
+    if (!index) {
+      return false;
+    }
+
+    bindingInfo.nameIndex = index;
+  }
+
+  return true;
+}
+
 void InputScope::trace(JSTracer* trc) {
   using ScopePtr = Scope*;
   if (scope_.is<ScopePtr>()) {
     ScopePtr* ptrAddr = &scope_.as<ScopePtr>();
     TraceNullableRoot(trc, ptrAddr, "compilation-input-scope");
   }
 }