generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
Context
Follow-up to #307 (B3 Verifier PR). Currently, processes complete B3 programs in batch. This issue proposes adding streaming translation at the declaration level to enable incremental verification and better support for language lifting.
Motivation
- Streaming conversion: Process declarations one at a time as they arrive from other languages
- Incremental verification: Verify procedures as soon as their dependencies are satisfied
- Better modularity: Each declaration type has explicit handling
- Memory efficiency: Avoid building entire B3 AST in memory before verification
Proposed Architecture
ProgramBuilder with Dependency Tracking
structure ProgramBuilder where
verificationState : B3VerificationState -- Emitted to SMT (axioms, functions)
pendingDecls : List (B3AST.Decl SourceRange) -- Waiting for dependencies
reports : List ProcedureReport
errors : List String
-- Core streaming API
def addDeclaration (builder : ProgramBuilder) (decl : B3AST.Decl SourceRange)
: IO ProgramBuilder := do
-- Try to emit this declaration
-- If dependencies satisfied: emit to SMT, check if any pending can now be emitted
-- If dependencies missing: add to pendingDecls
...
def endProgram (builder : ProgramBuilder) : IO (List ProcedureReport × List String) := do
-- Report errors for any remaining pendingDecls with unfulfilled dependencies
...
-- Optional: Manual dependency override
def flushPending (builder : ProgramBuilder) (assumeDependenciesSatisfied : Bool := false)
: IO ProgramBuilder := do
-- If assumeDependenciesSatisfied: emit all pending declarations
-- Otherwise: report errors
...Key Features
- Dependency tracking: Track what each declaration needs (function names, type names)
- Eager emission: Emit to SMT as soon as dependencies are ready
- Buffering: Hold back declarations with unmet dependencies
- Cascade effect: When a declaration is emitted, check if it unblocks pending ones
- Manual override:
flushPendingfor cases where dependencies are known to be satisfied
Use Case: Language Lifting
When lifting from another language to B3:
-- Streaming: emit B3 declarations as you translate
let mut builder ← ProgramBuilder.init solver
for sourceDecl in sourceProgram do
let b3Decl ← liftToB3Declaration sourceDecl
builder ← builder.addDeclaration b3Decl
-- Verification happens automatically when dependencies are met
let (reports, errors) ← builder.endProgramThis avoids building the entire B3 AST in memory before verification starts.
Implementation Notes
- Parameterless procedures are just statements wrapped in push/pop
- Need to track function dependencies (which functions does this declaration reference?)
- Need to track type dependencies (which types does this declaration use?)
- Consider using a dependency graph or topological sort for efficient resolution
Related
- PR Add B3 Verifier: SMT-based verification for B3 programs #307 - B3 Verifier implementation
- Current
programToSMTworks fine for complete programs, this is an enhancement for streaming use cases
Metadata
Metadata
Assignees
Labels
No labels