Reference nested abstractions instead of skipping them - #377
Open
kavigupta wants to merge 1 commit into
Open
Conversation
When one abstraction is defined in terms of another, DreamCoder inlines the inner one as a nested `#(lambda ...)`. Previously the converter descended into it and failed, skipping the outer abstraction. Each abstraction is added to the DSL under its full `#(lambda ...)` string as its symbol, so build a stitch name_mapping from the abstractions already in the DSL and rewrite inlined occurrences to opaque placeholders (longest first) before the de Bruijn conversion -- then map each placeholder back to the referenced production and emit a reference to it. Composes with lambda fusion: a referenced abstraction inside a fused multi-argument lambda is remapped correctly. If the referenced abstraction is not (yet) in the DSL, the outer one is still skipped. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 3 of 4. Stacks on #376.
What
When one abstraction is defined in terms of another, DreamCoder inlines the inner one as a nested
#(lambda ...). The converter descended into it and failed, skipping the outer abstraction.Each abstraction is added to the DSL under its full
#(lambda ...)string as its symbol. So we build a stitchname_mappingfrom the abstractions already in the DSL and rewrite inlined occurrences to opaque placeholders (longest first, so a nested-in-nested invention isn't mangled) before the de Bruijn conversion — then map each placeholder back to the referenced production and emit a reference.Composes with lambda fusion: a referenced abstraction inside a fused multi-argument lambda is remapped correctly. If the referent isn't in the DSL yet, the outer abstraction is still skipped.
Reproducing test
tests/s_exp/dreamcoder_abstractions_test.py::TestNestedAbstractionReferences#(lambda (gt? 1 (sum $0))):Nonebefore inner is added,[i] -> b(body references the inner production) aftermapi_3lambda →[[i]] -> [b]🤖 Generated with Claude Code