update tests and ensure identity reducer handles no_inline lambda

This commit is contained in:
microproofs 2024-03-02 17:22:23 -05:00 committed by Kasey
parent af6c107187
commit d971d9818b
11 changed files with 98 additions and 50 deletions

View File

@ -46,7 +46,7 @@ use uplc::{
builder::{CONSTR_FIELDS_EXPOSER, CONSTR_INDEX_EXPOSER, EXPECT_ON_LIST},
builtins::DefaultFunction,
machine::cost_model::ExBudget,
optimize::aiken_optimize_and_intern,
optimize::{aiken_optimize_and_intern, shrinker::NO_INLINE},
parser::interner::Interner,
};

View File

@ -16,8 +16,8 @@ description: "Code:\n\npub type Foo {\n foo: Int\n}\n\nvalidator {\n fn an
"$ref": "#/definitions/Data"
}
},
"compiledCode": "58310100003222253330044a22930a99ab9c49011856616c696461746f722072657475726e65642066616c7365001365657341",
"hash": "089cd4ae25b73d144116d7736d915ffb18302b482f91e0c89020adbe",
"compiledCode": "5833010000323222253330044a22930a99802a491856616c696461746f722072657475726e65642066616c736500136565734ae701",
"hash": "52a21f2b4f282074cb6c5aefef20d18c25f3657ca348c73875810c37",
"definitions": {
"Data": {
"title": "Data",

View File

@ -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"
}
},
"compiledCode": "59017d0100003232323232323232232253330064a22930a99803a4811856616c696461746f722072657475726e65642066616c7365001365632325323330073001002132533300a001153300900416132533300b300d002149854cc02801458c94cccccc03800454cc0280145854cc0280145854cc0280145854cc028014584dd7000980580098028020a99919804180080189929998058008a998050028b0992999806180700109924c64a666016600a002264a66601c0022a6601a0102c264a66601e60220042930a998070048b1929999998090008a998070048b0a998070048b0a998070048b09bad001153300e00916300f00130090021533300b30040011533300d3009002149854cc03001c5854cc03001c58c02400454cc02c01858c030004c018014dc3a40042a660100062c6e1d2000300400249012a72656465656d65723a204569746865723c4279746541727261792c20496e74657276616c3c496e743e3e00235573c6ea80048d55ce9baa0015734ae7155cfaba15744ae901",
"hash": "336e48e839e1def7f4de623b6fdbc755400abea87292691daab43632",
"compiledCode": "59018201000032323232323232323232232253330064a22930a99803a4811856616c696461746f722072657475726e65642066616c7365001365632325323330073001002132533300c001153300900416132533300d300f002149854cc02801458c94cccccc04000454cc0280145854cc0280145854cc0280145854cc028014584dd7000980680098028020a99919804180080189929998068008a998050028b0992999807180800109924c64a666016600a002264a6660200022a6601a0102c264a66602260260042930a998070048b19299999980a0008a998070048b0a998070048b0a998070048b09bad001153300e00916301100130090021533300b30040011533300f3009002149854cc03001c5854cc03001c58c02400454cc02c01858c038004c018014dc3a40042a660100062c6e1d2000300400249012a72656465656d65723a204569746865723c4279746541727261792c20496e74657276616c3c496e743e3e00230063754002460086ea80055cd2b9c5573aaae7955cfaba15744ae901",
"hash": "87903885b9ea1cbfcc5a9dc9d7a0e9f071a7673451233e9177fa7d1f",
"definitions": {
"ByteArray": {
"dataType": "bytes"

View File

@ -10,8 +10,8 @@ description: "Code:\n\ntype Dict<key, value> {\n inner: List<(ByteArray, valu
"$ref": "#/definitions/test_module~1Dict$test_module~1UUID_Int"
}
},
"compiledCode": "59012f0100003232323232323232232253330044a22930a99802a4811856616c696461746f722072657475726e65642066616c73650013656323253330043370e900000089929998048008a998030018b0992999805180600109924c646600200200444a66601800229309919801801980780119191929999998090008a998060048b0a998060048b0a998060048b09bad001153300c00916300d002325333333011001153300b00816153300b00816153300b00816153300b008161375c0026016002601a0022a6600e0082c64a66666601a0022a6600e0082c26eac00454cc01c0105854cc01c0105854cc01c01058c028004c01cdd50018a998028010b18029baa00249011972656465656d65723a20446963743c555549442c20496e743e005734ae7155ceaab9e5573eae855d12ba41",
"hash": "237ebd507b132e833ed155f5f88f47ce06047f16b0b1488b48a8af67",
"compiledCode": "59012c0100003232323232323232232253330044a22930a99802a4811856616c696461746f722072657475726e65642066616c736500136563253330033370e900018029baa00213253330080011533005002161325333009300b002132498c8cc004004008894ccc02c00452613233003003300e0023232325333333011001153300b00816153300b00816153300b008161375a0022a660160102c601800464a6666660200022a6601400e2c2a6601400e2c2a6601400e2c2a6601400e2c26eb8004c028004c03000454cc01800c58c94cccccc03000454cc01800c584dd58008a998030018b0a998030018b0a998030018b180480098031baa0021533004001164911972656465656d65723a20446963743c555549442c20496e743e005734ae7155ceaab9e5573eae855d12ba41",
"hash": "a74dc32316d19627c62b81eb9d616bb02926f242a9844ef2646e7685",
"definitions": {
"ByteArray": {
"dataType": "bytes"

View File

@ -18,8 +18,8 @@ description: "Code:\n\nvalidator(utxo_ref: Int) {\n fn mint(redeemer: Data, ctx
}
}
],
"compiledCode": "5835010000322322253330054a22930a99ab9c49011856616c696461746f722072657475726e65642066616c73650013656375a002ae69",
"hash": "839f0c7156304227ee3d4b98d4a9c9febdfc73881d946a79d221534d",
"compiledCode": "583701000032322322253330054a22930a998032491856616c696461746f722072657475726e65642066616c73650013656375a002ae695ce1",
"hash": "2837caccfd96d636a07e0da584ebbef94069bd7bfa4447096ecd9b80",
"definitions": {
"Data": {
"title": "Data",

View File

@ -16,8 +16,8 @@ description: "Code:\n\npub type Foo {\n foo: Data\n}\n\nvalidator {\n fn nes
"$ref": "#/definitions/Int"
}
},
"compiledCode": "58c40100003232323232323232232232253330074a22930a998042491856616c696461746f722072657475726e65642066616c73650013656533333300b0011533006004161533006004161533006004161375a0022a6600c0082c6464a66600a66e1d20000011325333009001153300700316132533300a300c002149854cc02001058c028004c01cdd50018a998030010b1aab9d37540049210a646174756d3a20466f6f0049010d72656465656d65723a20496e74005734ae7155cf2ab9f5742ae895d201",
"hash": "3234e31bc79a06ae16e351a0da2bbc177f2d474e174fc319b262d17c",
"compiledCode": "58c4010000323232323232323232232232253330074a22930a998042491856616c696461746f722072657475726e65642066616c73650013656533333300c0011533006004161533006004161533006004161375a0022a6600c0082c64a66600866e1d200030063754004264a6660120022a6600c0042c264a66601460180042930a998038018b180500098039baa00215330050011649010a646174756d3a20466f6f0049010d72656465656d65723a20496e74005734ae7155ceaab9e5573eae855d12ba41",
"hash": "935eefeabd502b0da8d7ea94cfafe9f94557f33801609dc948a3aee8",
"definitions": {
"Data": {
"title": "Data",

View File

@ -16,8 +16,8 @@ description: "Code:\n\npub type LinkedList<a> {\n Cons(a, LinkedList<a>)\n Nil
"$ref": "#/definitions/test_module~1LinkedList$Int"
}
},
"compiledCode": "5902f1010000323232323232323232322323232322322533300b4a22930a998062491856616c696461746f722072657475726e65642066616c73650013656330030014911972656465656d65723a204c696e6b65644c6973743c496e743e00323253330093005001132533300e001153300b00316132533300f3011002132498c8cc00400400888c94ccc038c0280044c94ccc04c00454cc040020584c8c94ccc05400454cc048028584c94ccc058c0600084c92633007007001153301300b16301600130160023253333330170011300b301237540022a660220122c2a660220122c2a660220122c2a660220122c602800260180042a66601c60120022a66602460180042930a998078038b0a998078038b18060008a998060020b180780098038030a999804980200089929998070008a998058018b0991929998080008a998068028b0992999808980980109924c64646600200264a66666602e0022a660220122c2a660220122c26eb000454cc0440245854cc04402458c04800c894ccc050004526132330030033017002323300b00100a3015001325333333015001153300f00716153300f00716153300f00716153300f007161375c002601e0022a6601c00c2c64a6666660280022a6601c00c2c2a6601c00c2c26466ec0c04c004c04cc050004dd60008a998070030b0a998070030b180880098088011929999998090008a998060020b0a998060020b0a998060020b09bad001153300c00416300f0013007006153300a0021630070054910a646174756d3a20466f6f002232330010010032232533300b30070011325333010001153300d00516132325333012001153300f0071613253330133015002132498cc01c01c00454cc04002058c04c004c04c008c94cccccc05000454cc0380185854cc0380185854cc038018584dd68008a998070030b180880098048010a99980598030008a99980798048010a4c2a660180082c2a660180082c60120026e1d2002370e9000118031baa001230043754002ae695ce2ab9d5573caae7d5d0aba257481",
"hash": "9d102876de45c0d08ca859c7441172a790db51889f5735678bde4d8b",
"compiledCode": "5902ef010000323232323232323232322323232322322533300b4a22930a998062491856616c696461746f722072657475726e65642066616c73650013656330030014911972656465656d65723a204c696e6b65644c6973743c496e743e00323253330093005001132533300e001153300b00316132533300f3011002132498c8cc00400400888c94ccc038c0280044c94ccc04c00454cc040020584c8c94ccc05400454cc048028584c94ccc058c0600084c92633007007001153301300b16301600130160023253333330170011300b301237540022a660220122c2a660220122c2a660220122c2a660220122c602800260180042a66601c60120022a66602460180042930a998078038b0a998078038b18060008a998060020b180780098038030a999804980200089929998070008a998058018b0991929998080008a998068028b0992999808980980109924c64646600200264a66666602e0022a660220122c2a660220122c26eb000454cc0440245854cc04402458c04800c894ccc0500045261323300300330170023300a3015001009325333333015001153300f00716153300f00716153300f00716153300f007161375c002601e0022a6601c00c2c64a6666660280022a6601c00c2c2a6601c00c2c26466ec0c04c004c04cc050004dd60008a998070030b0a998070030b180880098088011929999998090008a998060020b0a998060020b0a998060020b09bad001153300c00416300f0013007006153300a00216300700549010a646174756d3a20466f6f002232330010010032232533300b30070011325333010001153300d00516132325333012001153300f0071613253330133015002132498cc01c01c00454cc04002058c04c004c04c008c94cccccc05000454cc0380185854cc0380185854cc038018584dd68008a998070030b180880098048010a99980598030008a99980798048010a4c2a660180082c2a660180082c60120026e1d2002370e9000118031baa001230043754002ae695ce2ab9d5573caae7d5d0aba257481",
"hash": "51c3b605f73897a692b449d522d38480a01eade8e21dbe0e3d661f9c",
"definitions": {
"Bool": {
"title": "Bool",

View File

@ -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"
}
},
"compiledCode": "5901610100003232323232323232232253330054a22930a9980324811856616c696461746f722072657475726e65642066616c73650013656323233001001003223253330073370e900000089929998058008a998048028b099299980618070010a4c2a6601400c2c64a66666601e0022a6601400c2c2a6601400c2c2a6601400c2c26eb400454cc02801858c030004c01800854ccc01ccdc3a4004002264a6660160022a6601200a2c26464a66601a0022a6601600e2c264a66601c6020004264649319804004001198038038018a998060040b18070009807001180600098030010a99980399b87480100044c94ccc02c00454cc024014584c8c94ccc03400454cc02c01c584c94ccc038c0400084c8c9263300800800233007007003153300c00816300e001300e002300c00130060021533008004163008375400292010e72656465656d65723a204578707200235573c6ea80055cd2b9c5573aaae7d5d0aba25749",
"hash": "91a6540bf2a0537951ab4a68fa2e921518e3008e50866f8cb3efb6ff",
"compiledCode": "590164010000323232323232323232232253330054a22930a9980324811856616c696461746f722072657475726e65642066616c73650013656323233001001003223253330073370e900000089929998060008a998048028b099299980698078010a4c2a6601400c2c64a6666660200022a6601400c2c2a6601400c2c2a6601400c2c26eb400454cc02801858c034004c01800854ccc01ccdc3a4004002264a6660180022a6601200a2c26464a66601c0022a6601600e2c264a66601e6022004264649319804004001198038038018a998060040b18078009807801180680098030010a99980399b87480100044c94ccc03000454cc024014584c8c94ccc03800454cc02c01c584c94ccc03cc0440084c8c9263300800800233007007003153300c00816300f001300f002300d00130060021533008004163008375400292010e72656465656d65723a204578707200230053754002ae695ce2ab9d5573caae7d5d0aba257481",
"hash": "e36b64eadd545f7ccc38d21b3970034503ecb32d34c615e67307c2c6",
"definitions": {
"Int": {
"dataType": "integer"

View File

@ -16,8 +16,8 @@ description: "Code:\n\n/// On-chain state\ntype State {\n /// The contestatio
"$ref": "#/definitions/test_module~1Input"
}
},
"compiledCode": "59020c010000323232323232323223232232253330094a22930a998052491856616c696461746f722072657475726e65642066616c736500136563232533300930050011533300b3007003149854cc0280085854ccc024cdc3a40040022a666016600e0062930a998050010b0a99980499b874801000454ccc02cc01c00c526153300a00216153300a00216300700249010f72656465656d65723a20496e70757400323253330073003001132533300a00115330090031613232533300c001153300b0051613232533300e001153300d00716132533300f301100213232498c8cc004004014894ccc048004526132330030033015002325333333016001153301200c16153301200c16153301200c16153301200c161375c002602600264a66601c6014002264a6660220022a660200142c264a66602460280042930a998088058b19299999980a8008a998088058b0a998088058b0a998088058b09bad001153301100b163012001300c006153300f00916300c005153300e00816325333333012001153300e00816153300e00816153300e00816153300e008161375c002601e002601e00464a6666660200022a6601800c2c2a6601800c2c26eb000454cc0300185854cc03001858c034004c034008c02c004c01401054cc02000858c01400d24010c646174756d3a20537461746500370e900011aab9e375400246aae74dd5000ab9a5738aae7d5d0aba257481",
"hash": "68d148a09243a8035dad9c17b6c970c786ddfb657509e2c2e64e23dc",
"compiledCode": "59020c0100003232323232323232323223232232253330094a22930a998052491856616c696461746f722072657475726e65642066616c736500136563232533300930050011533300d3007003149854cc0280085854ccc024cdc3a40040022a66601a600e0062930a998050010b0a99980499b874801000454ccc034c01c00c526153300a00216153300a00216300700249010f72656465656d65723a20496e7075740032533300630023005003132533300b00115330080021613232533300d001153300a0041613232533300f001153300c006161325333010301200213232498c8cc004004014894ccc04c004526132330030033016002325333333017001153301100b16153301100b16153301100b16153301100b161375c0026028002a6660186010601600a264a6660220022a6601c0102c264a66602460280042930a998078048b19299999980a8008a998078048b0a998078048b0a998078048b09bad001153300f009163012001300a005153300d00716153300d00716325333333013001153300d00716153300d00716153300d00716153300d007161375c0026020002602000464a6666660220022a6601600a2c2a6601600a2c26eb000454cc02c0145854cc02c01458c038004c038008c030004c01000c54cc01c0045924010c646174756d3a20537461746500370e9000118031baa001230043754002ae695ce2ab9d5573caae7d5d0aba257481",
"hash": "95ac6630108cf1703b7479ededd419dd258a433751ff391002f1e1f8",
"definitions": {
"ByteArray": {
"dataType": "bytes"

View File

@ -16,8 +16,8 @@ description: "Code:\n\nvalidator {\n fn tuples(datum: (Int, ByteArray), redeeme
"$ref": "#/definitions/Tuple$Int_Int_Int"
}
},
"compiledCode": "5901d0010000323232323232323223232232322533300a4a22930a99805a491856616c696461746f722072657475726e65642066616c73650013656533300a00115330090061613232533300c001153300b0081613232533300e001153300d00a16132533300f3011002149854cc03802c58c94cccccc04800454cc03802c5854cc03802c5854cc03802c584dd68008a998070058b180780098078011929999998080008a998060048b0a998060048b0a998060048b09bad001153300c00916300d001300d00232533333300e001153300a00716153300a00716153300a007161375a0022a6601400e2c6016002a6666660180022a6601000a2c2a6601000a2c26eb000454cc0200145854cc02001458c8c94cccccc03000454cc0200185854cc0200185854cc0200185854cc020018584dd70009aab9e00232533333300b0011533007005161533007005161533007005161375a0022a6600e00a2c6aae740054cccccc02400454cc01400c5854cc01400c584c8cdd81804000980418048009bac00115330050031615330050031649011972656465656d65723a2028496e742c20496e742c20496e742900490117646174756d3a2028496e742c2042797465417272617929005734ae7155cfaba15744ae91",
"hash": "228fd04e0d8a804ee6bec7e076e89221cc6e9379a7357d7f8265b448",
"compiledCode": "5901d50100003232323232323232323223232232322533300a4a22930a99805a491856616c696461746f722072657475726e65642066616c73650013656533300c00115330090061613232533300e001153300b00816132325333010001153300d00a1613253330113013002149854cc03802c58c94cccccc05000454cc03802c5854cc03802c5854cc03802c584dd68008a998070058b180880098088011929999998090008a998060048b0a998060048b0a998060048b09bad001153300c00916300f001300f002325333333010001153300a00716153300a00716153300a007161375a0022a6601400e2c601a002a66666601c0022a6601000a2c2a6601000a2c26eb000454cc0200145854cc02001458c8c94cccccc03800454cc0200185854cc0200185854cc0200185854cc020018584dd700098048011929999998068008a998038028b0a998038028b0a998038028b09bad0011533007005163007001533333300b001153300500316153300500316132337606014002601460160026eb000454cc01400c5854cc01400c592411972656465656d65723a2028496e742c20496e742c20496e742900490117646174756d3a2028496e742c2042797465417272617929005734ae7155ceaab9e5573eae855d12ba41",
"hash": "aa6c3e4e255488cc2097dea5ab851837ae7923d9be789ecd1c26f2ba",
"definitions": {
"ByteArray": {
"dataType": "bytes"

View File

@ -929,40 +929,88 @@ impl Program<Name> {
body,
} => {
// pops stack here no matter what
if let Some((
arg_id,
Term::Lambda {
parameter_name: identity_name,
body: identity_body,
},
)) = arg_stack.pop()
{
if let Term::Var(identity_var) = identity_body.as_ref() {
if identity_var.as_ref() == identity_name.as_ref() {
// Replace all applied usages of identity with the arg
let temp_term =
replace_identity_usage(body.as_ref(), parameter_name.clone());
// Have to check if the body still has any occurrences of the parameter
// After attempting replacement
if var_occurrences(
body.as_ref(),
parameter_name.clone(),
vec![],
vec![],
)
.found
{
let body = Rc::make_mut(body);
*body = temp_term;
} else {
identity_applied_ids.push(arg_id);
*term = temp_term;
match arg_stack.pop() {
Some((
arg_id,
Term::Lambda {
parameter_name: inline_name,
body: identity_body,
},
)) if inline_name.text == NO_INLINE => {
if let Term::Lambda {
parameter_name: identity_name,
body: identity_body,
} = identity_body.as_ref()
{
if let Term::Var(identity_var) = identity_body.as_ref() {
if identity_var.text == identity_name.text
&& identity_var.unique == identity_name.unique
{
// Replace all applied usages of identity with the arg
let temp_term = replace_identity_usage(
body.as_ref(),
parameter_name.clone(),
);
// Have to check if the body still has any occurrences of the parameter
// After attempting replacement
if var_occurrences(
body.as_ref(),
parameter_name.clone(),
vec![],
vec![],
)
.found
{
let body = Rc::make_mut(body);
*body = temp_term;
} else {
identity_applied_ids.push(arg_id);
*term = temp_term;
}
}
}
}
}
Some((
arg_id,
Term::Lambda {
parameter_name: identity_name,
body: identity_body,
},
)) => {
if let Term::Var(identity_var) = identity_body.as_ref() {
if identity_var.text == identity_name.text
&& identity_var.unique == identity_name.unique
{
// Replace all applied usages of identity with the arg
let temp_term = replace_identity_usage(
body.as_ref(),
parameter_name.clone(),
);
// Have to check if the body still has any occurrences of the parameter
// After attempting replacement
if var_occurrences(
body.as_ref(),
parameter_name.clone(),
vec![],
vec![],
)
.found
{
let body = Rc::make_mut(body);
*body = temp_term;
} else {
identity_applied_ids.push(arg_id);
*term = temp_term;
}
}
}
}
_ => {}
}
}
Term::Constr { .. } => todo!(),
Term::Case { .. } => todo!(),
_ => {}
@ -1994,7 +2042,7 @@ mod tests {
let expected: Program<NamedDeBruijn> = expected.try_into().unwrap();
let actual = program.inline_reducer();
let actual = program.identity_reducer().inline_reducer();
let actual: Program<NamedDeBruijn> = actual.try_into().unwrap();
@ -2046,7 +2094,7 @@ mod tests {
let expected: Program<NamedDeBruijn> = expected.try_into().unwrap();
let actual = program.inline_reducer();
let actual = program.identity_reducer().inline_reducer();
let actual: Program<NamedDeBruijn> = actual.try_into().unwrap();