Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split function body application from name in some cases #1083

Merged
merged 12 commits into from
Jan 12, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle case where write_bits is used without being applied
  • Loading branch information
MicroProofs committed Jan 11, 2025
commit d559e384eca461844e1cdd6392384e5118c9e8ec
4 changes: 4 additions & 0 deletions crates/uplc/src/builder.rs
Original file line number Diff line number Diff line change
@@ -408,6 +408,10 @@ where
pub fn serialise_data() -> Self {
Term::Builtin(DefaultFunction::SerialiseData)
}

pub fn write_bits() -> Self {
Term::Builtin(DefaultFunction::WriteBits)
}
}

impl<T> Term<T>
21 changes: 18 additions & 3 deletions crates/uplc/src/optimize/shrinker.rs
Original file line number Diff line number Diff line change
@@ -1498,6 +1498,7 @@ impl Term<Name> {
}
arg => {
context.write_bits_convert = true;

*arg = Term::var(INDICES_CONVERTER)
.apply(std::mem::replace(arg, Term::Error.force()));
}
@@ -1506,10 +1507,24 @@ impl Term<Name> {
}

Term::Builtin(DefaultFunction::WriteBits) => {
// first arg not needed
arg_stack.pop();
if arg_stack.is_empty() {
context.write_bits_convert = true;

*self = Term::write_bits()
.apply(Term::var("__arg_1"))
.apply(Term::var(INDICES_CONVERTER).apply(Term::var("__arg_2")))
.apply(Term::var("__arg_3"))
.lambda("__arg_3")
.lambda("__arg_2")
.lambda("__arg_1")
} else {
// first arg not needed
arg_stack.pop();

let Some(Args::Apply(arg_id, _)) = arg_stack.pop() else {
return;
};

if let Some(Args::Apply(arg_id, _)) = arg_stack.pop() {
context.write_bits_indices_arg.push(arg_id);
}
}
19 changes: 19 additions & 0 deletions examples/acceptance_tests/117/lib/tests.ak
Original file line number Diff line number Diff line change
@@ -15,3 +15,22 @@ test baz() {
let x = [0, 1, 2, 3]
write_bits(#"f0", x, True) == #"ff"
}

test bur() {
let x =
if True {
[0, 1, 2, 3]
} else {
[0, 1]
}

if False {
fn(_a, _b, _c) { #"" }
} else {
write_bits
}(
#"f0",
x,
True,
) == #"ff"
}
Loading