Skip to content

pretyping: reject vector shifts with conflicting sign prefix and suffix - #1532

Open
MavenRain wants to merge 1 commit into
jasmin-lang:mainfrom
MavenRain:1441-vector-shift-sign-consistency
Open

pretyping: reject vector shifts with conflicting sign prefix and suffix#1532
MavenRain wants to merge 1 commit into
jasmin-lang:mainfrom
MavenRain:1441-vector-shift-sign-consistency

Conversation

@MavenRain

Copy link
Copy Markdown

Description

The scalar shift >>s32u is rejected with invalid operator >>s 32u. The vector form >>s4u32 was accepted. The compiler ignored the s prefix and used only the sign in the suffix. It emitted a logical (unsigned) shift for an operator that asks for an arithmetic (signed) shift.

This change adds the same consistency check to the vector path. The CVS arm of op_info in compiler/src/pretyping.ml now compares the prefix sign with the sign in the vector suffix. If they conflict, the type checker rejects the program with the same invalid operator error as the scalar path. If they agree, or if there is no prefix, the behavior does not change. Only >> (ShR) is affected. All other operators either take no sign prefix or reject vector suffixes before this point.

Notes on scope:

  • >>s4s32 and >>u4u64 (agreeing signs) stay accepted. This matches the scalar rule, where >>s32s is accepted. Two such lines are added to the positive test compiler/tests/success/x86-64/vector_expression.jazz to pin this.
  • @eponier proposed a stricter option in the issue: "In my opinion, we could even purely reject such syntax, even when both signs agree." That variant is a small change to the same guard. I can switch this PR to it if you prefer. No file in this repository uses a sign prefix together with a vector suffix, so both options are compatible with the existing code and tests.

Tests: a new negative test compiler/tests/fail/typing/x86-64/vector_shift_sign_mismatch.jazz checks that >>s4u32 is rejected, with its expected diagnostic in compiler/tests/negative.expected.

Fixes #1441

Checklist

  • Add a changelog entry in changes if the PR is a user-visible change
  • Add one or several tests to compiler/tests if it makes sense, especially if it is a bug fix
  • Update the documentation if needed
  • Add your name to AUTHORS

I used Claude to help prepare this change. I reviewed and tested it.

The scalar path rejects `>>s32u` with "invalid operator >>s 32u". The
vector path accepted `>>s4u32` and silently used the suffix sign,
emitting a logical shift where the prefix asks for an arithmetic one.
Apply the same consistency check in the CVS arm of op_info. Agreeing
signs (e.g. `>>s8s32`) stay accepted, matching the scalar rule.

Fixes jasmin-lang#1441

Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
@MavenRain
MavenRain force-pushed the 1441-vector-shift-sign-consistency branch from d808bc2 to e7fd960 Compare August 8, 2026 15:19

@vbgl vbgl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution. I’ve left a minor comment about your implementation.

Comment thread compiler/src/pretyping.ml
| CVS(vs,sg,ve) ->
let s1 = tt_sign sg in
let s =
Option.map_default

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using map here looks strange. Using Option.may might be clearer.

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.

Inconsistent signedness check for vectorized shift operators

2 participants