Skip to content

check annotated operand types in generated builders - #847

Open
JonhasA wants to merge 5 commits into
rustfrom
jc/rs-ssa-val-check
Open

JonhasA wants to merge 5 commits into
rustfrom
jc/rs-ssa-val-check

Conversation

@JonhasA

@JonhasA JonhasA commented Nov 10, 2026 •

Copy link
Copy Markdown

I was doing something like the following:

#[derive(Clone, Debug, PartialEq, Dialect, HasParser, PrettyPrint)]
#[kirin(builders, type = TypeSys::<CodeType>)]
#[chumsky(format = "$TransversalH(code_block={code_block}):{block_type} -> {result:type}")]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TransversalH {
    pub block_type: CodeType,
    #[kirin(type=TypeSys::Scalar(block_type))]
    pub code_block: SSAValue,

    #[kirin(type=TypeSys::Scalar(block_type))]
    pub result: ResultValue,
}

and I noticed that for the argument operands, in this case,

#[kirin(type=TypeSys::Scalar(block_type))]
pub code_block: SSAValue, 

did not have any type verification being done, compared to pub result: ResultValue, which did.

We had that #[kirin(type = ...)] was accepted on SSAValue operand fields but ignored. This is because the expr was stored and never emitted. This patch enforces that generated builders now enforce it, ie., we panic if an annotated operand's type is known and differs from the annotation. Unannotated operands and operands whose type is not yet set (such as graph-port placeholders) are skipped.

Note that this only applies to generated stage builders. Parsed IR and direct statement construction still require a separate verification pass.

@Roger-luo

Copy link
Copy Markdown
Collaborator

How does this interact with type inference? e.g., when you mark certain type as unknown and waiting for inference?

This branch has not been deployed

No deployments
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.

2 participants