Closed Bug 1654149 Opened 4 years ago Closed 4 years ago

Add testing function to dump stencil

Categories

(Core :: JavaScript Engine, task, P2)

task

Tracking

()

RESOLVED FIXED
81 Branch
Tracking Status
firefox81 --- fixed

People

(Reporter: arai, Assigned: arai)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Just like "parse", having a testing function that receives source string and dumps stencil would be nice for development.

Blocks: stencil

I have WIP patch.
I'll post it here after bug 1653248 and optionally bug 1649968

Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED
Severity: -- → N/A
Priority: -- → P2

Add dump method to stencil-related structs, that dumps the struct as JSON,
and dumpStencil() shell-builtin as a consumer.

Some structs have dumpFields method, given that JSONPrinter only provide
beginObjectProperty/endObject to print a property with an object value.

There's some design decision about when to use string-representation and when
to use object.
Currently simple single-field struct like ScopeIndex uses string-representation
like "ScopeIndex(0)", and ScriptAtom also uses string-representation.

There's an exception in ScriptAtom case in DumpScriptThing,
that we need to differentiate string and string-representation of other
structs, and for simplicity, ScriptAtom case uses object with "type" property,
and other single-field structs use string-representation.

The current dumpStencil does not dump CompilationInfo.asmJS (FIXME) and
ScriptStencil.immutableScriptData.

Most of ScriptStencil.immutableScriptData field can be dumped by dis()
function.

input:

var s = `
var x = [1, 2, 3];
var y = { a: 10, 1: 20 };
var z = [1, 1.2, 20n, true, null, undefined, /abc/g];
function f() {
  function g() {}
}
`;
dumpStencil(s);

output:

{
  "topLevel": {
    "immutableFlags": [
      "NoScriptRval",
      "TreatAsRunOnce",
      "HasInnerFunctions"
    ],
    "fieldInitializers": "Nothing",
    "gcThings": [
      "ScopeIndex(0)",
      {
        "type": "ScriptAtom",
        "value": "x"
      },
      {
        "type": "ScriptAtom",
        "value": "y"
      },
      {
        "type": "ScriptAtom",
        "value": "z"
      },
      "FunctionIndex(0)",
      {
        "type": "ObjLiteralCreationData",
        "value": {
          "writer": {
            "flags": [
              "Array"
            ],
            "code": [
              {
                "key": "ConstAtom(0)",
                "op": "ConstValue(1.000000)"
              },
              {
                "key": "ConstAtom(0)",
                "op": "ConstValue(2.000000)"
              },
              {
                "key": "ConstAtom(0)",
                "op": "ConstValue(3.000000)"
              }
            ]
          },
          "atoms": [
          ]
        }
      },
      {
        "type": "ObjLiteralCreationData",
        "value": {
          "writer": {
            "flags": [
              "SpecificGroup",
              "Singleton"
            ],
            "code": [
              {
                "key": "ConstAtom(0)",
                "op": "ConstValue(10.000000)"
              },
              {
                "key": "ArrayIndex(1)",
                "op": "ConstValue(20.000000)"
              }
            ]
          },
          "atoms": [
            "a"
          ]
        }
      },
      "BigIntIndex(0)",
      {
        "type": "ScriptAtom",
        "value": "undefined"
      },
      "RegExpIndex(0)"
    ],
    "immutableScriptData": "exists",
    "extent": {
      "sourceStart": 0,
      "sourceEnd": 135,
      "toStringStart": 0,
      "toStringEnd": 135,
      "lineno": 1,
      "column": 0
    }
  },
  "funcData": [
    {
      "immutableFlags": [
        "IsFunction",
        "HasInnerFunctions",
        "HasMappedArgsObj"
      ],
      "fieldInitializers": "Nothing",
      "gcThings": [
        "FunctionIndex(1)"
      ],
      "immutableScriptData": null,
      "extent": {
        "sourceStart": 110,
        "sourceEnd": 134,
        "toStringStart": 100,
        "toStringEnd": 134,
        "lineno": 5,
        "column": 10
      },
      "functionAtom": "f",
      "functionFlags": [
        "NORMAL_KIND",
        "BASESCRIPT",
        "CONSTRUCTOR"
      ],
      "nargs": 0,
      "lazyFunctionEnclosingScopeIndex": "Some(ScopeIndex(0))",
      "isStandaloneFunction": false,
      "wasFunctionEmitted": true,
      "isSingletonFunction": true
    },
    {
      "immutableFlags": [
        "IsFunction",
        "HasMappedArgsObj"
      ],
      "fieldInitializers": "Nothing",
      "gcThings": [
      ],
      "immutableScriptData": null,
      "extent": {
        "sourceStart": 127,
        "sourceEnd": 132,
        "toStringStart": 117,
        "toStringEnd": 132,
        "lineno": 6,
        "column": 12
      },
      "functionAtom": "g",
      "functionFlags": [
        "NORMAL_KIND",
        "BASESCRIPT",
        "CONSTRUCTOR"
      ],
      "nargs": 0,
      "lazyFunctionEnclosingScopeIndex": "Nothing",
      "isStandaloneFunction": false,
      "wasFunctionEmitted": false,
      "isSingletonFunction": false
    }
  ],
  "regExpData": [
    "/abc/g"
  ],
  "bigIntData": [
    "20"
  ],
  "scopeData": [
    {
      "enclosing": "Nothing",
      "kind": "global",
      "firstFrameSlot": 0,
      "numEnvironmentSlots": "Nothing",
      "data": {
        "letStart": 4,
        "constStart": 4,
        "trailingNames": [
          {
            "closedOver": false,
            "isTopLevelFunction": false,
            "name": "x"
          },
          {
            "closedOver": false,
            "isTopLevelFunction": false,
            "name": "y"
          },
          {
            "closedOver": false,
            "isTopLevelFunction": false,
            "name": "z"
          },
          {
            "closedOver": false,
            "isTopLevelFunction": true,
            "name": "f"
          }
        ]
      }
    }
  ]
}
Pushed by arai_a@mac.com:
https://hg.mozilla.org/integration/autoland/rev/c2583743d4eb
Add dumpStencil shell-builtin. r=tcampbell

Backed out for bustages on ObjLiteral.cpp

backout: https://hg.mozilla.org/integration/autoland/rev/786545256e8814da7899374a2165f22509c08993

push: https://treeherder.mozilla.org/#/jobs?repo=autoland&selectedTaskRun=aG4rzsXyTFWhQO8EQKDZ5w.0&revision=c2583743d4ebe36e8b152f50ee718232e23814fd&group_state=expanded

failure log: https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=312228029&repo=autoland&lineNumber=17161

[task 2020-08-06T06:49:48.084Z] 06:49:48 INFO - In file included from Unified_cpp_js_src_frontend3.cpp:47:
[task 2020-08-06T06:49:48.084Z] 06:49:48 ERROR - /builds/worker/checkouts/gecko/js/src/frontend/ObjLiteral.cpp:158:24: error: out-of-line definition of 'dump' does not match any declaration in 'js::ObjLiteralWriter'
[task 2020-08-06T06:49:48.084Z] 06:49:48 INFO - void ObjLiteralWriter::dump() {
[task 2020-08-06T06:49:48.084Z] 06:49:48 INFO - ^~~~
[task 2020-08-06T06:49:48.084Z] 06:49:48 ERROR - /builds/worker/checkouts/gecko/js/src/frontend/ObjLiteral.cpp:164:24: error: out-of-line definition of 'dump' does not match any declaration in 'js::ObjLiteralWriter'
[task 2020-08-06T06:49:48.084Z] 06:49:48 INFO - void ObjLiteralWriter::dump(js::JSONPrinter& json) {
[task 2020-08-06T06:49:48.084Z] 06:49:48 INFO - ^~~~
[task 2020-08-06T06:49:48.084Z] 06:49:48 ERROR - /builds/worker/checkouts/gecko/js/src/frontend/ObjLiteral.cpp:166:3: error: use of undeclared identifier 'dumpFields'
[task 2020-08-06T06:49:48.084Z] 06:49:48 INFO - dumpFields(json);
[task 2020-08-06T06:49:48.084Z] 06:49:48 INFO - ^
[task 2020-08-06T06:49:48.084Z] 06:49:48 ERROR - /builds/worker/checkouts/gecko/js/src/frontend/ObjLiteral.cpp:170:24: error: out-of-line definition of 'dumpFields' does not match any declaration in 'js::ObjLiteralWriter'
[task 2020-08-06T06:49:48.084Z] 06:49:48 INFO - void ObjLiteralWriter::dumpFields(js::JSONPrinter& json) {
[task 2020-08-06T06:49:48.085Z] 06:49:48 INFO - ^~~~~~~~~~
[task 2020-08-06T06:49:48.085Z] 06:49:48 ERROR - /builds/worker/checkouts/gecko/js/src/frontend/ObjLiteral.cpp:224:30: error: out-of-line definition of 'dump' does not match any declaration in 'js::ObjLiteralCreationData'
[task 2020-08-06T06:49:48.085Z] 06:49:48 INFO - void ObjLiteralCreationData::dump() {
[task 2020-08-06T06:49:48.085Z] 06:49:48 INFO - ^~~~
[task 2020-08-06T06:49:48.085Z] 06:49:48 ERROR - /builds/worker/checkouts/gecko/js/src/frontend/ObjLiteral.cpp:230:30: error: out-of-line definition of 'dump' does not match any declaration in 'js::ObjLiteralCreationData'
[task 2020-08-06T06:49:48.085Z] 06:49:48 INFO - void ObjLiteralCreationData::dump(js::JSONPrinter& json) {
[task 2020-08-06T06:49:48.085Z] 06:49:48 INFO - ^~~~

Flags: needinfo?(arai.unmht)
Pushed by arai_a@mac.com:
https://hg.mozilla.org/integration/autoland/rev/af63ceb25422
Add dumpStencil shell-builtin. r=tcampbell
Flags: needinfo?(arai.unmht)
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 81 Branch
Regressions: 1657764
Blocks: stencil-backlog
No longer blocks: stencil
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: