From 59f2c1749f77c1ef30aa0db3802a8b77df1037fd Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Thu, 16 May 2013 12:46:47 -0700 Subject: [PATCH] Fewer varEnvs in generators If the original function has a variable that the generator does not, we create a varenv. Its not clear that that should ever happen, but it *was* happening because: - closures get a magic variable called 0Closure, but generators from closures did not. - unused parameters didnt get put into the variable table, so generators with unused parameters got a varenv --- hphp/compiler/analysis/emitter.cpp | 14 ++++++++------ hphp/compiler/statement/method_statement.cpp | 7 +++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/hphp/compiler/analysis/emitter.cpp b/hphp/compiler/analysis/emitter.cpp index ba26abf2f..bd36c9620 100644 --- a/hphp/compiler/analysis/emitter.cpp +++ b/hphp/compiler/analysis/emitter.cpp @@ -5319,15 +5319,17 @@ void EmitterVisitor::emitPostponedMeths() { m_curFunc = fe; - if (fe->isClosureBody()) { + if (fe->isClosureBody() || fe->isGeneratorFromClosure()) { // We are going to keep the closure as the first local fe->allocVarId(StringData::GetStaticString("0Closure")); - ClosureUseVarVec* useVars = p.m_closureUseVars; - for (auto& useVar : *useVars) { - // These are all locals. I want them right after the params so I don't - // have to keep track of which one goes where at runtime. - fe->allocVarId(useVar.first); + if (fe->isClosureBody()) { + ClosureUseVarVec* useVars = p.m_closureUseVars; + for (auto& useVar : *useVars) { + // These are all locals. I want them right after the params so I don't + // have to keep track of which one goes where at runtime. + fe->allocVarId(useVar.first); + } } } diff --git a/hphp/compiler/statement/method_statement.cpp b/hphp/compiler/statement/method_statement.cpp index b3acb31e0..8510fe7ec 100644 --- a/hphp/compiler/statement/method_statement.cpp +++ b/hphp/compiler/statement/method_statement.cpp @@ -14,8 +14,6 @@ +----------------------------------------------------------------------+ */ -#include "hphp/runtime/base/complex_types.h" - #include "hphp/compiler/statement/method_statement.h" #include "hphp/compiler/statement/return_statement.h" #include "hphp/compiler/statement/statement_list.h" @@ -47,6 +45,8 @@ #include "hphp/compiler/builtin_symbols.h" #include "hphp/compiler/analysis/alias_manager.h" +#include "hphp/runtime/base/complex_types.h" + #include "hphp/util/parser/parser.h" #include "hphp/util/util.h" @@ -389,8 +389,7 @@ void MethodStatement::analyzeProgram(AnalysisResultPtr ar) { if (ExpressionListPtr params = orig->getParams()) { for (int i = 0; i < params->getCount(); ++i) { auto param = dynamic_pointer_cast((*params)[i]); - Symbol *gp = variables->addDeclaredSymbol( - param->getName(), ConstructPtr()); + Symbol *gp = variables->addDeclaredSymbol(param->getName(), param); gp->setGeneratorParameter(); if (param->isRef()) { gp->setRefGeneratorParameter();