[Mlir-commits] [mlir] [mlir-python] Fix duplicate EnumAttr builder registration across dialects. (PR #187191)

Maksim Levental llvmlistbot at llvm.org
Wed Mar 18 23:31:28 PDT 2026


================
@@ -94,7 +99,11 @@ static bool emitAttributeBuilder(const EnumInfo &enumInfo, raw_ostream &os) {
     return false;
 
   int64_t bitwidth = enumInfo.getBitwidth();
-  os << formatv("@register_attribute_builder(\"{0}\")\n",
+  // These builders may be emitted by multiple dialect enum_gen files when
+  // dialects share enum definitions via .td includes. Use allow_existing=True
+  // so that the first loaded dialect registers the builder and subsequent
+  // loads silently skip (first-registration wins).
----------------
makslevental wrote:

There are really only two choices here (and neither along the axis of "permissiveness) - first one wins (sticks) or last one wins (replaces anything possibly registered prior). But both have to be maximally permissive (ie win silently) because these registrations are "configured" at TD/generation time (there's no way for a user to intervene).

We do an environment variable type thing but I think it's too much - this should only be happening for upstream EnumInfos which no one should be themselves shadowing (so no reason to override). And anyway the docs say we recommend EnumAttr (which can disambiguated by dialect) over EnumInfo. 

https://github.com/llvm/llvm-project/pull/187191


More information about the Mlir-commits mailing list