Skip to content

Commit 3ee71d8

Browse files
committed
fix: Update async constructor tests for sret convention
The state machine constructor now uses sret (structure return) convention where: - First param is output pointer (__sret) - Original function params follow - Return is void (struct written via sret pointer) Update test assertions to match: - test_state_machine_constructor_generation: 2 params (sret + x), void return - test_constructor_with_multiple_parameters: Store instructions instead of InsertValue, 4 param values (sret + 3 original)
1 parent 2ff7e12 commit 3ee71d8

1 file changed

Lines changed: 13 additions & 19 deletions

File tree

crates/compiler/src/async_support.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,9 +2907,9 @@ mod tests {
29072907
);
29082908

29092909
// Verify constructor signature
2910-
assert_eq!(constructor.signature.params.len(), 1); // Original param
2911-
assert_eq!(constructor.signature.returns.len(), 1);
2912-
assert_eq!(constructor.signature.returns[0], struct_type);
2910+
// Constructor has: sret pointer (output) + original params
2911+
assert_eq!(constructor.signature.params.len(), 2); // sret + original x param
2912+
assert_eq!(constructor.signature.returns.len(), 0); // Uses sret, so void return
29132913
assert!(!constructor.signature.is_async); // Constructor is not async
29142914

29152915
// Verify it has an entry block
@@ -2919,10 +2919,10 @@ mod tests {
29192919
let entry_block = &constructor.blocks[&constructor.entry_block];
29202920
assert!(matches!(entry_block.terminator, HirTerminator::Return { .. }));
29212921

2922-
// Verify return values
2922+
// Verify return values (sret convention - void return)
29232923
match &entry_block.terminator {
29242924
HirTerminator::Return { values } => {
2925-
assert_eq!(values.len(), 1); // Should return struct instance
2925+
assert_eq!(values.len(), 0); // Void return - struct written via sret pointer
29262926
}
29272927
_ => panic!("Expected return terminator"),
29282928
}
@@ -3065,27 +3065,21 @@ mod tests {
30653065
_ => panic!("Expected struct type"),
30663066
}
30673067

3068-
// Verify constructor has InsertValue instructions
3068+
// Verify constructor uses sret convention with Store instructions
30693069
let entry_block = &constructor.blocks[&constructor.entry_block];
30703070

3071-
// Should have 4 InsertValue instructions (state + 3 params)
3072-
let insert_count = entry_block.instructions.iter()
3073-
.filter(|inst| matches!(inst, HirInstruction::InsertValue { .. }))
3071+
// Should have Store instructions for state + 3 params = 4 stores
3072+
// Plus Binary/GEP instructions for computing field pointers
3073+
let store_count = entry_block.instructions.iter()
3074+
.filter(|inst| matches!(inst, HirInstruction::Store { .. }))
30743075
.count();
3075-
assert_eq!(insert_count, 4);
3076-
3077-
// Verify the InsertValue instructions have correct indices
3078-
for (idx, inst) in entry_block.instructions.iter().enumerate() {
3079-
if let HirInstruction::InsertValue { indices, .. } = inst {
3080-
assert_eq!(indices.len(), 1);
3081-
assert_eq!(indices[0], idx as u32); // Index matches instruction order
3082-
}
3083-
}
3076+
assert_eq!(store_count, 4); // state + x + y + msg
30843077

30853078
// Verify parameters are properly referenced
3079+
// sret pointer + 3 original params = 4 parameter values
30863080
let param_values: Vec<_> = constructor.values.values()
30873081
.filter(|v| matches!(v.kind, HirValueKind::Parameter(_)))
30883082
.collect();
3089-
assert_eq!(param_values.len(), 3); // 3 parameters
3083+
assert_eq!(param_values.len(), 4); // sret + 3 original params
30903084
}
30913085
}

0 commit comments

Comments
 (0)