Skip to content

Commit cda4125

Browse files
Sinan Cepelfacebook-github-bot
authored andcommitted
remove now-redundant originalFilename field from HHBBC's function representations
Summary: The duplication of `originalFilename` and `originalUnit` were introduced in D6770083 to support the flattening of traits in HHBBC. A later diff, D6770160, removed the trait flattening code from hphpc, but we never appear to have cleaned up the originalFilename field. This change makes it so we only keep `originalUnit` around, and renames `FuncEmitter`'s originalFilename to originalUnit for consistency. As the asserts demonstrate, this saves 8 bytes from the `php::Func` structs in both low-pointer mode and regular-sized pointer modes in HHBBC. The `originalUnit` field had to be aligned above Attr where we were wasting some padding to realize the gain in lowptr mode. Reviewed By: ricklavoie Differential Revision: D73373868 fbshipit-source-id: 78c630124ed53b55c29b58bd49f5fdcbaace9990
1 parent 7779110 commit cda4125

20 files changed

+56
-61
lines changed

hphp/hhbbc/emit.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,7 @@ void emit_finish_func(EmitUnitState& state, FuncEmitter& fe,
972972
fe.userAttributes = func.userAttributes;
973973
fe.retUserType = func.returnUserType;
974974
fe.retTypeConstraints = func.retTypeConstraints;
975-
fe.originalFilename =
976-
func.originalFilename ? func.originalFilename :
975+
fe.originalUnit =
977976
func.originalUnit ? func.originalUnit : nullptr;
978977
fe.originalModuleName = func.originalModuleName;
979978
fe.requiresFromOriginalModule = func.requiresFromOriginalModule;

hphp/hhbbc/index.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const StaticString s_Traversable("HH\\Traversable");
117117
static_assert(CheckSize<php::Block, 24>(), "");
118118
static_assert(CheckSize<php::Local, use_lowptr ? 12 : 16>(), "");
119119
static_assert(CheckSize<php::Param, use_lowptr ? 56: 88>(), "");
120-
static_assert(CheckSize<php::Func, use_lowptr ? 176: 224>(), "");
120+
static_assert(CheckSize<php::Func, use_lowptr ? 168: 216>(), "");
121121

122122
// Likewise, we also keep the bytecode and immediate types small.
123123
static_assert(CheckSize<Bytecode, use_lowptr ? 32 : 40>(), "");
@@ -11050,7 +11050,6 @@ struct FlattenJob {
1105011050
auto meth = std::move(clone->methods[i]);
1105111051
meth->cls = clone.get();
1105211052
assertx(meth->clsIdx == i);
11053-
if (!meth->originalFilename) meth->originalFilename = meth->unit;
1105411053
if (!meth->originalUnit) meth->originalUnit = meth->unit;
1105511054
if (!meth->originalClass) meth->originalClass = closure.name;
1105611055
meth->requiresFromOriginalModule = requiresFromOriginalModule;
@@ -11135,7 +11134,6 @@ struct FlattenJob {
1113511134
cloned->cls = const_cast<php::Class*>(&dstCls);
1113611135
cloned->unit = dstCls.unit;
1113711136

11138-
if (!cloned->originalFilename) cloned->originalFilename = orig.unit;
1113911137
if (!cloned->originalUnit) cloned->originalUnit = orig.unit;
1114011138
cloned->originalClass = orig.originalClass
1114111139
? orig.originalClass

hphp/hhbbc/interp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,8 @@ void in(ISS& env, const bc::File&) {
10201020
return push(env, TSStr);
10211021
}
10221022

1023-
auto filename = env.ctx.func->originalFilename
1024-
? env.ctx.func->originalFilename
1023+
auto filename = env.ctx.func->originalUnit
1024+
? env.ctx.func->originalUnit
10251025
: env.ctx.func->unit;
10261026
if (!FileUtil::isAbsolutePath(filename->slice())) {
10271027
filename = makeStaticString(
@@ -1038,8 +1038,8 @@ void in(ISS& env, const bc::Dir&) {
10381038
return push(env, TSStr);
10391039
}
10401040

1041-
auto filename = env.ctx.func->originalFilename
1042-
? env.ctx.func->originalFilename
1041+
auto filename = env.ctx.func->originalUnit
1042+
? env.ctx.func->originalUnit
10431043
: env.ctx.func->unit;
10441044
if (!FileUtil::isAbsolutePath(filename->slice())) {
10451045
filename = makeStaticString(

hphp/hhbbc/parse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ std::unique_ptr<php::Func> parse_func(ParseUnitState& puState,
686686
ret->userAttributes = fe.userAttributes;
687687
ret->returnUserType = fe.retUserType.ptr(ue);
688688
ret->retTypeConstraints = fe.retTypeConstraints;
689-
ret->originalFilename = fe.originalFilename;
689+
ret->originalUnit = fe.originalUnit;
690690
ret->originalModuleName = unit->moduleName;
691691

692692
ret->isClosureBody = fe.isClosureBody;

hphp/hhbbc/representation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ template <typename SerDe> void Func::serde(SerDe& sd, Class* parentClass) {
100100
(numIters)
101101
(mainEntry)
102102
(returnUserType)
103-
(originalFilename)
104103
(originalUnit)
105104
(originalClass)
106105
(originalModuleName)

hphp/hhbbc/representation.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,16 @@ struct Func : FuncBase {
303303
*/
304304
LSString name;
305305
SrcInfo srcInfo;
306+
307+
308+
/*
309+
* If hhbbc flattens a trait, we keep the original filename of the file
310+
* that defined the trait in originalUnit to get to the srcLocs. This
311+
* ensures that backtraces and whatnot work correctly. Otherwise this is
312+
* nullptr. This field lives above `attrs` for alignment reasons.
313+
*/
314+
LSString originalUnit{};
315+
306316
Attr attrs;
307317

308318
/*
@@ -348,17 +358,6 @@ struct Func : FuncBase {
348358
*/
349359
LSString returnUserType;
350360

351-
/*
352-
* If traits are being flattened by hphpc, we keep the original
353-
* filename of a function (the file that defined the trait) so
354-
* backtraces and things work correctly. Otherwise this is nullptr.
355-
* Similarly, if hhbbc did the flattening itself, we need the original
356-
* unit, to get to the srcLocs. Once we stop flattening in hphpc, we can
357-
* drop the originalFilename.
358-
*/
359-
LSString originalFilename;
360-
LSString originalUnit{};
361-
362361
/*
363362
* The reference of the trait where the method was originally
364363
* defined. This is used to detected if a method is imported

hphp/runtime/base/backtrace.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,8 @@ Array createBacktrace(const BacktraceArgs& btArgs) {
440440
// Builtins and generators don't have a file and line number.
441441
if (prev && !prev.func()->isBuiltin()) {
442442
auto const prevFunc = prev.func();
443-
auto const prevFile = prevFunc->originalFilename()
444-
? prevFunc->originalFilename()
443+
auto const prevFile = prevFunc->originalUnit()
444+
? prevFunc->originalUnit()
445445
: prevFunc->unit()->filepath();
446446

447447
assertx(prevFile != nullptr);
@@ -684,8 +684,8 @@ Array CompactTraceData::extract() const {
684684
auto const prevFunc = prev->func;
685685
auto const prevUnit = prevFunc->unit();
686686
auto prevFile = prevUnit->filepath();
687-
if (prevFunc->originalFilename()) {
688-
prevFile = prevFunc->originalFilename();
687+
if (prevFunc->originalUnit()) {
688+
prevFile = prevFunc->originalUnit();
689689
}
690690

691691
auto const prevPc = prev->prevPc;

hphp/runtime/base/execution-context.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,8 +1225,8 @@ StringData* ExecutionContext::getContainingFileName() {
12251225
if (ar->skipFrame()) ar = getPrevVMStateSkipFrame(ar);
12261226
if (ar == nullptr) return staticEmptyString();
12271227
Unit* unit = ar->func()->unit();
1228-
auto const path = ar->func()->originalFilename() ?
1229-
ar->func()->originalFilename() : unit->filepath();
1228+
auto const path = ar->func()->originalUnit() ?
1229+
ar->func()->originalUnit() : unit->filepath();
12301230
return const_cast<StringData*>(path);
12311231
}
12321232

hphp/runtime/ext/asio/ext_async-function-wait-handle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ void c_AsyncFunctionWaitHandle::exitContext(ContextIndex contextIdx) {
384384

385385
// Get the filename in which execution will proceed when execution resumes.
386386
String c_AsyncFunctionWaitHandle::getFilename() {
387-
if (actRec()->func()->originalFilename()) {
388-
return actRec()->func()->originalFilename()->data();
387+
if (actRec()->func()->originalUnit()) {
388+
return actRec()->func()->originalUnit()->data();
389389
} else {
390390
return actRec()->func()->unit()->filepath()->data();
391391
}

hphp/runtime/ext/std/ext_std_errorfunc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ bool hphp_debug_caller_info_impl(
104104
RuntimeStruct::registerRuntimeStruct(s_hphp_debug_caller_info, s_fields);
105105

106106
auto const cls = func->cls();
107-
auto const path = func->originalFilename() ?
108-
func->originalFilename() : func->unit()->filepath();
107+
auto const path = func->originalUnit() ?
108+
func->originalUnit() : func->unit()->filepath();
109109

110110
auto const has_cls = cls && !func->isClosureBody();
111111
StructDictInit init(s_struct, has_cls ? 4 : 3);

0 commit comments

Comments
 (0)