feat: pass type-valued records across compile-time procedures

This commit is contained in:
2026-10-28 02:38:58 +01:00
parent ae5314462a
commit 440ef93a23
5 changed files with 431 additions and 88 deletions
+28
View File
@@ -228,6 +228,29 @@ recompiles_specialized_calls_without_borrowing_previous_ir test {
` if (original.child != i8 or original.counts[1] != 0) return bool
` return struct { values [config.counts[1]]config.child, bias i16 = config.bias }
`}
`BoundaryConfig :: struct { child type, counts [2]mut usize, bias i16 = 2 }
`record_config proc() BoundaryConfig { return { child = i16, counts = [1, 2] } }
`change_record_config proc(input BoundaryConfig) BoundaryConfig {
` copied := input
` copied.child = u8
` copied.counts[1] = 3
` return copied
`}
`RecordBoundary proc(input BoundaryConfig) type {
` changed :: change_record_config(input)
` if (input.child != i16 or input.counts[1] != 2) return bool
` if (changed.child != u8 or changed.counts[1] != 3) return bool
` return struct { values [input.counts[1]]input.child, bias i16 = input.bias }
`}
`RecordAlias :: alias RecordBoundary(record_config())
`read_record_config proc($input BoundaryConfig, value input.child) input.child {
` return value + input.bias
`}
`record_pair proc() struct { type, usize } { return {i16, 2} }
`RecordPairElement proc(input struct { type, usize }) type { return field!(input, "0") }
`read_record_pair proc($input struct { type, usize }, value RecordPairElement(input)) RecordPairElement(input) {
` return value + i16(field!(input, "1"))
`}
`read_selected proc($choice Choice, value i16) i16 {
` match choice {
` .payload |detail|: {
@@ -280,6 +303,11 @@ recompiles_specialized_calls_without_borrowing_previous_ir test {
` type_record TypeRecord() :: { values = [19, 21] }
` same_type_record TypeRecord() :: type_record
` if (same_type_record.values[0] + same_type_record.values[1] + same_type_record.bias != 42) return 0
` record_boundary RecordAlias :: { values = [19, 21] }
` same_record_boundary RecordBoundary({ child = i16, counts = [1, 2] }) :: record_boundary
` if (same_record_boundary.values[0] + same_record_boundary.values[1] + same_record_boundary.bias != 42) return 0
` if (read_record_config(record_config(), 40) != 42) return 0
` if (read_record_pair(record_pair(), 40) != 42 or read_record_pair(record_pair(), 40) != 42) return 0
` copied_initialized = same_initialized.second
` payload :: packet.choices[0].payload
` if (payload.values[0] != 40 or payload.values[1] != 2 or payload.text.len != 2) return 0