Skip to content

[WIP] core: Add a Not Constraint#5167

Closed
Jimmy2027 wants to merge 3 commits intoxdslproject:mainfrom
Jimmy2027:hendrik/core/not_constraint
Closed

[WIP] core: Add a Not Constraint#5167
Jimmy2027 wants to merge 3 commits intoxdslproject:mainfrom
Jimmy2027:hendrik/core/not_constraint

Conversation

@Jimmy2027
Copy link
Copy Markdown
Collaborator

wip to discuss the addition of a Not Constraint,
discussion started in #5098

wip to discuss the addition of a Not Constraint,
discussion started in xdslproject#5098
@Jimmy2027 Jimmy2027 changed the title WIP core: (Not Constraint) Add a Not Constraint WIP core: Add a Not Constraint Sep 7, 2025
Jimmy2027 added a commit to Jimmy2027/xdsl that referenced this pull request Sep 11, 2025
Add a constraint that constrains an integer to not be equal to a given value.
Might be generalized to a general "Not" constraint, see xdslproject#5167
Jimmy2027 added a commit to Jimmy2027/xdsl that referenced this pull request Sep 11, 2025
…ains an integer to not be equal to a given value. Might be generalized to a general "Not" constraint, see xdslproject#5167
Jimmy2027 added a commit to Jimmy2027/xdsl that referenced this pull request Sep 11, 2025
… constrains an integer to not be equal to a given value. Might be generalized to a general "Not" constraint, see xdslproject#5167
@superlopuh
Copy link
Copy Markdown
Member

Can you please make the CI pass? Then would be nice to chat on the Zulip about this to have a bit more of a high-bandwidth conversation. It seems like the general approach should work but would be good to have @math-fehr and @alexarice's takes.

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 12, 2025

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.66%. Comparing base (4b8bca6) to head (524874b).
⚠️ Report is 635 commits behind head on main.

Files with missing lines Patch % Lines
xdsl/irdl/constraints.py 90.90% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5167      +/-   ##
==========================================
- Coverage   86.12%   85.66%   -0.47%     
==========================================
  Files         367      367              
  Lines       51804    52217     +413     
  Branches     5900     5925      +25     
==========================================
+ Hits        44617    44730     +113     
- Misses       5763     6061     +298     
- Partials     1424     1426       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@superlopuh superlopuh added the core xDSL core (ir, textual format, ...) label Sep 12, 2025
@superlopuh superlopuh changed the title WIP core: Add a Not Constraint [WIP] core: Add a Not Constraint Sep 12, 2025
Copy link
Copy Markdown
Collaborator

@math-fehr math-fehr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good to me! I think we need that constraint, even though that can easily become a footgun if we are not careful enough

@superlopuh
Copy link
Copy Markdown
Member

Would be good to get @alexarice's tick before merging. It would be nice to have a way to avoid the backtracking. This seems related to the anyof PR, a bit of functionality we're missing is a check for whether running the constraint will modify the context.

Copy link
Copy Markdown
Collaborator

@alexarice alexarice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm generally hesitant about checks on constraints that ensure there are no variables, as I feel at least part of the motivation of this system was to eventually be fully compatible/upstream to irdl, where every constraint is a variable. I guess in irdl this could be replaced with some sort of check that the constraint only has a single use, but I still thought I'd voice my unease at this.

Comment thread xdsl/irdl/constraints.py

def __post_init__(self) -> None:
"""Validate that the inner constraint doesn't contain variables."""
if self.constraint.variables():
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the xdsl meeting. I don't believe this ensures that the constraint doesn't mention any variables, just that it doesn't guarantee solving variables.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an example Not(Not(VarConstraint("x", AnyAttr())) is allowed by this atm

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the inner constraint Not(VarConstraint("x", AnyAttr()) would throw an error no?
I'm getting this:
xdsl.utils.exceptions.PyRDLError: Not constraint cannot contain variables, but inner constraint VarConstraint(name='x', constraint=AnyAttr()) has variables: {'x'}.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it was a bad example: I think Not(AnyOf(VarConstraint("x", base(IntegerAttr)), VarConstraint("y", base(FloatAttr)))) is a concrete example.

@superlopuh
Copy link
Copy Markdown
Member

I still think we might want to merge this at some point, but let's close it for now, until we have a better conviction of when this is safe to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core xDSL core (ir, textual format, ...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants