Bug 1565945 - Compute LazyScript::TreatAsRunOnce flag the same as JSScript. r=jandem

This has equivalent overall behavior as before, but computes the
precise LazyScript::TreatAsRunOnce flag rather than checking the extra
conditions during delazification. The heuristics can be computed using
just the LazyScript information so the result is the same.

Differential Revision: https://phabricator.services.mozilla.com/D38025

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ted Campbell 2019-07-15 12:41:39 +00:00
Родитель b4aa417b65
Коммит f0774d58e3
4 изменённых файлов: 18 добавлений и 11 удалений

Просмотреть файл

@ -998,6 +998,8 @@ static bool CompileLazyFunctionImpl(JSContext* cx, Handle<LazyScript*> lazy,
return false;
}
MOZ_ASSERT(lazy->treatAsRunOnce() == script->treatAsRunOnce());
delazificationCompletion.complete();
assertException.reset();
return true;

Просмотреть файл

@ -2219,18 +2219,14 @@ MOZ_NEVER_INLINE bool BytecodeEmitter::emitSwitch(SwitchStatement* switchStmt) {
}
bool BytecodeEmitter::isRunOnceLambda() {
// The run once lambda flags set by the parser are approximate, and we look
// at properties of the function itself before deciding to emit a function
// as a run once lambda.
if (!(parent && parent->emittingRunOnceLambda) &&
(emitterMode != LazyFunction || !lazyScript->treatAsRunOnce())) {
return false;
if (lazyScript) {
MOZ_ASSERT_IF(sc->asFunctionBox()->shouldSuppressRunOnce(),
!lazyScript->treatAsRunOnce());
return lazyScript->treatAsRunOnce();
}
FunctionBox* funbox = sc->asFunctionBox();
return !funbox->argumentsHasLocalBinding() && !funbox->isGenerator() &&
!funbox->isAsync() && !funbox->explicitName();
return parent && parent->emittingRunOnceLambda &&
!sc->asFunctionBox()->shouldSuppressRunOnce();
}
bool BytecodeEmitter::allocateResumeIndex(BytecodeOffset offset,

Просмотреть файл

@ -113,7 +113,7 @@ bool FunctionEmitter::emitLazy() {
}
funbox_->setEnclosingScopeForInnerLazyFunction(bce_->innermostScope());
if (bce_->emittingRunOnceLambda) {
if (bce_->emittingRunOnceLambda && !funbox_->shouldSuppressRunOnce()) {
fun_->lazyScript()->setTreatAsRunOnce();
}

Просмотреть файл

@ -553,6 +553,15 @@ class FunctionBox : public ObjectBox, public SharedContext {
return !strict() && hasSimpleParameterList();
}
bool shouldSuppressRunOnce() const {
// These heuristics suppress the run-once optimization if we expect that
// script-cloning will have more impact than TI type-precision would gain.
//
// See also: Bug 864218
return explicitName() || argumentsHasLocalBinding() || isGenerator() ||
isAsync();
}
// Return whether this or an enclosing function is being parsed and
// validated as asm.js. Note: if asm.js validation fails, this will be false
// while the function is being reparsed. This flag can be used to disable