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

feat: Distill the EvaluationProgram #183

Merged
merged 15 commits into from
Sep 5, 2024
Merged

Conversation

winston-h-zhang
Copy link
Member

@winston-h-zhang winston-h-zhang commented Aug 1, 2024

This PR adds the distilled program and distilled memory to loam. Here are the changes:

  1. Implemented cons/car/cdr/atom/quote, as well as tests.
  2. Implemented the distilled program.
  3. Implemented the memory distillation process.
  4. Added tests for inconsistent memory.
  5. Added debugging and printing infrastructure for ascent, and for memory distillation.

src/loam/evaluation.rs Outdated Show resolved Hide resolved
src/loam/evaluation.rs Outdated Show resolved Hide resolved
src/loam/evaluation.rs Outdated Show resolved Hide resolved
src/loam/evaluation.rs Outdated Show resolved Hide resolved
src/loam/evaluation.rs Outdated Show resolved Hide resolved
src/loam/evaluation.rs Outdated Show resolved Hide resolved
src/loam/evaluation.rs Outdated Show resolved Hide resolved
src/loam/evaluation.rs Outdated Show resolved Hide resolved
src/loam/evaluation.rs Outdated Show resolved Hide resolved
src/loam/evaluation.rs Outdated Show resolved Hide resolved
src/loam/allocation.rs Outdated Show resolved Hide resolved
ascent! {
#![trace]

struct DistilledAllocationProgram {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good! However, I think you were too aggressive and removed some non-signal relations. In particular, as far as I can tell, there are no surviving hashing rules (or related relations). You can see from first principles that this cannot be correct, since a proof will necessarily prove the hashes. If that weren't the case, it would be possible to falsify the digests.

This would actually be a useful test to add. I'm not being rhetorical, it would strengthen the test suite for memory in general. The test would be to replace digests with random values. If correctly constrained by rules that check the digests, such a randomization should fail. But I think in this DistilledAllocationProgram it will go undetected.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean "assert" in the literal sense, so that a rule takes a join of the digest and relations, and then checks the hash? Otherwise I don't think there's an easy way to write the distilled program to support this, because you have to check the 3 cases of digest/relation/full pointers. For example, if I only want to register a cons_rel if I have a cons_mem but not a cons_digest_mem, ascent doesn't let me write something like:

    cons_rel(car, cdr, cons) <--
        cons_mem(car, cdr, addr), let cons = Ptr(Tag::Cons.elt(), *addr),
        !cons_digest_mem(value, addr);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should discuss further on zulip @porcuquine

src/loam/allocation.rs Outdated Show resolved Hide resolved
src/loam/allocation.rs Outdated Show resolved Hide resolved
Comment on lines 254 to 272
relation eval_car(Ptr, Ptr, Ptr); // (expr, env, body)
relation eval_car_cdr(Ptr, Ptr, Ptr, bool); // (expr, env, body, is_car)

eval_input(body, env), eval_car(expr, env, body) <--
eval_input(expr, env), cons_rel(op, tail, expr), if op.is_car(),
eval_input(body, env), eval_car_cdr(expr, env, body, is_car) <--
eval_input(expr, env), cons_rel(op, tail, expr), if op.is_car_cdr(), let is_car = op.is_car(),
cons_rel(body, end, tail), if end.is_nil();

eval(expr, env, car) <--
eval_car(expr, env, body),
eval_car_cdr(expr, env, body, true),
eval(body, env, evaled),
cons_rel(car, cdr, evaled);

eval(expr, env, cdr) <--
eval_car_cdr(expr, env, body, false),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be taken further. This is really eval_unop, I think. Instead of a bool, you can include op (a Ptr), as in fold and friends. Later, we could remove the tag and just use the symbol address as an optimization.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, same thoughts

src/loam/evaluation.rs Outdated Show resolved Hide resolved
src/loam/evaluation.rs Outdated Show resolved Hide resolved
src/loam/evaluation.rs Outdated Show resolved Hide resolved
src/loam/mod.rs Outdated Show resolved Hide resolved
src/loam/allocation.rs Outdated Show resolved Hide resolved
src/loam/memory.rs Outdated Show resolved Hide resolved
@winston-h-zhang
Copy link
Member Author

I'm going to rename test_distilled to test_second_phase and clean up the testing code slightly.

porcuquine
porcuquine previously approved these changes Sep 4, 2024
Copy link
Collaborator

@porcuquine porcuquine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I didn't scrutinize the actual evaluation programs closely again, but I did review them over time as the work built up. Since that's all in flux anyway, I think this is good to merge now.

Let's try to keep PRs smaller, more focused, and less long-lived now that we're in the next phase of development. Good work.

src/loam/memory.rs Outdated Show resolved Hide resolved
src/loam/memory.rs Outdated Show resolved Hide resolved
@winston-h-zhang winston-h-zhang force-pushed the whz/compact-memory branch 2 times, most recently from 8291411 to 9aeb926 Compare September 5, 2024 23:21
@winston-h-zhang winston-h-zhang merged commit bead3a2 into main Sep 5, 2024
3 checks passed
@winston-h-zhang winston-h-zhang deleted the whz/compact-memory branch September 5, 2024 23:42
@porcuquine
Copy link
Collaborator

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants