update tests and fix final unique issues
This commit is contained in:
parent
62963f7fc2
commit
4e0aaf970f
|
@ -16,8 +16,8 @@ description: "Code:\n\npub type Foo {\n foo: Int\n}\n\nvalidator {\n fn an
|
||||||
"$ref": "#/definitions/Data"
|
"$ref": "#/definitions/Data"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"compiledCode": "5833010000323222253330044a22930a99802a491856616c696461746f722072657475726e65642066616c736500136565734ae701",
|
"compiledCode": "58310100003222253330044a22930a99ab9c49011856616c696461746f722072657475726e65642066616c7365001365657341",
|
||||||
"hash": "52a21f2b4f282074cb6c5aefef20d18c25f3657ca348c73875810c37",
|
"hash": "089cd4ae25b73d144116d7736d915ffb18302b482f91e0c89020adbe",
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"Data": {
|
"Data": {
|
||||||
"title": "Data",
|
"title": "Data",
|
||||||
|
|
|
@ -10,8 +10,8 @@ description: "Code:\n\ntype Either<left, right> {\n Left(left)\n Right(rig
|
||||||
"$ref": "#/definitions/test_module~1Either$ByteArray_test_module~1Interval$Int"
|
"$ref": "#/definitions/test_module~1Either$ByteArray_test_module~1Interval$Int"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"compiledCode": "59018201000032323232323232323232232253330064a22930a99803a4811856616c696461746f722072657475726e65642066616c73650013656323253330063370e900000089929998058008a998040018b099299980618070010a4c2a660120082c64a66666601e0022a660120082c2a660120082c2a660120082c2a660120082c26eb8004c030004c01000c54ccc018cdc3a4004002264a6660160022a660100062c264a666018601c0042649319299980499b87480000044c94ccc03800454cc02c018584c94ccc03cc044008526153300c00716325333333012001153300c00716153300c00716153300c007161375a0022a6601800e2c601e002600e0042a66601266e1d20020011533300d3007002149854cc0280145854cc02801458c01c00454cc02401058c030004c01000c54cc01c00858c0100092412a72656465656d65723a204569746865723c4279746541727261792c20496e74657276616c3c496e743e3e00230063754002460086ea80055cd2b9c5573aaae7955cfaba15744ae901",
|
"compiledCode": "59017d0100003232323232323232232253330064a22930a99803a4811856616c696461746f722072657475726e65642066616c7365001365632325323330073001002132533300a001153300900416132533300b300d002149854cc02801458c94cccccc03800454cc0280145854cc0280145854cc0280145854cc028014584dd7000980580098028020a99919804180080189929998058008a998050028b0992999806180700109924c64a666016600a002264a66601c0022a6601a0102c264a66601e60220042930a998070048b1929999998090008a998070048b0a998070048b0a998070048b09bad001153300e00916300f00130090021533300b30040011533300d3009002149854cc03001c5854cc03001c58c02400454cc02c01858c030004c018014dc3a40042a660100062c6e1d2000300400249012a72656465656d65723a204569746865723c4279746541727261792c20496e74657276616c3c496e743e3e00235573c6ea80048d55ce9baa0015734ae7155cfaba15744ae901",
|
||||||
"hash": "9832573170b2d30efa7f52dbdc96e82948f331228573cd2a00288006",
|
"hash": "336e48e839e1def7f4de623b6fdbc755400abea87292691daab43632",
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"ByteArray": {
|
"ByteArray": {
|
||||||
"dataType": "bytes"
|
"dataType": "bytes"
|
||||||
|
|
|
@ -18,8 +18,8 @@ description: "Code:\n\nvalidator(utxo_ref: Int) {\n fn mint(redeemer: Data, ctx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"compiledCode": "583701000032322322253330054a22930a998032491856616c696461746f722072657475726e65642066616c73650013656375a002ae695ce1",
|
"compiledCode": "5835010000322322253330054a22930a99ab9c49011856616c696461746f722072657475726e65642066616c73650013656375a002ae69",
|
||||||
"hash": "2837caccfd96d636a07e0da584ebbef94069bd7bfa4447096ecd9b80",
|
"hash": "839f0c7156304227ee3d4b98d4a9c9febdfc73881d946a79d221534d",
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"Data": {
|
"Data": {
|
||||||
"title": "Data",
|
"title": "Data",
|
||||||
|
|
|
@ -16,8 +16,8 @@ description: "Code:\n\npub type Foo {\n foo: Data\n}\n\nvalidator {\n fn nes
|
||||||
"$ref": "#/definitions/Int"
|
"$ref": "#/definitions/Int"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"compiledCode": "58c6010000323232323232323232232232253330074a22930a998042491856616c696461746f722072657475726e65642066616c73650013656533333300c0011533006004161533006004161533006004161375a0022a6600c0082c6464a66600a66e1d2000001132533300a001153300700316132533300b300d002149854cc02001058c02c004c020dd50018a998030010b18031baa0024910a646174756d3a20466f6f0049010d72656465656d65723a20496e74005734ae7155ceaab9e5573eae855d12ba41",
|
"compiledCode": "58c40100003232323232323232232232253330074a22930a998042491856616c696461746f722072657475726e65642066616c73650013656533333300b0011533006004161533006004161533006004161375a0022a6600c0082c6464a66600a66e1d20000011325333009001153300700316132533300a300c002149854cc02001058c028004c01cdd50018a998030010b1aab9d37540049210a646174756d3a20466f6f0049010d72656465656d65723a20496e74005734ae7155cf2ab9f5742ae895d201",
|
||||||
"hash": "e072a0b88ccfcefd779abd4e6c1eb095a845c0689b98a2efc7500ce3",
|
"hash": "3234e31bc79a06ae16e351a0da2bbc177f2d474e174fc319b262d17c",
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"Data": {
|
"Data": {
|
||||||
"title": "Data",
|
"title": "Data",
|
||||||
|
|
|
@ -16,8 +16,8 @@ description: "Code:\n\npub type LinkedList<a> {\n Cons(a, LinkedList<a>)\n Nil
|
||||||
"$ref": "#/definitions/test_module~1LinkedList$Int"
|
"$ref": "#/definitions/test_module~1LinkedList$Int"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"compiledCode": "5902f90100003232323232323232323223232232253330094a22930a998052491856616c696461746f722072657475726e65642066616c73650013656330030014911972656465656d65723a204c696e6b65644c6973743c496e743e00323253330073370e900000089929998060008a998048018b0992999806980780109924c64660020020044464a66601866e1d20000011325333011001153300e00816132325333013001153301000a1613253330143016002132498cc01c01c00454cc04402c58c050004c050008c94cccccc0540044cdc3a400460206ea800454cc03c0245854cc03c0245854cc03c0245854cc03c02458c048004c02800854ccc030cdc3a40040022a66602060140042930a998068038b0a998068038b18050008a998050020b180680098028020a99980399b87480080044c94ccc03000454cc02400c584c8c94ccc03800454cc02c014584c94ccc03cc0440084c9263232323300100100222533301300114984c8cc00c00cc058008cc02cc050004028c94cccccc05000454cc0380205854cc038020584dd60008a998070040b0a998070040b18078011929999998098008a998068038b0a998068038b0a998068038b0a998068038b09bae001300d001153300c00616325333333012001153300c00616153300c00616132337606022002602260240026eb000454cc0300185854cc03001858c03c004c03c008c94cccccc04000454cc0280105854cc0280105854cc028010584dd68008a998050020b180680098028020a998040010b1802801a490a646174756d3a20466f6f00223233001001003223253330093370e900000089929998070008a998058028b0991929998080008a998068038b0992999808980980109924c6600e00e0022a6601c0102c6022002602200464a6666660240022a6601800c2c2a6601800c2c2a6601800c2c26eb400454cc03001858c03c004c01c00854ccc024cdc3a40040022a66601a600e0042930a998050020b0a998050020b1803800918031baa001230043754002ae695ce2ab9d5573caae7d5d0aba257481",
|
"compiledCode": "5902f1010000323232323232323232322323232322322533300b4a22930a998062491856616c696461746f722072657475726e65642066616c73650013656330030014911972656465656d65723a204c696e6b65644c6973743c496e743e00323253330093005001132533300e001153300b00316132533300f3011002132498c8cc00400400888c94ccc038c0280044c94ccc04c00454cc040020584c8c94ccc05400454cc048028584c94ccc058c0600084c92633007007001153301300b16301600130160023253333330170011300b301237540022a660220122c2a660220122c2a660220122c2a660220122c602800260180042a66601c60120022a66602460180042930a998078038b0a998078038b18060008a998060020b180780098038030a999804980200089929998070008a998058018b0991929998080008a998068028b0992999808980980109924c64646600200264a66666602e0022a660220122c2a660220122c26eb000454cc0440245854cc04402458c04800c894ccc050004526132330030033017002323300b00100a3015001325333333015001153300f00716153300f00716153300f00716153300f007161375c002601e0022a6601c00c2c64a6666660280022a6601c00c2c2a6601c00c2c26466ec0c04c004c04cc050004dd60008a998070030b0a998070030b180880098088011929999998090008a998060020b0a998060020b0a998060020b09bad001153300c00416300f0013007006153300a0021630070054910a646174756d3a20466f6f002232330010010032232533300b30070011325333010001153300d00516132325333012001153300f0071613253330133015002132498cc01c01c00454cc04002058c04c004c04c008c94cccccc05000454cc0380185854cc0380185854cc038018584dd68008a998070030b180880098048010a99980598030008a99980798048010a4c2a660180082c2a660180082c60120026e1d2002370e9000118031baa001230043754002ae695ce2ab9d5573caae7d5d0aba257481",
|
||||||
"hash": "6af45610cc5e97cfcaee80597fbacc64c10abd247e4c4bd278cfd7b4",
|
"hash": "9d102876de45c0d08ca859c7441172a790db51889f5735678bde4d8b",
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"Bool": {
|
"Bool": {
|
||||||
"title": "Bool",
|
"title": "Bool",
|
||||||
|
|
|
@ -10,8 +10,8 @@ description: "Code:\n\npub type Expr {\n Val(Int)\n Sum(Expr, Expr)\n Mul(Exp
|
||||||
"$ref": "#/definitions/test_module~1Expr"
|
"$ref": "#/definitions/test_module~1Expr"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"compiledCode": "590164010000323232323232323232232253330054a22930a9980324811856616c696461746f722072657475726e65642066616c73650013656323233001001003223253330073370e900000089929998060008a998048028b099299980698078010a4c2a6601400c2c64a6666660200022a6601400c2c2a6601400c2c2a6601400c2c26eb400454cc02801858c034004c01800854ccc01ccdc3a4004002264a6660180022a6601200a2c26464a66601c0022a6601600e2c264a66601e6022004264649319804004001198038038018a998060040b18078009807801180680098030010a99980399b87480100044c94ccc03000454cc024014584c8c94ccc03800454cc02c01c584c94ccc03cc0440084c8c9263300800800233007007003153300c00816300f001300f002300d00130060021533008004163008375400292010e72656465656d65723a204578707200230053754002ae695ce2ab9d5573caae7d5d0aba257481",
|
"compiledCode": "5901610100003232323232323232232253330054a22930a9980324811856616c696461746f722072657475726e65642066616c73650013656323233001001003223253330073370e900000089929998058008a998048028b099299980618070010a4c2a6601400c2c64a66666601e0022a6601400c2c2a6601400c2c2a6601400c2c26eb400454cc02801858c030004c01800854ccc01ccdc3a4004002264a6660160022a6601200a2c26464a66601a0022a6601600e2c264a66601c6020004264649319804004001198038038018a998060040b18070009807001180600098030010a99980399b87480100044c94ccc02c00454cc024014584c8c94ccc03400454cc02c01c584c94ccc038c0400084c8c9263300800800233007007003153300c00816300e001300e002300c00130060021533008004163008375400292010e72656465656d65723a204578707200235573c6ea80055cd2b9c5573aaae7d5d0aba25749",
|
||||||
"hash": "e36b64eadd545f7ccc38d21b3970034503ecb32d34c615e67307c2c6",
|
"hash": "91a6540bf2a0537951ab4a68fa2e921518e3008e50866f8cb3efb6ff",
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"Int": {
|
"Int": {
|
||||||
"dataType": "integer"
|
"dataType": "integer"
|
||||||
|
|
|
@ -16,8 +16,8 @@ description: "Code:\n\n/// On-chain state\ntype State {\n /// The contestatio
|
||||||
"$ref": "#/definitions/test_module~1Input"
|
"$ref": "#/definitions/test_module~1Input"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"compiledCode": "59021301000032323232323232323232232232253330084a22930a99804a491856616c696461746f722072657475726e65642066616c73650013656323253330083370e90000008a99980618030018a4c2a660120042c2a66601066e1d20020011533300c3006003149854cc0240085854ccc020cdc3a40080022a666018600c0062930a998048010b0a998048010b18030012490f72656465656d65723a20496e70757400323253330063370e900000089929998058008a998040018b0991929998068008a998050028b0991929998078008a998060038b099299980818090010991924c646600200200a44a66602600229309919801801980b00119299999980b8008a998088060b0a998088060b0a998088060b0a998088060b09bae001301400132533300d3370e900000089929998090008a998078050b0992999809980a8010a4c2a660200162c64a66666602c0022a660200162c2a660200162c2a660200162c26eb400454cc04002c58c04c004c02c01854cc03802458c02c01454cc03402058c94cccccc04c00454cc0340205854cc0340205854cc0340205854cc034020584dd7000980800098080011929999998088008a998058030b0a998058030b09bac001153300b00616153300b00616300e001300e002300c0013004003153300700216300400249010c646174756d3a20537461746500230063754002460086ea80055cd2b9c5573aaae7955cfaba15744ae901",
|
"compiledCode": "59020c010000323232323232323223232232253330094a22930a998052491856616c696461746f722072657475726e65642066616c736500136563232533300930050011533300b3007003149854cc0280085854ccc024cdc3a40040022a666016600e0062930a998050010b0a99980499b874801000454ccc02cc01c00c526153300a00216153300a00216300700249010f72656465656d65723a20496e70757400323253330073003001132533300a00115330090031613232533300c001153300b0051613232533300e001153300d00716132533300f301100213232498c8cc004004014894ccc048004526132330030033015002325333333016001153301200c16153301200c16153301200c16153301200c161375c002602600264a66601c6014002264a6660220022a660200142c264a66602460280042930a998088058b19299999980a8008a998088058b0a998088058b0a998088058b09bad001153301100b163012001300c006153300f00916300c005153300e00816325333333012001153300e00816153300e00816153300e00816153300e008161375c002601e002601e00464a6666660200022a6601800c2c2a6601800c2c26eb000454cc0300185854cc03001858c034004c034008c02c004c01401054cc02000858c01400d24010c646174756d3a20537461746500370e900011aab9e375400246aae74dd5000ab9a5738aae7d5d0aba257481",
|
||||||
"hash": "9d24091b8ab1791f96d57c516381d16b09e6c8e8daa9dfc32c23bd25",
|
"hash": "68d148a09243a8035dad9c17b6c970c786ddfb657509e2c2e64e23dc",
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"ByteArray": {
|
"ByteArray": {
|
||||||
"dataType": "bytes"
|
"dataType": "bytes"
|
||||||
|
|
|
@ -16,8 +16,8 @@ description: "Code:\n\nvalidator {\n fn tuples(datum: (Int, ByteArray), redeeme
|
||||||
"$ref": "#/definitions/Tuple$Int_Int_Int"
|
"$ref": "#/definitions/Tuple$Int_Int_Int"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"compiledCode": "5901d50100003232323232323232323223232232322533300a4a22930a99805a491856616c696461746f722072657475726e65642066616c73650013656533300c00115330090061613232533300e001153300b00816132325333010001153300d00a1613253330113013002149854cc03802c58c94cccccc05000454cc03802c5854cc03802c5854cc03802c584dd68008a998070058b180880098088011929999998090008a998060048b0a998060048b0a998060048b09bad001153300c00916300f001300f002325333333010001153300a00716153300a00716153300a007161375a0022a6601400e2c601a002a66666601c0022a6601000a2c2a6601000a2c26eb000454cc0200145854cc02001458c8c94cccccc03800454cc0200185854cc0200185854cc0200185854cc020018584dd700098048011929999998068008a998038028b0a998038028b0a998038028b09bad0011533007005163007001533333300b001153300500316153300500316132337606014002601460160026eb000454cc01400c5854cc01400c592411972656465656d65723a2028496e742c20496e742c20496e742900490117646174756d3a2028496e742c2042797465417272617929005734ae7155ceaab9e5573eae855d12ba41",
|
"compiledCode": "5901d0010000323232323232323223232232322533300a4a22930a99805a491856616c696461746f722072657475726e65642066616c73650013656533300a00115330090061613232533300c001153300b0081613232533300e001153300d00a16132533300f3011002149854cc03802c58c94cccccc04800454cc03802c5854cc03802c5854cc03802c584dd68008a998070058b180780098078011929999998080008a998060048b0a998060048b0a998060048b09bad001153300c00916300d001300d00232533333300e001153300a00716153300a00716153300a007161375a0022a6601400e2c6016002a6666660180022a6601000a2c2a6601000a2c26eb000454cc0200145854cc02001458c8c94cccccc03000454cc0200185854cc0200185854cc0200185854cc020018584dd70009aab9e00232533333300b0011533007005161533007005161533007005161375a0022a6600e00a2c6aae740054cccccc02400454cc01400c5854cc01400c584c8cdd81804000980418048009bac00115330050031615330050031649011972656465656d65723a2028496e742c20496e742c20496e742900490117646174756d3a2028496e742c2042797465417272617929005734ae7155cfaba15744ae91",
|
||||||
"hash": "aa6c3e4e255488cc2097dea5ab851837ae7923d9be789ecd1c26f2ba",
|
"hash": "228fd04e0d8a804ee6bec7e076e89221cc6e9379a7357d7f8265b448",
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"ByteArray": {
|
"ByteArray": {
|
||||||
"dataType": "bytes"
|
"dataType": "bytes"
|
||||||
|
|
|
@ -2813,8 +2813,6 @@ fn acceptance_test_29_union() {
|
||||||
.apply(Term::var("k"))
|
.apply(Term::var("k"))
|
||||||
.apply(Term::var("v")),
|
.apply(Term::var("v")),
|
||||||
)
|
)
|
||||||
.lambda("rest")
|
|
||||||
.apply(Term::tail_list().apply(Term::var("left")))
|
|
||||||
.lambda("v")
|
.lambda("v")
|
||||||
.apply(
|
.apply(
|
||||||
Term::un_i_data()
|
Term::un_i_data()
|
||||||
|
@ -2825,6 +2823,8 @@ fn acceptance_test_29_union() {
|
||||||
Term::un_b_data()
|
Term::un_b_data()
|
||||||
.apply(Term::fst_pair().apply(Term::var("pair"))),
|
.apply(Term::fst_pair().apply(Term::var("pair"))),
|
||||||
)
|
)
|
||||||
|
.lambda("rest")
|
||||||
|
.apply(Term::tail_list().apply(Term::var("left")))
|
||||||
.lambda("pair")
|
.lambda("pair")
|
||||||
.apply(Term::head_list().apply(Term::var("left"))),
|
.apply(Term::head_list().apply(Term::var("left"))),
|
||||||
)
|
)
|
||||||
|
|
|
@ -420,6 +420,10 @@ impl Unique {
|
||||||
pub fn increment(&mut self) {
|
pub fn increment(&mut self) {
|
||||||
self.0 += 1;
|
self.0 += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn large_offset(&mut self) {
|
||||||
|
self.0 += 5_000_000;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<isize> for Unique {
|
impl From<isize> for Unique {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{Constant, Name, Term, Type},
|
ast::{Constant, Name, Term, Type, Unique},
|
||||||
builtins::DefaultFunction,
|
builtins::DefaultFunction,
|
||||||
};
|
};
|
||||||
use pallas::ledger::primitives::alonzo::PlutusData;
|
use pallas::ledger::primitives::alonzo::PlutusData;
|
||||||
|
@ -464,10 +464,31 @@ impl Term<Name> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn lambda_unique(self, parameter_name: impl ToString, unique: Unique) -> Self {
|
||||||
|
Term::Lambda {
|
||||||
|
parameter_name: Name {
|
||||||
|
text: parameter_name.to_string(),
|
||||||
|
unique,
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
body: self.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn var(name: impl ToString) -> Self {
|
pub fn var(name: impl ToString) -> Self {
|
||||||
Term::Var(Name::text(name).into())
|
Term::Var(Name::text(name).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn var_unique(name: impl ToString, unique: Unique) -> Self {
|
||||||
|
Term::Var(
|
||||||
|
Name {
|
||||||
|
text: name.to_string(),
|
||||||
|
unique,
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Misc.
|
// Misc.
|
||||||
pub fn constr_fields_exposer(self) -> Self {
|
pub fn constr_fields_exposer(self) -> Self {
|
||||||
self.lambda(CONSTR_FIELDS_EXPOSER).apply(
|
self.lambda(CONSTR_FIELDS_EXPOSER).apply(
|
||||||
|
|
|
@ -3,8 +3,10 @@ use crate::ast::{Name, Program};
|
||||||
pub mod shrinker;
|
pub mod shrinker;
|
||||||
|
|
||||||
pub fn aiken_optimize_and_intern(program: Program<Name>) -> Program<Name> {
|
pub fn aiken_optimize_and_intern(program: Program<Name>) -> Program<Name> {
|
||||||
|
let (program, mut current_unique) = program.builtin_force_reducer();
|
||||||
|
current_unique.large_offset();
|
||||||
|
|
||||||
program
|
program
|
||||||
.builtin_force_reducer()
|
|
||||||
.lambda_reducer()
|
.lambda_reducer()
|
||||||
.inline_reducer()
|
.inline_reducer()
|
||||||
.lambda_reducer()
|
.lambda_reducer()
|
||||||
|
@ -12,10 +14,10 @@ pub fn aiken_optimize_and_intern(program: Program<Name>) -> Program<Name> {
|
||||||
.force_delay_reducer()
|
.force_delay_reducer()
|
||||||
.cast_data_reducer()
|
.cast_data_reducer()
|
||||||
.convert_arithmetic_ops()
|
.convert_arithmetic_ops()
|
||||||
.builtin_curry_reducer()
|
.builtin_curry_reducer(&mut current_unique)
|
||||||
.lambda_reducer()
|
.lambda_reducer()
|
||||||
.inline_reducer()
|
.inline_reducer()
|
||||||
.builtin_curry_reducer()
|
.builtin_curry_reducer(&mut current_unique)
|
||||||
.lambda_reducer()
|
.lambda_reducer()
|
||||||
.inline_reducer()
|
.inline_reducer()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use itertools::Itertools;
|
||||||
use pallas::ledger::primitives::babbage::{BigInt, PlutusData};
|
use pallas::ledger::primitives::babbage::{BigInt, PlutusData};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{Constant, Data, Name, NamedDeBruijn, Program, Term, Type},
|
ast::{Constant, Data, Name, NamedDeBruijn, Program, Term, Type, Unique},
|
||||||
builtins::DefaultFunction,
|
builtins::DefaultFunction,
|
||||||
parser::interner::Interner,
|
parser::interner::Interner,
|
||||||
};
|
};
|
||||||
|
@ -85,18 +85,6 @@ impl Default for IdGen {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id_vec_function_to_var(func_name: &str, id_vec: &[usize]) -> String {
|
|
||||||
format!(
|
|
||||||
"__{}_{}_curried",
|
|
||||||
func_name,
|
|
||||||
id_vec
|
|
||||||
.iter()
|
|
||||||
.map(|item| item.to_string())
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join("_")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq, PartialOrd, Default, Debug, Clone)]
|
#[derive(PartialEq, PartialOrd, Default, Debug, Clone)]
|
||||||
pub struct VarLookup {
|
pub struct VarLookup {
|
||||||
found: bool,
|
found: bool,
|
||||||
|
@ -810,7 +798,7 @@ impl Program<Name> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn builtin_force_reducer(self) -> Self {
|
pub fn builtin_force_reducer(self) -> (Self, Unique) {
|
||||||
let mut builtin_map = IndexMap::new();
|
let mut builtin_map = IndexMap::new();
|
||||||
|
|
||||||
let program = self.traverse_uplc_with(&mut |_id, term, _arg_stack, _scope| {
|
let program = self.traverse_uplc_with(&mut |_id, term, _arg_stack, _scope| {
|
||||||
|
@ -868,7 +856,10 @@ impl Program<Name> {
|
||||||
|
|
||||||
let program = Program::<NamedDeBruijn>::try_from(program).unwrap();
|
let program = Program::<NamedDeBruijn>::try_from(program).unwrap();
|
||||||
|
|
||||||
Program::<Name>::try_from(program).unwrap()
|
(
|
||||||
|
Program::<Name>::try_from(program).unwrap(),
|
||||||
|
interner.current_unique(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inline_reducer(self) -> Self {
|
pub fn inline_reducer(self) -> Self {
|
||||||
|
@ -1156,7 +1147,7 @@ impl Program<Name> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn builtin_curry_reducer(self) -> Self {
|
pub fn builtin_curry_reducer(self, current: &mut Unique) -> Self {
|
||||||
let mut curried_terms = vec![];
|
let mut curried_terms = vec![];
|
||||||
let mut id_mapped_curry_terms: IndexMap<CurriedName, (Scope, Term<Name>, bool)> =
|
let mut id_mapped_curry_terms: IndexMap<CurriedName, (Scope, Term<Name>, bool)> =
|
||||||
IndexMap::new();
|
IndexMap::new();
|
||||||
|
@ -1164,6 +1155,7 @@ impl Program<Name> {
|
||||||
let mut scope_mapped_to_term: IndexMap<Scope, Vec<(CurriedName, Term<Name>)>> =
|
let mut scope_mapped_to_term: IndexMap<Scope, Vec<(CurriedName, Term<Name>)>> =
|
||||||
IndexMap::new();
|
IndexMap::new();
|
||||||
let mut final_ids: IndexMap<Vec<usize>, ()> = IndexMap::new();
|
let mut final_ids: IndexMap<Vec<usize>, ()> = IndexMap::new();
|
||||||
|
let mut unique_map: IndexMap<String, Unique> = IndexMap::new();
|
||||||
|
|
||||||
let step_a = self.traverse_uplc_with(&mut |_id, term, arg_stack, scope| match term {
|
let step_a = self.traverse_uplc_with(&mut |_id, term, arg_stack, scope| match term {
|
||||||
Term::Builtin(func) => {
|
Term::Builtin(func) => {
|
||||||
|
@ -1209,6 +1201,8 @@ impl Program<Name> {
|
||||||
|
|
||||||
id_only_vec.push(node.curried_id);
|
id_only_vec.push(node.curried_id);
|
||||||
|
|
||||||
|
let id_var_name = id_vec_function_to_var(&func.aiken_name(), &id_only_vec);
|
||||||
|
|
||||||
let curry_name = CurriedName {
|
let curry_name = CurriedName {
|
||||||
func_name: func.aiken_name(),
|
func_name: func.aiken_name(),
|
||||||
id_vec: id_only_vec,
|
id_vec: id_only_vec,
|
||||||
|
@ -1220,19 +1214,33 @@ impl Program<Name> {
|
||||||
*map_scope = map_scope.common_ancestor(scope);
|
*map_scope = map_scope.common_ancestor(scope);
|
||||||
*multi_occurrences = true;
|
*multi_occurrences = true;
|
||||||
} else if id_vec.is_empty() {
|
} else if id_vec.is_empty() {
|
||||||
|
unique_map.insert(id_var_name, *current);
|
||||||
|
|
||||||
|
current.increment();
|
||||||
|
|
||||||
id_mapped_curry_terms.insert(
|
id_mapped_curry_terms.insert(
|
||||||
curry_name,
|
curry_name,
|
||||||
(scope.clone(), Term::Builtin(*func).apply(node.term), false),
|
(scope.clone(), Term::Builtin(*func).apply(node.term), false),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
unique_map.insert(id_var_name, *current);
|
||||||
|
|
||||||
|
current.increment();
|
||||||
|
|
||||||
let var_name = id_vec_function_to_var(
|
let var_name = id_vec_function_to_var(
|
||||||
&func.aiken_name(),
|
&func.aiken_name(),
|
||||||
&id_vec.iter().map(|item| item.curried_id).collect_vec(),
|
&id_vec.iter().map(|item| item.curried_id).collect_vec(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let unique = *unique_map.get(&var_name).unwrap_or(current);
|
||||||
|
|
||||||
id_mapped_curry_terms.insert(
|
id_mapped_curry_terms.insert(
|
||||||
curry_name,
|
curry_name,
|
||||||
(scope.clone(), Term::var(var_name).apply(node.term), false),
|
(
|
||||||
|
scope.clone(),
|
||||||
|
Term::var_unique(var_name, unique).apply(node.term),
|
||||||
|
false,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1264,7 +1272,7 @@ impl Program<Name> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut step_b = step_a.traverse_uplc_with(&mut |id, term, arg_stack, scope| match term {
|
step_a.traverse_uplc_with(&mut |id, term, arg_stack, scope| match term {
|
||||||
Term::Builtin(func) => {
|
Term::Builtin(func) => {
|
||||||
if func.can_curry_builtin() && arg_stack.len() == func.arity() {
|
if func.can_curry_builtin() && arg_stack.len() == func.arity() {
|
||||||
let Some(curried_builtin) =
|
let Some(curried_builtin) =
|
||||||
|
@ -1304,7 +1312,9 @@ impl Program<Name> {
|
||||||
curry_applied_ids.push(item.applied_id);
|
curry_applied_ids.push(item.applied_id);
|
||||||
});
|
});
|
||||||
|
|
||||||
*term = Term::var(name);
|
let unique = *unique_map.get(&name).unwrap();
|
||||||
|
|
||||||
|
*term = Term::var_unique(name, unique);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Term::Apply { function, .. } => {
|
Term::Apply { function, .. } => {
|
||||||
|
@ -1318,8 +1328,19 @@ impl Program<Name> {
|
||||||
for (key, val) in insert_list.into_iter().rev() {
|
for (key, val) in insert_list.into_iter().rev() {
|
||||||
let name = id_vec_function_to_var(&key.func_name, &key.id_vec);
|
let name = id_vec_function_to_var(&key.func_name, &key.id_vec);
|
||||||
|
|
||||||
if var_occurrences(term, Name::text(&name).into()).found {
|
let unique = *unique_map.get(&name).unwrap();
|
||||||
*term = term.clone().lambda(name).apply(val);
|
|
||||||
|
if var_occurrences(
|
||||||
|
term,
|
||||||
|
Name {
|
||||||
|
text: name.clone(),
|
||||||
|
unique,
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
|
.found
|
||||||
|
{
|
||||||
|
*term = term.clone().lambda_unique(name, unique).apply(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1331,22 +1352,37 @@ impl Program<Name> {
|
||||||
for (key, val) in insert_list.into_iter().rev() {
|
for (key, val) in insert_list.into_iter().rev() {
|
||||||
let name = id_vec_function_to_var(&key.func_name, &key.id_vec);
|
let name = id_vec_function_to_var(&key.func_name, &key.id_vec);
|
||||||
|
|
||||||
if var_occurrences(term, Name::text(&name).into()).found {
|
let unique = *unique_map.get(&name).unwrap();
|
||||||
*term = term.clone().lambda(name).apply(val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut interner = Interner::new();
|
if var_occurrences(
|
||||||
|
term,
|
||||||
interner.program(&mut step_b);
|
Name {
|
||||||
|
text: name.clone(),
|
||||||
let step_b = Program::<NamedDeBruijn>::try_from(step_b).unwrap();
|
unique,
|
||||||
|
|
||||||
Program::<Name>::try_from(step_b).unwrap()
|
|
||||||
}
|
}
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
|
.found
|
||||||
|
{
|
||||||
|
*term = term.clone().lambda_unique(name, unique).apply(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn id_vec_function_to_var(func_name: &str, id_vec: &[usize]) -> String {
|
||||||
|
format!(
|
||||||
|
"__{}_{}_curried",
|
||||||
|
func_name,
|
||||||
|
id_vec
|
||||||
|
.iter()
|
||||||
|
.map(|item| item.to_string())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join("_")
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn var_occurrences(term: &Term<Name>, search_for: Rc<Name>) -> VarLookup {
|
fn var_occurrences(term: &Term<Name>, search_for: Rc<Name>) -> VarLookup {
|
||||||
|
@ -1740,7 +1776,7 @@ mod tests {
|
||||||
|
|
||||||
let expected: Program<NamedDeBruijn> = expected.try_into().unwrap();
|
let expected: Program<NamedDeBruijn> = expected.try_into().unwrap();
|
||||||
|
|
||||||
let mut actual = program.builtin_force_reducer();
|
let (mut actual, _) = program.builtin_force_reducer();
|
||||||
|
|
||||||
let mut interner = Interner::new();
|
let mut interner = Interner::new();
|
||||||
|
|
||||||
|
@ -1799,7 +1835,7 @@ mod tests {
|
||||||
|
|
||||||
let expected: Program<NamedDeBruijn> = expected.try_into().unwrap();
|
let expected: Program<NamedDeBruijn> = expected.try_into().unwrap();
|
||||||
|
|
||||||
let mut actual = program.builtin_force_reducer();
|
let (mut actual, _) = program.builtin_force_reducer();
|
||||||
|
|
||||||
let mut interner = Interner::new();
|
let mut interner = Interner::new();
|
||||||
|
|
||||||
|
@ -1965,9 +2001,13 @@ mod tests {
|
||||||
|
|
||||||
interner.program(&mut expected);
|
interner.program(&mut expected);
|
||||||
|
|
||||||
|
let mut unique = interner.current_unique();
|
||||||
|
|
||||||
|
unique.large_offset();
|
||||||
|
|
||||||
let expected: Program<NamedDeBruijn> = expected.try_into().unwrap();
|
let expected: Program<NamedDeBruijn> = expected.try_into().unwrap();
|
||||||
|
|
||||||
let actual = program.builtin_curry_reducer();
|
let actual = program.builtin_curry_reducer(&mut unique);
|
||||||
|
|
||||||
let actual: Program<NamedDeBruijn> = actual.try_into().unwrap();
|
let actual: Program<NamedDeBruijn> = actual.try_into().unwrap();
|
||||||
|
|
||||||
|
|
|
@ -76,4 +76,8 @@ impl Interner {
|
||||||
unique
|
unique
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn current_unique(&self) -> Unique {
|
||||||
|
self.current
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue