Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: c5f66f3853e95d0451861daf7b2f9887b109ad6b
      
https://github.com/WebKit/WebKit/commit/c5f66f3853e95d0451861daf7b2f9887b109ad6b
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-10-15 (Thu, 15 Oct 2026)

  Changed paths:
    A JSTests/stress/private-name-register-reuse.js
    M Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
    M Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
    M Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
    M Source/JavaScriptCore/parser/Nodes.h
    M Source/JavaScriptCore/parser/Parser.cpp
    M Source/JavaScriptCore/parser/Parser.h

  Log Message:
  -----------
  [JSC] Load each private name once in straight-line bytecode
https://bugs.webkit.org/show_bug.cgi?id=326801

Reviewed by Yusuke Suzuki.

Every private field access loads the private name symbol from the class
scope with resolve_scope and get_from_scope, so `this.#x * other.#x`
loads the same symbol twice.

This patch keeps a loaded private name in a register and reuses it until
a label is emitted, since code after a label can be reached without
passing the load. The registers are reserved when BytecodeGenerator is
constructed, so they sit below the temporaries used by expressions and
are neither interleaved with the operands of new_array or strcat nor
overwritten by a callee frame. To know how many to reserve, the parser
counts the private names used by the function. At most 16 registers are
reserved, and further names are loaded into a temporary as before.

The loaded names are also dropped when a class with private names is
entered or left, since it may declare the same name.
m_seenPrivateNameUseInNonReparsingFunctionMode is renamed to
m_seenPrivateNameUse because it is now also read while reparsing a
function.

Test: JSTests/stress/private-name-register-reuse.js

* JSTests/stress/private-name-register-reuse.js: Added.
(shouldBe):
(join):
(Point):
(Point.count):
(Point.sub):
(Point.prototype.method):
(Point.prototype.get accessor):
(Point.prototype.dot):
(Point.prototype.array):
(Point.prototype.template):
(Point.prototype.concat):
(Point.prototype.call):
(Point.prototype.nestedCall):
(Point.prototype.acrossCall):
(Point.prototype.spread):
(Point.prototype.construct):
(Point.prototype.conditional):
(Point.prototype.branch):
(Point.prototype.logical):
(Point.prototype.optional):
(Point.prototype.loop):
(Point.prototype.labeled):
(Point.prototype.select):
(Point.prototype.tryCatch):
(Point.prototype.tryFinally):
(Point.prototype.has):
(Point.prototype.write):
(Point.prototype.swap):
(Point.prototype.mixed):
(Point.prototype.generator):
(Point.prototype.async asynchronous):
(Point.prototype.arrow):
(Point.prototype.defaultParameter):
(Point.prototype.evaluate):
(Point.prototype.shadow.try.Inner):
(Point.prototype.shadow):
(Many.prototype.sum):
(Many.prototype.array):
(Many):
(testStraightLine):
(testCalls):
(testControlFlow):
(i.p.asynchronous.then):
* Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:
(JSC::GenericLabel<JSGeneratorTraits>::setLocation):
(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::emitLoadPrivateName):
(JSC::BytecodeGenerator::pushPrivateAccessNames):
(JSC::BytecodeGenerator::popPrivateAccessNames):
* Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h:
(JSC::BytecodeGenerator::invalidateLoadedPrivateNames):
* Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:
(JSC::BaseDotNode::emitGetPropertyValue):
(JSC::BaseDotNode::emitPutProperty):
(JSC::PostfixNode::emitDot):
(JSC::PrefixNode::emitDot):
(JSC::InNode::emitBytecode):
(JSC::DefineFieldNode::emitBytecode):
* Source/JavaScriptCore/parser/Nodes.h:
(JSC::ScopeNode::usedPrivateNameCount const):
(JSC::ScopeNode::setUsedPrivateNameCount):
* Source/JavaScriptCore/parser/Parser.cpp:
(JSC::Parser<LexerType>::parseInner):
(JSC::Parser<LexerType>::parseBinaryExpression):
(JSC::Parser<LexerType>::parseMemberExpression):
* Source/JavaScriptCore/parser/Parser.h:
(JSC::Parser<LexerType>::parse):

Canonical link: https://commits.webkit.org/323815@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to