Support recursive type descriptors#15530
Draft
gldubc wants to merge 1 commit into
Draft
Conversation
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.
Summary
if_setlazy to avoid infinite unfolding during constructionValidation
make compilemake test_stdlib TEST_FILES="module/types/recursive_test.exs"make test_stdlib TEST_FILES="module/types/descr_test.exs"Some extra information
This PR adds a new main data-structure: a type node, which essentially encodes a way to unfold a recursive type and lives next to the descr structure. For instance,
int_list = {integer(), int_list} or nilwill be encoded using a node that can produce the Descr representing{integer(), int_list} or nil.Emptiness detection is done using a simple algorith, with no memoization, that keeps track of which bdds have been encountered before. A memoizing algorith is possible, and could be implemented too if performances becomes an issue, notably when instantiating polymorphic types.
Limitation
Currently, recursive types don't support
opt_*. An easy way to loop: buildand try to compute
opt_intersection(<node X>, <node X>).<node X>unfolds to the descrSo when
opt_intersection/2intersects tuple fields individually, it eventually asks:which unfolds to the same thing again.
Assisted-by: Codex:GPT-5 (writing tests)