Skip to content

frontend: Marco match reaches typechecker #1044

Description

@BadGraphixD

Running the following two specs yields two different results. The first is parsed just fine, but the second produces an exception. Notice that the two specs are identical, except for the naming of the macro arguments. In the first, in the two models the parameter is named w, and in the second, the naming differs.

instruction set architecture Test = {

  constant C = 0
  record Wrapper (id : Id)
  model Match (w : Wrapper) : IsaDefs = {
    match : IsaDefs (
      $w.id = C => constant A = C;
      _ => constant A = C
    )
  }
  model M (w : Wrapper) : IsaDefs = { $Match($w) }
  $M((C))

}

yields the following expanded-macros.vadl:

instruction set architecture Test = {
  constant C = 0
  constant A = C
}

And the spec causing a crash:

instruction set architecture Test = {

  constant C = 0
  record Wrapper (id : Id)
  model Match (x : Wrapper) : IsaDefs = {
    match : IsaDefs (
      $x.id = C => constant A = C;
      _ => constant A = C
    )
  }
  model M (w : Wrapper) : IsaDefs = { $Match($w) }
  $M((C))

}

yields the following expanded-macros.vadl and exception:

instruction set architecture Test = {
  constant C = 0
  match : IsaDefs(
    $x.id = C =>     constant A = C
 ;
  _ =>     constant A = C
 )
}

                             ___ ___    _   ___ _  _
                            / __| _ \  /_\ / __| || |
                           | (__|   / / _ \\__ \ __ |
                            \___|_|_\/_/ \_\___/_||_|

                       🔥 The OpenVADL compiler crashed 🔥

This shouldn't have happened, please open an issue with the stacktrace below at:
https://github.com/OpenVADL/open-vadl/issues/new


Before the crash, the following dumps were generated:
        - output/dump/expanded-macros.vadl

java.lang.IllegalStateException: No macro match definition should ever reach the Typechecker
        at vadl.ast.TypeChecker.foreignNodeException(TypeChecker.java:556)
        at vadl.ast.TypeChecker.visit(TypeChecker.java:2154)
        at vadl.ast.TypeChecker.visit(TypeChecker.java:204)
        at vadl.ast.nodes.MacroMatchDefinition.accept(MacroMatchDefinition.java:35)
        at vadl.ast.TypeChecker.check(TypeChecker.java:445)
        at vadl.ast.TypeChecker.visit(TypeChecker.java:1560)
        at vadl.ast.TypeChecker.visit(TypeChecker.java:204)
        at vadl.ast.nodes.InstructionSetDefinition.accept(InstructionSetDefinition.java:98)
        at vadl.ast.TypeChecker.check(TypeChecker.java:445)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
        at vadl.ast.TypeChecker.lambda$verify$0(TypeChecker.java:470)
        at vadl.ast.InterleavedTimingRecorder.withPassTiming(InterleavedTimingRecorder.java:146)
        at vadl.ast.Ast.withPassTiming(Ast.java:54)
        at vadl.ast.TypeChecker.verify(TypeChecker.java:468)
        at vadl.cli.BaseCommand.parseToVIAM(BaseCommand.java:275)
        at vadl.cli.BaseCommand.call(BaseCommand.java:403)
        at vadl.cli.BaseCommand.call(BaseCommand.java:69)
        at picocli.CommandLine.executeUserObject(CommandLine.java:2045)
        at picocli.CommandLine.access$1500(CommandLine.java:148)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2465)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2457)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2419)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2277)
        at picocli.CommandLine$RunLast.execute(CommandLine.java:2421)
        at picocli.CommandLine.execute(CommandLine.java:2174)
        at vadl.cli.Main.main(Main.java:45)

Both have been run using openvadl check --expand-macros spec.vadl on version master-SNAPSHOT commit d0677e71e (2026-07-19 13:18).

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfrontendThis is frontend related

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions