diff --git a/kwasm-polkadot-host.md b/kwasm-polkadot-host.md index ba3a023..9fad85f 100644 --- a/kwasm-polkadot-host.md +++ b/kwasm-polkadot-host.md @@ -16,6 +16,7 @@ module KWASM-POLKADOT-HOST imports K-IO imports WASM-TEST imports KWASM-LEMMAS + imports MERGED-RULES configuration @@ -56,6 +57,185 @@ module KWASM-POLKADOT-HOST ... ID |-> IDX:Int ... ... +endmodule +``` + +Merged Rules +============ + +This is a set of rules created by identifying common sub-sequences of semantic steps during execution of the `set_free_balance` function. + +Most rules could not be used as they were printed, but had to be massaged in the following ways. +- Remove cell +- Remove ellipsis inserted under that cell +- Remove ensures +- ~> DotVar\W* => ... +- #init\([^l]\)locals => #init_locals \1 +- S SS => S SS:Stmts +- `BOP` => `BOP:IBinOp`, +- remove `` + +```k +module MERGED-RULES + imports WASM-TEST + + rule + + ( ITYPE0 .const VAL + ~> ITYPE0 . BOP:IBinOp:IBinOp SS => ITYPE0 . BOP C1 VAL modInt #pow( ITYPE0 ) + ~> SS ) + ... + + + ( < ITYPE0 > C1 : VALSTACK0 => VALSTACK0 ) + + ... + + requires notBool SS ==K .EmptyStmts andBool false ==K #pow( ITYPE0 ) ==Int 0 andBool true + [priority(25)] + + rule + + ( #init_locals N VALUE0 : VALUE2 : VALSTACK0 => #init_locals N +Int 2 VALSTACK0 ) + ... + + + + ( LOCALS => LOCALS [ N <- VALUE0 ] [ N +Int 1 <- VALUE2 ] ) + + ... + + ... + + requires true andBool true + [priority(25)] + + rule + + ( ITYPE .const VAL + ~> S SS:Stmts => S + ~> SS ) + ... + + + ( VALSTACK => < ITYPE > VAL modInt #pow( ITYPE ) : VALSTACK ) + + ... + + requires notBool SS ==K .EmptyStmts andBool false ==K #pow( ITYPE ) ==Int 0 andBool true + [priority(25)] + + rule + + ( #init_locals N VALUE0 : VALSTACK => #init_locals N +Int 1 VALSTACK ) + ... + + + + ( LOCALS => LOCALS [ N <- VALUE0 ] ) + + ... + + ... + + requires true andBool true + [priority(25)] + rule + + ( ITYPE0 .const VAL ITYPE0 . BOP:IBinOp SS0 => ITYPE0 . BOP C1 VAL modInt #pow( ITYPE0 ) + ~> SS0 ) + ... + + + ( < ITYPE0 > C1 : VALSTACK0 => VALSTACK0 ) + + ... + + requires notBool SS0 ==K .EmptyStmts andBool false ==K #pow( ITYPE0 ) ==Int 0 andBool true + [priority(25)] + + rule + + ( V + ~> S SS:Stmts => S + ~> SS ) + ... + + + ( VALSTACK => V : VALSTACK ) + + ... + + requires notBool V ==K undefined andBool notBool SS ==K .EmptyStmts +``` + +The following rule required extra massaging: + +- Remove `#Forall` side condition. +- Change #SemanticCastToInt to regular typing. +- Dotvar5 in the `` cell => ... on both sides. + +```k + rule + + ( local.get I:Int + ~> S SS:Stmts => S + ~> SS ) + ... + + + ( VALSTACK => VALUE : VALSTACK ) + + + + ... I |-> VALUE ... + + ... + + ... + + requires notBool SS ==K .EmptyStmts andBool true + [priority(25)] + + rule + + ( local.get I:Int S0 SS0 => S0 + ~> SS0 ) + ... + + + ( VALSTACK => VALUE : VALSTACK ) + + + + ... I |-> VALUE ... + + ... + + ... + + requires notBool SS0 ==K .EmptyStmts + andBool true + [priority(25)] + + rule + + ( local.get I:Int ITYPE0 .const VAL ITYPE0 . BOP:IBinOp SS1 => ITYPE0 . BOP C1 VAL modInt #pow( ITYPE0 ) + ~> SS1 ) + ... + + + + ... I |-> < ITYPE0 > C1 ... + + ... + + ... + + requires notBool SS1 ==K .EmptyStmts andBool false ==K #pow( ITYPE0 ) ==Int 0 andBool true +``` + +```k endmodule ``` diff --git a/search.py b/search.py index e2b2838..08dbdbe 100755 --- a/search.py +++ b/search.py @@ -99,7 +99,7 @@ def wasm_stmts_flattened(stmts, stmtType = 'Stmt'): sys.stdout.flush() if args['command'] == 'summary': - ruleMerges = merge_rules_max_productivity(ruleSeqs, min_merged_success_rate = 0.25, min_occurance_rate = 0.05) + ruleMerges = merge_rules_max_productivity(ruleSeqs, min_merged_success_rate = 0.15, min_occurance_rate = 0.00) mergedRules = tryMergeRules(WASM_definition_haskell_no_coverage_dir, WASM_definition_main_file, WASM_definition_main_module, ruleMerges) for mr in mergedRules: print('Merged Rule:')