{"record":{"id":"2c775d09c3bcb66e","repo":"jax-ml/jax","slug":"unsupported-constant-type-x-type","errorCode":null,"errorMessage":"Unsupported constant type: {x.type}","messagePattern":"Unsupported constant type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic/lowering.py","lineNumber":3494,"sourceCode":"class FoldingError(Exception):\n  pass\n\n\ndef _fold(x, fuel):\n  if fuel <= 0:\n    raise FoldingError()\n  op_name = getattr(x.owner, \"name\", None)\n  binop_folds = {\n      \"arith.maxsi\": max,\n      \"arith.minsi\": min,\n  }\n  if op_name == \"arith.constant\":\n    if isinstance(x.type, ir.IntegerType):\n      return ir.IntegerAttr(x.owner.attributes[\"value\"]).value\n    elif isinstance(x.type, ir.FloatType):\n      return ir.FloatAttr(x.owner.attributes[\"value\"]).value\n    else:\n      raise ValueError(f\"Unsupported constant type: {x.type}\")\n  if op_name in binop_folds:\n    return binop_folds[op_name](_fold(v, fuel - 1) for v in x.owner.operands)\n  raise FoldingError()\n\n\ndef _fold_and_get_constant_value(x):\n  try:\n    return _fold(x, 10)\n  except FoldingError:\n    return None\n\n\n@register_lowering_rule(lax.stop_gradient_p)\ndef _stop_gradient_lowering_rule(_: LoweringRuleContext, x):\n  return x\n\n@register_lowering_rule(\n    lax.max_p, ensure_mlir_values=False, kernel_types=[*tpu_core.CoreType]","sourceCodeStart":3476,"sourceCodeEnd":3512,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic/lowering.py#L3476-L3512","documentation":"The Mosaic constant-folding helper only understands arith.constant ops with IntegerType or FloatType results. A constant of any other MLIR type (bool/i1 handled elsewhere, complex, etc.) raises ValueError when the folder tries to extract its value.","triggerScenarios":"Constant folding encountering an arith.constant with a non-integer/non-float MLIR type while lowering a Pallas kernel, typically triggered indirectly by an operation whose operands fold to unusual constants.","commonSituations":"Kernels with boolean constants feeding into arithmetic; complex or index-type constants; version skew between JAX and jaxlib where new constant types appear in the pipeline.","solutions":["Update jaxlib to match your JAX version — this is often an internal version-mismatch bug","Simplify the kernel to avoid constants of exotic types reaching the folder (materialize them as kernel inputs)","Replace bool constants with int32 0/1","Report upstream at github.com/google/jax with a minimal repro"],"exampleFix":"// before\nflag = True  # traced bool constant used in arithmetic\n// after\nflag = jnp.int32(1)  # passed as kernel argument","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch ValueError from constant folding, simplify kernel constants, and retry; report if persistent","preventionTips":["Keep jax and jaxlib versions in lockstep","Avoid exotic-typed constants in kernels","Materialize unusual constants as kernel inputs"],"tags":["jax","pallas","mlir","constant-folding","internal"],"backgroundTag":"mlir-lowering-internal-error","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}