Category: Contextual Completion Correctness Status: Proof-sketch documentation complete; contextual Rocq modules are not present in this repository yet Started: 2025-01-21 Dependencies: Core dictionary backends (Phase 10)
This category contains formal verification documentation for the contextual completion engine in liblevenshtein-rust. Contextual completion provides hierarchical, scope-aware symbol completion with draft buffers, undo/redo support, and efficient incremental updates.
The rholang-language-server depends critically on liblevenshtein's contextual completion for:
Without formal verification, subtle bugs in context management could cause:
Formal verification provides mathematical certainty that:
These theorems unblock formal verification of:
| # | Theorem | Property | Status | Pages |
|---|---|---|---|---|
| 1 | Context Tree Visibility | visible_contexts(ctx) returns all ancestors in order | 🚧 Documenting | 4 |
| 2 | Draft Buffer Consistency | Insert/delete maintain valid UTF-8 boundaries | 🚧 Documenting | 3 |
| 3 | Checkpoint Stack Correctness | Undo restores exact previous state | 🚧 Documenting | 3 |
| 4 | Query Fusion Completeness | complete() returns union of draft + finalized | 🚧 Documenting | 4 |
| 5 | Levenshtein Distance Correctness | Naive $\mathcal{O}(n\cdot m)$ matches formal definition | 🚧 Documenting | 5 |
| 6 | Hierarchical Visibility Soundness | Children see parents, parents don't see children | 🚧 Documenting | 3 |
| 7 | Finalization Atomicity | Draft→dictionary is all-or-nothing | 🚧 Documenting | 4 |
Total: 7 main theorems, ~26 pages of formal documentation
Focused on properties needed for rholang-language-server scope detection:
complete() guaranteesTime: ~1 hour (14 pages)
Full coverage of all correctness properties:
Time: ~2-3 hours (26 pages)
Start with the proof-sketch pages, then compare their assumptions with the existing Rocq core under rocq/liblevenshtein/:
Visibility.v (Theorems 1, 6)DraftBuffer.v (Theorems 2, 3)Query.v (Theorems 4, 5)Finalization.v (Theorem 7)Theorem 1 (Context Visibility)
↓
Theorem 6 (Hierarchical Visibility)
↓
Theorem 4 (Query Fusion) ← Theorem 2 (Draft Consistency)
↑
Theorem 3 (Checkpoint) ← Theorem 2
Theorem 7 (Finalization) ← Theorem 2
Theorem 5 (Distance) - Independent
These theorems assume correct dictionary backends:
See docs/formal-verification/proofs/07_dictionary_backends/README.md for backend theorems.
Core Implementation (src/collection/dawg/contextual_completion/):
context.rs (lines 1-350) - Context tree structure
Context type definitionvisible_contexts() method (Theorem 1, 6)draft_buffer.rs (lines 1-280) - Draft buffer operations
DraftBuffer typeinsert_char(), delete_char() methods (Theorem 2)checkpoint.rs (lines 1-180) - Checkpoint stack
Checkpoint typesave(), restore() methods (Theorem 3)engine.rs (lines 1-650) - Main completion engine
DynamicContextualCompletionEngine typecomplete() method (Theorem 4)levenshtein_distance() helper (Theorem 5)finalize() method (Theorem 7)Unit Tests (src/collection/dawg/contextual_completion/mod.rs::#[cfg(test)]):
test_context_hierarchy_* - Context tree operationstest_draft_buffer_* - Incremental updatestest_checkpoint_* - Undo/redotest_complete_* - Query fusiontest_distance_* - Levenshtein calculationtest_visibility_* - Hierarchical scopingtest_finalize_* - Atomicity guaranteesIntegration Tests (rholang-language-server):
/home/dylon/Workspace/f1r3fly.io/rholang-language-server/tests/test_completion.rs
test_nested_scope_priority_inner - Tests Theorem 1, 4, 6test_local_symbol_priority_inner - Tests Theorem 6Property-test specifications:
Contextual Completion:
docs/algorithms/07-contextual-completion/README.md - Algorithm overviewdocs/algorithms/07-contextual-completion/patterns/ - Design patternsdocs/algorithms/07-contextual-completion/implementation/ - Implementation notesRelated Algorithms:
docs/algorithms/06-zipper-navigation/README.md - PrefixZipper (Theorem 4 depends on this)docs/algorithms/01-dictionary-layer/README.md - Dictionary backends (Theorem 7 depends on this)API Documentation:
cargo doc --open and navigate to:
liblevenshtein::collection::dawg::contextual_completionliblevenshtein::collection::dawg::contextual_completion::engine::DynamicContextualCompletionEngineDeveloper Guide:
docs/developer-guide/ - Contribution guidelinesdocs/examples/06-contextual/ - Usage examplesContextual Completion (general concept):
Levenshtein Distance:
Formal Verification:
/var/tmp/debug/f1r3node/docs/formal-verification/coq/ - Similar Rocq proofs for Rholangrholang-language-server:
/home/dylon/Workspace/f1r3fly.io/rholang-language-server/docs/completion_performance_summary.md
Scope-detection specifications:
/home/dylon/Workspace/f1r3fly.io/rholang-language-server/docs/formal-verification/scope-detection.md
Goal: Create markdown documentation for all 7 theorems
Status: Complete proof-sketch documentation
Progress:
Goal: Formalize types and theorems in Rocq
Candidate modules:
rocq/liblevenshtein/ContextualCompletion/Core.v - Type definitionsrocq/liblevenshtein/ContextualCompletion/Visibility.v - Theorems 1, 6rocq/liblevenshtein/ContextualCompletion/DraftBuffer.v - Theorems 2, 3rocq/liblevenshtein/ContextualCompletion/Query.v - Theorems 4, 5rocq/liblevenshtein/ContextualCompletion/Finalization.v - Theorem 7Priority order: Theorems 1, 2, 4 are the most critical for LSP integration.
Goal: Add property-based tests matching formal specifications
Candidate coverage:
proptestFollow the established pattern from docs/formal-verification/proofs/01_subsumption_properties.md:
Added:
proofs/06_contextual_completion/)Status: Proof-sketch documentation complete; contextual Rocq modules are not present in this repository yet.
This formal verification work is part of the liblevenshtein-rust project and follows the same license (MIT/Apache-2.0).
Last Updated: 2025-01-21 Promotion Policy: These pages are proof-sketch artifacts unless matching checked Rocq modules are added to the manifest.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |