{"record":{"id":"e82f9b646e06629f","repo":"jax-ml/jax","slug":"barrier-can-only-be-indexed-with-integers-or-slice","errorCode":null,"errorMessage":"Barrier can only be indexed with integers or slices, got {idx}","messagePattern":"Barrier can only be indexed with integers or slices, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic_gpu/primitives.py","lineNumber":1504,"sourceCode":"        for i, (idx, stride) in enumerate(zip(indexer.indices, strides[:])):\n          if isinstance(idx, indexing.Slice):\n            if idx.stride != 1:\n              raise NotImplementedError(\n                  \"Barrier does not support slice with `stride != 1`\"\n              )\n            idx = idx.start\n          else:\n            # This dimension is absent for any corresponding `NDIndexer`s, so\n            # we remove the corresponding stride.\n            strides.pop(i - num_int_idxs)\n            num_int_idxs += 1\n\n          if isinstance(\n              idx, (int, ir.Value, mgpu.FragmentedArray, literals.TypedNdArray)\n          ):\n            idx = lowering._as_index(idx)  # pylint: disable=protected-access\n          else:\n            raise ValueError(\n                \"Barrier can only be indexed with integers or slices, got\"\n                f\" {idx}\"\n            )\n\n          idx = arith_dialect.muli(idx, lowering._as_index(stride))  # pylint: disable=protected-access\n          if base_index is None:\n            base_index = idx\n          else:\n            base_index = arith_dialect.addi(base_index, idx)\n      case _:\n        raise ValueError(\"Barrier does not support arbitrary transforms\")\n  return base_index\n\n\nbarrier_arrive_p = jax_core.Primitive(\"barrier_arrive\")\nbarrier_arrive_p.multiple_results = True\n\n","sourceCodeStart":1486,"sourceCodeEnd":1522,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic_gpu/primitives.py#L1486-L1522","documentation":"Barrier address computation only accepts integer-like indices (Python int, MLIR ir.Value, FragmentedArray, TypedNdArray) or slices. Any other index type (e.g. a float, a tuple, or an unrecognized object) is rejected with this ValueError.","triggerScenarios":"Indexing a barrier ref with an unsupported type, e.g. barrier[1.0], barrier[(0, 1)], or a custom indexer object.","commonSituations":"Passing a numpy scalar or non-integer loop variable as a barrier index; typos producing nested tuples in multi-dimensional indexing.","solutions":["Convert the index to an int (e.g. int(i) or i.item()) before indexing the barrier.","Check the index expression for accidental tuple/float values; barriers are 1D and take a single integer or slice."],"exampleFix":"# before\nbarriers[np.float32(i)].arrive()\n# after\nbarriers[int(i)].arrive()","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def is_valid_barrier_index(idx):\n    return idx is None or isinstance(idx, (int, slice)) or hasattr(idx, 'type')  # ir.Value / FragmentedArray","tryCatchPattern":null,"preventionTips":["Coerce indices with int(...) before indexing barriers.","Keep barrier indexing 1D and integer-based."],"tags":["mosaic-gpu","pallas","barrier","indexing","type-error"],"backgroundTag":"invalid-index-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}