Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #199 from prozacchiwawa/20230725-recompile-check
Browse files Browse the repository at this point in the history
Update recompile check for new tree layout in chia-blockchain
  • Loading branch information
prozacchiwawa committed Jul 26, 2023
2 parents 92476a5 + 4c08b01 commit 8441877
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 34 deletions.
5 changes: 2 additions & 3 deletions src/classic/clvm_tools/stages/stage_2/optimize.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::borrow::Borrow;
use std::cell::{Ref, RefCell};
use std::collections::HashMap;
use std::mem::swap;
Expand Down Expand Up @@ -635,7 +634,7 @@ pub fn optimize_sexp_(
// pass and need to cache the result.
{
let memo_ref: Ref<HashMap<AllocatorRefOrTreeHash, NodePtr>> = memo.borrow();
let memo: &HashMap<AllocatorRefOrTreeHash, NodePtr> = memo_ref.borrow();
let memo: &HashMap<AllocatorRefOrTreeHash, NodePtr> = &memo_ref;
if let Some(res) = memo.get(&AllocatorRefOrTreeHash::new_from_nodeptr(r_)) {
return Ok(*res);
}
Expand All @@ -645,7 +644,7 @@ pub fn optimize_sexp_(
let footprint = AllocatorRefOrTreeHash::new_from_sexp(allocator, r_);
{
let memo_ref: Ref<HashMap<AllocatorRefOrTreeHash, NodePtr>> = memo.borrow();
let memo: &HashMap<AllocatorRefOrTreeHash, NodePtr> = memo_ref.borrow();
let memo: &HashMap<AllocatorRefOrTreeHash, NodePtr> = &memo_ref;
if let Some(res) = memo.get(&footprint) {
return Ok(*res);
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn helper_atom(h: &HelperForm) -> SExp {

fn build_tree(l: Srcloc, s: usize, e: usize, helper_array: &[HelperForm]) -> SExp {
if e - s == 1 {
helper_atom(helper_array[s].borrow())
helper_atom(&helper_array[s])
} else {
let mid = (e + s) / 2;
let car = build_tree(l.clone(), s, mid, helper_array);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ pub fn extract_program_and_env(program: Rc<SExp>) -> Option<(Rc<SExp>, Rc<SExp>)
return None;
}

match (is_apply(&lst[0]), lst[1].borrow(), lst[2].proper_list()) {
match (is_apply(&lst[0]), &lst[1], lst[2].proper_list()) {
(true, real_program, Some(cexp)) => {
if cexp.len() != 3 || !is_cons(&cexp[0]) || !is_whole_env(&cexp[2]) {
None
Expand All @@ -492,7 +492,7 @@ pub fn is_at_capture(head: Rc<SExp>, rest: Rc<SExp>) -> Option<(Vec<u8>, Rc<SExp
if l.len() != 2 {
return None;
}
if let (SExp::Atom(_, a), SExp::Atom(_, cap)) = (head.borrow(), l[0].borrow()) {
if let (SExp::Atom(_, a), SExp::Atom(_, cap)) = (head.borrow(), &l[0]) {
if a == &vec![b'@'] {
return Some((cap.clone(), Rc::new(l[1].clone())));
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ pub fn frontend(
"mod must end on an expression".to_string(),
)),
Some(v) => {
let compiled_val: &CompileForm = v.borrow();
let compiled_val: &CompileForm = &v;
Ok(compiled_val.clone())
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/sexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Display for SExp {
} else {
let vlen = s.len() * 2;
let mut outbuf = vec![0; vlen];
bin2hex(s, &mut outbuf).map_err(|_e| std::fmt::Error::default())?;
bin2hex(s, &mut outbuf).map_err(|_e| std::fmt::Error)?;
formatter.write_str("0x")?;
formatter.write_str(
std::str::from_utf8(&outbuf).expect("only hex digits expected"),
Expand Down Expand Up @@ -781,7 +781,7 @@ where
for this_char in s {
let next_location = start.clone().advance(this_char);

match parse_sexp_step(start.clone(), parse_state.borrow(), this_char) {
match parse_sexp_step(start.clone(), &parse_state, this_char) {
SExpParseResult::Error(l, e) => {
return Err((l, e));
}
Expand Down
85 changes: 60 additions & 25 deletions support/recompile_check.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,55 @@
import os
from pathlib import Path
import subprocess
import traceback

FULL_NODE='chia/full_node/puzzles'
CAT_WALLET='chia/wallet/cat_wallet/puzzles'
DID_WALLET='chia/wallet/did_wallet/puzzles'
NFT_WALLET='chia/wallet/nft_wallet/puzzles'
POOLS='chia/pools/puzzles'
CONSENSUS='chia/consensus/puzzles'
GENTEST='tests/generator/puzzles'

def full_node(x):
return {'fname': x, 'dirname': FULL_NODE}

def cat_wallet(x):
return {'fname': x, 'dirname': CAT_WALLET}

def did_wallet(x):
return {'fname': x, 'dirname': DID_WALLET}

def nft_wallet(x):
return {'fname': x, 'dirname': NFT_WALLET}

def pools(x):
return {'fname': x, 'dirname': POOLS}

def consensus(x):
return {'fname': x, 'dirname': CONSENSUS}

def gentest(x):
return {'fname': x, 'dirname': GENTEST}

recompile_list = [
'block_program_zero.clsp',
'calculate_synthetic_public_key.clsp',
'chialisp_deserialisation.clsp',
'decompress_coin_spend_entry.clsp',
'decompress_coin_spend_entry_with_prefix.clsp',
'decompress_puzzle.clsp',
'delegated_tail.clsp',
'did_innerpuz.clsp',
'everything_with_signature.clsp',
'genesis_by_coin_id.clsp',
'genesis_by_puzzle_hash.clsp',
'nft_metadata_updater_default.clsp',
'nft_metadata_updater_updateable.clsp',
'nft_ownership_layer.clsp',
'nft_ownership_transfer_program_one_way_claim_with_royalties.clsp',
'nft_state_layer.clsp',
full_node('block_program_zero.clsp'),
full_node('decompress_coin_spend_entry.clsp'),
full_node('decompress_coin_spend_entry_with_prefix.clsp'),
full_node('decompress_puzzle.clsp'),
cat_wallet('delegated_tail.clsp'),
cat_wallet('everything_with_signature.clsp'),
cat_wallet('genesis_by_coin_id.clsp'),
cat_wallet('genesis_by_puzzle_hash.clsp'),
did_wallet('did_innerpuz.clsp'),
nft_wallet('nft_metadata_updater_default.clsp'),
nft_wallet('nft_metadata_updater_updateable.clsp'),
nft_wallet('nft_ownership_layer.clsp'),
nft_wallet('nft_ownership_transfer_program_one_way_claim_with_royalties.clsp'),
nft_wallet('nft_state_layer.clsp'),
pools('pool_member_innerpuz.clsp'),
pools('pool_waitingroom_innerpuz.clsp'),
consensus('rom_bootstrap_generator.clsp'),
'p2_conditions.clsp',
'p2_delegated_conditions.clsp',
'p2_delegated_puzzle.clsp',
Expand All @@ -27,24 +58,28 @@
'p2_puzzle_hash.clsp',
'p2_singleton.clsp',
'p2_singleton_or_delayed_puzhash.clsp',
'pool_member_innerpuz.clsp',
'pool_waitingroom_innerpuz.clsp',
'rom_bootstrap_generator.clsp',
'settlement_payments.clsp',
'sha256tree_module.clsp',
'singleton_launcher.clsp',
'singleton_top_layer.clsp',
'singleton_top_layer_v1_1.clsp',
'test_generator_deserialize.clsp',
'test_multiple_generator_input_arguments.clsp'
gentest('test_generator_deserialize.clsp'),
gentest('test_multiple_generator_input_arguments.clsp')
]

for fname in recompile_list:
hexfile = f'./chia/wallet/puzzles/{fname}.hex'
for recompile_entry in recompile_list:
if 'dirname' in recompile_entry and 'fname' in recompile_entry:
dirname = recompile_entry['dirname']
filename = recompile_entry['fname']
else:
filename = recompile_entry
dirname = 'chia/wallet/puzzles'

srcfile = str(Path(dirname) / Path(filename))
hexfile = f'{str(srcfile)}.hex'
hexdata = open(hexfile).read().strip()
os.unlink(hexfile)
try:
compiled = subprocess.check_output(['../target/release/run', '-i', 'chia/wallet/puzzles/', f'chia/wallet/puzzles/{fname}']).strip()
compiled = subprocess.check_output(['../target/release/run', '-i', dirname, '-i', 'chia/wallet/puzzles', srcfile]).strip()
recompile = subprocess.check_output(['../target/release/opc', compiled]).decode('utf8').strip()
except:
print(f'compiling {fname}')
Expand Down

0 comments on commit 8441877

Please sign in to comment.