Skip to content

3 6 paraphrase echo and diagnostics

TransCompilator edited this page Nov 26, 2026 · 1 revision

3.6 Paraphrase Echo and Diagnostics

Source: https://deepwiki.com/PonvasanthPon/TransCompilator/3-6-paraphrase-echo-and-diagnostics

Paraphrase Echo and Diagnostics

Relevant source files

The following files were used as context for generating this wiki page:

Purpose and Scope

This section covers the semantic front end's diagnostic, tracing, and deterministic paraphrase facilities implemented in tc-semantics. The TransCompilator architecture eschews machine learning in favor of a deterministic zero-ML design. To ensure transparency, inspectability, and rigorous debugging, the compiler maintains two primary audit mechanisms:

  1. Deterministic Paraphrase Echo (tc-semantics/src/paraphrase.rs): Reconstructs canonicalized English statements directly from compiler decisions without re-parsing text.
  2. Structured Diagnostics and Traces (tc-semantics/src/lib.rs): Captures sentence-level provenance (SentenceTrace) and categorizes semantic failures via SemanticErrorKind.

1. Deterministic Paraphrase Echo Architecture

The paraphrase subsystem records semantic actions at the exact moment an anaphor is bound, a condition tree is constructed, or a phrase target is selected. Because entries are captured during lowering, the echo cannot diverge from the generated Core-7 IR.

Core Data Structures

  • ParaphraseEntry ([crates/tc-semantics/src/paraphrase.rs:14-26]()): Holds the source Span, original cleaned text, final IntentVerdict, canonical resolved string, and explicit discourse resolution annotations (e.g., [it -> cash]).
  • ParaphraseDoc ([crates/tc-semantics/src/paraphrase.rs:30-35]()): Groups all ParaphraseEntry records for a single named compilation module in source order.

Canonicalization Functionality

The function canonicalize_statement ([crates/tc-semantics/src/paraphrase.rs:115-181]()) maps recognized syntactic patterns (such as assignments, mutations, and let-bindings) into uniform imperative commands (e.g., converting let x be 10 or x is 10 into Set x to 10.).

graph TD
    NaturalLanguageSpace["Natural Language Input Text"] -->|tokenize_and_analyze| SemanticLowering["Semantic Lowering Engine"]
    SemanticLowering -->|capture_bindings| ParaphraseEntryStruct["ParaphraseEntry Struct"]
    ParaphraseEntryStruct -->|group_by_module| ParaphraseDocStruct["ParaphraseDoc Struct"]
    ParaphraseDocStruct -->|format_paraphrase| FormattedEcho["Formatted Paraphrase Echo"]

    classDef default stroke:#333,fill:#fff;
Loading

Sources: crates/tc-semantics/src/paraphrase.rs:14-89, crates/tc-semantics/src/lib.rs:143-151


2. Semantic Error Taxonomy (SemanticError)

When the semantic analyzer encounters malformed constructs, unhandled computational directives, or type violations, it emits structured diagnostic records.

SemanticErrorKind Variants

The SemanticErrorKind enum ([crates/tc-semantics/src/lib.rs:64-76]) classifies failures into five distinct categories:

  • Segmentation: Source segmentation failed.
  • Declaration: A declaration (such as a Phrase: or module import) was malformed.
  • Lowering: An executable sentence could not be lowered into the AST/IR.
  • Unsupported: A computational directive has no valid Core-7 lowering.
  • TypeCheck: The typed AST failed type checking or IR lowering.
graph TD
    CompilationFailure["Compilation Failure Encountered"] -->|classify| KindSelection{"SemanticErrorKind"}
    KindSelection -->|Segmentation| ErrSeg["Segmentation Error"]
    KindSelection -->|Declaration| ErrDecl["Declaration Error"]
    KindSelection -->|Lowering| ErrLow["Lowering Error"]
    KindSelection -->|Unsupported| ErrUnsup["Unsupported Feature"]
    KindSelection -->|TypeCheck| ErrTC["Type Check Error"]
    
    ErrSeg --> SemanticErrorStruct["SemanticError Struct"]
    ErrDecl --> SemanticErrorStruct
    ErrLow --> SemanticErrorStruct
    ErrUnsup --> SemanticErrorStruct
    ErrTC --> SemanticErrorStruct

    SemanticErrorStruct --> LowerProjectOutcomeStruct["LowerProjectOutcome"]

    classDef default stroke:#333,fill:#fff;
Loading

Sources: crates/tc-semantics/src/lib.rs:64-91, crates/tc-semantics/src/lib.rs:155-163


3. Sentence Provenance and Tracing (SentenceTrace)

Every processed English sentence produces a SentenceTrace record ([crates/tc-semantics/src/lib.rs:106-140]). This structure preserves complete metadata for auditing and language verification:

Field Name Type Description
module String Source module name
line / col u32 One-based source location coordinates
text String Cleaned sentence text
fillers Vec<String> Stripped leading discourse fillers
intent IntentVerdict Three-way intent classification (Exec, CommentOmitted, Unsupported)
lg_used bool True when Link Grammar produced a complete linkage
voice Voice Normalized voice (Active, Passive, etc.)
predicate Option<VerbPredicate> VerbNet predicate classification
concept Option<SemanticConcept> WordNet semantic concept mapping
graph TD
    SourceFileStream["SourceFile Stream"] -->|segment_and_tokenize| SentenceAnalysis["Sentence Analysis Pass"]
    SentenceAnalysis -->|extract_metadata| SentenceTraceStruct["SentenceTrace struct in lib.rs"]
    SentenceTraceStruct -->|aggregate| LoweredProjectStruct["LoweredProject struct"]
    SentenceTraceStruct -->|preserve_on_error| LowerProjectOutcomeStruct["LowerProjectOutcome struct"]

    classDef default stroke:#333,fill:#fff;
Loading

Sources: crates/tc-semantics/src/lib.rs:106-163


4. Suggestion Machinery and Error Reporting

The semantic front end incorporates diagnostic suggestion logic that assists developers in correcting syntactic and semantic slips:

  • Typo Hints: When an unknown verb or variable is encountered, lexical lookup scans available identifiers and open/closed class tables to suggest corrections.
  • Control Anchors: Validates block structures (such as If, Loop, and Phrase) and reports precise column-aligned error messages via SemanticError formatting ([crates/tc-semantics/src/lib.rs:93-100]()).
  • Resilient Outcomes: The LowerProjectOutcome structure ([crates/tc-semantics/src/lib.rs:155-163]()) retains all collected sentence traces even when subsequent statements trigger compilation errors, enabling tooling like language servers (tc-lsp) to provide real-time diagnostic feedback.

Sources: crates/tc-semantics/src/lib.rs:78-103, crates/tc-semantics/src/lib.rs:155-163


Clone this wiki locally