Repository navigation
hash_consing 0.2.0 - #2
Merged
Merged
Conversation
What is interned is now chosen by patterns: a constructor may have several templates, tried in order, the first that matches a term deciding its shape, and a term that none matches stays a plain compound. A nested template requires its constructor, and `;` is no longer an alternative. New predicates declared/1, is_id/1 and represented/2; intern/2 raises existence_error on a constructor without templates. The README lists the changes that break 0.1.0 users. The tests moved from a shell-driven baseline diff to plunit: test/hash_consing.plt, 60 tests, with snapshots in test/hash_consing_snapshots/. upserted/2 now inserts under sig_atomic/1, so that a time limit expiring between the insertion and the write-back of the handle no longer leaves the key pending. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g, and make declarations, insertions and spellings safe across threads
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.
Release 0.2.0. Merging this pull request publishes it: CI tags
V0.2.0and registers the version with the SWI-Prolog pack server.Templates are patterns
What is interned is now chosen by patterns, not by constructors.
*records the root constructor of any argument;;is an ordinary constructor, no longer an alternative.intern/2, the shape written in when the pattern decides it), it must not be (the plain layer, written in place), or it is undetermined (a fresh variable andrepresented/2). A clause is never split, so every clause keeps the meaning it has without interning.declared/1declares templates at run time,is_id/1tells an Id from any other value, andrepresented/2relates a layer to its representation.id_parts/4recognises an Id by looking up the Id functors this process made instead of scanning the name's prefix; alternating the old and the new library three times each on the same benchmark, a call on a plain compound or an Id took about a tenth less.upserted/2inserts undersig_atomic/1, so that a time limit expiring between the insertion and the write-back of the handle no longer leaves the key pending.Interrupted insertions and threads
sig_atomic/1does not hold it off: a limit falling between the insertion and the write-back still left the keypending, and the next lookup raisedtype_error(address, pending).settled_handle/4now repairs such a key at its next lookup.is_id/1answered twice;trie_insert/4raisedpermission_error(modify, trie_key, Term);trie_insert/3failed, and so did its interning.Incompatible changes
The README lists them for 0.1.0 users: the meaning of a nested template;
;; a term no template matches is no longer interned andintern/2fails on it;intern/2raisesexistence_error(templates, Name/Arity)on a constructor without templates instead of declaring it on first use; a rewritten body goal raises an instantiation error when an occurrence whose interning is undetermined is still undecided when the goal is called;*spells the root of any compound or atom instead of-.Tests
The shell-driven baseline diff is replaced by plunit,
test/hash_consing.plt, 65 tests in 10 units, with the rewritten clauses of each fixture compared totest/hash_consing_snapshots/. A warning or an error printed during the run fails it. Run from the root of the pack:Locally and on CI all 65 pass. The unit
interrupted_interninterrupts interning by every inference limit from 1 to 300 and by millisecond time limits; withoutsettled_handle/4it fails at the limit 25. The unitconcurrencyruns eight threads at once; before the mutexes, each of its three tests failed in 5 of 5 runs. The 30 queries of the old test keep their outcomes, and of the old fixtures onlyspinesrenders differently, where a single-layer application its nested template does not match is now a plain compound.🤖 Generated with Claude Code