MikePopoloski / slang

SystemVerilog compiler and language services
MIT License
558 stars 122 forks source link

uninstantiated generic classes should not include an invalid specialization in the AST #996

Closed tdp2110 closed 1 month ago

tdp2110 commented 1 month ago

Describe the bug Consider test.sv:

class foo # (type T);
endclass

module top;
endmodule

./bin/slang test.sv --ast-json test.json produces

{
  "design": {
    "name": "$root",
    "kind": "Root",
    "addr": 6583145610400,
    "members": [
      {
        "name": "",
        "kind": "CompilationUnit",
        "addr": 6583146894560,
        "members": [
          {
            "name": "foo",
            "kind": "GenericClassDef",
            "addr": 6583146874256,
            "specializations": [
              {
                "name": "foo",
                "kind": "ClassType",
                "addr": 6583146895168,
                "members": [
                  {
                    "name": "T",
                    "kind": "TypeParameter",
                    "addr": 6583146895416,
                    "type": "<error>",
                    "isLocal": false,
                    "isPort": true,
                    "isBody": false
                  }
                ],
                "isAbstract": false,
                "isInterface": false,
                "isFinal": false,
                "genericClass": "6583146874256 foo",
                "implements": [
                ]
              }
            ]
          }
        ]
      },
      {
        "name": "top",
        "kind": "Instance",
        "addr": 6583146895040,
        "body": {
          "name": "top",
          "kind": "InstanceBody",
          "addr": 6583146894856,
          "definition": "6583145479168 top"
        },
        "connections": [
        ]
      }
    ]
  },
  "definitions": [
    {
      "name": "top",
      "kind": "Definition",
      "addr": 6583145479168,
      "defaultNetType": "6583145608160 wire",
      "definitionKind": "Module",
      "defaultLifetime": "Static",
      "unconnectedDrive": "None"
    }
  ]
}

Notice specializations of the generic class contains one member, which has an invalid type parameter. These are created, on purpose, for diagnostic purposes (see https://github.com/MikePopoloski/slang/blob/master/source/ast/ElabVisitors.h#L447-L454), but they probably shouldn't persist in the AST. Am I wrong?

To Reproduce

See above commands.

Additional context Thanks, you rock.

MikePopoloski commented 1 month ago

Yeah, probably the invalid specialization should not be added to the specialization map. Or at the very least it can be filtered out during serialization.

MikePopoloski commented 1 month ago

Fixed in ff952d50165efb354988a7df629e14ae964a787a