Add dedicated 'Pair' typed and untyped expression

Before this commit, we would parse 'Pair' as a user-defined
  data-types, and thus piggybacking on that whole record system. While
  perhaps handy for some things, it's also semantically wrong and
  induces a lot more complexity in codegen which now needs to
  systematically distinguish every data-type access between pairs, and
  others.

  So it's better to have it as a separate expression, and handle it
  similar to tuples (since it's fundamentally a 2-tuple with a special
  serialization).
This commit is contained in:
KtorZ
2024-04-18 17:18:57 +02:00
committed by Kasey
parent 390bccd406
commit 2cb2c7fa1f
13 changed files with 235 additions and 22 deletions

View File

@@ -9,7 +9,7 @@ Schema {
Var {
tipo: RefCell {
value: Generic {
id: 33,
id: 37,
},
},
alias: None,

View File

@@ -0,0 +1,53 @@
---
source: crates/aiken-project/src/export.rs
assertion_line: 154
description: "Code:\n\npub type Foo<a> {\n Empty\n Bar(a, Foo<a>)\n}\n\npub fn add(a: Foo<Int>, b: Foo<Int>) -> Int {\n when (a, b) is {\n (Empty, Empty) -> 0\n (Bar(x, y), Bar(c, d)) -> x + c + add(y, d)\n (Empty, Bar(c, d)) -> c + add(Empty, d)\n (Bar(x, y), Empty) -> x + add(y, Empty)\n }\n}\n"
---
{
"name": "test_module.add",
"parameters": [
{
"title": "a",
"schema": {
"$ref": "#/definitions/test_module~1Foo$Int"
}
},
{
"title": "b",
"schema": {
"$ref": "#/definitions/test_module~1Foo$Int"
}
}
],
"compiledCode": "5901d501000032323232323222323232323253330083002300937540062a666010600460126ea801052000001001132323232533300b3004300c375400c2646464a66601c600e601e6ea80284c8cdc019b80003375a60260026600c0046026602800260206ea8028010c044c048008dd6980800098069baa006001132533300b3005300c375400c2a666016600860186ea801c4c8cdc01bad3010001330034c103d879800030103011001300d375400e00200226466e00dd698078009980118079808000a60103d8798000300c375400a600200244464646464a66601e601260206ea800854ccc03cc024c040dd50018a4000002002264a66601e601060206ea80084c8c8c94ccc048c02cc04cdd500309919b80337000066eb4c05c004ccc02c02c008c05cc060004c050dd5003002180a980b0011bad301400130113754004002264a66601e601260206ea800854ccc03cc020c040dd500189919b80375a6028002666010010980103d8798000301430150013011375400600200226466e00dd698098009998038039809980a000a60103d8798000301037540026022004602060220026601c0046601c00297ae0370e90011b8748000c024008c020c024004cc018008cc0180052f5c0ae6955ceaab9e5740ae855d101",
"hash": "dca86b6e092019b67ef310ba8360682d7bf8284cc728c6b525fb0b0d",
"definitions": {
"Int": {
"dataType": "integer"
},
"test_module/Foo$Int": {
"title": "Foo",
"anyOf": [
{
"title": "Empty",
"dataType": "constructor",
"index": 0,
"fields": []
},
{
"title": "Bar",
"dataType": "constructor",
"index": 1,
"fields": [
{
"$ref": "#/definitions/Int"
},
{
"$ref": "#/definitions/test_module~1Foo$Int"
}
]
}
]
}
}
}