Skip to content

Make non-optional attribute parsers error on unset fields #2806

@GleasonK

Description

@GleasonK

What happened?

Some non-optional attributes have default values implemented in the parser (example), this makes for nonsense errors at verification time instead of parse time:

$ cat /tmp/t.mlir
func.func @gather(%arg0: tensor<3x4x2xf32>, %arg1: tensor<2x3x2xi64>) -> tensor<2x3x2x2xf32> {
  %0 = "stablehlo.gather"(%arg0, %arg1) {
    dimension_numbers = #stablehlo.gather<
      offset_dims = [2, 3],
      collapsed_slice_dims = [0],
      start_index_map = [1, 0],
      // index_vector_dim = 2
    >,
    slice_sizes = array<i64: 1, 2, 2>,
    indices_are_sorted = false
  } : (tensor<3x4x2xf32>, tensor<2x3x2xi64>) -> tensor<2x3x2x2xf32>
  return %0 : tensor<2x3x2x2xf32>
}

$ stablehlo-opt /tmp/t.mlir 
/tmp/t.mlir:2:8: error: 'stablehlo.gather' op inferred type(s) 'tensor<3x2x2x2xf32>' are incompatible with return type(s) of operation 'tensor<2x3x2x2xf32>'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions