Skip to content

feat(parser): support signed and unsigned integer types - #1414

Merged
tobiasgrosser merged 9 commits into
opencompl:mainfrom
sueszli:issue/1352-signedness
Sep 27, 2026
Merged

tobiasgrosser merged 9 commits into
opencompl:mainfrom
sueszli:issue/1352-signedness

Conversation

@sueszli

@sueszli sueszli commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1352.

MLIR integer types carry signedness: i32 (signless), si32 (signed), ui32 (unsigned). Veir only supported i32.

"test.op"() <{attr = 42 : si32}> : () -> ()
"test.op"() <{attr = 7 : ui16}> : () -> ()

Adds a Signedness field to IntegerType defaulting to .signless, so all existing code compiles without change beyond updating constructor call sites.

@math-fehr math-fehr left a comment

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.

I'll review this once you fix the failing CI, but otherwise the design makes sense to me so far!

@sueszli

sueszli commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Awesome tysm

@sueszli
sueszli force-pushed the issue/1352-signedness branch from c726ed1 to a59eee9 Compare September 9, 2026 14:22
@math-fehr

Copy link
Copy Markdown
Collaborator

Just let me know when you want me to re-review this!

@sueszli
sueszli force-pushed the issue/1352-signedness branch from a59eee9 to 809c90d Compare September 14, 2026 19:46
@sueszli

sueszli commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Okidokes just rebased - Would really appreicate your review @math-fehr

@math-fehr math-fehr left a comment

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.

Nice! Just had 1-2 comments, but otherwise all good!

Comment thread UnitTest/AttrParser.lean Outdated

#assert expectSuccessType "i32" (IntegerType.mk 32)
#assert expectSuccessType "i0" (IntegerType.mk 0)
#assert expectSuccessType "i32" ({ bitwidth := 32 } : IntegerType)

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.

Can you change this to IntegerType.signless 32? And similarly in other places?
And can you add IntegerType.signed and IntegerType.unsigned as well as constructors?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes that makes a lot more sense, thank you!

Did I get this right in fad0651

Comment thread Veir/Dialects/LLVM/OpInfo.lean Outdated
match resultType with
| .llvmArrayType arrType =>
if arrType.type ≠ .integerType ⟨8⟩ then
if arrType.type ≠ .integerType ⟨8, .signless⟩ then

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.

Here for instance we could have IntegerType.signless 8 instead of this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Quick patch: d00aa01

Comment thread Veir/Parser/AttrParser.lean Outdated
if slice.size < 2 then
return none
if (← (getThe ParserState)).input.getD slice.start.byteOffset 0 == 'i'.toUInt8 then
let input := (← (getThe ParserState)).input

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.

Here, can you instead use slice.of ((← getThe ParserState).input) to get a ByteArray, and then just check equality with "si".toByteArray and so-on. That should make the code simpler I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah this made it a lot simpler. Thank you! Yes way simpler.

0dd139d

@math-fehr

Copy link
Copy Markdown
Collaborator

Oh also, a lot of the verifiers are not incorrect, since they now allow unsigned and signed integers, while they should not.
Can you modify OperationPtr.checkIsNonNullIntegerType to only accept signless integers?

@sueszli
sueszli force-pushed the issue/1352-signedness branch from 809c90d to 9bfbf25 Compare September 16, 2026 21:11
@sueszli

sueszli commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Done in c9f5099 with some new regression tests

@sueszli
sueszli force-pushed the issue/1352-signedness branch 2 times, most recently from e6d9670 to a1a20e7 Compare September 17, 2026 12:58
@math-fehr

Copy link
Copy Markdown
Collaborator

Arg sorry, all good now, but I forgot about this and now there is a merge conflict. Could you rebase it on main and fix the merge conflicts? Otherwise I can do this on your branch if you want, sorry about that!

@sueszli
sueszli force-pushed the issue/1352-signedness branch from a1a20e7 to 60c287c Compare September 24, 2026 08:13
@sueszli

sueszli commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

No worries and thank you very much! @math-fehr

@tobiasgrosser tobiasgrosser left a comment

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.

Very cool!

@sueszli

sueszli commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing @tobiasgrosser @math-fehr

@tobiasgrosser

Copy link
Copy Markdown
Collaborator

Is this ready to merge?

sueszli and others added 9 commits September 27, 2026 09:26
Replace `{ bitwidth := n }` with `IntegerType.signless n` throughout,
and add `IntegerType.signed` and `IntegerType.unsigned` constructors.
…ntegerType

Only signless integers are valid operand and result types for the operations
that apply this check, matching MLIR's signless-fixed-width-integer-like
constraint.
- Use `IntegerType.signless` in unit tests added upstream.
- Print `true`/`false` only for signless `i1`, as MLIR does.
- Normalize integer attribute values of unsigned types into the unsigned
  range, so `255 : ui8` round-trips.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tobiasgrosser

Copy link
Copy Markdown
Collaborator

I rebased this and merge this now.

@tobiasgrosser
tobiasgrosser added this pull request to the merge queue Sep 27, 2026
Merged via the queue into opencompl:main with commit 301f8c8 Sep 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Builtin integer types have no signedness

3 participants