Skip to content

Commit

Permalink
update JSON representation of TransformKind
Browse files Browse the repository at this point in the history
Summary:
This diff changes the JSON representation of `TransformKind` from a string to a
JSON object that spearates the global / local transforms as well as the base
kind, which makes parsing easier.

The new JSON object has the following format:

```
{
  "base" : <base_kind_str>,
  "global" : <global_transformation_str>,
  "local" : <local_transformation_str>
}
```
as a reference, the old string-based format is:
```
<local_transformation_str>@<global_transformation_str>:<base_kind_str>
```

The reason we still use strings rather than JSON arrays for global and local
transformations is that the MT integration tests tend to sort the JSON arrays
and break the order of transforms.

Reviewed By: yuhshin-oss

Differential Revision: D57931089

fbshipit-source-id: 90ebc5f475da0b6aec933eb23f6f4d0cb5bf1ffa
  • Loading branch information
jinghao-jia authored and facebook-github-bot committed May 31, 2024
1 parent f7045a0 commit 7d60fbd
Show file tree
Hide file tree
Showing 2 changed files with 413 additions and 4 deletions.
18 changes: 16 additions & 2 deletions sapp/pipeline/mariana_trench_parser_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@
UNKNOWN_LINE: int = -1


def _parse_kind_name(kind: Union[str, Dict[str, Any]]) -> str:
if type(kind) is str:
return kind
# Parse the name in case this is a TransformKind
name = ""
if local_transform := kind.get("local"):
name += f"{local_transform}@"
if global_transform := kind.get("global"):
name += f"{global_transform}:"
name += kind["base"]

return name


class Method(NamedTuple):
name: str

Expand Down Expand Up @@ -268,7 +282,7 @@ def from_json(
) -> "ExtraTrace":
frame_type = extra_trace["frame_type"]
return ExtraTrace(
kind=extra_trace["kind"],
kind=_parse_kind_name(extra_trace["kind"]),
callee=CallInfo.from_json(
extra_trace["call_info"], frame_type, caller_position
),
Expand Down Expand Up @@ -349,7 +363,7 @@ def from_json(
for extra_trace in kind.get("extra_traces", []):
extra_traces.append(ExtraTrace.from_json(extra_trace, caller_position))
return Kind(
name=kind["kind"],
name=_parse_kind_name(kind["kind"]),
distance=kind.get("distance", 0),
origins=origins,
extra_traces=extra_traces,
Expand Down
Loading

0 comments on commit 7d60fbd

Please sign in to comment.