Skip to content

[spec] Fix instr sequence typing rules to actually be composable#2197

Merged
rossberg merged 2 commits into
mainfrom
fix.2194
Jun 23, 2026
Merged

[spec] Fix instr sequence typing rules to actually be composable#2197
rossberg merged 2 commits into
mainfrom
fix.2194

Conversation

@rossberg

Copy link
Copy Markdown
Member

Fixes #2194.

@raoxiaojia, PTAL.


rule Instrs_ok/instr:
C |- instr : t_1* -> t_2*
-- Instr_ok: C |- instr : t_1* -> t_2*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, I am amazed that this can be correctly parsed by the backends, as at first glance it really looks like a self-referential rule; but actually it says instr_ok C instr : t1* -> ts2* constructs instrs_ok C [instr].

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well, the frontend does the resolution. There is nothing specific to do in the after elaboration.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Then I'll praise the frontend to have handled this cleanly!

C |- instr_1 instr_2* : t_1* -> t_3*
-- Instr_ok: C |- instr_1 : t_1* -> t_2*
C |- instr_1* instr_2* : t_1* -> t_3*
-- Instrs_ok: C |- instr_1* : t_1* -> t_2*

@raoxiaojia raoxiaojia Jun 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, this formulation will allow derivations of arbitrary lengths now, since either instruction list can be empty. I thought it would be better to preserve the original cons form of the rule and leave the general list append as a lemma (not too difficult to prove). Or did I overlook anything here?

Same for the 2.0/3.0 changes below.

@raoxiaojia

raoxiaojia commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Just a quick check regarding instrs_ok/seq -- is it deliberate that we want to allow arbitrary list concatenations (instead of the original 'cons' style of forward composition in the previous versions)?

@rossberg rossberg left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, it's deliberate. It's more symmetric and a better separation of concerns this way. In particular, I prefer if there is only one rule that injects from Instr_ok into Instrs_ok.

Arbitrarily long derivations are already possible without this change, since you can always throw in another redundant application of the subsumption (with it = it') or frame (with t* = eps) rule. Likewise, there generally are multiple choices where you can invoke these rules when they're necessary, so a unique shortest derivation also already doesn't exist. So I don't think this formulation loses anything relevant.


rule Instrs_ok/instr:
C |- instr : t_1* -> t_2*
-- Instr_ok: C |- instr : t_1* -> t_2*

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well, the frontend does the resolution. There is nothing specific to do in the after elaboration.

@raoxiaojia

raoxiaojia commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Thanks for the clarification! In fact, that actually makes the proofs easier, but I just want to make sure that I'm not granted a simplification by accident. the other parts already look good to me as well!

Upd: actually, it's probably about equal, because forward composition is free but inversion is slightly harder (and actually a bit more than slightly harder for 3.0 due to instruction types carrying the additional local flags).

@rossberg rossberg merged commit bd4633a into main Jun 23, 2026
10 checks passed
@rossberg rossberg deleted the fix.2194 branch June 23, 2026 21:25
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.

[spec] instrs_ok/seq's principality requirement is slightly over-restrictive

2 participants