Skip to content

Commit

Permalink
Remove operator== from synth trace records
Browse files Browse the repository at this point in the history
Summary:
Maintaining operator== for every record is error prone and requires a
lot of boilerplate. Given that this is only used for tests, change the
tests so they rely on just a JSON comparison of records, and delete
operator== from all records.

Reviewed By: ftanuma

Differential Revision: D57399341

fbshipit-source-id: a83b85acdaba7e209c4e53f9fb23a8afc6876afc
  • Loading branch information
neildhar authored and facebook-github-bot committed May 16, 2024
1 parent 02ddbb1 commit 8a27222
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 421 deletions.
255 changes: 0 additions & 255 deletions API/hermes/SynthTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,261 +299,6 @@ void SynthTrace::Record::toJSON(JSONEmitter &json) const {
json.closeDict();
}

bool SynthTrace::MarkerRecord::operator==(const Record &that) const {
return Record::operator==(that) &&
tag_ == dynamic_cast<const MarkerRecord &>(that).tag_;
}

bool SynthTrace::ReturnMixin::operator==(const ReturnMixin &that) const {
return retVal_ == that.retVal_;
}

bool SynthTrace::BeginExecJSRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
const auto &thatCasted = dynamic_cast<const BeginExecJSRecord &>(that);
return sourceURL_ == thatCasted.sourceURL_ &&
sourceHash_ == thatCasted.sourceHash_ &&
sourceIsBytecode_ == thatCasted.sourceIsBytecode_;
}

bool SynthTrace::EndExecJSRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
const auto &thatCasted = dynamic_cast<const EndExecJSRecord &>(that);
return MarkerRecord::operator==(thatCasted) &&
ReturnMixin::operator==(thatCasted);
}

bool SynthTrace::CreateObjectRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
const auto &thatCasted = dynamic_cast<const CreateObjectRecord &>(that);
return objID_ == thatCasted.objID_;
}

bool SynthTrace::QueueMicrotaskRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
const auto &thatCasted = dynamic_cast<const QueueMicrotaskRecord &>(that);
return callbackID_ == thatCasted.callbackID_;
}

bool SynthTrace::DrainMicrotasksRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
const auto &thatCasted = dynamic_cast<const DrainMicrotasksRecord &>(that);
return maxMicrotasksHint_ == thatCasted.maxMicrotasksHint_;
}

bool SynthTrace::CreateBigIntRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
auto &thatCasted = dynamic_cast<const CreateBigIntRecord &>(that);
return objID_ == thatCasted.objID_ && method_ == thatCasted.method_ &&
bits_ == thatCasted.bits_;
}

bool SynthTrace::BigIntToStringRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
auto &thatCasted = dynamic_cast<const BigIntToStringRecord &>(that);
return strID_ == thatCasted.strID_ && bigintID_ == thatCasted.bigintID_ &&
radix_ == thatCasted.radix_;
}

bool SynthTrace::CreateStringRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
auto &thatCasted = dynamic_cast<const CreateStringRecord &>(that);
return objID_ == thatCasted.objID_ && ascii_ == thatCasted.ascii_ &&
chars_ == thatCasted.chars_;
}

bool SynthTrace::CreatePropNameIDRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
auto &thatCasted = dynamic_cast<const CreatePropNameIDRecord &>(that);
return propNameID_ == thatCasted.propNameID_ &&
valueType_ == thatCasted.valueType_ &&
traceValue_ == thatCasted.traceValue_ && chars_ == thatCasted.chars_;
}

bool SynthTrace::CreateHostFunctionRecord::operator==(
const Record &that) const {
if (!CreateObjectRecord::operator==(that)) {
return false;
}
const auto &thatCasted = dynamic_cast<const CreateHostFunctionRecord &>(that);
if (!(propNameID_ == thatCasted.propNameID_ &&
paramCount_ == thatCasted.paramCount_)) {
return false;
}
#ifdef HERMESVM_API_TRACE_DEBUG
assert(functionName_ == thatCasted.functionName_);
#endif
return true;
}

bool SynthTrace::GetOrSetPropertyRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
const auto &thatCasted = dynamic_cast<const GetOrSetPropertyRecord &>(that);
if (!(objID_ == thatCasted.objID_ && propID_ == thatCasted.propID_ &&
value_ == thatCasted.value_)) {
return false;
}
#ifdef HERMESVM_API_TRACE_DEBUG
assert(propNameDbg_ == thatCasted.propNameDbg_);
#endif
return true;
}

bool SynthTrace::HasPropertyRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
const auto &thatCasted = dynamic_cast<const HasPropertyRecord &>(that);
return objID_ == thatCasted.objID_ && propID_ == thatCasted.propID_;
}

bool SynthTrace::GetPropertyNamesRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
const auto &thatCasted = dynamic_cast<const GetPropertyNamesRecord &>(that);
return objID_ == thatCasted.objID_ && propNamesID_ == thatCasted.propNamesID_;
}

bool SynthTrace::CreateArrayRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
const auto &thatCasted = dynamic_cast<const CreateArrayRecord &>(that);
return objID_ == thatCasted.objID_ && length_ == thatCasted.length_;
}

bool SynthTrace::ArrayReadOrWriteRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
const auto &thatCasted = dynamic_cast<const ArrayReadOrWriteRecord &>(that);
return objID_ == thatCasted.objID_ && index_ == thatCasted.index_ &&
value_ == thatCasted.value_;
}

bool SynthTrace::CallRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
const auto &thatCasted = dynamic_cast<const CallRecord &>(that);
return functionID_ == thatCasted.functionID_ &&
std::equal(
args_.begin(),
args_.end(),
thatCasted.args_.begin(),
[](TraceValue x, TraceValue y) { return x == y; });
}

bool SynthTrace::ReturnFromNativeRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
return ReturnMixin::operator==(
dynamic_cast<const ReturnFromNativeRecord &>(that));
}

bool SynthTrace::ReturnToNativeRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
return ReturnMixin::operator==(dynamic_cast<const ReturnMixin &>(that));
}

bool SynthTrace::GetOrSetPropertyNativeRecord::operator==(
const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
auto thatCasted = dynamic_cast<const GetOrSetPropertyNativeRecord *>(&that);
return hostObjectID_ == thatCasted->hostObjectID_ &&
propNameID_ == thatCasted->propNameID_ &&
propName_ == thatCasted->propName_;
}

bool SynthTrace::GetPropertyNativeRecord::operator==(const Record &that) const {
return GetOrSetPropertyNativeRecord::operator==(that);
}

bool SynthTrace::GetPropertyNativeReturnRecord::operator==(
const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
auto thatCasted = dynamic_cast<const GetPropertyNativeReturnRecord &>(that);
return ReturnMixin::operator==(thatCasted);
}

bool SynthTrace::SetPropertyNativeRecord::operator==(const Record &that) const {
return GetOrSetPropertyNativeRecord::operator==(that) &&
value_ == dynamic_cast<const SetPropertyNativeRecord &>(that).value_;
}

bool SynthTrace::GetNativePropertyNamesRecord::operator==(
const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
auto &thatCasted = dynamic_cast<const GetNativePropertyNamesRecord &>(that);
return hostObjectID_ == thatCasted.hostObjectID_;
}

bool SynthTrace::GetNativePropertyNamesReturnRecord::operator==(
const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
auto &thatCasted =
dynamic_cast<const GetNativePropertyNamesReturnRecord &>(that);
return propNameIDs_ == thatCasted.propNameIDs_;
}

bool SynthTrace::SetExternalMemoryPressureRecord::operator==(
const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
auto &thatCasted =
dynamic_cast<const SetExternalMemoryPressureRecord &>(that);
return objID_ == thatCasted.objID_ && amount_ == thatCasted.amount_;
}

bool SynthTrace::Utf8Record::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
auto &thatCasted = dynamic_cast<const Utf8Record &>(that);
return objID_ == thatCasted.objID_ && retVal_ == thatCasted.retVal_;
}

bool SynthTrace::GlobalRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
auto &thatCasted = dynamic_cast<const GlobalRecord &>(that);
return objID_ == thatCasted.objID_;
}

void SynthTrace::Record::toJSONInternal(JSONEmitter &json) const {
std::string storage;
llvh::raw_string_ostream os{storage};
Expand Down
Loading

0 comments on commit 8a27222

Please sign in to comment.