This is an archive of the discontinued LLVM Phabricator instance.

[mlir][ods] Support default-valued attributes in optional groups

Authored by rkayaith on Sep 30 2022, 2:48 PM.



Add support for default-valued attributes as optional-group anchors. The
attribute is considered present if it holds a non-default value.

Diff Detail

Event Timeline

rkayaith created this revision.Sep 30 2022, 2:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 30 2022, 2:48 PM
rkayaith added inline comments.Sep 30 2022, 6:24 PM

I didn't really understand the existing logic, it seemed odd to me to parse as optional under Normal context, but not under Optional context, but maybe I'm misunderstanding what "context" means here. I switched the use of GenContext so that genContext == Optional whenever the attribute should be optionally parsed (currently this is only for the first element of the then group).

rkayaith published this revision for review.Sep 30 2022, 6:24 PM
rkayaith added reviewers: rriddle, Mogball.
Mogball added inline comments.Oct 1 2022, 9:39 AM

GenContext::Optional means the element is inside an optional group, not whether the element should be optionally parsed.

rkayaith added inline comments.Oct 1 2022, 12:20 PM

I see, is there supposed to be a difference to how things are parsed in optional groups (other than the first element)? The only place I see genCtx used is this line, and it seems like it's allowing optional attributes to be optionally parsed when outside an optional group, but that just ends up breaking in the printer:

Mogball added inline comments.Oct 13 2022, 7:01 PM

Not really. Only that certain elements are prohibited in optional groups (e.g. nested optional groups). The issue you linked just looks like a bug to me. I think the feature you are adding is useful but I'd prefer not to fiddle with the gen context

rkayaith updated this revision to Diff 467872.Oct 14 2022, 11:56 AM

preserve genCtx logic

Mogball accepted this revision.Oct 14 2022, 11:58 AM
Mogball added inline comments.

there's a DefaultValuedStrAttr that lets you drop the quotes

This revision is now accepted and ready to land.Oct 14 2022, 11:58 AM
rkayaith added inline comments.Oct 14 2022, 12:00 PM

on main genCtx ends up being ignored on this path, should this be parseAsOptional instead?

and similarly for the isOptional() check inside genEnumAttrParser


ok, updated the diff and tried to preserve existing genCtx logic

rkayaith updated this revision to Diff 467936.Oct 14 2022, 2:57 PM

fix default-valued symbol and enum attrs, use DefaultValuedStrAttr


i switched these over to use parseAsOptional; otherwise default-valued symbols and enums break