diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d01803764..fd5a1c11d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,7 @@ jobs: - name: Build and test Strata uses: leanprover/lean-action@v1 - name: Build and run StrataVerify - run: lake exe StrataVerify Examples/SimpleProc.boogie.st + run: lake exe StrataVerify Examples/SimpleProc.core.st - name: Build BoogieToStrata run: dotnet build -warnaserror ${SOLUTION} - name: Test BoogieToStrata diff --git a/.kiro/steering/plausible-instructions.md b/.kiro/steering/plausible-instructions.md index 0e31357a8..95164fabb 100644 --- a/.kiro/steering/plausible-instructions.md +++ b/.kiro/steering/plausible-instructions.md @@ -63,7 +63,7 @@ instance : Shrinkable (α × β) where ``` ### Strata-Specific Types -For Lambda expressions, Imperative statements, or Boogie constructs, ensure generators produce well-typed, valid AST nodes. +For Lambda expressions, Imperative statements, or Strata Core constructs, ensure generators produce well-typed, valid AST nodes. ## Usage Modes diff --git a/.kiro/steering/structure.md b/.kiro/steering/structure.md index 9fc46dc8a..4370bb3e8 100644 --- a/.kiro/steering/structure.md +++ b/.kiro/steering/structure.md @@ -6,7 +6,7 @@ inclusion: always ## Overview -Strata is a Lean4 verification framework using **dialects** as composable language building blocks. The primary target is the **Boogie dialect** for deductive program verification. +Strata is a Lean4 verification framework using **dialects** as composable language building blocks. The primary target is the **Strata Core dialect** for deductive program verification. ## Repository Structure @@ -27,19 +27,23 @@ Strata is a Lean4 verification framework using **dialects** as composable langua **`Strata/DL/`** - Dialect Library - `Lambda/` - Pure functional expressions (base layer) - `Imperative/` - Statements with control flow (builds on Lambda) -- `SMT/` - SMT-LIB encoding and solver interface +- `SMT/` - The SMT-LIB standard definition and its solver interface - `Util/` - Shared utilities (maps, lists, string generation) **`Strata/Languages/`** - Concrete Language Implementations -- `Boogie/` - Primary verification language (procedures, contracts, VCG, SMT encoding) +- `Core/` - Primary verification language (procedures, contracts, VCG, SMT encoding) - `C_Simp/` - Simplified C-like language - `Dyn/` - Dynamic language example +- `Laurel/` - A common representation for front-end languages like Java, Python and JavaScript. +Translated to Core. +- `Python/` - The well-known Python language **`Strata/Transform/`** - Program Transformations - Each transformation has implementation + optional correctness proof (`*Correct.lean`) +- `CallElim` - Procedure call elimination via inlining the contract - `DetToNondet` - Deterministic to non-deterministic control flow -- `CallElim` - Procedure call elimination via inlining - `LoopElim` - Loop elimination using invariants +- `ProcedureInlining` - Procedure call elimination via inlining the body **`Strata/Backends/`** - Verification Backends - `CBMC/` - C Bounded Model Checker integration @@ -51,7 +55,7 @@ Strata is a Lean4 verification framework using **dialects** as composable langua Dialects are composable language layers, each defining syntax, types, and semantics: - **Lambda** - Base expression layer (functional) - **Imperative** - Adds statements and control flow (uses Lambda expressions) -- **Boogie** - Adds procedures, contracts, and verification (uses Imperative statements) +- **Strata Core (or simply Core)** - Adds procedures, contracts, and verification (uses Imperative statements) ### Lambda Dialect (Expressions) @@ -84,11 +88,13 @@ Statement-level constructs parameterized by expression and command types: - `StmtSemantics.lean` - Operational semantics - `Cmd.lean` - Command interface -## Boogie Dialect +## The Strata Core Dialect -**Location:** `Strata/Languages/Boogie/` +**Location:** `Strata/Languages/Core/` -Intermediate Verification Language for deductive program verification, mirroring the [Boogie verifier](https://github.com/boogie-org/boogie). +Intermediate Verification Language for deductive program verification. +Its syntax is highly motivated by the [Boogie verifier](https://github.com/boogie-org/boogie), +but has additional convenient syntactic features. ### Types (`Factory.lean`) - Primitives: `bool`, `int`, `real`, `bv`, `string` @@ -129,8 +135,8 @@ Top-level structure: ## Other Languages **C_Simp** (`Strata/Languages/C_Simp/`) - Simplified C-like language -- Verification via transformation to Boogie -- Pipeline: Parse → Transform loops → Translate to Boogie → VCG → SMT +- Verification via transformation to Strata Core +- Pipeline: Parse → Transform loops → Translate to Strata Core → VCG → SMT **Dyn** (`Strata/Languages/Dyn/`) - Dynamic language example demonstrating dialect extensibility @@ -158,13 +164,13 @@ Program-to-program translations for simplification and verification. Each has op | Expression types | `Strata/DL/Lambda/LTy.lean` | | Statement AST | `Strata/DL/Imperative/Stmt.lean` | | Statement semantics | `Strata/DL/Imperative/StmtSemantics.lean` | -| Boogie expressions | `Strata/Languages/Boogie/Expressions.lean` | -| Boogie commands | `Strata/Languages/Boogie/Statement.lean` | -| Boogie procedures | `Strata/Languages/Boogie/Procedure.lean` | -| Boogie programs | `Strata/Languages/Boogie/Program.lean` | -| Boogie operators | `Strata/Languages/Boogie/Factory.lean` | -| Boogie VCG | `Strata/Languages/Boogie/Verifier.lean` | -| SMT encoding | `Strata/Languages/Boogie/SMTEncoder.lean` | +| Strata Core expressions | `Strata/Languages/Core/Expressions.lean` | +| Strata Core commands | `Strata/Languages/Core/Statement.lean` | +| Strata Core procedures | `Strata/Languages/Core/Procedure.lean` | +| Strata Core programs | `Strata/Languages/Core/Program.lean` | +| Strata Core operators | `Strata/Languages/Core/Factory.lean` | +| Strata Core VCG | `Strata/Languages/Core/Verifier.lean` | +| SMT encoding | `Strata/Languages/Core/SMTEncoder.lean` | | SMT solver | `Strata/DL/SMT/Solver.lean` | | Transformations | `Strata/Transform/*.lean` | @@ -175,21 +181,21 @@ Program-to-program translations for simplification and verification. Each has op **Executables:** - `StrataVerify` - Main verifier -- `BoogieToGoto` - Boogie to GOTO translation +- `StrataCoreToGoto` - Strata Core to GOTO translation - `StrataToCBMC` - CBMC backend **Commands:** ```bash lake build # Build all lake test # Run tests -lake exe StrataVerify Examples/SimpleProc.boogie.st # Verify program +lake exe StrataVerify Examples/SimpleProc.core.st # Verify program ``` ## Verification Workflow -1. Write program (`.boogie.st` file) +1. Write program (`.core.st` file) 2. Parse (DDM parser) -3. Type check (Boogie type system) +3. Type check (Strata Core's type system) 4. Transform (optional: eliminate calls/loops) 5. Generate VCs (symbolic execution) 6. Encode to SMT (SMT-LIB format) @@ -204,7 +210,7 @@ Generated VCs saved in `vcs/*.smt2` Before starting any implementation task: -1. **Identify the layer** you're working on (Lambda, Imperative, Boogie, Transform) +1. **Identify the layer** you're working on (Lambda, Imperative, Strata Core, Transform) 2. **Read the core files** for that layer from the Key Files Quick Reference table 3. **Read related files** in the same directory to understand patterns and conventions 4. **Check for similar implementations** in other dialects or transformations @@ -212,7 +218,7 @@ Before starting any implementation task: **Example workflows:** -- **Adding a Boogie feature:** Read `Expressions.lean`, `Statement.lean`, `Factory.lean`, then check `StrataTest/Languages/Boogie/` for test patterns +- **Adding a feature to Strata Core:** Read `Expressions.lean`, `Statement.lean`, `Factory.lean`, then check `StrataTest/Languages/Core/` for test patterns - **Creating a transformation:** Read existing transforms (`DetToNondet.lean`, `CallElim.lean`), their correctness proofs, and tests in `StrataTest/Transform/` - **Modifying expressions:** Read `Strata/DL/Lambda/LExpr.lean`, `LExprEval.lean`, `LTy.lean` to understand the AST, evaluation, and type system - **Working with statements:** Read `Strata/DL/Imperative/Stmt.lean` and `StmtSemantics.lean` before making changes @@ -223,7 +229,7 @@ Before starting any implementation task: - **File organization:** Mirror test structure in `StrataTest/` to match `Strata/` - **Naming:** Use descriptive names; transformations end with `Correct.lean` for proofs -- **Example files:** Use pattern `..st` (e.g., `SimpleProc.boogie.st`) +- **Example files:** Use pattern `..st` (e.g., `SimpleProc.core.st`) - **Proofs:** Transformation correctness proofs are optional but encouraged - **Documentation:** Reference `docs/Architecture.md` for design philosophy, `docs/GettingStarted.md` for tutorials @@ -231,6 +237,6 @@ Before starting any implementation task: - **Expressions:** Start with Lambda dialect (`Strata/DL/Lambda/`) - **Statements:** Build on Imperative dialect (`Strata/DL/Imperative/`) -- **New languages:** Extend existing dialects, follow Boogie as reference +- **New languages:** Extend existing dialects, follow Strata Core as reference - **Transformations:** Implement in `Strata/Transform/`, add tests in `StrataTest/Transform/` - **Testing:** Add examples in `Examples/`, unit tests and property-based tests in `StrataTest/` diff --git a/.kiro/steering/testing-transformations.md b/.kiro/steering/testing-transformations.md index 90e906a4c..bc72ab918 100644 --- a/.kiro/steering/testing-transformations.md +++ b/.kiro/steering/testing-transformations.md @@ -19,11 +19,11 @@ Use Plausible for property-based testing of transformations. Three-step process: - Statements: commands (assign, assert, assume, havoc), control flow (if, loop, block) - Bias towards operations over constants for interesting tests -**Key types from `Strata/Languages/Boogie/`:** +**Key types from `Strata/Languages/Core/`:** - `Expression.Expr` (Expressions.lean) - `Statement` (Statement.lean) - `Command` (atomic operations) -- `BoogieIdent` (identifiers) +- `CoreIdent` (identifiers) ## Measurement Functions @@ -78,8 +78,8 @@ Write **total** (not `partial`) Lean functions to measure program properties. |-----------|----------| | Expression AST | `Strata/DL/Lambda/LExpr.lean` | | Statement AST | `Strata/DL/Imperative/Stmt.lean` | -| Boogie expressions | `Strata/Languages/Boogie/Expressions.lean` | -| Boogie statements | `Strata/Languages/Boogie/Statement.lean` | +| Strata Core expressions | `Strata/Languages/Core/Expressions.lean` | +| Strata Core statements | `Strata/Languages/Core/Statement.lean` | | Transformations | `Strata/Transform/*.lean` | | Transform tests | `StrataTest/Transform/*.lean` | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9ccb068cc..ff2a0d7a3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,7 +37,7 @@ this can be okay. However, because we aim for it to be possible to verify core functionality, we prefer that operations over programs or terms -- such as transformations, verification condition generation, or testing -- be total functions and that this fact can, at least in -principle, be proved. That a function is total is also usually a +principle, be proved. That a function is total is also usually a prerequisite for any proofs that use the function in question. In some cases, however, it may be valuable to prove properties of code @@ -131,9 +131,7 @@ main purposes: components (e.g., just the DDM, just the partial evaluator of a specific dialect, etc.). These tests serve as guides to understand how to set up, use, and compose these core components. - -* In the `Examples` directories (e.g., - `Strata/Languages/[Boogie|C_Simp]/Examples`), which showcase + `StrataTest/Languages/[Core|C_Simp]/Examples` showcases end-to-end Strata applications and may include output from external solvers. diff --git a/Examples/HeapReasoning.boogie.st b/Examples/HeapReasoning.core.st similarity index 97% rename from Examples/HeapReasoning.boogie.st rename to Examples/HeapReasoning.core.st index 95ccf814b..4f6b654b7 100644 --- a/Examples/HeapReasoning.boogie.st +++ b/Examples/HeapReasoning.core.st @@ -1,5 +1,5 @@ -program Boogie; -// lake exe StrataVerify Strata/Languages/Boogie/Examples/HeapReasoning.boogie.st +program Core; +// lake exe StrataVerify Examples/HeapReasoning.core.st // Prelude begin -------------------------------------------------- type Ref; @@ -76,8 +76,8 @@ spec { requires allocationTime(initialNext) < tickingClock; requires isContainer(r); - free ensures (forall o: Ref :: - { newHeap[o] } + free ensures (forall o: Ref :: + { newHeap[o] } (o != null && allocationTime(o) >= 0 && allocationTime(o) < old(tickingClock)) ==> (newHeap[o] == heap[o] || o == r)); @@ -132,8 +132,8 @@ spec { ensures tickingClock >= old(tickingClock); - free ensures (forall o: Ref :: - { newHeap[o] } + free ensures (forall o: Ref :: + { newHeap[o] } (o != null && allocationTime(o) >= 0 && allocationTime(o) < old(tickingClock)) ==> (newHeap[o] == heap[o] || o == ref1)); @@ -197,8 +197,8 @@ spec { free requires tickingClock >= 0; ensures tickingClock >= old(tickingClock); - free ensures (forall o: Ref :: - { newHeap[o] } + free ensures (forall o: Ref :: + { newHeap[o] } (o != null && allocationTime(o) >= 0 && allocationTime(o) < old(tickingClock)) ==> (newHeap[o] == heap[o])); } diff --git a/Examples/LoopSimple.boogie.st b/Examples/LoopSimple.core.st similarity index 95% rename from Examples/LoopSimple.boogie.st rename to Examples/LoopSimple.core.st index 835a77a6d..139c3573a 100644 --- a/Examples/LoopSimple.boogie.st +++ b/Examples/LoopSimple.core.st @@ -1,4 +1,4 @@ -program Boogie; +program Core; procedure loopSimple (n: int) returns (r: int) spec { diff --git a/Examples/SimpleProc.boogie.st b/Examples/SimpleProc.core.st similarity index 97% rename from Examples/SimpleProc.boogie.st rename to Examples/SimpleProc.core.st index 8c909fe95..4adbad260 100644 --- a/Examples/SimpleProc.boogie.st +++ b/Examples/SimpleProc.core.st @@ -1,4 +1,4 @@ -program Boogie; +program Core; // // Copyright Strata Contributors // diff --git a/Examples/TypeError.boogie.st b/Examples/TypeError.core.st similarity index 98% rename from Examples/TypeError.boogie.st rename to Examples/TypeError.core.st index 386db3dd4..c52319fd5 100644 --- a/Examples/TypeError.boogie.st +++ b/Examples/TypeError.core.st @@ -1,4 +1,4 @@ -program Boogie; +program Core; // // Copyright Strata Contributors // diff --git a/Examples/expected/HeapReasoning.boogie.expected b/Examples/expected/HeapReasoning.boogie.expected deleted file mode 100644 index 4bb12ba2c..000000000 --- a/Examples/expected/HeapReasoning.boogie.expected +++ /dev/null @@ -1,55 +0,0 @@ -Successfully parsed. -HeapReasoning.boogie.st(99, 2) [modifiesFrameRef1]: ✅ pass -HeapReasoning.boogie.st(104, 2) [modifiesFrameRef1]: ✅ pass -HeapReasoning.boogie.st(109, 2) [modifiesFrameRef1]: ✅ pass - [Container_ctor_ensures_4]: ✅ pass -HeapReasoning.boogie.st(87, 2) [Container_ctor_ensures_7]: ✅ pass -HeapReasoning.boogie.st(88, 2) [Container_ctor_ensures_8]: ✅ pass -HeapReasoning.boogie.st(89, 2) [Container_ctor_ensures_9]: ✅ pass -HeapReasoning.boogie.st(91, 2) [Container_ctor_ensures_10]: ✅ pass -HeapReasoning.boogie.st(165, 2) [modifiesFrameRef1]: ✅ pass -HeapReasoning.boogie.st(170, 2) [modifiesFrameRef2]: ✅ pass -HeapReasoning.boogie.st(173, 2) [modifiesFrameRef1Next]: ✅ pass -HeapReasoning.boogie.st(178, 2) [modifiesFrameRef2Next]: ✅ pass -HeapReasoning.boogie.st(133, 2) [UpdateContainers_ensures_5]: ✅ pass - [UpdateContainers_ensures_6]: ✅ pass -HeapReasoning.boogie.st(151, 2) [UpdateContainers_ensures_14]: ✅ pass -HeapReasoning.boogie.st(152, 2) [UpdateContainers_ensures_15]: ✅ pass -HeapReasoning.boogie.st(153, 2) [UpdateContainers_ensures_16]: ✅ pass -HeapReasoning.boogie.st(154, 2) [UpdateContainers_ensures_17]: ✅ pass -HeapReasoning.boogie.st(156, 2) [UpdateContainers_ensures_18]: ✅ pass -HeapReasoning.boogie.st(157, 2) [UpdateContainers_ensures_19]: ✅ pass -HeapReasoning.boogie.st(75, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_1]: ✅ pass -HeapReasoning.boogie.st(76, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_2]: ✅ pass -HeapReasoning.boogie.st(77, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_3]: ✅ pass -HeapReasoning.boogie.st(85, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_5]: ✅ pass -HeapReasoning.boogie.st(86, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_6]: ✅ pass -HeapReasoning.boogie.st(216, 2) [c1Lychees0]: ✅ pass -HeapReasoning.boogie.st(217, 2) [c1Pineapple1]: ✅ pass -HeapReasoning.boogie.st(75, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_1]: ✅ pass -HeapReasoning.boogie.st(76, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_2]: ✅ pass -HeapReasoning.boogie.st(77, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_3]: ✅ pass -HeapReasoning.boogie.st(85, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_5]: ✅ pass -HeapReasoning.boogie.st(86, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_6]: ✅ pass -HeapReasoning.boogie.st(227, 2) [assert_9]: ✅ pass -HeapReasoning.boogie.st(232, 2) [assert_10]: ✅ pass -HeapReasoning.boogie.st(127, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_1]: ✅ pass -HeapReasoning.boogie.st(128, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_2]: ✅ pass -HeapReasoning.boogie.st(130, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_3]: ✅ pass -HeapReasoning.boogie.st(131, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_4]: ✅ pass -HeapReasoning.boogie.st(141, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_7]: ✅ pass -HeapReasoning.boogie.st(143, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_8]: ✅ pass -HeapReasoning.boogie.st(144, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_9]: ✅ pass -HeapReasoning.boogie.st(146, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_10]: ✅ pass -HeapReasoning.boogie.st(147, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_11]: ✅ pass -HeapReasoning.boogie.st(148, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_12]: ✅ pass -HeapReasoning.boogie.st(149, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_13]: ✅ pass -HeapReasoning.boogie.st(238, 2) [c1Lychees1]: ✅ pass -HeapReasoning.boogie.st(239, 2) [c1Pineapple2]: ✅ pass -HeapReasoning.boogie.st(240, 2) [c2Lychees0]: ✅ pass -HeapReasoning.boogie.st(241, 2) [c2Pineapple0]: ✅ pass -HeapReasoning.boogie.st(243, 2) [c1NextEqC2]: ✅ pass -HeapReasoning.boogie.st(244, 2) [c2NextEqC1]: ✅ pass -HeapReasoning.boogie.st(198, 2) [Main_ensures_2]: ✅ pass - [Main_ensures_3]: ✅ pass -All 53 goals passed. diff --git a/Examples/expected/HeapReasoning.core.expected b/Examples/expected/HeapReasoning.core.expected new file mode 100644 index 000000000..dfe411735 --- /dev/null +++ b/Examples/expected/HeapReasoning.core.expected @@ -0,0 +1,55 @@ +Successfully parsed. +HeapReasoning.core.st(99, 2) [modifiesFrameRef1]: ✅ pass +HeapReasoning.core.st(104, 2) [modifiesFrameRef1]: ✅ pass +HeapReasoning.core.st(109, 2) [modifiesFrameRef1]: ✅ pass + [Container_ctor_ensures_4]: ✅ pass +HeapReasoning.core.st(87, 2) [Container_ctor_ensures_7]: ✅ pass +HeapReasoning.core.st(88, 2) [Container_ctor_ensures_8]: ✅ pass +HeapReasoning.core.st(89, 2) [Container_ctor_ensures_9]: ✅ pass +HeapReasoning.core.st(91, 2) [Container_ctor_ensures_10]: ✅ pass +HeapReasoning.core.st(165, 2) [modifiesFrameRef1]: ✅ pass +HeapReasoning.core.st(170, 2) [modifiesFrameRef2]: ✅ pass +HeapReasoning.core.st(173, 2) [modifiesFrameRef1Next]: ✅ pass +HeapReasoning.core.st(178, 2) [modifiesFrameRef2Next]: ✅ pass +HeapReasoning.core.st(133, 2) [UpdateContainers_ensures_5]: ✅ pass + [UpdateContainers_ensures_6]: ✅ pass +HeapReasoning.core.st(151, 2) [UpdateContainers_ensures_14]: ✅ pass +HeapReasoning.core.st(152, 2) [UpdateContainers_ensures_15]: ✅ pass +HeapReasoning.core.st(153, 2) [UpdateContainers_ensures_16]: ✅ pass +HeapReasoning.core.st(154, 2) [UpdateContainers_ensures_17]: ✅ pass +HeapReasoning.core.st(156, 2) [UpdateContainers_ensures_18]: ✅ pass +HeapReasoning.core.st(157, 2) [UpdateContainers_ensures_19]: ✅ pass +HeapReasoning.core.st(75, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_1]: ✅ pass +HeapReasoning.core.st(76, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_2]: ✅ pass +HeapReasoning.core.st(77, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_3]: ✅ pass +HeapReasoning.core.st(85, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_5]: ✅ pass +HeapReasoning.core.st(86, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_6]: ✅ pass +HeapReasoning.core.st(216, 2) [c1Lychees0]: ✅ pass +HeapReasoning.core.st(217, 2) [c1Pineapple1]: ✅ pass +HeapReasoning.core.st(75, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_1]: ✅ pass +HeapReasoning.core.st(76, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_2]: ✅ pass +HeapReasoning.core.st(77, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_3]: ✅ pass +HeapReasoning.core.st(85, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_5]: ✅ pass +HeapReasoning.core.st(86, 2) [(Origin_Container_ctor_Requires)Container_ctor_requires_6]: ✅ pass +HeapReasoning.core.st(227, 2) [assert_9]: ✅ pass +HeapReasoning.core.st(232, 2) [assert_10]: ✅ pass +HeapReasoning.core.st(127, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_1]: ✅ pass +HeapReasoning.core.st(128, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_2]: ✅ pass +HeapReasoning.core.st(130, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_3]: ✅ pass +HeapReasoning.core.st(131, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_4]: ✅ pass +HeapReasoning.core.st(141, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_7]: ✅ pass +HeapReasoning.core.st(143, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_8]: ✅ pass +HeapReasoning.core.st(144, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_9]: ✅ pass +HeapReasoning.core.st(146, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_10]: ✅ pass +HeapReasoning.core.st(147, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_11]: ✅ pass +HeapReasoning.core.st(148, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_12]: ✅ pass +HeapReasoning.core.st(149, 2) [(Origin_UpdateContainers_Requires)UpdateContainers_requires_13]: ✅ pass +HeapReasoning.core.st(238, 2) [c1Lychees1]: ✅ pass +HeapReasoning.core.st(239, 2) [c1Pineapple2]: ✅ pass +HeapReasoning.core.st(240, 2) [c2Lychees0]: ✅ pass +HeapReasoning.core.st(241, 2) [c2Pineapple0]: ✅ pass +HeapReasoning.core.st(243, 2) [c1NextEqC2]: ✅ pass +HeapReasoning.core.st(244, 2) [c2NextEqC1]: ✅ pass +HeapReasoning.core.st(198, 2) [Main_ensures_2]: ✅ pass + [Main_ensures_3]: ✅ pass +All 53 goals passed. diff --git a/Examples/expected/LoopSimple.boogie.expected b/Examples/expected/LoopSimple.boogie.expected deleted file mode 100644 index b07c25f11..000000000 --- a/Examples/expected/LoopSimple.boogie.expected +++ /dev/null @@ -1,6 +0,0 @@ -Successfully parsed. -LoopSimple.boogie.st(13, 2) [entry_invariant_0]: ✅ pass -LoopSimple.boogie.st(13, 2) [arbitrary_iter_maintain_invariant_0]: ✅ pass -LoopSimple.boogie.st(19, 2) [sum_assert]: ✅ pass -LoopSimple.boogie.st(20, 2) [neg_cond]: ✅ pass -All 4 goals passed. diff --git a/Examples/expected/LoopSimple.core.expected b/Examples/expected/LoopSimple.core.expected new file mode 100644 index 000000000..d6000ebdd --- /dev/null +++ b/Examples/expected/LoopSimple.core.expected @@ -0,0 +1,6 @@ +Successfully parsed. +LoopSimple.core.st(13, 2) [entry_invariant_0]: ✅ pass +LoopSimple.core.st(13, 2) [arbitrary_iter_maintain_invariant_0]: ✅ pass +LoopSimple.core.st(19, 2) [sum_assert]: ✅ pass +LoopSimple.core.st(20, 2) [neg_cond]: ✅ pass +All 4 goals passed. diff --git a/Examples/expected/SimpleProc.boogie.expected b/Examples/expected/SimpleProc.boogie.expected deleted file mode 100644 index 1432820ea..000000000 --- a/Examples/expected/SimpleProc.boogie.expected +++ /dev/null @@ -1,5 +0,0 @@ -Successfully parsed. -SimpleProc.boogie.st(21, 2) [Test_ensures_0]: ✅ pass -SimpleProc.boogie.st(22, 2) [Test_ensures_1]: ✅ pass -SimpleProc.boogie.st(23, 2) [Test_ensures_2]: ✅ pass -All 3 goals passed. diff --git a/Examples/expected/SimpleProc.core.expected b/Examples/expected/SimpleProc.core.expected new file mode 100644 index 000000000..1af99fbf4 --- /dev/null +++ b/Examples/expected/SimpleProc.core.expected @@ -0,0 +1,5 @@ +Successfully parsed. +SimpleProc.core.st(21, 2) [Test_ensures_0]: ✅ pass +SimpleProc.core.st(22, 2) [Test_ensures_1]: ✅ pass +SimpleProc.core.st(23, 2) [Test_ensures_2]: ✅ pass +All 3 goals passed. diff --git a/Examples/expected/TypeError.boogie.expected b/Examples/expected/TypeError.boogie.expected deleted file mode 100644 index c4324e9dd..000000000 --- a/Examples/expected/TypeError.boogie.expected +++ /dev/null @@ -1,4 +0,0 @@ -Successfully parsed. -❌ Type checking error. -TypeError.boogie.st(25, 2) Impossible to unify (Map int (Map bool bool)) with (Map int int). -First mismatch: (Map bool bool) with int. diff --git a/Examples/expected/TypeError.core.expected b/Examples/expected/TypeError.core.expected new file mode 100644 index 000000000..8d387f6e2 --- /dev/null +++ b/Examples/expected/TypeError.core.expected @@ -0,0 +1,4 @@ +Successfully parsed. +❌ Type checking error. +TypeError.core.st(25, 2) Impossible to unify (Map int (Map bool bool)) with (Map int int). +First mismatch: (Map bool bool) with int. diff --git a/README.md b/README.md index 93949bfa9..ddb685e14 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Unit tests are run with `#guard_msgs` commands. No output means the tests passed ## Running Analyses on Existing Strata Programs Strata programs use the `.st` file extension, preceded by the dialect name, -preceded by a second `.` e.g., `SimpleProc.boogie.st` or +preceded by a second `.` e.g., `SimpleProc.core.st` or `LoopSimple.csimp.st`. Note the current `StrataVerify` executable relies on this file extension convention to know what dialect it's parsing (since the Strata IR allows a program to open multiple @@ -51,7 +51,7 @@ dialects). Here is an example invocation that runs Strata's deductive verifier. ```bash -lake exe StrataVerify Examples/SimpleProc.boogie.st +lake exe StrataVerify Examples/SimpleProc.core.st ``` This will: diff --git a/Strata.lean b/Strata.lean index 5c5225eef..15e58f612 100644 --- a/Strata.lean +++ b/Strata.lean @@ -15,8 +15,8 @@ import Strata.DL.SMT.SMT import Strata.DL.Lambda.Lambda import Strata.DL.Imperative.Imperative -/- Boogie -/ -import Strata.Languages.Boogie.StatementSemantics +/- Strata Core -/ +import Strata.Languages.Core.StatementSemantics /- Code Transforms -/ import Strata.Transform.CallElimCorrect diff --git a/Strata/Backends/CBMC/BoogieToCBMC.lean b/Strata/Backends/CBMC/CoreToCBMC.lean similarity index 90% rename from Strata/Backends/CBMC/BoogieToCBMC.lean rename to Strata/Backends/CBMC/CoreToCBMC.lean index a1071601f..b77b9b755 100644 --- a/Strata/Backends/CBMC/BoogieToCBMC.lean +++ b/Strata/Backends/CBMC/CoreToCBMC.lean @@ -5,21 +5,21 @@ -/ import Lean.Data.Json -import Strata.Languages.Boogie.Env -import Strata.Languages.Boogie.DDMTransform.Parse -import Strata.Languages.Boogie.DDMTransform.Translate +import Strata.Languages.Core.Env +import Strata.Languages.Core.DDMTransform.Parse +import Strata.Languages.Core.DDMTransform.Translate import Strata.DL.Util.Map -import Strata.Languages.Boogie.Boogie +import Strata.Languages.Core.Core import Strata.Backends.CBMC.Common open Lean open Strata.CBMC -namespace Boogie +namespace Core -- Our test program def SimpleTestEnv := #strata -program Boogie; +program Core; procedure simpleTest(x : int, y : int) returns (ret : int) spec { @@ -34,10 +34,10 @@ spec { }; #end -open Boogie in +open Core in def SimpleTestEnvAST := Strata.TransM.run Inhabited.default (Strata.translateProgram (SimpleTestEnv)) -def myProc : Boogie.Procedure := match SimpleTestEnvAST.fst.decls.head!.getProc? with +def myProc : Core.Procedure := match SimpleTestEnvAST.fst.decls.head!.getProc? with | .some p => p | .none => panic! "Expected procedure" @@ -45,7 +45,7 @@ def myProc : Boogie.Procedure := match SimpleTestEnvAST.fst.decls.head!.getProc? class IdentToStr (I : Type) where toStr : I → String -instance : IdentToStr BoogieIdent where +instance : IdentToStr CoreIdent where toStr id := id.toPretty instance : IdentToStr String where @@ -54,7 +54,7 @@ instance : IdentToStr String where class HasLExpr (P : Imperative.PureExpr) (I : Lambda.LExprParams) where expr_eq : P.Expr = Lambda.LExpr I.mono -instance : HasLExpr Boogie.Expression BoogieLParams where +instance : HasLExpr Core.Expression CoreLParams where expr_eq := rfl def exprToJson (I : Lambda.LExprParams) [IdentToStr (Lambda.Identifier I.IDMeta)] (e : Lambda.LExpr I.mono) (loc: SourceLoc) : Json := @@ -79,7 +79,7 @@ def exprToJson (I : Lambda.LExprParams) [IdentToStr (Lambda.Identifier I.IDMeta) mkLvalueSymbol s!"{loc.functionName}::{IdentToStr.toStr name}" loc.lineNum loc.functionName | _ => panic! "Unimplemented" -def cmdToJson (e : Boogie.Command) (loc: SourceLoc) : Json := +def cmdToJson (e : Core.Command) (loc: SourceLoc) : Json := match e with | .call _ _ _ _ => panic! "Not supported" | .cmd c => @@ -102,7 +102,7 @@ def cmdToJson (e : Boogie.Command) (loc: SourceLoc) : Json := mkCodeBlock "expression" "6" loc.functionName #[ mkSideEffect "assign" "6" loc.functionName mkIntType #[ mkLvalueSymbol s!"{loc.functionName}::1::{name.toPretty}" "6" loc.functionName, - exprToJson (I:=BoogieLParams) expr exprLoc + exprToJson (I:=CoreLParams) expr exprLoc ] ] | .assert label expr _ => @@ -127,7 +127,7 @@ def cmdToJson (e : Boogie.Command) (loc: SourceLoc) : Json := Json.mkObj [ ("id", "arguments"), ("sub", Json.arr #[ - exprToJson (I:=BoogieLParams) expr exprLoc, + exprToJson (I:=CoreLParams) expr exprLoc, mkStringConstant label "7" loc.functionName ]) ] @@ -155,7 +155,7 @@ def cmdToJson (e : Boogie.Command) (loc: SourceLoc) : Json := Json.mkObj [ ("id", "arguments"), ("sub", Json.arr #[ - exprToJson (I:=BoogieLParams) expr exprLoc + exprToJson (I:=CoreLParams) expr exprLoc ]) ] ] @@ -207,11 +207,11 @@ def stmtToJson {P : Imperative.PureExpr} (I : Lambda.LExprParams) [IdentToStr (L decreasing_by all_goals(simp; omega) end -def listToExpr (l: ListMap BoogieLabel Boogie.Procedure.Check) : Boogie.Expression.Expr := +def listToExpr (l: ListMap CoreLabel Core.Procedure.Check) : Core.Expression.Expr := match l with | _ => .true () -def createContractSymbolFromAST (func : Boogie.Procedure) : CBMCSymbol := +def createContractSymbolFromAST (func : Core.Procedure) : CBMCSymbol := let location : Location := { id := "", namedSub := some (Json.mkObj [ @@ -254,7 +254,7 @@ def createContractSymbolFromAST (func : Boogie.Procedure) : CBMCSymbol := ]), ("sub", Json.arr #[ parameterTuple, - exprToJson (I:=BoogieLParams) (listToExpr func.spec.preconditions) {functionName := func.header.name.toPretty, lineNum := "2"} + exprToJson (I:=CoreLParams) (listToExpr func.spec.preconditions) {functionName := func.header.name.toPretty, lineNum := "2"} ]) ] @@ -266,7 +266,7 @@ def createContractSymbolFromAST (func : Boogie.Procedure) : CBMCSymbol := ]), ("sub", Json.arr #[ parameterTuple, - exprToJson (I:=BoogieLParams) (listToExpr func.spec.postconditions) {functionName := func.header.name.toPretty, lineNum := "2"} + exprToJson (I:=CoreLParams) (listToExpr func.spec.postconditions) {functionName := func.header.name.toPretty, lineNum := "2"} ]) ] @@ -310,14 +310,14 @@ def createContractSymbolFromAST (func : Boogie.Procedure) : CBMCSymbol := value := Json.mkObj [("id", "nil")] } -def getParamJson(func: Boogie.Procedure) : Json := +def getParamJson(func: Core.Procedure) : Json := Json.mkObj [ ("id", ""), ("sub", Json.arr (func.header.inputs.map (λ i => mkParameter i.fst.name (func.header.name.toPretty) "1")).toArray) ] -def createImplementationSymbolFromAST (func : Boogie.Procedure) : CBMCSymbol := +def createImplementationSymbolFromAST (func : Core.Procedure) : CBMCSymbol := let location : Location := { namedSub := some (Json.mkObj [ ("file", Json.mkObj [("id", "ex_prog.c")]), @@ -340,7 +340,7 @@ def createImplementationSymbolFromAST (func : Boogie.Procedure) : CBMCSymbol := -- For now, keep the hardcoded implementation but use function name from AST let loc : SourceLoc := { functionName := (func.header.name.toPretty), lineNum := "1" } - let stmtJsons := (func.body.map (stmtToJson (I:=BoogieLParams) · loc)) + let stmtJsons := (func.body.map (stmtToJson (I:=CoreLParams) · loc)) let implValue := Json.mkObj [ ("id", "code"), @@ -367,7 +367,7 @@ def createImplementationSymbolFromAST (func : Boogie.Procedure) : CBMCSymbol := value := implValue } -def testSymbols (proc: Boogie.Procedure) : String := Id.run do +def testSymbols (proc: Core.Procedure) : String := Id.run do -- Generate symbols using AST data let contractSymbol := createContractSymbolFromAST proc let implSymbol := createImplementationSymbolFromAST proc @@ -392,4 +392,4 @@ def testSymbols (proc: Boogie.Procedure) : String := Id.run do m := m.insert s!"{proc.header.name.name}::1::z" zSymbol toString (toJson m) -end Boogie +end Core diff --git a/Strata/Backends/CBMC/tests/simpleTest.boogie.st b/Strata/Backends/CBMC/tests/simpleTest.core.st similarity index 92% rename from Strata/Backends/CBMC/tests/simpleTest.boogie.st rename to Strata/Backends/CBMC/tests/simpleTest.core.st index aababdd68..a8ef4ab62 100644 --- a/Strata/Backends/CBMC/tests/simpleTest.boogie.st +++ b/Strata/Backends/CBMC/tests/simpleTest.core.st @@ -1,4 +1,4 @@ -program Boogie; +program Core; procedure simpleTest(x : int, y : int) returns (ret : int) spec { diff --git a/Strata/DL/Imperative/HasVars.lean b/Strata/DL/Imperative/HasVars.lean index ef4dff3a1..4658df925 100644 --- a/Strata/DL/Imperative/HasVars.lean +++ b/Strata/DL/Imperative/HasVars.lean @@ -6,7 +6,6 @@ import Strata.DL.Imperative.PureExpr --- open Imperative Boogie namespace Imperative /-! # Pure Expression Variable Lookup : HasVarsPure -/ diff --git a/Strata/DL/Lambda/TestGen.lean b/Strata/DL/Lambda/TestGen.lean index 6e2dea8e7..dc43a692a 100644 --- a/Strata/DL/Lambda/TestGen.lean +++ b/Strata/DL/Lambda/TestGen.lean @@ -1052,7 +1052,7 @@ instance {T : LExprParams} return Lambda.LExpr.fvar m x.fst none else throw Gen.genericFailure), - (0, -- FIXME: for now we avoid generating lambdas for the boogie translator. + (0, -- FIXME: for now we avoid generating lambdas for the Strata Core translator. match ty_1 with | Lambda.LTy.forAll (List.nil) diff --git a/Strata/Languages/Boogie/BoogieGen.lean b/Strata/Languages/Boogie/BoogieGen.lean deleted file mode 100644 index 58f845b91..000000000 --- a/Strata/Languages/Boogie/BoogieGen.lean +++ /dev/null @@ -1,113 +0,0 @@ -/- - Copyright Strata Contributors - - SPDX-License-Identifier: Apache-2.0 OR MIT --/ - -import Strata.Languages.Boogie.Statement -import Strata.DL.Util.LabelGen -import Strata.DL.Util.StringGen -import Strata.DL.Util.ListUtils -open Boogie Lambda Imperative - -/-! ## Boogie Identifier Generator - This file contains a Boogie Identifier generator `BoogieGenState.gen`, where the - uniqueness of the generated identifiers is designed to be provable. It relies on a - `StringGenState` to generate unique strings (See `StringGen.lean`). - - Also see `LabelGen.lean` for the generic type class for a unique label generator. --/ -namespace Names - -def initVarValue (id : BoogieIdent) : Expression.Expr := - .fvar () (BoogieIdent.unres ("init_" ++ id.name)) none - -end Names - -namespace Boogie - -structure BoogieGenState where - cs : StringGenState - generated : List BoogieIdent := [] - -def BoogieGenState.WF (σ : BoogieGenState) - := StringGenState.WF σ.cs ∧ - List.map Boogie.BoogieIdent.temp σ.cs.generated.unzip.snd = σ.generated ∧ - σ.generated.Nodup ∧ - Forall (BoogieIdent.isTemp ·) σ.generated - -instance : HasSubset BoogieGenState where - Subset σ₁ σ₂ := σ₁.generated.Subset σ₂.generated - -@[simp] -def BoogieGenState.emp : BoogieGenState := { cs := .emp, generated := [] } - -/-- A BoogieIdent generator - NOTE: we need to wrap the prefix into a BoogieIdent in order to conform with the interface of UniqueLabelGen.gen - TODO: Maybe use genIdent or genIdents? - -/ -def BoogieGenState.gen (pf : BoogieIdent) (σ : BoogieGenState) - : BoogieIdent × BoogieGenState := - let (s, cs') := StringGenState.gen pf.name σ.cs - let newState : BoogieGenState := { cs := cs', generated := (.temp s) :: σ.generated } - ((.temp s), newState) - -theorem genBoogieIdentTemp : - BoogieGenState.gen pf s = (l, s') → BoogieIdent.isTemp l := by - intros Hgen - simp [BoogieGenState.gen] at Hgen - rw [← Hgen.1] - constructor - -theorem BoogieGenState.WFMono' : - BoogieGenState.WF s → - BoogieGenState.gen pf s = (l, s') → - BoogieGenState.WF s' := by - intros Hwf Hgen - unfold BoogieGenState.WF at Hwf - simp [gen] at Hgen - simp [← Hgen] - generalize h1 : (StringGenState.gen pf.name s.cs).fst = st - generalize h2 : (StringGenState.gen pf.name s.cs).snd = stg - have Hstrgen: StringGenState.gen pf.name s.cs = (st, stg) := by simp [← h1, ← h2] - have Hwf':= StringGenState.WFMono Hwf.left Hstrgen - simp [StringGenState.gen] at Hstrgen - constructor <;> simp [*] - constructor - simp_all - simp [← Hwf.right.left, ← Hgen.left, ← Hstrgen.right, ← Hstrgen.left] - constructor <;> try simp [BoogieIdent.isTemp] - simp [← Hwf.right.left] - intro x str Hx - false_or_by_contra - have: str = st := by injections - have Hnodup := Hwf'.right.right.left - simp [← Hstrgen.right, Hstrgen.left] at Hnodup - have Hnodup := Hnodup.left x - simp_all - -theorem BoogieGenState.WFMono : ∀ (γ γ' : BoogieGenState) (pf l : BoogieIdent), - BoogieGenState.gen pf γ = (l, γ') → WF γ → WF γ' ∧ l ∈ γ'.generated ∧ γ ⊆ γ' := by - intros γ γ' pf l Hgen Hwf - have Hwf':= WFMono' Hwf Hgen - simp [gen] at Hgen - refine ⟨?_, ?_, ?_⟩ - assumption - simp [← Hgen.right, ← Hgen.left] - simp [Subset, ← Hgen.right] - apply List.subset_cons_self - -/-- BoogieLabelGen guarantees that all labels are .temp -/ -instance : LabelGen.WFLabelGen BoogieIdent BoogieGenState where - emp := .emp - gen := BoogieGenState.gen - generated := BoogieGenState.generated - wf := BoogieGenState.WF - wf_emp := by - simp [BoogieGenState.WF, StringGenState.WF, Counter.WF] - constructor - wf_gen := BoogieGenState.WFMono - -abbrev BoogieGenM := StateM BoogieGenState - -end Boogie diff --git a/Strata/Languages/Boogie/Function.lean b/Strata/Languages/Boogie/Function.lean deleted file mode 100644 index 81e194839..000000000 --- a/Strata/Languages/Boogie/Function.lean +++ /dev/null @@ -1,42 +0,0 @@ -/- - Copyright Strata Contributors - - SPDX-License-Identifier: Apache-2.0 OR MIT --/ - - - -import Strata.Languages.Boogie.Statement - ---------------------------------------------------------------------- - -namespace Boogie - -open Std (ToFormat Format format) -open Lambda - -/-! # Boogie Functions -/ - -abbrev Function := Lambda.LFunc BoogieLParams - --- Type class instances to enable type class resolution for BoogieLParams.Identifier -instance : DecidableEq BoogieLParams.IDMeta := - show DecidableEq Visibility from inferInstance - -instance : ToFormat BoogieLParams.IDMeta := - show ToFormat Visibility from inferInstance - -open LTy.Syntax LExpr.SyntaxMono in -/-- info: ok: ∀[a, b]. (arrow int (arrow a (arrow b (arrow a a)))) -/ -#guard_msgs in -#eval do let type ← LFunc.type (T:=BoogieLParams) - ({ name := BoogieIdent.unres "Foo", - typeArgs := ["a", "b"], - inputs := [(BoogieIdent.locl "w", mty[int]), (BoogieIdent.locl "x", mty[%a]), (BoogieIdent.locl "y", mty[%b]), (BoogieIdent.locl "z", mty[%a])], - output := mty[%a], - body := some (LExpr.fvar () (BoogieIdent.locl "x") none) } : Function) - return format type - ---------------------------------------------------------------------- - -end Boogie diff --git a/Strata/Languages/C_Simp/DDMTransform/Translate.lean b/Strata/Languages/C_Simp/DDMTransform/Translate.lean index b7df8b3b4..fbca8ca84 100644 --- a/Strata/Languages/C_Simp/DDMTransform/Translate.lean +++ b/Strata/Languages/C_Simp/DDMTransform/Translate.lean @@ -11,7 +11,7 @@ import Strata.Languages.C_Simp.C_Simp namespace Strata namespace C_Simp --- (TODO) A bunch of this is just copied from Boogie (or copied with very minor changes) +-- (TODO) A bunch of this is just copied from Strata Core (or copied with very minor changes) -- What can we factor out to shared code (and where should we put it)? diff --git a/Strata/Languages/C_Simp/Verify.lean b/Strata/Languages/C_Simp/Verify.lean index e9798b9e2..2c376f582 100644 --- a/Strata/Languages/C_Simp/Verify.lean +++ b/Strata/Languages/C_Simp/Verify.lean @@ -6,7 +6,7 @@ import Strata.Languages.C_Simp.C_Simp import Strata.Languages.C_Simp.DDMTransform.Translate -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier import Strata.DL.Imperative.Stmt namespace Strata @@ -16,7 +16,7 @@ namespace Strata -- 2. Running SymExec of Lambda and Imp -def translate_expr (e : C_Simp.Expression.Expr) : Lambda.LExpr Boogie.BoogieLParams.mono := +def translate_expr (e : C_Simp.Expression.Expr) : Lambda.LExpr Core.CoreLParams.mono := match e with | .const m c => .const m c | .op m o ty => .op m ⟨o.name, .unres⟩ ty @@ -28,12 +28,12 @@ def translate_expr (e : C_Simp.Expression.Expr) : Lambda.LExpr Boogie.BoogieLPar | .ite m c t e => .ite m (translate_expr c) (translate_expr t) (translate_expr e) | .eq m e1 e2 => .eq m (translate_expr e1) (translate_expr e2) -def translate_opt_expr (e : Option C_Simp.Expression.Expr) : Option (Lambda.LExpr Boogie.BoogieLParams.mono) := +def translate_opt_expr (e : Option C_Simp.Expression.Expr) : Option (Lambda.LExpr Core.CoreLParams.mono) := match e with | some e => translate_expr e | none => none -def translate_cmd (c: C_Simp.Command) : Boogie.Command := +def translate_cmd (c: C_Simp.Command) : Core.Command := match c with | .init name ty e _md => .cmd (.init ⟨name.name, .unres⟩ ty (translate_expr e) {}) | .set name e _md => .cmd (.set ⟨name.name, .unres⟩ (translate_expr e) {}) @@ -42,7 +42,7 @@ def translate_cmd (c: C_Simp.Command) : Boogie.Command := | .assume label b _md => .cmd (.assume label (translate_expr b) {}) | .cover label b _md => .cmd (.cover label (translate_expr b) {}) -def translate_stmt (s: Imperative.Stmt C_Simp.Expression C_Simp.Command) : Boogie.Statement := +def translate_stmt (s: Imperative.Stmt C_Simp.Expression C_Simp.Command) : Core.Statement := match s with | .cmd c => .cmd (translate_cmd c) | .block l b _md => .block l (b.map translate_stmt) {} @@ -73,71 +73,71 @@ Assumption that invariant holds on exit This is suitable for Symbolic Execution, but may not be suitable for other analyses. -/ -def loop_elimination_statement(s : C_Simp.Statement) : Boogie.Statement := +def loop_elimination_statement(s : C_Simp.Statement) : Core.Statement := match s with | .loop guard measure invariant body _ => match measure, invariant with | .some measure, some invariant => -- let bodyss : := body.ss let assigned_vars := (Imperative.Block.modifiedVars body).map (λ s => ⟨s.name, .unres⟩) - let havocd : Boogie.Statement := .block "loop havoc" (assigned_vars.map (λ n => Boogie.Statement.havoc n {})) {} + let havocd : Core.Statement := .block "loop havoc" (assigned_vars.map (λ n => Core.Statement.havoc n {})) {} let measure_pos := (.app () (.app () (.op () "Int.Ge" none) (translate_expr measure)) (.intConst () 0)) - let entry_invariant : Boogie.Statement := .assert "entry_invariant" (translate_expr invariant) {} - let assert_measure_positive : Boogie.Statement := .assert "assert_measure_pos" measure_pos {} - let first_iter_facts : Boogie.Statement := .block "first_iter_asserts" [entry_invariant, assert_measure_positive] {} + let entry_invariant : Core.Statement := .assert "entry_invariant" (translate_expr invariant) {} + let assert_measure_positive : Core.Statement := .assert "assert_measure_pos" measure_pos {} + let first_iter_facts : Core.Statement := .block "first_iter_asserts" [entry_invariant, assert_measure_positive] {} - let arbitrary_iter_assumes := .block "arbitrary_iter_assumes" [(Boogie.Statement.assume "assume_guard" (translate_expr guard) {}), (Boogie.Statement.assume "assume_invariant" (translate_expr invariant) {}), (Boogie.Statement.assume "assume_measure_pos" measure_pos {})] {} - let measure_old_value_assign : Boogie.Statement := .init "special-name-for-old-measure-value" (.forAll [] (.tcons "int" [])) (translate_expr measure) {} - let measure_decreases : Boogie.Statement := .assert "measure_decreases" (.app () (.app () (.op () "Int.Lt" none) (translate_expr measure)) (.fvar () "special-name-for-old-measure-value" none)) {} - let measure_imp_not_guard : Boogie.Statement := .assert "measure_imp_not_guard" (.ite () (.app () (.app () (.op () "Int.Le" none) (translate_expr measure)) (.intConst () 0)) (.app () (.op () "Bool.Not" none) (translate_expr guard)) (.true ())) {} - let maintain_invariant : Boogie.Statement := .assert "arbitrary_iter_maintain_invariant" (translate_expr invariant) {} - let body_statements : List Boogie.Statement := body.map translate_stmt - let arbitrary_iter_facts : Boogie.Statement := .block "arbitrary iter facts" ([havocd, arbitrary_iter_assumes, measure_old_value_assign] ++ body_statements ++ [measure_decreases, measure_imp_not_guard, maintain_invariant]) {} + let arbitrary_iter_assumes := .block "arbitrary_iter_assumes" [(Core.Statement.assume "assume_guard" (translate_expr guard) {}), (Core.Statement.assume "assume_invariant" (translate_expr invariant) {}), (Core.Statement.assume "assume_measure_pos" measure_pos {})] {} + let measure_old_value_assign : Core.Statement := .init "special-name-for-old-measure-value" (.forAll [] (.tcons "int" [])) (translate_expr measure) {} + let measure_decreases : Core.Statement := .assert "measure_decreases" (.app () (.app () (.op () "Int.Lt" none) (translate_expr measure)) (.fvar () "special-name-for-old-measure-value" none)) {} + let measure_imp_not_guard : Core.Statement := .assert "measure_imp_not_guard" (.ite () (.app () (.app () (.op () "Int.Le" none) (translate_expr measure)) (.intConst () 0)) (.app () (.op () "Bool.Not" none) (translate_expr guard)) (.true ())) {} + let maintain_invariant : Core.Statement := .assert "arbitrary_iter_maintain_invariant" (translate_expr invariant) {} + let body_statements : List Core.Statement := body.map translate_stmt + let arbitrary_iter_facts : Core.Statement := .block "arbitrary iter facts" ([havocd, arbitrary_iter_assumes, measure_old_value_assign] ++ body_statements ++ [measure_decreases, measure_imp_not_guard, maintain_invariant]) {} - let not_guard : Boogie.Statement := .assume "not_guard" (.app () (.op () "Bool.Not" none) (translate_expr guard)) {} - let invariant : Boogie.Statement := .assume "invariant" (translate_expr invariant) {} + let not_guard : Core.Statement := .assume "not_guard" (.app () (.op () "Bool.Not" none) (translate_expr guard)) {} + let invariant : Core.Statement := .assume "invariant" (translate_expr invariant) {} .ite (translate_expr guard) [first_iter_facts, arbitrary_iter_facts, havocd, not_guard, invariant] [] {} | _, _ => panic! "Loop elimination require measure and invariant" | _ => translate_stmt s --- C_Simp functions are Boogie procedures -def loop_elimination_function(f : C_Simp.Function) : Boogie.Procedure := - let boogie_preconditions := [("pre", {expr := translate_expr f.pre })] - let boogie_postconditions := [("post", {expr := translate_expr f.post })] +-- C_Simp functions are Strata Core procedures +def loop_elimination_function(f : C_Simp.Function) : Core.Procedure := + let core_preconditions := [("pre", {expr := translate_expr f.pre })] + let core_postconditions := [("post", {expr := translate_expr f.post })] {header := {name := f.name.name, typeArgs := [], inputs := f.inputs.map (λ p => (p.fst.name, p.snd)), outputs := [("return", f.ret_ty)]}, spec := {modifies := [], - preconditions := boogie_preconditions, - postconditions := boogie_postconditions}, + preconditions := core_preconditions, + postconditions := core_postconditions}, body := f.body.map loop_elimination_statement} -def loop_elimination(program : C_Simp.Program) : Boogie.Program := +def loop_elimination(program : C_Simp.Program) : Core.Program := {decls := program.funcs.map (λ f => .proc (loop_elimination_function f) {})} -- Do loop elimination -def to_boogie(program : C_Simp.Program) : Boogie.Program := +def to_core(program : C_Simp.Program) : Core.Program := loop_elimination program def C_Simp.get_program (p : Strata.Program) : C_Simp.Program := (Strata.C_Simp.TransM.run (Strata.C_Simp.translateProgram (p.commands))).fst def C_Simp.typeCheck (p : Strata.Program) (options : Options := Options.default): - Except Std.Format Boogie.Program := do + Except Std.Format Core.Program := do let program := C_Simp.get_program p - Boogie.typeCheck options (to_boogie program) + Core.typeCheck options (to_core program) def C_Simp.verify (smtsolver : String) (p : Strata.Program) (options : Options := Options.default) (tempDir : Option String := .none): - IO Boogie.VCResults := do + IO Core.VCResults := do let program := C_Simp.get_program p let runner tempDir := EIO.toIO (fun f => IO.Error.userError (toString f)) - (Boogie.verify smtsolver (to_boogie program) tempDir options) + (Core.verify smtsolver (to_core program) tempDir options) match tempDir with | .none => IO.FS.withTempDir runner diff --git a/Strata/Languages/Boogie/Axiom.lean b/Strata/Languages/Core/Axiom.lean similarity index 70% rename from Strata/Languages/Boogie/Axiom.lean rename to Strata/Languages/Core/Axiom.lean index ea113002b..a88781357 100644 --- a/Strata/Languages/Boogie/Axiom.lean +++ b/Strata/Languages/Core/Axiom.lean @@ -7,11 +7,11 @@ -import Strata.Languages.Boogie.Statement +import Strata.Languages.Core.Statement import Strata.DL.Lambda.LTy import Strata.DL.Lambda.LExpr -namespace Boogie +namespace Core --------------------------------------------------------------------- open Std (ToFormat Format format) @@ -20,17 +20,17 @@ open Lambda /-! ## Axioms -Axioms are propositions assumed to be true throughout a Strata.Boogie program. +Axioms are propositions assumed to be true throughout a Strata Core program. They are passed on as assumptions to the SMT solver during VC generation. It's the responsibility of the user to ensure that they are consistent. -/ structure Axiom where - name : BoogieLabel - e : LExpr BoogieLParams.mono + name : CoreLabel + e : LExpr CoreLParams.mono -instance : ToFormat (BoogieLParams.mono : LExprParamsT).base.Identifier := - show ToFormat BoogieIdent from inferInstance +instance : ToFormat (CoreLParams.mono : LExprParamsT).base.Identifier := + show ToFormat CoreIdent from inferInstance instance : ToFormat Axiom where format a := f!"axiom {a.name}: {a.e};" diff --git a/Strata/Languages/Boogie/CallGraph.lean b/Strata/Languages/Core/CallGraph.lean similarity index 92% rename from Strata/Languages/Boogie/CallGraph.lean rename to Strata/Languages/Core/CallGraph.lean index 8e60228d4..26ebda9ab 100644 --- a/Strata/Languages/Boogie/CallGraph.lean +++ b/Strata/Languages/Core/CallGraph.lean @@ -4,10 +4,10 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Program +import Strata.Languages.Core.Program --------------------------------------------------------------------- -namespace Boogie +namespace Core /-- Generic call graph structure -/ structure CallGraph where @@ -68,15 +68,15 @@ def buildCallGraph (items : List (String × List String)) : CallGraph := { callees := calleeMap, callers := callerMap } /-- -Extract function calls from an expression. We ignore Boogie's builtin functions -(`Boogie.builtinFunctions`) here. +Extract function calls from an expression. We ignore builtin functions +(`Core.builtinFunctions`) here. -/ def extractFunctionCallsFromExpr (expr : Expression.Expr) : List String := match expr with | .fvar _ _ _ => [] | .bvar _ _ => [] | .op _ fname _ => - let fname := BoogieIdent.toPretty fname + let fname := CoreIdent.toPretty fname if builtinFunctions.contains fname then [] else [fname] | .const _ _ => [] | .app _ fn arg => extractFunctionCallsFromExpr fn ++ extractFunctionCallsFromExpr arg @@ -118,14 +118,14 @@ abbrev FunctionCG := CallGraph def Program.toProcedureCG (prog : Program) : ProcedureCG := let procedures := prog.decls.filterMap (fun decl => match decl with - | .proc p _ => some (BoogieIdent.toPretty p.header.name, extractCallsFromProcedure p) + | .proc p _ => some (CoreIdent.toPretty p.header.name, extractCallsFromProcedure p) | _ => none) buildCallGraph procedures def Program.toFunctionCG (prog : Program) : FunctionCG := let functions := prog.decls.filterMap (fun decl => match decl with - | .func f _ => some (BoogieIdent.toPretty f.name, extractCallsFromFunction f) + | .func f _ => some (CoreIdent.toPretty f.name, extractCallsFromFunction f) | _ => none) buildCallGraph functions @@ -170,7 +170,7 @@ def Program.toFunctionAxiomMap (prog : Program) : Std.HashMap String (List Strin let functionAxiomPairs := axioms.flatMap (fun ax => let ops := Lambda.LExpr.getOps ax.e - ops.map (fun op => (BoogieIdent.toPretty op, ax))) + ops.map (fun op => (CoreIdent.toPretty op, ax))) functionAxiomPairs.foldl (fun acc (funcName, ax) => @@ -192,10 +192,10 @@ def Program.getIrrelevantAxioms (prog : Program) (functions : List String) : Lis | .ax a _ => let ops := Lambda.LExpr.getOps a.e let hasRelevantOp := ops.any (fun op => - functionsSet.binSearch (BoogieIdent.toPretty op) (· < ·) |>.isSome) + functionsSet.binSearch (CoreIdent.toPretty op) (· < ·) |>.isSome) if hasRelevantOp then none else some a.name | _ => none) --------------------------------------------------------------------- -end Boogie +end Core diff --git a/Strata/Languages/Boogie/CmdEval.lean b/Strata/Languages/Core/CmdEval.lean similarity index 95% rename from Strata/Languages/Boogie/CmdEval.lean rename to Strata/Languages/Core/CmdEval.lean index 1c38e3c53..7a51883f1 100644 --- a/Strata/Languages/Boogie/CmdEval.lean +++ b/Strata/Languages/Core/CmdEval.lean @@ -6,13 +6,13 @@ -import Strata.Languages.Boogie.OldExpressions -import Strata.Languages.Boogie.Expressions -import Strata.Languages.Boogie.Env +import Strata.Languages.Core.OldExpressions +import Strata.Languages.Core.Expressions +import Strata.Languages.Core.Env import Strata.DL.Imperative.EvalContext import Strata.DL.Imperative.CmdEval -namespace Boogie +namespace Core open Lambda Imperative open Std (ToFormat Format format) @@ -114,7 +114,6 @@ instance : EvalContext Expression Env where getPathConditions := CmdEval.getPathConditions addPathCondition := CmdEval.addPathCondition deferObligation := CmdEval.deferObligation - -- lookupEval := Boogie.lookupEval instance : ToFormat (Cmds Expression × Env) where format arg := @@ -125,7 +124,7 @@ instance : ToFormat (Cmds Expression × Env) where --------------------------------------------------------------------- -open LExpr.SyntaxMono LTy.Syntax Boogie.Syntax +open LExpr.SyntaxMono LTy.Syntax Core.Syntax private def testProgram1 : Cmds Expression := [.init "x" t[int] eb[#0], .set "x" eb[#10], @@ -217,4 +216,4 @@ Proof Obligation: end CmdEval --------------------------------------------------------------------- -end Boogie +end Core diff --git a/Strata/Languages/Boogie/CmdType.lean b/Strata/Languages/Core/CmdType.lean similarity index 77% rename from Strata/Languages/Boogie/CmdType.lean rename to Strata/Languages/Core/CmdType.lean index 5b6fcb6e2..db6528ce9 100644 --- a/Strata/Languages/Boogie/CmdType.lean +++ b/Strata/Languages/Core/CmdType.lean @@ -6,12 +6,12 @@ -import Strata.Languages.Boogie.OldExpressions -import Strata.Languages.Boogie.Expressions +import Strata.Languages.Core.OldExpressions +import Strata.Languages.Core.Expressions import Strata.DL.Imperative.TypeContext import Strata.DL.Lambda.Factory -namespace Boogie +namespace Core open Lambda Imperative open Std (ToFormat Format format) @@ -24,26 +24,26 @@ def isBoolType (ty : LTy) : Bool := | .forAll [] LMonoTy.bool => true | _ => false -def lookup (Env : TEnv Visibility) (x : BoogieIdent) : Option LTy := +def lookup (Env : TEnv Visibility) (x : CoreIdent) : Option LTy := Env.context.types.find? x -def update (Env : TEnv Visibility) (x : BoogieIdent) (ty : LTy) : TEnv Visibility := - Env.insertInContext (T := BoogieLParams) x ty +def update (Env : TEnv Visibility) (x : CoreIdent) (ty : LTy) : TEnv Visibility := + Env.insertInContext (T := CoreLParams) x ty -def freeVars (e : (LExpr BoogieLParams.mono)) : List BoogieIdent := +def freeVars (e : (LExpr CoreLParams.mono)) : List CoreIdent := (LExpr.freeVars e).map (fun (i, _) => i) /-- -Preprocess a user-facing type in Boogie amounts to converting a poly-type (i.e., +Preprocess a user-facing type in Core amounts to converting a poly-type (i.e., `LTy`) to a mono-type (i.e., `LMonoTy`) via instantiation. We still return an `LTy`, with no bound variables. -/ -def preprocess (C: LContext BoogieLParams) (Env : TEnv Visibility) (ty : LTy) : +def preprocess (C: LContext CoreLParams) (Env : TEnv Visibility) (ty : LTy) : Except Format (LTy × TEnv Visibility) := do let (mty, Env) ← ty.instantiateWithCheck C Env return (.forAll [] mty, Env) -def postprocess (_: LContext BoogieLParams) (Env: TEnv Visibility) (ty : LTy) : +def postprocess (_: LContext CoreLParams) (Env: TEnv Visibility) (ty : LTy) : Except Format (LTy × TEnv Visibility) := do if h: ty.isMonoType then let ty := LMonoTy.subst Env.stateSubstInfo.subst (ty.toMonoType h) @@ -55,8 +55,8 @@ def postprocess (_: LContext BoogieLParams) (Env: TEnv Visibility) (ty : LTy) : The inferred type of `e` will be an `LMonoTy`, but we return an `LTy` with no bound variables. -/ -def inferType (C: LContext BoogieLParams) (Env: TEnv Visibility) (c : Cmd Expression) (e : LExpr BoogieLParams.mono) : - Except Format ((LExpr BoogieLParams.mono) × LTy × TEnv Visibility) := do +def inferType (C: LContext CoreLParams) (Env: TEnv Visibility) (c : Cmd Expression) (e : LExpr CoreLParams.mono) : + Except Format ((LExpr CoreLParams.mono) × LTy × TEnv Visibility) := do -- We only allow free variables to appear in `init` statements. Any other -- occurrence leads to an error. let T ← match c with @@ -103,7 +103,7 @@ def typeErrorFmt (e : Format) : Format := --------------------------------------------------------------------- -instance : Imperative.TypeContext Expression (LContext BoogieLParams) (TEnv Visibility) Format where +instance : Imperative.TypeContext Expression (LContext CoreLParams) (TEnv Visibility) Format where isBoolType := CmdType.isBoolType freeVars := CmdType.freeVars preprocess := CmdType.preprocess @@ -117,4 +117,4 @@ instance : Imperative.TypeContext Expression (LContext BoogieLParams) (TEnv Visi end CmdType --------------------------------------------------------------------- -end Boogie +end Core diff --git a/Strata/Languages/Boogie/Boogie.lean b/Strata/Languages/Core/Core.lean similarity index 58% rename from Strata/Languages/Boogie/Boogie.lean rename to Strata/Languages/Core/Core.lean index 75ad4b490..40118b462 100644 --- a/Strata/Languages/Boogie/Boogie.lean +++ b/Strata/Languages/Core/Core.lean @@ -5,51 +5,48 @@ -/ -import Strata.Languages.Boogie.Options -import Strata.Languages.Boogie.ProgramEval -import Strata.Languages.Boogie.ProgramType +import Strata.Languages.Core.Options +import Strata.Languages.Core.ProgramEval +import Strata.Languages.Core.ProgramType --------------------------------------------------------------------- -namespace Boogie +namespace Core /-! -## Differences between Boogie and Strata.Boogie +## Differences between Boogie and Strata.Core 1. Local variables can shadow globals in Boogie, but the typechecker disallows - that in Strata.Boogie. + that in Strata.Core. -2. Unlike Boogie, Strata.Boogie is sensitive to global declaration order. E.g., +2. Unlike Boogie, Strata.Core is sensitive to global declaration order. E.g., a global variable must be declared before it can be used in a procedure. -3. Strata.Boogie does not (yet) support polymorphism. +3. Strata.Core does not (yet) support polymorphism. -4. Strata.Boogie does not (yet) support arbitrary gotos. All gotos must +4. Strata.Core does not (yet) support arbitrary gotos. All gotos must currently be to labels later in the program. -5. Strata.Boogie does not support `where` clauses and `unique` constants, +5. Strata.Core does not support `where` clauses and `unique` constants, requiring a tool like `BoogieToStrata` to desugar them. - -6. Strata.Boogie does not support algebraic data types or regular expression - types. -/ def typeCheck (options : Options) (program : Program) - (moreFns : @Lambda.Factory BoogieLParams := Lambda.Factory.default) : + (moreFns : @Lambda.Factory CoreLParams := Lambda.Factory.default) : Except Std.Format Program := do let T := Lambda.TEnv.default - let factory ← Boogie.Factory.addFactory moreFns + let factory ← Core.Factory.addFactory moreFns let C := { Lambda.LContext.default with functions := factory, - knownTypes := Boogie.KnownTypes } + knownTypes := Core.KnownTypes } let (program, _T) ← Program.typeCheck C T program - -- dbg_trace f!"[Strata.Boogie] Type variables:\n{T.state.substInfo.subst.length}" - -- dbg_trace f!"[Strata.Boogie] Annotated program:\n{program}" - if options.verbose >= .normal then dbg_trace f!"[Strata.Boogie] Type checking succeeded.\n" + -- dbg_trace f!"[Strata.Core] Type variables:\n{T.state.substInfo.subst.length}" + -- dbg_trace f!"[Strata.Core] Annotated program:\n{program}" + if options.verbose >= .normal then dbg_trace f!"[Strata.Core] Type checking succeeded.\n" return program def typeCheckAndPartialEval (options : Options) (program : Program) - (moreFns : @Lambda.Factory BoogieLParams := Lambda.Factory.default) : + (moreFns : @Lambda.Factory CoreLParams := Lambda.Factory.default) : Except Std.Format (List (Program × Env)) := do let program ← typeCheck options program moreFns -- Extract datatypes from program declarations and add to environment @@ -57,7 +54,7 @@ def typeCheckAndPartialEval (options : Options) (program : Program) match decl with | .type (.data d) _ => some d | _ => none - let σ ← (Lambda.LState.init).addFactory Boogie.Factory + let σ ← (Lambda.LState.init).addFactory Core.Factory let σ ← σ.addFactory moreFns let E := { Env.init with exprEnv := σ, program := program } @@ -72,6 +69,6 @@ def typeCheckAndPartialEval (options : Options) (program : Program) instance : ToString (Program) where toString p := toString (Std.format p) -end Boogie +end Core --------------------------------------------------------------------- diff --git a/Strata/Languages/Core/CoreGen.lean b/Strata/Languages/Core/CoreGen.lean new file mode 100644 index 000000000..338c6957a --- /dev/null +++ b/Strata/Languages/Core/CoreGen.lean @@ -0,0 +1,113 @@ +/- + Copyright Strata Contributors + + SPDX-License-Identifier: Apache-2.0 OR MIT +-/ + +import Strata.Languages.Core.Statement +import Strata.DL.Util.LabelGen +import Strata.DL.Util.StringGen +import Strata.DL.Util.ListUtils +open Core Lambda Imperative + +/-! ## Strata Core Identifier Generator + This file contains a Strata Core Identifier generator `CoreGenState.gen`, where the + uniqueness of the generated identifiers is designed to be provable. It relies on a + `StringGenState` to generate unique strings (See `StringGen.lean`). + + Also see `LabelGen.lean` for the generic type class for a unique label generator. +-/ +namespace Names + +def initVarValue (id : CoreIdent) : Expression.Expr := + .fvar () (CoreIdent.unres ("init_" ++ id.name)) none + +end Names + +namespace Core + +structure CoreGenState where + cs : StringGenState + generated : List CoreIdent := [] + +def CoreGenState.WF (σ : CoreGenState) + := StringGenState.WF σ.cs ∧ + List.map Core.CoreIdent.temp σ.cs.generated.unzip.snd = σ.generated ∧ + σ.generated.Nodup ∧ + Forall (CoreIdent.isTemp ·) σ.generated + +instance : HasSubset CoreGenState where + Subset σ₁ σ₂ := σ₁.generated.Subset σ₂.generated + +@[simp] +def CoreGenState.emp : CoreGenState := { cs := .emp, generated := [] } + +/-- A CoreIdent generator + NOTE: we need to wrap the prefix into a CoreIdent in order to conform with the interface of UniqueLabelGen.gen + TODO: Maybe use genIdent or genIdents? + -/ +def CoreGenState.gen (pf : CoreIdent) (σ : CoreGenState) + : CoreIdent × CoreGenState := + let (s, cs') := StringGenState.gen pf.name σ.cs + let newState : CoreGenState := { cs := cs', generated := (.temp s) :: σ.generated } + ((.temp s), newState) + +theorem genCoreIdentTemp : + CoreGenState.gen pf s = (l, s') → CoreIdent.isTemp l := by + intros Hgen + simp [CoreGenState.gen] at Hgen + rw [← Hgen.1] + constructor + +theorem CoreGenState.WFMono' : + CoreGenState.WF s → + CoreGenState.gen pf s = (l, s') → + CoreGenState.WF s' := by + intros Hwf Hgen + unfold CoreGenState.WF at Hwf + simp [gen] at Hgen + simp [← Hgen] + generalize h1 : (StringGenState.gen pf.name s.cs).fst = st + generalize h2 : (StringGenState.gen pf.name s.cs).snd = stg + have Hstrgen: StringGenState.gen pf.name s.cs = (st, stg) := by simp [← h1, ← h2] + have Hwf':= StringGenState.WFMono Hwf.left Hstrgen + simp [StringGenState.gen] at Hstrgen + constructor <;> simp [*] + constructor + simp_all + simp [← Hwf.right.left, ← Hgen.left, ← Hstrgen.right, ← Hstrgen.left] + constructor <;> try simp [CoreIdent.isTemp] + simp [← Hwf.right.left] + intro x str Hx + false_or_by_contra + have: str = st := by injections + have Hnodup := Hwf'.right.right.left + simp [← Hstrgen.right, Hstrgen.left] at Hnodup + have Hnodup := Hnodup.left x + simp_all + +theorem CoreGenState.WFMono : ∀ (γ γ' : CoreGenState) (pf l : CoreIdent), + CoreGenState.gen pf γ = (l, γ') → WF γ → WF γ' ∧ l ∈ γ'.generated ∧ γ ⊆ γ' := by + intros γ γ' pf l Hgen Hwf + have Hwf':= WFMono' Hwf Hgen + simp [gen] at Hgen + refine ⟨?_, ?_, ?_⟩ + assumption + simp [← Hgen.right, ← Hgen.left] + simp [Subset, ← Hgen.right] + apply List.subset_cons_self + +/-- CoreLabelGen guarantees that all labels are .temp -/ +instance : LabelGen.WFLabelGen CoreIdent CoreGenState where + emp := .emp + gen := CoreGenState.gen + generated := CoreGenState.generated + wf := CoreGenState.WF + wf_emp := by + simp [CoreGenState.WF, StringGenState.WF, Counter.WF] + constructor + wf_gen := CoreGenState.WFMono + +abbrev CoreGenM := StateM CoreGenState + +end Core diff --git a/Strata/Languages/Boogie/DDMTransform/Parse.lean b/Strata/Languages/Core/DDMTransform/Parse.lean similarity index 98% rename from Strata/Languages/Boogie/DDMTransform/Parse.lean rename to Strata/Languages/Core/DDMTransform/Parse.lean index d4e8494ea..24cb43c80 100644 --- a/Strata/Languages/Boogie/DDMTransform/Parse.lean +++ b/Strata/Languages/Core/DDMTransform/Parse.lean @@ -6,7 +6,7 @@ import Strata.DDM.Integration.Lean import Strata.DDM.Util.Format -import Strata.Languages.Boogie.Boogie +import Strata.Languages.Core.Core --------------------------------------------------------------------- @@ -15,12 +15,12 @@ namespace Strata --------------------------------------------------------------------- --------------------------------------------------------------------- -/- DDM support for parsing and pretty-printing Boogie -/ +/- DDM support for parsing and pretty-printing Strata Core -/ #dialect -dialect Boogie; +dialect Core; -// Declare Boogie-specific metadata for datatype declarations +// Declare Strata Core-specific metadata for datatype declarations metadata declareDatatype (name : Ident, typeParams : Ident, constructors : Ident, testerTemplate : FunctionTemplate, accessorTemplate : FunctionTemplate); @@ -244,7 +244,7 @@ op command_procedure (name : Ident, // type Array a; // instead of // type Array (a : Type); -// where the former is what's needed for Boogie. +// where the former is what Boogie does. @[declareType(name, some args)] op command_typedecl (name : Ident, args : Option Bindings) : Command => "type " name args ";\n"; @@ -325,11 +325,11 @@ op command_datatype (name : Ident, #end -namespace BoogieDDM +namespace CoreDDM --#strata_gen Boogie -end BoogieDDM +end CoreDDM --------------------------------------------------------------------- diff --git a/Strata/Languages/Boogie/DDMTransform/Translate.lean b/Strata/Languages/Core/DDMTransform/Translate.lean similarity index 67% rename from Strata/Languages/Boogie/DDMTransform/Translate.lean rename to Strata/Languages/Core/DDMTransform/Translate.lean index 0c563dbb4..0ab640b09 100644 --- a/Strata/Languages/Boogie/DDMTransform/Translate.lean +++ b/Strata/Languages/Core/DDMTransform/Translate.lean @@ -5,8 +5,8 @@ -/ import Strata.DDM.AST -import Strata.Languages.Boogie.DDMTransform.Parse -import Strata.Languages.Boogie.BoogieGen +import Strata.Languages.Core.DDMTransform.Parse +import Strata.Languages.Core.CoreGen import Strata.DDM.Util.DecimalRat @@ -15,7 +15,7 @@ namespace Strata /- Translating concrete syntax into abstract syntax -/ -open Boogie Lambda Imperative Lean.Parser +open Core Lambda Imperative Lean.Parser open Std (ToFormat Format format) --------------------------------------------------------------------- @@ -33,7 +33,7 @@ def TransM.run (ictx : InputContext) (m : TransM α) : (α × Array String) := let (v, s) := StateT.run m { inputCtx := ictx, errors := #[] } (v, s.errors) -instance : ToString (Boogie.Program × Array String) where +instance : ToString (Core.Program × Array String) where toString p := toString (Std.format p.fst) ++ "\n" ++ "Errors: " ++ (toString p.snd) @@ -45,7 +45,7 @@ def TransM.error [Inhabited α] (msg : String) : TransM α := do /- Metadata -/ -def SourceRange.toMetaData (ictx : InputContext) (sr : SourceRange) : Imperative.MetaData Boogie.Expression := +def SourceRange.toMetaData (ictx : InputContext) (sr : SourceRange) : Imperative.MetaData Core.Expression := let file := ictx.fileName let startPos := ictx.fileMap.toPosition sr.start let endPos := ictx.fileMap.toPosition sr.stop @@ -53,10 +53,10 @@ def SourceRange.toMetaData (ictx : InputContext) (sr : SourceRange) : Imperative let fileRangeElt := ⟨ MetaData.fileRange, .fileRange ⟨ uri, startPos, endPos ⟩ ⟩ #[fileRangeElt] -def getOpMetaData (op : Operation) : TransM (Imperative.MetaData Boogie.Expression) := +def getOpMetaData (op : Operation) : TransM (Imperative.MetaData Core.Expression) := return op.ann.toMetaData (← StateT.get).inputCtx -def getArgMetaData (arg : Arg) : TransM (Imperative.MetaData Boogie.Expression) := +def getArgMetaData (arg : Arg) : TransM (Imperative.MetaData Core.Expression) := return arg.ann.toMetaData (← StateT.get).inputCtx --------------------------------------------------------------------- @@ -111,7 +111,7 @@ def translateOptionLabel (default : String) (arg : Arg) : TransM String := do translateOption (fun maybe_arg => do match maybe_arg with | none => return default - | some lop => let args ← checkOpArg lop q`Boogie.label 1 + | some lop => let args ← checkOpArg lop q`Core.label 1 translateIdent String args[0]!) arg @@ -154,8 +154,8 @@ structure GenNum where structure TransBindings where boundTypeVars : Array TyIdentifier := #[] - boundVars : Array (LExpr BoogieLParams.mono) := #[] - freeVars : Array Boogie.Decl := #[] + boundVars : Array (LExpr CoreLParams.mono) := #[] + freeVars : Array Core.Decl := #[] gen : GenNum := (GenNum.mk 0 0 0 0 0) def incrNum (gen_kind : GenKind) (b : TransBindings) : TransBindings := @@ -178,22 +178,22 @@ instance : ToFormat TransBindings where {Format.line}\ Gen: {repr b.gen}" -instance : Inhabited (List Boogie.Statement × TransBindings) where +instance : Inhabited (List Core.Statement × TransBindings) where default := ([], {}) -instance : Inhabited Boogie.Decl where +instance : Inhabited Core.Decl where default := .var "badguy" (.forAll [] (.tcons "bool" [])) (.false ()) instance : Inhabited (Procedure.CheckAttr) where default := .Default -instance : Inhabited (Boogie.Decl × TransBindings) where +instance : Inhabited (Core.Decl × TransBindings) where default := (.var "badguy" (.forAll [] (.tcons "bool" [])) (.false ()), {}) -instance : Inhabited (Boogie.Decls × TransBindings) where +instance : Inhabited (Core.Decls × TransBindings) where default := ([], {}) -instance : Inhabited (List BoogieIdent × TransBindings) where +instance : Inhabited (List CoreIdent × TransBindings) where default := ([], {}) instance : Inhabited (List TyIdentifier × TransBindings) where @@ -204,7 +204,7 @@ instance : Inhabited (List TyIdentifier × TransBindings) where def translateTypeBinding (bindings : TransBindings) (op : Arg) : TransM (TyIdentifier × TransBindings) := do -- (FIXME) Account for metadata. - let bargs ← checkOpArg op q`Boogie.mkBinding 2 + let bargs ← checkOpArg op q`Core.mkBinding 2 let id ← translateIdent TyIdentifier bargs[0]! -- (TODO) It looks like other elements of `bargs` are irrelevant here? -- Perhaps we should not using `Bindings` for type declarations. @@ -229,11 +229,11 @@ partial def translateLMonoTy (bindings : TransBindings) (arg : Arg) : let .type tp := arg | TransM.error s!"translateLMonoTy expected type {repr arg}" match tp with - | .ident _ q`Boogie.bv1 #[] => pure <| .bitvec 1 - | .ident _ q`Boogie.bv8 #[] => pure <| .bitvec 8 - | .ident _ q`Boogie.bv16 #[] => pure <| .bitvec 16 - | .ident _ q`Boogie.bv32 #[] => pure <| .bitvec 32 - | .ident _ q`Boogie.bv64 #[] => pure <| .bitvec 64 + | .ident _ q`Core.bv1 #[] => pure <| .bitvec 1 + | .ident _ q`Core.bv8 #[] => pure <| .bitvec 8 + | .ident _ q`Core.bv16 #[] => pure <| .bitvec 16 + | .ident _ q`Core.bv32 #[] => pure <| .bitvec 32 + | .ident _ q`Core.bv64 #[] => pure <| .bitvec 64 | .ident _ i argst => let argst' ← translateLMonoTys bindings (argst.map ArgF.type) pure <| (.tcons i.name argst'.toList.reverse) @@ -245,7 +245,7 @@ partial def translateLMonoTy (bindings : TransBindings) (arg : Arg) : -- Type Declaration let ty := tcons.toType -- While the "unsafe" below looks scary, we should be alright as far as - -- Boogie is concerned. See `Boogie.TypeConstructor`, where there is no + -- Core is concerned. See `Core.TypeConstructor`, where there is no -- facility for providing the type arguments. pure ty.toMonoTypeUnsafe | .type (.syn syn) _md => @@ -283,13 +283,13 @@ def translateTypeArgs (op : Strata.Arg) : TransM (Array TyIdentifier) := do translateOption (fun x => do match x with | none => return Array.empty | some a => - let args ← checkOpArg a q`Boogie.type_args 1 + let args ← checkOpArg a q`Core.type_args 1 translateCommaSep (translateIdent TyIdentifier) args[0]!) op def translateTypeSynonym (bindings : TransBindings) (op : Operation) : - TransM (Boogie.Decl × TransBindings) := do - let _ ← @checkOp (Boogie.Decl × TransBindings) op q`Boogie.command_typesynonym 4 + TransM (Core.Decl × TransBindings) := do + let _ ← @checkOp (Core.Decl × TransBindings) op q`Core.command_typesynonym 4 let name ← translateIdent TyIdentifier op.args[0]! let (targs, bindings) ← translateOption @@ -297,7 +297,7 @@ def translateTypeSynonym (bindings : TransBindings) (op : Operation) : do match maybearg with | none => pure ([], bindings) | some arg => - let bargs ← checkOpArg arg q`Boogie.mkBindings 1 + let bargs ← checkOpArg arg q`Core.mkBindings 1 let args ← match bargs[0]! with | .seq _ .comma args => @@ -308,13 +308,13 @@ def translateTypeSynonym (bindings : TransBindings) (op : Operation) : op.args[1]! let typedef ← translateLMonoTy bindings op.args[3]! let md ← getOpMetaData op - let decl := Boogie.Decl.type (.syn { name := name, typeArgs := targs, type := typedef }) md + let decl := Core.Decl.type (.syn { name := name, typeArgs := targs, type := typedef }) md return (decl, { bindings with freeVars := bindings.freeVars.push decl }) def translateTypeDecl (bindings : TransBindings) (op : Operation) : - TransM (Boogie.Decl × TransBindings) := do - let _ ← @checkOp (Boogie.Decl × TransBindings) op q`Boogie.command_typedecl 2 + TransM (Core.Decl × TransBindings) := do + let _ ← @checkOp (Core.Decl × TransBindings) op q`Core.command_typedecl 2 let name ← translateIdent TyIdentifier op.args[0]! let numargs ← translateOption @@ -322,7 +322,7 @@ def translateTypeDecl (bindings : TransBindings) (op : Operation) : do match maybearg with | none => pure 0 | some arg => - let bargs ← checkOpArg arg q`Boogie.mkBindings 1 + let bargs ← checkOpArg arg q`Core.mkBindings 1 let numargs ← match bargs[0]! with | .seq _ .comma args => pure args.size @@ -332,26 +332,26 @@ def translateTypeDecl (bindings : TransBindings) (op : Operation) : let md ← getOpMetaData op -- Only the number of type arguments is important; the exact identifiers are -- irrelevant. - let decl := Boogie.Decl.type (.con { name := name, numargs := numargs }) md + let decl := Core.Decl.type (.con { name := name, numargs := numargs }) md return (decl, { bindings with freeVars := bindings.freeVars.push decl }) --------------------------------------------------------------------- -def translateLhs (arg : Arg) : TransM BoogieIdent := do +def translateLhs (arg : Arg) : TransM CoreIdent := do let .op op := arg | TransM.error s!"translateLhs expected op {repr arg}" match op.name, op.args with - | q`Boogie.lhsIdent, #[id] => translateIdent BoogieIdent id + | q`Core.lhsIdent, #[id] => translateIdent CoreIdent id -- (TODO) Implement lhsArray. | _, _ => TransM.error s!"translateLhs: unimplemented for {repr arg}" def translateBindMk (bindings : TransBindings) (arg : Arg) : - TransM (BoogieIdent × List TyIdentifier × LMonoTy) := do + TransM (CoreIdent × List TyIdentifier × LMonoTy) := do let .op op := arg | TransM.error s!"translateBindMk expected op {repr arg}" match op.name, op.args with - | q`Boogie.bind_mk, #[ida, targsa, tpa] => - let id ← translateIdent BoogieIdent ida + | q`Core.bind_mk, #[ida, targsa, tpa] => + let id ← translateIdent CoreIdent ida let args ← translateTypeArgs targsa let tp ← translateLMonoTy bindings tpa return (id, args.toList, tp) @@ -359,12 +359,12 @@ def translateBindMk (bindings : TransBindings) (arg : Arg) : TransM.error s!"translateBindMk unimplemented for {repr arg}" def translateMonoBindMk (bindings : TransBindings) (arg : Arg) : - TransM (BoogieIdent × LMonoTy) := do + TransM (CoreIdent × LMonoTy) := do let .op op := arg | TransM.error s!"translateMonoBindMk expected op {repr arg}" match op.name, op.args with - | q`Boogie.mono_bind_mk, #[ida, tpa] => - let id ← translateIdent BoogieIdent ida + | q`Core.mono_bind_mk, #[ida, tpa] => + let id ← translateIdent CoreIdent ida let tp ← translateLMonoTy bindings tpa return (id, tp) | _, _ => @@ -375,13 +375,13 @@ partial def translateDeclList (bindings : TransBindings) (arg : Arg) : let .op op := arg | TransM.error s!"translateDeclList expects an op {repr arg}" match op.name with - | q`Boogie.declAtom => - let args ← checkOpArg arg q`Boogie.declAtom 1 + | q`Core.declAtom => + let args ← checkOpArg arg q`Core.declAtom 1 let (id, targs, mty) ← translateBindMk bindings args[0]! let lty := .forAll targs mty pure [(id, lty)] - | q`Boogie.declPush => - let args ← checkOpArg arg q`Boogie.declPush 2 + | q`Core.declPush => + let args ← checkOpArg arg q`Core.declPush 2 let fst ← translateDeclList bindings args[0]! let (id, targs, mty) ← translateBindMk bindings args[1]! let lty : LTy := .forAll targs mty @@ -393,12 +393,12 @@ partial def translateMonoDeclList (bindings : TransBindings) (arg : Arg) : let .op op := arg | TransM.error s!"translateMonoDeclList expects an op {repr arg}" match op.name with - | q`Boogie.monoDeclAtom => - let args ← checkOpArg arg q`Boogie.monoDeclAtom 1 + | q`Core.monoDeclAtom => + let args ← checkOpArg arg q`Core.monoDeclAtom 1 let (id, mty) ← translateMonoBindMk bindings args[0]! pure [(id, mty)] - | q`Boogie.monoDeclPush => - let args ← checkOpArg arg q`Boogie.monoDeclPush 2 + | q`Core.monoDeclPush => + let args ← checkOpArg arg q`Core.monoDeclPush 2 let fst ← translateMonoDeclList bindings args[0]! let (id, mty) ← translateMonoBindMk bindings args[1]! pure (fst ++ ListMap.ofList [(id, mty)]) @@ -433,185 +433,185 @@ def isArithTy : LMonoTy → Bool | .bitvec _ => true | _ => false -def translateFn (ty? : Option LMonoTy) (q : QualifiedIdent) : TransM Boogie.Expression.Expr := +def translateFn (ty? : Option LMonoTy) (q : QualifiedIdent) : TransM Core.Expression.Expr := match ty?, q with - | _, q`Boogie.equiv => return boolEquivOp - | _, q`Boogie.implies => return boolImpliesOp - | _, q`Boogie.and => return boolAndOp - | _, q`Boogie.or => return boolOrOp - | _, q`Boogie.not => return boolNotOp - - | .some .int, q`Boogie.le => return intLeOp - | .some .int, q`Boogie.lt => return intLtOp - | .some .int, q`Boogie.ge => return intGeOp - | .some .int, q`Boogie.gt => return intGtOp - | .some .int, q`Boogie.add_expr => return intAddOp - | .some .int, q`Boogie.sub_expr => return intSubOp - | .some .int, q`Boogie.mul_expr => return intMulOp - | .some .int, q`Boogie.div_expr => return intDivOp - | .some .int, q`Boogie.mod_expr => return intModOp - | .some .int, q`Boogie.neg_expr => return intNegOp - - | .some .real, q`Boogie.le => return realLeOp - | .some .real, q`Boogie.lt => return realLtOp - | .some .real, q`Boogie.ge => return realGeOp - | .some .real, q`Boogie.gt => return realGtOp - | .some .real, q`Boogie.add_expr => return realAddOp - | .some .real, q`Boogie.sub_expr => return realSubOp - | .some .real, q`Boogie.mul_expr => return realMulOp - | .some .real, q`Boogie.div_expr => return realDivOp - | .some .real, q`Boogie.neg_expr => return realNegOp - - | .some .bv1, q`Boogie.le => return bv1ULeOp - | .some .bv1, q`Boogie.lt => return bv1ULtOp - | .some .bv1, q`Boogie.ge => return bv1UGeOp - | .some .bv1, q`Boogie.gt => return bv1UGtOp - | .some .bv1, q`Boogie.bvsle => return bv1SLeOp - | .some .bv1, q`Boogie.bvslt => return bv1SLtOp - | .some .bv1, q`Boogie.bvsge => return bv1SGeOp - | .some .bv1, q`Boogie.bvsgt => return bv1SGtOp - | .some .bv1, q`Boogie.neg_expr => return bv1NegOp - | .some .bv1, q`Boogie.add_expr => return bv1AddOp - | .some .bv1, q`Boogie.sub_expr => return bv1SubOp - | .some .bv1, q`Boogie.mul_expr => return bv1MulOp - | .some .bv1, q`Boogie.div_expr => return bv1UDivOp - | .some .bv1, q`Boogie.mod_expr => return bv1UModOp - | .some .bv1, q`Boogie.bvsdiv => return bv1SDivOp - | .some .bv1, q`Boogie.bvsmod => return bv1SModOp - | .some .bv1, q`Boogie.bvnot => return bv1NotOp - | .some .bv1, q`Boogie.bvand => return bv1AndOp - | .some .bv1, q`Boogie.bvor => return bv1OrOp - | .some .bv1, q`Boogie.bvxor => return bv1XorOp - | .some .bv1, q`Boogie.bvshl => return bv1ShlOp - | .some .bv1, q`Boogie.bvushr => return bv1UShrOp - | .some .bv1, q`Boogie.bvsshr => return bv1SShrOp - - | .some .bv8, q`Boogie.le => return bv8ULeOp - | .some .bv8, q`Boogie.lt => return bv8ULtOp - | .some .bv8, q`Boogie.ge => return bv8UGeOp - | .some .bv8, q`Boogie.gt => return bv8UGtOp - | .some .bv8, q`Boogie.bvsle => return bv8SLeOp - | .some .bv8, q`Boogie.bvslt => return bv8SLtOp - | .some .bv8, q`Boogie.bvsge => return bv8SGeOp - | .some .bv8, q`Boogie.bvsgt => return bv8SGtOp - | .some .bv8, q`Boogie.neg_expr => return bv8NegOp - | .some .bv8, q`Boogie.add_expr => return bv8AddOp - | .some .bv8, q`Boogie.sub_expr => return bv8SubOp - | .some .bv8, q`Boogie.mul_expr => return bv8MulOp - | .some .bv8, q`Boogie.div_expr => return bv8UDivOp - | .some .bv8, q`Boogie.mod_expr => return bv8UModOp - | .some .bv8, q`Boogie.bvsdiv => return bv8SDivOp - | .some .bv8, q`Boogie.bvsmod => return bv8SModOp - | .some .bv8, q`Boogie.bvnot => return bv8NotOp - | .some .bv8, q`Boogie.bvand => return bv8AndOp - | .some .bv8, q`Boogie.bvor => return bv8OrOp - | .some .bv8, q`Boogie.bvxor => return bv8XorOp - | .some .bv8, q`Boogie.bvshl => return bv8ShlOp - | .some .bv8, q`Boogie.bvushr => return bv8UShrOp - | .some .bv8, q`Boogie.bvsshr => return bv8SShrOp - - | .some .bv16, q`Boogie.le => return bv16ULeOp - | .some .bv16, q`Boogie.lt => return bv16ULtOp - | .some .bv16, q`Boogie.ge => return bv16UGeOp - | .some .bv16, q`Boogie.gt => return bv16UGtOp - | .some .bv16, q`Boogie.bvsle => return bv16SLeOp - | .some .bv16, q`Boogie.bvslt => return bv16SLtOp - | .some .bv16, q`Boogie.bvsge => return bv16SGeOp - | .some .bv16, q`Boogie.bvsgt => return bv16SGtOp - | .some .bv16, q`Boogie.neg_expr => return bv16NegOp - | .some .bv16, q`Boogie.add_expr => return bv16AddOp - | .some .bv16, q`Boogie.sub_expr => return bv16SubOp - | .some .bv16, q`Boogie.mul_expr => return bv16MulOp - | .some .bv16, q`Boogie.div_expr => return bv16UDivOp - | .some .bv16, q`Boogie.mod_expr => return bv16UModOp - | .some .bv16, q`Boogie.bvsdiv => return bv16SDivOp - | .some .bv16, q`Boogie.bvsmod => return bv16SModOp - | .some .bv16, q`Boogie.bvnot => return bv16NotOp - | .some .bv16, q`Boogie.bvand => return bv16AndOp - | .some .bv16, q`Boogie.bvor => return bv16OrOp - | .some .bv16, q`Boogie.bvxor => return bv16XorOp - | .some .bv16, q`Boogie.bvshl => return bv16ShlOp - | .some .bv16, q`Boogie.bvushr => return bv16UShrOp - | .some .bv16, q`Boogie.bvsshr => return bv16SShrOp - - | .some .bv32, q`Boogie.le => return bv32ULeOp - | .some .bv32, q`Boogie.lt => return bv32ULtOp - | .some .bv32, q`Boogie.ge => return bv32UGeOp - | .some .bv32, q`Boogie.gt => return bv32UGtOp - | .some .bv32, q`Boogie.bvsle => return bv32SLeOp - | .some .bv32, q`Boogie.bvslt => return bv32SLtOp - | .some .bv32, q`Boogie.bvsge => return bv32SGeOp - | .some .bv32, q`Boogie.bvsgt => return bv32SGtOp - | .some .bv32, q`Boogie.neg_expr => return bv32NegOp - | .some .bv32, q`Boogie.add_expr => return bv32AddOp - | .some .bv32, q`Boogie.sub_expr => return bv32SubOp - | .some .bv32, q`Boogie.mul_expr => return bv32MulOp - | .some .bv32, q`Boogie.div_expr => return bv32UDivOp - | .some .bv32, q`Boogie.mod_expr => return bv32UModOp - | .some .bv32, q`Boogie.bvsdiv => return bv32SDivOp - | .some .bv32, q`Boogie.bvsmod => return bv32SModOp - | .some .bv32, q`Boogie.bvnot => return bv32NotOp - | .some .bv32, q`Boogie.bvand => return bv32AndOp - | .some .bv32, q`Boogie.bvor => return bv32OrOp - | .some .bv32, q`Boogie.bvxor => return bv32XorOp - | .some .bv32, q`Boogie.bvshl => return bv32ShlOp - | .some .bv32, q`Boogie.bvushr => return bv32UShrOp - | .some .bv32, q`Boogie.bvsshr => return bv32SShrOp - - | .some .bv64, q`Boogie.le => return bv64ULeOp - | .some .bv64, q`Boogie.lt => return bv64ULtOp - | .some .bv64, q`Boogie.ge => return bv64UGeOp - | .some .bv64, q`Boogie.gt => return bv64UGtOp - | .some .bv64, q`Boogie.bvsle => return bv64SLeOp - | .some .bv64, q`Boogie.bvslt => return bv64SLtOp - | .some .bv64, q`Boogie.bvsge => return bv64SGeOp - | .some .bv64, q`Boogie.bvsgt => return bv64SGtOp - | .some .bv64, q`Boogie.neg_expr => return bv64NegOp - | .some .bv64, q`Boogie.add_expr => return bv64AddOp - | .some .bv64, q`Boogie.sub_expr => return bv64SubOp - | .some .bv64, q`Boogie.mul_expr => return bv64MulOp - | .some .bv64, q`Boogie.div_expr => return bv64UDivOp - | .some .bv64, q`Boogie.mod_expr => return bv64UModOp - | .some .bv64, q`Boogie.bvsdiv => return bv64SDivOp - | .some .bv64, q`Boogie.bvsmod => return bv64SModOp - | .some .bv64, q`Boogie.bvnot => return bv64NotOp - | .some .bv64, q`Boogie.bvand => return bv64AndOp - | .some .bv64, q`Boogie.bvor => return bv64OrOp - | .some .bv64, q`Boogie.bvxor => return bv64XorOp - | .some .bv64, q`Boogie.bvshl => return bv64ShlOp - | .some .bv64, q`Boogie.bvushr => return bv64UShrOp - | .some .bv64, q`Boogie.bvsshr => return bv64SShrOp - - | _, q`Boogie.bvconcat8 => return bv8ConcatOp - | _, q`Boogie.bvconcat16 => return bv16ConcatOp - | _, q`Boogie.bvconcat32 => return bv32ConcatOp - | _, q`Boogie.bvextract_7_7 => return bv8Extract_7_7_Op - | _, q`Boogie.bvextract_15_15 => return bv16Extract_15_15_Op - | _, q`Boogie.bvextract_31_31 => return bv32Extract_31_31_Op - | _, q`Boogie.bvextract_7_0_16 => return bv16Extract_7_0_Op - | _, q`Boogie.bvextract_7_0_32 => return bv32Extract_7_0_Op - | _, q`Boogie.bvextract_15_0_32 => return bv32Extract_15_0_Op - | _, q`Boogie.bvextract_7_0_64 => return bv64Extract_7_0_Op - | _, q`Boogie.bvextract_15_0_64 => return bv64Extract_15_0_Op - | _, q`Boogie.bvextract_31_0_64 => return bv64Extract_31_0_Op - - | _, q`Boogie.old => return polyOldOp - | _, q`Boogie.str_len => return strLengthOp - | _, q`Boogie.str_concat => return strConcatOp - | _, q`Boogie.str_substr => return strSubstrOp - | _, q`Boogie.str_toregex => return strToRegexOp - | _, q`Boogie.str_inregex => return strInRegexOp - | _, q`Boogie.re_all => return reAllOp - | _, q`Boogie.re_allchar => return reAllCharOp - | _, q`Boogie.re_range => return reRangeOp - | _, q`Boogie.re_concat => return reConcatOp - | _, q`Boogie.re_star => return reStarOp - | _, q`Boogie.re_plus => return rePlusOp - | _, q`Boogie.re_loop => return reLoopOp - | _, q`Boogie.re_union => return reUnionOp - | _, q`Boogie.re_inter => return reInterOp - | _, q`Boogie.re_comp => return reCompOp - | _, q`Boogie.re_none => return reNoneOp + | _, q`Core.equiv => return boolEquivOp + | _, q`Core.implies => return boolImpliesOp + | _, q`Core.and => return boolAndOp + | _, q`Core.or => return boolOrOp + | _, q`Core.not => return boolNotOp + + | .some .int, q`Core.le => return intLeOp + | .some .int, q`Core.lt => return intLtOp + | .some .int, q`Core.ge => return intGeOp + | .some .int, q`Core.gt => return intGtOp + | .some .int, q`Core.add_expr => return intAddOp + | .some .int, q`Core.sub_expr => return intSubOp + | .some .int, q`Core.mul_expr => return intMulOp + | .some .int, q`Core.div_expr => return intDivOp + | .some .int, q`Core.mod_expr => return intModOp + | .some .int, q`Core.neg_expr => return intNegOp + + | .some .real, q`Core.le => return realLeOp + | .some .real, q`Core.lt => return realLtOp + | .some .real, q`Core.ge => return realGeOp + | .some .real, q`Core.gt => return realGtOp + | .some .real, q`Core.add_expr => return realAddOp + | .some .real, q`Core.sub_expr => return realSubOp + | .some .real, q`Core.mul_expr => return realMulOp + | .some .real, q`Core.div_expr => return realDivOp + | .some .real, q`Core.neg_expr => return realNegOp + + | .some .bv1, q`Core.le => return bv1ULeOp + | .some .bv1, q`Core.lt => return bv1ULtOp + | .some .bv1, q`Core.ge => return bv1UGeOp + | .some .bv1, q`Core.gt => return bv1UGtOp + | .some .bv1, q`Core.bvsle => return bv1SLeOp + | .some .bv1, q`Core.bvslt => return bv1SLtOp + | .some .bv1, q`Core.bvsge => return bv1SGeOp + | .some .bv1, q`Core.bvsgt => return bv1SGtOp + | .some .bv1, q`Core.neg_expr => return bv1NegOp + | .some .bv1, q`Core.add_expr => return bv1AddOp + | .some .bv1, q`Core.sub_expr => return bv1SubOp + | .some .bv1, q`Core.mul_expr => return bv1MulOp + | .some .bv1, q`Core.div_expr => return bv1UDivOp + | .some .bv1, q`Core.mod_expr => return bv1UModOp + | .some .bv1, q`Core.bvsdiv => return bv1SDivOp + | .some .bv1, q`Core.bvsmod => return bv1SModOp + | .some .bv1, q`Core.bvnot => return bv1NotOp + | .some .bv1, q`Core.bvand => return bv1AndOp + | .some .bv1, q`Core.bvor => return bv1OrOp + | .some .bv1, q`Core.bvxor => return bv1XorOp + | .some .bv1, q`Core.bvshl => return bv1ShlOp + | .some .bv1, q`Core.bvushr => return bv1UShrOp + | .some .bv1, q`Core.bvsshr => return bv1SShrOp + + | .some .bv8, q`Core.le => return bv8ULeOp + | .some .bv8, q`Core.lt => return bv8ULtOp + | .some .bv8, q`Core.ge => return bv8UGeOp + | .some .bv8, q`Core.gt => return bv8UGtOp + | .some .bv8, q`Core.bvsle => return bv8SLeOp + | .some .bv8, q`Core.bvslt => return bv8SLtOp + | .some .bv8, q`Core.bvsge => return bv8SGeOp + | .some .bv8, q`Core.bvsgt => return bv8SGtOp + | .some .bv8, q`Core.neg_expr => return bv8NegOp + | .some .bv8, q`Core.add_expr => return bv8AddOp + | .some .bv8, q`Core.sub_expr => return bv8SubOp + | .some .bv8, q`Core.mul_expr => return bv8MulOp + | .some .bv8, q`Core.div_expr => return bv8UDivOp + | .some .bv8, q`Core.mod_expr => return bv8UModOp + | .some .bv8, q`Core.bvsdiv => return bv8SDivOp + | .some .bv8, q`Core.bvsmod => return bv8SModOp + | .some .bv8, q`Core.bvnot => return bv8NotOp + | .some .bv8, q`Core.bvand => return bv8AndOp + | .some .bv8, q`Core.bvor => return bv8OrOp + | .some .bv8, q`Core.bvxor => return bv8XorOp + | .some .bv8, q`Core.bvshl => return bv8ShlOp + | .some .bv8, q`Core.bvushr => return bv8UShrOp + | .some .bv8, q`Core.bvsshr => return bv8SShrOp + + | .some .bv16, q`Core.le => return bv16ULeOp + | .some .bv16, q`Core.lt => return bv16ULtOp + | .some .bv16, q`Core.ge => return bv16UGeOp + | .some .bv16, q`Core.gt => return bv16UGtOp + | .some .bv16, q`Core.bvsle => return bv16SLeOp + | .some .bv16, q`Core.bvslt => return bv16SLtOp + | .some .bv16, q`Core.bvsge => return bv16SGeOp + | .some .bv16, q`Core.bvsgt => return bv16SGtOp + | .some .bv16, q`Core.neg_expr => return bv16NegOp + | .some .bv16, q`Core.add_expr => return bv16AddOp + | .some .bv16, q`Core.sub_expr => return bv16SubOp + | .some .bv16, q`Core.mul_expr => return bv16MulOp + | .some .bv16, q`Core.div_expr => return bv16UDivOp + | .some .bv16, q`Core.mod_expr => return bv16UModOp + | .some .bv16, q`Core.bvsdiv => return bv16SDivOp + | .some .bv16, q`Core.bvsmod => return bv16SModOp + | .some .bv16, q`Core.bvnot => return bv16NotOp + | .some .bv16, q`Core.bvand => return bv16AndOp + | .some .bv16, q`Core.bvor => return bv16OrOp + | .some .bv16, q`Core.bvxor => return bv16XorOp + | .some .bv16, q`Core.bvshl => return bv16ShlOp + | .some .bv16, q`Core.bvushr => return bv16UShrOp + | .some .bv16, q`Core.bvsshr => return bv16SShrOp + + | .some .bv32, q`Core.le => return bv32ULeOp + | .some .bv32, q`Core.lt => return bv32ULtOp + | .some .bv32, q`Core.ge => return bv32UGeOp + | .some .bv32, q`Core.gt => return bv32UGtOp + | .some .bv32, q`Core.bvsle => return bv32SLeOp + | .some .bv32, q`Core.bvslt => return bv32SLtOp + | .some .bv32, q`Core.bvsge => return bv32SGeOp + | .some .bv32, q`Core.bvsgt => return bv32SGtOp + | .some .bv32, q`Core.neg_expr => return bv32NegOp + | .some .bv32, q`Core.add_expr => return bv32AddOp + | .some .bv32, q`Core.sub_expr => return bv32SubOp + | .some .bv32, q`Core.mul_expr => return bv32MulOp + | .some .bv32, q`Core.div_expr => return bv32UDivOp + | .some .bv32, q`Core.mod_expr => return bv32UModOp + | .some .bv32, q`Core.bvsdiv => return bv32SDivOp + | .some .bv32, q`Core.bvsmod => return bv32SModOp + | .some .bv32, q`Core.bvnot => return bv32NotOp + | .some .bv32, q`Core.bvand => return bv32AndOp + | .some .bv32, q`Core.bvor => return bv32OrOp + | .some .bv32, q`Core.bvxor => return bv32XorOp + | .some .bv32, q`Core.bvshl => return bv32ShlOp + | .some .bv32, q`Core.bvushr => return bv32UShrOp + | .some .bv32, q`Core.bvsshr => return bv32SShrOp + + | .some .bv64, q`Core.le => return bv64ULeOp + | .some .bv64, q`Core.lt => return bv64ULtOp + | .some .bv64, q`Core.ge => return bv64UGeOp + | .some .bv64, q`Core.gt => return bv64UGtOp + | .some .bv64, q`Core.bvsle => return bv64SLeOp + | .some .bv64, q`Core.bvslt => return bv64SLtOp + | .some .bv64, q`Core.bvsge => return bv64SGeOp + | .some .bv64, q`Core.bvsgt => return bv64SGtOp + | .some .bv64, q`Core.neg_expr => return bv64NegOp + | .some .bv64, q`Core.add_expr => return bv64AddOp + | .some .bv64, q`Core.sub_expr => return bv64SubOp + | .some .bv64, q`Core.mul_expr => return bv64MulOp + | .some .bv64, q`Core.div_expr => return bv64UDivOp + | .some .bv64, q`Core.mod_expr => return bv64UModOp + | .some .bv64, q`Core.bvsdiv => return bv64SDivOp + | .some .bv64, q`Core.bvsmod => return bv64SModOp + | .some .bv64, q`Core.bvnot => return bv64NotOp + | .some .bv64, q`Core.bvand => return bv64AndOp + | .some .bv64, q`Core.bvor => return bv64OrOp + | .some .bv64, q`Core.bvxor => return bv64XorOp + | .some .bv64, q`Core.bvshl => return bv64ShlOp + | .some .bv64, q`Core.bvushr => return bv64UShrOp + | .some .bv64, q`Core.bvsshr => return bv64SShrOp + + | _, q`Core.bvconcat8 => return bv8ConcatOp + | _, q`Core.bvconcat16 => return bv16ConcatOp + | _, q`Core.bvconcat32 => return bv32ConcatOp + | _, q`Core.bvextract_7_7 => return bv8Extract_7_7_Op + | _, q`Core.bvextract_15_15 => return bv16Extract_15_15_Op + | _, q`Core.bvextract_31_31 => return bv32Extract_31_31_Op + | _, q`Core.bvextract_7_0_16 => return bv16Extract_7_0_Op + | _, q`Core.bvextract_7_0_32 => return bv32Extract_7_0_Op + | _, q`Core.bvextract_15_0_32 => return bv32Extract_15_0_Op + | _, q`Core.bvextract_7_0_64 => return bv64Extract_7_0_Op + | _, q`Core.bvextract_15_0_64 => return bv64Extract_15_0_Op + | _, q`Core.bvextract_31_0_64 => return bv64Extract_31_0_Op + + | _, q`Core.old => return polyOldOp + | _, q`Core.str_len => return strLengthOp + | _, q`Core.str_concat => return strConcatOp + | _, q`Core.str_substr => return strSubstrOp + | _, q`Core.str_toregex => return strToRegexOp + | _, q`Core.str_inregex => return strInRegexOp + | _, q`Core.re_all => return reAllOp + | _, q`Core.re_allchar => return reAllCharOp + | _, q`Core.re_range => return reRangeOp + | _, q`Core.re_concat => return reConcatOp + | _, q`Core.re_star => return reStarOp + | _, q`Core.re_plus => return rePlusOp + | _, q`Core.re_loop => return reLoopOp + | _, q`Core.re_union => return reUnionOp + | _, q`Core.re_inter => return reInterOp + | _, q`Core.re_comp => return reCompOp + | _, q`Core.re_none => return reNoneOp | _, _ => TransM.error s!"translateFn: Unknown/unimplemented function {repr q} at type {repr ty?}" mutual @@ -621,7 +621,7 @@ def translateQuantifier (qk: QuantifierKind) (p : Program) (bindings : TransBindings) (xsa : Arg) (triggersa: Option Arg) (bodya: Arg) : - TransM Boogie.Expression.Expr := do + TransM Core.Expression.Expr := do let xsArray ← translateDeclList bindings xsa -- Note: the indices in the following are placeholders let newBoundVars := List.toArray (xsArray.mapIdx (fun i _ => LExpr.bvar () i)) @@ -650,163 +650,163 @@ def translateQuantifier partial def translateTriggerGroup (p: Program) (bindings : TransBindings) (arg : Arg) : - TransM Boogie.Expression.Expr := do + TransM Core.Expression.Expr := do let .op op := arg | TransM.error s!"translateTriggerGroup expected op, got {repr arg}" match op.name, op.args with - | q`Boogie.trigger, #[tsa] => do + | q`Core.trigger, #[tsa] => do let ts ← translateCommaSep (fun t => translateExpr p bindings t) tsa return ts.foldl (fun g t => .app () (.app () addTriggerOp t) g) emptyTriggerGroupOp | _, _ => panic! s!"Unexpected operator in trigger group" partial def translateTriggers (p: Program) (bindings : TransBindings) (arg : Arg) : - TransM Boogie.Expression.Expr := do + TransM Core.Expression.Expr := do let .op op := arg | TransM.error s!"translateTriggers expected op, got: {repr arg}" match op.name, op.args with - | q`Boogie.triggersAtom, #[group] => + | q`Core.triggersAtom, #[group] => let g ← translateTriggerGroup p bindings group return .app () (.app () addTriggerGroupOp g) emptyTriggersOp - | q`Boogie.triggersPush, #[triggers, group] => do + | q`Core.triggersPush, #[triggers, group] => do let ts ← translateTriggers p bindings triggers let g ← translateTriggerGroup p bindings group return .app () (.app () addTriggerGroupOp g) ts | _, _ => panic! s!"Unexpected operator in trigger" partial def translateExpr (p : Program) (bindings : TransBindings) (arg : Arg) : - TransM Boogie.Expression.Expr := do + TransM Core.Expression.Expr := do let .expr expr := arg | TransM.error s!"translateExpr expected expr {repr arg}" let (op, args) := expr.flatten match op, args with -- Constants/Literals - | .fn _ q`Boogie.btrue, [] => + | .fn _ q`Core.btrue, [] => return .true () - | .fn _ q`Boogie.bfalse, [] => + | .fn _ q`Core.bfalse, [] => return .false () - | .fn _ q`Boogie.natToInt, [xa] => + | .fn _ q`Core.natToInt, [xa] => let n ← translateNat xa return .intConst () n - | .fn _ q`Boogie.bv1Lit, [xa] => + | .fn _ q`Core.bv1Lit, [xa] => let n ← translateBitVec 1 xa return .bitvecConst () 1 n - | .fn _ q`Boogie.bv8Lit, [xa] => + | .fn _ q`Core.bv8Lit, [xa] => let n ← translateBitVec 8 xa return .bitvecConst () 8 n - | .fn _ q`Boogie.bv16Lit, [xa] => + | .fn _ q`Core.bv16Lit, [xa] => let n ← translateBitVec 16 xa return .bitvecConst () 16 n - | .fn _ q`Boogie.bv32Lit, [xa] => + | .fn _ q`Core.bv32Lit, [xa] => let n ← translateBitVec 32 xa return .bitvecConst () 32 n - | .fn _ q`Boogie.bv64Lit, [xa] => + | .fn _ q`Core.bv64Lit, [xa] => let n ← translateBitVec 64 xa return .bitvecConst () 64 n - | .fn _ q`Boogie.strLit, [xa] => + | .fn _ q`Core.strLit, [xa] => let x ← translateStr xa return .strConst () x - | .fn _ q`Boogie.realLit, [xa] => + | .fn _ q`Core.realLit, [xa] => let x ← translateReal xa return .realConst () (Strata.Decimal.toRat x) -- Equality - | .fn _ q`Boogie.equal, [_tpa, xa, ya] => + | .fn _ q`Core.equal, [_tpa, xa, ya] => let x ← translateExpr p bindings xa let y ← translateExpr p bindings ya return .eq () x y - | .fn _ q`Boogie.not_equal, [_tpa, xa, ya] => + | .fn _ q`Core.not_equal, [_tpa, xa, ya] => let x ← translateExpr p bindings xa let y ← translateExpr p bindings ya - return (.app () Boogie.boolNotOp (.eq () x y)) - | .fn _ q`Boogie.bvnot, [tpa, xa] => + return (.app () Core.boolNotOp (.eq () x y)) + | .fn _ q`Core.bvnot, [tpa, xa] => let tp ← translateLMonoTy bindings (dealiasTypeArg p tpa) let x ← translateExpr p bindings xa - let fn : LExpr BoogieLParams.mono ← - translateFn (.some tp) q`Boogie.bvnot + let fn : LExpr CoreLParams.mono ← + translateFn (.some tp) q`Core.bvnot return (.app () fn x) -- If-then-else expression - | .fn _ q`Boogie.if, [_tpa, ca, ta, fa] => + | .fn _ q`Core.if, [_tpa, ca, ta, fa] => let c ← translateExpr p bindings ca let t ← translateExpr p bindings ta let f ← translateExpr p bindings fa return .ite () c t f -- Re.AllChar - | .fn _ q`Boogie.re_allchar, [] => - let fn ← translateFn .none q`Boogie.re_allchar + | .fn _ q`Core.re_allchar, [] => + let fn ← translateFn .none q`Core.re_allchar return fn -- Re.None - | .fn _ q`Boogie.re_none, [] => - let fn ← translateFn .none q`Boogie.re_none + | .fn _ q`Core.re_none, [] => + let fn ← translateFn .none q`Core.re_none return fn -- Re.All - | .fn _ q`Boogie.re_all, [] => - let fn ← translateFn .none q`Boogie.re_all + | .fn _ q`Core.re_all, [] => + let fn ← translateFn .none q`Core.re_all return fn -- Unary function applications | .fn _ fni, [xa] => match fni with - | q`Boogie.not - | q`Boogie.bvextract_7_7 - | q`Boogie.bvextract_15_15 - | q`Boogie.bvextract_31_31 - | q`Boogie.bvextract_7_0_16 - | q`Boogie.bvextract_7_0_32 - | q`Boogie.bvextract_15_0_32 - | q`Boogie.bvextract_7_0_64 - | q`Boogie.bvextract_15_0_64 - | q`Boogie.bvextract_31_0_64 - | q`Boogie.str_len - | q`Boogie.str_toregex - | q`Boogie.re_star - | q`Boogie.re_plus - | q`Boogie.re_comp => do + | q`Core.not + | q`Core.bvextract_7_7 + | q`Core.bvextract_15_15 + | q`Core.bvextract_31_31 + | q`Core.bvextract_7_0_16 + | q`Core.bvextract_7_0_32 + | q`Core.bvextract_15_0_32 + | q`Core.bvextract_7_0_64 + | q`Core.bvextract_15_0_64 + | q`Core.bvextract_31_0_64 + | q`Core.str_len + | q`Core.str_toregex + | q`Core.re_star + | q`Core.re_plus + | q`Core.re_comp => do let fn ← translateFn .none fni let x ← translateExpr p bindings xa return .mkApp () fn [x] | _ => TransM.error s!"translateExpr unimplemented {repr op} {repr args}" - | .fn _ q`Boogie.neg_expr, [tpa, xa] => + | .fn _ q`Core.neg_expr, [tpa, xa] => let ty ← translateLMonoTy bindings (dealiasTypeArg p tpa) - let fn ← translateFn ty q`Boogie.neg_expr + let fn ← translateFn ty q`Core.neg_expr let x ← translateExpr p bindings xa return .mkApp () fn [x] -- Strings - | .fn _ q`Boogie.str_concat, [xa, ya] => + | .fn _ q`Core.str_concat, [xa, ya] => let x ← translateExpr p bindings xa let y ← translateExpr p bindings ya - return .mkApp () Boogie.strConcatOp [x, y] - | .fn _ q`Boogie.str_substr, [xa, ia, na] => + return .mkApp () Core.strConcatOp [x, y] + | .fn _ q`Core.str_substr, [xa, ia, na] => let x ← translateExpr p bindings xa let i ← translateExpr p bindings ia let n ← translateExpr p bindings na - return .mkApp () Boogie.strSubstrOp [x, i, n] - | .fn _ q`Boogie.old, [_tp, xa] => + return .mkApp () Core.strSubstrOp [x, i, n] + | .fn _ q`Core.old, [_tp, xa] => let x ← translateExpr p bindings xa - return .mkApp () Boogie.polyOldOp [x] - | .fn _ q`Boogie.map_get, [_ktp, _vtp, ma, ia] => + return .mkApp () Core.polyOldOp [x] + | .fn _ q`Core.map_get, [_ktp, _vtp, ma, ia] => let kty ← translateLMonoTy bindings _ktp let vty ← translateLMonoTy bindings _vtp - -- TODO: use Boogie.mapSelectOp, but specialized - let fn : LExpr BoogieLParams.mono := (LExpr.op () "select" (.some (LMonoTy.mkArrow (mapTy kty vty) [kty, vty]))) + -- TODO: use Core.mapSelectOp, but specialized + let fn : LExpr CoreLParams.mono := (LExpr.op () "select" (.some (LMonoTy.mkArrow (mapTy kty vty) [kty, vty]))) let m ← translateExpr p bindings ma let i ← translateExpr p bindings ia return .mkApp () fn [m, i] - | .fn _ q`Boogie.map_set, [_ktp, _vtp, ma, ia, xa] => + | .fn _ q`Core.map_set, [_ktp, _vtp, ma, ia, xa] => let kty ← translateLMonoTy bindings _ktp let vty ← translateLMonoTy bindings _vtp - -- TODO: use Boogie.mapUpdateOp, but specialized - let fn : LExpr BoogieLParams.mono := (LExpr.op () "update" (.some (LMonoTy.mkArrow (mapTy kty vty) [kty, vty, mapTy kty vty]))) + -- TODO: use Core.mapUpdateOp, but specialized + let fn : LExpr CoreLParams.mono := (LExpr.op () "update" (.some (LMonoTy.mkArrow (mapTy kty vty) [kty, vty, mapTy kty vty]))) let m ← translateExpr p bindings ma let i ← translateExpr p bindings ia let x ← translateExpr p bindings xa return .mkApp () fn [m, i, x] -- Quantifiers - | .fn _ q`Boogie.forall, [xsa, ba] => + | .fn _ q`Core.forall, [xsa, ba] => translateQuantifier .all p bindings xsa .none ba - | .fn _ q`Boogie.exists, [xsa, ba] => + | .fn _ q`Core.exists, [xsa, ba] => translateQuantifier .exist p bindings xsa .none ba - | .fn _ q`Boogie.forallT, [xsa, tsa, ba] => + | .fn _ q`Core.forallT, [xsa, tsa, ba] => translateQuantifier .all p bindings xsa (.some tsa) ba - | .fn _ q`Boogie.existsT, [xsa, tsa, ba] => + | .fn _ q`Core.existsT, [xsa, tsa, ba] => translateQuantifier .exist p bindings xsa (.some tsa) ba -- Binary function applications (monomorphic) | .fn _ fni, [xa, ya] => @@ -814,8 +814,8 @@ partial def translateExpr (p : Program) (bindings : TransBindings) (arg : Arg) : let x ← translateExpr p bindings xa let y ← translateExpr p bindings ya return .mkApp () fn [x, y] - | .fn _ q`Boogie.re_loop, [xa, ya, za] => - let fn ← translateFn .none q`Boogie.re_loop + | .fn _ q`Core.re_loop, [xa, ya, za] => + let fn ← translateFn .none q`Core.re_loop let x ← translateExpr p bindings xa let y ← translateExpr p bindings ya let z ← translateExpr p bindings za @@ -823,27 +823,27 @@ partial def translateExpr (p : Program) (bindings : TransBindings) (arg : Arg) : -- Binary function applications (polymorphic) | .fn _ fni, [tpa, xa, ya] => match fni with - | q`Boogie.add_expr - | q`Boogie.sub_expr - | q`Boogie.mul_expr - | q`Boogie.div_expr - | q`Boogie.mod_expr - | q`Boogie.bvand - | q`Boogie.bvor - | q`Boogie.bvxor - | q`Boogie.bvshl - | q`Boogie.bvushr - | q`Boogie.bvsshr - | q`Boogie.bvsdiv - | q`Boogie.bvsmod - | q`Boogie.le - | q`Boogie.lt - | q`Boogie.gt - | q`Boogie.ge - | q`Boogie.bvsle - | q`Boogie.bvslt - | q`Boogie.bvsgt - | q`Boogie.bvsge => + | q`Core.add_expr + | q`Core.sub_expr + | q`Core.mul_expr + | q`Core.div_expr + | q`Core.mod_expr + | q`Core.bvand + | q`Core.bvor + | q`Core.bvxor + | q`Core.bvshl + | q`Core.bvushr + | q`Core.bvsshr + | q`Core.bvsdiv + | q`Core.bvsmod + | q`Core.le + | q`Core.lt + | q`Core.gt + | q`Core.ge + | q`Core.bvsle + | q`Core.bvslt + | q`Core.bvsgt + | q`Core.bvsge => let ty ← translateLMonoTy bindings (dealiasTypeArg p tpa) if ¬ isArithTy ty then TransM.error s!"translateExpr unexpected type for {repr fni}: {repr args}" @@ -879,7 +879,7 @@ partial def translateExpr (p : Program) (bindings : TransBindings) (arg : Arg) : | _ => TransM.error s!"translateExpr unimplemented fvar decl (no args): {format decl}" | .fvar _ i, argsa => - -- Call of a function declared/defined in Boogie. + -- Call of a function declared/defined in Core. assert! i < bindings.freeVars.size let decl := bindings.freeVars[i]! match decl with @@ -895,7 +895,7 @@ partial def translateExpr (p : Program) (bindings : TransBindings) (arg : Arg) : Bindings: {format bindings}}" partial def translateExprs (p : Program) (bindings : TransBindings) (args : Array Arg) : - TransM (Array Boogie.Expression.Expr) := + TransM (Array Core.Expression.Expr) := args.mapM (fun a => translateExpr p bindings a) end @@ -904,22 +904,22 @@ end def translateInvariant (p : Program) (bindings : TransBindings) (arg : Arg) : TransM (Option Expression.Expr) := do match arg with | .option _ (.some m) => do - let args ← checkOpArg m q`Boogie.invariant 1 + let args ← checkOpArg m q`Core.invariant 1 translateExpr p bindings args[0]! | _ => pure none def initVarStmts (tpids : ListMap Expression.Ident LTy) (bindings : TransBindings) : - TransM ((List Boogie.Statement) × TransBindings) := do + TransM ((List Core.Statement) × TransBindings) := do match tpids with | [] => return ([], bindings) | (id, tp) :: rest => - let s := Boogie.Statement.init id tp (Names.initVarValue (id.name ++ "_" ++ (toString bindings.gen.var_def))) + let s := Core.Statement.init id tp (Names.initVarValue (id.name ++ "_" ++ (toString bindings.gen.var_def))) let bindings := incrNum .var_def bindings let (stmts, bindings) ← initVarStmts rest bindings return ((s :: stmts), bindings) def translateVarStatement (bindings : TransBindings) (decls : Array Arg) : - TransM ((List Boogie.Statement) × TransBindings) := do + TransM ((List Core.Statement) × TransBindings) := do if decls.size != 1 then TransM.error s!"translateVarStatement unexpected decls length {repr decls}" else @@ -927,103 +927,103 @@ def translateVarStatement (bindings : TransBindings) (decls : Array Arg) : let (stmts, bindings) ← initVarStmts tpids bindings let newVars ← tpids.mapM (fun (id, ty) => if h: ty.isMonoType then - return ((LExpr.fvar () id (ty.toMonoType h)): LExpr BoogieLParams.mono) + return ((LExpr.fvar () id (ty.toMonoType h)): LExpr CoreLParams.mono) else TransM.error s!"translateVarStatement requires {id} to have a monomorphic type, but it has type {ty}") let bbindings := bindings.boundVars ++ newVars return (stmts, { bindings with boundVars := bbindings }) def translateInitStatement (p : Program) (bindings : TransBindings) (args : Array Arg) : - TransM ((List Boogie.Statement) × TransBindings) := do + TransM ((List Core.Statement) × TransBindings) := do if args.size != 3 then TransM.error "translateInitStatement unexpected arg length {repr decls}" else let mty ← translateLMonoTy bindings args[0]! - let lhs ← translateIdent BoogieIdent args[1]! + let lhs ← translateIdent CoreIdent args[1]! let val ← translateExpr p bindings args[2]! let ty := (.forAll [] mty) - let newBinding: LExpr BoogieLParams.mono := LExpr.fvar () lhs mty + let newBinding: LExpr CoreLParams.mono := LExpr.fvar () lhs mty let bbindings := bindings.boundVars ++ [newBinding] return ([.init lhs ty val], { bindings with boundVars := bbindings }) mutual partial def translateStmt (p : Program) (bindings : TransBindings) (arg : Arg) : - TransM (List Boogie.Statement × TransBindings) := do + TransM (List Core.Statement × TransBindings) := do let .op op := arg | TransM.error s!"translateStmt expected op {repr arg}" match op.name, op.args with - | q`Boogie.varStatement, declsa => + | q`Core.varStatement, declsa => translateVarStatement bindings declsa - | q`Boogie.initStatement, args => + | q`Core.initStatement, args => translateInitStatement p bindings args - | q`Boogie.assign, #[_tpa, lhsa, ea] => + | q`Core.assign, #[_tpa, lhsa, ea] => let lhs ← translateLhs lhsa let val ← translateExpr p bindings ea let md ← getOpMetaData op return ([.set lhs val md], bindings) - | q`Boogie.havoc_statement, #[ida] => - let id ← translateIdent BoogieIdent ida + | q`Core.havoc_statement, #[ida] => + let id ← translateIdent CoreIdent ida let md ← getOpMetaData op return ([.havoc id md], bindings) - | q`Boogie.assert, #[la, ca] => + | q`Core.assert, #[la, ca] => let c ← translateExpr p bindings ca let default_name := s!"assert_{bindings.gen.assert_def}" let bindings := incrNum .assert_def bindings let l ← translateOptionLabel default_name la let md ← getOpMetaData op return ([.assert l c md], bindings) - | q`Boogie.cover, #[la, ca] => + | q`Core.cover, #[la, ca] => let c ← translateExpr p bindings ca let default_name := s!"cover_{bindings.gen.assert_def}" let bindings := incrNum .cover_def bindings let l ← translateOptionLabel default_name la let md ← getOpMetaData op return ([.cover l c md], bindings) - | q`Boogie.assume, #[la, ca] => + | q`Core.assume, #[la, ca] => let c ← translateExpr p bindings ca let default_name := s!"assume_{bindings.gen.assume_def}" let bindings := incrNum .assume_def bindings let l ← translateOptionLabel default_name la let md ← getOpMetaData op return ([.assume l c md], bindings) - | q`Boogie.if_statement, #[ca, ta, fa] => + | q`Core.if_statement, #[ca, ta, fa] => let c ← translateExpr p bindings ca let (tss, bindings) ← translateBlock p bindings ta let (fss, bindings) ← translateElse p bindings fa let md ← getOpMetaData op return ([.ite c tss fss md], bindings) - | q`Boogie.while_statement, #[ca, ia, ba] => + | q`Core.while_statement, #[ca, ia, ba] => let c ← translateExpr p bindings ca let i ← translateInvariant p bindings ia let (bodyss, bindings) ← translateBlock p bindings ba let md ← getOpMetaData op return ([.loop c .none i bodyss md], bindings) - | q`Boogie.call_statement, #[lsa, fa, esa] => - let ls ← translateCommaSep (translateIdent BoogieIdent) lsa + | q`Core.call_statement, #[lsa, fa, esa] => + let ls ← translateCommaSep (translateIdent CoreIdent) lsa let f ← translateIdent String fa let es ← translateCommaSep (fun a => translateExpr p bindings a) esa let md ← getOpMetaData op return ([.call ls.toList f es.toList md], bindings) - | q`Boogie.call_unit_statement, #[fa, esa] => + | q`Core.call_unit_statement, #[fa, esa] => let f ← translateIdent String fa let es ← translateCommaSep (fun a => translateExpr p bindings a) esa let md ← getOpMetaData op return ([.call [] f es.toList md], bindings) - | q`Boogie.block_statement, #[la, ba] => + | q`Core.block_statement, #[la, ba] => let l ← translateIdent String la let (ss, bindings) ← translateBlock p bindings ba let md ← getOpMetaData op return ([.block l ss md], bindings) - | q`Boogie.goto_statement, #[la] => + | q`Core.goto_statement, #[la] => let l ← translateIdent String la let md ← getOpMetaData op return ([.goto l md], bindings) | name, args => TransM.error s!"Unexpected statement {name.fullName} with {args.size} arguments." partial def translateBlock (p : Program) (bindings : TransBindings) (arg : Arg) : - TransM ((List Boogie.Statement) × TransBindings) := do - let args ← checkOpArg arg q`Boogie.block 1 + TransM ((List Core.Statement) × TransBindings) := do + let args ← checkOpArg arg q`Core.block 1 let .seq _ .none stmts := args[0]! | TransM.error s!"Invalid block {repr args[0]!}" let (a, bindings) ← stmts.foldlM (init := (#[], bindings)) fun (a, b) s => do @@ -1032,15 +1032,15 @@ partial def translateBlock (p : Program) (bindings : TransBindings) (arg : Arg) return (a.toList, bindings) partial def translateElse (p : Program) (bindings : TransBindings) (arg : Arg) : - TransM ((List Boogie.Statement) × TransBindings) := do + TransM ((List Core.Statement) × TransBindings) := do let .op op := arg | TransM.error s!"translateElse expected op {repr arg}" match op.name with - | q`Boogie.else0 => - let _ ← checkOpArg arg q`Boogie.else0 0 + | q`Core.else0 => + let _ ← checkOpArg arg q`Core.else0 0 return ([], bindings) - | q`Boogie.else1 => - let args ← checkOpArg arg q`Boogie.else1 1 + | q`Core.else1 => + let args ← checkOpArg arg q`Core.else1 1 translateBlock p bindings args[0]! | _ => TransM.error s!"translateElse unimplemented for {repr arg}" @@ -1049,20 +1049,20 @@ end --------------------------------------------------------------------- def translateInitMkBinding (bindings : TransBindings) (op : Arg) : - TransM (BoogieIdent × LMonoTy) := do + TransM (CoreIdent × LMonoTy) := do -- (FIXME) Account for metadata. - let bargs ← checkOpArg op q`Boogie.mkBinding 2 - let id ← translateIdent BoogieIdent bargs[0]! + let bargs ← checkOpArg op q`Core.mkBinding 2 + let id ← translateIdent CoreIdent bargs[0]! let tp ← translateLMonoTy bindings bargs[1]! return (id, tp) def translateInitMkBindings (bindings : TransBindings) (ops : Array Arg) : - TransM (Array (BoogieIdent × LMonoTy)) := do + TransM (Array (CoreIdent × LMonoTy)) := do ops.mapM (fun op => translateInitMkBinding bindings op) def translateBindings (bindings : TransBindings) (op : Arg) : - TransM (ListMap BoogieIdent LMonoTy) := do - let bargs ← checkOpArg op q`Boogie.mkBindings 1 + TransM (ListMap CoreIdent LMonoTy) := do + let bargs ← checkOpArg op q`Core.mkBindings 1 match bargs[0]! with | .seq _ .comma args => let arr ← translateInitMkBindings bindings args @@ -1070,57 +1070,57 @@ def translateBindings (bindings : TransBindings) (op : Arg) : | _ => TransM.error s!"translateBindings expects a comma separated list: {repr op}" -def translateModifies (arg : Arg) : TransM BoogieIdent := do - let args ← checkOpArg arg q`Boogie.modifies_spec 1 - translateIdent BoogieIdent args[0]! +def translateModifies (arg : Arg) : TransM CoreIdent := do + let args ← checkOpArg arg q`Core.modifies_spec 1 + translateIdent CoreIdent args[0]! def translateOptionFree (arg : Arg) : TransM Procedure.CheckAttr := do let .option _ free := arg | TransM.error s!"translateOptionFree unexpected {repr arg}" match free with | some f => - let _ ← checkOpArg f q`Boogie.free 0 + let _ ← checkOpArg f q`Core.free 0 return .Free | none => return .Default -def translateRequires (p : Program) (name : BoogieIdent) (count : Nat) (bindings : TransBindings) (arg : Arg) : - TransM (ListMap BoogieLabel Procedure.Check) := do - let args ← checkOpArg arg q`Boogie.requires_spec 3 +def translateRequires (p : Program) (name : CoreIdent) (count : Nat) (bindings : TransBindings) (arg : Arg) : + TransM (ListMap CoreLabel Procedure.Check) := do + let args ← checkOpArg arg q`Core.requires_spec 3 let l ← translateOptionLabel s!"{name.name}_requires_{count}" args[0]! let free? ← translateOptionFree args[1]! let e ← translateExpr p bindings args[2]! let md ← getArgMetaData arg return [(l, { expr := e, attr := free?, md := md })] -def translateEnsures (p : Program) (name : BoogieIdent) (count : Nat) (bindings : TransBindings) (arg : Arg) : - TransM (ListMap BoogieLabel Procedure.Check) := do - let args ← checkOpArg arg q`Boogie.ensures_spec 3 +def translateEnsures (p : Program) (name : CoreIdent) (count : Nat) (bindings : TransBindings) (arg : Arg) : + TransM (ListMap CoreLabel Procedure.Check) := do + let args ← checkOpArg arg q`Core.ensures_spec 3 let l ← translateOptionLabel s!"{name.name}_ensures_{count}" args[0]! let free? ← translateOptionFree args[1]! let e ← translateExpr p bindings args[2]! let md ← getArgMetaData arg return [(l, { expr := e, attr := free?, md := md })] -def translateSpecElem (p : Program) (name : BoogieIdent) (count : Nat) (bindings : TransBindings) (arg : Arg) : - TransM (List BoogieIdent × ListMap BoogieLabel Procedure.Check × ListMap BoogieLabel Procedure.Check) := do +def translateSpecElem (p : Program) (name : CoreIdent) (count : Nat) (bindings : TransBindings) (arg : Arg) : + TransM (List CoreIdent × ListMap CoreLabel Procedure.Check × ListMap CoreLabel Procedure.Check) := do let .op op := arg | TransM.error s!"translateSpecElem expects an op {repr arg}" match op.name with - | q`Boogie.modifies_spec => + | q`Core.modifies_spec => let elem ← translateModifies arg return ([elem], [], []) - | q`Boogie.requires_spec => + | q`Core.requires_spec => let elem ← translateRequires p name count bindings arg return ([], elem, []) - | q`Boogie.ensures_spec => + | q`Core.ensures_spec => let elem ← translateEnsures p name count bindings arg return ([], [], elem) | _ => TransM.error s!"translateSpecElem unimplemented for {repr arg}" -partial def translateSpec (p : Program) (name : BoogieIdent) (bindings : TransBindings) (arg : Arg) : - TransM (List BoogieIdent × ListMap BoogieLabel Procedure.Check × ListMap BoogieLabel Procedure.Check) := do - let sargs ← checkOpArg arg q`Boogie.spec_mk 1 +partial def translateSpec (p : Program) (name : CoreIdent) (bindings : TransBindings) (arg : Arg) : + TransM (List CoreIdent × ListMap CoreLabel Procedure.Check × ListMap CoreLabel Procedure.Check) := do + let sargs ← checkOpArg arg q`Core.spec_mk 1 let .seq _ .none args := sargs[0]! | TransM.error s!"Invalid specs {repr sargs[0]!}" go 0 args.size args @@ -1134,9 +1134,9 @@ partial def translateSpec (p : Program) (name : BoogieIdent) (bindings : TransBi return (mods ++ restmods, reqs ++ restreqs, ens ++ restens) def translateProcedure (p : Program) (bindings : TransBindings) (op : Operation) : - TransM (Boogie.Decl × TransBindings) := do - let _ ← @checkOp (Boogie.Decl × TransBindings) op q`Boogie.command_procedure 6 - let pname ← translateIdent BoogieIdent op.args[0]! + TransM (Core.Decl × TransBindings) := do + let _ ← @checkOp (Core.Decl × TransBindings) op q`Core.command_procedure 6 + let pname ← translateIdent CoreIdent op.args[0]! let typeArgs ← translateTypeArgs op.args[1]! let sig ← translateBindings bindings op.args[2]! let ret ← translateOptionMonoDeclList bindings op.args[3]! @@ -1171,9 +1171,9 @@ def translateProcedure (p : Program) (bindings : TransBindings) (op : Operation) --------------------------------------------------------------------- def translateConstant (bindings : TransBindings) (op : Operation) : - TransM (Boogie.Decl × TransBindings) := do - let _ ← @checkOp (Boogie.Decl × TransBindings) op q`Boogie.command_constdecl 3 - let cname ← translateIdent BoogieIdent op.args[0]! + TransM (Core.Decl × TransBindings) := do + let _ ← @checkOp (Core.Decl × TransBindings) op q`Core.command_constdecl 3 + let cname ← translateIdent CoreIdent op.args[0]! let typeArgs ← translateTypeArgs op.args[1]! let ret ← translateLMonoTy bindings op.args[2]! let md ← getOpMetaData op @@ -1188,8 +1188,8 @@ def translateConstant (bindings : TransBindings) (op : Operation) : --------------------------------------------------------------------- def translateAxiom (p : Program) (bindings : TransBindings) (op : Operation) : - TransM (Boogie.Decl × TransBindings) := do - let _ ← @checkOp (Boogie.Decl × TransBindings) op q`Boogie.command_axiom 2 + TransM (Core.Decl × TransBindings) := do + let _ ← @checkOp (Core.Decl × TransBindings) op q`Core.command_axiom 2 let default_name := s!"axiom_{bindings.gen.axiom_def}" let bindings := incrNum .axiom_def bindings let l ← translateOptionLabel default_name op.args[0]! @@ -1198,8 +1198,8 @@ def translateAxiom (p : Program) (bindings : TransBindings) (op : Operation) : return (.ax (Axiom.mk l e) md, bindings) def translateDistinct (p : Program) (bindings : TransBindings) (op : Operation) : - TransM (Boogie.Decl × TransBindings) := do - let _ ← @checkOp (Boogie.Decl × TransBindings) op q`Boogie.command_distinct 2 + TransM (Core.Decl × TransBindings) := do + let _ ← @checkOp (Core.Decl × TransBindings) op q`Core.command_distinct 2 let default_name := s!"axiom_distinct_{bindings.gen.axiom_def}" let bindings := incrNum .axiom_def bindings let l ← translateOptionLabel default_name op.args[0]! @@ -1224,17 +1224,17 @@ def translateOptionInline (arg : Arg) : TransM (Array String) := do | TransM.error s!"translateOptionInline unexpected {repr arg}" match inline with | some f => - let _ ← checkOpArg f q`Boogie.inline 0 + let _ ← checkOpArg f q`Core.inline 0 return #["inline"] | none => return #[] def translateFunction (status : FnInterp) (p : Program) (bindings : TransBindings) (op : Operation) : - TransM (Boogie.Decl × TransBindings) := do + TransM (Core.Decl × TransBindings) := do let _ ← match status with - | .Definition => @checkOp (Boogie.Decl × TransBindings) op q`Boogie.command_fndef 6 - | .Declaration => @checkOp (Boogie.Decl × TransBindings) op q`Boogie.command_fndecl 4 - let fname ← translateIdent BoogieIdent op.args[0]! + | .Definition => @checkOp (Core.Decl × TransBindings) op q`Core.command_fndef 6 + | .Declaration => @checkOp (Core.Decl × TransBindings) op q`Core.command_fndecl 4 + let fname ← translateIdent CoreIdent op.args[0]! let typeArgs ← translateTypeArgs op.args[1]! let sig ← translateBindings bindings op.args[2]! let ret ← translateLMonoTy bindings op.args[3]! @@ -1268,14 +1268,14 @@ def translateFunction (status : FnInterp) (p : Program) (bindings : TransBinding /-- Information about a single constructor extracted during translation. -This is the Boogie-specific version of `ConstructorInfo` from AST.lean, +This is the Strata Core-specific version of `ConstructorInfo` from AST.lean, with types translated from `TypeExpr` to `LMonoTy`. -/ structure TransConstructorInfo where /-- Constructor name -/ - name : BoogieIdent + name : CoreIdent /-- Fields as (fieldName, fieldType) pairs with translated types -/ - fields : Array (BoogieIdent × LMonoTy) + fields : Array (CoreIdent × LMonoTy) deriving Repr /-- @@ -1305,7 +1305,7 @@ def translateConstructorList (p : Program) (bindings : TransBindings) (arg : Arg Translate a datatype declaration to Boogie declarations, updating bindings appropriately. -**Important:** The returned `Boogie.Decls` only contains the type declaration +**Important:** The returned `Core.Decls` only contains the type declaration itself. Factory functions (constructors, testers, destructors) are generated automatically by `Env.addDatatypes` during program evaluation to avoid duplicates. @@ -1316,9 +1316,9 @@ duplicates. - `op`: The `command_datatype` operation to translate -/ def translateDatatype (p : Program) (bindings : TransBindings) (op : Operation) : - TransM (Boogie.Decls × TransBindings) := do + TransM (Core.Decls × TransBindings) := do -- Check operation has correct name and argument count - let _ ← @checkOp (Boogie.Decls × TransBindings) op q`Boogie.command_datatype 3 + let _ ← @checkOp (Core.Decls × TransBindings) op q`Core.command_datatype 3 let datatypeName ← translateIdent String op.args[0]! @@ -1329,7 +1329,7 @@ def translateDatatype (p : Program) (bindings : TransBindings) (op : Operation) do match maybearg with | none => pure ([], bindings) | some arg => - let bargs ← checkOpArg arg q`Boogie.mkBindings 1 + let bargs ← checkOpArg arg q`Core.mkBindings 1 let args ← match bargs[0]! with | .seq _ .comma args => @@ -1347,7 +1347,7 @@ def translateDatatype (p : Program) (bindings : TransBindings) (op : Operation) typeArgs := typeArgs constrs := [{ name := datatypeName, args := [], testerName := "" }] constrs_ne := by simp } - let placeholderDecl := Boogie.Decl.type (.data placeholderLDatatype) + let placeholderDecl := Core.Decl.type (.data placeholderLDatatype) let bindingsWithPlaceholder := { bindings with freeVars := bindings.freeVars.push placeholderDecl } -- Extract constructor information (possibly recursive) @@ -1374,16 +1374,16 @@ def translateDatatype (p : Program) (bindings : TransBindings) (op : Operation) constrs := lConstrs constrs_ne := constrs_ne } - -- Generate factory from LDatatype and convert to Boogie.Decl + -- Generate factory from LDatatype and convert to Core.Decl -- (used only for bindings.freeVars, not for allDecls) - let factory ← match ldatatype.genFactory (T := BoogieLParams) with + let factory ← match ldatatype.genFactory (T := CoreLParams) with | .ok f => pure f | .error e => TransM.error s!"Failed to generate datatype factory: {e}" - let funcDecls : List Boogie.Decl := factory.toList.map fun func => - Boogie.Decl.func func + let funcDecls : List Core.Decl := factory.toList.map fun func => + Core.Decl.func func -- Only includes typeDecl, factory functions generated later - let typeDecl := Boogie.Decl.type (.data ldatatype) + let typeDecl := Core.Decl.type (.data ldatatype) let allDecls := [typeDecl] /- @@ -1427,8 +1427,8 @@ def translateDatatype (p : Program) (bindings : TransBindings) (op : Operation) --------------------------------------------------------------------- def translateGlobalVar (bindings : TransBindings) (op : Operation) : - TransM (Boogie.Decl × TransBindings) := do - let _ ← @checkOp (Boogie.Decl × TransBindings) op q`Boogie.command_var 1 + TransM (Core.Decl × TransBindings) := do + let _ ← @checkOp (Core.Decl × TransBindings) op q`Core.command_var 1 let (id, targs, mty) ← translateBindMk bindings op.args[0]! let ty := LTy.forAll targs mty let md ← getOpMetaData op @@ -1438,11 +1438,11 @@ def translateGlobalVar (bindings : TransBindings) (op : Operation) : --------------------------------------------------------------------- -partial def translateBoogieDecls (p : Program) (bindings : TransBindings) : - TransM Boogie.Decls := do +partial def translateCoreDecls (p : Program) (bindings : TransBindings) : + TransM Core.Decls := do let (decls, _) ← go 0 p.commands.size bindings p.commands return decls - where go (count max : Nat) bindings ops : TransM (Boogie.Decls × TransBindings) := do + where go (count max : Nat) bindings ops : TransM (Core.Decls × TransBindings) := do match (max - count) with | 0 => return ([], bindings) | _ + 1 => @@ -1450,37 +1450,37 @@ partial def translateBoogieDecls (p : Program) (bindings : TransBindings) : -- Commands that produce multiple declarations let (newDecls, bindings) ← match op.name with - | q`Boogie.command_datatype => + | q`Core.command_datatype => translateDatatype p bindings op | _ => -- All other commands produce a single declaration let (decl, bindings) ← match op.name with - | q`Boogie.command_var => + | q`Core.command_var => translateGlobalVar bindings op - | q`Boogie.command_constdecl => + | q`Core.command_constdecl => translateConstant bindings op - | q`Boogie.command_typedecl => + | q`Core.command_typedecl => translateTypeDecl bindings op - | q`Boogie.command_typesynonym => + | q`Core.command_typesynonym => translateTypeSynonym bindings op - | q`Boogie.command_axiom => + | q`Core.command_axiom => translateAxiom p bindings op - | q`Boogie.command_distinct => + | q`Core.command_distinct => translateDistinct p bindings op - | q`Boogie.command_procedure => + | q`Core.command_procedure => translateProcedure p bindings op - | q`Boogie.command_fndef => + | q`Core.command_fndef => translateFunction .Definition p bindings op - | q`Boogie.command_fndecl => + | q`Core.command_fndecl => translateFunction .Declaration p bindings op - | _ => TransM.error s!"translateBoogieDecls unimplemented for {repr op}" + | _ => TransM.error s!"translateCoreDecls unimplemented for {repr op}" pure ([decl], bindings) let (decls, bindings) ← go (count + 1) max bindings ops return (newDecls ++ decls, bindings) -def translateProgram (p : Program) : TransM Boogie.Program := do - let decls ← translateBoogieDecls p {} +def translateProgram (p : Program) : TransM Core.Program := do + let decls ← translateCoreDecls p {} return { decls := decls } --------------------------------------------------------------------- diff --git a/Strata/Languages/Boogie/Env.lean b/Strata/Languages/Core/Env.lean similarity index 88% rename from Strata/Languages/Boogie/Env.lean rename to Strata/Languages/Core/Env.lean index 1ebc91778..2ecb1694d 100644 --- a/Strata/Languages/Boogie/Env.lean +++ b/Strata/Languages/Core/Env.lean @@ -6,10 +6,10 @@ -import Strata.Languages.Boogie.Program +import Strata.Languages.Core.Program import Strata.DL.Imperative.EvalContext -namespace Boogie +namespace Core open Std (ToFormat Format format) open Imperative @@ -18,11 +18,11 @@ instance : ToFormat ExpressionMetadata := -- ToFormat instance for Expression.Expr instance : ToFormat Expression.Expr := by - show ToFormat (Lambda.LExpr BoogieLParams.mono) + show ToFormat (Lambda.LExpr CoreLParams.mono) infer_instance -- Custom ToFormat instance for our specific Scope type to get the desired formatting -private def formatScope (m : Map BoogieIdent (Option Lambda.LMonoTy × Expression.Expr)) : Std.Format := +private def formatScope (m : Map CoreIdent (Option Lambda.LMonoTy × Expression.Expr)) : Std.Format := match m with | [] => "" | [(k, (ty, v))] => go k ty v @@ -33,7 +33,7 @@ private def formatScope (m : Map BoogieIdent (Option Lambda.LMonoTy × Expressio | some ty => f!"({k} : {ty}) → {v}" | none => f!"{k} → {v}" -instance : ToFormat (Map BoogieIdent (Option Lambda.LMonoTy × Expression.Expr)) where +instance : ToFormat (Map CoreIdent (Option Lambda.LMonoTy × Expression.Expr)) where format := formatScope instance : Inhabited ExpressionMetadata := @@ -42,8 +42,8 @@ instance : Inhabited ExpressionMetadata := instance : Lambda.Traceable Lambda.LExpr.EvalProvenance ExpressionMetadata where combine _ := () -instance : Inhabited (Lambda.LExpr ⟨⟨ExpressionMetadata, BoogieIdent⟩, LMonoTy⟩) := - show Inhabited (Lambda.LExpr ⟨⟨Unit, BoogieIdent⟩, LMonoTy⟩) from inferInstance +instance : Inhabited (Lambda.LExpr ⟨⟨ExpressionMetadata, CoreIdent⟩, LMonoTy⟩) := + show Inhabited (Lambda.LExpr ⟨⟨Unit, CoreIdent⟩, LMonoTy⟩) from inferInstance --------------------------------------------------------------------- @@ -140,7 +140,7 @@ structure Env where def Env.init (empty_factory:=false): Env := let σ := Lambda.LState.init - let σ := if empty_factory then σ else σ.setFactory Boogie.Factory + let σ := if empty_factory then σ else σ.setFactory Core.Factory { error := none, program := Program.init, substMap := [], @@ -184,7 +184,7 @@ def oldVarSubst (subst : SubstMap) (E : Env) : SubstMap := def Env.exprEval (E : Env) (e : Expression.Expr) : Expression.Expr := e.eval E.exprEnv.config.fuel E.exprEnv -def Env.pushScope (E : Env) (scope : (Lambda.Scope BoogieLParams)) : Env := +def Env.pushScope (E : Env) (scope : (Lambda.Scope CoreLParams)) : Env := { E with exprEnv.state := E.exprEnv.state.push scope } def Env.pushEmptyScope (E : Env) : Env := @@ -193,14 +193,14 @@ def Env.pushEmptyScope (E : Env) : Env := def Env.popScope (E : Env) : Env := { E with exprEnv.state := E.exprEnv.state.pop } -def Env.factory (E : Env) : (@Lambda.Factory BoogieLParams) := +def Env.factory (E : Env) : (@Lambda.Factory CoreLParams) := E.exprEnv.config.factory -def Env.addFactory (E : Env) (f : (@Lambda.Factory BoogieLParams)) : Except Format Env := do +def Env.addFactory (E : Env) (f : (@Lambda.Factory CoreLParams)) : Except Format Env := do let exprEnv ← E.exprEnv.addFactory f .ok { E with exprEnv := exprEnv } -def Env.addFactoryFunc (E : Env) (func : (Lambda.LFunc BoogieLParams)) : Except Format Env := do +def Env.addFactoryFunc (E : Env) (func : (Lambda.LFunc CoreLParams)) : Except Format Env := do let exprEnv ← E.exprEnv.addFactoryFunc func .ok { E with exprEnv := exprEnv } @@ -216,16 +216,16 @@ def Env.addToContext List.foldl (fun E (x, v) => E.insertInContext x v) E xs -- TODO: prove uniqueness, add different prefix -def Env.genSym (x : String) (c : Lambda.EvalConfig BoogieLParams) : BoogieIdent × Lambda.EvalConfig BoogieLParams := +def Env.genSym (x : String) (c : Lambda.EvalConfig CoreLParams) : CoreIdent × Lambda.EvalConfig CoreLParams := let new_idx := c.gen let c := c.incGen let new_var := c.varPrefix ++ x ++ toString new_idx (.temp new_var, c) -def Env.genVar' (x : String) (σ : (Lambda.LState BoogieLParams)) : - (BoogieIdent × (Lambda.LState BoogieLParams)) := +def Env.genVar' (x : String) (σ : (Lambda.LState CoreLParams)) : + (CoreIdent × (Lambda.LState CoreLParams)) := let (new_var, config) := Env.genSym x σ.config - let σ : Lambda.LState BoogieLParams := { σ with config := config } + let σ : Lambda.LState CoreLParams := { σ with config := config } -- let known_vars := Lambda.LState.knownVars σ -- if new_var ∈ known_vars then -- panic s!"[LState.genVar] Generated variable {Std.format new_var} is not fresh!\n\ @@ -239,7 +239,7 @@ def Env.genVar (x : Expression.Ident) (E : Env) : Expression.Ident × Env := let (var, σ) := Env.genVar' name E.exprEnv (var, { E with exprEnv := σ }) -def Env.genVars (xs : List String) (σ : Lambda.LState BoogieLParams) : (List BoogieIdent × Lambda.LState BoogieLParams) := +def Env.genVars (xs : List String) (σ : Lambda.LState CoreLParams) : (List CoreIdent × Lambda.LState CoreLParams) := match xs with | [] => ([], σ) | x :: rest => @@ -319,10 +319,10 @@ def Env.merge (cond : Expression.Expr) (E1 E2 : Env) : Env := Env.performMerge cond E1 E2 (by simp_all) (by simp_all) def Env.addDatatypes (E: Env) (datatypes: List (Lambda.LDatatype Visibility)) : Except Format Env := do - let f ← Lambda.TypeFactory.genFactory (T:=BoogieLParams) (datatypes.toArray) + let f ← Lambda.TypeFactory.genFactory (T:=CoreLParams) (datatypes.toArray) let env ← E.addFactory f return { env with datatypes := datatypes.toArray } -end Boogie +end Core --------------------------------------------------------------------- diff --git a/Strata/Languages/Boogie/Expressions.lean b/Strata/Languages/Core/Expressions.lean similarity index 90% rename from Strata/Languages/Boogie/Expressions.lean rename to Strata/Languages/Core/Expressions.lean index ba9cef6f1..60d37b6f7 100644 --- a/Strata/Languages/Boogie/Expressions.lean +++ b/Strata/Languages/Core/Expressions.lean @@ -8,17 +8,17 @@ import Strata.DL.Lambda.Lambda import Strata.DL.Imperative.PureExpr -import Strata.Languages.Boogie.Identifiers +import Strata.Languages.Core.Identifiers import Strata.DL.Imperative.HasVars -namespace Boogie +namespace Core open Std (ToFormat Format format) --------------------------------------------------------------------- def ExpressionMetadata := Unit abbrev Expression : Imperative.PureExpr := - { Ident := BoogieIdent, + { Ident := CoreIdent, EqIdent := inferInstanceAs (DecidableEq (Lambda.Identifier _)) Expr := Lambda.LExpr ⟨⟨ExpressionMetadata, Visibility⟩, Lambda.LMonoTy⟩, Ty := Lambda.LTy, @@ -34,4 +34,4 @@ instance : Inhabited Expression.Expr where --------------------------------------------------------------------- -end Boogie +end Core diff --git a/Strata/Languages/Boogie/Factory.lean b/Strata/Languages/Core/Factory.lean similarity index 76% rename from Strata/Languages/Boogie/Factory.lean rename to Strata/Languages/Core/Factory.lean index d99db8b9d..ee1e98e7c 100644 --- a/Strata/Languages/Boogie/Factory.lean +++ b/Strata/Languages/Core/Factory.lean @@ -5,13 +5,13 @@ -/ import Lean.Elab.Command -import Strata.Languages.Boogie.Identifiers -import Strata.Languages.Boogie.Expressions +import Strata.Languages.Core.Identifiers +import Strata.Languages.Core.Expressions import Strata.DL.Lambda.Factory import Strata.DL.Lambda.IntBoolFactory --------------------------------------------------------------------- -namespace Boogie +namespace Core open Lambda LTy.Syntax LExpr.SyntaxMono @[match_pattern] @@ -41,24 +41,24 @@ def TImplicit {Metadata: Type} (IDMeta: Type): LExprParamsT := ({Metadata := Met Convert an LExpr LMonoTy Unit to an LExpr LMonoTy Visibility TODO: Remove when Lambda elaborator offers parametric identifier type -/ -def ToBoogieIdent {M: Type} (ine: LExpr (@TImplicit M Unit)): LExpr (@TImplicit M Visibility) := +def ToCoreIdent {M: Type} (ine: LExpr (@TImplicit M Unit)): LExpr (@TImplicit M Visibility) := match ine with | .const m c => .const m c - | .op m o oty => .op m (BoogieIdent.unres o.name) oty + | .op m o oty => .op m (CoreIdent.unres o.name) oty | .bvar m deBruijnIndex => .bvar m deBruijnIndex - | .fvar m name oty => .fvar m (BoogieIdent.unres name.name) oty - | .abs m oty e => .abs m oty (ToBoogieIdent e) - | .quant m k oty tr e => .quant m k oty (ToBoogieIdent tr) (ToBoogieIdent e) - | .app m fn e => .app m (ToBoogieIdent fn) (ToBoogieIdent e) - | .ite m c t e => .ite m (ToBoogieIdent c) (ToBoogieIdent t) (ToBoogieIdent e) - | .eq m e1 e2 => .eq m (ToBoogieIdent e1) (ToBoogieIdent e2) + | .fvar m name oty => .fvar m (CoreIdent.unres name.name) oty + | .abs m oty e => .abs m oty (ToCoreIdent e) + | .quant m k oty tr e => .quant m k oty (ToCoreIdent tr) (ToCoreIdent e) + | .app m fn e => .app m (ToCoreIdent fn) (ToCoreIdent e) + | .ite m c t e => .ite m (ToCoreIdent c) (ToCoreIdent t) (ToCoreIdent e) + | .eq m e1 e2 => .eq m (ToCoreIdent e1) (ToCoreIdent e2) private def bvBinaryOp (fn:∀ {n}, BitVec n → BitVec n → BitVec n) (check:∀ {n}, BitVec n → BitVec n → Bool) - (m:BoogieLParams.Metadata) - (ops:List (LExpr BoogieLParams.mono)) - : Option (LExpr BoogieLParams.mono) := + (m:CoreLParams.Metadata) + (ops:List (LExpr CoreLParams.mono)) + : Option (LExpr CoreLParams.mono) := match ops with | [.bitvecConst _ n1 b1, .bitvecConst _ n2 b2] => if h : n1 = n2 then @@ -69,9 +69,9 @@ private def bvBinaryOp (fn:∀ {n}, BitVec n → BitVec n → BitVec n) | _ => .none private def bvShiftOp (fn:∀ {n}, BitVec n → Nat → BitVec n) - (m:BoogieLParams.Metadata) - (ops:List (LExpr BoogieLParams.mono)) - : Option (LExpr BoogieLParams.mono) := + (m:CoreLParams.Metadata) + (ops:List (LExpr CoreLParams.mono)) + : Option (LExpr CoreLParams.mono) := match ops with | [.bitvecConst _ n1 b1, .bitvecConst _ n2 b2] => let i2 := BitVec.toNat b2 @@ -81,18 +81,18 @@ private def bvShiftOp (fn:∀ {n}, BitVec n → Nat → BitVec n) | _ => .none private def bvUnaryOp (fn:∀ {n}, BitVec n → BitVec n) - (m:BoogieLParams.Metadata) - (ops:List (LExpr BoogieLParams.mono)) - : Option (LExpr BoogieLParams.mono) := + (m:CoreLParams.Metadata) + (ops:List (LExpr CoreLParams.mono)) + : Option (LExpr CoreLParams.mono) := match ops with | [.bitvecConst _ n b] => .some (.bitvecConst m n (fn b)) | _ => .none private def bvBinaryPred (fn:∀ {n}, BitVec n → BitVec n → Bool) (swap:Bool) - (m:BoogieLParams.Metadata) - (ops:List (LExpr BoogieLParams.mono)) - : Option (LExpr BoogieLParams.mono) := + (m:CoreLParams.Metadata) + (ops:List (LExpr CoreLParams.mono)) + : Option (LExpr CoreLParams.mono) := match ops with | [.bitvecConst _ n1 b1, .bitvecConst _ n2 b2] => if h : n1 = n2 then @@ -159,7 +159,7 @@ elab "ExpandBVOpFuncDefs" "[" sizes:num,* "]" : command => do let opName := Syntax.mkStrLit s!"Bv{s}.{op}" let bvTypeName := Name.mkSimple s!"bv{s}" let opStr := Syntax.mkStrLit op - elabCommand (← `(def $funcName : LFunc BoogieLParams := + elabCommand (← `(def $funcName : LFunc CoreLParams := $funcArity $opName mty[$(mkIdent bvTypeName):ident] ((BVOpEvals.find? (fun (k,_) => k == $opStr)).bind (fun (_,w)=>w)))) @@ -167,136 +167,136 @@ ExpandBVOpFuncDefs[1, 2, 8, 16, 32, 64] /- Real Arithmetic Operations -/ -def realAddFunc : LFunc BoogieLParams := binaryOp "Real.Add" mty[real] none -def realSubFunc : LFunc BoogieLParams := binaryOp "Real.Sub" mty[real] none -def realMulFunc : LFunc BoogieLParams := binaryOp "Real.Mul" mty[real] none -def realDivFunc : LFunc BoogieLParams := binaryOp "Real.Div" mty[real] none -def realNegFunc : LFunc BoogieLParams := unaryOp "Real.Neg" mty[real] none +def realAddFunc : LFunc CoreLParams := binaryOp "Real.Add" mty[real] none +def realSubFunc : LFunc CoreLParams := binaryOp "Real.Sub" mty[real] none +def realMulFunc : LFunc CoreLParams := binaryOp "Real.Mul" mty[real] none +def realDivFunc : LFunc CoreLParams := binaryOp "Real.Div" mty[real] none +def realNegFunc : LFunc CoreLParams := unaryOp "Real.Neg" mty[real] none /- Real Comparison Operations -/ -def realLtFunc : LFunc BoogieLParams := binaryPredicate "Real.Lt" mty[real] none -def realLeFunc : LFunc BoogieLParams := binaryPredicate "Real.Le" mty[real] none -def realGtFunc : LFunc BoogieLParams := binaryPredicate "Real.Gt" mty[real] none -def realGeFunc : LFunc BoogieLParams := binaryPredicate "Real.Ge" mty[real] none +def realLtFunc : LFunc CoreLParams := binaryPredicate "Real.Lt" mty[real] none +def realLeFunc : LFunc CoreLParams := binaryPredicate "Real.Le" mty[real] none +def realGtFunc : LFunc CoreLParams := binaryPredicate "Real.Gt" mty[real] none +def realGeFunc : LFunc CoreLParams := binaryPredicate "Real.Ge" mty[real] none /- String Operations -/ -def strLengthFunc : LFunc BoogieLParams := +def strLengthFunc : LFunc CoreLParams := { name := "Str.Length", typeArgs := [], inputs := [("x", mty[string])] output := mty[int], - concreteEval := some (unOpCeval (T:=BoogieLParams) String Int (.intConst (T:=BoogieLParams.mono)) (@LExpr.denoteString BoogieLParams) + concreteEval := some (unOpCeval (T:=CoreLParams) String Int (.intConst (T:=CoreLParams.mono)) (@LExpr.denoteString CoreLParams) (fun s => (Int.ofNat (String.length s))))} -def strConcatFunc : LFunc BoogieLParams := +def strConcatFunc : LFunc CoreLParams := { name := "Str.Concat", typeArgs := [], inputs := [("x", mty[string]), ("y", mty[string])] output := mty[string], - concreteEval := some (binOpCeval String String (.strConst (T := BoogieLParams.mono)) + concreteEval := some (binOpCeval String String (.strConst (T := CoreLParams.mono)) LExpr.denoteString String.append)} -def strSubstrFunc : LFunc BoogieLParams := +def strSubstrFunc : LFunc CoreLParams := { name := "Str.Substr", typeArgs := [], -- longest substring of `x` of length at most `n` starting at position `i`. inputs := [("x", mty[string]), ("i", mty[int]), ("n", mty[int])] output := mty[string] } -def strToRegexFunc : LFunc BoogieLParams := +def strToRegexFunc : LFunc CoreLParams := { name := "Str.ToRegEx", typeArgs := [], inputs := [("x", mty[string])] output := mty[regex] } -def strInRegexFunc : LFunc BoogieLParams := +def strInRegexFunc : LFunc CoreLParams := { name := "Str.InRegEx", typeArgs := [], inputs := [("x", mty[string]), ("y", mty[regex])] output := mty[bool] } -def reAllCharFunc : LFunc BoogieLParams := +def reAllCharFunc : LFunc CoreLParams := { name := "Re.AllChar", typeArgs := [], inputs := [] output := mty[regex] } -def reAllFunc : LFunc BoogieLParams := +def reAllFunc : LFunc CoreLParams := { name := "Re.All", typeArgs := [], inputs := [] output := mty[regex] } -def reRangeFunc : LFunc BoogieLParams := +def reRangeFunc : LFunc CoreLParams := { name := "Re.Range", typeArgs := [], inputs := [("x", mty[string]), ("y", mty[string])] output := mty[regex] } -def reConcatFunc : LFunc BoogieLParams := +def reConcatFunc : LFunc CoreLParams := { name := "Re.Concat", typeArgs := [], inputs := [("x", mty[regex]), ("y", mty[regex])] output := mty[regex] } -def reStarFunc : LFunc BoogieLParams := +def reStarFunc : LFunc CoreLParams := { name := "Re.Star", typeArgs := [], inputs := [("x", mty[regex])] output := mty[regex] } -def rePlusFunc : LFunc BoogieLParams := +def rePlusFunc : LFunc CoreLParams := { name := "Re.Plus", typeArgs := [], inputs := [("x", mty[regex])] output := mty[regex] } -def reLoopFunc : LFunc BoogieLParams := +def reLoopFunc : LFunc CoreLParams := { name := "Re.Loop", typeArgs := [], inputs := [("x", mty[regex]), ("n1", mty[int]), ("n2", mty[int])] output := mty[regex] } -def reUnionFunc : LFunc BoogieLParams := +def reUnionFunc : LFunc CoreLParams := { name := "Re.Union", typeArgs := [], inputs := [("x", mty[regex]), ("y", mty[regex])] output := mty[regex] } -def reInterFunc : LFunc BoogieLParams := +def reInterFunc : LFunc CoreLParams := { name := "Re.Inter", typeArgs := [], inputs := [("x", mty[regex]), ("y", mty[regex])] output := mty[regex] } -def reCompFunc : LFunc BoogieLParams := +def reCompFunc : LFunc CoreLParams := { name := "Re.Comp", typeArgs := [], inputs := [("x", mty[regex])] output := mty[regex] } -def reNoneFunc : LFunc BoogieLParams := +def reNoneFunc : LFunc CoreLParams := { name := "Re.None", typeArgs := [], inputs := [] output := mty[regex] } /- A polymorphic `old` function with type `∀a. a → a`. -/ -def polyOldFunc : LFunc BoogieLParams := +def polyOldFunc : LFunc CoreLParams := { name := "old", typeArgs := ["a"], - inputs := [((BoogieIdent.locl "x"), mty[%a])] + inputs := [((CoreIdent.locl "x"), mty[%a])] output := mty[%a]} /- A `Map` selection function with type `∀k, v. Map k v → k → v`. -/ -def mapSelectFunc : LFunc BoogieLParams := +def mapSelectFunc : LFunc CoreLParams := { name := "select", typeArgs := ["k", "v"], inputs := [("m", mapTy mty[%k] mty[%v]), ("i", mty[%k])], output := mty[%v] } /- A `Map` update function with type `∀k, v. Map k v → k → v → Map k v`. -/ -def mapUpdateFunc : LFunc BoogieLParams := +def mapUpdateFunc : LFunc CoreLParams := { name := "update", typeArgs := ["k", "v"], inputs := [("m", mapTy mty[%k] mty[%v]), ("i", mty[%k]), ("x", mty[%v])], @@ -304,7 +304,7 @@ def mapUpdateFunc : LFunc BoogieLParams := axioms := [ -- updateSelect: forall m: Map k v, kk: k, vv: v :: m[kk := vv][kk] == vv - ToBoogieIdent esM[∀(Map %k %v): + ToCoreIdent esM[∀(Map %k %v): (∀ (%k): (∀ (%v):{ (((~select : (Map %k %v) → %k → %v) @@ -312,7 +312,7 @@ def mapUpdateFunc : LFunc BoogieLParams := (((~select : (Map %k %v) → %k → %v) ((((~update : (Map %k %v) → %k → %v → (Map %k %v)) %2) %1) %0)) %1) == %0))], -- updatePreserve: forall m: Map k v, okk: k, kk: k, vv: v :: okk != kk ==> m[kk := vv][okk] == m[okk] - ToBoogieIdent esM[∀ (Map %k %v): -- %3 m + ToCoreIdent esM[∀ (Map %k %v): -- %3 m (∀ (%k): -- %2 okk (∀ (%k): -- %1 kk (∀ (%v): -- %0 vv @@ -331,28 +331,28 @@ def mapUpdateFunc : LFunc BoogieLParams := ] } -def emptyTriggersFunc : LFunc BoogieLParams := +def emptyTriggersFunc : LFunc CoreLParams := { name := "Triggers.empty", typeArgs := [], inputs := [], output := mty[Triggers], concreteEval := none } -def addTriggerGroupFunc : LFunc BoogieLParams := +def addTriggerGroupFunc : LFunc CoreLParams := { name := "Triggers.addGroup", typeArgs := [], inputs := [("g", mty[TriggerGroup]), ("t", mty[Triggers])], output := mty[Triggers], concreteEval := none } -def emptyTriggerGroupFunc : LFunc BoogieLParams := +def emptyTriggerGroupFunc : LFunc CoreLParams := { name := "TriggerGroup.empty", typeArgs := [], inputs := [], output := mty[TriggerGroup], concreteEval := none } -def addTriggerFunc : LFunc BoogieLParams := +def addTriggerFunc : LFunc CoreLParams := { name := "TriggerGroup.addTrigger", typeArgs := ["a"], inputs := [("x", mty[%a]), ("t", mty[TriggerGroup])], @@ -364,18 +364,18 @@ macro "ExpandBVOpFuncNames" "[" sizes:num,* "]" : term => do let mut allOps := #[] for size in sizes.getElems do let s := size.getNat.repr - let ops := BVOpNames.map (mkIdent ∘ (.str (.str .anonymous "Boogie")) ∘ (s!"bv{s}" ++ · ++ "Func")) + let ops := BVOpNames.map (mkIdent ∘ (.str (.str .anonymous "Core")) ∘ (s!"bv{s}" ++ · ++ "Func")) allOps := allOps ++ ops.toArray `([$(allOps),*]) -def bvConcatFunc (size : Nat) : LFunc BoogieLParams := +def bvConcatFunc (size : Nat) : LFunc CoreLParams := { name := s!"Bv{size}.Concat", typeArgs := [], inputs := [("x", .bitvec size), ("y", .bitvec size)] output := .bitvec (size*2), concreteEval := none } -def bvExtractFunc (size hi lo: Nat) : LFunc BoogieLParams := +def bvExtractFunc (size hi lo: Nat) : LFunc CoreLParams := { name := s!"Bv{size}.Extract_{hi}_{lo}", typeArgs := [], inputs := [("x", .bitvec size)] @@ -396,18 +396,18 @@ def bv64Extract_31_0_Func := bvExtractFunc 64 31 0 def bv64Extract_15_0_Func := bvExtractFunc 64 15 0 def bv64Extract_7_0_Func := bvExtractFunc 64 7 0 -def Factory : @Factory BoogieLParams := #[ - @intAddFunc BoogieLParams _, - @intSubFunc BoogieLParams _, - @intMulFunc BoogieLParams _, - @intDivFunc BoogieLParams _, - @intModFunc BoogieLParams _, - @intNegFunc BoogieLParams _, +def Factory : @Factory CoreLParams := #[ + @intAddFunc CoreLParams _, + @intSubFunc CoreLParams _, + @intMulFunc CoreLParams _, + @intDivFunc CoreLParams _, + @intModFunc CoreLParams _, + @intNegFunc CoreLParams _, - @intLtFunc BoogieLParams _, - @intLeFunc BoogieLParams _, - @intGtFunc BoogieLParams _, - @intGeFunc BoogieLParams _, + @intLtFunc CoreLParams _, + @intLeFunc CoreLParams _, + @intGtFunc CoreLParams _, + @intGeFunc CoreLParams _, realAddFunc, realSubFunc, @@ -419,11 +419,11 @@ def Factory : @Factory BoogieLParams := #[ realGtFunc, realGeFunc, - @boolAndFunc BoogieLParams _, - @boolOrFunc BoogieLParams _, - @boolImpliesFunc BoogieLParams _, - @boolEquivFunc BoogieLParams _, - @boolNotFunc BoogieLParams _, + @boolAndFunc CoreLParams _, + @boolOrFunc CoreLParams _, + @boolImpliesFunc CoreLParams _, + @boolEquivFunc CoreLParams _, + @boolNotFunc CoreLParams _, strLengthFunc, strConcatFunc, @@ -472,10 +472,10 @@ elab "DefBVOpFuncExprs" "[" sizes:num,* "]" : command => do let s := size.getNat.repr for op in BVOpNames do let opName := mkIdent (.str .anonymous s!"bv{s}{op}Op") - let funcName := mkIdent (.str (.str .anonymous "Boogie") s!"bv{s}{op}Func") + let funcName := mkIdent (.str (.str .anonymous "Core") s!"bv{s}{op}Func") elabCommand (← `(def $opName : Expression.Expr := ($funcName).opExpr)) -instance : Inhabited BoogieLParams.Metadata where +instance : Inhabited CoreLParams.Metadata where default := () DefBVOpFuncExprs [1, 8, 16, 32, 64] @@ -499,19 +499,19 @@ def addTriggerGroupOp : Expression.Expr := addTriggerGroupFunc.opExpr def emptyTriggerGroupOp : Expression.Expr := emptyTriggerGroupFunc.opExpr def addTriggerOp : Expression.Expr := addTriggerFunc.opExpr -instance : Inhabited (⟨ExpressionMetadata, BoogieIdent⟩: LExprParams).Metadata where +instance : Inhabited (⟨ExpressionMetadata, CoreIdent⟩: LExprParams).Metadata where default := () -def intAddOp : Expression.Expr := (@intAddFunc BoogieLParams _).opExpr -def intSubOp : Expression.Expr := (@intSubFunc BoogieLParams _).opExpr -def intMulOp : Expression.Expr := (@intMulFunc BoogieLParams _).opExpr -def intDivOp : Expression.Expr := (@intDivFunc BoogieLParams _).opExpr -def intModOp : Expression.Expr := (@intModFunc BoogieLParams _).opExpr -def intNegOp : Expression.Expr := (@intNegFunc BoogieLParams _).opExpr -def intLtOp : Expression.Expr := (@intLtFunc BoogieLParams _).opExpr -def intLeOp : Expression.Expr := (@intLeFunc BoogieLParams _).opExpr -def intGtOp : Expression.Expr := (@intGtFunc BoogieLParams _).opExpr -def intGeOp : Expression.Expr := (@intGeFunc BoogieLParams _).opExpr +def intAddOp : Expression.Expr := (@intAddFunc CoreLParams _).opExpr +def intSubOp : Expression.Expr := (@intSubFunc CoreLParams _).opExpr +def intMulOp : Expression.Expr := (@intMulFunc CoreLParams _).opExpr +def intDivOp : Expression.Expr := (@intDivFunc CoreLParams _).opExpr +def intModOp : Expression.Expr := (@intModFunc CoreLParams _).opExpr +def intNegOp : Expression.Expr := (@intNegFunc CoreLParams _).opExpr +def intLtOp : Expression.Expr := (@intLtFunc CoreLParams _).opExpr +def intLeOp : Expression.Expr := (@intLeFunc CoreLParams _).opExpr +def intGtOp : Expression.Expr := (@intGtFunc CoreLParams _).opExpr +def intGeOp : Expression.Expr := (@intGeFunc CoreLParams _).opExpr def realAddOp : Expression.Expr := realAddFunc.opExpr def realSubOp : Expression.Expr := realSubFunc.opExpr def realMulOp : Expression.Expr := realMulFunc.opExpr @@ -521,11 +521,11 @@ def realLtOp : Expression.Expr := realLtFunc.opExpr def realLeOp : Expression.Expr := realLeFunc.opExpr def realGtOp : Expression.Expr := realGtFunc.opExpr def realGeOp : Expression.Expr := realGeFunc.opExpr -def boolAndOp : Expression.Expr := (@boolAndFunc BoogieLParams _).opExpr -def boolOrOp : Expression.Expr := (@boolOrFunc BoogieLParams _).opExpr -def boolImpliesOp : Expression.Expr := (@boolImpliesFunc BoogieLParams _).opExpr -def boolEquivOp : Expression.Expr := (@boolEquivFunc BoogieLParams _).opExpr -def boolNotOp : Expression.Expr := (@boolNotFunc BoogieLParams _).opExpr +def boolAndOp : Expression.Expr := (@boolAndFunc CoreLParams _).opExpr +def boolOrOp : Expression.Expr := (@boolOrFunc CoreLParams _).opExpr +def boolImpliesOp : Expression.Expr := (@boolImpliesFunc CoreLParams _).opExpr +def boolEquivOp : Expression.Expr := (@boolEquivFunc CoreLParams _).opExpr +def boolNotOp : Expression.Expr := (@boolNotFunc CoreLParams _).opExpr def strLengthOp : Expression.Expr := strLengthFunc.opExpr def strConcatOp : Expression.Expr := strConcatFunc.opExpr def strSubstrOp : Expression.Expr := strSubstrFunc.opExpr @@ -554,11 +554,10 @@ def mkTriggerExpr (ts : List (List Expression.Expr)) : Expression.Expr := groups.foldl (fun gs g => .app () (.app () addTriggerGroupOp g) gs) emptyTriggersOp /-- -Get all the built-in functions supported by Boogie. +Get all the built-in functions supported by Strata Core. -/ def builtinFunctions : Array String := - Factory.map (fun f => BoogieIdent.toPretty f.name) - + Factory.map (fun f => CoreIdent.toPretty f.name) set_option maxRecDepth 32768 in set_option maxHeartbeats 4000000 in @@ -598,4 +597,4 @@ theorem Factory_wf : repeat (rcases args with _ | ⟨ args0, args ⟩ <;> try grind))) contradiction -end Boogie +end Core diff --git a/Strata/Languages/Core/Function.lean b/Strata/Languages/Core/Function.lean new file mode 100644 index 000000000..d2ff685bc --- /dev/null +++ b/Strata/Languages/Core/Function.lean @@ -0,0 +1,42 @@ +/- + Copyright Strata Contributors + + SPDX-License-Identifier: Apache-2.0 OR MIT +-/ + + + +import Strata.Languages.Core.Statement + +--------------------------------------------------------------------- + +namespace Core + +open Std (ToFormat Format format) +open Lambda + +/-! # Strata Core Functions -/ + +abbrev Function := Lambda.LFunc CoreLParams + +-- Type class instances to enable type class resolution for CoreLParams.Identifier +instance : DecidableEq CoreLParams.IDMeta := + show DecidableEq Visibility from inferInstance + +instance : ToFormat CoreLParams.IDMeta := + show ToFormat Visibility from inferInstance + +open LTy.Syntax LExpr.SyntaxMono in +/-- info: ok: ∀[a, b]. (arrow int (arrow a (arrow b (arrow a a)))) -/ +#guard_msgs in +#eval do let type ← LFunc.type (T:=CoreLParams) + ({ name := CoreIdent.unres "Foo", + typeArgs := ["a", "b"], + inputs := [(CoreIdent.locl "w", mty[int]), (CoreIdent.locl "x", mty[%a]), (CoreIdent.locl "y", mty[%b]), (CoreIdent.locl "z", mty[%a])], + output := mty[%a], + body := some (LExpr.fvar () (CoreIdent.locl "x") none) } : Function) + return format type + +--------------------------------------------------------------------- + +end Core diff --git a/Strata/Languages/Boogie/FunctionType.lean b/Strata/Languages/Core/FunctionType.lean similarity index 87% rename from Strata/Languages/Boogie/FunctionType.lean rename to Strata/Languages/Core/FunctionType.lean index 089b41ec2..76d4af933 100644 --- a/Strata/Languages/Boogie/FunctionType.lean +++ b/Strata/Languages/Core/FunctionType.lean @@ -6,20 +6,20 @@ -import Strata.Languages.Boogie.Function -import Strata.Languages.Boogie.Program +import Strata.Languages.Core.Function +import Strata.Languages.Core.Program --------------------------------------------------------------------- -namespace Boogie +namespace Core namespace Function open Lambda Imperative open Std (ToFormat Format format) -def typeCheck (C: Boogie.Expression.TyContext) (Env : Boogie.Expression.TyEnv) (func : Function) : - Except Format (Function × Boogie.Expression.TyEnv) := do +def typeCheck (C: Core.Expression.TyContext) (Env : Core.Expression.TyEnv) (func : Function) : + Except Format (Function × Core.Expression.TyEnv) := do -- (FIXME) Very similar to `Lambda.inferOp`, except that the body is annotated -- using `LExprT.resolve`. Can we share code here? -- @@ -56,4 +56,4 @@ def typeCheck (C: Boogie.Expression.TyContext) (Env : Boogie.Expression.TyEnv) ( end Function --------------------------------------------------------------------- -end Boogie +end Core diff --git a/Strata/Languages/Boogie/Identifiers.lean b/Strata/Languages/Core/Identifiers.lean similarity index 54% rename from Strata/Languages/Boogie/Identifiers.lean rename to Strata/Languages/Core/Identifiers.lean index 081ef9509..4c2b5367f 100644 --- a/Strata/Languages/Boogie/Identifiers.lean +++ b/Strata/Languages/Core/Identifiers.lean @@ -8,12 +8,13 @@ import Strata.DL.Lambda.LExprTypeEnv import Strata.DL.Lambda.Factory -namespace Boogie +namespace Core open Std /-- - The purpose of `Visiblity` is to denote the visibility/scope of a Boogie identifier. + The purpose of `Visiblity` is to denote the visibility/scope of a Strata Core + identifier. For example, global variables should have a `.glob` (i.e., global) visibility, and variables declared within a procedure should have a `.locl` (i.e., local) @@ -34,7 +35,7 @@ open Std is the responsibility of the variable generator to ensure that the generated names themselves are unique (i.e., do not have duplicates). - See `BoogieGenState` for a unique generator for Boogie Identifiers. + See `CoreGenState` for a unique generator for Strata Core Identifiers. -/ inductive Visibility where | unres @@ -50,83 +51,83 @@ instance : ToFormat Visibility where | .locl => "l:" | .temp => "t:" -abbrev BoogieIdent := Lambda.Identifier Visibility +abbrev CoreIdent := Lambda.Identifier Visibility instance : ToString Visibility where toString v := toString $ ToFormat.format v -abbrev BoogieExprMetadata := Unit -abbrev BoogieLParams: Lambda.LExprParams := {Metadata := BoogieExprMetadata, IDMeta := Visibility} -abbrev BoogieLabel := String +abbrev CoreExprMetadata := Unit +abbrev CoreLParams: Lambda.LExprParams := {Metadata := CoreExprMetadata, IDMeta := Visibility} +abbrev CoreLabel := String -def BoogieIdentDec : DecidableEq BoogieIdent := inferInstanceAs (DecidableEq (Lambda.Identifier Visibility)) +def CoreIdentDec : DecidableEq CoreIdent := inferInstanceAs (DecidableEq (Lambda.Identifier Visibility)) @[match_pattern] -def BoogieIdent.unres (s : String) : BoogieIdent := ⟨s, Visibility.unres⟩ +def CoreIdent.unres (s : String) : CoreIdent := ⟨s, Visibility.unres⟩ @[match_pattern] -def BoogieIdent.glob (s : String) : BoogieIdent := ⟨s, Visibility.glob⟩ +def CoreIdent.glob (s : String) : CoreIdent := ⟨s, Visibility.glob⟩ @[match_pattern] -def BoogieIdent.locl (s : String) : BoogieIdent := ⟨s, Visibility.locl⟩ +def CoreIdent.locl (s : String) : CoreIdent := ⟨s, Visibility.locl⟩ @[match_pattern] -def BoogieIdent.temp (s : String) : BoogieIdent := ⟨s, Visibility.temp⟩ +def CoreIdent.temp (s : String) : CoreIdent := ⟨s, Visibility.temp⟩ -def BoogieIdent.isUnres (id : BoogieIdent) : Bool := match id with +def CoreIdent.isUnres (id : CoreIdent) : Bool := match id with | .unres _ => true | _ => false -def BoogieIdent.isGlob (id : BoogieIdent) : Bool := match id with +def CoreIdent.isGlob (id : CoreIdent) : Bool := match id with | .glob _ => true | _ => false -def BoogieIdent.isLocl (id : BoogieIdent) : Bool := match id with +def CoreIdent.isLocl (id : CoreIdent) : Bool := match id with | .locl _ => true | _ => false -def BoogieIdent.isTemp (id : BoogieIdent) : Bool := match id with +def CoreIdent.isTemp (id : CoreIdent) : Bool := match id with | .temp _ => true | _ => false -def BoogieIdent.isGlobOrLocl (id : BoogieIdent) : Bool := - BoogieIdent.isGlob id ∨ BoogieIdent.isLocl id +def CoreIdent.isGlobOrLocl (id : CoreIdent) : Bool := + CoreIdent.isGlob id ∨ CoreIdent.isLocl id -instance : Coe String BoogieIdent where +instance : Coe String CoreIdent where coe | s => .unres s --- instance : DecidableEq BoogieIdent := instDecidableEqProd +-- instance : DecidableEq CoreIdent := instDecidableEqProd -/-- The pretty-printer for Boogie Identifiers. +/-- The pretty-printer for Strata Core Identifiers. We ignore the visibility part so that the output can be parsed again -/ -def BoogieIdent.toPretty (x : BoogieIdent) : String := +def CoreIdent.toPretty (x : CoreIdent) : String := match x with | ⟨s, _⟩ => s -/-- The pretty-printer for Boogie Identifiers. +/-- The pretty-printer for Strata Core Identifiers. We ignore the visibility part so that the output can be parsed again -/ -instance : ToFormat BoogieIdent where - format i := BoogieIdent.toPretty i +instance : ToFormat CoreIdent where + format i := CoreIdent.toPretty i --- Explicit instances for BoogieLParams field access -instance : ToFormat BoogieLParams.Identifier := - show ToFormat BoogieIdent from inferInstance +-- Explicit instances for CoreLParams field access +instance : ToFormat CoreLParams.Identifier := + show ToFormat CoreIdent from inferInstance -instance : DecidableEq BoogieLParams.Identifier := - show DecidableEq BoogieIdent from inferInstance +instance : DecidableEq CoreLParams.Identifier := + show DecidableEq CoreIdent from inferInstance -/-- Full representation of Boogie Identifier with scope. +/-- Full representation of Strata Core Identifier with scope. This can be useful for both debugging and generating "unique" strings, for example, as labels of proof obligations in the VC generator. - As a general guideline, whenever conversion from a `BoogieIdent` to `String` + As a general guideline, whenever conversion from a `CoreIdent` to `String` is needed, _always use the `toString` method_." Since `toString` includes the scoping information, consistency is ensured. Moreover, we could change the string representation fairly easily by overriding the method, if needed. -/ -instance : ToString BoogieIdent where +instance : ToString CoreIdent where toString | ⟨s, v⟩ => (toString $ ToFormat.format v) ++ (toString $ ToFormat.format s) -instance : Repr BoogieIdent where +instance : Repr CoreIdent where reprPrec | ⟨s, v⟩, _ => (ToFormat.format v) ++ (ToFormat.format s) -instance : Inhabited BoogieIdent where +instance : Inhabited CoreIdent where default := ⟨"_", .unres⟩ instance : Lambda.HasGen Visibility where genVar T := let (sym, state') := (Lambda.TState.genExprSym T.genState) - (BoogieIdent.temp sym, { T with genState := state' }) + (CoreIdent.temp sym, { T with genState := state' }) namespace Syntax @@ -134,30 +135,30 @@ open Lean Elab Meta Lambda.LExpr.SyntaxMono scoped syntax ident : lidentmono /-- Elaborator for String identifiers, construct a String instance -/ -def elabBoogieIdent : Syntax → MetaM Expr +def elabCoreIdent : Syntax → MetaM Expr | `(lidentmono| $s:ident) => do let s := toString s.getId - return ← mkAppM ``BoogieIdent.unres #[mkStrLit s] + return ← mkAppM ``CoreIdent.unres #[mkStrLit s] | _ => throwUnsupportedSyntax -- -instance : MkLExprParams ⟨BoogieExprMetadata, Visibility⟩ where - elabIdent := elabBoogieIdent - toExpr := mkApp2 (mkConst ``Lambda.LExprParams.mk) (mkConst ``BoogieExprMetadata) (.const ``Visibility []) +instance : MkLExprParams ⟨CoreExprMetadata, Visibility⟩ where + elabIdent := elabCoreIdent + toExpr := mkApp2 (mkConst ``Lambda.LExprParams.mk) (mkConst ``CoreExprMetadata) (.const ``Visibility []) -elab "eb[" e:lexprmono "]" : term => elabLExprMono (T:=⟨BoogieExprMetadata, Visibility⟩) e +elab "eb[" e:lexprmono "]" : term => elabLExprMono (T:=⟨CoreExprMetadata, Visibility⟩) e /-- -info: Lambda.LExpr.op () (BoogieIdent.unres "old") - none : Lambda.LExpr { Metadata := BoogieExprMetadata, IDMeta := Visibility }.mono +info: Lambda.LExpr.op () (CoreIdent.unres "old") + none : Lambda.LExpr { Metadata := CoreExprMetadata, IDMeta := Visibility }.mono -/ #guard_msgs in #check eb[~old] /-- -info: Lambda.LExpr.app () (Lambda.LExpr.op () (BoogieIdent.unres "old") none) - (Lambda.LExpr.fvar () (BoogieIdent.unres "a") - none) : Lambda.LExpr { Metadata := BoogieExprMetadata, IDMeta := Visibility }.mono +info: Lambda.LExpr.app () (Lambda.LExpr.op () (CoreIdent.unres "old") none) + (Lambda.LExpr.fvar () (CoreIdent.unres "a") + none) : Lambda.LExpr { Metadata := CoreExprMetadata, IDMeta := Visibility }.mono -/ #guard_msgs in #check eb[(~old a)] @@ -165,8 +166,8 @@ info: Lambda.LExpr.app () (Lambda.LExpr.op () (BoogieIdent.unres "old") none) open Lambda.LTy.Syntax in /-- -info: Lambda.LExpr.fvar () (BoogieIdent.unres "x") - (some (Lambda.LMonoTy.tcons "bool" [])) : Lambda.LExpr { Metadata := BoogieExprMetadata, IDMeta := Visibility }.mono +info: Lambda.LExpr.fvar () (CoreIdent.unres "x") + (some (Lambda.LMonoTy.tcons "bool" [])) : Lambda.LExpr { Metadata := CoreExprMetadata, IDMeta := Visibility }.mono -/ #guard_msgs in #check eb[(x : bool)] diff --git a/Strata/Languages/Boogie/OldExpressions.lean b/Strata/Languages/Core/OldExpressions.lean similarity index 96% rename from Strata/Languages/Boogie/OldExpressions.lean rename to Strata/Languages/Core/OldExpressions.lean index c18e0e709..efba2865b 100644 --- a/Strata/Languages/Boogie/OldExpressions.lean +++ b/Strata/Languages/Core/OldExpressions.lean @@ -4,18 +4,19 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.BoogieGen -import Strata.Languages.Boogie.Procedure +import Strata.Languages.Core.CoreGen +import Strata.Languages.Core.Procedure -namespace Boogie +namespace Core namespace OldExpressions -open Lambda.LExpr.SyntaxMono Lambda.LTy.Syntax Boogie.Syntax +open Lambda.LExpr.SyntaxMono Lambda.LTy.Syntax Core.Syntax -/-! ## Old Expressions in Boogie +/-! ## Old Expressions in Strata Core -From Section 4.3 in "This is Boogie 2": +The `old e` expression in Strata Core follows the syntax of the old expression +in Boogie. Specifically, in Section 4.3 in "This is Boogie 2": "Postconditions and procedure implementations are two-state contexts. This means that it is possible to refer to two different values of each variable. In a @@ -57,7 +58,7 @@ def oldExpr (e : Expression.Expr) : Expression.Expr := - .app mApp (.op mOp (BoogieIdent.unres "old") tyold) e + .app mApp (.op mOp (CoreIdent.unres "old") tyold) e @[match_pattern] def oldVar @@ -71,7 +72,7 @@ def oldVar := @oldExpr mApp mOp tyold (.fvar mVar v tyv) inductive IsOldPred : Expression.Expr → Prop where - | oldPred : IsOldPred (.op m (BoogieIdent.unres "old") ty) + | oldPred : IsOldPred (.op m (CoreIdent.unres "old") ty) def IsOldPred.decidablePred (e : Expression.Expr): Decidable (IsOldPred e) := match He : e with @@ -162,7 +163,7 @@ This function is agnostic of old expression normalization (see -/ def containsOldExpr (e : Expression.Expr) : Bool := match e with - | .op _ (BoogieIdent.unres "old") _ => true + | .op _ (CoreIdent.unres "old") _ => true | .op _ _ _ => false | .const _ _ | .bvar _ _ | .fvar _ _ _ => false | .abs _ _ e' => containsOldExpr e' @@ -190,8 +191,8 @@ def extractOldExprVars (expr : Expression.Expr) | .abs _ _ e => extractOldExprVars e | .quant _ _ _ tr e => extractOldExprVars tr ++ extractOldExprVars e | .app _ e1 e2 => match e1, e2 with - | .op _ (BoogieIdent.unres "old") _, .fvar _ v _ => [v] - | .op _ (BoogieIdent.unres "old") _, _ => panic! s!"Old expression {expr} not normalized" + | .op _ (CoreIdent.unres "old") _, .fvar _ v _ => [v] + | .op _ (CoreIdent.unres "old") _, _ => panic! s!"Old expression {expr} not normalized" | e1', e2' => extractOldExprVars e1' ++ extractOldExprVars e2' | .ite _ c t e => extractOldExprVars c ++ extractOldExprVars t ++ extractOldExprVars e | .eq _ e1 e2 => extractOldExprVars e1 ++ extractOldExprVars e2 @@ -211,7 +212,7 @@ def substOld (var : Expression.Ident) (s e : Expression.Expr) : | .quant m qk ty tr' e' => .quant m qk ty (substOld var s tr') (substOld var s e') | .app m e1 e2 => match e1, e2 with - | .op _ (BoogieIdent.unres "old") _, .fvar _ x _ => + | .op _ (CoreIdent.unres "old") _, .fvar _ x _ => -- NOTE: We rely on the typeChecker to normalize `e` ensure that `old` is -- only used with an `fvar`. if x == var @@ -236,7 +237,7 @@ def substsOldExpr (sm : Map Expression.Ident Expression.Expr) (e : Expression.Ex | .quant m qk ty tr' e' => .quant m qk ty (substsOldExpr sm tr') (substsOldExpr sm e') | .app m e1 e2 => match e1, e2 with - | .op _ (BoogieIdent.unres "old") _, .fvar _ x _ => + | .op _ (CoreIdent.unres "old") _, .fvar _ x _ => match sm.find? x with | some s => s | none => e @@ -390,9 +391,9 @@ theorem IsOldPredNormalize : simp [normalizeOldExpr] at Hold cases Hold case neg Hneg' => - unfold BoogieIdent.unres at * + unfold CoreIdent.unres at * unfold normalizeOldExpr at Hold - unfold BoogieIdent.unres at * + unfold CoreIdent.unres at * split at Hold <;> simp_all split at Hold <;> simp_all unfold normalizeOldExpr at Hold @@ -523,7 +524,7 @@ case app fn e fn_ih e_ih => cases Hval with | app Hval1 Hval2 Hnold => have Hold'' := IsOldPredNormalize Hval1 Hold' - cases Hold'' <;> simp [BoogieIdent.unres] at * + cases Hold'' <;> simp [CoreIdent.unres] at * case ite c t e c_ih t_ih e_ih => apply c_ih cases Hval <;> assumption @@ -699,4 +700,4 @@ inductive ContainsOldVar : Expression.Expr → Prop where | eq_2 : ContainsOldVar e2 → ContainsOldVar (.eq m e1 e2) end OldExpressions -end Boogie +end Core diff --git a/Strata/Languages/Boogie/Options.lean b/Strata/Languages/Core/Options.lean similarity index 100% rename from Strata/Languages/Boogie/Options.lean rename to Strata/Languages/Core/Options.lean diff --git a/Strata/Languages/Boogie/Procedure.lean b/Strata/Languages/Core/Procedure.lean similarity index 84% rename from Strata/Languages/Boogie/Procedure.lean rename to Strata/Languages/Core/Procedure.lean index edfaf804a..e1fd6bf42 100644 --- a/Strata/Languages/Boogie/Procedure.lean +++ b/Strata/Languages/Core/Procedure.lean @@ -7,11 +7,11 @@ import Strata.DL.Imperative.HasVars -import Strata.Languages.Boogie.Statement +import Strata.Languages.Core.Statement --------------------------------------------------------------------- -namespace Boogie +namespace Core open Std (ToFormat Format format) open Lambda @@ -23,31 +23,31 @@ instance : DecidableEq ExpressionMetadata := instance : Repr ExpressionMetadata := show Repr Unit from inferInstance -instance : DecidableEq (⟨⟨ExpressionMetadata, BoogieIdent⟩, LMonoTy⟩ : LExprParamsT).base.Metadata := +instance : DecidableEq (⟨⟨ExpressionMetadata, CoreIdent⟩, LMonoTy⟩ : LExprParamsT).base.Metadata := show DecidableEq ExpressionMetadata from inferInstance -instance : DecidableEq (⟨⟨ExpressionMetadata, BoogieIdent⟩, LMonoTy⟩ : LExprParamsT).base.IDMeta := - show DecidableEq BoogieIdent from inferInstance +instance : DecidableEq (⟨⟨ExpressionMetadata, CoreIdent⟩, LMonoTy⟩ : LExprParamsT).base.IDMeta := + show DecidableEq CoreIdent from inferInstance -instance : DecidableEq (⟨⟨ExpressionMetadata, BoogieIdent⟩, LMonoTy⟩ : LExprParamsT).TypeType := +instance : DecidableEq (⟨⟨ExpressionMetadata, CoreIdent⟩, LMonoTy⟩ : LExprParamsT).TypeType := show DecidableEq LMonoTy from inferInstance -instance : Repr (⟨⟨ExpressionMetadata, BoogieIdent⟩, LMonoTy⟩ : LExprParamsT).base.Metadata := +instance : Repr (⟨⟨ExpressionMetadata, CoreIdent⟩, LMonoTy⟩ : LExprParamsT).base.Metadata := show Repr ExpressionMetadata from inferInstance -instance : Repr (⟨⟨ExpressionMetadata, BoogieIdent⟩, LMonoTy⟩ : LExprParamsT).base.IDMeta := - show Repr BoogieIdent from inferInstance +instance : Repr (⟨⟨ExpressionMetadata, CoreIdent⟩, LMonoTy⟩ : LExprParamsT).base.IDMeta := + show Repr CoreIdent from inferInstance -instance : Repr (⟨⟨ExpressionMetadata, BoogieIdent⟩, LMonoTy⟩ : LExprParamsT).TypeType := +instance : Repr (⟨⟨ExpressionMetadata, CoreIdent⟩, LMonoTy⟩ : LExprParamsT).TypeType := show Repr LMonoTy from inferInstance instance : Repr Expression.Expr := show Repr Expression.Expr from inferInstance -/-! # Boogie Procedures -/ +/-! # Strata Core Procedures -/ structure Procedure.Header where - name : BoogieIdent + name : CoreIdent typeArgs : List TyIdentifier inputs : @LMonoTySignature Visibility outputs : @LMonoTySignature Visibility @@ -93,8 +93,8 @@ def Procedure.Check.eraseTypes (c : Procedure.Check) : Procedure.Check := structure Procedure.Spec where modifies : List Expression.Ident - preconditions : ListMap BoogieLabel Procedure.Check - postconditions : ListMap BoogieLabel Procedure.Check + preconditions : ListMap CoreLabel Procedure.Check + postconditions : ListMap CoreLabel Procedure.Check deriving Inhabited, Repr instance : ToFormat Procedure.Spec where @@ -109,14 +109,14 @@ def Procedure.Spec.eraseTypes (s : Procedure.Spec) : Procedure.Spec := postconditions := s.postconditions.map (fun (l, c) => (l, c.eraseTypes)) } -def Procedure.Spec.getCheckExprs (conds : ListMap BoogieLabel Procedure.Check) : +def Procedure.Spec.getCheckExprs (conds : ListMap CoreLabel Procedure.Check) : List Expression.Expr := let checks := conds.values checks.map (fun c => c.expr) def Procedure.Spec.updateCheckExprs - (es : List Expression.Expr) (conds : ListMap BoogieLabel Procedure.Check) : - ListMap BoogieLabel Procedure.Check := + (es : List Expression.Expr) (conds : ListMap CoreLabel Procedure.Check) : + ListMap CoreLabel Procedure.Check := let checks := go es conds.values conds.keys.zip checks where go (es : List Expression.Expr) (checks : List Procedure.Check) := @@ -209,4 +209,4 @@ instance : HasVarsTrans Expression (List Statement) Procedure where allVarsTrans := Statements.allVarsTrans -end Boogie +end Core diff --git a/Strata/Languages/Boogie/ProcedureEval.lean b/Strata/Languages/Core/ProcedureEval.lean similarity index 94% rename from Strata/Languages/Boogie/ProcedureEval.lean rename to Strata/Languages/Core/ProcedureEval.lean index 13b07ad69..1ed7e6a4b 100644 --- a/Strata/Languages/Boogie/ProcedureEval.lean +++ b/Strata/Languages/Core/ProcedureEval.lean @@ -6,15 +6,15 @@ -import Strata.Languages.Boogie.Procedure -import Strata.Languages.Boogie.Statement -import Strata.Languages.Boogie.StatementEval -import Strata.Languages.Boogie.StatementSemantics +import Strata.Languages.Core.Procedure +import Strata.Languages.Core.Statement +import Strata.Languages.Core.StatementEval +import Strata.Languages.Core.StatementSemantics import Strata.Transform.LoopElim --------------------------------------------------------------------- -namespace Boogie +namespace Core namespace Procedure open Std @@ -89,4 +89,4 @@ def evalOne (E : Env) (p : Procedure) : Procedure × Env := --------------------------------------------------------------------- end Procedure -end Boogie +end Core diff --git a/Strata/Languages/Boogie/ProcedureType.lean b/Strata/Languages/Core/ProcedureType.lean similarity index 95% rename from Strata/Languages/Boogie/ProcedureType.lean rename to Strata/Languages/Core/ProcedureType.lean index 63a66f5aa..4e1a9495e 100644 --- a/Strata/Languages/Boogie/ProcedureType.lean +++ b/Strata/Languages/Core/ProcedureType.lean @@ -6,22 +6,22 @@ -import Strata.Languages.Boogie.Procedure +import Strata.Languages.Core.Procedure import Strata.DL.Imperative.HasVars -import Strata.Languages.Boogie.StatementType -import Strata.Languages.Boogie.OldExpressions +import Strata.Languages.Core.StatementType +import Strata.Languages.Core.OldExpressions --------------------------------------------------------------------- -namespace Boogie +namespace Core open Std (ToFormat Format format) open Imperative (MetaData) namespace Procedure -def typeCheck (C: Boogie.Expression.TyContext) (Env : Boogie.Expression.TyEnv) (p : Program) - (proc : Procedure) (md : MetaData Expression) : Except Format (Procedure × Boogie.Expression.TyEnv) := +def typeCheck (C: Core.Expression.TyContext) (Env : Core.Expression.TyEnv) (p : Program) + (proc : Procedure) (md : MetaData Expression) : Except Format (Procedure × Core.Expression.TyEnv) := let sourceLoc := MetaData.formatFileRangeD md (includeEnd? := false) let sourceLoc := if sourceLoc.isEmpty then sourceLoc else f!"{sourceLoc} " let errorWithSourceLoc := fun e => if sourceLoc.isEmpty then e else f!"{sourceLoc} {e}" @@ -102,4 +102,4 @@ def typeCheck (C: Boogie.Expression.TyContext) (Env : Boogie.Expression.TyEnv) ( --------------------------------------------------------------------- end Procedure -end Boogie +end Core diff --git a/Strata/Languages/Boogie/ProcedureWF.lean b/Strata/Languages/Core/ProcedureWF.lean similarity index 89% rename from Strata/Languages/Boogie/ProcedureWF.lean rename to Strata/Languages/Core/ProcedureWF.lean index 136592380..68ce457bb 100644 --- a/Strata/Languages/Boogie/ProcedureWF.lean +++ b/Strata/Languages/Core/ProcedureWF.lean @@ -7,17 +7,17 @@ import Strata.DL.Util.ListUtils -import Strata.Languages.Boogie.Program -import Strata.Languages.Boogie.ProcedureType -import Strata.Languages.Boogie.WF -import Strata.Languages.Boogie.StatementWF +import Strata.Languages.Core.Program +import Strata.Languages.Core.ProcedureType +import Strata.Languages.Core.WF +import Strata.Languages.Core.StatementWF -namespace Boogie +namespace Core namespace WF open Lambda -theorem snd_values_mem {ps : ListMap BoogieLabel Procedure.Check} : +theorem snd_values_mem {ps : ListMap CoreLabel Procedure.Check} : x ∈ ps.toList → x.snd ∈ ListMap.values ps := by intros Hin @@ -81,9 +81,9 @@ theorem Procedure.typeCheckWF : Procedure.typeCheck T p pp = Except.ok (pp', T') exact Hc2 . -- 11. All `modifies` variables have no duplicates. sorry - . -- 14. The `inputs` list of a procedure are all `BoogieIdent.locl` + . -- 14. The `inputs` list of a procedure are all `CoreIdent.locl` sorry - . -- 15. The `outputs` list of a procedure are all `BoogieIdent.locl` + . -- 15. The `outputs` list of a procedure are all `CoreIdent.locl` sorry . constructor <;> simp . -- precondition @@ -91,7 +91,7 @@ theorem Procedure.typeCheckWF : Procedure.typeCheck T p pp = Except.ok (pp', T') intros x Hin constructor . constructor - -- 5. All variables in post-conditions and pre-conditions are either `BoogieIdent.locl` or `BoogieIdent.glob`. + -- 5. All variables in post-conditions and pre-conditions are either `CoreIdent.locl` or `CoreIdent.glob`. . sorry -- 16. All variables in pre/post conditions that are `.locl` must be in `outputs` or `inputs` of the procedure . sorry @@ -107,7 +107,7 @@ theorem Procedure.typeCheckWF : Procedure.typeCheck T p pp = Except.ok (pp', T') apply List.Forall_mem_iff.mpr intros x Hin constructor - . -- 5. All variables in post-conditions and pre-conditions are either `BoogieIdent.locl` or `BoogieIdent.glob`. + . -- 5. All variables in post-conditions and pre-conditions are either `CoreIdent.locl` or `CoreIdent.glob`. sorry . -- 6. Postconditions in a procedure are all `ValidExpression`s sorry @@ -121,4 +121,4 @@ theorem Procedure.typeCheckWF : Procedure.typeCheck T p pp = Except.ok (pp', T') -/ end WF -end Boogie +end Core diff --git a/Strata/Languages/Boogie/Program.lean b/Strata/Languages/Core/Program.lean similarity index 92% rename from Strata/Languages/Boogie/Program.lean rename to Strata/Languages/Core/Program.lean index b62f23a25..67fe33ddd 100644 --- a/Strata/Languages/Boogie/Program.lean +++ b/Strata/Languages/Core/Program.lean @@ -6,14 +6,14 @@ -import Strata.Languages.Boogie.Procedure -import Strata.Languages.Boogie.Function -import Strata.Languages.Boogie.TypeDecl -import Strata.Languages.Boogie.Axiom +import Strata.Languages.Core.Procedure +import Strata.Languages.Core.Function +import Strata.Languages.Core.TypeDecl +import Strata.Languages.Core.Axiom --------------------------------------------------------------------- -namespace Boogie +namespace Core open Std (ToFormat Format format) open Imperative @@ -22,8 +22,8 @@ open Imperative instance : Inhabited TypeDecl where default := .con { name := "DefaultType", numargs := 0 } --- ToFormat instance for Function (which is LFunc BoogieLParams) --- Note: ToFormat BoogieLParams.Identifier is now defined in Identifiers.lean +-- ToFormat instance for Function (which is LFunc CoreLParams) +-- Note: ToFormat CoreLParams.Identifier is now defined in Identifiers.lean inductive DeclKind : Type where | var | type | ax | distinct | proc | func @@ -39,17 +39,17 @@ instance : ToFormat DeclKind where | .func => "function" /-- -A Boogie declaration. +A Strata Core declaration. Note: constants are 0-ary functions. -/ inductive Decl where - | var (name : Expression.Ident) (ty : Expression.Ty) (e : Expression.Expr) (md : MetaData Boogie.Expression := .empty) - | type (t : TypeDecl) (md : MetaData Boogie.Expression := .empty) - | ax (a : Axiom) (md : MetaData Boogie.Expression := .empty) + | var (name : Expression.Ident) (ty : Expression.Ty) (e : Expression.Expr) (md : MetaData Core.Expression := .empty) + | type (t : TypeDecl) (md : MetaData Core.Expression := .empty) + | ax (a : Axiom) (md : MetaData Core.Expression := .empty) -- The following is temporary, until we have lists and can encode `distinct` in Lambda. - | distinct (name : Expression.Ident) (es : List Expression.Expr) (md : MetaData Boogie.Expression := .empty) - | proc (d : Procedure) (md : MetaData Boogie.Expression := .empty) - | func (f : Function) (md : MetaData Boogie.Expression := .empty) + | distinct (name : Expression.Ident) (es : List Expression.Expr) (md : MetaData Core.Expression := .empty) + | proc (d : Procedure) (md : MetaData Core.Expression := .empty) + | func (f : Function) (md : MetaData Core.Expression := .empty) deriving Inhabited def Decl.metadata (d : Decl) : MetaData Expression := @@ -140,7 +140,7 @@ def Decl.formatWithMetaData (decl : Decl) : Format := abbrev Decls := List Decl -/-- A Boogie Program -/ +/-- A Core.Program -/ structure Program where { decls : Decls } @@ -310,4 +310,4 @@ def Program.Procedure.findP? (P : Program) (x : Expression.Ident) --------------------------------------------------------------------- -end Boogie +end Core diff --git a/Strata/Languages/Boogie/ProgramEval.lean b/Strata/Languages/Core/ProgramEval.lean similarity index 96% rename from Strata/Languages/Boogie/ProgramEval.lean rename to Strata/Languages/Core/ProgramEval.lean index 132580f23..f16f8230f 100644 --- a/Strata/Languages/Boogie/ProgramEval.lean +++ b/Strata/Languages/Core/ProgramEval.lean @@ -6,12 +6,12 @@ -import Strata.Languages.Boogie.Program -import Strata.Languages.Boogie.ProcedureEval +import Strata.Languages.Core.Program +import Strata.Languages.Core.ProcedureEval --------------------------------------------------------------------- -namespace Boogie +namespace Core open Std (ToFormat Format format) @@ -93,4 +93,4 @@ def eval (E : Env) : List (Program × Env) := -------------------------------------------------------------------- end Program -end Boogie +end Core diff --git a/Strata/Languages/Boogie/ProgramType.lean b/Strata/Languages/Core/ProgramType.lean similarity index 89% rename from Strata/Languages/Boogie/ProgramType.lean rename to Strata/Languages/Core/ProgramType.lean index 001acc0a6..c28b88b27 100644 --- a/Strata/Languages/Boogie/ProgramType.lean +++ b/Strata/Languages/Core/ProgramType.lean @@ -7,13 +7,13 @@ import Strata.DL.Lambda.LExprType -import Strata.Languages.Boogie.Program -import Strata.Languages.Boogie.FunctionType -import Strata.Languages.Boogie.ProcedureType +import Strata.Languages.Core.Program +import Strata.Languages.Core.FunctionType +import Strata.Languages.Core.ProcedureType --------------------------------------------------------------------- -namespace Boogie +namespace Core open Std (ToFormat Format format) open Lambda @@ -21,14 +21,14 @@ open Lambda namespace Program -def typeCheck (C: Boogie.Expression.TyContext) (Env : Boogie.Expression.TyEnv) (program : Program) : - Except Format (Program × Boogie.Expression.TyEnv) := do +def typeCheck (C: Core.Expression.TyContext) (Env : Core.Expression.TyEnv) (program : Program) : + Except Format (Program × Core.Expression.TyEnv) := do -- Push a type substitution scope to store global type variables. let Env := Env.updateSubst { subst := [[]], isWF := SubstWF_of_empty_empty } let (decls, Env) ← go C Env program.decls [] .ok ({ decls }, Env) - where go C Env remaining acc : Except Format (Decls × Boogie.Expression.TyEnv) := + where go C Env remaining acc : Except Format (Decls × Core.Expression.TyEnv) := match remaining with | [] => .ok (acc.reverse, Env) | decl :: drest => do @@ -102,4 +102,4 @@ def typeCheck (C: Boogie.Expression.TyContext) (Env : Boogie.Expression.TyEnv) ( --------------------------------------------------------------------- end Program -end Boogie +end Core diff --git a/Strata/Languages/Boogie/ProgramWF.lean b/Strata/Languages/Core/ProgramWF.lean similarity index 95% rename from Strata/Languages/Boogie/ProgramWF.lean rename to Strata/Languages/Core/ProgramWF.lean index 31ceca4ed..10379b42f 100644 --- a/Strata/Languages/Boogie/ProgramWF.lean +++ b/Strata/Languages/Core/ProgramWF.lean @@ -5,10 +5,10 @@ -/ import Strata.DL.Util.ListUtils -import Strata.Languages.Boogie.ProgramType -import Strata.Languages.Boogie.WF -import Strata.Languages.Boogie.StatementWF -import Strata.Languages.Boogie.ProcedureWF +import Strata.Languages.Core.ProgramType +import Strata.Languages.Core.WF +import Strata.Languages.Core.StatementWF +import Strata.Languages.Core.ProcedureWF /-! ## Well-Formedness for Programs This file is the entry point of typechecker correctness proofs. Specifically, @@ -24,24 +24,24 @@ import Strata.Languages.Boogie.ProcedureWF well-formedness condition is not needed, it is denoted by '-'. 1. All `modifies` variables in a procedure are declared in the program. - 2. All declared global variables are `BoogieIdent.glob`. - - All local variable declarations in a procedure are `BoogieIdent.locl`. + 2. All declared global variables are `CoreIdent.glob`. + - All local variable declarations in a procedure are `CoreIdent.locl`. 4. All local variable declarations in a procedure have no duplicates. - 5. All variables in post-conditions and pre-conditions are either `BoogieIdent.locl` or `BoogieIdent.glob`. + 5. All variables in post-conditions and pre-conditions are either `CoreIdent.locl` or `CoreIdent.glob`. 6. Postconditions in a procedure are all `ValidExpression`s (c.f., `OldExpressions.lean`), that is, the old predicates do not occur on the right hand side of an `.app`. - 7. The `lhs` of a call statement contain no duplicates and are `BoogieIdent.locl`. + 7. The `lhs` of a call statement contain no duplicates and are `CoreIdent.locl`. This is to avoid overlapping with global variables that occurs in pre/post conditions, because call elimination directly substitutes `lhs` into the pre/post conditions, they must not already exist in the pre/post conditions. If a `lhs` needs to be global, a separate transformation can be implemented to create/substitute temporary variables before the call statement, and insert an assignment statement to + The `outputs` list of a procedure contains no duplicates - 9. All variables mentioned in `args` of a call statement are either `BoogieIdent.locl` or `BoogieIdent.glob`. + 9. All variables mentioned in `args` of a call statement are either `CoreIdent.locl` or `CoreIdent.glob`. + The `inputs` list of a procedure contains no duplicates 11. All `modifies` variables have no duplicates. 12. The `inputs` list of a procedure is disjoint from the `outputs` list of the procedure 13. The `lhs` of a call statement is disjoint from `modifies`, `outputs`, and `inputs` of the procedure - 14. The `inputs` list of a procedure are all `BoogieIdent.locl` - 15. The `outputs` list of a procedure are all `BoogieIdent.locl` + 14. The `inputs` list of a procedure are all `CoreIdent.locl` + 15. The `outputs` list of a procedure are all `CoreIdent.locl` 16. All variables in pre/post conditions that are `.locl` must be in `outputs` or `inputs` of the procedure In order to fully prove the type checker's properties, it might be necessary to @@ -73,7 +73,7 @@ import Strata.Languages.Boogie.ProcedureWF the program is type-checked. -/ -namespace Boogie +namespace Core namespace WF open Imperative Std Lambda @@ -133,7 +133,7 @@ theorem Program.typeCheck.goWF' : | intro l r => apply And.intro . constructor - -- 2. All declared global variables are `BoogieIdent.glob`. + -- 2. All declared global variables are `CoreIdent.glob`. sorry . exists v.1, { context := res.snd.context.subst res.snd.state.substInfo.subst, @@ -173,7 +173,7 @@ theorem Program.typeCheck.goWF' : state := (LMonoTys.instantiate td.typeArgs [td.toLHSLMonoTy, td.type] T).snd.state, functions := (LMonoTys.instantiate td.typeArgs [td.toLHSLMonoTy, td.type] T).snd.functions, knownTypes := (LMonoTys.instantiate td.typeArgs [td.toLHSLMonoTy, td.type] T).snd.knownTypes - : TEnv BoogieIdent } -- NOTE: this type annotation is important + : TEnv CoreIdent } -- NOTE: this type annotation is important = TT at Htc exists v'.fst, TT, v'.snd | ax a => @@ -390,4 +390,4 @@ theorem Program.typeCheckWF : Program.typeCheck C T p = .ok (p', T') → WF.WFPr exact typeCheck.goWF Hgo end WF -end Boogie +end Core diff --git a/Strata/Languages/Boogie/SMTEncoder.lean b/Strata/Languages/Core/SMTEncoder.lean similarity index 96% rename from Strata/Languages/Boogie/SMTEncoder.lean rename to Strata/Languages/Core/SMTEncoder.lean index 0cc448514..7819858bb 100644 --- a/Strata/Languages/Boogie/SMTEncoder.lean +++ b/Strata/Languages/Core/SMTEncoder.lean @@ -6,7 +6,7 @@ -import Strata.Languages.Boogie.Boogie +import Strata.Languages.Core.Core import Strata.DL.SMT.SMT import Init.Data.String.Extra import Strata.DDM.Util.DecimalRat @@ -14,7 +14,7 @@ import Strata.DDM.Util.Graph.Tarjan --------------------------------------------------------------------- -namespace Boogie +namespace Core open Std (ToFormat Format format) open Lambda Strata.SMT @@ -35,8 +35,8 @@ structure SMT.Context where ifs : Array SMT.IF := #[] axms : Array Term := #[] tySubst: Map String TermType := [] - datatypes : Array (LDatatype BoogieLParams.IDMeta) := #[] - datatypeFuns : Map String (Op.DatatypeFuncs × LConstr BoogieLParams.IDMeta) := Map.empty + datatypes : Array (LDatatype CoreLParams.IDMeta) := #[] + datatypeFuns : Map String (Op.DatatypeFuncs × LConstr CoreLParams.IDMeta) := Map.empty deriving Repr, DecidableEq, Inhabited def SMT.Context.default : SMT.Context := {} @@ -67,7 +67,7 @@ def SMT.Context.removeSubst (ctx : SMT.Context) (newSubst: Map String TermType) def SMT.Context.hasDatatype (ctx : SMT.Context) (name : String) : Bool := (ctx.datatypes.map LDatatype.name).contains name -def SMT.Context.addDatatype (ctx : SMT.Context) (d : LDatatype BoogieLParams.IDMeta) : SMT.Context := +def SMT.Context.addDatatype (ctx : SMT.Context) (d : LDatatype CoreLParams.IDMeta) : SMT.Context := if ctx.hasDatatype d.name then ctx else let (c, i, s) := d.genFunctionMaps @@ -97,7 +97,7 @@ private def lMonoTyToSMTString (ty : LMonoTy) : String := Build a dependency graph for datatypes. Returns a mapping from datatype names to their dependencies. -/ -private def buildDatatypeDependencyGraph (datatypes : Array (LDatatype BoogieLParams.IDMeta)) : +private def buildDatatypeDependencyGraph (datatypes : Array (LDatatype CoreLParams.IDMeta)) : Map String (Array String) := let depMap := datatypes.foldl (fun acc d => let deps := d.constrs.foldl (fun deps c => @@ -259,7 +259,7 @@ def convertQuantifierKind : Lambda.QuantifierKind -> Strata.SMT.QuantifierKind mutual -partial def toSMTTerm (E : Env) (bvs : BoundVars) (e : LExpr BoogieLParams.mono) (ctx : SMT.Context) +partial def toSMTTerm (E : Env) (bvs : BoundVars) (e : LExpr CoreLParams.mono) (ctx : SMT.Context) : Except Format (Term × SMT.Context) := do match e with | .boolConst _ b => .ok (Term.bool b, ctx) @@ -316,7 +316,7 @@ partial def toSMTTerm (E : Env) (bvs : BoundVars) (e : LExpr BoogieLParams.mono) | .app _ _ _ => appToSMTTerm E bvs e [] ctx -partial def appToSMTTerm (E : Env) (bvs : BoundVars) (e : LExpr BoogieLParams.mono) (acc : List Term) (ctx : SMT.Context) : +partial def appToSMTTerm (E : Env) (bvs : BoundVars) (e : LExpr CoreLParams.mono) (acc : List Term) (ctx : SMT.Context) : Except Format (Term × SMT.Context) := do match e with -- Special case for indexed SMT operations. @@ -358,7 +358,7 @@ partial def appToSMTTerm (E : Env) (bvs : BoundVars) (e : LExpr BoogieLParams.mo | _ => toSMTTerm E bvs e ctx -partial def toSMTOp (E : Env) (fn : BoogieIdent) (fnty : LMonoTy) (ctx : SMT.Context) : +partial def toSMTOp (E : Env) (fn : CoreIdent) (fnty : LMonoTy) (ctx : SMT.Context) : Except Format ((List Term → TermType → Term) × TermType × SMT.Context) := open LTy.Syntax in do -- Encode the type to ensure any datatypes are registered in the context @@ -386,7 +386,7 @@ partial def toSMTOp (E : Env) (fn : BoogieIdent) (fnty : LMonoTy) (ctx : SMT.Con | none => -- Not a constructor, tester, or destructor match E.factory.getFactoryLFunc fn.name with - | none => .error f!"Cannot find function {fn} in Boogie's Factory!" + | none => .error f!"Cannot find function {fn} in Strata Core's Factory!" | some func => match func.name.name with | "Bool.And" => .ok (.app Op.and, .bool, ctx) @@ -595,7 +595,7 @@ partial def toSMTOp (E : Env) (fn : BoogieIdent) (fnty : LMonoTy) (ctx : SMT.Con .ok (acc_map.insert tyVar smtTy) ) Map.empty -- Add all axioms for this function to the context, with types binding for the type variables in the expr - let ctx ← func.axioms.foldlM (fun acc_ctx (ax: LExpr BoogieLParams.mono) => do + let ctx ← func.axioms.foldlM (fun acc_ctx (ax: LExpr CoreLParams.mono) => do let current_axiom_ctx := acc_ctx.addSubst smt_ty_inst let (axiom_term, new_ctx) ← toSMTTerm E [] ax current_axiom_ctx .ok (new_ctx.addAxiom axiom_term) @@ -606,7 +606,7 @@ partial def toSMTOp (E : Env) (fn : BoogieIdent) (fnty : LMonoTy) (ctx : SMT.Con .ok (.app (Op.uf uf), smt_outty, ctx) end -def toSMTTerms (E : Env) (es : List (LExpr BoogieLParams.mono)) (ctx : SMT.Context) : +def toSMTTerms (E : Env) (es : List (LExpr CoreLParams.mono)) (ctx : SMT.Context) : Except Format ((List Term) × SMT.Context) := do match es with | [] => .ok ([], ctx) @@ -642,11 +642,11 @@ def ProofObligation.toSMTTerms (E : Env) Except Format ((List Term) × SMT.Context) := do let assumptions := d.assumptions.flatten.map (fun a => a.snd) let (ctx, distinct_terms) ← E.distinct.foldlM (λ (ctx, tss) es => - do let (ts, ctx') ← Boogie.toSMTTerms E es ctx; pure (ctx', ts :: tss)) (ctx, []) + do let (ts, ctx') ← Core.toSMTTerms E es ctx; pure (ctx', ts :: tss)) (ctx, []) let distinct_assumptions := distinct_terms.map (λ ts => Term.app (.core .distinct) ts .bool) - let (assumptions_terms, ctx) ← Boogie.toSMTTerms E assumptions ctx - let (obligation_pos_term, ctx) ← Boogie.toSMTTerm E [] d.obligation ctx + let (assumptions_terms, ctx) ← Core.toSMTTerms E assumptions ctx + let (obligation_pos_term, ctx) ← Core.toSMTTerm E [] d.obligation ctx let obligation_term := if d.property == .cover then obligation_pos_term @@ -657,7 +657,7 @@ def ProofObligation.toSMTTerms (E : Env) --------------------------------------------------------------------- /-- Convert an expression of type LExpr to a String representation in SMT-Lib syntax, for testing. -/ -def toSMTTermString (e : LExpr BoogieLParams.mono) (E : Env := Env.init) (ctx : SMT.Context := SMT.Context.default) +def toSMTTermString (e : LExpr CoreLParams.mono) (E : Env := Env.init) (ctx : SMT.Context := SMT.Context.default) : IO String := do let smtctx := toSMTTerm E [] e ctx match smtctx with @@ -714,7 +714,7 @@ info: "; f\n(declare-const f0 (arrow Int Int))\n; f\n(declare-fun f1 (Int) Int)\ (E := {Env.init with exprEnv := { Env.init.exprEnv with config := { Env.init.exprEnv.config with - factory := Boogie.Factory + factory := Core.Factory } }}) @@ -754,4 +754,4 @@ info: "; f\n(declare-fun f0 (Int Int) Int)\n; x\n(declare-const f1 Int)\n(define }}) -end Boogie +end Core diff --git a/Strata/Languages/Boogie/Statement.lean b/Strata/Languages/Core/Statement.lean similarity index 96% rename from Strata/Languages/Boogie/Statement.lean rename to Strata/Languages/Core/Statement.lean index 005e8ae19..eaa843393 100644 --- a/Strata/Languages/Boogie/Statement.lean +++ b/Strata/Languages/Core/Statement.lean @@ -6,15 +6,15 @@ -import Strata.Languages.Boogie.Expressions +import Strata.Languages.Core.Expressions import Strata.DL.Imperative.PureExpr -import Strata.Languages.Boogie.Identifiers -import Strata.Languages.Boogie.Factory +import Strata.Languages.Core.Identifiers +import Strata.Languages.Core.Factory import Strata.DL.Imperative.Stmt import Strata.DL.Imperative.HasVars import Strata.DL.Lambda.LExpr -namespace Boogie +namespace Core open Imperative open Std (ToFormat Format format) --------------------------------------------------------------------- @@ -34,7 +34,7 @@ inductive CmdExt (P : PureExpr) where (md : MetaData P := .empty) /-- -We parameterize Boogie's Commands with Lambda dialect's expressions. +We parameterize Strata Core's Commands with Lambda dialect's expressions. -/ abbrev Command := CmdExt Expression @@ -64,7 +64,7 @@ instance [ToFormat (Cmd P)] [ToFormat (MetaData P)] --------------------------------------------------------------------- -abbrev Statement := Imperative.Stmt Boogie.Expression Boogie.Command +abbrev Statement := Imperative.Stmt Core.Expression Core.Command abbrev Statements := List Statement @[match_pattern] @@ -94,7 +94,7 @@ abbrev Statement.cover (label : String) (b : Expression.Expr) (md : MetaData Exp --------------------------------------------------------------------- -abbrev Block := Imperative.Block Boogie.Expression Boogie.Command +abbrev Block := Imperative.Block Core.Expression Core.Command --------------------------------------------------------------------- @@ -317,7 +317,7 @@ def Block.substFvar (b : Block) (fr:Expression.Ident) termination_by b.sizeOf decreasing_by apply sizeOf_stmt_in_block; assumption -def Statement.substFvar (s : Boogie.Statement) +def Statement.substFvar (s : Core.Statement) (fr:Expression.Ident) (to:Expression.Expr) : Statement := match s with @@ -360,7 +360,7 @@ def Block.renameLhs (b : Block) termination_by b.sizeOf decreasing_by apply sizeOf_stmt_in_block; assumption -def Statement.renameLhs (s : Boogie.Statement) +def Statement.renameLhs (s : Core.Statement) (fr: Lambda.Identifier Visibility) (to: Lambda.Identifier Visibility) : Statement := match s with @@ -382,4 +382,4 @@ end --------------------------------------------------------------------- -end Boogie +end Core diff --git a/Strata/Languages/Boogie/StatementEval.lean b/Strata/Languages/Core/StatementEval.lean similarity index 98% rename from Strata/Languages/Boogie/StatementEval.lean rename to Strata/Languages/Core/StatementEval.lean index e01a43098..34749e28e 100644 --- a/Strata/Languages/Boogie/StatementEval.lean +++ b/Strata/Languages/Core/StatementEval.lean @@ -6,15 +6,15 @@ -import Strata.Languages.Boogie.Statement -import Strata.Languages.Boogie.Program -import Strata.Languages.Boogie.OldExpressions -import Strata.Languages.Boogie.Env -import Strata.Languages.Boogie.CmdEval +import Strata.Languages.Core.Statement +import Strata.Languages.Core.Program +import Strata.Languages.Core.OldExpressions +import Strata.Languages.Core.Env +import Strata.Languages.Core.CmdEval --------------------------------------------------------------------- -namespace Boogie +namespace Core namespace Statement @@ -60,7 +60,7 @@ Evaluate a procedure call `lhs := pname(args)`. def Command.evalCall (E : Env) (old_var_subst : SubstMap) (lhs : List Expression.Ident) (pname : String) (args : List Expression.Expr) (md : Imperative.MetaData Expression) : Command × Env := - -- Procedures in Boogie have a `modifies` clause that contain global variables that + -- Procedures in Strata Core have a `modifies` clause that contain global variables that -- can be modified by the procedure. Also, the procedure's post-conditions can -- contain `old ` expressions, which refer to the value of -- `` before the execution of the procedure (i.e., pre-state). See also @@ -375,7 +375,7 @@ def evalAuxGo (steps : Nat) (old_var_subst : SubstMap) (Ewn : EnvWithNext) (ss : | .loop _ _ _ _ _ => panic! "Cannot evaluate `loop` statement. \ Please transform your program to eliminate loops before \ - calling Boogie.Statement.evalAux" + calling Core.Statement.evalAux" | .goto l md => [{ Ewn with stk := Ewn.stk.appendToTop [.goto l md], nextLabel := (some l)}] @@ -463,6 +463,6 @@ def evalOne (E : Env) (old_var_subst : SubstMap) (ss : Statements) : Statements | _ => (ss, { E with error := some (.Misc "More than one result environment") }) end Statement -end Boogie +end Core --------------------------------------------------------------------- diff --git a/Strata/Languages/Boogie/StatementSemantics.lean b/Strata/Languages/Core/StatementSemantics.lean similarity index 85% rename from Strata/Languages/Boogie/StatementSemantics.lean rename to Strata/Languages/Core/StatementSemantics.lean index 9b0f9ed51..32ebca1d6 100644 --- a/Strata/Languages/Boogie/StatementSemantics.lean +++ b/Strata/Languages/Core/StatementSemantics.lean @@ -6,14 +6,14 @@ import Strata.DL.Lambda.LExpr import Strata.DL.Imperative.StmtSemantics -import Strata.Languages.Boogie.OldExpressions +import Strata.Languages.Core.OldExpressions --------------------------------------------------------------------- -namespace Boogie +namespace Core /-- expressions that can't be reduced when evaluating -/ -inductive Value : Boogie.Expression.Expr → Prop where +inductive Value : Core.Expression.Expr → Prop where | const : Value (.const () _) | bvar : Value (.bvar () _) | op : Value (.op () _ _) @@ -21,33 +21,33 @@ inductive Value : Boogie.Expression.Expr → Prop where open Imperative -instance : HasVal Boogie.Expression where value := Value +instance : HasVal Core.Expression where value := Value -instance : HasFvar Boogie.Expression where +instance : HasFvar Core.Expression where mkFvar := (.fvar () · none) getFvar | .fvar _ v _ => some v | _ => none @[match_pattern] -def Boogie.true : Boogie.Expression.Expr := .boolConst () Bool.true +def Core.true : Core.Expression.Expr := .boolConst () Bool.true @[match_pattern] -def Boogie.false : Boogie.Expression.Expr := .boolConst () Bool.false +def Core.false : Core.Expression.Expr := .boolConst () Bool.false -instance : HasBool Boogie.Expression where - tt := Boogie.true - ff := Boogie.false +instance : HasBool Core.Expression where + tt := Core.true + ff := Core.false -instance : HasNot Boogie.Expression where +instance : HasNot Core.Expression where not - | Boogie.true => Boogie.false - | Boogie.false => Boogie.true - | e => Lambda.LExpr.app () (Lambda.LFunc.opExpr (T:=BoogieLParams) Lambda.boolNotFunc) e + | Core.true => Core.false + | Core.false => Core.true + | e => Lambda.LExpr.app () (Lambda.LFunc.opExpr (T:=CoreLParams) Lambda.boolNotFunc) e -abbrev BoogieEval := SemanticEval Expression -abbrev BoogieStore := SemanticStore Expression +abbrev CoreEval := SemanticEval Expression +abbrev CoreStore := SemanticStore Expression -structure WellFormedBoogieEvalCong (δ : BoogieEval): Prop where +structure WellFormedCoreEvalCong (δ : CoreEval): Prop where abscongr: (∀ σ σ' e₁ e₁' , δ σ e₁ = δ σ' e₁' → (∀ ty m, δ σ (.abs ty m e₁) = δ σ' (.abs ty m e₁'))) @@ -163,8 +163,8 @@ def updatedStates -- https://dafny.org/latest/DafnyRef/DafnyRef#sec-two-state -- where this condition will be asserted at procedures utilizing those two-state functions -/ -def WellFormedBoogieEvalTwoState (δ : BoogieEval) (σ₀ σ : BoogieStore) : Prop := - open Boogie.OldExpressions in +def WellFormedCoreEvalTwoState (δ : CoreEval) (σ₀ σ : CoreStore) : Prop := + open Core.OldExpressions in (∃ vs vs' σ₁, HavocVars σ₀ vs σ₁ ∧ InitVars σ₁ vs' σ) ∧ (∀ vs vs' σ₀ σ₁ σ, (HavocVars σ₀ vs σ₁ ∧ InitVars σ₁ vs' σ) → @@ -181,8 +181,8 @@ def WellFormedBoogieEvalTwoState (δ : BoogieEval) (σ₀ σ : BoogieStore) : Pr -- Might not be needed if we assume all expressions are normalized (∀ e σ, δ σ e = δ σ (normalizeOldExpr e)) -inductive EvalCommand : (String → Option Procedure) → BoogieEval → - BoogieStore → Command → BoogieStore → Prop where +inductive EvalCommand : (String → Option Procedure) → CoreEval → + CoreStore → Command → CoreStore → Prop where | cmd_sem {π δ σ c σ'} : Imperative.EvalCmd (P:=Expression) δ σ c σ' → ---- @@ -206,7 +206,7 @@ inductive EvalCommand : (String → Option Procedure) → BoogieEval → WellFormedSemanticEvalVal δ → WellFormedSemanticEvalVar δ → WellFormedSemanticEvalBool δ → - WellFormedBoogieEvalTwoState δ σ₀ σ → + WellFormedCoreEvalTwoState δ σ₀ σ → isDefinedOver (HasVarsTrans.allVarsTrans π) σ (Statement.call lhs n args) → @@ -233,16 +233,16 @@ inductive EvalCommand : (String → Option Procedure) → BoogieEval → ---- EvalCommand π δ σ (CmdExt.call lhs n args) σ' -abbrev EvalStatement (π : String → Option Procedure) : BoogieEval → - BoogieStore → Statement → BoogieStore → Prop := +abbrev EvalStatement (π : String → Option Procedure) : CoreEval → + CoreStore → Statement → CoreStore → Prop := Imperative.EvalStmt Expression Command (EvalCommand π) -abbrev EvalStatements (π : String → Option Procedure) : BoogieEval → - BoogieStore → List Statement → BoogieStore → Prop := +abbrev EvalStatements (π : String → Option Procedure) : CoreEval → + CoreStore → List Statement → CoreStore → Prop := Imperative.EvalBlock Expression Command (EvalCommand π) -inductive EvalCommandContract : (String → Option Procedure) → BoogieEval → - BoogieStore → Command → BoogieStore → Prop where +inductive EvalCommandContract : (String → Option Procedure) → CoreEval → + CoreStore → Command → CoreStore → Prop where | cmd_sem {π δ σ c σ'} : Imperative.EvalCmd (P:=Expression) δ σ c σ' → ---- @@ -250,12 +250,12 @@ inductive EvalCommandContract : (String → Option Procedure) → BoogieEval | call_sem {π δ σ args oVals vals σA σAO σO σR n p modvals lhs σ'} : π n = .some p → - EvalExpressions (P:=Boogie.Expression) δ σ args vals → + EvalExpressions (P:=Core.Expression) δ σ args vals → ReadValues σ lhs oVals → WellFormedSemanticEvalVal δ → WellFormedSemanticEvalVar δ → WellFormedSemanticEvalBool δ → - WellFormedBoogieEvalTwoState δ σ₀ σ → + WellFormedCoreEvalTwoState δ σ₀ σ → isDefinedOver (HasVarsTrans.allVarsTrans π) σ (Statement.call lhs n args) → @@ -282,10 +282,10 @@ inductive EvalCommandContract : (String → Option Procedure) → BoogieEval ---- EvalCommandContract π δ σ (.call lhs n args) σ' -abbrev EvalStatementContract (π : String → Option Procedure) : BoogieEval → - BoogieStore → Statement → BoogieStore → Prop := +abbrev EvalStatementContract (π : String → Option Procedure) : CoreEval → + CoreStore → Statement → CoreStore → Prop := Imperative.EvalStmt Expression Command (EvalCommandContract π) -abbrev EvalStatementsContract (π : String → Option Procedure) : BoogieEval → - BoogieStore → List Statement → BoogieStore → Prop := +abbrev EvalStatementsContract (π : String → Option Procedure) : CoreEval → + CoreStore → List Statement → CoreStore → Prop := Imperative.EvalBlock Expression Command (EvalCommandContract π) diff --git a/Strata/Languages/Boogie/StatementSemanticsProps.lean b/Strata/Languages/Core/StatementSemanticsProps.lean similarity index 99% rename from Strata/Languages/Boogie/StatementSemanticsProps.lean rename to Strata/Languages/Core/StatementSemanticsProps.lean index 8fe645f7f..20f943b5d 100644 --- a/Strata/Languages/Boogie/StatementSemanticsProps.lean +++ b/Strata/Languages/Core/StatementSemanticsProps.lean @@ -9,14 +9,14 @@ import Strata.DL.Imperative.StmtSemantics import Strata.DL.Imperative.HasVars import Strata.DL.Util.Nodup import Strata.DL.Util.ListUtils -import Strata.Languages.Boogie.Procedure -import Strata.Languages.Boogie.Statement -import Strata.Languages.Boogie.OldExpressions -import Strata.Languages.Boogie.StatementSemantics +import Strata.Languages.Core.Procedure +import Strata.Languages.Core.Statement +import Strata.Languages.Core.OldExpressions +import Strata.Languages.Core.StatementSemantics /-! ## Theorems related to StatementSemantics -/ -namespace Boogie +namespace Core open Imperative theorem InitStatesEmpty : @@ -610,7 +610,7 @@ theorem ReadValuesLength : induction Hrd <;> simp_all theorem EvalExpressionsLength : - EvalExpressions (P:=Boogie.Expression) δ σ ks vs → + EvalExpressions (P:=Core.Expression) δ σ ks vs → ks.length = vs.length := by intros Hrd induction Hrd <;> simp_all @@ -1707,7 +1707,7 @@ theorem HavocVarsDefined : theorem EvalCmdDefMonotone : isDefined σ v → - EvalCmd Boogie.Expression δ σ c σ' → + EvalCmd Core.Expression δ σ c σ' → isDefined σ' v := by intros Hdef Heval cases Heval <;> try exact Hdef @@ -2088,7 +2088,7 @@ theorem EvalStmtRefinesContract : We work around this by requiring this condition at `EvalExpressions`. -/ theorem EvalExpressionIsDefined : - WellFormedBoogieEvalCong δ → + WellFormedCoreEvalCong δ → WellFormedSemanticEvalVar δ → (δ σ e).isSome → isDefined σ (HasVarsPure.getVars e) := by diff --git a/Strata/Languages/Boogie/StatementType.lean b/Strata/Languages/Core/StatementType.lean similarity index 94% rename from Strata/Languages/Boogie/StatementType.lean rename to Strata/Languages/Core/StatementType.lean index 38b06eac7..8e7c3a400 100644 --- a/Strata/Languages/Boogie/StatementType.lean +++ b/Strata/Languages/Core/StatementType.lean @@ -6,13 +6,13 @@ -import Strata.Languages.Boogie.Statement -import Strata.Languages.Boogie.CmdType -import Strata.Languages.Boogie.Program -import Strata.Languages.Boogie.OldExpressions +import Strata.Languages.Core.Statement +import Strata.Languages.Core.CmdType +import Strata.Languages.Core.Program +import Strata.Languages.Core.OldExpressions import Strata.DL.Imperative.CmdType -namespace Boogie +namespace Core namespace Statement open Lambda Imperative @@ -20,12 +20,12 @@ open Std (ToFormat Format format) --------------------------------------------------------------------- /-- -Type checker for Boogie commands. +Type checker for Strata Core commands. Note that this function needs the entire program to type-check `call` commands by looking up the corresponding procedure's information. -/ -def typeCheckCmd (C: LContext BoogieLParams) (Env : TEnv Visibility) (P : Program) (c : Command) : +def typeCheckCmd (C: LContext CoreLParams) (Env : TEnv Visibility) (P : Program) (c : Command) : Except Format (Command × (TEnv Visibility)) := do match c with | .cmd c => @@ -38,7 +38,7 @@ def typeCheckCmd (C: LContext BoogieLParams) (Env : TEnv Visibility) (P : Progra match Program.Procedure.find? P pname with | none => .error f!"[{c}]: Procedure {pname} not found!" | some proc => - if lhs.any (fun (l: BoogieIdent) => (Env.context.types.find? l).isNone) then + if lhs.any (fun (l: CoreIdent) => (Env.context.types.find? l).isNone) then .error f!"[{c}]: All the return variables {lhs} must exist in the context!" else if lhs.length != proc.header.outputs.length then .error f!"[{c}]: Arity mismatch in this call's return values!\ @@ -75,7 +75,7 @@ def typeCheckCmd (C: LContext BoogieLParams) (Env : TEnv Visibility) (P : Progra .error f!"{@MetaData.formatFileRangeD Expression _ md false} {e}" -def typeCheckAux (C: LContext BoogieLParams) (Env : TEnv Visibility) (P : Program) (op : Option Procedure) (ss : List Statement) : +def typeCheckAux (C: LContext CoreLParams) (Env : TEnv Visibility) (P : Program) (op : Option Procedure) (ss : List Statement) : Except Format (List Statement × TEnv Visibility) := go Env ss [] where @@ -231,4 +231,4 @@ def typeCheck (C: Expression.TyContext) (Env : Expression.TyEnv) (P : Program) ( --------------------------------------------------------------------- end Statement -end Boogie +end Core diff --git a/Strata/Languages/Boogie/StatementWF.lean b/Strata/Languages/Core/StatementWF.lean similarity index 96% rename from Strata/Languages/Boogie/StatementWF.lean rename to Strata/Languages/Core/StatementWF.lean index 751b41b34..0b79fc324 100644 --- a/Strata/Languages/Boogie/StatementWF.lean +++ b/Strata/Languages/Core/StatementWF.lean @@ -7,12 +7,12 @@ import Strata.DL.Util.ListUtils -import Strata.Languages.Boogie.Program -import Strata.Languages.Boogie.WF -import Strata.Languages.Boogie.StatementType +import Strata.Languages.Core.Program +import Strata.Languages.Core.WF +import Strata.Languages.Core.StatementType --------------------------------------------------------------------- -namespace Boogie +namespace Core namespace WF open Std Lambda @@ -172,14 +172,14 @@ theorem Statement.typeCheckWF : constructor <;> simp_all . -- 13. The `lhs` of a call statement is disjoint from `modifies`, `outputs`, and `inputs` of the procedure sorry - . -- 7. The `lhs` of a call statement contain no duplicates and are `BoogieIdent.locl`. + . -- 7. The `lhs` of a call statement contain no duplicates and are `CoreIdent.locl`. sorry . refine List.Forall_mem_iff.mpr ?_ intros arg Hin constructor refine List.Forall_mem_iff.mpr ?_ intros var Hin' - -- 9. All variables mentioned in `args` of a call statement are either `BoogieIdent.locl` or `BoogieIdent.glob`. + -- 9. All variables mentioned in `args` of a call statement are either `CoreIdent.locl` or `CoreIdent.glob`. sorry | cmd => constructor @@ -230,4 +230,4 @@ theorem Statement.typeCheckWF : -/ end WF -end Boogie +end Core diff --git a/Strata/Languages/Boogie/TypeDecl.lean b/Strata/Languages/Core/TypeDecl.lean similarity index 94% rename from Strata/Languages/Boogie/TypeDecl.lean rename to Strata/Languages/Core/TypeDecl.lean index 6b1d075c4..4777445bb 100644 --- a/Strata/Languages/Boogie/TypeDecl.lean +++ b/Strata/Languages/Core/TypeDecl.lean @@ -6,16 +6,16 @@ -import Strata.Languages.Boogie.Statement +import Strata.Languages.Core.Statement --------------------------------------------------------------------- -namespace Boogie +namespace Core open Std (ToFormat Format format) open Lambda -/-! # Boogie Type Declarations -/ +/-! # Strata Core Type Declarations -/ inductive Boundedness where | Finite @@ -51,7 +51,7 @@ open Lambda.LTy.Syntax in #guard_msgs in #eval format $ TypeConstructor.toType { name := "Foo", numargs := 3 } -/-! # Boogie Type Synonyms -/ +/-! # Strata Core Type Synonyms -/ structure TypeSynonym where name : String @@ -81,7 +81,7 @@ def TypeSynonym.toLHSLTy (t : TypeSynonym) : LTy := def TypeSynonym.toRHSLTy (t : TypeSynonym) : LTy := .forAll t.typeArgs t.type -/-! # Boogie Type Declarations -/ +/-! # Strata Core Type Declarations -/ inductive TypeDecl where | con : TypeConstructor → TypeDecl diff --git a/Strata/Languages/Boogie/Verifier.lean b/Strata/Languages/Core/Verifier.lean similarity index 93% rename from Strata/Languages/Boogie/Verifier.lean rename to Strata/Languages/Core/Verifier.lean index cc34f384e..84038fdcf 100644 --- a/Strata/Languages/Boogie/Verifier.lean +++ b/Strata/Languages/Core/Verifier.lean @@ -4,10 +4,10 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.DDMTransform.Translate -import Strata.Languages.Boogie.Options -import Strata.Languages.Boogie.CallGraph -import Strata.Languages.Boogie.SMTEncoder +import Strata.Languages.Core.DDMTransform.Translate +import Strata.Languages.Core.Options +import Strata.Languages.Core.CallGraph +import Strata.Languages.Core.SMTEncoder import Strata.DL.Imperative.MetaData import Strata.DL.Imperative.SMTUtils import Strata.DL.SMT.CexParser @@ -19,7 +19,7 @@ namespace Strata.SMT.Encoder open Strata.SMT.Encoder -- Derived from Strata.SMT.Encoder.encode. -def encodeBoogie (ctx : Boogie.SMT.Context) (prelude : SolverM Unit) (ts : List Term) : +def encodeCore (ctx : Core.SMT.Context) (prelude : SolverM Unit) (ts : List Term) : SolverM (List String × EncoderState) := do Solver.reset Solver.setLogic "ALL" @@ -41,7 +41,7 @@ end Strata.SMT.Encoder --------------------------------------------------------------------- -namespace Boogie.SMT +namespace Core.SMT open Std (ToFormat Format format) open Lambda Strata.SMT -- (TODO) Use DL.Imperative.SMTUtils. @@ -188,7 +188,7 @@ def dischargeObligation let handle ← IO.FS.Handle.mk filename IO.FS.Mode.write let solver ← Solver.fileWriter handle let prelude := getSolverPrelude smtsolver - let (ids, estate) ← Strata.SMT.Encoder.encodeBoogie ctx prelude terms solver + let (ids, estate) ← Strata.SMT.Encoder.encodeCore ctx prelude terms solver let _ ← solver.checkSat ids -- Will return unknown for Solver.fileWriter if options.verbose > .normal then IO.println s!"Wrote problem to {filename}." let flags := getSolverFlags options smtsolver @@ -197,10 +197,10 @@ def dischargeObligation | .error e => return .error e | .ok result => return .ok (result, estate) -end Boogie.SMT +end Core.SMT --------------------------------------------------------------------- -namespace Boogie +namespace Core open Imperative Lambda Strata.SMT open Std (ToFormat Format format) @@ -262,8 +262,8 @@ def VCResult.isUnknown (vr : VCResult) : Bool := def VCResult.isImplementationError (vr : VCResult) : Bool := match vr.result with | .implementationError _ => true | _ => false -def VCResult.isNotSuccess (vcResult : Boogie.VCResult) := - !Boogie.VCResult.isSuccess vcResult +def VCResult.isNotSuccess (vcResult : Core.VCResult) := + !Core.VCResult.isSuccess vcResult abbrev VCResults := Array VCResult @@ -314,7 +314,7 @@ def preprocessObligation (obligation : ProofObligation Expression) (p : Program) -- axioms w.r.t. the consequent to reduce the size of the proof -- obligation. let cg := Program.toFunctionCG p - let fns := obligation.obligation.getOps.map BoogieIdent.toPretty + let fns := obligation.obligation.getOps.map CoreIdent.toPretty let relevant_fns := (fns ++ (CallGraph.getAllCalleesClosure cg fns)).dedup let irrelevant_axs := Program.getIrrelevantAxioms p relevant_fns let new_assumptions := Imperative.PathConditions.removeByNames obligation.assumptions irrelevant_axs @@ -406,9 +406,9 @@ def verifySingleEnv (smtsolver : String) (pE : Program × Env) (options : Option def verify (smtsolver : String) (program : Program) (tempDir : System.FilePath) (options : Options := Options.default) - (moreFns : @Lambda.Factory BoogieLParams := Lambda.Factory.default) + (moreFns : @Lambda.Factory CoreLParams := Lambda.Factory.default) : EIO Format VCResults := do - match Boogie.typeCheckAndPartialEval options program moreFns with + match Core.typeCheckAndPartialEval options program moreFns with | .error err => .error f!"❌ Type checking error.\n{format err}" | .ok pEs => @@ -419,7 +419,7 @@ def verify (smtsolver : String) (program : Program) (List.mapM (fun pE => verifySingleEnv smtsolver pE options counter tempDir) pEs) .ok VCss.toArray.flatten -end Boogie +end Core --------------------------------------------------------------------- namespace Strata @@ -427,33 +427,33 @@ namespace Strata open Lean.Parser def typeCheck (ictx : InputContext) (env : Program) (options : Options := Options.default) - (moreFns : @Lambda.Factory Boogie.BoogieLParams := Lambda.Factory.default) : - Except Std.Format Boogie.Program := do + (moreFns : @Lambda.Factory Core.CoreLParams := Lambda.Factory.default) : + Except Std.Format Core.Program := do let (program, errors) := TransM.run ictx (translateProgram env) if errors.isEmpty then -- dbg_trace f!"AST: {program}" - Boogie.typeCheck options program moreFns + Core.typeCheck options program moreFns else .error s!"DDM Transform Error: {repr errors}" -def Boogie.getProgram +def Core.getProgram (p : Strata.Program) - (ictx : InputContext := Inhabited.default) : Boogie.Program × Array String := + (ictx : InputContext := Inhabited.default) : Core.Program × Array String := TransM.run ictx (translateProgram p) def verify (smtsolver : String) (env : Program) (ictx : InputContext := Inhabited.default) (options : Options := Options.default) - (moreFns : @Lambda.Factory Boogie.BoogieLParams := Lambda.Factory.default) + (moreFns : @Lambda.Factory Core.CoreLParams := Lambda.Factory.default) (tempDir : Option String := .none) - : IO Boogie.VCResults := do - let (program, errors) := Boogie.getProgram env ictx + : IO Core.VCResults := do + let (program, errors) := Core.getProgram env ictx if errors.isEmpty then -- dbg_trace f!"AST: {program}" let runner tempDir := EIO.toIO (fun f => IO.Error.userError (toString f)) - (Boogie.verify smtsolver program tempDir options moreFns) + (Core.verify smtsolver program tempDir options moreFns) match tempDir with | .none => IO.FS.withTempDir runner @@ -472,7 +472,7 @@ structure Diagnostic where message : String deriving Repr, BEq -def toDiagnostic (vcr : Boogie.VCResult) : Option Diagnostic := do +def toDiagnostic (vcr : Core.VCResult) : Option Diagnostic := do -- Only create a diagnostic if verification failed. match vcr.result with | .pass => none -- Verification succeeded, no diagnostic diff --git a/Strata/Languages/Boogie/WF.lean b/Strata/Languages/Core/WF.lean similarity index 87% rename from Strata/Languages/Boogie/WF.lean rename to Strata/Languages/Core/WF.lean index e79c6f445..4a79db2d3 100644 --- a/Strata/Languages/Boogie/WF.lean +++ b/Strata/Languages/Core/WF.lean @@ -5,11 +5,11 @@ -/ import Strata.DL.Util.ListUtils -import Strata.Languages.Boogie.Program -import Strata.Languages.Boogie.OldExpressions +import Strata.Languages.Core.Program +import Strata.Languages.Core.OldExpressions -/-! # Well-Formedness of Boogie Programs - This file contains well-formedness definitions of Boogie `Program`s Note that +/-! # Well-Formedness of Strata Core Programs + This file contains well-formedness definitions of Strata Core `Program`s Note that the substructures such as `WFStatementProp` also carry a `Program` instance, and this allows us to state more expressive well-formedness conditions than a typical inductive relation. @@ -35,7 +35,7 @@ import Strata.Languages.Boogie.OldExpressions -/ -namespace Boogie +namespace Core namespace WF open Imperative @@ -45,7 +45,7 @@ open Imperative structure WFcmdProp (p : Program) (c : Imperative.Cmd Expression) : Prop where structure WFargProp (p : Program) (arg : Expression.Expr) : Prop where - glarg : Forall (BoogieIdent.isGlobOrLocl ·) (HasVarsPure.getVars (P:=Expression) arg) + glarg : Forall (CoreIdent.isGlobOrLocl ·) (HasVarsPure.getVars (P:=Expression) arg) structure WFcallProp (p : Program) (lhs : List Expression.Ident) (procName : String) (args : List Expression.Expr) : Prop where defined : (Program.Procedure.find? p (.unres procName)).isSome @@ -55,7 +55,7 @@ structure WFcallProp (p : Program) (lhs : List Expression.Ident) (procName : Str proc.header.outputs.length = lhs.length lhsDisj : (Program.Procedure.find? p (.unres procName) = some proc) → lhs.Disjoint (proc.spec.modifies ++ ListMap.keys proc.header.inputs ++ ListMap.keys proc.header.outputs) - lhsWF : lhs.Nodup ∧ Forall (BoogieIdent.isLocl ·) lhs + lhsWF : lhs.Nodup ∧ Forall (CoreIdent.isLocl ·) lhs wfargs : Forall (WFargProp p) args def WFCmdExtProp (p : Program) (c : CmdExt Expression) : Prop := match c with @@ -89,20 +89,20 @@ instance (p : Program) : ListP (WFStatementProp p) (WFStatementsProp p) where /- Spec Wellformedness -/ -structure WFPrePostProp (p : Program) (d : Procedure) (pp : BoogieLabel × Procedure.Check) +structure WFPrePostProp (p : Program) (d : Procedure) (pp : CoreLabel × Procedure.Check) : Prop where - glvars : Forall (BoogieIdent.isGlobOrLocl ·) (HasVarsPure.getVars (P:=Expression) pp.2.expr) + glvars : Forall (CoreIdent.isGlobOrLocl ·) (HasVarsPure.getVars (P:=Expression) pp.2.expr) lvars : Forall (fun x => - (BoogieIdent.isLocl x) → + (CoreIdent.isLocl x) → (x ∈ (ListMap.keys d.header.inputs) ++ (ListMap.keys d.header.outputs))) (HasVarsPure.getVars (P:=Expression) pp.2.expr) -structure WFPreProp (p : Program) (d : Procedure) (pp : BoogieLabel × Procedure.Check) +structure WFPreProp (p : Program) (d : Procedure) (pp : CoreLabel × Procedure.Check) : Prop extends WFPrePostProp p d pp where nold : ¬ OldExpressions.containsOldExpr pp.2.expr -structure WFPostProp (p : Program) (d : Procedure) (pp : BoogieLabel × Procedure.Check) +structure WFPostProp (p : Program) (d : Procedure) (pp : CoreLabel × Procedure.Check) : Prop extends WFPrePostProp p d pp where oldexprs : OldExpressions.ValidExpression pp.2.expr @@ -127,7 +127,7 @@ structure WFSpecProp (p : Program) (spec : Procedure.Spec) (d : Procedure): Prop /- Procedure Wellformedness -/ structure WFVarProp (p : Program) (name : Expression.Ident) (ty : Expression.Ty) (e : Expression.Expr) : Prop where - glob : BoogieIdent.isGlob name + glob : CoreIdent.isGlob name structure WFTypeDeclarationProp (p : Program) (f : TypeDecl) : Prop where @@ -142,8 +142,8 @@ structure WFProcedureProp (p : Program) (d : Procedure) : Prop where inputsNodup : (ListMap.keys d.header.inputs).Nodup outputsNodup : (ListMap.keys d.header.outputs).Nodup modNodup : d.spec.modifies.Nodup - inputsLocl : Forall (BoogieIdent.isLocl ·) (ListMap.keys d.header.inputs) - outputsLocl : Forall (BoogieIdent.isLocl ·) (ListMap.keys d.header.outputs) + inputsLocl : Forall (CoreIdent.isLocl ·) (ListMap.keys d.header.inputs) + outputsLocl : Forall (CoreIdent.isLocl ·) (ListMap.keys d.header.outputs) wfspec : WFSpecProp p d.spec d structure WFFunctionProp (p : Program) (f : Function) : Prop where @@ -174,4 +174,4 @@ structure WFProgram extends (Wrapper Program) where prop: WFProgramProp self end WF -end Boogie +end Core diff --git a/Strata/Languages/Laurel/Grammar/ConcreteToAbstractTreeTranslator.lean b/Strata/Languages/Laurel/Grammar/ConcreteToAbstractTreeTranslator.lean index e79088187..6ba5474f3 100644 --- a/Strata/Languages/Laurel/Grammar/ConcreteToAbstractTreeTranslator.lean +++ b/Strata/Languages/Laurel/Grammar/ConcreteToAbstractTreeTranslator.lean @@ -8,7 +8,7 @@ import Strata.DDM.AST import Strata.Languages.Laurel.Grammar.LaurelGrammar import Strata.Languages.Laurel.Laurel import Strata.DL.Imperative.MetaData -import Strata.Languages.Boogie.Expressions +import Strata.Languages.Core.Expressions namespace Laurel @@ -30,7 +30,7 @@ def TransM.run (ictx : InputContext) (m : TransM α) : Except String α := def TransM.error (msg : String) : TransM α := throw msg -def SourceRange.toMetaData (ictx : InputContext) (sr : SourceRange) : Imperative.MetaData Boogie.Expression := +def SourceRange.toMetaData (ictx : InputContext) (sr : SourceRange) : Imperative.MetaData Core.Expression := let file := ictx.fileName let startPos := ictx.fileMap.toPosition sr.start let endPos := ictx.fileMap.toPosition sr.stop @@ -38,7 +38,7 @@ def SourceRange.toMetaData (ictx : InputContext) (sr : SourceRange) : Imperative let fileRangeElt := ⟨ Imperative.MetaDataElem.Field.label "fileRange", .fileRange ⟨ uri, startPos, endPos ⟩ ⟩ #[fileRangeElt] -def getArgMetaData (arg : Arg) : TransM (Imperative.MetaData Boogie.Expression) := +def getArgMetaData (arg : Arg) : TransM (Imperative.MetaData Core.Expression) := return SourceRange.toMetaData (← get).inputCtx arg.ann def checkOp (op : Strata.Operation) (name : QualifiedIdent) (argc : Nat) : diff --git a/Strata/Languages/Laurel/Laurel.lean b/Strata/Languages/Laurel/Laurel.lean index ffa4d5d39..03819e523 100644 --- a/Strata/Languages/Laurel/Laurel.lean +++ b/Strata/Languages/Laurel/Laurel.lean @@ -5,8 +5,8 @@ -/ import Strata.DL.Imperative.MetaData -import Strata.Languages.Boogie.Expressions -import Strata.Languages.Boogie.Procedure +import Strata.Languages.Core.Expressions +import Strata.Languages.Core.Procedure /- The Laurel language is supposed to serve as an intermediate verification language for at least Java, Python, JavaScript. @@ -58,7 +58,7 @@ inductive Operation: Type where deriving Repr -- Explicit instance needed for deriving Repr in the mutual block -instance : Repr (Imperative.MetaData Boogie.Expression) := inferInstance +instance : Repr (Imperative.MetaData Core.Expression) := inferInstance mutual structure Procedure: Type where @@ -153,8 +153,8 @@ inductive StmtExpr : Type where | Fresh(value : StmtExpr) /- Related to proofs -/ - | Assert (condition: StmtExpr) (md : Imperative.MetaData Boogie.Expression) - | Assume (condition: StmtExpr) (md : Imperative.MetaData Boogie.Expression) + | Assert (condition: StmtExpr) (md : Imperative.MetaData Core.Expression) + | Assume (condition: StmtExpr) (md : Imperative.MetaData Core.Expression) /- ProveBy allows writing proof trees. Its semantics are the same as that of the given `value`, but the `proof` is used to help prove any assertions in `value`. diff --git a/Strata/Languages/Laurel/LaurelToBoogieTranslator.lean b/Strata/Languages/Laurel/LaurelToCoreTranslator.lean similarity index 65% rename from Strata/Languages/Laurel/LaurelToBoogieTranslator.lean rename to Strata/Languages/Laurel/LaurelToCoreTranslator.lean index c8be1d9ef..7061bf5c8 100644 --- a/Strata/Languages/Laurel/LaurelToBoogieTranslator.lean +++ b/Strata/Languages/Laurel/LaurelToCoreTranslator.lean @@ -4,11 +4,11 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Program -import Strata.Languages.Boogie.Verifier -import Strata.Languages.Boogie.Statement -import Strata.Languages.Boogie.Procedure -import Strata.Languages.Boogie.Options +import Strata.Languages.Core.Program +import Strata.Languages.Core.Verifier +import Strata.Languages.Core.Statement +import Strata.Languages.Core.Procedure +import Strata.Languages.Core.Options import Strata.Languages.Laurel.Laurel import Strata.Languages.Laurel.LiftExpressionAssignments import Strata.DL.Imperative.Stmt @@ -18,14 +18,14 @@ import Strata.Languages.Laurel.LaurelFormat namespace Laurel -open Boogie (VCResult VCResults) +open Core (VCResult VCResults) open Strata -open Boogie (intAddOp intSubOp intMulOp intDivOp intModOp intNegOp intLtOp intLeOp intGtOp intGeOp boolAndOp boolOrOp boolNotOp) +open Core (intAddOp intSubOp intMulOp intDivOp intModOp intNegOp intLtOp intLeOp intGtOp intGeOp boolAndOp boolOrOp boolNotOp) open Lambda (LMonoTy LTy LExpr) /- -Translate Laurel HighType to Boogie Type +Translate Laurel HighType to Core Type -/ def translateType (ty : HighType) : LMonoTy := match ty with @@ -35,14 +35,14 @@ def translateType (ty : HighType) : LMonoTy := | _ => panic s!"unsupported type {repr ty}" /-- -Translate Laurel StmtExpr to Boogie Expression +Translate Laurel StmtExpr to Core Expression -/ -def translateExpr (expr : StmtExpr) : Boogie.Expression.Expr := +def translateExpr (expr : StmtExpr) : Core.Expression.Expr := match h: expr with | .LiteralBool b => .const () (.boolConst b) | .LiteralInt i => .const () (.intConst i) | .Identifier name => - let ident := Boogie.BoogieIdent.locl name + let ident := Core.CoreIdent.locl name .fvar () ident (some LMonoTy.int) -- Default to int type | .PrimitiveOp op [e] => match op with @@ -50,7 +50,7 @@ def translateExpr (expr : StmtExpr) : Boogie.Expression.Expr := | .Neg => .app () intNegOp (translateExpr e) | _ => panic! s!"translateExpr: Invalid unary op: {repr op}" | .PrimitiveOp op [e1, e2] => - let binOp (bop : Boogie.Expression.Expr): Boogie.Expression.Expr := + let binOp (bop : Core.Expression.Expr): Core.Expression.Expr := LExpr.mkApp () bop [translateExpr e1, translateExpr e2] match op with | .Eq => .eq () (translateExpr e1) (translateExpr e2) @@ -79,7 +79,7 @@ def translateExpr (expr : StmtExpr) : Boogie.Expression.Expr := | .Assign _ value => translateExpr value -- For expressions, just translate the value | .StaticCall name args => -- Create function call as an op application - let ident := Boogie.BoogieIdent.glob name + let ident := Core.CoreIdent.glob name let fnOp := .op () ident (some LMonoTy.int) -- Assume int return type args.foldl (fun acc arg => .app () acc (translateExpr arg)) fnOp | _ => panic! Std.Format.pretty (Std.ToFormat.format expr) @@ -87,45 +87,45 @@ def translateExpr (expr : StmtExpr) : Boogie.Expression.Expr := all_goals (simp_wf; try omega) rename_i x_in; have := List.sizeOf_lt_of_mem x_in; omega -def getNameFromMd (md : Imperative.MetaData Boogie.Expression): String := +def getNameFromMd (md : Imperative.MetaData Core.Expression): String := let fileRange := (Imperative.getFileRange md).get! s!"({fileRange.start.column},{fileRange.start.line})" /-- -Translate Laurel StmtExpr to Boogie Statements +Translate Laurel StmtExpr to Core Statements Takes the list of output parameter names to handle return statements correctly -/ -def translateStmt (outputParams : List Parameter) (stmt : StmtExpr) : List Boogie.Statement := +def translateStmt (outputParams : List Parameter) (stmt : StmtExpr) : List Core.Statement := match stmt with | @StmtExpr.Assert cond md => - let boogieExpr := translateExpr cond - [Boogie.Statement.assert ("assert" ++ getNameFromMd md) boogieExpr md] + let coreExpr := translateExpr cond + [Core.Statement.assert ("assert" ++ getNameFromMd md) coreExpr md] | @StmtExpr.Assume cond md => - let boogieExpr := translateExpr cond - [Boogie.Statement.assume ("assume" ++ getNameFromMd md) boogieExpr md] + let coreExpr := translateExpr cond + [Core.Statement.assume ("assume" ++ getNameFromMd md) coreExpr md] | .Block stmts _ => stmts.flatMap (translateStmt outputParams) | .LocalVariable name ty initializer => - let boogieMonoType := translateType ty - let boogieType := LTy.forAll [] boogieMonoType - let ident := Boogie.BoogieIdent.locl name + let coreMonoType := translateType ty + let coreType := LTy.forAll [] coreMonoType + let ident := Core.CoreIdent.locl name match initializer with | some initExpr => - let boogieExpr := translateExpr initExpr - [Boogie.Statement.init ident boogieType boogieExpr] + let coreExpr := translateExpr initExpr + [Core.Statement.init ident coreType coreExpr] | none => -- Initialize with default value let defaultExpr := match ty with | .TInt => .const () (.intConst 0) | .TBool => .const () (.boolConst false) | _ => .const () (.intConst 0) - [Boogie.Statement.init ident boogieType defaultExpr] + [Core.Statement.init ident coreType defaultExpr] | .Assign target value => match target with | .Identifier name => - let ident := Boogie.BoogieIdent.locl name - let boogieExpr := translateExpr value - [Boogie.Statement.set ident boogieExpr] + let ident := Core.CoreIdent.locl name + let coreExpr := translateExpr value + [Core.Statement.set ident coreExpr] | _ => [] -- Can only assign to simple identifiers | .IfThenElse cond thenBranch elseBranch => let bcond := translateExpr cond @@ -133,24 +133,24 @@ def translateStmt (outputParams : List Parameter) (stmt : StmtExpr) : List Boogi let belse := match elseBranch with | some e => translateStmt outputParams e | none => [] - -- Use Boogie's if-then-else construct + -- Use Core's if-then-else construct [Imperative.Stmt.ite bcond bthen belse .empty] | .StaticCall name args => - let boogieArgs := args.map translateExpr - [Boogie.Statement.call [] name boogieArgs] + let coreArgs := args.map translateExpr + [Core.Statement.call [] name coreArgs] | .Return valueOpt => - -- In Boogie, returns are done by assigning to output parameters + -- In Core, returns are done by assigning to output parameters match valueOpt, outputParams.head? with | some value, some outParam => -- Assign to the first output parameter, then assume false for no fallthrough - let ident := Boogie.BoogieIdent.locl outParam.name - let boogieExpr := translateExpr value - let assignStmt := Boogie.Statement.set ident boogieExpr - let noFallThrough := Boogie.Statement.assume "return" (.const () (.boolConst false)) .empty + let ident := Core.CoreIdent.locl outParam.name + let coreExpr := translateExpr value + let assignStmt := Core.Statement.set ident coreExpr + let noFallThrough := Core.Statement.assume "return" (.const () (.boolConst false)) .empty [assignStmt, noFallThrough] | none, _ => -- Return with no value - just indicate no fallthrough - let noFallThrough := Boogie.Statement.assume "return" (.const () (.boolConst false)) .empty + let noFallThrough := Core.Statement.assume "return" (.const () (.boolConst false)) .empty [noFallThrough] | some _, none => -- Error: trying to return a value but no output parameters @@ -158,33 +158,33 @@ def translateStmt (outputParams : List Parameter) (stmt : StmtExpr) : List Boogi | _ => panic! Std.Format.pretty (Std.ToFormat.format stmt) /-- -Translate Laurel Parameter to Boogie Signature entry +Translate Laurel Parameter to Core Signature entry -/ -def translateParameterToBoogie (param : Parameter) : (Boogie.BoogieIdent × LMonoTy) := - let ident := Boogie.BoogieIdent.locl param.name +def translateParameterToCore (param : Parameter) : (Core.CoreIdent × LMonoTy) := + let ident := Core.CoreIdent.locl param.name let ty := translateType param.type (ident, ty) /-- -Translate Laurel Procedure to Boogie Procedure +Translate Laurel Procedure to Core Procedure -/ -def translateProcedure (proc : Procedure) : Boogie.Procedure := +def translateProcedure (proc : Procedure) : Core.Procedure := -- Translate input parameters - let inputPairs := proc.inputs.map translateParameterToBoogie + let inputPairs := proc.inputs.map translateParameterToCore let inputs := inputPairs - let header : Boogie.Procedure.Header := { + let header : Core.Procedure.Header := { name := proc.name typeArgs := [] inputs := inputs - outputs := proc.outputs.map translateParameterToBoogie + outputs := proc.outputs.map translateParameterToCore } - let spec : Boogie.Procedure.Spec := { + let spec : Core.Procedure.Spec := { modifies := [] preconditions := [] postconditions := [] } - let body : List Boogie.Statement := + let body : List Core.Statement := match proc.body with | .Transparent bodyExpr => translateStmt proc.outputs bodyExpr | _ => [] -- TODO: handle Opaque and Abstract bodies @@ -195,17 +195,17 @@ def translateProcedure (proc : Procedure) : Boogie.Procedure := } /-- -Translate Laurel Program to Boogie Program +Translate Laurel Program to Core Program -/ -def translate (program : Program) : Boogie.Program := +def translate (program : Program) : Core.Program := -- First, sequence all assignments (move them out of expression positions) let sequencedProgram := liftExpressionAssignments program dbg_trace "=== Sequenced program Program ===" dbg_trace (toString (Std.Format.pretty (Std.ToFormat.format sequencedProgram))) dbg_trace "=================================" - -- Then translate to Boogie + -- Then translate to Core let procedures := sequencedProgram.staticProcedures.map translateProcedure - let decls := procedures.map (fun p => Boogie.Decl.proc p .empty) + let decls := procedures.map (fun p => Core.Decl.proc p .empty) { decls := decls } /-- @@ -213,14 +213,14 @@ Verify a Laurel program using an SMT solver -/ def verifyToVcResults (smtsolver : String) (program : Program) (options : Options := Options.default) : IO VCResults := do - let boogieProgram := translate program - -- Debug: Print the generated Boogie program - dbg_trace "=== Generated Boogie Program ===" - dbg_trace (toString (Std.Format.pretty (Std.ToFormat.format boogieProgram))) + let coreProgram := translate program + -- Debug: Print the generated Core program + dbg_trace "=== Generated Core.Program ===" + dbg_trace (toString (Std.Format.pretty (Std.ToFormat.format coreProgram))) dbg_trace "=================================" IO.FS.withTempDir (fun tempDir => EIO.toIO (fun f => IO.Error.userError (toString f)) - (Boogie.verify smtsolver boogieProgram tempDir options)) + (Core.verify smtsolver coreProgram tempDir options)) def verifyToDiagnostics (smtsolver : String) (program : Program): IO (Array Diagnostic) := do let results <- verifyToVcResults smtsolver program diff --git a/Strata/Languages/Python/BoogiePrelude.lean b/Strata/Languages/Python/CorePrelude.lean similarity index 97% rename from Strata/Languages/Python/BoogiePrelude.lean rename to Strata/Languages/Python/CorePrelude.lean index 7eb7cd3dc..333078049 100644 --- a/Strata/Languages/Python/BoogiePrelude.lean +++ b/Strata/Languages/Python/CorePrelude.lean @@ -6,14 +6,14 @@ import Strata.DDM.Elab import Strata.DDM.AST -import Strata.Languages.Boogie.DDMTransform.Parse -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.DDMTransform.Parse +import Strata.Languages.Core.Verifier namespace Strata -def boogiePrelude := +def corePrelude := #strata -program Boogie; +program Core; datatype None () { None_none() @@ -183,7 +183,7 @@ datatype Client () { // - -999999999 <= days <= 999999999 // "" -// In Boogie representation, an int type that corresponds to the full +// In the Strata Core representation, an int type that corresponds to the full // milliseconds is simply used. See Timedelta_mk. procedure timedelta(days: IntOrNone, hours: IntOrNone) returns (delta : int, maybe_except: ExceptOrNone) @@ -357,7 +357,7 @@ spec { #end -def Boogie.prelude : Boogie.Program := - Boogie.getProgram Strata.boogiePrelude |>.fst +def Core.prelude : Core.Program := + Core.getProgram Strata.corePrelude |>.fst end Strata diff --git a/Strata/Languages/Python/FunctionSignatures.lean b/Strata/Languages/Python/FunctionSignatures.lean index 2f0c7809b..1870bdef7 100644 --- a/Strata/Languages/Python/FunctionSignatures.lean +++ b/Strata/Languages/Python/FunctionSignatures.lean @@ -4,12 +4,12 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Boogie +import Strata.Languages.Core.Core namespace Strata namespace Python -/-- A type identifier in the Python Boogie prelude. -/ +/-- A type identifier in the Strata Core prelude for Python. -/ abbrev TypeId := String /-- An argument declaration for a Python method -/ @@ -48,7 +48,7 @@ structure FuncDecl where instance : Inhabited FuncDecl where default := { args := #[], argIndexMap := {} } -/-- The name of a Python method as encoded in the Boogie dialect-/ +/-- The name of a Python method as encoded in the Strata Core dialect-/ abbrev FuncName := String /-- A collection of function signatures. -/ @@ -143,7 +143,7 @@ def coreSignatures : Signatures := addCoreDecls |>.run end -def TypeStrToBoogieExpr (ty: String) : Boogie.Expression.Expr := +def TypeStrToCoreExpr (ty: String) : Core.Expression.Expr := if !ty.endsWith "OrNone" then panic! s!"Should only be called for possibly None types. Called for: {ty}" else diff --git a/Strata/Languages/Python/PyFactory.lean b/Strata/Languages/Python/PyFactory.lean index 927e8dfd4..9a620ff80 100644 --- a/Strata/Languages/Python/PyFactory.lean +++ b/Strata/Languages/Python/PyFactory.lean @@ -4,8 +4,8 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier -import Strata.Languages.Python.Regex.ReToBoogie +import Strata.Languages.Core.Verifier +import Strata.Languages.Python.Regex.ReToCore namespace Strata namespace Python @@ -27,7 +27,7 @@ if not re.match(REGEX, name) then # default flags == 0 ... ``` -## Corresponding Strata.Boogie: +## Corresponding Strata.Core: ``` procedure _main () { @@ -61,10 +61,10 @@ if not PyReMatch(REGEX, name, 0) then -/ -open Boogie +open Core open Lambda LTy.Syntax LExpr.SyntaxMono -def reCompileFunc : LFunc Boogie.BoogieLParams := +def reCompileFunc : LFunc Core.CoreLParams := { name := "PyReCompile", typeArgs := [], inputs := [("string", mty[string]), @@ -78,10 +78,10 @@ def reCompileFunc : LFunc Boogie.BoogieLParams := -- (FIXME): We use `.match` mode below because we support only -- `re.match` for now. However, `re.compile` isn't mode-specific in -- general. - let (expr, maybe_err) := pythonRegexToBoogie s .match + let (expr, maybe_err) := pythonRegexToCore s .match match maybe_err with | none => - -- Note: Do not use `eb` (in Boogie.Syntax) here (e.g., see below) + -- Note: Do not use `eb` (in Strata Core Syntax) here (e.g., see below) -- eb[(~ExceptErrorRegex_mkOK expr)] -- that captures `expr` as an `.fvar`. .some (LExpr.mkApp () (.op () "ExceptErrorRegex_mkOK" none) [expr]) @@ -94,7 +94,7 @@ def reCompileFunc : LFunc Boogie.BoogieLParams := | _ => .none) } -def ReFactory : @Factory Boogie.BoogieLParams := +def ReFactory : @Factory Core.CoreLParams := #[ reCompileFunc ] diff --git a/Strata/Languages/Python/Python.lean b/Strata/Languages/Python/Python.lean index dc56fc802..c704939eb 100644 --- a/Strata/Languages/Python/Python.lean +++ b/Strata/Languages/Python/Python.lean @@ -4,7 +4,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Python.PythonToBoogie +import Strata.Languages.Python.PythonToCore import Strata.Languages.Python.PythonDialect -import StrataTest.Internal.InternalBoogiePrelude +import StrataTest.Internal.InternalCorePrelude import StrataTest.Internal.InternalFunctionSignatures diff --git a/Strata/Languages/Python/PythonToBoogie.lean b/Strata/Languages/Python/PythonToCore.lean similarity index 73% rename from Strata/Languages/Python/PythonToBoogie.lean rename to Strata/Languages/Python/PythonToCore.lean index b8827277c..06dd2a1d7 100644 --- a/Strata/Languages/Python/PythonToBoogie.lean +++ b/Strata/Languages/Python/PythonToCore.lean @@ -7,12 +7,12 @@ import Strata.DDM.Elab import Strata.DDM.AST -import Strata.Languages.Boogie.DDMTransform.Parse +import Strata.Languages.Core.DDMTransform.Parse -import Strata.Languages.Boogie.Boogie +import Strata.Languages.Core.Core import Strata.Languages.Python.PythonDialect import Strata.Languages.Python.FunctionSignatures -import Strata.Languages.Python.Regex.ReToBoogie +import Strata.Languages.Python.Regex.ReToCore import Strata.Languages.Python.PyFactory import Strata.Languages.Python.FunctionSignatures @@ -20,36 +20,36 @@ namespace Strata open Lambda.LTy.Syntax -- Some hard-coded things we'll need to fix later: -def clientType : Boogie.Expression.Ty := .forAll [] (.tcons "Client" []) -def dummyClient : Boogie.Expression.Expr := .fvar () "DUMMY_CLIENT" none +def clientType : Core.Expression.Ty := .forAll [] (.tcons "Client" []) +def dummyClient : Core.Expression.Expr := .fvar () "DUMMY_CLIENT" none -def dictStrAnyType : Boogie.Expression.Ty := .forAll [] (.tcons "DictStrAny" []) -def dummyDictStrAny : Boogie.Expression.Expr := .fvar () "DUMMY_DICT_STR_ANY" none +def dictStrAnyType : Core.Expression.Ty := .forAll [] (.tcons "DictStrAny" []) +def dummyDictStrAny : Core.Expression.Expr := .fvar () "DUMMY_DICT_STR_ANY" none -def strType : Boogie.Expression.Ty := .forAll [] (.tcons "string" []) -def dummyStr : Boogie.Expression.Expr := .fvar () "DUMMY_STR" none +def strType : Core.Expression.Ty := .forAll [] (.tcons "string" []) +def dummyStr : Core.Expression.Expr := .fvar () "DUMMY_STR" none -def listStrType : Boogie.Expression.Ty := .forAll [] (.tcons "ListStr" []) -def dummyListStr : Boogie.Expression.Expr := .fvar () "DUMMY_LIST_STR" none +def listStrType : Core.Expression.Ty := .forAll [] (.tcons "ListStr" []) +def dummyListStr : Core.Expression.Expr := .fvar () "DUMMY_LIST_STR" none -def datetimeType : Boogie.Expression.Ty := .forAll [] (.tcons "Datetime" []) -def dummyDatetime : Boogie.Expression.Expr := .fvar () "DUMMY_DATETIME" none +def datetimeType : Core.Expression.Ty := .forAll [] (.tcons "Datetime" []) +def dummyDatetime : Core.Expression.Expr := .fvar () "DUMMY_DATETIME" none -def dateType : Boogie.Expression.Ty := .forAll [] (.tcons "Date" []) -def dummyDate : Boogie.Expression.Expr := .fvar () "DUMMY_DATE" none +def dateType : Core.Expression.Ty := .forAll [] (.tcons "Date" []) +def dummyDate : Core.Expression.Expr := .fvar () "DUMMY_DATE" none -def timedeltaType : Boogie.Expression.Ty := .forAll [] (.tcons "int" []) -def dummyTimedelta : Boogie.Expression.Expr := .fvar () "DUMMY_Timedelta" none +def timedeltaType : Core.Expression.Ty := .forAll [] (.tcons "int" []) +def dummyTimedelta : Core.Expression.Expr := .fvar () "DUMMY_Timedelta" none ------------------------------------------------------------------------------- --- Translating a Python expression can require Boogie statements, e.g., a function call +-- Translating a Python expression can require Strata Core statements, e.g., a function call -- We translate these by first defining temporary variables to store the results of the stmts -- and then using those variables in the expression. structure PyExprTranslated where - stmts : List Boogie.Statement - expr: Boogie.Expression.Expr - post_stmts : List Boogie.Statement := [] + stmts : List Core.Statement + expr: Core.Expression.Expr + post_stmts : List Core.Statement := [] deriving Inhabited structure PythonFunctionDecl where @@ -83,10 +83,10 @@ def unwrapModule (c : Python.Command SourceRange) : Array (Python.stmt SourceRan | Python.Command.Module _ body _ => body.val | _ => panic! "Expected module" -def strToBoogieExpr (s: String) : Boogie.Expression.Expr := +def strToCoreExpr (s: String) : Core.Expression.Expr := .strConst () s -def intToBoogieExpr (i: Int) : Boogie.Expression.Expr := +def intToCoreExpr (i: Int) : Core.Expression.Expr := .intConst () i def PyIntToInt (i : Python.int SourceRange) : Int := @@ -94,7 +94,7 @@ def PyIntToInt (i : Python.int SourceRange) : Int := | .IntPos _ n => n.val | .IntNeg _ n => -n.val -def PyConstToBoogie (c: Python.constant SourceRange) : Boogie.Expression.Expr := +def PyConstToCore (c: Python.constant SourceRange) : Core.Expression.Expr := match c with | .ConString _ s => .strConst () s.val | .ConPos _ i => .intConst () i.val @@ -103,27 +103,27 @@ def PyConstToBoogie (c: Python.constant SourceRange) : Boogie.Expression.Expr := | .ConFloat _ f => .strConst () (f.val) | _ => panic! s!"Unhandled Constant: {repr c}" -def PyAliasToBoogieExpr (a : Python.alias SourceRange) : Boogie.Expression.Expr := +def PyAliasToCoreExpr (a : Python.alias SourceRange) : Core.Expression.Expr := match a with | .mk_alias _ n as_n => assert! as_n.val.isNone .strConst () n.val -def handleAdd (lhs rhs: Boogie.Expression.Expr) : Boogie.Expression.Expr := +def handleAdd (lhs rhs: Core.Expression.Expr) : Core.Expression.Expr := let lty : Lambda.LMonoTy := mty[string] let rty : Lambda.LMonoTy := mty[string] match lty, rty with | (.tcons "string" []), (.tcons "string" []) => .app () (.app () (.op () "Str.Concat" mty[string → (string → string)]) lhs) rhs | _, _ => panic! s!"Unimplemented add op for {lhs} + {rhs}" -def handleSub (lhs rhs: Boogie.Expression.Expr) : Boogie.Expression.Expr := +def handleSub (lhs rhs: Core.Expression.Expr) : Core.Expression.Expr := let lty : Lambda.LMonoTy := (.tcons "Datetime" []) let rty : Lambda.LMonoTy := (.tcons "int" []) match lty, rty with | (.tcons "Datetime" []), (.tcons "int" []) => .app () (.app () (.op () "Datetime_sub" none) lhs) rhs | _, _ => panic! s!"Unimplemented add op for {lhs} + {rhs}" -def handleMult (translation_ctx: TranslationContext) (lhs rhs: Boogie.Expression.Expr) : Boogie.Expression.Expr := +def handleMult (translation_ctx: TranslationContext) (lhs rhs: Core.Expression.Expr) : Core.Expression.Expr := match lhs, rhs with | .strConst () s, .intConst () i => .strConst () (String.join (List.replicate i.toNat s)) | .intConst () l, .intConst () r => .intConst () (l * r) @@ -138,26 +138,26 @@ def handleMult (translation_ctx: TranslationContext) (lhs rhs: Boogie.Expression | _, _ => panic! s!"Missing needed type information for *. Exprs: {lhs} and {rhs}" | _ , _ => panic! s!"Unsupported args for * . Got: {lhs} and {rhs}" -def handleFloorDiv (_translation_ctx: TranslationContext) (lhs rhs: Boogie.Expression.Expr) : Boogie.Expression.Expr := +def handleFloorDiv (_translation_ctx: TranslationContext) (lhs rhs: Core.Expression.Expr) : Core.Expression.Expr := .app () (.app () (.op () "Int.Div" mty[int → (int → int)]) lhs) rhs -def handleNot (arg: Boogie.Expression.Expr) : Boogie.Expression.Expr := +def handleNot (arg: Core.Expression.Expr) : Core.Expression.Expr := let ty : Lambda.LMonoTy := (.tcons "ListStr" []) match ty with | (.tcons "ListStr" []) => .eq () arg (.op () "ListStr_nil" none) | _ => panic! s!"Unimplemented not op for {arg}" -def handleLtE (lhs rhs: Boogie.Expression.Expr) : Boogie.Expression.Expr := +def handleLtE (lhs rhs: Core.Expression.Expr) : Core.Expression.Expr := let eq := (.eq () lhs rhs) let lt := (.app () (.app () (.op () "Datetime_lt" none) lhs) rhs) (.app () (.app () (.op () "Bool.Or" none) eq) lt) -def handleGt (lhs rhs: Boogie.Expression.Expr) : Boogie.Expression.Expr := +def handleGt (lhs rhs: Core.Expression.Expr) : Core.Expression.Expr := (.app () (.app () (.op () "Float_gt" none) lhs) rhs) structure SubstitutionRecord where pyExpr : Python.expr SourceRange - boogieExpr : Boogie.Expression.Expr + coreExpr : Core.Expression.Expr instance : Repr (List SubstitutionRecord) where reprPrec xs _ := @@ -170,8 +170,8 @@ def PyExprIdent (e1 e2: Python.expr SourceRange) : Bool := | _ , _ => false -- TODO: handle rest of names -def PyListStrToBoogie (names : Array (Python.alias SourceRange)) : Boogie.Expression.Expr := - .app () (.app () (.op () "ListStr_cons" mty[string → (ListStr → ListStr)]) (PyAliasToBoogieExpr names[0]!)) +def PyListStrToCore (names : Array (Python.alias SourceRange)) : Core.Expression.Expr := + .app () (.app () (.op () "ListStr_cons" mty[string → (ListStr → ListStr)]) (PyAliasToCoreExpr names[0]!)) (.op () "ListStr_nil" mty[ListStr]) def handleList (_elmts: Array (Python.expr SourceRange)) (expected_type : Lambda.LMonoTy): PyExprTranslated := @@ -243,7 +243,7 @@ def callCanThrow (func_infos : List PythonFunctionDecl) (stmt: Python.stmt Sourc | _ => false | _ => false -def noneOrExpr (translation_ctx : TranslationContext) (fname n : String) (e: Boogie.Expression.Expr) : Boogie.Expression.Expr := +def noneOrExpr (translation_ctx : TranslationContext) (fname n : String) (e: Core.Expression.Expr) : Core.Expression.Expr := let type_str := translation_ctx.signatures.getFuncSigType fname n if type_str.endsWith "OrNone" then -- Optional param. Need to wrap e.g., string into StrOrNone @@ -255,7 +255,7 @@ def noneOrExpr (translation_ctx : TranslationContext) (fname n : String) (e: Boo else e -def handleCallThrow (jmp_target : String) : Boogie.Statement := +def handleCallThrow (jmp_target : String) : Core.Statement := let cond := .app () (.op () "ExceptOrNone..isExceptOrNone_mk_code" none) (.fvar () "maybe_except" none) .ite cond [.goto jmp_target] [] @@ -279,7 +279,7 @@ def deduplicateTypeAnnotations (l : List (String × Option String)) : List (Stri | .some ty => (n, ty) | .none => panic s!"Missing type annotations for {n}") -partial def collectVarDecls (translation_ctx : TranslationContext) (stmts: Array (Python.stmt SourceRange)) : List Boogie.Statement := +partial def collectVarDecls (translation_ctx : TranslationContext) (stmts: Array (Python.stmt SourceRange)) : List Core.Statement := let rec go (s : Python.stmt SourceRange) : List (String × Option String) := match s with | .Assign _ lhs _ _ => @@ -292,7 +292,7 @@ partial def collectVarDecls (translation_ctx : TranslationContext) (stmts: Array | _ => [] let dup := stmts.toList.flatMap go let dedup := deduplicateTypeAnnotations dup - let toBoogie (p: String × String) : List Boogie.Statement := + let toCore (p: String × String) : List Core.Statement := let name := p.fst let ty_name := p.snd match ty_name with @@ -315,7 +315,7 @@ partial def collectVarDecls (translation_ctx : TranslationContext) (stmts: Array let user_defined_class_dummy := .fvar () ("DUMMY_" ++ i.name) none [(.init name user_defined_class_ty user_defined_class_dummy), (.havoc name)] | .none => panic! s!"Unsupported type annotation: `{ty_name}`" - let foo := dedup.map toBoogie + let foo := dedup.map toCore foo.flatten def isCall (e: Python.expr SourceRange) : Bool := @@ -334,14 +334,14 @@ def remapFname (translation_ctx: TranslationContext) (fname: String) : String := mutual -partial def PyExprToBoogieWithSubst (translation_ctx : TranslationContext) (substitution_records : Option (List SubstitutionRecord)) (e : Python.expr SourceRange) : PyExprTranslated := - PyExprToBoogie translation_ctx e substitution_records +partial def PyExprToCoreWithSubst (translation_ctx : TranslationContext) (substitution_records : Option (List SubstitutionRecord)) (e : Python.expr SourceRange) : PyExprTranslated := + PyExprToCore translation_ctx e substitution_records -partial def PyKWordsToBoogie (substitution_records : Option (List SubstitutionRecord)) (kw : Python.keyword SourceRange) : (String × PyExprTranslated) := +partial def PyKWordsToCore (substitution_records : Option (List SubstitutionRecord)) (kw : Python.keyword SourceRange) : (String × PyExprTranslated) := match kw with | .mk_keyword _ name expr => match name.val with - | some n => (n.val, PyExprToBoogieWithSubst default substitution_records expr) + | some n => (n.val, PyExprToCoreWithSubst default substitution_records expr) | none => panic! "Keyword arg should have a name" -- TODO: we should be checking that args are right @@ -349,22 +349,22 @@ partial def argsAndKWordsToCanonicalList (translation_ctx : TranslationContext) (fname: String) (args : Array (Python.expr SourceRange)) (kwords: Array (Python.keyword SourceRange)) - (substitution_records : Option (List SubstitutionRecord) := none) : List Boogie.Expression.Expr × List Boogie.Statement := + (substitution_records : Option (List SubstitutionRecord) := none) : List Core.Expression.Expr × List Core.Statement := if translation_ctx.func_infos.any (λ e => e.name == fname) || translation_ctx.class_infos.any (λ e => e.name++"___init__" == fname) then if translation_ctx.func_infos.any (λ e => e.name == fname) then - (args.toList.map (λ a => (PyExprToBoogieWithSubst default substitution_records a).expr), []) + (args.toList.map (λ a => (PyExprToCoreWithSubst default substitution_records a).expr), []) else - (args.toList.map (λ a => (PyExprToBoogieWithSubst default substitution_records a).expr), []) + (args.toList.map (λ a => (PyExprToCoreWithSubst default substitution_records a).expr), []) else let required_order := translation_ctx.signatures.getFuncSigOrder fname assert! args.size <= required_order.length let remaining := required_order.drop args.size - let kws_and_exprs := kwords.toList.map (PyKWordsToBoogie substitution_records) + let kws_and_exprs := kwords.toList.map (PyKWordsToCore substitution_records) let ordered_remaining_args := remaining.map (λ n => match kws_and_exprs.find? (λ p => p.fst == n) with | .some p => noneOrExpr translation_ctx fname n p.snd.expr - | .none => Strata.Python.TypeStrToBoogieExpr (translation_ctx.signatures.getFuncSigType fname n)) - let args := args.map (PyExprToBoogieWithSubst default substitution_records) + | .none => Strata.Python.TypeStrToCoreExpr (translation_ctx.signatures.getFuncSigType fname n)) + let args := args.map (PyExprToCoreWithSubst default substitution_records) let args := (List.range required_order.length).filterMap (λ n => if n < args.size then let arg_name := required_order[n]! -- Guaranteed by range. Using finRange causes breaking coercions to Nat. @@ -386,7 +386,7 @@ partial def handleDict (keys: Array (Python.opt_expr SourceRange)) (values: Arra match f with | .Name _ {ann := _ , val := "str"} _ => assert! args.val.size == 1 - let dt := (.app () (.op () "datetime_to_str" none) ((PyExprToBoogie default args.val[0]!).expr)) + let dt := (.app () (.op () "datetime_to_str" none) ((PyExprToCore default args.val[0]!).expr)) let dict_of_v_is_k := (.assume s!"assume_{n}_key" (.eq () (.app () (.app () (.op () "dict_str_any_get_str" none) dict) (.strConst () n)) dt)) [in_dict, dict_of_v_is_k] | _ => panic! "Unsupported function when constructing map" @@ -396,16 +396,16 @@ partial def handleDict (keys: Array (Python.opt_expr SourceRange)) (values: Arra {stmts := res , expr := dict, post_stmts := []} -partial def PyExprToBoogie (translation_ctx : TranslationContext) (e : Python.expr SourceRange) (substitution_records : Option (List SubstitutionRecord) := none) : PyExprTranslated := +partial def PyExprToCore (translation_ctx : TranslationContext) (e : Python.expr SourceRange) (substitution_records : Option (List SubstitutionRecord) := none) : PyExprTranslated := if h : substitution_records.isSome && (substitution_records.get!.find? (λ r => PyExprIdent r.pyExpr e)).isSome then have hr : (List.find? (fun r => PyExprIdent r.pyExpr e) substitution_records.get!).isSome = true := by rw [Bool.and_eq_true] at h; exact h.2 let record := (substitution_records.get!.find? (λ r => PyExprIdent r.pyExpr e)).get hr - {stmts := [], expr := record.boogieExpr} + {stmts := [], expr := record.coreExpr} else match e with | .Call _ f args kwords => panic! s!"Call should be handled at stmt level: \n(func: {repr f}) \n(Records: {repr substitution_records}) \n(AST: {repr e.toAst})" - | .Constant _ c _ => {stmts := [], expr := PyConstToBoogie c} + | .Constant _ c _ => {stmts := [], expr := PyConstToCore c} | .Name _ n _ => match n.val with | "AssertionError" | "Exception" => {stmts := [], expr := .strConst () n.val} @@ -419,10 +419,10 @@ partial def PyExprToBoogie (translation_ctx : TranslationContext) (e : Python.ex else {stmts := [], expr := .fvar () n.val none} | .none => {stmts := [], expr := .fvar () n.val none} - | .JoinedStr _ ss => PyExprToBoogie translation_ctx ss.val[0]! -- TODO: need to actually join strings + | .JoinedStr _ ss => PyExprToCore translation_ctx ss.val[0]! -- TODO: need to actually join strings | .BinOp _ lhs op rhs => - let lhs := (PyExprToBoogie translation_ctx lhs) - let rhs := (PyExprToBoogie translation_ctx rhs) + let lhs := (PyExprToCore translation_ctx lhs) + let rhs := (PyExprToCore translation_ctx rhs) match op with | .Add _ => {stmts := lhs.stmts ++ rhs.stmts, expr := handleAdd lhs.expr rhs.expr} @@ -432,9 +432,9 @@ partial def PyExprToBoogie (translation_ctx : TranslationContext) (e : Python.ex {stmts := lhs.stmts ++ rhs.stmts, expr := handleMult translation_ctx lhs.expr rhs.expr} | _ => panic! s!"Unhandled BinOp: {repr e}" | .Compare _ lhs op rhs => - let lhs := PyExprToBoogie translation_ctx lhs + let lhs := PyExprToCore translation_ctx lhs assert! rhs.val.size == 1 - let rhs := PyExprToBoogie translation_ctx rhs.val[0]! + let rhs := PyExprToCore translation_ctx rhs.val[0]! match op.val with | #[v] => match v with | Strata.Python.cmpop.Eq _ => @@ -452,26 +452,26 @@ partial def PyExprToBoogie (translation_ctx : TranslationContext) (e : Python.ex res | .ListComp _ keys values => panic! "ListComp must be handled at stmt level" | .UnaryOp _ op arg => match op with - | .Not _ => {stmts := [], expr := handleNot (PyExprToBoogie translation_ctx arg).expr} + | .Not _ => {stmts := [], expr := handleNot (PyExprToCore translation_ctx arg).expr} | _ => panic! "Unsupported UnaryOp: {repr e}" | .Subscript _ v slice _ => - let l := PyExprToBoogie translation_ctx v - let k := PyExprToBoogie translation_ctx slice + let l := PyExprToCore translation_ctx v + let k := PyExprToCore translation_ctx slice -- TODO: we need to plumb the type of `v` here match s!"{repr l.expr}" with - | "LExpr.fvar () { name := \"keys\", metadata := Boogie.Visibility.unres } none" => - -- let access_check : Boogie.Statement := .assert "subscript_bounds_check" (.app () (.app () (.op () "str_in_dict_str_any" none) k.expr) l.expr) + | "LExpr.fvar () { name := \"keys\", metadata := Core.Visibility.unres } none" => + -- let access_check : Core.Statement := .assert "subscript_bounds_check" (.app () (.app () (.op () "str_in_dict_str_any" none) k.expr) l.expr) {stmts := l.stmts ++ k.stmts, expr := .app () (.app () (.op () "list_str_get" none) l.expr) k.expr} - | "LExpr.fvar () { name := \"blended_cost\", metadata := Boogie.Visibility.unres } none" => - -- let access_check : Boogie.Statement := .assert "subscript_bounds_check" (.app () (.app () (.op () "str_in_dict_str_any" none) k.expr) l.expr) + | "LExpr.fvar () { name := \"blended_cost\", metadata := Core.Visibility.unres } none" => + -- let access_check : Core.Statement := .assert "subscript_bounds_check" (.app () (.app () (.op () "str_in_dict_str_any" none) k.expr) l.expr) {stmts := l.stmts ++ k.stmts, expr := .app () (.app () (.op () "dict_str_any_get_str" none) l.expr) k.expr} | _ => match translation_ctx.expectedType with | .some (.tcons "ListStr" []) => - let access_check : Boogie.Statement := .assert "subscript_bounds_check" (.app () (.app () (.op () "str_in_dict_str_any" none) k.expr) l.expr) + let access_check : Core.Statement := .assert "subscript_bounds_check" (.app () (.app () (.op () "str_in_dict_str_any" none) k.expr) l.expr) {stmts := l.stmts ++ k.stmts ++ [access_check], expr := .app () (.app () (.op () "dict_str_any_get_list_str" none) l.expr) k.expr} | _ => - let access_check : Boogie.Statement := .assert "subscript_bounds_check" (.app () (.app () (.op () "str_in_dict_str_any" none) k.expr) l.expr) + let access_check : Core.Statement := .assert "subscript_bounds_check" (.app () (.app () (.op () "str_in_dict_str_any" none) k.expr) l.expr) {stmts := l.stmts ++ k.stmts ++ [access_check], expr := .app () (.app () (.op () "dict_str_any_get" none) l.expr) k.expr} | .List _ elmts _ => match elmts.val[0]! with @@ -482,52 +482,52 @@ partial def PyExprToBoogie (translation_ctx : TranslationContext) (e : Python.ex | _ => panic! s!"Unexpected element: {repr elmts.val[0]!}" | _ => panic! s!"Unhandled Expr: {repr e}" -partial def initTmpParam (p: Python.expr SourceRange × String) : List Boogie.Statement := +partial def initTmpParam (p: Python.expr SourceRange × String) : List Core.Statement := match p.fst with | .Call _ f args _ => match f with | .Name _ n _ => match n.val with - | "json_dumps" => [(.init p.snd t[string] (.strConst () "")), .call [p.snd, "maybe_except"] "json_dumps" [(.app () (.op () "DictStrAny_mk" none) (.strConst () "DefaultDict")), (Strata.Python.TypeStrToBoogieExpr "IntOrNone")]] + | "json_dumps" => [(.init p.snd t[string] (.strConst () "")), .call [p.snd, "maybe_except"] "json_dumps" [(.app () (.op () "DictStrAny_mk" none) (.strConst () "DefaultDict")), (Strata.Python.TypeStrToCoreExpr "IntOrNone")]] | "str" => assert! args.val.size == 1 - [(.init p.snd t[string] (.strConst () "")), .set p.snd (.app () (.op () "datetime_to_str" none) ((PyExprToBoogie default args.val[0]!).expr))] + [(.init p.snd t[string] (.strConst () "")), .set p.snd (.app () (.op () "datetime_to_str" none) ((PyExprToCore default args.val[0]!).expr))] | "int" => [(.init p.snd t[int] (.intConst () 0)), .set p.snd (.op () "datetime_to_int" none)] | _ => panic! s!"Unsupported name {n.val}" | _ => panic! s!"Unsupported tmp param init call: {repr f}" | _ => panic! "Expected Call" -partial def exceptHandlersToBoogie (jmp_targets: List String) (translation_ctx: TranslationContext) (h : Python.excepthandler SourceRange) : List Boogie.Statement := +partial def exceptHandlersToCore (jmp_targets: List String) (translation_ctx: TranslationContext) (h : Python.excepthandler SourceRange) : List Core.Statement := assert! jmp_targets.length >= 2 match h with | .ExceptHandler _ ex_ty _ body => let set_ex_ty_matches := match ex_ty.val with | .some ex_ty => - let inherits_from : Boogie.BoogieIdent := "inheritsFrom" - let get_ex_tag : Boogie.BoogieIdent := "ExceptOrNone_code_val" - let exception_ty : Boogie.Expression.Expr := .app () (.op () get_ex_tag none) (.fvar () "maybe_except" none) - let rhs_curried : Boogie.Expression.Expr := .app () (.op () inherits_from none) exception_ty - let res := PyExprToBoogie translation_ctx ex_ty - let rhs : Boogie.Expression.Expr := .app () rhs_curried (res.expr) + let inherits_from : Core.CoreIdent := "inheritsFrom" + let get_ex_tag : Core.CoreIdent := "ExceptOrNone_code_val" + let exception_ty : Core.Expression.Expr := .app () (.op () get_ex_tag none) (.fvar () "maybe_except" none) + let rhs_curried : Core.Expression.Expr := .app () (.op () inherits_from none) exception_ty + let res := PyExprToCore translation_ctx ex_ty + let rhs : Core.Expression.Expr := .app () rhs_curried (res.expr) let call := .set "exception_ty_matches" rhs res.stmts ++ [call] | .none => [.set "exception_ty_matches" (.boolConst () false)] let cond := .fvar () "exception_ty_matches" none - let body_if_matches := body.val.toList.flatMap (λ s => (PyStmtToBoogie jmp_targets translation_ctx s).fst) ++ [.goto jmp_targets[1]!] + let body_if_matches := body.val.toList.flatMap (λ s => (PyStmtToCore jmp_targets translation_ctx s).fst) ++ [.goto jmp_targets[1]!] set_ex_ty_matches ++ [.ite cond body_if_matches []] -partial def handleFunctionCall (lhs: List Boogie.Expression.Ident) +partial def handleFunctionCall (lhs: List Core.Expression.Ident) (fname: String) (args: Ann (Array (Python.expr SourceRange)) SourceRange) (kwords: Ann (Array (Python.keyword SourceRange)) SourceRange) (_jmp_targets: List String) (translation_ctx: TranslationContext) - (_s : Python.stmt SourceRange) : List Boogie.Statement := + (_s : Python.stmt SourceRange) : List Core.Statement := let fname := remapFname translation_ctx fname - -- Boogie doesn't allow nested function calls, so we need to introduce temporary variables for each nested call + -- Strata Core doesn't allow nested function calls, so we need to introduce temporary variables for each nested call let nested_args_calls := args.val.filterMap (λ a => if isCall a then some a else none) let args_calls_to_tmps := nested_args_calls.map (λ a => (a, s!"call_arg_tmp_{a.toAst.ann.start}")) let nested_kwords_calls := kwords.val.filterMap (λ a => @@ -536,36 +536,36 @@ partial def handleFunctionCall (lhs: List Boogie.Expression.Ident) if isCall arg then some arg else none) let kwords_calls_to_tmps := nested_kwords_calls.map (λ a => (a, s!"call_kword_tmp_{a.toAst.ann.start}")) - let substitution_records : List SubstitutionRecord := args_calls_to_tmps.toList.map (λ p => {pyExpr := p.fst, boogieExpr := .fvar () p.snd none}) ++ - kwords_calls_to_tmps.toList.map (λ p => {pyExpr := p.fst, boogieExpr := .fvar () p.snd none}) + let substitution_records : List SubstitutionRecord := args_calls_to_tmps.toList.map (λ p => {pyExpr := p.fst, coreExpr := .fvar () p.snd none}) ++ + kwords_calls_to_tmps.toList.map (λ p => {pyExpr := p.fst, coreExpr := .fvar () p.snd none}) let res := argsAndKWordsToCanonicalList translation_ctx fname args.val kwords.val substitution_records args_calls_to_tmps.toList.flatMap initTmpParam ++ kwords_calls_to_tmps.toList.flatMap initTmpParam ++ res.snd ++ [.call lhs fname res.fst] -partial def handleComprehension (lhs: Python.expr SourceRange) (gen: Array (Python.comprehension SourceRange)) : List Boogie.Statement := +partial def handleComprehension (lhs: Python.expr SourceRange) (gen: Array (Python.comprehension SourceRange)) : List Core.Statement := assert! gen.size == 1 match gen[0]! with | .mk_comprehension _ _ itr _ _ => - let res := PyExprToBoogie default itr + let res := PyExprToCore default itr let guard := .app () (.op () "Bool.Not" none) (.eq () (.app () (.op () "dict_str_any_length" none) res.expr) (.intConst () 0)) - let then_ss: List Boogie.Statement := [.havoc (PyExprToString lhs)] - let else_ss: List Boogie.Statement := [.set (PyExprToString lhs) (.op () "ListStr_nil" none)] + let then_ss: List Core.Statement := [.havoc (PyExprToString lhs)] + let else_ss: List Core.Statement := [.set (PyExprToString lhs) (.op () "ListStr_nil" none)] res.stmts ++ [.ite guard then_ss else_ss] -partial def PyStmtToBoogie (jmp_targets: List String) (translation_ctx : TranslationContext) (s : Python.stmt SourceRange) : List Boogie.Statement × TranslationContext := +partial def PyStmtToCore (jmp_targets: List String) (translation_ctx : TranslationContext) (s : Python.stmt SourceRange) : List Core.Statement × TranslationContext := assert! jmp_targets.length > 0 - let non_throw : List Boogie.Statement × Option (String × Lambda.LMonoTy) := match s with + let non_throw : List Core.Statement × Option (String × Lambda.LMonoTy) := match s with | .Import _ names => - ([.call [] "import" [PyListStrToBoogie names.val]], none) + ([.call [] "import" [PyListStrToCore names.val]], none) | .ImportFrom _ s names i => let n := match s.val with - | some s => [strToBoogieExpr s.val] + | some s => [strToCoreExpr s.val] | none => [] let i := match i.val with - | some i => [intToBoogieExpr (PyIntToInt i)] + | some i => [intToCoreExpr (PyIntToInt i)] | none => [] - ([.call [] "importFrom" (n ++ [PyListStrToBoogie names.val] ++ i)], none) + ([.call [] "importFrom" (n ++ [PyListStrToCore names.val] ++ i)], none) | .Expr _ (.Call _ func args kwords) => let fname := PyExprToString func if callCanThrow translation_ctx.func_infos s then @@ -583,7 +583,7 @@ partial def PyStmtToBoogie (jmp_targets: List String) (translation_ctx : Transla (handleFunctionCall [PyExprToString lhs.val[0]!, "maybe_except"] fname args kwords jmp_targets translation_ctx s, none) | .Assign _ lhs rhs _ => assert! lhs.val.size == 1 - let res := PyExprToBoogie translation_ctx rhs + let res := PyExprToCore translation_ctx rhs (res.stmts ++ [.set (PyExprToString lhs.val[0]!) res.expr], none) | .AnnAssign _ lhs ty { ann := _ , val := (.some (.Call _ func args kwords))} _ => let fname := PyExprToString func @@ -591,54 +591,54 @@ partial def PyStmtToBoogie (jmp_targets: List String) (translation_ctx : Transla | .AnnAssign _ lhs ty { ann := _ , val := (.some (.ListComp _ _ gen))} _ => (handleComprehension lhs gen.val, some (PyExprToString lhs, PyExprToMonoTy ty)) | .AnnAssign _ lhs ty {ann := _, val := (.some e)} _ => - let res := (PyExprToBoogie {translation_ctx with expectedType := PyExprToMonoTy ty} e) + let res := (PyExprToCore {translation_ctx with expectedType := PyExprToMonoTy ty} e) (res.stmts ++ [.set (PyExprToString lhs) res.expr], some (PyExprToString lhs, PyExprToMonoTy ty)) | .Try _ body handlers _orelse _finalbody => let new_target := s!"excepthandlers_{jmp_targets[0]!}" let entry_except_handlers := [.block new_target []] let new_jmp_stack := new_target :: jmp_targets - let except_handlers := handlers.val.toList.flatMap (exceptHandlersToBoogie new_jmp_stack translation_ctx) + let except_handlers := handlers.val.toList.flatMap (exceptHandlersToCore new_jmp_stack translation_ctx) let var_decls := collectVarDecls translation_ctx body.val - ([.block "try_block" (var_decls ++ body.val.toList.flatMap (λ s => (PyStmtToBoogie new_jmp_stack translation_ctx s).fst) ++ entry_except_handlers ++ except_handlers)], none) - | .FunctionDef _ _ _ _ _ _ _ _ => panic! "Can't translate FunctionDef to Boogie statement" + ([.block "try_block" (var_decls ++ body.val.toList.flatMap (λ s => (PyStmtToCore new_jmp_stack translation_ctx s).fst) ++ entry_except_handlers ++ except_handlers)], none) + | .FunctionDef _ _ _ _ _ _ _ _ => panic! "Can't translate FunctionDef to Strata Core statement" | .If _ test then_b else_b => let guard_ctx := {translation_ctx with expectedType := some (.tcons "bool" [])} - ([.ite (PyExprToBoogie guard_ctx test).expr (ArrPyStmtToBoogie translation_ctx then_b.val).fst (ArrPyStmtToBoogie translation_ctx else_b.val).fst], none) + ([.ite (PyExprToCore guard_ctx test).expr (ArrPyStmtToCore translation_ctx then_b.val).fst (ArrPyStmtToCore translation_ctx else_b.val).fst], none) | .Return _ v => match v.val with - | .some v => ([.set "ret" (PyExprToBoogie translation_ctx v).expr, .goto jmp_targets[0]!], none) -- TODO: need to thread return value name here. For now, assume "ret" + | .some v => ([.set "ret" (PyExprToCore translation_ctx v).expr, .goto jmp_targets[0]!], none) -- TODO: need to thread return value name here. For now, assume "ret" | .none => ([.goto jmp_targets[0]!], none) | .For _ tgt itr body _ _ => -- Do one unrolling: - let guard := .app () (.op () "Bool.Not" none) (.eq () (.app () (.op () "dict_str_any_length" none) (PyExprToBoogie default itr).expr) (.intConst () 0)) + let guard := .app () (.op () "Bool.Not" none) (.eq () (.app () (.op () "dict_str_any_length" none) (PyExprToCore default itr).expr) (.intConst () 0)) match tgt with | .Name _ n _ => let assign_tgt := [(.init n.val dictStrAnyType dummyDictStrAny)] - ([.ite guard (assign_tgt ++ (ArrPyStmtToBoogie translation_ctx body.val).fst) []], none) + ([.ite guard (assign_tgt ++ (ArrPyStmtToCore translation_ctx body.val).fst) []], none) | _ => panic! s!"tgt must be single name: {repr tgt}" -- TODO: missing havoc | .While _ test body _ => -- Do one unrolling: - let guard := .app () (.op () "Bool.Not" none) (.eq () (.app () (.op () "dict_str_any_length" none) (PyExprToBoogie default test).expr) (.intConst () 0)) - ([.ite guard (ArrPyStmtToBoogie translation_ctx body.val).fst []], none) + let guard := .app () (.op () "Bool.Not" none) (.eq () (.app () (.op () "dict_str_any_length" none) (PyExprToCore default test).expr) (.intConst () 0)) + ([.ite guard (ArrPyStmtToCore translation_ctx body.val).fst []], none) -- TODO: missing havoc | .Assert _ a _ => - let res := PyExprToBoogie translation_ctx a + let res := PyExprToCore translation_ctx a ([(.assert "py_assertion" res.expr)], none) | .AugAssign _ lhs op rhs => match op with | .Add _ => match lhs with | .Name _ n _ => - let rhs := PyExprToBoogie translation_ctx rhs + let rhs := PyExprToCore translation_ctx rhs let new_lhs := (.strConst () "DUMMY_FLOAT") (rhs.stmts ++ [.set n.val new_lhs], none) | _ => panic! s!"Expected lhs to be name: {repr lhs}" | .FloorDiv _ => match lhs with | .Name _ n _ => - let lhs := PyExprToBoogie translation_ctx lhs - let rhs := PyExprToBoogie translation_ctx rhs + let lhs := PyExprToCore translation_ctx lhs + let rhs := PyExprToCore translation_ctx rhs let new_lhs := .app () (.app () (.op () "Int.Div" mty[int → (int → int)]) lhs.expr) rhs.expr (rhs.stmts ++ [.set n.val new_lhs], none) | _ => panic! s!"Expected lhs to be name: {repr lhs}" @@ -653,28 +653,28 @@ partial def PyStmtToBoogie (jmp_targets: List String) (translation_ctx : Transla else (non_throw.fst, new_translation_ctx) -partial def ArrPyStmtToBoogie (translation_ctx: TranslationContext) (a : Array (Python.stmt SourceRange)) : (List Boogie.Statement × TranslationContext) := +partial def ArrPyStmtToCore (translation_ctx: TranslationContext) (a : Array (Python.stmt SourceRange)) : (List Core.Statement × TranslationContext) := a.foldl (fun (stmts, ctx) stmt => - let (newStmts, newCtx) := PyStmtToBoogie ["end"] ctx stmt + let (newStmts, newCtx) := PyStmtToCore ["end"] ctx stmt (stmts ++ newStmts, newCtx) ) ([], translation_ctx) end --mutual -def translateFunctions (a : Array (Python.stmt SourceRange)) (translation_ctx: TranslationContext) : List Boogie.Decl := +def translateFunctions (a : Array (Python.stmt SourceRange)) (translation_ctx: TranslationContext) : List Core.Decl := a.toList.filterMap (λ s => match s with | .FunctionDef _ name _args body _ _ret _ _ => - let varDecls : List Boogie.Statement := [] - let proc : Boogie.Procedure := { + let varDecls : List Core.Statement := [] + let proc : Core.Procedure := { header := { name := name.val, typeArgs := [], inputs := [], outputs := [("maybe_except", (.tcons "ExceptOrNone" []))]}, spec := default, - body := varDecls ++ (ArrPyStmtToBoogie translation_ctx body.val).fst ++ [.block "end" []] + body := varDecls ++ (ArrPyStmtToCore translation_ctx body.val).fst ++ [.block "end" []] } some (.proc proc) | _ => none) @@ -686,10 +686,10 @@ def pyTyStrToLMonoTy (ty_str: String) : Lambda.LMonoTy := | "datetime" => (.tcons "Datetime" []) | _ => panic! s!"Unsupported type: {ty_str}" -def pythonFuncToBoogie (name : String) (args: List (String × String)) (body: Array (Python.stmt SourceRange)) (ret : Option (Python.expr SourceRange)) (spec : Boogie.Procedure.Spec) (translation_ctx : TranslationContext) : Boogie.Procedure := - let inputs : List (Lambda.Identifier Boogie.Visibility × Lambda.LMonoTy) := args.map (λ p => (p.fst, pyTyStrToLMonoTy p.snd)) +def pythonFuncToCore (name : String) (args: List (String × String)) (body: Array (Python.stmt SourceRange)) (ret : Option (Python.expr SourceRange)) (spec : Core.Procedure.Spec) (translation_ctx : TranslationContext) : Core.Procedure := + let inputs : List (Lambda.Identifier Core.Visibility × Lambda.LMonoTy) := args.map (λ p => (p.fst, pyTyStrToLMonoTy p.snd)) let varDecls := collectVarDecls translation_ctx body ++ [(.init "exception_ty_matches" t[bool] (.boolConst () false)), (.havoc "exception_ty_matches")] - let stmts := (ArrPyStmtToBoogie translation_ctx body).fst + let stmts := (ArrPyStmtToCore translation_ctx body).fst let body := varDecls ++ stmts ++ [.block "end" []] let constructor := name.endsWith "___init__" let outputs : Lambda.LMonoTySignature := if not constructor then @@ -725,14 +725,14 @@ def unpackPyArguments (args: Python.arguments SourceRange) : List (String × Str | .some ty => some (name.val, PyExprToString ty) | _ => panic! s!"Missing type annotation on arg: {repr a} ({repr args})") -def PyFuncDefToBoogie (s: Python.stmt SourceRange) (translation_ctx: TranslationContext) : List Boogie.Decl × PythonFunctionDecl := +def PyFuncDefToCore (s: Python.stmt SourceRange) (translation_ctx: TranslationContext) : List Core.Decl × PythonFunctionDecl := match s with | .FunctionDef _ name args body _ ret _ _ => let args := unpackPyArguments args - ([.proc (pythonFuncToBoogie name.val args body.val ret.val default translation_ctx)], {name := name.val, args, ret := s!"{repr ret}"}) + ([.proc (pythonFuncToCore name.val args body.val ret.val default translation_ctx)], {name := name.val, args, ret := s!"{repr ret}"}) | _ => panic! s!"Expected function def: {repr s}" -def PyClassDefToBoogie (s: Python.stmt SourceRange) (translation_ctx: TranslationContext) : List Boogie.Decl × PythonClassDecl := +def PyClassDefToCore (s: Python.stmt SourceRange) (translation_ctx: TranslationContext) : List Core.Decl × PythonClassDecl := match s with | .ClassDef _ c_name _ _ body _ _ => let member_fn_defs := body.val.toList.filterMap (λ s => match s with @@ -743,10 +743,10 @@ def PyClassDefToBoogie (s: Python.stmt SourceRange) (translation_ctx: Translatio let args := unpackPyArguments f.snd.fst let body := f.snd.snd.fst.val let ret := f.snd.snd.snd.val - .proc (pythonFuncToBoogie (c_name.val++"_"++name) args body ret default translation_ctx)), {name := c_name.val}) + .proc (pythonFuncToCore (c_name.val++"_"++name) args body ret default translation_ctx)), {name := c_name.val}) | _ => panic! s!"Expected function def: {repr s}" -def pythonToBoogie (signatures : Python.Signatures) (pgm: Strata.Program): Boogie.Program := +def pythonToCore (signatures : Python.Signatures) (pgm: Strata.Program): Core.Program := let pyCmds := toPyCommands pgm.commands assert! pyCmds.size == 1 let insideMod := unwrapModule pyCmds[0]! @@ -765,10 +765,10 @@ def pythonToBoogie (signatures : Python.Signatures) (pgm: Strata.Program): Boogi let globals := [(.var "__name__" (.forAll [] mty[string]) (.strConst () "__main__"))] - let rec helper {α : Type} (f : Python.stmt SourceRange → TranslationContext → List Boogie.Decl × α) + let rec helper {α : Type} (f : Python.stmt SourceRange → TranslationContext → List Core.Decl × α) (update : TranslationContext → α → TranslationContext) (acc : TranslationContext) : - List (Python.stmt SourceRange) → List Boogie.Decl × TranslationContext + List (Python.stmt SourceRange) → List Core.Decl × TranslationContext | [] => ([], acc) | x :: xs => let (y, info) := f x acc @@ -777,15 +777,15 @@ def pythonToBoogie (signatures : Python.Signatures) (pgm: Strata.Program): Boogi (y ++ ys, acc'') let func_info : TranslationContext := { signatures } - let func_defs_and_infos := helper PyFuncDefToBoogie (fun acc info => {acc with func_infos := info :: acc.func_infos}) func_info func_defs.toList + let func_defs_and_infos := helper PyFuncDefToCore (fun acc info => {acc with func_infos := info :: acc.func_infos}) func_info func_defs.toList let func_defs := func_defs_and_infos.fst let func_infos := func_defs_and_infos.snd - let class_defs_and_infos := helper PyClassDefToBoogie (fun acc info => {acc with class_infos := info :: acc.class_infos}) func_infos class_defs.toList + let class_defs_and_infos := helper PyClassDefToCore (fun acc info => {acc with class_infos := info :: acc.class_infos}) func_infos class_defs.toList let class_defs := class_defs_and_infos.fst let class_infos := class_defs_and_infos.snd let class_ty_decls := [(.type (.con {name := "LatencyAnalyzer", numargs := 0})) ] - {decls := globals ++ class_ty_decls ++ func_defs ++ class_defs ++ [.proc (pythonFuncToBoogie "__main__" [] non_func_blocks none default class_infos)]} + {decls := globals ++ class_ty_decls ++ func_defs ++ class_defs ++ [.proc (pythonFuncToCore "__main__" [] non_func_blocks none default class_infos)]} end Strata diff --git a/Strata/Languages/Python/Regex/ReToBoogie.lean b/Strata/Languages/Python/Regex/ReToCore.lean similarity index 72% rename from Strata/Languages/Python/Regex/ReToBoogie.lean rename to Strata/Languages/Python/Regex/ReToCore.lean index 4ea29793f..79c209fba 100644 --- a/Strata/Languages/Python/Regex/ReToBoogie.lean +++ b/Strata/Languages/Python/Regex/ReToCore.lean @@ -5,7 +5,7 @@ -/ import Strata.Languages.Python.Regex.ReParser -import Strata.Languages.Boogie.Factory +import Strata.Languages.Core.Factory namespace Strata namespace Python @@ -13,7 +13,7 @@ namespace Python ------------------------------------------------------------------------------- open Lambda.LExpr -open Boogie +open Core /-- Python regexes can be interpreted differently based on the matching mode. @@ -66,17 +66,17 @@ def RegexAST.alwaysConsume (r : RegexAST) : Bool := /-- Empty regex pattern; matches an empty string. -/ -def Boogie.emptyRegex : Boogie.Expression.Expr := +def Core.emptyRegex : Core.Expression.Expr := mkApp () (.op () strToRegexFunc.name none) [strConst () ""] /-- Unmatchable regex pattern. -/ -def Boogie.unmatchableRegex : Boogie.Expression.Expr := +def Core.unmatchableRegex : Core.Expression.Expr := mkApp () (.op () reNoneFunc.name none) [] -partial def RegexAST.toBoogie (r : RegexAST) (atStart atEnd : Bool) : - Boogie.Expression.Expr := +partial def RegexAST.toCore (r : RegexAST) (atStart atEnd : Bool) : + Core.Expression.Expr := match r with | .char c => (mkApp () (.op () strToRegexFunc.name none) [strConst () (toString c)]) @@ -84,79 +84,79 @@ partial def RegexAST.toBoogie (r : RegexAST) (atStart atEnd : Bool) : mkApp () (.op () reRangeFunc.name none) [strConst () (toString c1), strConst () (toString c2)] | .anychar => mkApp () (.op () reAllCharFunc.name none) [] - | .empty => Boogie.emptyRegex + | .empty => Core.emptyRegex | .complement r => - let rb := toBoogie r atStart atEnd + let rb := toCore r atStart atEnd mkApp () (.op () reCompFunc.name none) [rb] | .anchor_start => - if atStart then Boogie.emptyRegex else Boogie.unmatchableRegex + if atStart then Core.emptyRegex else Core.unmatchableRegex | .anchor_end => - if atEnd then Boogie.emptyRegex else Boogie.unmatchableRegex + if atEnd then Core.emptyRegex else Core.unmatchableRegex | .plus r1 => - toBoogie (.concat r1 (.star r1)) atStart atEnd + toCore (.concat r1 (.star r1)) atStart atEnd | .star r1 => - let r1b := toBoogie r1 atStart atEnd + let r1b := toCore r1 atStart atEnd let r2b := match (alwaysConsume r1) with | true => - let r1b := toBoogie r1 atStart false -- r1 at the beginning - let r2b := toBoogie r1 false false -- r1s in the middle - let r3b := toBoogie r1 false atEnd -- r1 at the end + let r1b := toCore r1 atStart false -- r1 at the beginning + let r2b := toCore r1 false false -- r1s in the middle + let r3b := toCore r1 false atEnd -- r1 at the end let r2b := mkApp () (.op () reStarFunc.name none) [r2b] mkApp () (.op () reConcatFunc.name none) [mkApp () (.op () reConcatFunc.name none) [r1b, r2b], r3b] | false => mkApp () (.op () reStarFunc.name none) [r1b] mkApp () (.op () reUnionFunc.name none) - [mkApp () (.op () reUnionFunc.name none) [Boogie.emptyRegex, r1b], r2b] + [mkApp () (.op () reUnionFunc.name none) [Core.emptyRegex, r1b], r2b] | .optional r1 => - toBoogie (.union .empty r1) atStart atEnd + toCore (.union .empty r1) atStart atEnd | .loop r1 n m => match n, m with - | 0, 0 => Boogie.emptyRegex - | 0, 1 => toBoogie (.union .empty r1) atStart atEnd + | 0, 0 => Core.emptyRegex + | 0, 1 => toCore (.union .empty r1) atStart atEnd | 0, m => -- Note: m >= 2 - let r1b := toBoogie r1 atStart atEnd + let r1b := toCore r1 atStart atEnd let r2b := match (alwaysConsume r1) with | true => - let r1b := toBoogie r1 atStart false -- r1 at the beginning - let r2b := toBoogie r1 false false -- r1s in the middle - let r3b := toBoogie r1 false atEnd -- r1 at the end + let r1b := toCore r1 atStart false -- r1 at the beginning + let r2b := toCore r1 false false -- r1s in the middle + let r3b := toCore r1 false atEnd -- r1 at the end let r2b := mkApp () (.op () reLoopFunc.name none) [r2b, intConst () 0, intConst () (m-2)] mkApp () (.op () reConcatFunc.name none) [mkApp () (.op () reConcatFunc.name none) [r1b, r2b], r3b] | false => mkApp () (.op () reLoopFunc.name none) [r1b, intConst () 0, intConst () m] mkApp () (.op () reUnionFunc.name none) - [mkApp () (.op () reUnionFunc.name none) [Boogie.emptyRegex, r1b], + [mkApp () (.op () reUnionFunc.name none) [Core.emptyRegex, r1b], r2b] | _, _ => - toBoogie (.concat r1 (.loop r1 (n - 1) (m - 1))) atStart atEnd - | .group r1 => toBoogie r1 atStart atEnd + toCore (.concat r1 (.loop r1 (n - 1) (m - 1))) atStart atEnd + | .group r1 => toCore r1 atStart atEnd | .concat r1 r2 => match (alwaysConsume r1), (alwaysConsume r2) with | true, true => - let r1b := toBoogie r1 atStart false - let r2b := toBoogie r2 false atEnd + let r1b := toCore r1 atStart false + let r2b := toCore r2 false atEnd mkApp () (.op () reConcatFunc.name none) [r1b, r2b] | true, false => - let r1b := toBoogie r1 atStart atEnd - let r2b := toBoogie r2 false atEnd + let r1b := toCore r1 atStart atEnd + let r2b := toCore r2 false atEnd mkApp () (.op () reConcatFunc.name none) [r1b, r2b] | false, true => - let r1b := toBoogie r1 atStart false - let r2b := toBoogie r2 true atEnd + let r1b := toCore r1 atStart false + let r2b := toCore r2 true atEnd mkApp () (.op () reConcatFunc.name none) [r1b, r2b] | false, false => - let r1b := toBoogie r1 atStart atEnd - let r2b := toBoogie r2 atStart atEnd + let r1b := toCore r1 atStart atEnd + let r2b := toCore r2 atStart atEnd mkApp () (.op () reConcatFunc.name none) [r1b, r2b] | .union r1 r2 => - let r1b := toBoogie r1 atStart atEnd - let r2b := toBoogie r2 atStart atEnd + let r1b := toCore r1 atStart atEnd + let r2b := toCore r2 atStart atEnd mkApp () (.op () reUnionFunc.name none) [r1b, r2b] -def pythonRegexToBoogie (pyRegex : String) (mode : MatchMode := .fullmatch) : - Boogie.Expression.Expr × Option ParseError := +def pythonRegexToCore (pyRegex : String) (mode : MatchMode := .fullmatch) : + Core.Expression.Expr × Option ParseError := match parseTop pyRegex with | .error err => (mkApp () (.op () reAllFunc.name none) [], some err) | .ok ast => @@ -166,7 +166,7 @@ def pythonRegexToBoogie (pyRegex : String) (mode : MatchMode := .fullmatch) : | .fullmatch => ast | .match => .concat ast dotStar | .search => .concat dotStar (.concat ast dotStar) - let result := RegexAST.toBoogie ast true true + let result := RegexAST.toCore ast true true (result, none) /-- @@ -174,208 +174,208 @@ info: (((~Re.Concat ((~Re.Concat (~Str.ToRegEx #a)) (~Str.ToRegEx #b))) ((~Re.Un none) -/ #guard_msgs in -#eval Std.format$ pythonRegexToBoogie "ab.*" -- Encoded as `ab(|.|..*.)` +#eval Std.format$ pythonRegexToCore "ab.*" -- Encoded as `ab(|.|..*.)` /-- info: (((~Re.Concat ((~Re.Concat (~Str.ToRegEx #a)) (~Str.ToRegEx #b))) ((~Re.Union ((~Re.Union (~Str.ToRegEx #)) ((~Re.Concat (~Str.ToRegEx #c)) (~Str.ToRegEx #)))) ((~Re.Concat ((~Re.Concat ((~Re.Concat (~Str.ToRegEx #c)) ~Re.None)) (~Re.Star ((~Re.Concat (~Str.ToRegEx #c)) ~Re.None)))) ((~Re.Concat (~Str.ToRegEx #c)) (~Str.ToRegEx #))))), none) -/ #guard_msgs in -#eval Std.format$ pythonRegexToBoogie "ab(c$)*" +#eval Std.format$ pythonRegexToCore "ab(c$)*" /-- info: (((~Re.Concat ((~Re.Concat (~Str.ToRegEx #a)) (~Str.ToRegEx #b))) ((~Re.Union ((~Re.Union (~Str.ToRegEx #)) ((~Re.Concat ((~Re.Concat ~Re.None) (~Str.ToRegEx #c))) (~Str.ToRegEx #)))) ((~Re.Concat ((~Re.Concat ((~Re.Concat ((~Re.Concat ~Re.None) (~Str.ToRegEx #c))) ~Re.None)) (~Re.Star ((~Re.Concat ((~Re.Concat ~Re.None) (~Str.ToRegEx #c))) ~Re.None)))) ((~Re.Concat ((~Re.Concat ~Re.None) (~Str.ToRegEx #c))) (~Str.ToRegEx #))))), none) -/ #guard_msgs in -#eval Std.format$ pythonRegexToBoogie "ab(^c$)*" +#eval Std.format$ pythonRegexToCore "ab(^c$)*" /-- info: (((~Re.Concat (~Str.ToRegEx #a)) (~Str.ToRegEx #b)), none) -/ #guard_msgs in -#eval Std.format$ pythonRegexToBoogie "ab" +#eval Std.format$ pythonRegexToCore "ab" /-- info: (((~Re.Union (~Str.ToRegEx #a)) (~Str.ToRegEx #b)), none) -/ #guard_msgs in -#eval Std.format$ pythonRegexToBoogie "a|b" +#eval Std.format$ pythonRegexToCore "a|b" /-- info: (((~Re.Concat ((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #a))) (~Str.ToRegEx #b)), none) -/ #guard_msgs in -#eval Std.format$ pythonRegexToBoogie "^ab" +#eval Std.format$ pythonRegexToCore "^ab" /-- info: (((~Re.Concat ((~Re.Concat ((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #a))) (~Str.ToRegEx #b))) (~Str.ToRegEx #)), none) -/ #guard_msgs in -#eval Std.format$ pythonRegexToBoogie "^ab$" +#eval Std.format$ pythonRegexToCore "^ab$" /-- info: (((~Re.Concat ((~Re.Concat (~Str.ToRegEx #a)) ~Re.None)) (~Str.ToRegEx #b)), none) -/ #guard_msgs in -#eval Std.format$ pythonRegexToBoogie "(a$)b" +#eval Std.format$ pythonRegexToCore "(a$)b" /-- info: (((~Re.Concat ((~Re.Concat ((~Re.Concat ((~Re.Concat ((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #))) (~Str.ToRegEx #))) (~Str.ToRegEx #a))) (~Str.ToRegEx #))) (~Str.ToRegEx #)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "^^^a$$" +#eval Std.format $ pythonRegexToCore "^^^a$$" /-- info: (((~Re.Concat (~Str.ToRegEx #)) ((~Re.Concat ((~Re.Concat ((~Re.Concat ((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #))) (~Str.ToRegEx #a))) (~Str.ToRegEx #))) (~Str.ToRegEx #))), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "^(^^a$$)" +#eval Std.format $ pythonRegexToCore "^(^^a$$)" /-- info: (((~Re.Union ((~Re.Concat ((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #a))) (~Str.ToRegEx #))) ((~Re.Concat ((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #b))) (~Str.ToRegEx #))), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "(^a$)|(^b$)" +#eval Std.format $ pythonRegexToCore "(^a$)|(^b$)" /-- info: (((~Re.Concat (~Str.ToRegEx #c)) ((~Re.Union ((~Re.Concat ~Re.None) (~Str.ToRegEx #a))) ((~Re.Concat ~Re.None) (~Str.ToRegEx #b)))), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "c((^a)|(^b))" +#eval Std.format $ pythonRegexToCore "c((^a)|(^b))" /-- info: (((~Re.Concat ((~Re.Union ((~Re.Concat (~Str.ToRegEx #a)) ~Re.None)) ((~Re.Concat (~Str.ToRegEx #b)) ~Re.None))) (~Str.ToRegEx #c)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "((a$)|(b$))c" +#eval Std.format $ pythonRegexToCore "((a$)|(b$))c" /-- info: (((~Re.Concat ((~Re.Union ((~Re.Concat (~Str.ToRegEx #a)) ~Re.None)) (~Str.ToRegEx #b))) (~Str.ToRegEx #c)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "((a$)|(b))c" +#eval Std.format $ pythonRegexToCore "((a$)|(b))c" /-- info: (((~Re.Concat (~Str.ToRegEx #c)) ((~Re.Union ((~Re.Concat (~Str.ToRegEx #a)) (~Str.ToRegEx #))) ((~Re.Concat ((~Re.Concat ~Re.None) (~Str.ToRegEx #b))) (~Str.ToRegEx #)))), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "c((a$)|(^b$))" +#eval Std.format $ pythonRegexToCore "c((a$)|(^b$))" /-- info: (((~Re.Concat ((~Re.Union ((~Re.Concat (~Str.ToRegEx #a)) ~Re.None)) (~Str.ToRegEx #b))) (~Str.ToRegEx #c)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "((a$)|(b))c" +#eval Std.format $ pythonRegexToCore "((a$)|(b))c" /-- info: (((~Re.Concat ((~Re.Concat (~Str.ToRegEx #)) ~Re.None)) (~Str.ToRegEx #b)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "^$b" +#eval Std.format $ pythonRegexToCore "^$b" /-- info: (((~Re.Union ((~Re.Concat ((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #a))) (~Str.ToRegEx #))) ((~Re.Concat ((~Re.Concat (~Str.ToRegEx #)) ~Re.None)) (~Str.ToRegEx #b))), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "^a$|^$b" +#eval Std.format $ pythonRegexToCore "^a$|^$b" /-- info: (((~Re.Concat ((~Re.Concat (~Str.ToRegEx #c)) ((~Re.Union ((~Re.Concat ~Re.None) (~Str.ToRegEx #a))) ((~Re.Concat (~Str.ToRegEx #b)) ~Re.None)))) (~Str.ToRegEx #d)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "c(^a|b$)d" +#eval Std.format $ pythonRegexToCore "c(^a|b$)d" /-- info: (((~Re.Concat ((~Re.Concat (~Str.ToRegEx #c)) ((~Re.Union ((~Re.Concat ~Re.None) (~Str.ToRegEx #a))) ((~Re.Concat (~Str.ToRegEx #b)) ~Re.None)))) (~Str.ToRegEx #d)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "(c(^a|b$))d" +#eval Std.format $ pythonRegexToCore "(c(^a|b$))d" /-- info: (((~Re.Concat ((~Re.Union ((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #a))) ((~Re.Concat (~Str.ToRegEx #b)) ~Re.None))) ((~Re.Union ((~Re.Concat ~Re.None) (~Str.ToRegEx #c))) ((~Re.Concat (~Str.ToRegEx #d)) (~Str.ToRegEx #)))), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "(^a|b$)(^c|d$)" +#eval Std.format $ pythonRegexToCore "(^a|b$)(^c|d$)" /-- info: (((~Re.Concat ((~Re.Concat ((~Re.Union ((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #a))) ((~Re.Concat (~Str.ToRegEx #b)) ~Re.None))) ~Re.None)) (~Str.ToRegEx #c)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "((^a|b$)^)c" +#eval Std.format $ pythonRegexToCore "((^a|b$)^)c" /-- info: (((~Re.Concat ((~Re.Union (~Str.ToRegEx #)) ~Re.None)) (~Str.ToRegEx #c)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "(^|$)c" +#eval Std.format $ pythonRegexToCore "(^|$)c" /-- info: (((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "^^" +#eval Std.format $ pythonRegexToCore "^^" /-- info: (((~Re.Concat ((~Re.Concat ((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #))) (~Str.ToRegEx #))) (~Str.ToRegEx #)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "^$$^" +#eval Std.format $ pythonRegexToCore "^$$^" /-- info: (((~Re.Concat ((~Re.Union (~Str.ToRegEx #)) (~Str.ToRegEx #))) (~Str.ToRegEx #)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "(^|$)^" +#eval Std.format $ pythonRegexToCore "(^|$)^" /-- info: (((~Re.Concat ((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #a))) (~Str.ToRegEx #)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "^a$" .fullmatch +#eval Std.format $ pythonRegexToCore "^a$" .fullmatch /-- info: (~Re.All, some Pattern error at position 1: Invalid repeat bounds {100,2}: maximum 2 is less than minimum 100 in pattern 'x{100,2}') -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "x{100,2}" .fullmatch +#eval Std.format $ pythonRegexToCore "x{100,2}" .fullmatch -- (unmatchable) /-- info: (((~Re.Concat ((~Re.Concat (~Str.ToRegEx #a)) ~Re.None)) (~Str.ToRegEx #b)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "a^b" .fullmatch +#eval Std.format $ pythonRegexToCore "a^b" .fullmatch /-- info: (((~Re.Concat ((~Re.Concat ((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #a))) ~Re.None)) (~Str.ToRegEx #b)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "^a^b" .fullmatch +#eval Std.format $ pythonRegexToCore "^a^b" .fullmatch /-- info: (((~Re.Concat ((~Re.Concat (~Str.ToRegEx #a)) ~Re.None)) (~Str.ToRegEx #b)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "a$b" .fullmatch +#eval Std.format $ pythonRegexToCore "a$b" .fullmatch /-- info: ((~Re.Comp (~Str.ToRegEx #b)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "[^b]" .fullmatch +#eval Std.format $ pythonRegexToCore "[^b]" .fullmatch /-- info: ((~Re.Comp ((~Re.Range #A) #Z)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "[^A-Z]" .fullmatch +#eval Std.format $ pythonRegexToCore "[^A-Z]" .fullmatch /-- info: ((~Re.Comp (~Str.ToRegEx #^)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "[^^]" .fullmatch +#eval Std.format $ pythonRegexToCore "[^^]" .fullmatch /-- info: ((~Str.ToRegEx #a), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "a" .fullmatch +#eval Std.format $ pythonRegexToCore "a" .fullmatch /-- info: (((~Re.Concat (~Str.ToRegEx #a)) ((~Re.Union ((~Re.Union (~Str.ToRegEx #)) ~Re.AllChar)) ((~Re.Concat ((~Re.Concat ~Re.AllChar) (~Re.Star ~Re.AllChar))) ~Re.AllChar))), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "a" .match +#eval Std.format $ pythonRegexToCore "a" .match -- search mode tests /-- @@ -383,24 +383,24 @@ info: (((~Re.Concat ((~Re.Union ((~Re.Union (~Str.ToRegEx #)) ~Re.AllChar)) ((~R none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "a" .search +#eval Std.format $ pythonRegexToCore "a" .search /-- info: (((~Re.Concat ((~Re.Union ((~Re.Union (~Str.ToRegEx #)) ~Re.AllChar)) ((~Re.Concat ((~Re.Concat ~Re.AllChar) (~Re.Star ~Re.AllChar))) ~Re.AllChar))) ((~Re.Concat ((~Re.Concat ((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #a))) (~Str.ToRegEx #))) ((~Re.Union ((~Re.Union (~Str.ToRegEx #)) ~Re.AllChar)) ((~Re.Concat ((~Re.Concat ~Re.AllChar) (~Re.Star ~Re.AllChar))) ~Re.AllChar)))), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "^a$" .search +#eval Std.format $ pythonRegexToCore "^a$" .search /-- info: (((~Re.Concat (~Str.ToRegEx #)) (~Str.ToRegEx #a)), none) -/ #guard_msgs in -#eval Std.format $ pythonRegexToBoogie "^a" .fullmatch +#eval Std.format $ pythonRegexToCore "^a" .fullmatch -- -- BAD --- #eval Std.format $ pythonRegexToBoogie "a$.*" .fullmatch +-- #eval Std.format $ pythonRegexToCore "a$.*" .fullmatch -- -- -- BAD --- #eval Std.format $ pythonRegexToBoogie "a$" .match +-- #eval Std.format $ pythonRegexToCore "a$" .match ------------------------------------------------------------------------------- diff --git a/Strata/Transform/CallElim.lean b/Strata/Transform/CallElim.lean index 96748474f..e90397063 100644 --- a/Strata/Transform/CallElim.lean +++ b/Strata/Transform/CallElim.lean @@ -4,21 +4,21 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Transform.BoogieTransform +import Strata.Transform.CoreTransform /-! # Call Elimination Transformation -/ -namespace Boogie +namespace Core namespace CallElim -open Boogie.Transform +open Core.Transform /-- The main call elimination transformation algorithm on a single command. The returned result is a sequence of statements -/ def callElimCmd (cmd: Command) (p : Program) - : BoogieTransformM (List Statement) := do + : CoreTransformM (List Statement) := do match cmd with | .call lhs procName args _ => @@ -94,8 +94,8 @@ def callElimL (dcls : List Decl) (prog : Program) := /-- Call Elimination for an entire program by walking through all procedure bodies -/ -def callElim' (p : Program) : BoogieTransformM Program := +def callElim' (p : Program) : CoreTransformM Program := runProgram callElimCmd p end CallElim -end Boogie +end Core diff --git a/Strata/Transform/CallElimCorrect.lean b/Strata/Transform/CallElimCorrect.lean index c01f52296..2f32c8163 100644 --- a/Strata/Transform/CallElimCorrect.lean +++ b/Strata/Transform/CallElimCorrect.lean @@ -6,17 +6,17 @@ import Init.Data.List.Basic import Init.Data.List.Lemmas -import Strata.Languages.Boogie.Env -import Strata.Languages.Boogie.Identifiers -import Strata.Languages.Boogie.Program -import Strata.Languages.Boogie.ProgramType -import Strata.Languages.Boogie.WF +import Strata.Languages.Core.Env +import Strata.Languages.Core.Identifiers +import Strata.Languages.Core.Program +import Strata.Languages.Core.ProgramType +import Strata.Languages.Core.WF import Strata.DL.Lambda.Lambda -import Strata.Transform.BoogieTransform +import Strata.Transform.CoreTransform import Strata.Transform.CallElim import Strata.DL.Imperative.CmdSemantics -import Strata.Languages.Boogie.StatementSemantics -import Strata.Languages.Boogie.StatementSemanticsProps +import Strata.Languages.Core.StatementSemantics +import Strata.Languages.Core.StatementSemanticsProps import Strata.DL.Util.ListUtils /-! # Call Elimination Correctness Proof @@ -28,33 +28,33 @@ import Strata.DL.Util.ListUtils -/ namespace CallElimCorrect -open Boogie Boogie.Transform CallElim +open Core Core.Transform CallElim -theorem BoogieIdent.isGlob_isGlobOrLocl : - PredImplies (BoogieIdent.isGlob ·) (BoogieIdent.isGlobOrLocl ·) := by +theorem CoreIdent.isGlob_isGlobOrLocl : + PredImplies (CoreIdent.isGlob ·) (CoreIdent.isGlobOrLocl ·) := by intros x H - simp [BoogieIdent.isGlobOrLocl] + simp [CoreIdent.isGlobOrLocl] exact Or.symm (Or.inr H) -theorem BoogieIdent.isLocl_isGlobOrLocl : - PredImplies (BoogieIdent.isLocl ·) (BoogieIdent.isGlobOrLocl ·) := by +theorem CoreIdent.isLocl_isGlobOrLocl : + PredImplies (CoreIdent.isLocl ·) (CoreIdent.isGlobOrLocl ·) := by intros x H - simp [BoogieIdent.isGlobOrLocl] + simp [CoreIdent.isGlobOrLocl] exact Or.symm (Or.inl H) -theorem BoogieIdent.Disjoint_isTemp_isGlobOrLocl : - PredDisjoint (BoogieIdent.isTemp ·) (BoogieIdent.isGlobOrLocl ·) := by +theorem CoreIdent.Disjoint_isTemp_isGlobOrLocl : + PredDisjoint (CoreIdent.isTemp ·) (CoreIdent.isGlobOrLocl ·) := by intros x H1 H2 - simp [BoogieIdent.isTemp] at H1 - simp [BoogieIdent.isGlobOrLocl] at H2 + simp [CoreIdent.isTemp] at H1 + simp [CoreIdent.isGlobOrLocl] at H2 split at H1 <;> simp_all - cases H2 <;> simp [BoogieIdent.isGlob, BoogieIdent.isLocl] at * + cases H2 <;> simp [CoreIdent.isGlob, CoreIdent.isLocl] at * -theorem BoogieIdent.Disjoint_isLocl_isGlob : - PredDisjoint (BoogieIdent.isLocl ·) (BoogieIdent.isGlob ·) := by +theorem CoreIdent.Disjoint_isLocl_isGlob : + PredDisjoint (CoreIdent.isLocl ·) (CoreIdent.isGlob ·) := by intros x H1 H2 - simp [BoogieIdent.isLocl] at H1 - simp [BoogieIdent.isGlob] at H2 + simp [CoreIdent.isLocl] at H1 + simp [CoreIdent.isGlob] at H2 split at H1 <;> simp_all -- inidividual lemmas @@ -137,7 +137,7 @@ theorem getIdentTy!_no_throw : theorem getIdentTys!_no_throw : ∀ {p : Program} {idents : List Expression.Ident} - {cs : BoogieGenState}, + {cs : CoreGenState}, (∀ ident ∈ idents, (p.find? .var ident).isSome = true) → ∃ r, (runWith idents (getIdentTys! p) cs).fst = (Except.ok r) := by intros p idents cs Hglob @@ -165,8 +165,8 @@ theorem getIdentTys!_no_throw : -- Step 1. A theorem stating that given a well-formed program, call-elim will return no exception theorem callElimBlockNoExcept : - ∀ (st : Boogie.Statement) - (p : Boogie.Program), + ∀ (st : Core.Statement) + (p : Core.Program), WF.WFStatementsProp p [st] → ∃ sts, Except.ok sts = ((run [st] (CallElim.callElimStmts · p))) -- NOTE: the generated variables will not be local, but temp. So it will not be well-formed @@ -240,7 +240,7 @@ theorem callElimBlockNoExcept : exfalso apply Hne simp [Option.isSome] at df - unfold BoogieIdent.unres at * + unfold CoreIdent.unres at * split at df <;> simp_all apply Hne simp [← ol, Lambda.LMonoTySignature.toTrivialLTy] @@ -256,7 +256,7 @@ theorem callElimBlockNoExcept : exfalso apply Hne simp [Option.isSome] at df - unfold BoogieIdent.unres at * + unfold CoreIdent.unres at * split at df <;> simp_all apply Hne simp [← al, Lambda.LMonoTySignature.toTrivialLTy] @@ -270,7 +270,7 @@ theorem callElimBlockNoExcept : cases wf with | mk wf => simp [Program.Procedure.find?] at wf - unfold BoogieIdent.unres at * + unfold CoreIdent.unres at * split at wf <;> simp_all . -- other case grind @@ -299,7 +299,7 @@ theorem postconditions_subst_unwrap : symm exact Hin.2 -theorem prepostconditions_unwrap {ps : List (BoogieLabel × Procedure.Check)} : +theorem prepostconditions_unwrap {ps : List (CoreLabel × Procedure.Check)} : post ∈ List.map Procedure.Check.expr (ListMap.values ps) → ∃ label attr md, (label, { expr := post, attr := attr, md := md : Procedure.Check }) ∈ ps := by intros H @@ -333,9 +333,9 @@ theorem updatedStateIsDefinedMono : by_cases Heq : (k' = k) <;> simp [Heq] case neg => assumption -theorem EvalExpressionUpdatedState {δ : BoogieEval}: +theorem EvalExpressionUpdatedState {δ : CoreEval}: Imperative.WellFormedSemanticEvalVar δ → -Boogie.WellFormedBoogieEvalCong δ → +Core.WellFormedCoreEvalCong δ → Imperative.WellFormedSemanticEvalVal δ → ¬ k ∈ (Imperative.HasVarsPure.getVars e) → δ σ e = some v' → @@ -364,13 +364,13 @@ Imperative.WellFormedSemanticEvalVal δ → case eq m e1 e2 e1ih e2ih => apply Hwfc.eqcongr <;> grind -theorem EvalExpressionsUpdatedState {δ : BoogieEval} : +theorem EvalExpressionsUpdatedState {δ : CoreEval} : Imperative.WellFormedSemanticEvalVar δ → - Boogie.WellFormedBoogieEvalCong δ → + Core.WellFormedCoreEvalCong δ → Imperative.WellFormedSemanticEvalVal δ → ¬ k ∈ es.flatMap Imperative.HasVarsPure.getVars → - EvalExpressions (P:=Boogie.Expression) δ σ es vs → - EvalExpressions (P:=Boogie.Expression) δ (updatedState σ k v) es vs := by + EvalExpressions (P:=Core.Expression) δ σ es vs → + EvalExpressions (P:=Core.Expression) δ (updatedState σ k v) es vs := by intros Hwfv Hwfc Hwfvl Hnin Heval have Hlen := EvalExpressionsLength Heval induction es generalizing vs σ @@ -389,9 +389,9 @@ theorem EvalExpressionsUpdatedState {δ : BoogieEval} : . apply EvalExpressionUpdatedState <;> simp_all . apply ih <;> simp_all -theorem EvalExpressionUpdatedStates {δ : BoogieEval} : +theorem EvalExpressionUpdatedStates {δ : CoreEval} : Imperative.WellFormedSemanticEvalVar δ → - Boogie.WellFormedBoogieEvalCong δ → + Core.WellFormedCoreEvalCong δ → Imperative.WellFormedSemanticEvalVal δ → ks'.length = vs'.length → ks'.Nodup → @@ -420,15 +420,15 @@ theorem EvalExpressionUpdatedStates {δ : BoogieEval} : simp_all . rw [List.unzip_zip] <;> grind -theorem EvalExpressionsUpdatedStates {δ : BoogieEval} : +theorem EvalExpressionsUpdatedStates {δ : CoreEval} : Imperative.WellFormedSemanticEvalVar δ → - Boogie.WellFormedBoogieEvalCong δ → + Core.WellFormedCoreEvalCong δ → Imperative.WellFormedSemanticEvalVal δ → ks'.length = vs'.length → ks'.Nodup → ks'.Disjoint (es.flatMap Imperative.HasVarsPure.getVars) → - EvalExpressions (P:=Boogie.Expression) δ σ es vs → - EvalExpressions (P:=Boogie.Expression) δ (updatedStates σ ks' vs') es vs := by + EvalExpressions (P:=Core.Expression) δ σ es vs → + EvalExpressions (P:=Core.Expression) δ (updatedStates σ ks' vs') es vs := by intros Hwfv Hwfc Hwfvl Hlen Hnd Hnin Heval have Hlen := EvalExpressionsLength Heval induction ks' generalizing vs' σ @@ -702,11 +702,11 @@ theorem EvalStatementContractInit : theorem EvalStatementsContractInits : Imperative.WellFormedSemanticEvalVar δ → Imperative.WellFormedSemanticEvalVal δ → - WellFormedBoogieEvalCong δ → + WellFormedCoreEvalCong δ → -- the generated old variable names shouldn't overlap with original variables trips.unzip.1.unzip.1.Disjoint (List.flatMap (Imperative.HasVarsPure.getVars (P:=Expression)) trips.unzip.2) → List.Nodup (trips.unzip.1.unzip.1) → - EvalExpressions (P:=Boogie.Expression) δ σ (trips.unzip.2) vvs → + EvalExpressions (P:=Core.Expression) δ σ (trips.unzip.2) vvs → -- ReadValues σ (trips.unzip.2) vvs → Imperative.isNotDefined σ (trips.unzip.1.unzip.1) → EvalStatementsContract π δ σ @@ -799,7 +799,7 @@ theorem createFvarsSubstStores : Imperative.substDefined σ σA (ks1.zip ks2) → Imperative.substStores σ σA (ks1.zip ks2) → ReadValues σA ks2 argVals → - EvalExpressions (P:=Boogie.Expression) δ σ (createFvars ks1) argVals := by + EvalExpressions (P:=Core.Expression) δ σ (createFvars ks1) argVals := by intros Hlen Hwfv Hdef Hsubst Hrd simp [createFvars] have Hlen2 := ReadValuesLength Hrd @@ -1110,7 +1110,7 @@ case cons h t ih => because then we can't say anything about the stores due to not knowing the exact form of the expressions -/ theorem Lambda.LExpr.substFvarCorrect : - Boogie.WellFormedBoogieEvalCong δ → + Core.WellFormedCoreEvalCong δ → Imperative.WellFormedSemanticEvalVar (P:=Expression) δ → Imperative.WellFormedSemanticEvalVal (P:=Expression) δ → Imperative.substStores σ σ' [(fro, to)] → @@ -1210,7 +1210,7 @@ theorem Lambda.LExpr.substFvarCorrect : apply Hwfc.eqcongr <;> grind theorem Lambda.LExpr.substFvarsCorrectZero : - Boogie.WellFormedBoogieEvalCong δ → + Core.WellFormedCoreEvalCong δ → Imperative.WellFormedSemanticEvalVar δ → Imperative.WellFormedSemanticEvalVal δ → Imperative.invStores σ σ' (Imperative.HasVarsPure.getVars e) → @@ -1500,7 +1500,7 @@ case eq fn e fn_ih e_ih => cases e_ih <;> simp_all theorem Lambda.LExpr.substFvarsCorrect : - WellFormedBoogieEvalCong δ → + WellFormedCoreEvalCong δ → Imperative.WellFormedSemanticEvalVar (P:=Expression) δ → Imperative.WellFormedSemanticEvalVal (P:=Expression) δ → fro.length = to.length → @@ -1572,7 +1572,7 @@ theorem createAssertsCorrect : Imperative.WellFormedSemanticEvalVar δ → Imperative.WellFormedSemanticEvalVal δ → -- TODO: remove congruence of old expressions, and require pre to contain no old expressions - Boogie.WellFormedBoogieEvalCong δ → + Core.WellFormedCoreEvalCong δ → ks.length = ks'.length → Imperative.substNodup (ks.zip ks') → Imperative.substDefined σA σ' (ks.zip ks') → @@ -1630,7 +1630,7 @@ theorem createAssumesCorrect : Imperative.WellFormedSemanticEvalBool δ → Imperative.WellFormedSemanticEvalVar δ → Imperative.WellFormedSemanticEvalVal δ → - Boogie.WellFormedBoogieEvalCong δ → + Core.WellFormedCoreEvalCong δ → ks.length = ks'.length → Imperative.substNodup (ks.zip ks') → Imperative.substDefined σA σ' (ks.zip ks') → @@ -1719,8 +1719,8 @@ theorem createOldStoreSubstEq : theorem substOldCorrect : Imperative.WellFormedSemanticEvalVar δ → Imperative.WellFormedSemanticEvalVal δ → - Boogie.WellFormedBoogieEvalCong δ → - Boogie.WellFormedBoogieEvalTwoState δ σ₀ σ → + Core.WellFormedCoreEvalCong δ → + Core.WellFormedCoreEvalTwoState δ σ₀ σ → OldExpressions.NormalizedOldExpr e → --Imperative.invStores σ₀ σ -- ((OldExpressions.extractOldExprVars e).removeAll [fro]) → @@ -1752,7 +1752,7 @@ theorem substOldCorrect : . -- is an old var that is substituted next x ty eq => simp [eq] at * - simp [WellFormedBoogieEvalTwoState] at Hwf2 + simp [WellFormedCoreEvalTwoState] at Hwf2 cases Hwf2.1 with | intro vs Hwf2' => cases Hwf2' with @@ -1765,7 +1765,7 @@ theorem substOldCorrect : have HH:= Hwf2.2.1 vs vs' σ₀ σ₁ σ Hwf2'.1 Hwf2'.2 fro simp [OldExpressions.oldVar, OldExpressions.oldExpr, - BoogieIdent.unres, Hin] at HH + CoreIdent.unres, Hin] at HH rw [HH] simp [createFvar] simp [Imperative.WellFormedSemanticEvalVar] at Hwfvr @@ -1786,7 +1786,7 @@ theorem substOldCorrect : . have HH:= Hwf2.2.1 vs vs' σ₀ σ₁ σ Hwf2'.1 Hwf2'.2 fro simp [OldExpressions.oldVar, OldExpressions.oldExpr, - BoogieIdent.unres, Hin] at HH + CoreIdent.unres, Hin] at HH simp [createFvar] simp [HH] simp [Imperative.WellFormedSemanticEvalVar] at Hwfvr @@ -1951,12 +1951,12 @@ case cons h t ih => exact fun a => Hne (Eq.symm a) simp_all -theorem updatedStateOldWellFormedBoogieEvalTwoState : +theorem updatedStateOldWellFormedCoreEvalTwoState : σ k = some v → - WellFormedBoogieEvalTwoState δ σ₀ σ → - WellFormedBoogieEvalTwoState δ (updatedState σ₀ k v) σ := by + WellFormedCoreEvalTwoState δ σ₀ σ → + WellFormedCoreEvalTwoState δ (updatedState σ₀ k v) σ := by intros Hsome Hwf2 - simp [WellFormedBoogieEvalTwoState] at * + simp [WellFormedCoreEvalTwoState] at * refine ⟨?_, Hwf2.2⟩ cases Hwf2.1 with | intro vs Hwf2 => @@ -2027,7 +2027,7 @@ NormalizedOldExpr e → cases Hold cases Hwf simp_all - simp [BoogieIdent.unres] at HH + simp [CoreIdent.unres] at HH rename_i md tyy id v have HH2 := HH md tyy () id v simp_all @@ -2086,7 +2086,7 @@ theorem substOldExpr_cons: rename_i _ fn e _ _ H generalize H1: (OldExpressions.substOld h.snd (Lambda.LExpr.fvar () h.fst.fst none) fn) = fn' generalize H2: (OldExpressions.substOld h.snd (Lambda.LExpr.fvar () h.fst.fst none) e) = e' - rw (occs := [3]) [Boogie.OldExpressions.substsOldExpr.eq_def] + rw (occs := [3]) [Core.OldExpressions.substsOldExpr.eq_def] simp; split simp_all [Map.isEmpty]; rename_i H; split at H <;> simp_all rw[OldExpressions.substOldExpr_nil, OldExpressions.substOldExpr_nil]; simp @@ -2128,8 +2128,8 @@ theorem substOldExpr_cons: theorem substsOldCorrect : Imperative.WellFormedSemanticEvalVar δ → Imperative.WellFormedSemanticEvalVal δ → - Boogie.WellFormedBoogieEvalCong δ → - Boogie.WellFormedBoogieEvalTwoState δ σ₀ σ → + Core.WellFormedCoreEvalCong δ → + Core.WellFormedCoreEvalTwoState δ σ₀ σ → OldExpressions.NormalizedOldExpr e → Imperative.substStores σ₀ σ (createOldStoreSubst oldTrips) → Imperative.substDefined σ₀ σ (createOldStoreSubst oldTrips) → @@ -2408,7 +2408,7 @@ theorem Program.find.var_in_decls : theorem WFProgGlob : WF.WFDeclsProp p p.decls → - PredImplies (isGlobalVar p ·) (BoogieIdent.isGlob ·) := by + PredImplies (isGlobalVar p ·) (CoreIdent.isGlob ·) := by intros Hwf x HH simp [isGlobalVar, Option.isSome] at HH split at HH <;> simp at HH @@ -2473,30 +2473,30 @@ case cons h t ih => . simp [StateT.pure,pure] at Hgen cases Hgen -/--! Theorems about well-formedness of BoogieGen -/ +/--! Theorems about well-formedness of CoreGen -/ theorem genArgExprIdentTemp : - genArgExprIdent s = (l, s') → BoogieIdent.isTemp l := - fun Hgen => by exact genBoogieIdentTemp Hgen + genArgExprIdent s = (l, s') → CoreIdent.isTemp l := + fun Hgen => by exact genCoreIdentTemp Hgen theorem genOutExprIdentTemp : - genOutExprIdent e s = (l, s') → BoogieIdent.isTemp l := - fun Hgen => genBoogieIdentTemp Hgen + genOutExprIdent e s = (l, s') → CoreIdent.isTemp l := + fun Hgen => genCoreIdentTemp Hgen -theorem genBoogieIdentGeneratedWF : - BoogieGenState.gen pf s = (l, s') → s'.generated = l :: s.generated := by +theorem genCoreIdentGeneratedWF : + CoreGenState.gen pf s = (l, s') → s'.generated = l :: s.generated := by intros Hgen - simp [BoogieGenState.gen] at Hgen + simp [CoreGenState.gen] at Hgen rw [← Hgen.2] simp_all theorem genIdentGeneratedWF : genIdent ident pf s = (l, s') → s'.generated = l :: s.generated := - fun Hgen => genBoogieIdentGeneratedWF Hgen + fun Hgen => genCoreIdentGeneratedWF Hgen theorem genArgExprIdentGeneratedWF : genArgExprIdent s = (l, s') → s'.generated = l :: s.generated := - fun Hgen => genBoogieIdentGeneratedWF Hgen + fun Hgen => genCoreIdentGeneratedWF Hgen theorem genArgExprIdentsGeneratedWF : genArgExprIdents n s = (ls, s') → @@ -2520,7 +2520,7 @@ theorem genArgExprIdentsGeneratedWF : have HH := genArgExprIdentGeneratedWF heq grind -theorem genArgExprIdentsTripGeneratedWF { s s' : BoogieGenState } : +theorem genArgExprIdentsTripGeneratedWF { s s' : CoreGenState } : genArgExprIdentsTrip outs xs s = (Except.ok trips, s') → trips.unzip.1.unzip.1.reverse ++ s.generated = s'.generated := by intros Hgen @@ -2552,15 +2552,15 @@ theorem genArgExprIdentsTripGeneratedWF { s s' : BoogieGenState } : cases Hgen theorem genArgExprIdentWFMono : - BoogieGenState.WF s → + CoreGenState.WF s → genArgExprIdent s = (l, s') → - BoogieGenState.WF s' := - fun Hgen => BoogieGenState.WFMono' Hgen + CoreGenState.WF s' := + fun Hgen => CoreGenState.WFMono' Hgen theorem genArgExprIdentsWFMono : - BoogieGenState.WF s → + CoreGenState.WF s → genArgExprIdents n s = (ls, s') → - BoogieGenState.WF s' := by + CoreGenState.WF s' := by intros Hwf Hgen simp [genArgExprIdents] at Hgen induction n generalizing s ls s' @@ -2579,9 +2579,9 @@ theorem genArgExprIdentsWFMono : grind theorem genArgExprIdentsTripWFMono : - BoogieGenState.WF s → + CoreGenState.WF s → genArgExprIdentsTrip outs xs s = (Except.ok trips, s') → - BoogieGenState.WF s' := by + CoreGenState.WF s' := by intros Hwf Hgen simp [genArgExprIdentsTrip] at * split at Hgen @@ -2608,7 +2608,7 @@ theorem genArgExprIdentsTripWFMono : theorem genOutExprIdentGeneratedWF : genOutExprIdent e s = (l, s') → s'.generated = l :: s.generated := - fun Hgen => genBoogieIdentGeneratedWF Hgen + fun Hgen => genCoreIdentGeneratedWF Hgen theorem genOutExprIdentsGeneratedWF : genOutExprIdents es s = (ls, s') → @@ -2632,7 +2632,7 @@ theorem genOutExprIdentsGeneratedWF : simp [HH] at ih simp_all -theorem genOutExprIdentsTripGeneratedWF { s s' : BoogieGenState } : +theorem genOutExprIdentsTripGeneratedWF { s s' : CoreGenState } : genOutExprIdentsTrip outs xs s = (Except.ok trips, s') → trips.unzip.1.unzip.1.reverse ++ s.generated = s'.generated := by intros Hgen @@ -2664,15 +2664,15 @@ theorem genOutExprIdentsTripGeneratedWF { s s' : BoogieGenState } : cases Hgen theorem genOutExprIdentWFMono : - BoogieGenState.WF s → + CoreGenState.WF s → genOutExprIdent e s = (l, s') → - BoogieGenState.WF s' := - fun Hgen => BoogieGenState.WFMono' Hgen + CoreGenState.WF s' := + fun Hgen => CoreGenState.WFMono' Hgen theorem genOutExprIdentsWFMono : - BoogieGenState.WF s → + CoreGenState.WF s → genOutExprIdents es s = (ls, s') → - BoogieGenState.WF s' := by + CoreGenState.WF s' := by intros Hwf Hgen simp [genOutExprIdents] at Hgen induction es generalizing s ls s' <;> simp at Hgen @@ -2690,9 +2690,9 @@ theorem genOutExprIdentsWFMono : exact ih HH heq' theorem genOutExprIdentsTripWFMono : - BoogieGenState.WF s → + CoreGenState.WF s → genOutExprIdentsTrip outs xs s = (Except.ok trips, s') → - BoogieGenState.WF s' := by + CoreGenState.WF s' := by intros Hwf Hgen simp [genOutExprIdentsTrip] at * split at Hgen @@ -2719,7 +2719,7 @@ theorem genOutExprIdentsTripWFMono : theorem genOldExprIdentGeneratedWF : genOldExprIdent e s = (l, s') → s'.generated = l :: s.generated := - fun Hgen => genBoogieIdentGeneratedWF Hgen + fun Hgen => genCoreIdentGeneratedWF Hgen theorem genOldExprIdentsGeneratedWF : genOldExprIdents es s = (ls, s') → @@ -2743,7 +2743,7 @@ theorem genOldExprIdentsGeneratedWF : simp [HH] at ih simp_all -theorem genOldExprIdentsTripGeneratedWF { s s' : BoogieGenState } : +theorem genOldExprIdentsTripGeneratedWF { s s' : CoreGenState } : genOldExprIdentsTrip p xs s = (Except.ok trips, s') → trips.unzip.1.unzip.1.reverse ++ s.generated = s'.generated := by intros Hgen @@ -2778,15 +2778,15 @@ theorem genOldExprIdentsTripGeneratedWF { s s' : BoogieGenState } : . cases Hgen theorem genOldExprIdentWFMono : - BoogieGenState.WF s → + CoreGenState.WF s → genOldExprIdent e s = (l, s') → - BoogieGenState.WF s' := - fun Hgen => BoogieGenState.WFMono' Hgen + CoreGenState.WF s' := + fun Hgen => CoreGenState.WFMono' Hgen theorem genOldExprIdentsWFMono : - BoogieGenState.WF s → + CoreGenState.WF s → genOldExprIdents es s = (ls, s') → - BoogieGenState.WF s' := by + CoreGenState.WF s' := by intros Hwf Hgen simp [genOldExprIdents] at Hgen induction es generalizing s ls s' <;> simp at Hgen @@ -2804,9 +2804,9 @@ theorem genOldExprIdentsWFMono : exact ih HH heq' theorem genOldExprIdentsTripWFMono : - BoogieGenState.WF s → + CoreGenState.WF s → genOldExprIdentsTrip outs xs s = (Except.ok trips, s') → - BoogieGenState.WF s' := by + CoreGenState.WF s' := by intros Hwf Hgen simp [genOldExprIdentsTrip, bind, liftM,] at * simp [Functor.map, ExceptT.bind, ExceptT.bindCont, bind, @@ -3276,11 +3276,11 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : -- all global variables in p exist in σ (∀ gk, (p.find? .var gk).isSome → (σ gk).isSome) → EvalStatementsContract π δ σ [st] σ' → - WellFormedBoogieEvalCong δ → + WellFormedCoreEvalCong δ → WF.WFStatementsProp p [st] → WF.WFProgramProp p → - BoogieGenState.WF γ → - (∀ v, v ∈ γ.generated ↔ ((σ v).isSome ∧ BoogieIdent.isTemp v)) → + CoreGenState.WF γ → + (∀ v, v ∈ γ.generated ↔ ((σ v).isSome ∧ CoreIdent.isTemp v)) → (Except.ok sts, γ') = (runWith [st] (CallElim.callElimStmts · p) γ) → -- NOTE: The theorem does not expect the same store due to inserting new temp variables exists σ'', @@ -3328,11 +3328,11 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : cases Heval with | call_sem lkup Hevalargs Hevalouts Hwfval Hwfvars Hwfb Hwf2 Hwf Hinitin Hinitout Hpre Hhav1 Hhav2 Hpost Hrd Hupdate => next outVals argVals σA σAO σO σR p' modvals => - unfold BoogieIdent.unres at Hfind + unfold CoreIdent.unres at Hfind have Hsome : (Program.Procedure.find? p procName).isSome := by grind simp [Option.isSome] at Hsome - unfold BoogieIdent.unres at * + unfold CoreIdent.unres at * have lkup' := lkup split at Hsome <;> try contradiction next x val Hfind => @@ -3387,30 +3387,30 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : have HH := List.mem_filter.mp Hin exact HH.2 have HrdOld := isDefinedReadValues HoldDef - have Hwfgenargs : BoogieGenState.WF s_arg := genArgExprIdentsTripWFMono Hwfgen Heqarg - have Hwfgenouts : BoogieGenState.WF s_out := genOutExprIdentsTripWFMono Hwfgenargs Heqout - have Hwfgenolds : BoogieGenState.WF cs' := genOldExprIdentsTripWFMono Hwfgenouts Heqold + have Hwfgenargs : CoreGenState.WF s_arg := genArgExprIdentsTripWFMono Hwfgen Heqarg + have Hwfgenouts : CoreGenState.WF s_out := genOutExprIdentsTripWFMono Hwfgenargs Heqout + have Hwfgenolds : CoreGenState.WF cs' := genOldExprIdentsTripWFMono Hwfgenouts Heqold have Hgenargs := genArgExprIdentsTripGeneratedWF Heqarg have Hgenouts := genOutExprIdentsTripGeneratedWF Heqout have Hgenolds := genOldExprIdentsTripGeneratedWF Heqold - have HargTemp : Forall (BoogieIdent.isTemp ·) argTrips.unzip.1.unzip.1 := by - simp [BoogieGenState.WF] at Hwfgenargs + have HargTemp : Forall (CoreIdent.isTemp ·) argTrips.unzip.1.unzip.1 := by + simp [CoreGenState.WF] at Hwfgenargs have HH := List.Forall_mem_iff.mp Hwfgenargs.2.2.2 simp only [← Hgenargs] at HH refine List.Forall_mem_iff.mpr ?_ intros x Hin apply HH exact List.mem_append_left γ.generated (List.mem_reverse.mpr Hin) - have HoutTemp : Forall (BoogieIdent.isTemp ·) outTrips.unzip.1.unzip.1 := by - simp [BoogieGenState.WF] at Hwfgenouts + have HoutTemp : Forall (CoreIdent.isTemp ·) outTrips.unzip.1.unzip.1 := by + simp [CoreGenState.WF] at Hwfgenouts have HH := List.Forall_mem_iff.mp Hwfgenouts.2.2.2 simp only [← Hgenouts] at HH refine List.Forall_mem_iff.mpr ?_ intros x Hin apply HH exact List.mem_append_left s_arg.generated (List.mem_reverse.mpr Hin) - have HoldTemp : Forall (BoogieIdent.isTemp ·) oldTrips.unzip.1.unzip.1 := by - simp [BoogieGenState.WF] at Hwfgenolds + have HoldTemp : Forall (CoreIdent.isTemp ·) oldTrips.unzip.1.unzip.1 := by + simp [CoreGenState.WF] at Hwfgenolds have HH := List.Forall_mem_iff.mp Hwfgenolds.2.2.2 simp only [← Hgenolds] at HH refine List.Forall_mem_iff.mpr ?_ @@ -3427,7 +3427,7 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : argTrips.unzip.fst.unzip.fst ++ outTrips.unzip.fst.unzip.fst ++ oldTrips.unzip.fst.unzip.fst).Nodup := by - simp [BoogieGenState.WF] at Hwfgenolds + simp [CoreGenState.WF] at Hwfgenolds have Hnd := nodup_reverse Hwfgenolds.2.2.1 simp only [List.reverse_append, List.reverse_reverse, ← List.append_assoc, ← Hgenargs,← Hgenouts,← Hgenolds] at Hnd @@ -3463,14 +3463,14 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : have Hcontra := List.mem_reverse.mpr ((Hwfgenst v).mpr ⟨Hsome, Htemp⟩) simp only [List.append_assoc] at Hin Hgennd' exact (List.nodup_append.mp Hgennd').2.2 v Hcontra v Hin rfl - have Hmodglob : Forall (BoogieIdent.isGlob ·) proc.spec.modifies := by + have Hmodglob : Forall (CoreIdent.isGlob ·) proc.spec.modifies := by simp [WF.WFModsProp] at wfmod apply List.Forall_PredImplies exact wfmod intros x HH apply WFProgGlob Hwfp exact WF.WFModProp.defined HH - have Holdsndglob : Forall (BoogieIdent.isGlob ·) oldTrips.unzip.snd := by + have Holdsndglob : Forall (CoreIdent.isGlob ·) oldTrips.unzip.snd := by simp [genOldExprIdentsTrip_snd Heqold] apply List.Forall_PredImplies apply List.Forall_filter @@ -3530,15 +3530,15 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . assumption . simp [genArgExprIdentsTrip_snd Heqarg] apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . simp at HargTemp apply HargTemp . apply List.Forall_flatMap.mp apply List.Forall_PredImplies Hwfargs intros x Hp exact WF.WFargProp.glarg Hp - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . apply List.Sublist.nodup (List.sublist_append_left _ _) ?_ . exact outTrips.unzip.fst.unzip.fst apply List.Sublist.nodup (List.sublist_append_left _ _) ?_ @@ -3585,27 +3585,27 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . -- Disjoint between localGlob and Temp simp [genOutExprIdentsTrip_snd Heqout] apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isLocl ·)) . simp at HoutTemp exact HoutTemp . exact Hlhs.2 . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isLocl_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isLocl_isGlobOrLocl . simp refine ReadValuesUpdatedStates ?_ ?_ ?_ . simp [Hargtriplen] . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isLocl ·)) . simp at HargTemp exact HargTemp . simp [← Heqouts] exact Hlhs.2 . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isLocl_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isLocl_isGlobOrLocl . simp [← Heqouts] exact Hevalouts . -- out vars generated are not defined @@ -3631,22 +3631,22 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : apply filter_nodup apply eraseDups_Nodup . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlob ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlob ·)) . exact HoldTemp . simp [genOldExprIdentsTrip_snd Heqold] apply List.Forall_PredImplies . apply List.Forall_filter . exact WFProgGlob Hwfp . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isGlob_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isGlob_isGlobOrLocl . simp apply ReadValuesUpdatedStates . simp [Houttriplen] . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlob ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlob ·)) . simp at HoutTemp exact HoutTemp . simp [genOldExprIdentsTrip_snd Heqold] @@ -3654,13 +3654,13 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . apply List.Forall_filter . exact WFProgGlob Hwfp . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isGlob_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isGlob_isGlobOrLocl apply ReadValuesUpdatedStates . simp [Hargtriplen] . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlob ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlob ·)) . simp at HargTemp exact HargTemp . simp [genOldExprIdentsTrip_snd Heqold] @@ -3668,8 +3668,8 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . apply List.Forall_filter . exact WFProgGlob Hwfp . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isGlob_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isGlob_isGlobOrLocl . simp at HoldVals exact HoldVals . -- old vars generated are not defined @@ -3739,23 +3739,23 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . exact (List.Disjoint_Nodup_iff.mpr Hgennd).1 . exact Hlhs.1 . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isLocl ·)) . exact HargTemp . exact Hlhs.2 . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isLocl_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isLocl_isGlobOrLocl . apply List.Disjoint.symm apply List.Disjoint_app.mp ⟨?_, ?_⟩ . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . exact HargTemp . apply List.Forall_append.mpr ⟨?_, ?_⟩ - . exact List.Forall_PredImplies Hinlc BoogieIdent.isLocl_isGlobOrLocl - . exact List.Forall_PredImplies Houtlc BoogieIdent.isLocl_isGlobOrLocl - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . exact List.Forall_PredImplies Hinlc CoreIdent.isLocl_isGlobOrLocl + . exact List.Forall_PredImplies Houtlc CoreIdent.isLocl_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . intros x Hin1 Hin2 apply Hlhsdisj Hin1 simp_all @@ -3816,8 +3816,8 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : apply List.Disjoint.mono_right . exact List.removeAll_Sublist . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . apply List.Forall_append.mpr exact ⟨HoutTemp, HoldTemp⟩ . have HH := prepostconditions_unwrap Hin @@ -3830,7 +3830,7 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : have Hwf := (List.Forall_mem_iff.mp wfpre _ HH).glvars simp at Hwf exact Hwf - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . have HH := prepostconditions_unwrap Hin cases HH with | intro label HH => @@ -3840,26 +3840,26 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : | intro md HH => apply List.Disjoint_app.mp ⟨?_, ?_⟩ . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . exact HargTemp . have Hwf := (List.Forall_mem_iff.mp wfpre _ HH).glvars simp at Hwf exact Hwf - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . have Hpre := (List.Forall_mem_iff.mp wfpre _ HH) have Hlcl := List.Forall_mem_iff.mp Hpre.lvars have Hgl := List.Forall_mem_iff.mp Hpre.glvars simp at Hlcl Hgl intros x Hin1 Hin2 specialize Hgl x Hin2 - simp [BoogieIdent.isGlobOrLocl] at Hgl + simp [CoreIdent.isGlobOrLocl] at Hgl cases Hgl with | inl Hg => -- disjoint of local and global have Hlhs := List.Forall_mem_iff.mp Hlhs.2 specialize Hlhs x Hin1 - exact BoogieIdent.Disjoint_isLocl_isGlob _ Hlhs Hg + exact CoreIdent.Disjoint_isLocl_isGlob _ Hlhs Hg | inr Hl => -- disjoint because of WF specialize Hlcl x Hin2 Hl @@ -3919,13 +3919,13 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . -- length, provable simp [Hargtriplen, Houttriplen] . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isLocl ·)) . apply List.Forall_append.mpr ⟨HargTemp, HoutTemp⟩ . exact Hlhs.2 . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isLocl_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isLocl_isGlobOrLocl . exact Hevalouts . exact Hrdinout . -- Read Values @@ -3958,36 +3958,36 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . apply ReadValuesUpdatedStates . simp [Holdtriplen] . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isLocl ·)) . simp at HoldTemp exact HoldTemp . exact Hlhs.2 . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isLocl_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isLocl_isGlobOrLocl . apply ReadValuesUpdatedStates . simp [Houttriplen] . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isLocl ·)) . simp at HoutTemp exact HoutTemp . exact Hlhs.2 . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isLocl_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isLocl_isGlobOrLocl . apply ReadValuesUpdatedStates . simp [Hargtriplen] . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isLocl ·)) . simp at HargTemp exact HargTemp . exact Hlhs.2 . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isLocl_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isLocl_isGlobOrLocl . exact Hevalouts . -- Prove havocs correct simp [← createHavocsApp] @@ -4047,23 +4047,23 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . exact (List.nodup_append.mp HH.1).1 . exact Hlhs.1 . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isLocl ·)) . exact HargTemp . exact Hlhs.2 . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isLocl_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isLocl_isGlobOrLocl . apply List.Disjoint.symm apply List.Disjoint_app.mp ⟨?_, ?_⟩ . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . exact HargTemp . apply List.Forall_append.mpr ⟨?_, ?_⟩ - . exact List.Forall_PredImplies Hinlc BoogieIdent.isLocl_isGlobOrLocl - . exact List.Forall_PredImplies Houtlc BoogieIdent.isLocl_isGlobOrLocl - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . exact List.Forall_PredImplies Hinlc CoreIdent.isLocl_isGlobOrLocl + . exact List.Forall_PredImplies Houtlc CoreIdent.isLocl_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . intros x Hin1 Hin2 apply Hlhsdisj Hin1 simp_all @@ -4116,11 +4116,11 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : refine List.Disjoint_Nodup_iff.mp ⟨Houtnd, Hmodsnd, ?_⟩ -- disjoint between local and global apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isLocl ·)) - (Q:=(BoogieIdent.isGlob ·)) + (P:=(CoreIdent.isLocl ·)) + (Q:=(CoreIdent.isGlob ·)) . exact Houtlc . exact Hmodglob - . exact BoogieIdent.Disjoint_isLocl_isGlob + . exact CoreIdent.Disjoint_isLocl_isGlob have Hrd1 := UpdateStatesReadValues Houtnd Hup1 have Hrd2 := UpdateStatesReadValues Hmodsnd Hup2 have Heq2 := ReadValuesInjective Hrd2 Hrd'.2.2 @@ -4210,13 +4210,13 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : intros x Hin1 Hin2 have Hdisj : oldTrips.unzip.fst.unzip.fst.Disjoint oldTrips.unzip.snd := by apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlob ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlob ·)) . simp; exact HoldTemp . simp; exact Holdsndglob . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isGlob_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isGlob_isGlobOrLocl have Hsubset := substsOldPostSubset (post:=(OldExpressions.normalizeOldExpr post)) (oldTrips:=oldTrips) Hdisj have Hin : x ∈ (Imperative.HasVarsPure.getVars (P:=Expression) (OldExpressions.normalizeOldExpr post) ++ oldTrips.unzip.fst.unzip.fst) := by @@ -4231,13 +4231,13 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : -- disjoint of global/local with temp have Hin := normalizeOldExprInVars Hin specialize Hgl x Hin - apply BoogieIdent.Disjoint_isTemp_isGlobOrLocl + apply CoreIdent.Disjoint_isTemp_isGlobOrLocl . exact List.Forall_mem_iff.mp HargTemp x Hin1 . exact Hgl | inr Hin => -- disjoint among temp simp only [List.unzip_fst, List.map_map] at Hin - simp [BoogieIdent.isGlobOrLocl] at Hgl + simp [CoreIdent.isGlobOrLocl] at Hgl have HH := (List.nodup_append.mp Hgennd).2.2 apply HH x Hin1 x apply List.mem_append.mpr @@ -4249,13 +4249,13 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : have Hin := normalizeOldExprInVars Hin specialize Hgl x Hin -- x is either global or local - simp [BoogieIdent.isGlobOrLocl] at Hgl + simp [CoreIdent.isGlobOrLocl] at Hgl cases Hgl with | inl Hg => -- x is global have Hlhs := List.Forall_mem_iff.mp Hlhs.2 specialize Hlhs x Hin1 - exact BoogieIdent.Disjoint_isLocl_isGlob _ Hlhs Hg + exact CoreIdent.Disjoint_isLocl_isGlob _ Hlhs Hg | inr Hl => -- x is local, use wf specialize Hlcl x Hin Hl @@ -4264,9 +4264,9 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : | inr Hin => -- oldTrips disjoint from lhs simp only [List.unzip_fst, List.map_map] at Hin - apply BoogieIdent.Disjoint_isTemp_isGlobOrLocl + apply CoreIdent.Disjoint_isTemp_isGlobOrLocl . exact List.Forall_mem_iff.mp HoldTemp x Hin - . apply BoogieIdent.isLocl_isGlobOrLocl + . apply CoreIdent.isLocl_isGlobOrLocl exact List.Forall_mem_iff.mp Hlhs.2 _ Hin1 . -- post condition correct have Hmem := SubstPostsMem HinSubst @@ -4289,7 +4289,7 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . assumption . assumption -- wfTwoState, should be provable by setting inits to the oldVars created - . simp [WellFormedBoogieEvalTwoState] + . simp [WellFormedCoreEvalTwoState] refine ⟨?_, ?_, Hwf2.2⟩ . -- split into havoc and init, by setting inits to the oldVars created simp [← HσR₁] @@ -4312,22 +4312,22 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . -- Disjoint between local and temp apply List.Disjoint.symm apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . exact List.Forall_append.mpr ⟨HoutTemp, HoldTemp⟩ - . exact List.Forall_PredImplies Houtlc BoogieIdent.isLocl_isGlobOrLocl - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . exact List.Forall_PredImplies Houtlc CoreIdent.isLocl_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . simp [Houtlen] . simp [InitStatesUpdated Hinitin] apply UpdatedStatesDisjNotDefMonotone . -- Disjoint between local and temp apply List.Disjoint.symm apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . exact List.Forall_append.mpr ⟨HoutTemp, HoldTemp⟩ - . exact List.Forall_PredImplies Hinlc BoogieIdent.isLocl_isGlobOrLocl - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . exact List.Forall_PredImplies Hinlc CoreIdent.isLocl_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . simp [← Hargtriplen, Harglen, ← Heqargs] . have Hndef := (Imperative.isNotDefinedApp' Hndefgen).2 exact UpdateStatesNotDefMonotone' Hndef Hupdate @@ -4364,14 +4364,14 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . -- Disjoint between local and temp apply List.Disjoint.symm apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isLocl ·)) - (Q:=(BoogieIdent.isGlob ·)) + (P:=(CoreIdent.isLocl ·)) + (Q:=(CoreIdent.isGlob ·)) . exact Houtlc . simp [genOldExprIdentsTrip_snd Heqold] apply List.Forall_PredImplies . apply List.Forall_filter . exact WFProgGlob Hwfp - . exact BoogieIdent.Disjoint_isLocl_isGlob + . exact CoreIdent.Disjoint_isLocl_isGlob . apply InitStatesReadValuesMonotone (σ:=σA) ?_ Hinitout . apply InitStatesReadValuesMonotone (σ:=σ) ?_ Hinitin simp only [List.unzip_snd] @@ -4411,21 +4411,21 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . exact (List.nodup_append.mp (List.nodup_append.mp Hgennd).2.1).2.1 . apply List.Disjoint.symm apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlob ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlob ·)) . exact HoldTemp . simp [genOldExprIdentsTrip_snd Heqold] apply List.Forall_PredImplies . apply List.Forall_filter . exact WFProgGlob Hwfp . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isGlob_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isGlob_isGlobOrLocl . simp [Holdtriplen] . apply List.Disjoint_Subset_right (ks:=(Imperative.HasVarsPure.getVars post)) . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . simp exact HoldTemp . have HH := prepostconditions_unwrap Hin.1 @@ -4438,7 +4438,7 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : have Hwf := (List.Forall_mem_iff.mp wfpost _ HH).glvars simp at Hwf exact Hwf - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . refine extractedOldVarsInVars ?_ have HH := prepostconditions_unwrap Hin.1 cases HH with @@ -4456,8 +4456,8 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . simp [Holdtriplen] . exact (List.nodup_append.mp (List.nodup_append.mp Hgennd).2.1).2.1 . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . exact HoldTemp . have HH := prepostconditions_unwrap Hin.1 cases HH with @@ -4469,13 +4469,13 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : have Hwf := (List.Forall_mem_iff.mp wfpost _ HH).glvars simp at Hwf exact Hwf - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl apply EvalExpressionUpdatedStates <;> try assumption . simp [Houttriplen] . exact (List.nodup_append.mp (List.nodup_append.mp Hgennd).2.1).1 . apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . exact HoutTemp . have HH := prepostconditions_unwrap Hin.1 cases HH with @@ -4487,7 +4487,7 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : have Hwf := (List.Forall_mem_iff.mp wfpost _ HH).glvars simp at Hwf exact Hwf - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl exact Hpost.2 . -- substStores, provable apply ReadValuesSubstStores (vs:=argVals ++ v1) @@ -4503,11 +4503,11 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . exact Hmodsnd . -- Disjoint between local and temp apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isLocl ·)) - (Q:=(BoogieIdent.isGlob ·)) + (P:=(CoreIdent.isLocl ·)) + (Q:=(CoreIdent.isGlob ·)) . exact Hinlc . exact Hmodglob - . exact BoogieIdent.Disjoint_isLocl_isGlob + . exact CoreIdent.Disjoint_isLocl_isGlob . apply UpdateStatesReadValuesMonotone (σ:=σAO) _ ?_ Hup1 . exact Hinoutnd . apply InitStatesReadValuesMonotone (σ:=σA) _ Hinitout @@ -4526,22 +4526,22 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . -- Disjoint between local and temp apply List.Disjoint.symm apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . exact List.Forall_append.mpr ⟨HoutTemp, HoldTemp⟩ - . refine List.Forall_PredImplies Houtlc BoogieIdent.isLocl_isGlobOrLocl - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . refine List.Forall_PredImplies Houtlc CoreIdent.isLocl_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . simp [Houtlen] . simp [InitStatesUpdated Hinitin] apply UpdatedStatesDisjNotDefMonotone . -- Disjoint between local and temp apply List.Disjoint.symm apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . exact List.Forall_append.mpr ⟨HoutTemp, HoldTemp⟩ - . refine List.Forall_PredImplies Hinlc BoogieIdent.isLocl_isGlobOrLocl - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . refine List.Forall_PredImplies Hinlc CoreIdent.isLocl_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . simp [← Hargtriplen, Harglen, ← Heqargs] . have Hndef := (Imperative.isNotDefinedApp' Hndefgen).2 exact UpdateStatesNotDefMonotone' Hndef Hupdate @@ -4552,20 +4552,20 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . simp [Holdtriplen] . -- Disjoint between local and temp apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . exact HoldTemp - . refine List.Forall_PredImplies Houtlc BoogieIdent.isLocl_isGlobOrLocl - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . refine List.Forall_PredImplies Houtlc CoreIdent.isLocl_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . apply ReadValuesUpdatedStates . simp [Houttriplen] . -- Disjoint between local and temp apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . exact HoutTemp - . refine List.Forall_PredImplies Houtlc BoogieIdent.isLocl_isGlobOrLocl - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . refine List.Forall_PredImplies Houtlc CoreIdent.isLocl_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . exact Hrd'.2.1 . apply ReadValuesApp . apply ReadValuesUpdatedStates @@ -4586,35 +4586,35 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : . simp [Holdtriplen] . -- Disjoint between local and temp apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isLocl ·)) . exact HoldTemp . exact Hlhs.2 . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isLocl_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isLocl_isGlobOrLocl . apply ReadValuesUpdatedStates . simp [Houttriplen] . -- Disjoint between local and temp apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isLocl ·)) . exact HoutTemp . exact Hlhs.2 . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isLocl_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isLocl_isGlobOrLocl . apply ReadValuesUpdatedStates . simp [Hargtriplen] . -- Disjoint between local and temp apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isLocl ·)) . exact HargTemp . exact Hlhs.2 . apply List.PredDisjoint_PredImplies_right - exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl - exact BoogieIdent.isLocl_isGlobOrLocl + exact CoreIdent.Disjoint_isTemp_isGlobOrLocl + exact CoreIdent.isLocl_isGlobOrLocl . apply ReadValuesUpdatedStates . exact ReadValuesLength Hrd'.2.2 . intros x Hin1 Hin2 @@ -4642,14 +4642,14 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : rw [List.map_fst_zip] . -- Disjoint between old labels and lhs, modified, and modvals apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . simp at HargTemp exact HargTemp . apply List.Forall_append.mpr ⟨?_, ?_⟩ - . exact List.Forall_PredImplies Hlhs.2 BoogieIdent.isLocl_isGlobOrLocl - . exact List.Forall_PredImplies Hmodglob BoogieIdent.isGlob_isGlobOrLocl - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . exact List.Forall_PredImplies Hlhs.2 CoreIdent.isLocl_isGlobOrLocl + . exact List.Forall_PredImplies Hmodglob CoreIdent.isGlob_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . simp_all . simp_all . -- Disjoint between old labels and lhs, modified, and modvals @@ -4657,14 +4657,14 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : rw [List.map_fst_zip] rw [List.map_fst_zip (l₂:=modvals)] apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . simp at HoutTemp exact HoutTemp . apply List.Forall_append.mpr ⟨?_, ?_⟩ - . exact List.Forall_PredImplies Hlhs.2 BoogieIdent.isLocl_isGlobOrLocl - . exact List.Forall_PredImplies Hmodglob BoogieIdent.isGlob_isGlobOrLocl - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . exact List.Forall_PredImplies Hlhs.2 CoreIdent.isLocl_isGlobOrLocl + . exact List.Forall_PredImplies Hmodglob CoreIdent.isGlob_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . have Hlen := UpdateStatesLength Hupdate omega . simp_all @@ -4673,14 +4673,14 @@ theorem callElimStatementCorrect [LawfulBEq Expression.Expr] : rw [List.map_fst_zip] rw [List.map_fst_zip (l₂:=modvals)] apply List.PredDisjoint_Disjoint - (P:=(BoogieIdent.isTemp ·)) - (Q:=(BoogieIdent.isGlobOrLocl ·)) + (P:=(CoreIdent.isTemp ·)) + (Q:=(CoreIdent.isGlobOrLocl ·)) . simp at HoldTemp exact HoldTemp . apply List.Forall_append.mpr ⟨?_, ?_⟩ - . exact List.Forall_PredImplies Hlhs.2 BoogieIdent.isLocl_isGlobOrLocl - . exact List.Forall_PredImplies Hmodglob BoogieIdent.isGlob_isGlobOrLocl - . exact BoogieIdent.Disjoint_isTemp_isGlobOrLocl + . exact List.Forall_PredImplies Hlhs.2 CoreIdent.isLocl_isGlobOrLocl + . exact List.Forall_PredImplies Hmodglob CoreIdent.isGlob_isGlobOrLocl + . exact CoreIdent.Disjoint_isTemp_isGlobOrLocl . have Hlen := UpdateStatesLength Hupdate omega . simp_all diff --git a/Strata/Transform/BoogieTransform.lean b/Strata/Transform/CoreTransform.lean similarity index 81% rename from Strata/Transform/BoogieTransform.lean rename to Strata/Transform/CoreTransform.lean index eeb313356..d4bd7664b 100644 --- a/Strata/Transform/BoogieTransform.lean +++ b/Strata/Transform/CoreTransform.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Statement -import Strata.Languages.Boogie.Boogie -import Strata.Languages.Boogie.BoogieGen +import Strata.Languages.Core.Statement +import Strata.Languages.Core.Core +import Strata.Languages.Core.CoreGen import Strata.DL.Util.LabelGen -/-! # Utility functions for program transformation in Boogie -/ +/-! # Utility functions for program transformation in Strata Core -/ -namespace Boogie +namespace Core namespace Transform open LabelGen @@ -34,18 +34,18 @@ def createFvars (ident : List Expression.Ident) := ident.map createFvar def genIdent (ident : Expression.Ident) (pf : String → String) - : BoogieGenM Expression.Ident := - BoogieGenState.gen (pf ident.name) + : CoreGenM Expression.Ident := + CoreGenState.gen (pf ident.name) /-- Generate identifiers in the form of arg_... that can be used to reduce argument expressions to temporary variables. -/ def genArgExprIdent - : BoogieGenM Expression.Ident := + : CoreGenM Expression.Ident := genIdent "arg" tmpVarPrefix def genArgExprIdents (n:Nat) - : BoogieGenM (List Expression.Ident) := + : CoreGenM (List Expression.Ident) := List.mapM (fun _ => genArgExprIdent) (List.replicate n ()) /-- @@ -53,11 +53,11 @@ Retrieves a fresh identifier from the counter generator the given identifier "id Assumes that ident contains no duplicates -/ def genOutExprIdent (ident : Expression.Ident) - : BoogieGenM Expression.Ident := + : CoreGenM Expression.Ident := genIdent ident tmpVarPrefix def genOutExprIdents (idents : List Expression.Ident) - : BoogieGenM (List Expression.Ident) + : CoreGenM (List Expression.Ident) := List.mapM genOutExprIdent idents /-- @@ -65,11 +65,11 @@ Retrieves a fresh identifier from the counter generator the given identifier "id Assumes that ident contains no duplicates -/ def genOldExprIdent (ident : Expression.Ident) - : BoogieGenM Expression.Ident := + : CoreGenM Expression.Ident := genIdent ident oldVarPrefix def genOldExprIdents (idents : List Expression.Ident) - : BoogieGenM (List Expression.Ident) + : CoreGenM (List Expression.Ident) := List.mapM genOldExprIdent idents /-- Checks whether a variable `ident` can be found in program `p` -/ @@ -78,18 +78,18 @@ def isGlobalVar (p : Program) (ident : Expression.Ident) : Bool := abbrev Err := String -abbrev BoogieTransformM := ExceptT Err BoogieGenM +abbrev CoreTransformM := ExceptT Err CoreGenM def getIdentTy? (p : Program) (id : Expression.Ident) := p.getVarTy? id def getIdentTy! (p : Program) (id : Expression.Ident) - : BoogieTransformM (Expression.Ty) := do + : CoreTransformM (Expression.Ty) := do match getIdentTy? p id with | none => throw s!"failed to find type for {Std.format id}" | some ty => return ty def getIdentTys! (p : Program) (ids : List Expression.Ident) - : BoogieTransformM (List Expression.Ty) := do + : CoreTransformM (List Expression.Ty) := do match ids with | [] => return [] | id :: rest => @@ -104,7 +104,7 @@ Only types of the 'inputs' parameter are used def genArgExprIdentsTrip (inputs : @Lambda.LTySignature Visibility) (args : List Expression.Expr) - : BoogieTransformM (List ((Expression.Ident × Lambda.LTy) × Expression.Expr)) + : CoreTransformM (List ((Expression.Ident × Lambda.LTy) × Expression.Expr)) := do if inputs.length ≠ args.length then throw "input length and args length mismatch" else let gen_idents ← genArgExprIdents args.length @@ -118,7 +118,7 @@ Only types of the 'outputs' parameter are used. def genOutExprIdentsTrip (outputs : @Lambda.LTySignature Visibility) (lhs : List Expression.Ident) - : BoogieTransformM (List ((Expression.Ident × Expression.Ty) × Expression.Ident)) := do + : CoreTransformM (List ((Expression.Ident × Expression.Ty) × Expression.Ident)) := do if outputs.length ≠ lhs.length then throw "output length and lhs length mismatch" else let gen_idents ← genOutExprIdents lhs return (gen_idents.zip outputs.unzip.2).zip lhs @@ -130,7 +130,7 @@ returned list has the shape def genOldExprIdentsTrip (p : Program) (ids : List Expression.Ident) - : BoogieTransformM (List ((Expression.Ident × Expression.Ty) × Expression.Ident)) := do + : CoreTransformM (List ((Expression.Ident × Expression.Ty) × Expression.Ident)) := do let gen_idents ← genOldExprIdents ids let tys ← getIdentTys! p ids return (gen_idents.zip tys).zip ids @@ -190,9 +190,9 @@ def createOldVarsSubst /- Generic runner functions -/ -- Only visit top-level statements and run f -def runStmts (f : Command → Program → BoogieTransformM (List Statement)) +def runStmts (f : Command → Program → CoreTransformM (List Statement)) (ss : List Statement) (inputProg : Program) - : BoogieTransformM (List Statement) := do + : CoreTransformM (List Statement) := do match ss with | [] => return [] | s :: ss => @@ -203,9 +203,9 @@ def runStmts (f : Command → Program → BoogieTransformM (List Statement)) return (← s') ++ (← ss') -- Recursively visit all blocks and run f -def runStmtsRec (f : Command → Program → BoogieTransformM (List Statement)) +def runStmtsRec (f : Command → Program → CoreTransformM (List Statement)) (ss : List Statement) (inputProg : Program) - : BoogieTransformM (List Statement) := do + : CoreTransformM (List Statement) := do match ss with | [] => return [] | s :: ss' => @@ -231,9 +231,9 @@ termination_by sizeOf ss decreasing_by all_goals (unfold Imperative.instSizeOfBlock; decreasing_tactic) -def runProcedures (f : Command → Program → BoogieTransformM (List Statement)) +def runProcedures (f : Command → Program → CoreTransformM (List Statement)) (dcls : List Decl) (inputProg : Program) - : BoogieTransformM (List Decl) := do + : CoreTransformM (List Decl) := do match dcls with | [] => return [] | d :: ds => @@ -244,23 +244,23 @@ def runProcedures (f : Command → Program → BoogieTransformM (List Statement) } md :: (← (runProcedures f ds inputProg)) | _ => return d :: (← (runProcedures f ds inputProg)) -def runProgram (f : Command → Program → BoogieTransformM (List Statement)) - (p : Program) : BoogieTransformM Program := do +def runProgram (f : Command → Program → CoreTransformM (List Statement)) + (p : Program) : CoreTransformM Program := do let newDecls ← runProcedures f p.decls p return { decls := newDecls } @[simp] -def runWith {α : Type} (p : α) (f : α → BoogieTransformM β) - (s : BoogieGenState): - Except Err β × BoogieGenState := +def runWith {α : Type} (p : α) (f : α → CoreTransformM β) + (s : CoreGenState): + Except Err β × CoreGenState := (StateT.run (f p) s) @[simp] -def run {α : Type} (p : α) (f : α → BoogieTransformM β) - (s : BoogieGenState := .emp): +def run {α : Type} (p : α) (f : α → CoreTransformM β) + (s : CoreGenState := .emp): Except Err β := (runWith p f s).fst end Transform -end Boogie +end Core diff --git a/Strata/Transform/DetToNondet.lean b/Strata/Transform/DetToNondet.lean index 37313a927..ec163de41 100644 --- a/Strata/Transform/DetToNondet.lean +++ b/Strata/Transform/DetToNondet.lean @@ -7,7 +7,7 @@ import Strata.DL.Imperative.Cmd import Strata.DL.Imperative.Stmt import Strata.DL.Imperative.NondetStmt -import Strata.Languages.Boogie.StatementType +import Strata.Languages.Core.StatementType /-! # Deterministic-to-Nondeterministic Transformation -/ diff --git a/Strata/Transform/DetToNondetCorrect.lean b/Strata/Transform/DetToNondetCorrect.lean index 86c5e62d5..9b22a9922 100644 --- a/Strata/Transform/DetToNondetCorrect.lean +++ b/Strata/Transform/DetToNondetCorrect.lean @@ -16,7 +16,7 @@ import Strata.Transform.DetToNondet `StmtToNondetStmtCorrect`) -/ -open Imperative Boogie +open Imperative Core /-- The proof implementation for `StmtToNondetStmtCorrect` and diff --git a/Strata/Transform/LoopElim.lean b/Strata/Transform/LoopElim.lean index 1a5f435f2..69d8e5772 100644 --- a/Strata/Transform/LoopElim.lean +++ b/Strata/Transform/LoopElim.lean @@ -6,7 +6,7 @@ import Strata.DL.Imperative.Stmt -namespace Boogie +namespace Core open Imperative Lambda /-! ## Loop elimination diff --git a/Strata/Transform/ProcedureInlining.lean b/Strata/Transform/ProcedureInlining.lean index 0c6abe73a..8f40ca343 100644 --- a/Strata/Transform/ProcedureInlining.lean +++ b/Strata/Transform/ProcedureInlining.lean @@ -6,15 +6,15 @@ import Strata.DL.Util.LabelGen import Strata.DL.Util.ListUtils -import Strata.Languages.Boogie.Boogie -import Strata.Languages.Boogie.BoogieGen -import Strata.Languages.Boogie.ProgramWF -import Strata.Languages.Boogie.Statement -import Strata.Transform.BoogieTransform +import Strata.Languages.Core.Core +import Strata.Languages.Core.CoreGen +import Strata.Languages.Core.ProgramWF +import Strata.Languages.Core.Statement +import Strata.Transform.CoreTransform /-! # Procedure Inlining Transformation -/ -namespace Boogie +namespace Core namespace ProcedureInlining open Transform @@ -26,7 +26,7 @@ def Block.substFvar (b : Block) (fr:Expression.Ident) termination_by b.sizeOf decreasing_by apply Imperative.sizeOf_stmt_in_block; assumption -def Statement.substFvar (s : Boogie.Statement) +def Statement.substFvar (s : Core.Statement) (fr:Expression.Ident) (to:Expression.Expr) : Statement := match s with @@ -65,7 +65,7 @@ def Block.renameLhs (b : Block) (fr: Lambda.Identifier Visibility) (to: Lambda.I termination_by b.sizeOf decreasing_by apply Imperative.sizeOf_stmt_in_block; assumption -def Statement.renameLhs (s : Boogie.Statement) (fr: Lambda.Identifier Visibility) (to: Lambda.Identifier Visibility) +def Statement.renameLhs (s : Core.Statement) (fr: Lambda.Identifier Visibility) (to: Lambda.Identifier Visibility) : Statement := match s with | .init lhs ty rhs metadata => @@ -95,7 +95,7 @@ def Block.labels (b : Block): List String := -- Assume and Assert's labels have special meanings, so they must not be -- mangled during procedure inlining. -def Statement.labels (s : Boogie.Statement) : List String := +def Statement.labels (s : Core.Statement) : List String := match s with | .block lbl b _ => lbl :: (Block.labels b) | .ite _ thenb elseb _ => (Block.labels thenb) ++ (Block.labels elseb) @@ -114,7 +114,7 @@ def Block.replaceLabels (b : Block) (map:Map String String) decreasing_by apply Imperative.sizeOf_stmt_in_block; assumption def Statement.replaceLabels - (s : Boogie.Statement) (map:Map String String) : Boogie.Statement := + (s : Core.Statement) (map:Map String String) : Core.Statement := let app (s:String) := match Map.find? map s with | .none => s @@ -135,7 +135,7 @@ end private def genOldToFreshIdMappings (old_vars : List Expression.Ident) (prev_map : Map Expression.Ident Expression.Ident) (prefix_ : String) - : BoogieTransformM (Map Expression.Ident Expression.Ident) := do + : CoreTransformM (Map Expression.Ident Expression.Ident) := do let prev_map <- old_vars.foldlM (fun var_map id => do let new_name <- genIdent id (fun s => prefix_ ++ "_" ++ s) @@ -144,7 +144,7 @@ private def genOldToFreshIdMappings (old_vars : List Expression.Ident) return prev_map private def renameAllLocalNames (c:Procedure) - : BoogieTransformM (Procedure × Map Expression.Ident Expression.Ident) := do + : CoreTransformM (Procedure × Map Expression.Ident Expression.Ident) := do let var_map: Map Expression.Ident Expression.Ident := [] let proc_name := c.header.name.name @@ -194,7 +194,7 @@ the reachability query. -/ def inlineCallCmd (excluded_calls:List String := []) (cmd: Command) (p : Program) - : BoogieTransformM (List Statement) := + : CoreTransformM (List Statement) := open Lambda in do match cmd with | .call lhs procName args _ => @@ -223,7 +223,7 @@ def inlineCallCmd (excluded_calls:List String := []) -- set x1 := out1 --- outputSetStmts -- set x2 := out2 -- `init outN` is not necessary because calls are only allowed to use - -- already declared variables (per Boogie.typeCheck) + -- already declared variables (per Core.typeCheck) -- Create a fresh var statement for each LHS let outputTrips ← genOutExprIdentsTrip sigOutputs sigOutputs.unzip.fst @@ -248,7 +248,7 @@ def inlineCallCmd (excluded_calls:List String := []) Statement.set lhs_var (.fvar () out_var (.none))) outs_lhs_and_sig - let stmts:List (Imperative.Stmt Boogie.Expression Boogie.Command) + let stmts:List (Imperative.Stmt Core.Expression Core.Command) := inputInits ++ outputInits ++ outputHavocs ++ proc.body ++ outputSetStmts @@ -257,12 +257,12 @@ def inlineCallCmd (excluded_calls:List String := []) | _ => return [.cmd cmd] def inlineCallStmtsRec (ss: List Statement) (prog : Program) - : BoogieTransformM (List Statement) := + : CoreTransformM (List Statement) := runStmtsRec inlineCallCmd ss prog def inlineCallL (dcls : List Decl) (prog : Program) - : BoogieTransformM (List Decl) := + : CoreTransformM (List Decl) := runProcedures inlineCallCmd dcls prog end ProcedureInlining -end Boogie +end Core diff --git a/BoogieToGoto.lean b/StrataCoreToGoto.lean similarity index 81% rename from BoogieToGoto.lean rename to StrataCoreToGoto.lean index 49a7f3a66..329c7824c 100644 --- a/BoogieToGoto.lean +++ b/StrataCoreToGoto.lean @@ -10,9 +10,9 @@ import StrataTest.Backends.CBMC.SimpleAdd.SimpleAdd def main (args : List String) : IO Unit := do match args with | ["writeFiles"] => - BoogieToGOTO.writeToGotoJson (programName := "simpleAdd") + CoreToGOTO.writeToGotoJson (programName := "simpleAdd") (symTabFileName := "StrataTest/Backends/CBMC/SimpleAdd/simpleAdd.symtab.json") (gotoFileName := "StrataTest/Backends/CBMC/SimpleAdd/simpleAdd.goto.json") Strata.simpleAdd IO.println "Written JSON files in StrataTest/Backends/CBMC/SimpleAdd/" - | _ => IO.println "Bad usage of BoogieToGoto" + | _ => IO.println "Bad usage of StrataCoreToGoto" diff --git a/StrataMain.lean b/StrataMain.lean index 5556a1c8c..d0ded56ce 100644 --- a/StrataMain.lean +++ b/StrataMain.lean @@ -12,7 +12,7 @@ import Strata.Util.IO import Strata.DDM.Integration.Java.Gen import Strata.Languages.Python.Python -import Strata.Transform.BoogieTransform +import Strata.Transform.CoreTransform import Strata.Transform.ProcedureInlining def exitFailure {α} (message : String) : IO α := do @@ -182,12 +182,12 @@ def readPythonStrata (path : String) : IO Strata.Program := do def pyTranslateCommand : Command where name := "pyTranslate" args := [ "file" ] - help := "Translate a Strata Python Ion file to Strata.Boogie. Write results to stdout." + help := "Translate a Strata Python Ion file to Strata Core. Write results to stdout." callback := fun _ v => do let pgm ← readPythonStrata v[0] - let preludePgm := Strata.Python.Internal.Boogie.prelude - let bpgm := Strata.pythonToBoogie Strata.Python.Internal.signatures pgm - let newPgm : Boogie.Program := { decls := preludePgm.decls ++ bpgm.decls } + let preludePgm := Strata.Python.Internal.Core.prelude + let bpgm := Strata.pythonToCore Strata.Python.Internal.signatures pgm + let newPgm : Core.Program := { decls := preludePgm.decls ++ bpgm.decls } IO.print newPgm def pyAnalyzeCommand : Command where @@ -199,13 +199,13 @@ def pyAnalyzeCommand : Command where let pgm ← readPythonStrata v[0] if verbose then IO.print pgm - let preludePgm := Strata.Python.Internal.Boogie.prelude - let bpgm := Strata.pythonToBoogie Strata.Python.Internal.signatures pgm - let newPgm : Boogie.Program := { decls := preludePgm.decls ++ bpgm.decls } + let preludePgm := Strata.Python.Internal.Core.prelude + let bpgm := Strata.pythonToCore Strata.Python.Internal.signatures pgm + let newPgm : Core.Program := { decls := preludePgm.decls ++ bpgm.decls } if verbose then IO.print newPgm - match Boogie.Transform.runProgram - (Boogie.ProcedureInlining.inlineCallCmd (excluded_calls := ["main"])) + match Core.Transform.runProgram + (Core.ProcedureInlining.inlineCallCmd (excluded_calls := ["main"])) newPgm .emp with | ⟨.error e, _⟩ => panic! e | ⟨.ok newPgm, _⟩ => @@ -217,7 +217,7 @@ def pyAnalyzeCommand : Command where let vcResults ← IO.FS.withTempDir (fun tempDir => EIO.toIO (fun f => IO.Error.userError (toString f)) - (Boogie.verify solverName newPgm tempDir + (Core.verify solverName newPgm tempDir { Options.default with stopOnFirstError := false, verbose := verboseMode, removeIrrelevantAxioms := true } (moreFns := Strata.Python.ReFactory))) let mut s := "" diff --git a/StrataTest/Backends/CBMC/BoogieToCProverGOTO.lean b/StrataTest/Backends/CBMC/CoreToCProverGOTO.lean similarity index 65% rename from StrataTest/Backends/CBMC/BoogieToCProverGOTO.lean rename to StrataTest/Backends/CBMC/CoreToCProverGOTO.lean index a3035cbce..d5cfa0a46 100644 --- a/StrataTest/Backends/CBMC/BoogieToCProverGOTO.lean +++ b/StrataTest/Backends/CBMC/CoreToCProverGOTO.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier import Strata.Backends.CBMC.GOTO.InstToJson import StrataTest.Backends.CBMC.ToCProverGOTO open Std (ToFormat Format format) /- -We map Boogie's procedures to a CProverGOTO program, which is then written to +We map Strata Core's procedures to a CProverGOTO program, which is then written to CBMC-compatible JSON files that contain all the necessary information to construct a GOTO binary. @@ -21,20 +21,20 @@ model-check a Strata-generated GOTO binary. ------------------------------------------------------------------------------- -abbrev BoogieParams : Lambda.LExprParams := ⟨Unit, Boogie.Visibility⟩ +abbrev CoreParams : Lambda.LExprParams := ⟨Unit, Core.Visibility⟩ -abbrev Boogie.ExprStr : Imperative.PureExpr := - { Ident := BoogieParams.Identifier, - Expr := Lambda.LExpr BoogieParams.mono, +abbrev Core.ExprStr : Imperative.PureExpr := + { Ident := CoreParams.Identifier, + Expr := Lambda.LExpr CoreParams.mono, Ty := Lambda.LTy, - TyEnv := @Lambda.TEnv BoogieParams.IDMeta, - TyContext := @Lambda.LContext BoogieParams, - EvalEnv := Lambda.LState BoogieParams - EqIdent := inferInstanceAs (DecidableEq BoogieParams.Identifier) } + TyEnv := @Lambda.TEnv CoreParams.IDMeta, + TyContext := @Lambda.LContext CoreParams, + EvalEnv := Lambda.LState CoreParams + EqIdent := inferInstanceAs (DecidableEq CoreParams.Identifier) } -namespace BoogieToGOTO +namespace CoreToGOTO -private def lookupType (T : Boogie.Expression.TyEnv) (i : Boogie.Expression.Ident) : +private def lookupType (T : Core.Expression.TyEnv) (i : Core.Expression.Ident) : Except Format CProverGOTO.Ty := match T.context.types.find? i with | none => .error s!"Cannot find {i} in the type context!" @@ -44,18 +44,18 @@ private def lookupType (T : Boogie.Expression.TyEnv) (i : Boogie.Expression.Iden ty.toGotoType else .error f!"Poly-type unexpected in the context for {i}: {ty}" -private def updateType (T : Boogie.Expression.TyEnv) (i : Boogie.Expression.Ident) - (ty : Boogie.Expression.Ty) : Boogie.Expression.TyEnv := - @Lambda.TEnv.insertInContext ⟨Boogie.ExpressionMetadata, Boogie.Visibility⟩ _ T i ty +private def updateType (T : Core.Expression.TyEnv) (i : Core.Expression.Ident) + (ty : Core.Expression.Ty) : Core.Expression.TyEnv := + @Lambda.TEnv.insertInContext ⟨Core.ExpressionMetadata, Core.Visibility⟩ _ T i ty -instance : Imperative.ToGoto Boogie.Expression where +instance : Imperative.ToGoto Core.Expression where lookupType := lookupType updateType := updateType identToString := (fun i => i.toPretty) toGotoType := (fun ty => Lambda.LMonoTy.toGotoType ty.toMonoTypeUnsafe) toGotoExpr := Lambda.LExpr.toGotoExpr -private def lookupTypeStr (T : Boogie.ExprStr.TyEnv) (i : Boogie.ExprStr.Ident) : +private def lookupTypeStr (T : Core.ExprStr.TyEnv) (i : Core.ExprStr.Ident) : Except Format CProverGOTO.Ty := match T.context.types.find? i with | none => .error s!"Cannot find {i} in the type context!" @@ -65,11 +65,11 @@ private def lookupTypeStr (T : Boogie.ExprStr.TyEnv) (i : Boogie.ExprStr.Ident) ty.toGotoType else .error f!"Poly-type unexpected in the context for {i}: {ty}" -private def updateTypeStr (T : Boogie.ExprStr.TyEnv) (i : Boogie.ExprStr.Ident) - (ty : Boogie.ExprStr.Ty) : Boogie.ExprStr.TyEnv := +private def updateTypeStr (T : Core.ExprStr.TyEnv) (i : Core.ExprStr.Ident) + (ty : Core.ExprStr.Ty) : Core.ExprStr.TyEnv := T.insertInContext i ty -instance : Imperative.ToGoto Boogie.ExprStr where +instance : Imperative.ToGoto Core.ExprStr where lookupType := lookupTypeStr updateType := updateTypeStr identToString := (fun x => x.name) @@ -78,36 +78,36 @@ instance : Imperative.ToGoto Boogie.ExprStr where open Lambda in def substVarNames {Metadata IDMeta: Type} [DecidableEq IDMeta] - (e : LExpr ⟨⟨Metadata, IDMeta⟩, LMonoTy⟩) (frto : Map String String) : (LExpr ⟨⟨Unit, Boogie.Visibility⟩, LMonoTy⟩) := + (e : LExpr ⟨⟨Metadata, IDMeta⟩, LMonoTy⟩) (frto : Map String String) : (LExpr ⟨⟨Unit, Core.Visibility⟩, LMonoTy⟩) := match e with | .const _ c => .const () c | .bvar _ b => .bvar () b - | .op _ o ty => .op () (Lambda.Identifier.mk o.name Boogie.Visibility.unres) ty + | .op _ o ty => .op () (Lambda.Identifier.mk o.name Core.Visibility.unres) ty | .fvar _ name ty => let name_alt := frto.find? name.name - .fvar () (Lambda.Identifier.mk (name_alt.getD name.name) Boogie.Visibility.unres) ty + .fvar () (Lambda.Identifier.mk (name_alt.getD name.name) Core.Visibility.unres) ty | .abs _ ty e' => .abs () ty (substVarNames e' frto) | .quant _ qk ty tr' e' => .quant () qk ty (substVarNames tr' frto) (substVarNames e' frto) | .app _ f e' => .app () (substVarNames f frto) (substVarNames e' frto) | .ite _ c t e' => .ite () (substVarNames c frto) (substVarNames t frto) (substVarNames e' frto) | .eq _ e1 e2 => .eq () (substVarNames e1 frto) (substVarNames e2 frto) -def Boogie.Cmd.renameVars (frto : Map String String) (c : Imperative.Cmd Boogie.Expression) - : Imperative.Cmd Boogie.ExprStr := +def Core.Cmd.renameVars (frto : Map String String) (c : Imperative.Cmd Core.Expression) + : Imperative.Cmd Core.ExprStr := match c with | .init name ty e _ => let e' := substVarNames e frto - let name_alt := frto.find? (Boogie.BoogieIdent.toPretty name) - let new := name_alt.getD (Boogie.BoogieIdent.toPretty name) + let name_alt := frto.find? (Core.CoreIdent.toPretty name) + let new := name_alt.getD (Core.CoreIdent.toPretty name) .init new ty e' .empty | .set name e _ => let e' := substVarNames e frto - let name_alt := frto.find? (Boogie.BoogieIdent.toPretty name) - let new := name_alt.getD (Boogie.BoogieIdent.toPretty name) + let name_alt := frto.find? (Core.CoreIdent.toPretty name) + let new := name_alt.getD (Core.CoreIdent.toPretty name) .set new e' .empty | .havoc name _ => - let name_alt := frto.find? (Boogie.BoogieIdent.toPretty name) - let new := name_alt.getD (Boogie.BoogieIdent.toPretty name) + let name_alt := frto.find? (Core.CoreIdent.toPretty name) + let new := name_alt.getD (Core.CoreIdent.toPretty name) .havoc new .empty | .assume label e _ => let e' := substVarNames e frto @@ -119,11 +119,11 @@ def Boogie.Cmd.renameVars (frto : Map String String) (c : Imperative.Cmd Boogie. let e' := substVarNames e frto .cover label e' .empty -def Boogie.Cmds.renameVars (frto : Map String String) - (cs : Imperative.Cmds Boogie.Expression) : Imperative.Cmds Boogie.ExprStr := +def Core.Cmds.renameVars (frto : Map String String) + (cs : Imperative.Cmds Core.Expression) : Imperative.Cmds Core.ExprStr := match cs with | [] => [] - | c :: crest => [(Boogie.Cmd.renameVars frto c)] ++ (renameVars frto crest) + | c :: crest => [(Core.Cmd.renameVars frto c)] ++ (renameVars frto crest) ------------------------------------------------------------------------------- @@ -155,48 +155,48 @@ def CProverGOTO.Context.toJson (programName : String) (ctx : CProverGOTO.Context { symtab := symbols, goto := goto_functions } open Lambda.LTy.Syntax in -def transformToGoto (boogie : Boogie.Program) : Except Format CProverGOTO.Context := do - let Ctx := { Lambda.LContext.default with functions := Boogie.Factory, knownTypes := Boogie.KnownTypes } +def transformToGoto (cprog : Core.Program) : Except Format CProverGOTO.Context := do + let Ctx := { Lambda.LContext.default with functions := Core.Factory, knownTypes := Core.KnownTypes } let Env := Lambda.TEnv.default - let (boogie, _Env) ← Boogie.Program.typeCheck Ctx Env boogie - dbg_trace f!"[Strata.Boogie] Type Checking Succeeded!" - if h : boogie.decls.length = 1 then - let decl := boogie.decls[0]'(by exact Nat.lt_of_sub_eq_succ h) + let (cprog, _Env) ← Core.Program.typeCheck Ctx Env cprog + dbg_trace f!"[Strata.Core] Type Checking Succeeded!" + if h : cprog.decls.length = 1 then + let decl := cprog.decls[0]'(by exact Nat.lt_of_sub_eq_succ h) match decl.getProc? with - | none => .error f!"[transformToGoto] We can process only Boogie procedures at this time. \ + | none => .error f!"[transformToGoto] We can process only Strata Core procedures at this time. \ Declaration encountered: {decl}" | some p => - let pname := Boogie.BoogieIdent.toPretty p.header.name + let pname := Core.CoreIdent.toPretty p.header.name if !p.header.typeArgs.isEmpty then - .error f!"[transformToGoto] Translation for polymorphic Boogie procedures is unimplemented." + .error f!"[transformToGoto] Translation for polymorphic Strata Core procedures is unimplemented." let cmds ← p.body.mapM (fun b => match b with | .cmd (.cmd c) => return c - | _ => .error f!"[transformToGoto] We can process Boogie commands only, not statements! \ + | _ => .error f!"[transformToGoto] We can process Strata Core commands only, not statements! \ Statement encountered: {b}") if 1 < p.header.outputs.length then - .error f!"[transformToGoto] Translation for multi-return value Boogie procedures is unimplemented." + .error f!"[transformToGoto] Translation for multi-return value Strata Core procedures is unimplemented." let ret_tys ← p.header.outputs.values.mapM (fun ty => Lambda.LMonoTy.toGotoType ty) let ret_ty := if ret_tys.isEmpty then CProverGOTO.Ty.Empty else ret_tys[0]! - let formals := p.header.inputs.keys.map Boogie.BoogieIdent.toPretty + let formals := p.header.inputs.keys.map Core.CoreIdent.toPretty let formals_tys ← p.header.inputs.values.mapM (fun ty => Lambda.LMonoTy.toGotoType ty) let new_formals := formals.map (fun f => CProverGOTO.mkFormalSymbol pname f) let formals_renamed := formals.zip new_formals let formals_tys : Map String CProverGOTO.Ty := formals.zip formals_tys - let locals := (Imperative.Block.definedVars p.body).map Boogie.BoogieIdent.toPretty + let locals := (Imperative.Block.definedVars p.body).map Core.CoreIdent.toPretty let new_locals := locals.map (fun l => CProverGOTO.mkLocalSymbol pname l) let locals_renamed := locals.zip new_locals let args_renamed := formals_renamed ++ locals_renamed - let cmds := Boogie.Cmds.renameVars args_renamed cmds + let cmds := Core.Cmds.renameVars args_renamed cmds - let ans ← @Imperative.Cmds.toGotoTransform Boogie.ExprStr - BoogieToGOTO.instToGotoExprStr _ Env pname cmds (loc := 0) + let ans ← @Imperative.Cmds.toGotoTransform Core.ExprStr + CoreToGOTO.instToGotoExprStr _ Env pname cmds (loc := 0) let ending_insts : Array CProverGOTO.Instruction := #[ -- (FIXME): Add lifetime markers. -- { type := .DEAD, locationNum := ans.nextLoc + 1, @@ -204,7 +204,7 @@ def transformToGoto (boogie : Boogie.Program) : Except Format CProverGOTO.Contex { type := .END_FUNCTION, locationNum := ans.nextLoc + 1}] let insts := ans.instructions ++ ending_insts - let pgm := { name := Boogie.BoogieIdent.toPretty p.header.name, + let pgm := { name := Core.CoreIdent.toPretty p.header.name, parameterIdentifiers := new_formals.toArray, instructions := insts } @@ -213,14 +213,14 @@ def transformToGoto (boogie : Boogie.Program) : Except Format CProverGOTO.Contex ret := ret_ty, locals := locals } else - .error f!"[transformToGoto] We can transform only a single Boogie procedure to \ + .error f!"[transformToGoto] We can transform only a single Strata Core procedure to \ GOTO at a time!" open Strata in def getGotoJson (programName : String) (env : Program) : IO CProverGOTO.Json := do let (program, errors) := TransM.run Inhabited.default (translateProgram env) if errors.isEmpty then - (match (BoogieToGOTO.transformToGoto program) with + (match (CoreToGOTO.transformToGoto program) with | .error e => dbg_trace s!"{e}" return {} @@ -235,6 +235,6 @@ def writeToGotoJson (programName symTabFileName gotoFileName : String) (env : Pr IO.FS.writeFile symTabFileName json.symtab.pretty IO.FS.writeFile gotoFileName json.goto.pretty -end BoogieToGOTO +end CoreToGOTO ------------------------------------------------------------------------------- diff --git a/StrataTest/Backends/CBMC/SimpleAdd/SimpleAdd.lean b/StrataTest/Backends/CBMC/SimpleAdd/SimpleAdd.lean index 08d460ddf..e1f9b5d76 100644 --- a/StrataTest/Backends/CBMC/SimpleAdd/SimpleAdd.lean +++ b/StrataTest/Backends/CBMC/SimpleAdd/SimpleAdd.lean @@ -4,7 +4,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import StrataTest.Backends.CBMC.BoogieToCProverGOTO +import StrataTest.Backends.CBMC.CoreToCProverGOTO open Std (ToFormat Format format) ------------------------------------------------------------------------------- @@ -13,7 +13,7 @@ namespace Strata protected def simpleAdd : Program := #strata -program Boogie; +program Core; procedure simpleAdd (x : bv32, y : bv32) returns () { assume (x < bv{32}(0xFFFF0000)); @@ -27,9 +27,9 @@ procedure simpleAdd (x : bv32, y : bv32) returns () { }; #end --- #eval BoogieToGOTO.getGotoJson "simpleAddU" Strata.simpleAddU +-- #eval CoreToGOTO.getGotoJson "simpleAddU" Strata.simpleAddU --- #eval BoogieToGOTO.writeToGotoJson (programName := "simpleAdd") +-- #eval CoreToGOTO.writeToGotoJson (programName := "simpleAdd") -- (symTabFileName := "StrataTest/Backends/CBMC/SimpleAdd/simpleAdd.symtab.json") -- (gotoFileName := "StrataTest/Backends/CBMC/SimpleAdd/simpleAdd.goto.json") -- Strata.simpleAdd diff --git a/StrataTest/Backends/CBMC/SimpleAdd/mkGotoBin.sh b/StrataTest/Backends/CBMC/SimpleAdd/mkGotoBin.sh index c1d6553c7..95735407c 100755 --- a/StrataTest/Backends/CBMC/SimpleAdd/mkGotoBin.sh +++ b/StrataTest/Backends/CBMC/SimpleAdd/mkGotoBin.sh @@ -4,9 +4,9 @@ echo "Cleaning any previous artifacts" rm -f *.json rm -f *.gb -echo "Writing out JSON files from a Strata.Boogie program SimpleAdd" +echo "Writing out JSON files from a Strata Core program SimpleAdd" pushd ../../../../ -lake exe BoogieToGoto writeFiles +lake exe StrataCoreToGoto writeFiles popd # Merge generated file ../simpleAdd.symtab.json with diff --git a/StrataTest/Backends/CBMC/run_tests.sh b/StrataTest/Backends/CBMC/run_tests.sh index 8a0417a5d..f83f02c4d 100755 --- a/StrataTest/Backends/CBMC/run_tests.sh +++ b/StrataTest/Backends/CBMC/run_tests.sh @@ -5,9 +5,9 @@ echo "First: tests for the C-like AST interface." pushd ../../../ -echo "Boogie -> CBMC: illustrates verification fail." +echo "Strata Core -> CBMC: illustrates verification fail." echo "----------------------------------------------------------------------" -Strata/Backends/CBMC/run_strata_cbmc.sh Strata/Backends/CBMC/tests/simpleTest.boogie.st +Strata/Backends/CBMC/run_strata_cbmc.sh Strata/Backends/CBMC/tests/simpleTest.core.st echo "######################################################################" diff --git a/StrataTest/DDM/Integration/Java/TestGen.lean b/StrataTest/DDM/Integration/Java/TestGen.lean index 40d390af4..439808ea3 100644 --- a/StrataTest/DDM/Integration/Java/TestGen.lean +++ b/StrataTest/DDM/Integration/Java/TestGen.lean @@ -7,7 +7,7 @@ import Strata.DDM.Integration.Java import Strata.DDM.Integration.Lean.Env -- For dialectExt import Strata.DDM.Integration.Lean.HashCommands -- For #load_dialect -import Strata.Languages.Boogie.DDMTransform.Parse -- Loads Boogie dialect into env +import Strata.Languages.Core.DDMTransform.Parse -- Loads Strata Core dialect into env namespace Strata.Java.Test @@ -223,19 +223,19 @@ def check (s sub : String) : Bool := (s.splitOn sub).length > 1 assert! files.interfaces.any (fun i => check i.2 "non-sealed interface Expr") pure () --- Test 10: Boogie dialect returns error (has type/function declarations not yet supported) -elab "#testBoogieError" : command => do +-- Test 10: Core dialect returns error (has type/function declarations not yet supported) +elab "#testCoreError" : command => do let env ← Lean.getEnv let state := Strata.dialectExt.getState env - let some boogie := state.loaded.dialects["Boogie"]? - | Lean.logError "Boogie dialect not found"; return - match generateDialect boogie "com.strata.boogie" with + let some core := state.loaded.dialects["Core"]? + | Lean.logError "Core dialect not found"; return + match generateDialect core "com.strata.core" with | .error msg => if !(check msg "type declaration" || check msg "function declaration") then Lean.logError s!"Expected error about type/function declaration, got: {msg}" - | .ok _ => Lean.logError "Expected error for Boogie dialect" + | .ok _ => Lean.logError "Expected error for Core dialect" -#testBoogieError +#testCoreError -- Test 11: Cross-dialect name collision (A.Num vs B.Num) #eval do diff --git a/StrataTest/Internal/InternalBoogiePrelude.lean b/StrataTest/Internal/InternalCorePrelude.lean similarity index 52% rename from StrataTest/Internal/InternalBoogiePrelude.lean rename to StrataTest/Internal/InternalCorePrelude.lean index f44231686..e55fcaa5b 100644 --- a/StrataTest/Internal/InternalBoogiePrelude.lean +++ b/StrataTest/Internal/InternalCorePrelude.lean @@ -6,15 +6,15 @@ import Strata.DDM.Elab import Strata.DDM.AST -import Strata.Languages.Boogie.DDMTransform.Parse -import Strata.Languages.Boogie.Verifier -import Strata.Languages.Python.BoogiePrelude +import Strata.Languages.Core.DDMTransform.Parse +import Strata.Languages.Core.Verifier +import Strata.Languages.Python.CorePrelude namespace Strata namespace Python namespace Internal -def Boogie.prelude : Boogie.Program := Strata.Boogie.prelude +def Core.prelude : Core.Program := Strata.Core.prelude end Internal end Python diff --git a/StrataTest/Internal/InternalFunctionSignatures.lean b/StrataTest/Internal/InternalFunctionSignatures.lean index a286a750c..ba6b1409c 100644 --- a/StrataTest/Internal/InternalFunctionSignatures.lean +++ b/StrataTest/Internal/InternalFunctionSignatures.lean @@ -4,7 +4,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Boogie +import Strata.Languages.Core.Core import Strata.Languages.Python.FunctionSignatures namespace Strata diff --git a/StrataTest/Languages/C_Simp/Examples/Coprime.lean b/StrataTest/Languages/C_Simp/Examples/Coprime.lean index 7c877fe80..544331d22 100644 --- a/StrataTest/Languages/C_Simp/Examples/Coprime.lean +++ b/StrataTest/Languages/C_Simp/Examples/Coprime.lean @@ -111,4 +111,4 @@ else{} return := #true -/ #guard_msgs in -#eval Strata.to_boogie (Strata.C_Simp.get_program CoprimePgm) +#eval Strata.to_core (Strata.C_Simp.get_program CoprimePgm) diff --git a/StrataTest/Languages/C_Simp/Examples/LinearSearch.lean b/StrataTest/Languages/C_Simp/Examples/LinearSearch.lean index 99dae219c..ef1b23689 100644 --- a/StrataTest/Languages/C_Simp/Examples/LinearSearch.lean +++ b/StrataTest/Languages/C_Simp/Examples/LinearSearch.lean @@ -102,4 +102,4 @@ else{} return := #false -/ #guard_msgs in -#eval Strata.to_boogie (Strata.C_Simp.get_program LinearSearchEnv) +#eval Strata.to_core (Strata.C_Simp.get_program LinearSearchEnv) diff --git a/StrataTest/Languages/C_Simp/Examples/LoopSimple.lean b/StrataTest/Languages/C_Simp/Examples/LoopSimple.lean index 4aa5702a7..a24c70fd7 100644 --- a/StrataTest/Languages/C_Simp/Examples/LoopSimple.lean +++ b/StrataTest/Languages/C_Simp/Examples/LoopSimple.lean @@ -104,10 +104,10 @@ assert [sum_assert] (((~Int.Div ((~Int.Mul n) ((~Int.Sub n) #1))) #2) == sum) return := sum -/ #guard_msgs in -#eval Strata.to_boogie (Strata.C_Simp.get_program LoopSimplePgm) +#eval Strata.to_core (Strata.C_Simp.get_program LoopSimplePgm) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/C_Simp/Examples/LoopTrivial.lean b/StrataTest/Languages/C_Simp/Examples/LoopTrivial.lean index 98488be05..69c7cb712 100644 --- a/StrataTest/Languages/C_Simp/Examples/LoopTrivial.lean +++ b/StrataTest/Languages/C_Simp/Examples/LoopTrivial.lean @@ -94,10 +94,10 @@ assert [i_eq_n] (i == n) return := i -/ #guard_msgs in -#eval Strata.to_boogie (Strata.C_Simp.get_program LoopTrivialPgm) +#eval Strata.to_core (Strata.C_Simp.get_program LoopTrivialPgm) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/C_Simp/Examples/Min.lean b/StrataTest/Languages/C_Simp/Examples/Min.lean index 47070cf70..ae67754fe 100644 --- a/StrataTest/Languages/C_Simp/Examples/Min.lean +++ b/StrataTest/Languages/C_Simp/Examples/Min.lean @@ -56,7 +56,7 @@ open Strata.C_Simp in #eval TransM.run (translateProgram (MinPgm.commands)) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/C_Simp/Examples/SimpleTest.lean b/StrataTest/Languages/C_Simp/Examples/SimpleTest.lean index 9a9255c16..c348b19d2 100644 --- a/StrataTest/Languages/C_Simp/Examples/SimpleTest.lean +++ b/StrataTest/Languages/C_Simp/Examples/SimpleTest.lean @@ -72,7 +72,7 @@ open Strata.C_Simp in #eval TransM.run (translateProgram (SimpleTestEnv.commands)) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/C_Simp/Examples/Trivial.lean b/StrataTest/Languages/C_Simp/Examples/Trivial.lean index 0bd2d41b6..dc63027a0 100644 --- a/StrataTest/Languages/C_Simp/Examples/Trivial.lean +++ b/StrataTest/Languages/C_Simp/Examples/Trivial.lean @@ -45,7 +45,7 @@ Errors: #[] #eval Strata.C_Simp.TransM.run (Strata.C_Simp.translateProgram (TrivialPgm.commands)) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/DatatypeVerificationTests.lean b/StrataTest/Languages/Core/DatatypeVerificationTests.lean similarity index 74% rename from StrataTest/Languages/Boogie/DatatypeVerificationTests.lean rename to StrataTest/Languages/Core/DatatypeVerificationTests.lean index 5a66914b1..b404b77df 100644 --- a/StrataTest/Languages/Boogie/DatatypeVerificationTests.lean +++ b/StrataTest/Languages/Core/DatatypeVerificationTests.lean @@ -4,17 +4,17 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Boogie -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Core +import Strata.Languages.Core.Verifier import Strata.DL.Lambda.TypeFactory /-! # Datatype Verification Integration Tests -Verify Boogie programs with datatypes, encoding with declare-datatype +Verify Strata Core programs with datatypes, encoding with declare-datatype -/ -namespace Boogie.DatatypeVerificationTests +namespace Core.DatatypeVerificationTests open Lambda open Std (ToFormat Format) @@ -76,7 +76,7 @@ def containerDatatype : LDatatype Visibility := /-! ## Helper Functions -/ /-- -Create a Boogie program with datatypes and a procedure. +Create a STrata Core program with datatypes and a procedure. -/ def mkProgramWithDatatypes (datatypes : List (LDatatype Visibility)) @@ -85,7 +85,7 @@ def mkProgramWithDatatypes : Except Format Program := do let proc : Procedure := { header := { - name := BoogieIdent.unres procName + name := CoreIdent.unres procName typeArgs := [] inputs := [] outputs := [] @@ -109,7 +109,7 @@ Run verification and return a summary string. def runVerificationTest (testName : String) (program : Program) : IO String := do try match ← (IO.FS.withTempDir (fun tempDir => - EIO.toIO' (Boogie.verify "cvc5" program tempDir Options.quiet))) with + EIO.toIO' (Core.verify "cvc5" program tempDir Options.quiet))) with | .error err => return s!"{testName}: FAILED\n Error: {err}" | .ok results => @@ -138,13 +138,13 @@ procedure testConstructors () { def test1_constructorApplication : IO String := do let statements : List Statement := [ -- Create None value - Statement.init (BoogieIdent.unres "x") (.forAll [] (LMonoTy.tcons "Option" [.int])) - (LExpr.op () (BoogieIdent.unres "None") (.some (LMonoTy.tcons "Option" [.int]))), + Statement.init (CoreIdent.unres "x") (.forAll [] (LMonoTy.tcons "Option" [.int])) + (LExpr.op () (CoreIdent.unres "None") (.some (LMonoTy.tcons "Option" [.int]))), -- Create Some value - Statement.init (BoogieIdent.unres "y") (.forAll [] (LMonoTy.tcons "Option" [.int])) + Statement.init (CoreIdent.unres "y") (.forAll [] (LMonoTy.tcons "Option" [.int])) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "Some") + (LExpr.op () (CoreIdent.unres "Some") (.some (LMonoTy.arrow .int (LMonoTy.tcons "Option" [.int])))) (LExpr.intConst () 42)), @@ -176,29 +176,29 @@ procedure testTesters () { def test2_testerFunctions : IO String := do let statements : List Statement := [ -- Create None value - Statement.init (BoogieIdent.unres "x") (.forAll [] (LMonoTy.tcons "Option" [.int])) - (LExpr.op () (BoogieIdent.unres "None") (.some (LMonoTy.tcons "Option" [.int]))), + Statement.init (CoreIdent.unres "x") (.forAll [] (LMonoTy.tcons "Option" [.int])) + (LExpr.op () (CoreIdent.unres "None") (.some (LMonoTy.tcons "Option" [.int]))), -- Assert that x is None Statement.assert "x_is_none" (LExpr.app () - (LExpr.op () (BoogieIdent.unres "isNone") + (LExpr.op () (CoreIdent.unres "isNone") (.some (LMonoTy.arrow (LMonoTy.tcons "Option" [.int]) .bool))) - (LExpr.fvar () (BoogieIdent.unres "x") (.some (LMonoTy.tcons "Option" [.int])))), + (LExpr.fvar () (CoreIdent.unres "x") (.some (LMonoTy.tcons "Option" [.int])))), -- Create Some value - Statement.init (BoogieIdent.unres "y") (.forAll [] (LMonoTy.tcons "Option" [.int])) + Statement.init (CoreIdent.unres "y") (.forAll [] (LMonoTy.tcons "Option" [.int])) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "Some") + (LExpr.op () (CoreIdent.unres "Some") (.some (LMonoTy.arrow .int (LMonoTy.tcons "Option" [.int])))) (LExpr.intConst () 42)), -- Assert that y is Some Statement.assert "y_is_some" (LExpr.app () - (LExpr.op () (BoogieIdent.unres "isSome") + (LExpr.op () (CoreIdent.unres "isSome") (.some (LMonoTy.arrow (LMonoTy.tcons "Option" [.int]) .bool))) - (LExpr.fvar () (BoogieIdent.unres "y") (.some (LMonoTy.tcons "Option" [.int])))) + (LExpr.fvar () (CoreIdent.unres "y") (.some (LMonoTy.tcons "Option" [.int])))) ] match mkProgramWithDatatypes [optionDatatype] "testTesters" statements with @@ -229,45 +229,45 @@ procedure testDestructors () { def test3_destructorFunctions : IO String := do let statements : List Statement := [ -- Create Some(42) - Statement.init (BoogieIdent.unres "opt") (.forAll [] (LMonoTy.tcons "Option" [.int])) + Statement.init (CoreIdent.unres "opt") (.forAll [] (LMonoTy.tcons "Option" [.int])) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "Some") + (LExpr.op () (CoreIdent.unres "Some") (.some (LMonoTy.arrow .int (LMonoTy.tcons "Option" [.int])))) (LExpr.intConst () 42)), -- Extract value from Some - Statement.init (BoogieIdent.unres "value") (.forAll [] LMonoTy.int) + Statement.init (CoreIdent.unres "value") (.forAll [] LMonoTy.int) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "OptionVal") + (LExpr.op () (CoreIdent.unres "OptionVal") (.some (LMonoTy.arrow (LMonoTy.tcons "Option" [.int]) .int))) - (LExpr.fvar () (BoogieIdent.unres "opt") (.some (LMonoTy.tcons "Option" [.int])))), + (LExpr.fvar () (CoreIdent.unres "opt") (.some (LMonoTy.tcons "Option" [.int])))), -- Assert that val == 42 Statement.assert "val_is_42" (LExpr.eq () - (LExpr.fvar () (BoogieIdent.unres "value") (.some .int)) + (LExpr.fvar () (CoreIdent.unres "value") (.some .int)) (LExpr.intConst () 42)), -- Create Cons(1, Nil) - Statement.init (BoogieIdent.unres "list") (.forAll [] (LMonoTy.tcons "List" [.int])) + Statement.init (CoreIdent.unres "list") (.forAll [] (LMonoTy.tcons "List" [.int])) (LExpr.app () (LExpr.app () - (LExpr.op () (BoogieIdent.unres "Cons") + (LExpr.op () (CoreIdent.unres "Cons") (.some (LMonoTy.arrow .int (LMonoTy.arrow (LMonoTy.tcons "List" [.int]) (LMonoTy.tcons "List" [.int]))))) (LExpr.intConst () 1)) - (LExpr.op () (BoogieIdent.unres "Nil") (.some (LMonoTy.tcons "List" [.int])))), + (LExpr.op () (CoreIdent.unres "Nil") (.some (LMonoTy.tcons "List" [.int])))), -- Extract head - Statement.init (BoogieIdent.unres "head") (.forAll [] LMonoTy.int) + Statement.init (CoreIdent.unres "head") (.forAll [] LMonoTy.int) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "hd") + (LExpr.op () (CoreIdent.unres "hd") (.some (LMonoTy.arrow (LMonoTy.tcons "List" [.int]) .int))) - (LExpr.fvar () (BoogieIdent.unres "list") (.some (LMonoTy.tcons "List" [.int])))), + (LExpr.fvar () (CoreIdent.unres "list") (.some (LMonoTy.tcons "List" [.int])))), -- Assert head == 1 Statement.assert "head_is_1" (LExpr.eq () - (LExpr.fvar () (BoogieIdent.unres "head") (.some .int)) + (LExpr.fvar () (CoreIdent.unres "head") (.some .int)) (LExpr.intConst () 1)) ] @@ -297,49 +297,49 @@ procedure testNested () { def test4_nestedDatatypes : IO String := do let statements : List Statement := [ -- Create a List of Option: Cons(Some(42), Nil) - Statement.init (BoogieIdent.unres "listOfOpt") + Statement.init (CoreIdent.unres "listOfOpt") (.forAll [] (LMonoTy.tcons "List" [LMonoTy.tcons "Option" [.int]])) (LExpr.app () (LExpr.app () - (LExpr.op () (BoogieIdent.unres "Cons") + (LExpr.op () (CoreIdent.unres "Cons") (.some (LMonoTy.arrow (LMonoTy.tcons "Option" [.int]) (LMonoTy.arrow (LMonoTy.tcons "List" [LMonoTy.tcons "Option" [.int]]) (LMonoTy.tcons "List" [LMonoTy.tcons "Option" [.int]]))))) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "Some") + (LExpr.op () (CoreIdent.unres "Some") (.some (LMonoTy.arrow .int (LMonoTy.tcons "Option" [.int])))) (LExpr.intConst () 42))) - (LExpr.op () (BoogieIdent.unres "Nil") + (LExpr.op () (CoreIdent.unres "Nil") (.some (LMonoTy.tcons "List" [LMonoTy.tcons "Option" [.int]])))), -- Assert that the list is Cons Statement.assert "list_is_cons" (LExpr.app () - (LExpr.op () (BoogieIdent.unres "isCons") + (LExpr.op () (CoreIdent.unres "isCons") (.some (LMonoTy.arrow (LMonoTy.tcons "List" [LMonoTy.tcons "Option" [.int]]) .bool))) - (LExpr.fvar () (BoogieIdent.unres "listOfOpt") + (LExpr.fvar () (CoreIdent.unres "listOfOpt") (.some (LMonoTy.tcons "List" [LMonoTy.tcons "Option" [.int]])))), -- Extract the head of the list (which is an Option) - Statement.init (BoogieIdent.unres "headOpt") (.forAll [] (LMonoTy.tcons "Option" [.int])) + Statement.init (CoreIdent.unres "headOpt") (.forAll [] (LMonoTy.tcons "Option" [.int])) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "hd") + (LExpr.op () (CoreIdent.unres "hd") (.some (LMonoTy.arrow (LMonoTy.tcons "List" [LMonoTy.tcons "Option" [.int]]) (LMonoTy.tcons "Option" [.int])))) - (LExpr.fvar () (BoogieIdent.unres "listOfOpt") + (LExpr.fvar () (CoreIdent.unres "listOfOpt") (.some (LMonoTy.tcons "List" [LMonoTy.tcons "Option" [.int]])))), -- Extract the value from the Option - Statement.init (BoogieIdent.unres "value") (.forAll [] LMonoTy.int) + Statement.init (CoreIdent.unres "value") (.forAll [] LMonoTy.int) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "OptionVal") + (LExpr.op () (CoreIdent.unres "OptionVal") (.some (LMonoTy.arrow (LMonoTy.tcons "Option" [.int]) .int))) - (LExpr.fvar () (BoogieIdent.unres "headOpt") + (LExpr.fvar () (CoreIdent.unres "headOpt") (.some (LMonoTy.tcons "Option" [.int])))), -- Assert that the extracted value is 42 Statement.assert "value_is_42" (LExpr.eq () - (LExpr.fvar () (BoogieIdent.unres "value") (.some .int)) + (LExpr.fvar () (CoreIdent.unres "value") (.some .int)) (LExpr.intConst () 42)) ] @@ -368,26 +368,26 @@ procedure testTesterHavoc () { def test5_testerWithHavoc : IO String := do let statements : List Statement := [ -- Havoc an Option value (non-deterministic) - Statement.init (BoogieIdent.unres "x") (.forAll [] (LMonoTy.tcons "Option" [.int])) - (LExpr.op () (BoogieIdent.unres "None") (.some (LMonoTy.tcons "Option" [.int]))), - Statement.havoc (BoogieIdent.unres "x"), + Statement.init (CoreIdent.unres "x") (.forAll [] (LMonoTy.tcons "Option" [.int])) + (LExpr.op () (CoreIdent.unres "None") (.some (LMonoTy.tcons "Option" [.int]))), + Statement.havoc (CoreIdent.unres "x"), -- Assume x is Some Statement.assume "x_is_some" (LExpr.app () - (LExpr.op () (BoogieIdent.unres "isSome") + (LExpr.op () (CoreIdent.unres "isSome") (.some (LMonoTy.arrow (LMonoTy.tcons "Option" [.int]) .bool))) - (LExpr.fvar () (BoogieIdent.unres "x") (.some (LMonoTy.tcons "Option" [.int])))), + (LExpr.fvar () (CoreIdent.unres "x") (.some (LMonoTy.tcons "Option" [.int])))), -- Assert x is not None (should follow from assumption) Statement.assert "x_not_none" (LExpr.app () - (LExpr.op () (BoogieIdent.unres "Bool.Not") + (LExpr.op () (CoreIdent.unres "Bool.Not") (.some (LMonoTy.arrow .bool .bool))) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "isNone") + (LExpr.op () (CoreIdent.unres "isNone") (.some (LMonoTy.arrow (LMonoTy.tcons "Option" [.int]) .bool))) - (LExpr.fvar () (BoogieIdent.unres "x") (.some (LMonoTy.tcons "Option" [.int]))))) + (LExpr.fvar () (CoreIdent.unres "x") (.some (LMonoTy.tcons "Option" [.int]))))) ] match mkProgramWithDatatypes [optionDatatype] "testTesterHavoc" statements with @@ -415,33 +415,33 @@ procedure testDestructorHavoc () { def test6_destructorWithHavoc : IO String := do let statements : List Statement := [ -- Havoc an Option value - Statement.init (BoogieIdent.unres "opt") (.forAll [] (LMonoTy.tcons "Option" [.int])) + Statement.init (CoreIdent.unres "opt") (.forAll [] (LMonoTy.tcons "Option" [.int])) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "Some") + (LExpr.op () (CoreIdent.unres "Some") (.some (LMonoTy.arrow .int (LMonoTy.tcons "Option" [.int])))) (LExpr.intConst () 0)), - Statement.havoc (BoogieIdent.unres "opt"), + Statement.havoc (CoreIdent.unres "opt"), -- Assume opt is Some(42) Statement.assume "opt_is_some_42" (LExpr.eq () - (LExpr.fvar () (BoogieIdent.unres "opt") (.some (LMonoTy.tcons "Option" [.int]))) + (LExpr.fvar () (CoreIdent.unres "opt") (.some (LMonoTy.tcons "Option" [.int]))) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "Some") + (LExpr.op () (CoreIdent.unres "Some") (.some (LMonoTy.arrow .int (LMonoTy.tcons "Option" [.int])))) (LExpr.intConst () 42))), -- Extract value - Statement.init (BoogieIdent.unres "value") (.forAll [] LMonoTy.int) + Statement.init (CoreIdent.unres "value") (.forAll [] LMonoTy.int) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "OptionVal") + (LExpr.op () (CoreIdent.unres "OptionVal") (.some (LMonoTy.arrow (LMonoTy.tcons "Option" [.int]) .int))) - (LExpr.fvar () (BoogieIdent.unres "opt") (.some (LMonoTy.tcons "Option" [.int])))), + (LExpr.fvar () (CoreIdent.unres "opt") (.some (LMonoTy.tcons "Option" [.int])))), -- Assert val == 42 Statement.assert "val_is_42" (LExpr.eq () - (LExpr.fvar () (BoogieIdent.unres "value") (.some .int)) + (LExpr.fvar () (CoreIdent.unres "value") (.some .int)) (LExpr.intConst () 42)) ] @@ -469,26 +469,26 @@ procedure testListHavoc () { def test7_listWithHavoc : IO String := do let statements : List Statement := [ -- Havoc a list - Statement.init (BoogieIdent.unres "xs") (.forAll [] (LMonoTy.tcons "List" [.int])) - (LExpr.op () (BoogieIdent.unres "Nil") (.some (LMonoTy.tcons "List" [.int]))), - Statement.havoc (BoogieIdent.unres "xs"), + Statement.init (CoreIdent.unres "xs") (.forAll [] (LMonoTy.tcons "List" [.int])) + (LExpr.op () (CoreIdent.unres "Nil") (.some (LMonoTy.tcons "List" [.int]))), + Statement.havoc (CoreIdent.unres "xs"), -- Assume xs is Cons Statement.assume "xs_is_cons" (LExpr.app () - (LExpr.op () (BoogieIdent.unres "isCons") + (LExpr.op () (CoreIdent.unres "isCons") (.some (LMonoTy.arrow (LMonoTy.tcons "List" [.int]) .bool))) - (LExpr.fvar () (BoogieIdent.unres "xs") (.some (LMonoTy.tcons "List" [.int])))), + (LExpr.fvar () (CoreIdent.unres "xs") (.some (LMonoTy.tcons "List" [.int])))), -- Assert xs is not Nil Statement.assert "xs_not_nil" (LExpr.app () - (LExpr.op () (BoogieIdent.unres "Bool.Not") + (LExpr.op () (CoreIdent.unres "Bool.Not") (.some (LMonoTy.arrow .bool .bool))) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "isNil") + (LExpr.op () (CoreIdent.unres "isNil") (.some (LMonoTy.arrow (LMonoTy.tcons "List" [.int]) .bool))) - (LExpr.fvar () (BoogieIdent.unres "xs") (.some (LMonoTy.tcons "List" [.int]))))) + (LExpr.fvar () (CoreIdent.unres "xs") (.some (LMonoTy.tcons "List" [.int]))))) ] match mkProgramWithDatatypes [listDatatype] "testListHavoc" statements with @@ -520,42 +520,42 @@ procedure testHiddenTypeRecursion () { def test8_hiddenTypeRecursion : IO String := do let statements : List Statement := [ -- Initialize with Empty Container - note we NEVER use Hidden directly - Statement.init (BoogieIdent.unres "container") + Statement.init (CoreIdent.unres "container") (.forAll [] (LMonoTy.tcons "Container" [.int])) - (LExpr.op () (BoogieIdent.unres "Empty") (.some (LMonoTy.tcons "Container" [.int]))), + (LExpr.op () (CoreIdent.unres "Empty") (.some (LMonoTy.tcons "Container" [.int]))), -- Havoc the container to make it non-deterministic - Statement.havoc (BoogieIdent.unres "container"), + Statement.havoc (CoreIdent.unres "container"), -- Assume container is not Empty (so it must be WithHidden) Statement.assume "container_not_empty" (LExpr.app () - (LExpr.op () (BoogieIdent.unres "Bool.Not") + (LExpr.op () (CoreIdent.unres "Bool.Not") (.some (LMonoTy.arrow .bool .bool))) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "isEmpty") + (LExpr.op () (CoreIdent.unres "isEmpty") (.some (LMonoTy.arrow (LMonoTy.tcons "Container" [.int]) .bool))) - (LExpr.fvar () (BoogieIdent.unres "container") (.some (LMonoTy.tcons "Container" [.int]))))), + (LExpr.fvar () (CoreIdent.unres "container") (.some (LMonoTy.tcons "Container" [.int]))))), -- Extract the visible part - Statement.init (BoogieIdent.unres "visiblePart") (.forAll [] LMonoTy.int) + Statement.init (CoreIdent.unres "visiblePart") (.forAll [] LMonoTy.int) (LExpr.app () - (LExpr.op () (BoogieIdent.unres "visiblePart") + (LExpr.op () (CoreIdent.unres "visiblePart") (.some (LMonoTy.arrow (LMonoTy.tcons "Container" [.int]) .int))) - (LExpr.fvar () (BoogieIdent.unres "container") (.some (LMonoTy.tcons "Container" [.int])))), + (LExpr.fvar () (CoreIdent.unres "container") (.some (LMonoTy.tcons "Container" [.int])))), -- Assume the visible part has a specific value Statement.assume "visible_part_is_42" (LExpr.eq () - (LExpr.fvar () (BoogieIdent.unres "visiblePart") (.some .int)) + (LExpr.fvar () (CoreIdent.unres "visiblePart") (.some .int)) (LExpr.intConst () 42)), -- Assert that container is WithHidden Statement.assert "container_is_with_hidden" (LExpr.app () - (LExpr.op () (BoogieIdent.unres "isWithHidden") + (LExpr.op () (CoreIdent.unres "isWithHidden") (.some (LMonoTy.arrow (LMonoTy.tcons "Container" [.int]) .bool))) - (LExpr.fvar () (BoogieIdent.unres "container") (.some (LMonoTy.tcons "Container" [.int])))) + (LExpr.fvar () (CoreIdent.unres "container") (.some (LMonoTy.tcons "Container" [.int])))) ] match mkProgramWithDatatypes [hiddenDatatype, containerDatatype] "testHiddenTypeRecursion" statements with @@ -615,4 +615,4 @@ info: "Test 8 - Hidden Type Recursion: PASSED\n Verified 1 obligation(s)\n" #eval test8_hiddenTypeRecursion -end Boogie.DatatypeVerificationTests +end Core.DatatypeVerificationTests diff --git a/StrataTest/Languages/Boogie/Examples/AdvancedMaps.lean b/StrataTest/Languages/Core/Examples/AdvancedMaps.lean similarity index 98% rename from StrataTest/Languages/Boogie/Examples/AdvancedMaps.lean rename to StrataTest/Languages/Core/Examples/AdvancedMaps.lean index 295201201..35be0b0c9 100644 --- a/StrataTest/Languages/Boogie/Examples/AdvancedMaps.lean +++ b/StrataTest/Languages/Core/Examples/AdvancedMaps.lean @@ -5,14 +5,14 @@ -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- open Strata private def mapPgm := #strata -program Boogie; +program Core; type MapII := Map int int; type MapIMapII := Map int MapII; @@ -82,7 +82,7 @@ Errors: #[] #eval TransM.run Inhabited.default (translateProgram mapPgm) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/AdvancedQuantifiers.lean b/StrataTest/Languages/Core/Examples/AdvancedQuantifiers.lean similarity index 90% rename from StrataTest/Languages/Boogie/Examples/AdvancedQuantifiers.lean rename to StrataTest/Languages/Core/Examples/AdvancedQuantifiers.lean index 5b448305d..d0d462cc2 100644 --- a/StrataTest/Languages/Boogie/Examples/AdvancedQuantifiers.lean +++ b/StrataTest/Languages/Core/Examples/AdvancedQuantifiers.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def advQuantPgm := #strata -program Boogie; +program Core; axiom [mapAllValues0]: forall m: (Map int int), k: int :: m[k] == 0; procedure Update(mArg: Map int int, kArg: int) returns (res: int) spec { @@ -25,7 +25,7 @@ spec { /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/AssertionDefaultNames.lean b/StrataTest/Languages/Core/Examples/AssertionDefaultNames.lean similarity index 87% rename from StrataTest/Languages/Boogie/Examples/AssertionDefaultNames.lean rename to StrataTest/Languages/Core/Examples/AssertionDefaultNames.lean index 38dd61f2e..54da2240b 100644 --- a/StrataTest/Languages/Boogie/Examples/AssertionDefaultNames.lean +++ b/StrataTest/Languages/Core/Examples/AssertionDefaultNames.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def assertionNames := #strata -program Boogie; +program Core; procedure Test(x : int) returns () spec { requires x == 1; @@ -21,7 +21,7 @@ spec { }; #end --- Translation from DDM AST to Boogie/Strata AST +-- Translation from DDM AST to Strata Core AST /-- info: true -/ #guard_msgs in @@ -41,7 +41,7 @@ Errors: #[] #eval TransM.run Inhabited.default (translateProgram assertionNames) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/Axioms.lean b/StrataTest/Languages/Core/Examples/Axioms.lean similarity index 88% rename from StrataTest/Languages/Boogie/Examples/Axioms.lean rename to StrataTest/Languages/Core/Examples/Axioms.lean index 205ff4cd1..652836418 100644 --- a/StrataTest/Languages/Boogie/Examples/Axioms.lean +++ b/StrataTest/Languages/Core/Examples/Axioms.lean @@ -5,15 +5,15 @@ -/ -import Strata.Languages.Boogie.Verifier -import Strata.Languages.Boogie.CallGraph +import Strata.Languages.Core.Verifier +import Strata.Languages.Core.CallGraph --------------------------------------------------------------------- namespace Strata def axiomPgm1 := #strata -program Boogie; +program Core; const x : int; axiom [a1]: x == 5; @@ -42,7 +42,7 @@ procedure P2() returns () #end /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: @@ -107,7 +107,7 @@ Result: ✅ pass def axiomPgm2 := #strata -program Boogie; +program Core; function f(x : int) : int; function g(x : int) : int; @@ -125,11 +125,11 @@ assert [axiomPgm2_main_assert]: (x >= 0 ==> f(x) > x); /-- info: [] -/ #guard_msgs in -#eval let (program, _) := Boogie.getProgram axiomPgm2 - Std.format (Boogie.Program.getIrrelevantAxioms program ["f"]) +#eval let (program, _) := Core.getProgram axiomPgm2 + Std.format (Core.Program.getIrrelevantAxioms program ["f"]) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/BitVecParse.lean b/StrataTest/Languages/Core/Examples/BitVecParse.lean similarity index 91% rename from StrataTest/Languages/Boogie/Examples/BitVecParse.lean rename to StrataTest/Languages/Core/Examples/BitVecParse.lean index f8eb356ea..9051fdef9 100644 --- a/StrataTest/Languages/Boogie/Examples/BitVecParse.lean +++ b/StrataTest/Languages/Core/Examples/BitVecParse.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata private def pgm : Program := #strata -program Boogie; +program Core; procedure bitVecParseTest() returns () { @@ -23,7 +23,7 @@ procedure bitVecParseTest() returns () { #end /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/Cover.lean b/StrataTest/Languages/Core/Examples/Cover.lean similarity index 95% rename from StrataTest/Languages/Boogie/Examples/Cover.lean rename to StrataTest/Languages/Core/Examples/Cover.lean index 33beafe42..445cd3d07 100644 --- a/StrataTest/Languages/Boogie/Examples/Cover.lean +++ b/StrataTest/Languages/Core/Examples/Cover.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def coverPgm1 := #strata -program Boogie; +program Core; procedure Test() returns () { var x : int; @@ -65,7 +65,7 @@ Result: ✅ pass def coverPgm2 := #strata -program Boogie; +program Core; procedure Test(x : int) returns () spec { requires x > 1; diff --git a/StrataTest/Languages/Boogie/Examples/DDMAxiomsExtraction.lean b/StrataTest/Languages/Core/Examples/DDMAxiomsExtraction.lean similarity index 63% rename from StrataTest/Languages/Boogie/Examples/DDMAxiomsExtraction.lean rename to StrataTest/Languages/Core/Examples/DDMAxiomsExtraction.lean index 1e8635a81..f01e4ebe7 100644 --- a/StrataTest/Languages/Boogie/Examples/DDMAxiomsExtraction.lean +++ b/StrataTest/Languages/Core/Examples/DDMAxiomsExtraction.lean @@ -5,15 +5,15 @@ -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata --- Example Boogie program with axioms +-- Example Strata Core program with axioms def examplePgm := #strata -program Boogie; +program Core; type k; type v; axiom [updateSelect]: forall m: Map k v, kk: k, vv: v :: m[kk := vv][kk] == vv; @@ -21,10 +21,10 @@ axiom [updatePreserves]: forall m: Map k v, okk: k, kk: k, vv: v :: m[kk := vv][ #end /-- - This function extracts the Boogie.Decl in the given program that are axiom declarations + This function extracts the Core.Decl in the given program that are axiom declarations -/ -def extractAxiomsDecl (prg: Boogie.Program) : (List Boogie.Decl) := - let rec loop (acc: List Boogie.Decl) (l: List Boogie.Decl): List Boogie.Decl := +def extractAxiomsDecl (prg: Core.Program) : (List Core.Decl) := + let rec loop (acc: List Core.Decl) (l: List Core.Decl): List Core.Decl := match l with | [] => acc | hd :: tl => @@ -36,7 +36,7 @@ def extractAxiomsDecl (prg: Boogie.Program) : (List Boogie.Decl) := /-- Extract the body LExpr from the axiom declaration -/ -def extractExpr (axDecl: Boogie.Decl): Boogie.Expression.Expr := +def extractExpr (axDecl: Core.Decl): Core.Expression.Expr := match axDecl with | .ax a _ => a.e | _ => panic "Can be called only on axiom declaration" @@ -61,7 +61,7 @@ def transformSimpleTypeToFreeVariable (ty: Lambda.LMonoTy) (to_replace: List Str Transform all occurences of types of the form LMonoTy.tcons name [] into ftvar name, if name is in to_replace in the given expression -/ -def replaceTypesByFTV (expr: Boogie.Expression.Expr) (to_replace: List String): Boogie.Expression.Expr := +def replaceTypesByFTV (expr: Core.Expression.Expr) (to_replace: List String): Core.Expression.Expr := match expr with | .const m c => .const m c | .op m o oty => .op m o (oty.map (fun t => transformSimpleTypeToFreeVariable t to_replace)) @@ -74,17 +74,17 @@ def replaceTypesByFTV (expr: Boogie.Expression.Expr) (to_replace: List String): | .eq m e1 e2 => .eq m (replaceTypesByFTV e1 to_replace) (replaceTypesByFTV e2 to_replace) /-- - Extract all axioms from the given environment by first translating it into a Boogie Program. + Extract all axioms from the given environment by first translating it into a Strata Core Program. It then extracts LExpr body from the axioms, and replace all occurences of the typeArgs by a ftvar with the same name -/ -def extractAxiomsWithFreeTypeVars (pgm: Program) (typeArgs: List String): (List Boogie.Expression.Expr) := - let prg: Boogie.Program := (TransM.run Inhabited.default (translateProgram pgm)).fst +def extractAxiomsWithFreeTypeVars (pgm: Program) (typeArgs: List String): (List Core.Expression.Expr) := + let prg: Core.Program := (TransM.run Inhabited.default (translateProgram pgm)).fst let axiomsDecls := extractAxiomsDecl prg let axioms := axiomsDecls.map extractExpr axioms.map (fun a => replaceTypesByFTV a typeArgs) /-- -info: program Boogie; +info: program Core; type k; type v; axiom [updateSelect]:forall(((m):(Map v k)),((kk):(k))),((vv):(v))::((m)[kk:=vv])[kk]==vv; @@ -94,302 +94,302 @@ axiom [updatePreserves]:forall((((m):(Map v k)),((okk):(k))),((kk):(k))),((vv):( #eval IO.println examplePgm /-- -info: #[{ ann := { start := { byteIdx := 295 }, stop := { byteIdx := 302 } }, - name := { dialect := "Boogie", name := "command_typedecl" }, +info: #[{ ann := { start := { byteIdx := 296 }, stop := { byteIdx := 303 } }, + name := { dialect := "Core", name := "command_typedecl" }, args := - ((Array.mkEmpty 2).push (ArgF.ident { start := { byteIdx := 300 }, stop := { byteIdx := 301 } } "k")).push - (ArgF.option { start := { byteIdx := 301 }, stop := { byteIdx := 301 } } none) }, - { ann := { start := { byteIdx := 303 }, stop := { byteIdx := 310 } }, - name := { dialect := "Boogie", name := "command_typedecl" }, + ((Array.mkEmpty 2).push (ArgF.ident { start := { byteIdx := 301 }, stop := { byteIdx := 302 } } "k")).push + (ArgF.option { start := { byteIdx := 302 }, stop := { byteIdx := 302 } } none) }, + { ann := { start := { byteIdx := 304 }, stop := { byteIdx := 311 } }, + name := { dialect := "Core", name := "command_typedecl" }, args := - ((Array.mkEmpty 2).push (ArgF.ident { start := { byteIdx := 308 }, stop := { byteIdx := 309 } } "v")).push - (ArgF.option { start := { byteIdx := 309 }, stop := { byteIdx := 309 } } none) }, - { ann := { start := { byteIdx := 311 }, stop := { byteIdx := 390 } }, - name := { dialect := "Boogie", name := "command_axiom" }, + ((Array.mkEmpty 2).push (ArgF.ident { start := { byteIdx := 309 }, stop := { byteIdx := 310 } } "v")).push + (ArgF.option { start := { byteIdx := 310 }, stop := { byteIdx := 310 } } none) }, + { ann := { start := { byteIdx := 312 }, stop := { byteIdx := 391 } }, + name := { dialect := "Core", name := "command_axiom" }, args := ((Array.mkEmpty 2).push - (ArgF.option { start := { byteIdx := 317 }, stop := { byteIdx := 332 } } + (ArgF.option { start := { byteIdx := 318 }, stop := { byteIdx := 333 } } (some (ArgF.op - { ann := { start := { byteIdx := 317 }, stop := { byteIdx := 332 } }, - name := { dialect := "Boogie", name := "label" }, + { ann := { start := { byteIdx := 318 }, stop := { byteIdx := 333 } }, + name := { dialect := "Core", name := "label" }, args := (Array.mkEmpty 1).push - (ArgF.ident { start := { byteIdx := 318 }, stop := { byteIdx := 330 } } + (ArgF.ident { start := { byteIdx := 319 }, stop := { byteIdx := 331 } } "updateSelect") })))).push (ArgF.expr - (ExprF.app { start := { byteIdx := 333 }, stop := { byteIdx := 389 } } - (ExprF.app { start := { byteIdx := 333 }, stop := { byteIdx := 389 } } - (ExprF.fn { start := { byteIdx := 333 }, stop := { byteIdx := 389 } } - { dialect := "Boogie", name := "forall" }) + (ExprF.app { start := { byteIdx := 334 }, stop := { byteIdx := 390 } } + (ExprF.app { start := { byteIdx := 334 }, stop := { byteIdx := 390 } } + (ExprF.fn { start := { byteIdx := 334 }, stop := { byteIdx := 390 } } + { dialect := "Core", name := "forall" }) (ArgF.op - { ann := { start := { byteIdx := 340 }, stop := { byteIdx := 364 } }, - name := { dialect := "Boogie", name := "declPush" }, + { ann := { start := { byteIdx := 341 }, stop := { byteIdx := 365 } }, + name := { dialect := "Core", name := "declPush" }, args := ((Array.mkEmpty 2).push (ArgF.op - { ann := { start := { byteIdx := 340 }, stop := { byteIdx := 357 } }, - name := { dialect := "Boogie", name := "declPush" }, + { ann := { start := { byteIdx := 341 }, stop := { byteIdx := 358 } }, + name := { dialect := "Core", name := "declPush" }, args := ((Array.mkEmpty 2).push (ArgF.op - { ann := { start := { byteIdx := 340 }, stop := { byteIdx := 350 } }, - name := { dialect := "Boogie", name := "declAtom" }, + { ann := { start := { byteIdx := 341 }, stop := { byteIdx := 351 } }, + name := { dialect := "Core", name := "declAtom" }, args := (Array.mkEmpty 1).push (ArgF.op - { ann := { start := { byteIdx := 340 }, stop := { byteIdx := 350 } }, - name := { dialect := "Boogie", name := "bind_mk" }, + { ann := { start := { byteIdx := 341 }, stop := { byteIdx := 351 } }, + name := { dialect := "Core", name := "bind_mk" }, args := (((Array.mkEmpty 3).push (ArgF.ident - { start := { byteIdx := 340 }, - stop := { byteIdx := 341 } } + { start := { byteIdx := 341 }, + stop := { byteIdx := 342 } } "m")).push (ArgF.option - { start := { byteIdx := 343 }, stop := { byteIdx := 343 } } + { start := { byteIdx := 344 }, stop := { byteIdx := 344 } } none)).push (ArgF.type (TypeExprF.ident - { start := { byteIdx := 343 }, stop := { byteIdx := 346 } } - { dialect := "Boogie", name := "Map" } + { start := { byteIdx := 344 }, stop := { byteIdx := 347 } } + { dialect := "Core", name := "Map" } (((Array.mkEmpty 2).push (TypeExprF.fvar - { start := { byteIdx := 349 }, - stop := { byteIdx := 350 } } + { start := { byteIdx := 350 }, + stop := { byteIdx := 351 } } 1 (Array.mkEmpty 0))).push (TypeExprF.fvar - { start := { byteIdx := 347 }, - stop := { byteIdx := 348 } } + { start := { byteIdx := 348 }, + stop := { byteIdx := 349 } } 0 (Array.mkEmpty 0))))) }) })).push (ArgF.op - { ann := { start := { byteIdx := 352 }, stop := { byteIdx := 357 } }, - name := { dialect := "Boogie", name := "bind_mk" }, + { ann := { start := { byteIdx := 353 }, stop := { byteIdx := 358 } }, + name := { dialect := "Core", name := "bind_mk" }, args := (((Array.mkEmpty 3).push (ArgF.ident - { start := { byteIdx := 352 }, stop := { byteIdx := 354 } } + { start := { byteIdx := 353 }, stop := { byteIdx := 355 } } "kk")).push - (ArgF.option { start := { byteIdx := 356 }, stop := { byteIdx := 356 } } + (ArgF.option { start := { byteIdx := 357 }, stop := { byteIdx := 357 } } none)).push (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 356 }, stop := { byteIdx := 357 } } + (TypeExprF.fvar { start := { byteIdx := 357 }, stop := { byteIdx := 358 } } 0 (Array.mkEmpty 0))) }) })).push (ArgF.op - { ann := { start := { byteIdx := 359 }, stop := { byteIdx := 364 } }, - name := { dialect := "Boogie", name := "bind_mk" }, + { ann := { start := { byteIdx := 360 }, stop := { byteIdx := 365 } }, + name := { dialect := "Core", name := "bind_mk" }, args := (((Array.mkEmpty 3).push - (ArgF.ident { start := { byteIdx := 359 }, stop := { byteIdx := 361 } } + (ArgF.ident { start := { byteIdx := 360 }, stop := { byteIdx := 362 } } "vv")).push - (ArgF.option { start := { byteIdx := 363 }, stop := { byteIdx := 363 } } none)).push + (ArgF.option { start := { byteIdx := 364 }, stop := { byteIdx := 364 } } none)).push (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 363 }, stop := { byteIdx := 364 } } 1 + (TypeExprF.fvar { start := { byteIdx := 364 }, stop := { byteIdx := 365 } } 1 (Array.mkEmpty 0))) }) })) (ArgF.expr - (ExprF.app { start := { byteIdx := 368 }, stop := { byteIdx := 389 } } - (ExprF.app { start := { byteIdx := 368 }, stop := { byteIdx := 389 } } - (ExprF.app { start := { byteIdx := 368 }, stop := { byteIdx := 389 } } - (ExprF.fn { start := { byteIdx := 368 }, stop := { byteIdx := 389 } } - { dialect := "Boogie", name := "equal" }) + (ExprF.app { start := { byteIdx := 369 }, stop := { byteIdx := 390 } } + (ExprF.app { start := { byteIdx := 369 }, stop := { byteIdx := 390 } } + (ExprF.app { start := { byteIdx := 369 }, stop := { byteIdx := 390 } } + (ExprF.fn { start := { byteIdx := 369 }, stop := { byteIdx := 390 } } + { dialect := "Core", name := "equal" }) (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 349 }, stop := { byteIdx := 350 } } 1 (Array.mkEmpty 0)))) + (TypeExprF.fvar { start := { byteIdx := 350 }, stop := { byteIdx := 351 } } 1 (Array.mkEmpty 0)))) (ArgF.expr - (ExprF.app { start := { byteIdx := 368 }, stop := { byteIdx := 383 } } - (ExprF.app { start := { byteIdx := 368 }, stop := { byteIdx := 383 } } - (ExprF.app { start := { byteIdx := 368 }, stop := { byteIdx := 383 } } - (ExprF.app { start := { byteIdx := 368 }, stop := { byteIdx := 383 } } - (ExprF.fn { start := { byteIdx := 368 }, stop := { byteIdx := 383 } } - { dialect := "Boogie", name := "map_get" }) + (ExprF.app { start := { byteIdx := 369 }, stop := { byteIdx := 384 } } + (ExprF.app { start := { byteIdx := 369 }, stop := { byteIdx := 384 } } + (ExprF.app { start := { byteIdx := 369 }, stop := { byteIdx := 384 } } + (ExprF.app { start := { byteIdx := 369 }, stop := { byteIdx := 384 } } + (ExprF.fn { start := { byteIdx := 369 }, stop := { byteIdx := 384 } } + { dialect := "Core", name := "map_get" }) (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 347 }, stop := { byteIdx := 348 } } 0 + (TypeExprF.fvar { start := { byteIdx := 348 }, stop := { byteIdx := 349 } } 0 (Array.mkEmpty 0)))) (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 349 }, stop := { byteIdx := 350 } } 1 + (TypeExprF.fvar { start := { byteIdx := 350 }, stop := { byteIdx := 351 } } 1 (Array.mkEmpty 0)))) (ArgF.expr - (ExprF.app { start := { byteIdx := 368 }, stop := { byteIdx := 379 } } - (ExprF.app { start := { byteIdx := 368 }, stop := { byteIdx := 379 } } - (ExprF.app { start := { byteIdx := 368 }, stop := { byteIdx := 379 } } - (ExprF.app { start := { byteIdx := 368 }, stop := { byteIdx := 379 } } - (ExprF.app { start := { byteIdx := 368 }, stop := { byteIdx := 379 } } - (ExprF.fn { start := { byteIdx := 368 }, stop := { byteIdx := 379 } } - { dialect := "Boogie", name := "map_set" }) + (ExprF.app { start := { byteIdx := 369 }, stop := { byteIdx := 380 } } + (ExprF.app { start := { byteIdx := 369 }, stop := { byteIdx := 380 } } + (ExprF.app { start := { byteIdx := 369 }, stop := { byteIdx := 380 } } + (ExprF.app { start := { byteIdx := 369 }, stop := { byteIdx := 380 } } + (ExprF.app { start := { byteIdx := 369 }, stop := { byteIdx := 380 } } + (ExprF.fn { start := { byteIdx := 369 }, stop := { byteIdx := 380 } } + { dialect := "Core", name := "map_set" }) (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 347 }, stop := { byteIdx := 348 } } 0 + (TypeExprF.fvar { start := { byteIdx := 348 }, stop := { byteIdx := 349 } } 0 (Array.mkEmpty 0)))) (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 349 }, stop := { byteIdx := 350 } } 1 + (TypeExprF.fvar { start := { byteIdx := 350 }, stop := { byteIdx := 351 } } 1 (Array.mkEmpty 0)))) - (ArgF.expr (ExprF.bvar { start := { byteIdx := 368 }, stop := { byteIdx := 369 } } 2))) - (ArgF.expr (ExprF.bvar { start := { byteIdx := 370 }, stop := { byteIdx := 372 } } 1))) - (ArgF.expr (ExprF.bvar { start := { byteIdx := 376 }, stop := { byteIdx := 378 } } 0))))) - (ArgF.expr (ExprF.bvar { start := { byteIdx := 380 }, stop := { byteIdx := 382 } } 1))))) - (ArgF.expr (ExprF.bvar { start := { byteIdx := 387 }, stop := { byteIdx := 389 } } 0)))))) }, - { ann := { start := { byteIdx := 391 }, stop := { byteIdx := 486 } }, - name := { dialect := "Boogie", name := "command_axiom" }, + (ArgF.expr (ExprF.bvar { start := { byteIdx := 369 }, stop := { byteIdx := 370 } } 2))) + (ArgF.expr (ExprF.bvar { start := { byteIdx := 371 }, stop := { byteIdx := 373 } } 1))) + (ArgF.expr (ExprF.bvar { start := { byteIdx := 377 }, stop := { byteIdx := 379 } } 0))))) + (ArgF.expr (ExprF.bvar { start := { byteIdx := 381 }, stop := { byteIdx := 383 } } 1))))) + (ArgF.expr (ExprF.bvar { start := { byteIdx := 388 }, stop := { byteIdx := 390 } } 0)))))) }, + { ann := { start := { byteIdx := 392 }, stop := { byteIdx := 487 } }, + name := { dialect := "Core", name := "command_axiom" }, args := ((Array.mkEmpty 2).push - (ArgF.option { start := { byteIdx := 397 }, stop := { byteIdx := 415 } } + (ArgF.option { start := { byteIdx := 398 }, stop := { byteIdx := 416 } } (some (ArgF.op - { ann := { start := { byteIdx := 397 }, stop := { byteIdx := 415 } }, - name := { dialect := "Boogie", name := "label" }, + { ann := { start := { byteIdx := 398 }, stop := { byteIdx := 416 } }, + name := { dialect := "Core", name := "label" }, args := (Array.mkEmpty 1).push - (ArgF.ident { start := { byteIdx := 398 }, stop := { byteIdx := 413 } } + (ArgF.ident { start := { byteIdx := 399 }, stop := { byteIdx := 414 } } "updatePreserves") })))).push (ArgF.expr - (ExprF.app { start := { byteIdx := 416 }, stop := { byteIdx := 485 } } - (ExprF.app { start := { byteIdx := 416 }, stop := { byteIdx := 485 } } - (ExprF.fn { start := { byteIdx := 416 }, stop := { byteIdx := 485 } } - { dialect := "Boogie", name := "forall" }) + (ExprF.app { start := { byteIdx := 417 }, stop := { byteIdx := 486 } } + (ExprF.app { start := { byteIdx := 417 }, stop := { byteIdx := 486 } } + (ExprF.fn { start := { byteIdx := 417 }, stop := { byteIdx := 486 } } + { dialect := "Core", name := "forall" }) (ArgF.op - { ann := { start := { byteIdx := 423 }, stop := { byteIdx := 455 } }, - name := { dialect := "Boogie", name := "declPush" }, + { ann := { start := { byteIdx := 424 }, stop := { byteIdx := 456 } }, + name := { dialect := "Core", name := "declPush" }, args := ((Array.mkEmpty 2).push (ArgF.op - { ann := { start := { byteIdx := 423 }, stop := { byteIdx := 448 } }, - name := { dialect := "Boogie", name := "declPush" }, + { ann := { start := { byteIdx := 424 }, stop := { byteIdx := 449 } }, + name := { dialect := "Core", name := "declPush" }, args := ((Array.mkEmpty 2).push (ArgF.op - { ann := { start := { byteIdx := 423 }, stop := { byteIdx := 441 } }, - name := { dialect := "Boogie", name := "declPush" }, + { ann := { start := { byteIdx := 424 }, stop := { byteIdx := 442 } }, + name := { dialect := "Core", name := "declPush" }, args := ((Array.mkEmpty 2).push (ArgF.op { ann := - { start := { byteIdx := 423 }, stop := { byteIdx := 433 } }, - name := { dialect := "Boogie", name := "declAtom" }, + { start := { byteIdx := 424 }, stop := { byteIdx := 434 } }, + name := { dialect := "Core", name := "declAtom" }, args := (Array.mkEmpty 1).push (ArgF.op { ann := - { start := { byteIdx := 423 }, - stop := { byteIdx := 433 } }, - name := { dialect := "Boogie", name := "bind_mk" }, + { start := { byteIdx := 424 }, + stop := { byteIdx := 434 } }, + name := { dialect := "Core", name := "bind_mk" }, args := (((Array.mkEmpty 3).push (ArgF.ident - { start := { byteIdx := 423 }, - stop := { byteIdx := 424 } } + { start := { byteIdx := 424 }, + stop := { byteIdx := 425 } } "m")).push (ArgF.option - { start := { byteIdx := 426 }, - stop := { byteIdx := 426 } } + { start := { byteIdx := 427 }, + stop := { byteIdx := 427 } } none)).push (ArgF.type (TypeExprF.ident - { start := { byteIdx := 426 }, - stop := { byteIdx := 429 } } - { dialect := "Boogie", name := "Map" } + { start := { byteIdx := 427 }, + stop := { byteIdx := 430 } } + { dialect := "Core", name := "Map" } (((Array.mkEmpty 2).push (TypeExprF.fvar - { start := { byteIdx := 432 }, - stop := { byteIdx := 433 } } + { start := { byteIdx := 433 }, + stop := { byteIdx := 434 } } 1 (Array.mkEmpty 0))).push (TypeExprF.fvar - { start := { byteIdx := 430 }, - stop := { byteIdx := 431 } } + { start := { byteIdx := 431 }, + stop := { byteIdx := 432 } } 0 (Array.mkEmpty 0))))) }) })).push (ArgF.op - { ann := { start := { byteIdx := 435 }, stop := { byteIdx := 441 } }, - name := { dialect := "Boogie", name := "bind_mk" }, + { ann := { start := { byteIdx := 436 }, stop := { byteIdx := 442 } }, + name := { dialect := "Core", name := "bind_mk" }, args := (((Array.mkEmpty 3).push (ArgF.ident - { start := { byteIdx := 435 }, - stop := { byteIdx := 438 } } + { start := { byteIdx := 436 }, + stop := { byteIdx := 439 } } "okk")).push (ArgF.option - { start := { byteIdx := 440 }, stop := { byteIdx := 440 } } + { start := { byteIdx := 441 }, stop := { byteIdx := 441 } } none)).push (ArgF.type (TypeExprF.fvar - { start := { byteIdx := 440 }, stop := { byteIdx := 441 } } 0 + { start := { byteIdx := 441 }, stop := { byteIdx := 442 } } 0 (Array.mkEmpty 0))) }) })).push (ArgF.op - { ann := { start := { byteIdx := 443 }, stop := { byteIdx := 448 } }, - name := { dialect := "Boogie", name := "bind_mk" }, + { ann := { start := { byteIdx := 444 }, stop := { byteIdx := 449 } }, + name := { dialect := "Core", name := "bind_mk" }, args := (((Array.mkEmpty 3).push (ArgF.ident - { start := { byteIdx := 443 }, stop := { byteIdx := 445 } } + { start := { byteIdx := 444 }, stop := { byteIdx := 446 } } "kk")).push - (ArgF.option { start := { byteIdx := 447 }, stop := { byteIdx := 447 } } + (ArgF.option { start := { byteIdx := 448 }, stop := { byteIdx := 448 } } none)).push (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 447 }, stop := { byteIdx := 448 } } + (TypeExprF.fvar { start := { byteIdx := 448 }, stop := { byteIdx := 449 } } 0 (Array.mkEmpty 0))) }) })).push (ArgF.op - { ann := { start := { byteIdx := 450 }, stop := { byteIdx := 455 } }, - name := { dialect := "Boogie", name := "bind_mk" }, + { ann := { start := { byteIdx := 451 }, stop := { byteIdx := 456 } }, + name := { dialect := "Core", name := "bind_mk" }, args := (((Array.mkEmpty 3).push - (ArgF.ident { start := { byteIdx := 450 }, stop := { byteIdx := 452 } } + (ArgF.ident { start := { byteIdx := 451 }, stop := { byteIdx := 453 } } "vv")).push - (ArgF.option { start := { byteIdx := 454 }, stop := { byteIdx := 454 } } none)).push + (ArgF.option { start := { byteIdx := 455 }, stop := { byteIdx := 455 } } none)).push (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 454 }, stop := { byteIdx := 455 } } 1 + (TypeExprF.fvar { start := { byteIdx := 455 }, stop := { byteIdx := 456 } } 1 (Array.mkEmpty 0))) }) })) (ArgF.expr - (ExprF.app { start := { byteIdx := 459 }, stop := { byteIdx := 485 } } - (ExprF.app { start := { byteIdx := 459 }, stop := { byteIdx := 485 } } - (ExprF.app { start := { byteIdx := 459 }, stop := { byteIdx := 485 } } - (ExprF.fn { start := { byteIdx := 459 }, stop := { byteIdx := 485 } } - { dialect := "Boogie", name := "equal" }) + (ExprF.app { start := { byteIdx := 460 }, stop := { byteIdx := 486 } } + (ExprF.app { start := { byteIdx := 460 }, stop := { byteIdx := 486 } } + (ExprF.app { start := { byteIdx := 460 }, stop := { byteIdx := 486 } } + (ExprF.fn { start := { byteIdx := 460 }, stop := { byteIdx := 486 } } + { dialect := "Core", name := "equal" }) (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 432 }, stop := { byteIdx := 433 } } 1 (Array.mkEmpty 0)))) + (TypeExprF.fvar { start := { byteIdx := 433 }, stop := { byteIdx := 434 } } 1 (Array.mkEmpty 0)))) (ArgF.expr - (ExprF.app { start := { byteIdx := 459 }, stop := { byteIdx := 475 } } - (ExprF.app { start := { byteIdx := 459 }, stop := { byteIdx := 475 } } - (ExprF.app { start := { byteIdx := 459 }, stop := { byteIdx := 475 } } - (ExprF.app { start := { byteIdx := 459 }, stop := { byteIdx := 475 } } - (ExprF.fn { start := { byteIdx := 459 }, stop := { byteIdx := 475 } } - { dialect := "Boogie", name := "map_get" }) + (ExprF.app { start := { byteIdx := 460 }, stop := { byteIdx := 476 } } + (ExprF.app { start := { byteIdx := 460 }, stop := { byteIdx := 476 } } + (ExprF.app { start := { byteIdx := 460 }, stop := { byteIdx := 476 } } + (ExprF.app { start := { byteIdx := 460 }, stop := { byteIdx := 476 } } + (ExprF.fn { start := { byteIdx := 460 }, stop := { byteIdx := 476 } } + { dialect := "Core", name := "map_get" }) (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 430 }, stop := { byteIdx := 431 } } 0 + (TypeExprF.fvar { start := { byteIdx := 431 }, stop := { byteIdx := 432 } } 0 (Array.mkEmpty 0)))) (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 432 }, stop := { byteIdx := 433 } } 1 + (TypeExprF.fvar { start := { byteIdx := 433 }, stop := { byteIdx := 434 } } 1 (Array.mkEmpty 0)))) (ArgF.expr - (ExprF.app { start := { byteIdx := 459 }, stop := { byteIdx := 470 } } - (ExprF.app { start := { byteIdx := 459 }, stop := { byteIdx := 470 } } - (ExprF.app { start := { byteIdx := 459 }, stop := { byteIdx := 470 } } - (ExprF.app { start := { byteIdx := 459 }, stop := { byteIdx := 470 } } - (ExprF.app { start := { byteIdx := 459 }, stop := { byteIdx := 470 } } - (ExprF.fn { start := { byteIdx := 459 }, stop := { byteIdx := 470 } } - { dialect := "Boogie", name := "map_set" }) + (ExprF.app { start := { byteIdx := 460 }, stop := { byteIdx := 471 } } + (ExprF.app { start := { byteIdx := 460 }, stop := { byteIdx := 471 } } + (ExprF.app { start := { byteIdx := 460 }, stop := { byteIdx := 471 } } + (ExprF.app { start := { byteIdx := 460 }, stop := { byteIdx := 471 } } + (ExprF.app { start := { byteIdx := 460 }, stop := { byteIdx := 471 } } + (ExprF.fn { start := { byteIdx := 460 }, stop := { byteIdx := 471 } } + { dialect := "Core", name := "map_set" }) (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 430 }, stop := { byteIdx := 431 } } 0 + (TypeExprF.fvar { start := { byteIdx := 431 }, stop := { byteIdx := 432 } } 0 (Array.mkEmpty 0)))) (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 432 }, stop := { byteIdx := 433 } } 1 + (TypeExprF.fvar { start := { byteIdx := 433 }, stop := { byteIdx := 434 } } 1 (Array.mkEmpty 0)))) - (ArgF.expr (ExprF.bvar { start := { byteIdx := 459 }, stop := { byteIdx := 460 } } 3))) - (ArgF.expr (ExprF.bvar { start := { byteIdx := 461 }, stop := { byteIdx := 463 } } 1))) - (ArgF.expr (ExprF.bvar { start := { byteIdx := 467 }, stop := { byteIdx := 469 } } 0))))) - (ArgF.expr (ExprF.bvar { start := { byteIdx := 471 }, stop := { byteIdx := 474 } } 2))))) + (ArgF.expr (ExprF.bvar { start := { byteIdx := 460 }, stop := { byteIdx := 461 } } 3))) + (ArgF.expr (ExprF.bvar { start := { byteIdx := 462 }, stop := { byteIdx := 464 } } 1))) + (ArgF.expr (ExprF.bvar { start := { byteIdx := 468 }, stop := { byteIdx := 470 } } 0))))) + (ArgF.expr (ExprF.bvar { start := { byteIdx := 472 }, stop := { byteIdx := 475 } } 2))))) (ArgF.expr - (ExprF.app { start := { byteIdx := 479 }, stop := { byteIdx := 485 } } - (ExprF.app { start := { byteIdx := 479 }, stop := { byteIdx := 485 } } - (ExprF.app { start := { byteIdx := 479 }, stop := { byteIdx := 485 } } - (ExprF.app { start := { byteIdx := 479 }, stop := { byteIdx := 485 } } - (ExprF.fn { start := { byteIdx := 479 }, stop := { byteIdx := 485 } } - { dialect := "Boogie", name := "map_get" }) + (ExprF.app { start := { byteIdx := 480 }, stop := { byteIdx := 486 } } + (ExprF.app { start := { byteIdx := 480 }, stop := { byteIdx := 486 } } + (ExprF.app { start := { byteIdx := 480 }, stop := { byteIdx := 486 } } + (ExprF.app { start := { byteIdx := 480 }, stop := { byteIdx := 486 } } + (ExprF.fn { start := { byteIdx := 480 }, stop := { byteIdx := 486 } } + { dialect := "Core", name := "map_get" }) (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 430 }, stop := { byteIdx := 431 } } 0 + (TypeExprF.fvar { start := { byteIdx := 431 }, stop := { byteIdx := 432 } } 0 (Array.mkEmpty 0)))) (ArgF.type - (TypeExprF.fvar { start := { byteIdx := 432 }, stop := { byteIdx := 433 } } 1 + (TypeExprF.fvar { start := { byteIdx := 433 }, stop := { byteIdx := 434 } } 1 (Array.mkEmpty 0)))) - (ArgF.expr (ExprF.bvar { start := { byteIdx := 479 }, stop := { byteIdx := 480 } } 3))) - (ArgF.expr (ExprF.bvar { start := { byteIdx := 481 }, stop := { byteIdx := 484 } } 2)))))))) }] + (ArgF.expr (ExprF.bvar { start := { byteIdx := 480 }, stop := { byteIdx := 481 } } 3))) + (ArgF.expr (ExprF.bvar { start := { byteIdx := 482 }, stop := { byteIdx := 485 } } 2)))))))) }] -/ #guard_msgs in #eval examplePgm.commands @@ -402,7 +402,7 @@ info: [LExpr.quant () QuantifierKind.all (some Lambda.LMonoTy.tcons "v"]) (LExpr.bvar () 0) (LExpr.quant () QuantifierKind.all (some Lambda.LMonoTy.ftvar "k") (LExpr.bvar () 0) (LExpr.quant () QuantifierKind.all (some Lambda.LMonoTy.ftvar "v") (LExpr.bvar () 0) (LExpr.eq () (LExpr.app () (LExpr.app () (LExpr.op () { name := "select", - metadata := Boogie.Visibility.unres } (some Lambda.LMonoTy.tcons + metadata := Core.Visibility.unres } (some Lambda.LMonoTy.tcons "arrow" [Lambda.LMonoTy.tcons "Map" [Lambda.LMonoTy.ftvar "k", Lambda.LMonoTy.ftvar "v"], Lambda.LMonoTy.tcons @@ -410,7 +410,7 @@ info: [LExpr.quant () QuantifierKind.all (some Lambda.LMonoTy.tcons [Lambda.LMonoTy.ftvar "k", Lambda.LMonoTy.ftvar "v"]])) (LExpr.app () (LExpr.app () (LExpr.app () (LExpr.op () { name := "update", - metadata := Boogie.Visibility.unres } (some Lambda.LMonoTy.tcons + metadata := Core.Visibility.unres } (some Lambda.LMonoTy.tcons "arrow" [Lambda.LMonoTy.tcons "Map" [Lambda.LMonoTy.ftvar "k", Lambda.LMonoTy.ftvar "v"], Lambda.LMonoTy.tcons @@ -432,7 +432,7 @@ info: [LExpr.quant () QuantifierKind.all (some Lambda.LMonoTy.tcons "k") (LExpr.bvar () 0) (LExpr.quant () QuantifierKind.all (some Lambda.LMonoTy.ftvar "k") (LExpr.bvar () 0) (LExpr.quant () QuantifierKind.all (some Lambda.LMonoTy.ftvar "v") (LExpr.bvar () 0) (LExpr.eq () (LExpr.app () (LExpr.app () (LExpr.op () { name := "select", - metadata := Boogie.Visibility.unres } (some Lambda.LMonoTy.tcons + metadata := Core.Visibility.unres } (some Lambda.LMonoTy.tcons "arrow" [Lambda.LMonoTy.tcons "Map" [Lambda.LMonoTy.ftvar "k", Lambda.LMonoTy.ftvar "v"], Lambda.LMonoTy.tcons @@ -440,7 +440,7 @@ info: [LExpr.quant () QuantifierKind.all (some Lambda.LMonoTy.tcons [Lambda.LMonoTy.ftvar "k", Lambda.LMonoTy.ftvar "v"]])) (LExpr.app () (LExpr.app () (LExpr.app () (LExpr.op () { name := "update", - metadata := Boogie.Visibility.unres } (some Lambda.LMonoTy.tcons + metadata := Core.Visibility.unres } (some Lambda.LMonoTy.tcons "arrow" [Lambda.LMonoTy.tcons "Map" [Lambda.LMonoTy.ftvar "k", Lambda.LMonoTy.ftvar "v"], Lambda.LMonoTy.tcons @@ -454,7 +454,7 @@ info: [LExpr.quant () QuantifierKind.all (some Lambda.LMonoTy.tcons [Lambda.LMonoTy.ftvar "k", Lambda.LMonoTy.ftvar "v"]]]])) (LExpr.bvar () 3)) (LExpr.bvar () 1)) (LExpr.bvar () 0))) (LExpr.bvar () 2)) (LExpr.app () (LExpr.app () (LExpr.op () { name := "select", - metadata := Boogie.Visibility.unres } (some Lambda.LMonoTy.tcons + metadata := Core.Visibility.unres } (some Lambda.LMonoTy.tcons "arrow" [Lambda.LMonoTy.tcons "Map" [Lambda.LMonoTy.ftvar "k", Lambda.LMonoTy.ftvar "v"], Lambda.LMonoTy.tcons diff --git a/StrataTest/Languages/Boogie/Examples/DDMTransform.lean b/StrataTest/Languages/Core/Examples/DDMTransform.lean similarity index 97% rename from StrataTest/Languages/Boogie/Examples/DDMTransform.lean rename to StrataTest/Languages/Core/Examples/DDMTransform.lean index 2edbf2acb..ae12923f3 100644 --- a/StrataTest/Languages/Boogie/Examples/DDMTransform.lean +++ b/StrataTest/Languages/Core/Examples/DDMTransform.lean @@ -4,7 +4,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata @@ -12,7 +12,7 @@ set_option maxRecDepth 10000 def msPgm : Program := #strata -program Boogie; +program Core; // Running example from Mutual Summaries paper // // int g; diff --git a/StrataTest/Languages/Boogie/Examples/DatatypeEnum.lean b/StrataTest/Languages/Core/Examples/DatatypeEnum.lean similarity index 97% rename from StrataTest/Languages/Boogie/Examples/DatatypeEnum.lean rename to StrataTest/Languages/Core/Examples/DatatypeEnum.lean index c437521e8..ab5c5aa0a 100644 --- a/StrataTest/Languages/Boogie/Examples/DatatypeEnum.lean +++ b/StrataTest/Languages/Core/Examples/DatatypeEnum.lean @@ -4,7 +4,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier /-! # Datatype Enum Integration Test @@ -24,7 +24,7 @@ namespace Strata.DatatypeEnumTest def enumPgm : Program := #strata -program Boogie; +program Core; // Define an enum-style datatype with no fields datatype Color () { Red(), Green(), Blue() }; @@ -79,7 +79,7 @@ Result: ✅ pass def enumHavocPgm : Program := #strata -program Boogie; +program Core; datatype Color () { Red(), Green(), Blue() }; @@ -132,7 +132,7 @@ Result: ✅ pass def enumExhaustivePgm : Program := #strata -program Boogie; +program Core; datatype Color () { Red(), Green(), Blue() }; diff --git a/StrataTest/Languages/Boogie/Examples/DatatypeList.lean b/StrataTest/Languages/Core/Examples/DatatypeList.lean similarity index 98% rename from StrataTest/Languages/Boogie/Examples/DatatypeList.lean rename to StrataTest/Languages/Core/Examples/DatatypeList.lean index e734362de..1cdaa36a1 100644 --- a/StrataTest/Languages/Boogie/Examples/DatatypeList.lean +++ b/StrataTest/Languages/Core/Examples/DatatypeList.lean @@ -4,7 +4,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier /-! # Datatype List Integration Test @@ -26,7 +26,7 @@ namespace Strata.DatatypeListTest def listTesterPgm : Program := #strata -program Boogie; +program Core; // Define List datatype with Nil() and Cons(head: int, tail: List) constructors // Note: This is a recursive datatype - tail has type List @@ -95,7 +95,7 @@ Result: ✅ pass def listHavocPgm : Program := #strata -program Boogie; +program Core; datatype List () { Nil(), Cons(head: int, tail: List) }; @@ -141,7 +141,7 @@ Result: ✅ pass def listExhaustivePgm : Program := #strata -program Boogie; +program Core; datatype List () { Nil(), Cons(head: int, tail: List) }; @@ -184,7 +184,7 @@ Result: ✅ pass def listMutualExclusionPgm : Program := #strata -program Boogie; +program Core; datatype List () { Nil(), Cons(head: int, tail: List) }; @@ -230,7 +230,7 @@ Result: ✅ pass def listEqualityPgm : Program := #strata -program Boogie; +program Core; datatype List () { Nil(), Cons(head: int, tail: List) }; @@ -285,7 +285,7 @@ Result: ✅ pass def listInequalityPgm : Program := #strata -program Boogie; +program Core; datatype List () { Nil(), Cons(head: int, tail: List) }; @@ -329,7 +329,7 @@ Result: ✅ pass def listDestructorPgm : Program := #strata -program Boogie; +program Core; datatype List () { Nil(), Cons(head: int, tail: List) }; @@ -402,7 +402,7 @@ Result: ✅ pass def listNestedPgm : Program := #strata -program Boogie; +program Core; datatype List () { Nil(), Cons(head: int, tail: List) }; @@ -448,7 +448,7 @@ Result: ✅ pass def listDestructorHavocPgm : Program := #strata -program Boogie; +program Core; datatype List () { Nil(), Cons(head: int, tail: List) }; @@ -498,7 +498,7 @@ Result: ✅ pass def listDifferentValuesPgm : Program := #strata -program Boogie; +program Core; datatype List () { Nil(), Cons(head: int, tail: List) }; diff --git a/StrataTest/Languages/Boogie/Examples/DatatypeOption.lean b/StrataTest/Languages/Core/Examples/DatatypeOption.lean similarity index 98% rename from StrataTest/Languages/Boogie/Examples/DatatypeOption.lean rename to StrataTest/Languages/Core/Examples/DatatypeOption.lean index 62b72b188..c0572d6d4 100644 --- a/StrataTest/Languages/Boogie/Examples/DatatypeOption.lean +++ b/StrataTest/Languages/Core/Examples/DatatypeOption.lean @@ -4,7 +4,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier /-! # Datatype Option Integration Test @@ -25,7 +25,7 @@ namespace Strata.DatatypeOptionTest def optionTesterPgm : Program := #strata -program Boogie; +program Core; // Define Option datatype with None() and Some(val: int) constructors datatype Option () { None(), Some(val: int) }; @@ -93,7 +93,7 @@ Result: ✅ pass def optionHavocPgm : Program := #strata -program Boogie; +program Core; datatype Option () { None(), Some(val: int) }; @@ -139,7 +139,7 @@ Result: ✅ pass def optionExhaustivePgm : Program := #strata -program Boogie; +program Core; datatype Option () { None(), Some(val: int) }; @@ -182,7 +182,7 @@ Result: ✅ pass def optionMutualExclusionPgm : Program := #strata -program Boogie; +program Core; datatype Option () { None(), Some(val: int) }; @@ -228,7 +228,7 @@ Result: ✅ pass def optionEqualityPgm : Program := #strata -program Boogie; +program Core; datatype Option () { None(), Some(val: int) }; @@ -283,7 +283,7 @@ Result: ✅ pass def optionInequalityPgm : Program := #strata -program Boogie; +program Core; datatype Option () { None(), Some(val: int) }; @@ -327,7 +327,7 @@ Result: ✅ pass def optionDestructorPgm : Program := #strata -program Boogie; +program Core; datatype Option () { None(), Some(val: int) }; diff --git a/StrataTest/Languages/Boogie/Examples/DatatypeTree.lean b/StrataTest/Languages/Core/Examples/DatatypeTree.lean similarity index 98% rename from StrataTest/Languages/Boogie/Examples/DatatypeTree.lean rename to StrataTest/Languages/Core/Examples/DatatypeTree.lean index d2296073d..055653804 100644 --- a/StrataTest/Languages/Boogie/Examples/DatatypeTree.lean +++ b/StrataTest/Languages/Core/Examples/DatatypeTree.lean @@ -4,7 +4,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier /-! # Datatype Tree Integration Test @@ -25,7 +25,7 @@ namespace Strata.DatatypeTreeTest def treeTesterPgm : Program := #strata -program Boogie; +program Core; // Define Tree datatype with Leaf(val: int) and Node(left: Tree, right: Tree) constructors datatype Tree () { Leaf(val: int), Node(left: Tree, right: Tree) }; @@ -93,7 +93,7 @@ Result: ✅ pass def treeHavocPgm : Program := #strata -program Boogie; +program Core; datatype Tree () { Leaf(val: int), Node(left: Tree, right: Tree) }; @@ -139,7 +139,7 @@ Result: ✅ pass def treeExhaustivePgm : Program := #strata -program Boogie; +program Core; datatype Tree () { Leaf(val: int), Node(left: Tree, right: Tree) }; @@ -182,7 +182,7 @@ Result: ✅ pass def treeMutualExclusionPgm : Program := #strata -program Boogie; +program Core; datatype Tree () { Leaf(val: int), Node(left: Tree, right: Tree) }; @@ -228,7 +228,7 @@ Result: ✅ pass def treeEqualityPgm : Program := #strata -program Boogie; +program Core; datatype Tree () { Leaf(val: int), Node(left: Tree, right: Tree) }; @@ -283,7 +283,7 @@ Result: ✅ pass def treeInequalityPgm : Program := #strata -program Boogie; +program Core; datatype Tree () { Leaf(val: int), Node(left: Tree, right: Tree) }; @@ -327,7 +327,7 @@ Result: ✅ pass def treeDestructorPgm : Program := #strata -program Boogie; +program Core; datatype Tree () { Leaf(val: int), Node(left: Tree, right: Tree) }; @@ -408,7 +408,7 @@ Result: ✅ pass def treeNestedPgm : Program := #strata -program Boogie; +program Core; datatype Tree () { Leaf(val: int), Node(left: Tree, right: Tree) }; @@ -470,7 +470,7 @@ Result: ✅ pass def treeDestructorHavocPgm : Program := #strata -program Boogie; +program Core; datatype Tree () { Leaf(val: int), Node(left: Tree, right: Tree) }; @@ -520,7 +520,7 @@ Result: ✅ pass def treeDifferentValuesPgm : Program := #strata -program Boogie; +program Core; datatype Tree () { Leaf(val: int), Node(left: Tree, right: Tree) }; diff --git a/StrataTest/Languages/Boogie/Examples/FailingAssertion.lean b/StrataTest/Languages/Core/Examples/FailingAssertion.lean similarity index 94% rename from StrataTest/Languages/Boogie/Examples/FailingAssertion.lean rename to StrataTest/Languages/Core/Examples/FailingAssertion.lean index 0765a5801..10972fa26 100644 --- a/StrataTest/Languages/Boogie/Examples/FailingAssertion.lean +++ b/StrataTest/Languages/Core/Examples/FailingAssertion.lean @@ -5,14 +5,14 @@ -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- open Strata private def failing := #strata -program Boogie; +program Core; type MapII := Map int int; @@ -49,7 +49,7 @@ Errors: #[] #eval TransM.run Inhabited.default (translateProgram failing) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: @@ -91,7 +91,7 @@ Result: ❌ fail private def failingThrice := #strata -program Boogie; +program Core; procedure P(x : int) returns () spec { diff --git a/StrataTest/Languages/Boogie/Examples/FreeRequireEnsure.lean b/StrataTest/Languages/Core/Examples/FreeRequireEnsure.lean similarity index 88% rename from StrataTest/Languages/Boogie/Examples/FreeRequireEnsure.lean rename to StrataTest/Languages/Core/Examples/FreeRequireEnsure.lean index e4b0c22d2..65638af5a 100644 --- a/StrataTest/Languages/Boogie/Examples/FreeRequireEnsure.lean +++ b/StrataTest/Languages/Core/Examples/FreeRequireEnsure.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def freeReqEnsPgm : Program := #strata -program Boogie; +program Core; var g : int; procedure Proc() returns () spec { @@ -33,7 +33,7 @@ procedure ProcCaller () returns (x : int) { #end /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. Obligation (Origin_Proc_Requires)g_eq_15 is free! @@ -77,8 +77,8 @@ Evaluated program: var (g : int) := init_g_0 (procedure Proc : () → ()) modifies: [g] -preconditions: (g_eq_15, ((g : int) == #15) (Attribute: Boogie.Procedure.CheckAttr.Free)) -postconditions: (g_lt_10, (((~Int.Lt : (arrow int (arrow int bool))) (g : int)) #10) (Attribute: Boogie.Procedure.CheckAttr.Free)) +preconditions: (g_eq_15, ((g : int) == #15) (Attribute: Core.Procedure.CheckAttr.Free)) +postconditions: (g_lt_10, (((~Int.Lt : (arrow int (arrow int bool))) (g : int)) #10) (Attribute: Core.Procedure.CheckAttr.Free)) body: assume [g_eq_15] ($__g0 == #15) assert [g_gt_10_internal] ((~Int.Gt $__g0) #10) g := ((~Int.Add $__g0) #1) diff --git a/StrataTest/Languages/Boogie/Examples/Functions.lean b/StrataTest/Languages/Core/Examples/Functions.lean similarity index 73% rename from StrataTest/Languages/Boogie/Examples/Functions.lean rename to StrataTest/Languages/Core/Examples/Functions.lean index 582e6c436..a6d9de8be 100644 --- a/StrataTest/Languages/Boogie/Examples/Functions.lean +++ b/StrataTest/Languages/Core/Examples/Functions.lean @@ -4,15 +4,15 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier -import Strata.Languages.Boogie.CallGraph +import Strata.Languages.Core.Verifier +import Strata.Languages.Core.CallGraph --------------------------------------------------------------------- namespace Strata def funcPgm : Program := #strata -program Boogie; +program Core; const fooConst : int; inline function fooTest() : int { fooConst } @@ -35,17 +35,17 @@ barTest1 callers: [barTest4, barTest3] fooConst callees: [] -/ #guard_msgs in -#eval let (program, _) := Boogie.getProgram funcPgm - let cg := (Boogie.Program.toFunctionCG program) - let ans1 := Boogie.CallGraph.getCalleesClosure cg "barTest4" - let ans2 := Boogie.CallGraph.getCallersClosure cg "barTest1" - let ans3 := Boogie.CallGraph.getCalleesClosure cg "fooConst" +#eval let (program, _) := Core.getProgram funcPgm + let cg := (Core.Program.toFunctionCG program) + let ans1 := Core.CallGraph.getCalleesClosure cg "barTest4" + let ans2 := Core.CallGraph.getCallersClosure cg "barTest1" + let ans3 := Core.CallGraph.getCalleesClosure cg "fooConst" Std.format f!"barTest4 callees: {ans1}\n\ barTest1 callers: {ans2}\n\ fooConst callees: {ans3}" /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/GeneratedLabels.lean b/StrataTest/Languages/Core/Examples/GeneratedLabels.lean similarity index 95% rename from StrataTest/Languages/Boogie/Examples/GeneratedLabels.lean rename to StrataTest/Languages/Core/Examples/GeneratedLabels.lean index 1c04f149c..f154f9d8a 100644 --- a/StrataTest/Languages/Boogie/Examples/GeneratedLabels.lean +++ b/StrataTest/Languages/Core/Examples/GeneratedLabels.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def genLabelsPgm : Program := #strata -program Boogie; +program Core; type Ref; type Field; @@ -34,8 +34,8 @@ procedure test(h: Heap, ref: Ref, field: Field) returns () #end /-- -info: type Boogie.Boundedness.Infinite Ref [] -type Boogie.Boundedness.Infinite Field [] +info: type Core.Boundedness.Infinite Ref [] +type Core.Boundedness.Infinite Field [] type Struct := (Map Field int) type Heap := (Map Ref Struct) axiom axiom_0: (∀ (∀ (∀ (∀ (((~Bool.Implies : (arrow bool (arrow bool bool))) ((~Bool.Not : (arrow bool bool)) (%2 == %1))) ((((~select : (arrow (Map Field int) (arrow Field int))) %3) %2) == (((~select : (arrow (Map Field int) (arrow Field int))) ((((~update : (arrow (Map Field int) (arrow Field (arrow int (Map Field int))))) %3) %1) %0)) %2))))))); @@ -53,7 +53,7 @@ assert [assert_0] ((((~select : (arrow (Map Field int) (arrow Field int))) (((~s #eval (TransM.run Inhabited.default (translateProgram genLabelsPgm) |>.fst) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/Goto.lean b/StrataTest/Languages/Core/Examples/Goto.lean similarity index 89% rename from StrataTest/Languages/Boogie/Examples/Goto.lean rename to StrataTest/Languages/Core/Examples/Goto.lean index f5b06728b..9c9671649 100644 --- a/StrataTest/Languages/Boogie/Examples/Goto.lean +++ b/StrataTest/Languages/Core/Examples/Goto.lean @@ -4,15 +4,15 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Boogie -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Core +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def gotoPgm : Program := #strata -program Boogie; +program Core; var g : bool; procedure Test1(x : bool) returns (y : bool) { @@ -54,10 +54,10 @@ procedure Test2(x : int) returns (y : bool) #end -- def p := (translateProgram gotoEnv.commands).run --- def err := Boogie.typeCheckAndPartialEval p.fst +-- def err := Core.typeCheckAndPartialEval p.fst /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/Havoc.lean b/StrataTest/Languages/Core/Examples/Havoc.lean similarity index 92% rename from StrataTest/Languages/Boogie/Examples/Havoc.lean rename to StrataTest/Languages/Core/Examples/Havoc.lean index 6c9263fc5..192e7af28 100644 --- a/StrataTest/Languages/Boogie/Examples/Havoc.lean +++ b/StrataTest/Languages/Core/Examples/Havoc.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def havocPgm : Program := #strata -program Boogie; +program Core; procedure S() returns () { var x : int; @@ -42,7 +42,7 @@ Errors: #[] #eval TransM.run Inhabited.default (translateProgram havocPgm) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/Loops.lean b/StrataTest/Languages/Core/Examples/Loops.lean similarity index 96% rename from StrataTest/Languages/Boogie/Examples/Loops.lean rename to StrataTest/Languages/Core/Examples/Loops.lean index 21cbc94ce..69d6f39d8 100644 --- a/StrataTest/Languages/Boogie/Examples/Loops.lean +++ b/StrataTest/Languages/Core/Examples/Loops.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def gaussPgm := #strata -program Boogie; +program Core; procedure sum(n : int) returns (s : int) spec { @@ -34,7 +34,7 @@ spec { #end /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: @@ -85,7 +85,7 @@ Result: ✅ pass def nestedPgm := #strata -program Boogie; +program Core; const top : int; axiom [top100]: top == 100; diff --git a/StrataTest/Languages/Boogie/Examples/Map.lean b/StrataTest/Languages/Core/Examples/Map.lean similarity index 94% rename from StrataTest/Languages/Boogie/Examples/Map.lean rename to StrataTest/Languages/Core/Examples/Map.lean index b6409d133..7f409943c 100644 --- a/StrataTest/Languages/Boogie/Examples/Map.lean +++ b/StrataTest/Languages/Core/Examples/Map.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier open Strata --------------------------------------------------------------------- private def mapPgm := #strata -program Boogie; +program Core; const a : Map int bool; @@ -44,7 +44,7 @@ Errors: #[] #eval TransM.run Inhabited.default (translateProgram mapPgm) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/Min.lean b/StrataTest/Languages/Core/Examples/Min.lean similarity index 88% rename from StrataTest/Languages/Boogie/Examples/Min.lean rename to StrataTest/Languages/Core/Examples/Min.lean index 166c8f350..b3d6b5b66 100644 --- a/StrataTest/Languages/Boogie/Examples/Min.lean +++ b/StrataTest/Languages/Core/Examples/Min.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata private def testPgm : Program := #strata -program Boogie; +program Core; procedure min(n : int, m : int) returns (k : int) spec { @@ -25,7 +25,7 @@ spec { /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/OldExpressions.lean b/StrataTest/Languages/Core/Examples/OldExpressions.lean similarity index 96% rename from StrataTest/Languages/Boogie/Examples/OldExpressions.lean rename to StrataTest/Languages/Core/Examples/OldExpressions.lean index 27f6ea8de..429214708 100644 --- a/StrataTest/Languages/Boogie/Examples/OldExpressions.lean +++ b/StrataTest/Languages/Core/Examples/OldExpressions.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def oldExprPgm : Program := #strata -program Boogie; +program Core; var g : bool; var g2 : bool; @@ -50,7 +50,7 @@ spec { #end /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/PrecedenceCheck.lean b/StrataTest/Languages/Core/Examples/PrecedenceCheck.lean similarity index 95% rename from StrataTest/Languages/Boogie/Examples/PrecedenceCheck.lean rename to StrataTest/Languages/Core/Examples/PrecedenceCheck.lean index b9cc7fb9c..2b01f55d7 100644 --- a/StrataTest/Languages/Boogie/Examples/PrecedenceCheck.lean +++ b/StrataTest/Languages/Core/Examples/PrecedenceCheck.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def precPgm : Program := #strata -program Boogie; +program Core; function foo(a : bool, b : bool, c : bool, d : bool) : bool { (((!a) || b) && ((!c) || d)) @@ -34,7 +34,7 @@ procedure TestFoo () returns () { #end /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/ProcedureCall.lean b/StrataTest/Languages/Core/Examples/ProcedureCall.lean similarity index 90% rename from StrataTest/Languages/Boogie/Examples/ProcedureCall.lean rename to StrataTest/Languages/Core/Examples/ProcedureCall.lean index bd2e7b70f..81487018f 100644 --- a/StrataTest/Languages/Boogie/Examples/ProcedureCall.lean +++ b/StrataTest/Languages/Core/Examples/ProcedureCall.lean @@ -4,15 +4,15 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier -import Strata.Languages.Boogie.CallGraph +import Strata.Languages.Core.Verifier +import Strata.Languages.Core.CallGraph --------------------------------------------------------------------- namespace Strata def globalCounterPgm : Program := #strata -program Boogie; +program Core; var counter : int; @@ -54,11 +54,11 @@ info: { callees := Std.HashMap.ofList [("Inc", []), ("Q2", ["Q1"]), ("P", ["Inc" callers := Std.HashMap.ofList [("Inc", ["P"]), ("Q1", ["Q2"])] } -/ #guard_msgs in -#eval let (program, _) := Boogie.getProgram globalCounterPgm - Boogie.Program.toProcedureCG program +#eval let (program, _) := Core.getProgram globalCounterPgm + Core.Program.toProcedureCG program /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: @@ -147,7 +147,7 @@ Result: ✅ pass -- DDM AST #eval globalCounterEnv.commands --- Translation from DDM AST to Boogie/Strata AST +-- Translation from DDM AST to Strata Core AST #eval TransM.run (translateProgram (globalCounterEnv.commands)) -/ diff --git a/StrataTest/Languages/Boogie/Examples/Quantifiers.lean b/StrataTest/Languages/Core/Examples/Quantifiers.lean similarity index 95% rename from StrataTest/Languages/Boogie/Examples/Quantifiers.lean rename to StrataTest/Languages/Core/Examples/Quantifiers.lean index ce0eb42a0..458065c62 100644 --- a/StrataTest/Languages/Boogie/Examples/Quantifiers.lean +++ b/StrataTest/Languages/Core/Examples/Quantifiers.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def quantPgm := #strata -program Boogie; +program Core; procedure Test(x : int) returns (r : int) spec { ensures [good]: (forall y : int :: exists z : int :: r + (z + y) == y + (z + r)); @@ -25,7 +25,7 @@ spec { def triggerPgm := #strata -program Boogie; +program Core; function f(x : int): int; function g(x : int, y : int): int; @@ -47,7 +47,7 @@ spec { #end /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: @@ -114,7 +114,7 @@ Model: #eval verify "cvc5" quantPgm Inhabited.default Options.default /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/QuantifiersWithTypeAliases.lean b/StrataTest/Languages/Core/Examples/QuantifiersWithTypeAliases.lean similarity index 95% rename from StrataTest/Languages/Boogie/Examples/QuantifiersWithTypeAliases.lean rename to StrataTest/Languages/Core/Examples/QuantifiersWithTypeAliases.lean index 101f2097c..5c58af510 100644 --- a/StrataTest/Languages/Boogie/Examples/QuantifiersWithTypeAliases.lean +++ b/StrataTest/Languages/Core/Examples/QuantifiersWithTypeAliases.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def QuantTypeAliases := #strata -program Boogie; +program Core; type Ref; type Field; @@ -36,8 +36,8 @@ procedure test(h: Heap, ref: Ref, field: Field) returns () #guard TransM.run Inhabited.default (translateProgram QuantTypeAliases) |>.snd |>.isEmpty /-- -info: type Boogie.Boundedness.Infinite Ref [] -type Boogie.Boundedness.Infinite Field [] +info: type Core.Boundedness.Infinite Ref [] +type Core.Boundedness.Infinite Field [] type Struct := (Map Field int) type Heap := (Map Ref Struct) axiom axiom_0: (∀ (∀ (∀ (∀ (((~Bool.Implies : (arrow bool (arrow bool bool))) ((~Bool.Not : (arrow bool bool)) (%2 == %1))) ((((~select : (arrow (Map Field int) (arrow Field int))) %3) %2) == (((~select : (arrow (Map Field int) (arrow Field int))) ((((~update : (arrow (Map Field int) (arrow Field (arrow int (Map Field int))))) %3) %1) %0)) %2))))))); @@ -58,7 +58,7 @@ Errors: #[] /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/RealBitVector.lean b/StrataTest/Languages/Core/Examples/RealBitVector.lean similarity index 96% rename from StrataTest/Languages/Boogie/Examples/RealBitVector.lean rename to StrataTest/Languages/Core/Examples/RealBitVector.lean index f0e37d546..14d78d9f0 100644 --- a/StrataTest/Languages/Boogie/Examples/RealBitVector.lean +++ b/StrataTest/Languages/Core/Examples/RealBitVector.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def realPgm : Program := #strata -program Boogie; +program Core; const x : real; const y : real; @@ -49,7 +49,7 @@ Errors: #[] #eval TransM.run Inhabited.default (translateProgram realPgm) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: @@ -107,7 +107,7 @@ Result: ❌ fail def bvPgm : Program := #strata -program Boogie; +program Core; const x : bv8; const y : bv8; @@ -156,7 +156,7 @@ Errors: #[] #eval TransM.run Inhabited.default (translateProgram bvPgm) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: @@ -193,7 +193,7 @@ Result: ✅ pass def bvMoreOpsPgm : Program := #strata -program Boogie; +program Core; procedure P(x: bv8, y: bv8, z: bv8) returns () { assert [add_comm]: x + y == y + x; diff --git a/StrataTest/Languages/Boogie/Examples/RecursiveProcIte.lean b/StrataTest/Languages/Core/Examples/RecursiveProcIte.lean similarity index 97% rename from StrataTest/Languages/Boogie/Examples/RecursiveProcIte.lean rename to StrataTest/Languages/Core/Examples/RecursiveProcIte.lean index 1a6d71c05..591079605 100644 --- a/StrataTest/Languages/Boogie/Examples/RecursiveProcIte.lean +++ b/StrataTest/Languages/Core/Examples/RecursiveProcIte.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def procIfPgm : Program := #strata -program Boogie; +program Core; procedure F(n : int) returns (r : int) spec { @@ -32,7 +32,7 @@ spec { #end /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/Regex.lean b/StrataTest/Languages/Core/Examples/Regex.lean similarity index 96% rename from StrataTest/Languages/Boogie/Examples/Regex.lean rename to StrataTest/Languages/Core/Examples/Regex.lean index 91e9473a4..54105ea2d 100644 --- a/StrataTest/Languages/Boogie/Examples/Regex.lean +++ b/StrataTest/Languages/Core/Examples/Regex.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def regexPgm1 := #strata -program Boogie; +program Core; function cannot_end_with_period () : regex { re.comp(re.concat (re.* (re.all()), str.to.re("."))) @@ -48,7 +48,7 @@ procedure main() returns () { /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: @@ -169,7 +169,7 @@ Result: ✅ pass def regexPgm2 := #strata -program Boogie; +program Core; function bad_re_loop (n : int) : regex { re.loop(re.range("a", "z"), 1, n) @@ -191,7 +191,7 @@ procedure main(n : int) returns () { #end /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: @@ -270,7 +270,7 @@ Original expression: (((~Re.Loop ((~Re.Range #a) #z)) #1) %0) def regexPgm3 := #strata -program Boogie; +program Core; procedure main(n : int) returns () { @@ -281,7 +281,7 @@ procedure main(n : int) returns () { #end /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/RemoveIrrelevantAxioms.lean b/StrataTest/Languages/Core/Examples/RemoveIrrelevantAxioms.lean similarity index 98% rename from StrataTest/Languages/Boogie/Examples/RemoveIrrelevantAxioms.lean rename to StrataTest/Languages/Core/Examples/RemoveIrrelevantAxioms.lean index ce0d13505..90a10b922 100644 --- a/StrataTest/Languages/Boogie/Examples/RemoveIrrelevantAxioms.lean +++ b/StrataTest/Languages/Core/Examples/RemoveIrrelevantAxioms.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def irrelevantAxiomsTestPgm : Strata.Program := #strata -program Boogie; +program Core; type StrataHeap; type StrataRef; type StrataField (t: Type); diff --git a/StrataTest/Languages/Boogie/Examples/SimpleProc.lean b/StrataTest/Languages/Core/Examples/SimpleProc.lean similarity index 91% rename from StrataTest/Languages/Boogie/Examples/SimpleProc.lean rename to StrataTest/Languages/Core/Examples/SimpleProc.lean index afaad96cd..3372e8ac9 100644 --- a/StrataTest/Languages/Boogie/Examples/SimpleProc.lean +++ b/StrataTest/Languages/Core/Examples/SimpleProc.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def simpleProcPgm : Program := #strata -program Boogie; +program Core; var g : bool; procedure Test(x : bool) returns (y : bool) spec { @@ -24,7 +24,7 @@ spec { }; #end --- Translation from DDM AST to Boogie/Strata AST +-- Translation from DDM AST to Strata Core AST /-- info: true -/ #guard_msgs in @@ -45,7 +45,7 @@ Errors: #[] #eval TransM.run Inhabited.default (translateProgram simpleProcPgm) /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/String.lean b/StrataTest/Languages/Core/Examples/String.lean similarity index 95% rename from StrataTest/Languages/Boogie/Examples/String.lean rename to StrataTest/Languages/Core/Examples/String.lean index 9085ad8d2..226c03c8a 100644 --- a/StrataTest/Languages/Boogie/Examples/String.lean +++ b/StrataTest/Languages/Core/Examples/String.lean @@ -4,7 +4,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata @@ -16,7 +16,7 @@ namespace Strata def strPgm := #strata -program Boogie; +program Core; procedure main() returns () { @@ -37,7 +37,7 @@ procedure main() returns () { #end /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/TypeAlias.lean b/StrataTest/Languages/Core/Examples/TypeAlias.lean similarity index 93% rename from StrataTest/Languages/Boogie/Examples/TypeAlias.lean rename to StrataTest/Languages/Core/Examples/TypeAlias.lean index 1ce1a0e16..a948933d9 100644 --- a/StrataTest/Languages/Boogie/Examples/TypeAlias.lean +++ b/StrataTest/Languages/Core/Examples/TypeAlias.lean @@ -4,7 +4,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata @@ -17,7 +17,7 @@ error: Expression has type FooAlias (Foo int int) when Foo bool int expected. #guard_msgs in def badTypeAlias : Program := #strata -program Boogie; +program Core; type Foo (a : Type, b : Type); type FooAlias (a : Type) := Foo bool bool; @@ -36,7 +36,7 @@ procedure P () returns () { def goodTypeAlias : Program := #strata -program Boogie; +program Core; type Foo (a : Type, b : Type); type FooAlias (a : Type) := Foo int bool; type FooAlias2 (a : Type) := FooAlias (FooAlias bool); @@ -57,7 +57,7 @@ procedure P () returns () { #eval TransM.run Inhabited.default (translateProgram goodTypeAlias) |>.snd /-- -info: type Boogie.Boundedness.Infinite Foo [_, _] +info: type Core.Boundedness.Infinite Foo [_, _] type FooAlias a := (Foo int bool) type FooAlias2 a := (FooAlias (FooAlias bool)) func fooVal : () → (FooAlias2 (Foo int int)); @@ -75,7 +75,7 @@ assert [fooAssertion] ((~fooConst1 : (Foo int bool)) == (~fooConst2 : (Foo int b #eval TransM.run Inhabited.default (translateProgram goodTypeAlias) |>.fst /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: @@ -101,7 +101,7 @@ Result: ✅ pass def funcAndTypeAliasesPgm : Program := #strata -program Boogie; +program Core; type MapInt := Map int int; @@ -119,7 +119,7 @@ procedure test () returns () { #end /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/Examples/TypeDecl.lean b/StrataTest/Languages/Core/Examples/TypeDecl.lean similarity index 92% rename from StrataTest/Languages/Boogie/Examples/TypeDecl.lean rename to StrataTest/Languages/Core/Examples/TypeDecl.lean index 40c159470..7a1063a9b 100644 --- a/StrataTest/Languages/Boogie/Examples/TypeDecl.lean +++ b/StrataTest/Languages/Core/Examples/TypeDecl.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata private def typeDeclPgm1 : Program := #strata -program Boogie; +program Core; type Foo (a : Type, b : Type); const fooConst : Foo int bool; @@ -28,7 +28,7 @@ procedure P () returns () { #eval TransM.run Inhabited.default (translateProgram typeDeclPgm1) |>.snd /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: @@ -57,7 +57,7 @@ error: Expression has type Foo bool int when Foo bool bool expected. #guard_msgs in def typeDeclPgm2 := #strata -program Boogie; +program Core; type Foo (a : Type, b : Type); @@ -72,7 +72,7 @@ procedure P () returns () { def typeDeclPgm3 : Program := #strata -program Boogie; +program Core; type Foo (a : Type, b : Type); const fooVal : Foo int bool; @@ -91,7 +91,7 @@ procedure P () returns () { #eval TransM.run Inhabited.default (translateProgram typeDeclPgm3) |>.snd /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: @@ -118,7 +118,7 @@ Result: ✅ pass def typeDeclPgm4 := #strata -program Boogie; +program Core; type int := bool; #end diff --git a/StrataTest/Languages/Boogie/Examples/TypeVarImplicitlyQuantified.lean b/StrataTest/Languages/Core/Examples/TypeVarImplicitlyQuantified.lean similarity index 83% rename from StrataTest/Languages/Boogie/Examples/TypeVarImplicitlyQuantified.lean rename to StrataTest/Languages/Core/Examples/TypeVarImplicitlyQuantified.lean index d84cf20fa..66bd8e18d 100644 --- a/StrataTest/Languages/Boogie/Examples/TypeVarImplicitlyQuantified.lean +++ b/StrataTest/Languages/Core/Examples/TypeVarImplicitlyQuantified.lean @@ -6,13 +6,13 @@ -- Fix for https://github.com/strata-org/Strata/issues/105. -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier namespace Strata private def pgm := #strata -program Boogie; +program Core; type set := Map int bool; @@ -30,14 +30,14 @@ axiom [a2]: (forall l_0: bool, l_1: int, l_2: int, y: int :: ); #end -def boogie_pgm := TransM.run Inhabited.default (translateProgram pgm) +def core_pgm := TransM.run Inhabited.default (translateProgram pgm) /-- info: true -/ #guard_msgs in -#eval boogie_pgm.snd.isEmpty +#eval core_pgm.snd.isEmpty /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. --- info: ok: type set := (Map int bool) @@ -47,4 +47,4 @@ axiom a1: (∀ (∀ ((((~diff : (arrow (Map int bool) (arrow (Map int bool) (Map axiom a2: (∀ (∀ (∀ (∀ ((((~select : (arrow (Map int int) (arrow int int))) ((((~lambda_0 : (arrow bool (arrow int (arrow int (Map int int))))) %3) %2) %1)) %0) == (((~select : (arrow (Map int int) (arrow int int))) ((((~lambda_0 : (arrow bool (arrow int (arrow int (Map int int))))) %3) %1) %2)) %0)))))); -/ #guard_msgs in -#eval Boogie.typeCheck Options.default boogie_pgm.fst +#eval Core.typeCheck Options.default core_pgm.fst diff --git a/StrataTest/Languages/Boogie/Examples/UnreachableAssert.lean b/StrataTest/Languages/Core/Examples/UnreachableAssert.lean similarity index 93% rename from StrataTest/Languages/Boogie/Examples/UnreachableAssert.lean rename to StrataTest/Languages/Core/Examples/UnreachableAssert.lean index 5e67c4831..50d3235cb 100644 --- a/StrataTest/Languages/Boogie/Examples/UnreachableAssert.lean +++ b/StrataTest/Languages/Core/Examples/UnreachableAssert.lean @@ -4,14 +4,14 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier --------------------------------------------------------------------- namespace Strata def unreachableAssertPgm := #strata -program Boogie; +program Core; procedure R() returns () { var x : int, y : int; @@ -28,7 +28,7 @@ procedure R() returns () #end /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: diff --git a/StrataTest/Languages/Boogie/ExprEvalTest.lean b/StrataTest/Languages/Core/ExprEvalTest.lean similarity index 79% rename from StrataTest/Languages/Boogie/ExprEvalTest.lean rename to StrataTest/Languages/Core/ExprEvalTest.lean index 7dc5956ad..d0d73c937 100644 --- a/StrataTest/Languages/Boogie/ExprEvalTest.lean +++ b/StrataTest/Languages/Core/ExprEvalTest.lean @@ -10,17 +10,17 @@ import Strata.DL.Lambda.LState import Strata.DL.Lambda.LTy import Strata.DL.SMT.Term import Strata.DL.SMT.Encoder -import Strata.Languages.Boogie.Env -import Strata.Languages.Boogie.Factory -import Strata.Languages.Boogie.Identifiers -import Strata.Languages.Boogie.Options -import Strata.Languages.Boogie.SMTEncoder -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Env +import Strata.Languages.Core.Factory +import Strata.Languages.Core.Identifiers +import Strata.Languages.Core.Options +import Strata.Languages.Core.SMTEncoder +import Strata.Languages.Core.Verifier import Strata.DL.Lambda.TestGen import Strata.DL.Lambda.PlausibleHelpers import Plausible.Gen -/-! This file does random testing of Boogie operations registered in factory, by +/-! This file does random testing of Strata Core operations registered in factory, by (1) choosing random constant inputs to the operations (2) doing concrete evaluation and getting the results, (3) SMT encoding the expression, and @@ -28,28 +28,28 @@ import Plausible.Gen the SMT expression. -/ -namespace Boogie +namespace Core section Tests open Lambda open Std -def encode (e:LExpr BoogieLParams.mono) +def encode (e:LExpr CoreLParams.mono) (tenv:TEnv Visibility) - (init_state:LState BoogieLParams): + (init_state:LState CoreLParams): Except Format (Option (Strata.SMT.Term × SMT.Context)) := do - let init_state ← init_state.addFactory Boogie.Factory + let init_state ← init_state.addFactory Core.Factory let lcont := { Lambda.LContext.default with - functions := Boogie.Factory, knownTypes := Boogie.KnownTypes } + functions := Core.Factory, knownTypes := Core.KnownTypes } let (e,_T) ← LExpr.annotate lcont tenv e let e_res := LExpr.eval init_state.config.fuel init_state e match e_res with | .const _ _ => - let env := Boogie.Env.init - let (smt_term_lhs,ctx) ← Boogie.toSMTTerm env [] e SMT.Context.default - let (smt_term_rhs,ctx) ← Boogie.toSMTTerm env [] e_res ctx + let env := Core.Env.init + let (smt_term_lhs,ctx) ← Core.toSMTTerm env [] e SMT.Context.default + let (smt_term_rhs,ctx) ← Core.toSMTTerm env [] e_res ctx let smt_term_eq := Strata.SMT.Factory.eq smt_term_lhs smt_term_rhs return (.some (smt_term_eq, ctx)) | _ => return .none @@ -58,7 +58,7 @@ def encode (e:LExpr BoogieLParams.mono) Check whether concrete evaluation of e matches the SMT encoding of e. Returns false if e did not reduce to a constant. -/ -def checkValid (e:LExpr BoogieLParams.mono): IO Bool := do +def checkValid (e:LExpr CoreLParams.mono): IO Bool := do let tenv := TEnv.default let init_state := LState.init match encode e tenv init_state with @@ -67,7 +67,7 @@ def checkValid (e:LExpr BoogieLParams.mono): IO Bool := do | .ok (.some (smt_term, ctx)) => IO.FS.withTempDir (fun tempDir => do let filename := tempDir / s!"exprEvalTest.smt2" - let ans ← Boogie.SMT.dischargeObligation + let ans ← Core.SMT.dischargeObligation { Options.default with verbose := .quiet } (LExpr.freeVars e) "z3" filename.toString [smt_term] ctx @@ -101,7 +101,7 @@ private def pickRandInt (abs_bound:Nat): IO Int := do let rand_size <- IO.rand 0 abs_bound return (if rand_sign = 0 then rand_size else - (Int.ofNat rand_size)) -private def mkRandConst (ty:LMonoTy): IO (Option (LExpr BoogieLParams.mono)) +private def mkRandConst (ty:LMonoTy): IO (Option (LExpr CoreLParams.mono)) := do match ty with | .tcons "int" [] => @@ -121,7 +121,7 @@ private def mkRandConst (ty:LMonoTy): IO (Option (LExpr BoogieLParams.mono)) | .tcons "regex" [] => -- TODO: random regex generator return (.some (.app () - (.op () (BoogieIdent.unres "Str.ToRegEx") .none) (.strConst () ".*"))) + (.op () (CoreIdent.unres "Str.ToRegEx") .none) (.strConst () ".*"))) | .bitvec n => let specialvals := [0, 1, -1, Int.ofNat n, (Int.pow 2 (n-1)) - 1, -(Int.pow 2 (n-1))] @@ -131,7 +131,7 @@ private def mkRandConst (ty:LMonoTy): IO (Option (LExpr BoogieLParams.mono)) return .none def checkFactoryOps (verbose:Bool): IO Unit := do - let arr:Array (LFunc BoogieLParams) := Boogie.Factory + let arr:Array (LFunc CoreLParams) := Core.Factory let print (f:Format): IO Unit := if verbose then IO.println f else return () @@ -145,7 +145,7 @@ def checkFactoryOps (verbose:Bool): IO Unit := do let mut unsupported := false let mut cnt_skipped := 0 for _ in [0:cnt] do - let args:List (Option (LExpr BoogieLParams.mono)) + let args:List (Option (LExpr CoreLParams.mono)) <- e.inputs.mapM (fun t => do let res <- mkRandConst t.snd match res with @@ -159,7 +159,7 @@ def checkFactoryOps (verbose:Bool): IO Unit := do else let args := List.map (Option.get!) args let expr := List.foldl (fun e arg => (.app () e arg)) - (LExpr.op () (BoogieIdent.unres e.name.name) .none) args + (LExpr.op () (CoreIdent.unres e.name.name) .none) args let res <- checkValid expr if ¬ res then if cnt_skipped = 0 then @@ -185,7 +185,7 @@ open Lambda.LTy.Syntax #guard_msgs in #eval (checkValid eb[if #1 == #2 then #false else #true]) /-- info: true -/ #guard_msgs in #eval (checkValid - (.app () (.app () (.op () (BoogieIdent.unres "Int.Add") .none) eb[#100]) eb[#50])) + (.app () (.app () (.op () (CoreIdent.unres "Int.Add") .none) eb[#100]) eb[#50])) -- This may take a while (~ 5min) @@ -195,11 +195,11 @@ open Plausible TestGen deriving instance Arbitrary for Visibility -def test_lctx : LContext BoogieLParams := +def test_lctx : LContext CoreLParams := { LContext.empty with - functions := Boogie.Factory - knownTypes := Boogie.KnownTypes + functions := Core.Factory + knownTypes := Core.KnownTypes } def test_ctx : TContext Visibility := ⟨[[]], []⟩ @@ -207,7 +207,7 @@ def test_ctx : TContext Visibility := ⟨[[]], []⟩ abbrev test_ty : LTy := .forAll [] <| .tcons "bool" [] #guard_msgs(drop all) in #eval do - let P : LExpr BoogieLParams.mono → Prop := fun t => HasType test_lctx test_ctx t test_ty + let P : LExpr CoreLParams.mono → Prop := fun t => HasType test_lctx test_ctx t test_ty let t ← Gen.runUntil .none (ArbitrarySizedSuchThat.arbitrarySizedST P 5) 5 IO.println s!"Generated {t}" let b ← checkValid t @@ -216,4 +216,4 @@ abbrev test_ty : LTy := .forAll [] <| .tcons "bool" [] end Tests -end Boogie +end Core diff --git a/StrataTest/Languages/Boogie/ProcedureEvalTests.lean b/StrataTest/Languages/Core/ProcedureEvalTests.lean similarity index 99% rename from StrataTest/Languages/Boogie/ProcedureEvalTests.lean rename to StrataTest/Languages/Core/ProcedureEvalTests.lean index dd5d9f47d..f716dee51 100644 --- a/StrataTest/Languages/Boogie/ProcedureEvalTests.lean +++ b/StrataTest/Languages/Core/ProcedureEvalTests.lean @@ -4,15 +4,15 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.ProcedureEval +import Strata.Languages.Core.ProcedureEval -namespace Boogie +namespace Core --------------------------------------------------------------------- section Tests open Std (ToFormat Format format) -open Procedure Statement Lambda Lambda.LTy.Syntax Lambda.LExpr.SyntaxMono Boogie.Syntax +open Procedure Statement Lambda Lambda.LTy.Syntax Lambda.LExpr.SyntaxMono Core.Syntax /-- info: Error: @@ -240,4 +240,4 @@ Proof Obligation: end Tests --------------------------------------------------------------------- -end Boogie +end Core diff --git a/StrataTest/Languages/Boogie/ProcedureTypeTests.lean b/StrataTest/Languages/Core/ProcedureTypeTests.lean similarity index 93% rename from StrataTest/Languages/Boogie/ProcedureTypeTests.lean rename to StrataTest/Languages/Core/ProcedureTypeTests.lean index 0f2eb4e10..7379b45d9 100644 --- a/StrataTest/Languages/Boogie/ProcedureTypeTests.lean +++ b/StrataTest/Languages/Core/ProcedureTypeTests.lean @@ -4,15 +4,15 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.ProcedureType +import Strata.Languages.Core.ProcedureType -namespace Boogie +namespace Core --------------------------------------------------------------------- section Tests open Std (ToFormat Format format) -open Procedure Statement Lambda Lambda.LTy.Syntax Lambda.LExpr.SyntaxMono Boogie.Syntax +open Procedure Statement Lambda Lambda.LTy.Syntax Lambda.LExpr.SyntaxMono Core.Syntax /-- info: ok: ((procedure P : ((x : int)) → ((y : int))) @@ -26,7 +26,7 @@ info: ok: ((procedure P : ((x : int)) → ((y : int))) aliases: [] state: tyGen: 6 tyPrefix: $__ty exprGen: 0 exprPrefix: $__var subst: []) -/ #guard_msgs in -#eval do let ans ← typeCheck { LContext.default with functions := Boogie.Factory } TEnv.default +#eval do let ans ← typeCheck { LContext.default with functions := Core.Factory } TEnv.default Program.init { header := {name := "P", typeArgs := [], @@ -54,7 +54,7 @@ body: g := (((~Int.Add : (arrow int (arrow int int))) (a : int)) (g : int)) let g : TGenEnv Visibility := { @TGenEnv.default Visibility with context := {types := [[("g", t[int])]] }}; let ans ← typeCheck { @LContext.default ⟨Unit, Visibility⟩ with - functions := Boogie.Factory} {@TEnv.default Visibility with genEnv := g} + functions := Core.Factory} {@TEnv.default Visibility with genEnv := g} Program.init { header := { name := "P", typeArgs := [], @@ -82,7 +82,7 @@ body: g := (((~Int.Add : (arrow int (arrow int int))) (a : int)) (g : int)) let g : TGenEnv Visibility := { @TGenEnv.default Visibility with context := {types := [[("g", t[int])]] }}; let ans ← typeCheck { @LContext.default ⟨Unit, Visibility⟩ with - functions := Boogie.Factory} + functions := Core.Factory} { @TEnv.default Visibility with genEnv := g} Program.init { header := { name := "P", @@ -102,4 +102,4 @@ body: g := (((~Int.Add : (arrow int (arrow int int))) (a : int)) (g : int)) --------------------------------------------------------------------- end Tests -end Boogie +end Core diff --git a/StrataTest/Languages/Boogie/ProgramTypeTests.lean b/StrataTest/Languages/Core/ProgramTypeTests.lean similarity index 98% rename from StrataTest/Languages/Boogie/ProgramTypeTests.lean rename to StrataTest/Languages/Core/ProgramTypeTests.lean index 4156d3be8..a3d558b19 100644 --- a/StrataTest/Languages/Boogie/ProgramTypeTests.lean +++ b/StrataTest/Languages/Core/ProgramTypeTests.lean @@ -4,15 +4,15 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Boogie +import Strata.Languages.Core.Core -namespace Boogie +namespace Core --------------------------------------------------------------------- section Tests open Std (ToFormat Format format) -open Lambda.LTy.Syntax Lambda.LExpr.SyntaxMono Boogie.Syntax +open Lambda.LTy.Syntax Lambda.LExpr.SyntaxMono Core.Syntax def bad_prog : Program := { decls := [ -- type Foo _ _; @@ -69,7 +69,7 @@ def good_prog : Program := { decls := [ ]} /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. VCs: @@ -82,7 +82,7 @@ Proof Obligation: (~fooAliasVal == ~fooVal) --- -info: ok: [(type Boogie.Boundedness.Infinite Foo [_, _] +info: ok: [(type Core.Boundedness.Infinite Foo [_, _] type FooAlias a := (Foo int bool) func fooAliasVal : () → (Foo int bool); func fooVal : () → (Foo int bool); @@ -371,7 +371,7 @@ def polyFuncProg : Program := { decls := [ ]} /-- -info: [Strata.Boogie] Type checking succeeded. +info: [Strata.Core] Type checking succeeded. --- info: ok: func identity : ∀[$__ty0]. ((x : $__ty0)) → $__ty0; @@ -391,4 +391,4 @@ m := (((~makePair : (arrow int (arrow bool (Map int bool)))) ((~identity : (arro --------------------------------------------------------------------- end Tests -end Boogie +end Core diff --git a/StrataTest/Languages/Boogie/SMTEncoderDatatypeTest.lean b/StrataTest/Languages/Core/SMTEncoderDatatypeTest.lean similarity index 85% rename from StrataTest/Languages/Boogie/SMTEncoderDatatypeTest.lean rename to StrataTest/Languages/Core/SMTEncoderDatatypeTest.lean index 80f3ba9cb..95fdb1c8f 100644 --- a/StrataTest/Languages/Boogie/SMTEncoderDatatypeTest.lean +++ b/StrataTest/Languages/Core/SMTEncoderDatatypeTest.lean @@ -11,18 +11,18 @@ import Strata.DL.Lambda.LTy import Strata.DL.Lambda.TypeFactory import Strata.DL.SMT.Term import Strata.DL.SMT.Encoder -import Strata.Languages.Boogie.Env -import Strata.Languages.Boogie.Factory -import Strata.Languages.Boogie.Identifiers -import Strata.Languages.Boogie.Options -import Strata.Languages.Boogie.SMTEncoder -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Env +import Strata.Languages.Core.Factory +import Strata.Languages.Core.Identifiers +import Strata.Languages.Core.Options +import Strata.Languages.Core.SMTEncoder +import Strata.Languages.Core.Verifier /-! This file contains unit tests for SMT datatype encoding. -/ -namespace Boogie +namespace Core section DatatypeTests @@ -70,7 +70,7 @@ def treeDatatype : LDatatype Visibility := /-- Convert an expression to full SMT string including datatype declarations. -/ -def toSMTStringWithDatatypes (e : LExpr BoogieLParams.mono) (datatypes : List (LDatatype Visibility)) : IO String := do +def toSMTStringWithDatatypes (e : LExpr CoreLParams.mono) (datatypes : List (LDatatype Visibility)) : IO String := do match Env.init.addDatatypes datatypes with | .error msg => return s!"Error creating environment: {msg}" | .ok env => @@ -108,7 +108,7 @@ info: (declare-datatype TestOption (par (α) ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.fvar () (BoogieIdent.unres "x") (.some (.tcons "TestOption" [.int]))) + (.fvar () (CoreIdent.unres "x") (.some (.tcons "TestOption" [.int]))) [optionDatatype] -- Test 2: Recursive datatype (List) - using List type @@ -122,7 +122,7 @@ info: (declare-datatype TestList (par (α) ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.fvar () (BoogieIdent.unres "xs") (.some (.tcons "TestList" [.int]))) + (.fvar () (CoreIdent.unres "xs") (.some (.tcons "TestList" [.int]))) [listDatatype] -- Test 3: Multiple constructors - Tree with Leaf and Node @@ -136,7 +136,7 @@ info: (declare-datatype TestTree (par (α) ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.fvar () (BoogieIdent.unres "tree") (.some (.tcons "TestTree" [.bool]))) + (.fvar () (CoreIdent.unres "tree") (.some (.tcons "TestTree" [.bool]))) [treeDatatype] -- Test 4: Parametric datatype instantiation - List Int @@ -150,7 +150,7 @@ info: (declare-datatype TestList (par (α) ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.fvar () (BoogieIdent.unres "intList") (.some (.tcons "TestList" [.int]))) + (.fvar () (CoreIdent.unres "intList") (.some (.tcons "TestList" [.int]))) [listDatatype] -- Test 5: Parametric datatype instantiation - List Bool (should reuse same datatype) @@ -164,7 +164,7 @@ info: (declare-datatype TestList (par (α) ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.fvar () (BoogieIdent.unres "boolList") (.some (.tcons "TestList" [.bool]))) + (.fvar () (CoreIdent.unres "boolList") (.some (.tcons "TestList" [.bool]))) [listDatatype] -- Test 6: Multi-field constructor - Tree with 3 fields @@ -178,7 +178,7 @@ info: (declare-datatype TestTree (par (α) ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.fvar () (BoogieIdent.unres "intTree") (.some (.tcons "TestTree" [.int]))) + (.fvar () (CoreIdent.unres "intTree") (.some (.tcons "TestTree" [.int]))) [treeDatatype] -- Test 7: Nested parametric types - List of Option (should declare both datatypes) @@ -195,7 +195,7 @@ info: (declare-datatype TestOption (par (α) ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.fvar () (BoogieIdent.unres "listOfOption") (.some (.tcons "TestList" [.tcons "TestOption" [.int]]))) + (.fvar () (CoreIdent.unres "listOfOption") (.some (.tcons "TestList" [.tcons "TestOption" [.int]]))) [listDatatype, optionDatatype] /-! ## Constructor Application Tests -/ @@ -209,7 +209,7 @@ info: (declare-datatype TestOption (par (α) ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.op () (BoogieIdent.unres "None") (.some (.tcons "TestOption" [.int]))) + (.op () (CoreIdent.unres "None") (.some (.tcons "TestOption" [.int]))) [optionDatatype] -- Test 9: Some constructor (single-argument) @@ -221,7 +221,7 @@ info: (declare-datatype TestOption (par (α) ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.app () (.op () (BoogieIdent.unres "Some") (.some (.arrow .int (.tcons "TestOption" [.int])))) (.intConst () 42)) + (.app () (.op () (CoreIdent.unres "Some") (.some (.arrow .int (.tcons "TestOption" [.int])))) (.intConst () 42)) [optionDatatype] -- Test 10: Cons constructor (multi-argument) @@ -235,9 +235,9 @@ info: (declare-datatype TestList (par (α) ( #guard_msgs in #eval format <$> toSMTStringWithDatatypes (.app () - (.app () (.op () (BoogieIdent.unres "Cons") (.some (.arrow .int (.arrow (.tcons "TestList" [.int]) (.tcons "TestList" [.int]))))) + (.app () (.op () (CoreIdent.unres "Cons") (.some (.arrow .int (.arrow (.tcons "TestList" [.int]) (.tcons "TestList" [.int]))))) (.intConst () 1)) - (.op () (BoogieIdent.unres "Nil") (.some (.tcons "TestList" [.int])))) + (.op () (CoreIdent.unres "Nil") (.some (.tcons "TestList" [.int])))) [listDatatype] /-! ## Tester Function Tests -/ @@ -254,8 +254,8 @@ info: (declare-datatype TestOption (par (α) ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.app () (.op () (BoogieIdent.unres "TestOption$isNone") (.some (.arrow (.tcons "TestOption" [.int]) .bool))) - (.fvar () (BoogieIdent.unres "x") (.some (.tcons "TestOption" [.int])))) + (.app () (.op () (CoreIdent.unres "TestOption$isNone") (.some (.arrow (.tcons "TestOption" [.int]) .bool))) + (.fvar () (CoreIdent.unres "x") (.some (.tcons "TestOption" [.int])))) [optionDatatype] -- Test 12: isCons tester @@ -270,8 +270,8 @@ info: (declare-datatype TestList (par (α) ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.app () (.op () (BoogieIdent.unres "TestList$isCons") (.some (.arrow (.tcons "TestList" [.int]) .bool))) - (.fvar () (BoogieIdent.unres "xs") (.some (.tcons "TestList" [.int])))) + (.app () (.op () (CoreIdent.unres "TestList$isCons") (.some (.arrow (.tcons "TestList" [.int]) .bool))) + (.fvar () (CoreIdent.unres "xs") (.some (.tcons "TestList" [.int])))) [listDatatype] /-! ## Destructor Function Tests -/ @@ -288,8 +288,8 @@ info: (declare-datatype TestOption (par (α) ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.app () (.op () (BoogieIdent.unres "TestOption$SomeProj0") (.some (.arrow (.tcons "TestOption" [.int]) .int))) - (.fvar () (BoogieIdent.unres "x") (.some (.tcons "TestOption" [.int])))) + (.app () (.op () (CoreIdent.unres "TestOption$SomeProj0") (.some (.arrow (.tcons "TestOption" [.int]) .int))) + (.fvar () (CoreIdent.unres "x") (.some (.tcons "TestOption" [.int])))) [optionDatatype] -- Test 14: Cons head destructor @@ -304,8 +304,8 @@ info: (declare-datatype TestList (par (α) ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.app () (.op () (BoogieIdent.unres "TestList$ConsProj0") (.some (.arrow (.tcons "TestList" [.int]) .int))) - (.fvar () (BoogieIdent.unres "xs") (.some (.tcons "TestList" [.int])))) + (.app () (.op () (CoreIdent.unres "TestList$ConsProj0") (.some (.arrow (.tcons "TestList" [.int]) .int))) + (.fvar () (CoreIdent.unres "xs") (.some (.tcons "TestList" [.int])))) [listDatatype] -- Test 15: Cons tail destructor @@ -320,8 +320,8 @@ info: (declare-datatype TestList (par (α) ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.app () (.op () (BoogieIdent.unres "TestList$ConsProj1") (.some (.arrow (.tcons "TestList" [.int]) (.tcons "TestList" [.int])))) - (.fvar () (BoogieIdent.unres "xs") (.some (.tcons "TestList" [.int])))) + (.app () (.op () (CoreIdent.unres "TestList$ConsProj1") (.some (.arrow (.tcons "TestList" [.int]) (.tcons "TestList" [.int])))) + (.fvar () (CoreIdent.unres "xs") (.some (.tcons "TestList" [.int])))) [listDatatype] /-! ## Complex Dependency Topological Sorting Tests -/ @@ -416,7 +416,7 @@ info: (declare-datatype Zeta ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.fvar () (BoogieIdent.unres "alphaVar") (.some (.tcons "Alpha" []))) + (.fvar () (CoreIdent.unres "alphaVar") (.some (.tcons "Alpha" []))) [alphaDatatype, betaDatatype, gammaDatatype, deltaDatatype, epsilonDatatype, zetaDatatype] -- Test 17: Diamond dependency pattern @@ -479,9 +479,9 @@ info: (declare-datatype Root ( -/ #guard_msgs in #eval format <$> toSMTStringWithDatatypes - (.fvar () (BoogieIdent.unres "diamondVar") (.some (.tcons "Diamond" []))) + (.fvar () (CoreIdent.unres "diamondVar") (.some (.tcons "Diamond" []))) [diamondDatatype, leftDatatype, rightDatatype, rootDatatype] end DatatypeTests -end Boogie +end Core diff --git a/StrataTest/Languages/Boogie/StatementEvalTests.lean b/StrataTest/Languages/Core/StatementEvalTests.lean similarity index 98% rename from StrataTest/Languages/Boogie/StatementEvalTests.lean rename to StrataTest/Languages/Core/StatementEvalTests.lean index 29c6bead4..8281bec1c 100644 --- a/StrataTest/Languages/Boogie/StatementEvalTests.lean +++ b/StrataTest/Languages/Core/StatementEvalTests.lean @@ -4,15 +4,15 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.StatementEval +import Strata.Languages.Core.StatementEval -namespace Boogie +namespace Core --------------------------------------------------------------------- section Tests open Std (ToFormat Format format) -open Statement Lambda Lambda.LTy.Syntax Lambda.LExpr.SyntaxMono Boogie.Syntax +open Statement Lambda Lambda.LTy.Syntax Lambda.LExpr.SyntaxMono Core.Syntax /-- info: Error: @@ -379,4 +379,4 @@ Proof Obligation: end Tests --------------------------------------------------------------------- -end Boogie +end Core diff --git a/StrataTest/Languages/Boogie/StatementTypeTests.lean b/StrataTest/Languages/Core/StatementTypeTests.lean similarity index 98% rename from StrataTest/Languages/Boogie/StatementTypeTests.lean rename to StrataTest/Languages/Core/StatementTypeTests.lean index 88f441d27..bc41e1cc6 100644 --- a/StrataTest/Languages/Boogie/StatementTypeTests.lean +++ b/StrataTest/Languages/Core/StatementTypeTests.lean @@ -4,16 +4,16 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.StatementType +import Strata.Languages.Core.StatementType -namespace Boogie +namespace Core --------------------------------------------------------------------- section Tests open Std (ToFormat Format format) -open Statement Lambda Lambda.LTy.Syntax Lambda.LExpr.SyntaxMono Boogie.Syntax +open Statement Lambda Lambda.LTy.Syntax Lambda.LExpr.SyntaxMono Core.Syntax /-- info: ok: init (x : int) := (xinit : int) @@ -153,4 +153,4 @@ end Tests --------------------------------------------------------------------- -end Boogie +end Core diff --git a/StrataTest/Languages/Laurel/TestExamples.lean b/StrataTest/Languages/Laurel/TestExamples.lean index 473eacb03..d333b6a9f 100644 --- a/StrataTest/Languages/Laurel/TestExamples.lean +++ b/StrataTest/Languages/Laurel/TestExamples.lean @@ -10,7 +10,7 @@ import Strata.DDM.BuiltinDialects.Init import Strata.Util.IO import Strata.Languages.Laurel.Grammar.LaurelGrammar import Strata.Languages.Laurel.Grammar.ConcreteToAbstractTreeTranslator -import Strata.Languages.Laurel.LaurelToBoogieTranslator +import Strata.Languages.Laurel.LaurelToCoreTranslator open StrataTest.Util open Strata diff --git a/StrataTest/Transform/CallElim.lean b/StrataTest/Transform/CallElim.lean index 8fe5d5cdb..06b88a3eb 100644 --- a/StrataTest/Transform/CallElim.lean +++ b/StrataTest/Transform/CallElim.lean @@ -6,17 +6,17 @@ import Strata.DDM.Integration.Lean import Strata.DDM.Util.Format -import Strata.Languages.Boogie.Boogie -import Strata.Languages.Boogie.DDMTransform.Translate -import Strata.Languages.Boogie.ProgramType -import Strata.Languages.Boogie.ProgramWF -import Strata.Languages.Boogie.StatementSemantics -import Strata.Transform.BoogieTransform +import Strata.Languages.Core.Core +import Strata.Languages.Core.DDMTransform.Translate +import Strata.Languages.Core.ProgramType +import Strata.Languages.Core.ProgramWF +import Strata.Languages.Core.StatementSemantics +import Strata.Transform.CoreTransform import Strata.Transform.CallElim -open Boogie -open Boogie.Transform +open Core +open Core.Transform open CallElim open Strata @@ -25,7 +25,7 @@ section CallElimExamples def CallElimTest1 := #strata -program Boogie; +program Core; var i : bool; var j : bool; var k : bool; @@ -46,7 +46,7 @@ procedure h() returns () spec { def CallElimTest1Ans := #strata -program Boogie; +program Core; var i : bool; var j : bool; var k : bool; @@ -73,7 +73,7 @@ procedure h() returns () spec { def CallElimTest2 := #strata -program Boogie; +program Core; var i : bool; var j : bool; var k : bool; @@ -95,7 +95,7 @@ procedure h() returns () spec { def CallElimTest2Ans := #strata -program Boogie; +program Core; var i : bool; var j : bool; var k : bool; @@ -126,7 +126,7 @@ procedure h() returns () spec { def CallElimTest3 := #strata -program Boogie; +program Core; var i : bool; var j : bool; var k : bool; @@ -148,7 +148,7 @@ procedure h() returns () spec { def CallElimTest3Ans := #strata -program Boogie; +program Core; var i : bool; var j : bool; var k : bool; @@ -177,9 +177,9 @@ procedure h() returns () spec { }; #end -def translate (t : Strata.Program) : Boogie.Program := (TransM.run Inhabited.default (translateProgram t)).fst +def translate (t : Strata.Program) : Core.Program := (TransM.run Inhabited.default (translateProgram t)).fst -def env := (Lambda.LContext.default.addFactoryFunctions Boogie.Factory) +def env := (Lambda.LContext.default.addFactoryFunctions Core.Factory) def translateWF (t : Strata.Program) : WF.WFProgram := let p := translate t @@ -187,14 +187,14 @@ def translateWF (t : Strata.Program) : WF.WFProgram := | .error e => panic! "Well, " ++ Std.format e |> toString | .ok res => { self := p, prop := by exact WF.Program.typeCheckWF H } -def tests : List (Boogie.Program × Boogie.Program) := [ +def tests : List (Core.Program × Core.Program) := [ (CallElimTest1, CallElimTest1Ans), (CallElimTest2, CallElimTest2Ans), (CallElimTest3, CallElimTest3Ans), ].map (Prod.map translate translate) -def callElim (p : Boogie.Program) - : Boogie.Program := +def callElim (p : Core.Program) + : Core.Program := match (run p callElim') with | .ok res => res | .error e => panic! e diff --git a/StrataTest/Transform/DetToNondet.lean b/StrataTest/Transform/DetToNondet.lean index 4c95af7fb..321067ab1 100644 --- a/StrataTest/Transform/DetToNondet.lean +++ b/StrataTest/Transform/DetToNondet.lean @@ -5,12 +5,12 @@ -/ import Strata.Transform.DetToNondet -import Strata.Languages.Boogie.StatementSemantics -import Strata.Languages.Boogie.ProgramType -import Strata.Languages.Boogie.ProgramWF +import Strata.Languages.Core.StatementSemantics +import Strata.Languages.Core.ProgramType +import Strata.Languages.Core.ProgramWF import Strata.DL.Lambda.IntBoolFactory -open Boogie +open Core /-! ## Deterministic-to-Nondeterministic Examples -/ section NondetExamples @@ -18,12 +18,12 @@ section NondetExamples open Imperative def NondetTest1 : Stmt Expression (Cmd Expression) := - .ite (Boogie.true) [.cmd $ .havoc "x" ] [.cmd $ .havoc "y" ] + .ite (Core.true) [.cmd $ .havoc "x" ] [.cmd $ .havoc "y" ] def NondetTest1Ans : NondetStmt Expression (Cmd Expression) := .choice - (.seq (.cmd (.assume "true_cond" Boogie.true)) (.seq (.cmd $ .havoc "x") (.assume "skip" Imperative.HasBool.tt))) - (.seq (.cmd (.assume "false_cond" Boogie.false)) (.seq (.cmd $ .havoc "y") (.assume "skip" Imperative.HasBool.tt))) + (.seq (.cmd (.assume "true_cond" Core.true)) (.seq (.cmd $ .havoc "x") (.assume "skip" Imperative.HasBool.tt))) + (.seq (.cmd (.assume "false_cond" Core.false)) (.seq (.cmd $ .havoc "y") (.assume "skip" Imperative.HasBool.tt))) -- #eval toString $ Std.format (StmtToNondetStmt NondetTest1) diff --git a/StrataTest/Transform/ProcedureInlining.lean b/StrataTest/Transform/ProcedureInlining.lean index 85d332902..91d859de3 100644 --- a/StrataTest/Transform/ProcedureInlining.lean +++ b/StrataTest/Transform/ProcedureInlining.lean @@ -6,16 +6,16 @@ import Strata.DDM.Integration.Lean import Strata.DDM.Util.Format -import Strata.Languages.Boogie.Boogie -import Strata.Languages.Boogie.DDMTransform.Translate -import Strata.Languages.Boogie.StatementSemantics -import Strata.Languages.Boogie.ProgramType -import Strata.Languages.Boogie.ProgramWF -import Strata.Transform.BoogieTransform +import Strata.Languages.Core.Core +import Strata.Languages.Core.DDMTransform.Translate +import Strata.Languages.Core.StatementSemantics +import Strata.Languages.Core.ProgramType +import Strata.Languages.Core.ProgramWF +import Strata.Transform.CoreTransform import Strata.Transform.ProcedureInlining -open Boogie -open Boogie.Transform +open Core +open Core.Transform open ProcedureInlining open Strata open Std @@ -64,7 +64,7 @@ private def substExpr (e1:Expression.Expr) (map:Map String String) (isReverse: B map.foldl (fun (e:Expression.Expr) ((i1,i2):String × String) => -- old_id has visibility of temp because the new local variables were - -- created by BoogieGenM. + -- created by CoreGenM. -- new_expr has visibility of unres because that is the default setting -- from DDM parsed program, and the substituted program is supposed to be -- equivalent to the answer program translated from DDM @@ -107,7 +107,7 @@ private def alphaEquivIdents (e1 e2: Expression.Ident) (map:IdMap) mutual -def alphaEquivBlock (b1 b2: Boogie.Block) (map:IdMap) +def alphaEquivBlock (b1 b2: Core.Block) (map:IdMap) : Except Format IdMap := do if b1.length ≠ b2.length then .error "Block lengths do not match" @@ -120,7 +120,7 @@ def alphaEquivBlock (b1 b2: Boogie.Block) (map:IdMap) termination_by b1.sizeOf decreasing_by cases st1; apply Imperative.sizeOf_stmt_in_block; assumption -def alphaEquivStatement (s1 s2: Boogie.Statement) (map:IdMap) +def alphaEquivStatement (s1 s2: Core.Statement) (map:IdMap) : Except Format IdMap := do let mk_err (s:Format): Except Format IdMap := .error (f!"{s}\ns1:{s1}\ns2:{s2}\nmap:{map.vars}") @@ -207,7 +207,7 @@ def alphaEquivStatement (s1 s2: Boogie.Statement) (map:IdMap) end -private def alphaEquiv (p1 p2:Boogie.Procedure):Except Format Bool := do +private def alphaEquiv (p1 p2:Core.Procedure):Except Format Bool := do if p1.body.length ≠ p2.body.length then .error (s!"# statements do not match: in {p1.header.name}, " ++ s!"inlined fn one has {p1.body.length}" @@ -223,15 +223,15 @@ private def alphaEquiv (p1 p2:Boogie.Procedure):Except Format Bool := do -def translate (t : Strata.Program) : Boogie.Program := +def translate (t : Strata.Program) : Core.Program := (TransM.run Inhabited.default (translateProgram t)).fst -def runInlineCall (p : Boogie.Program) : Boogie.Program := +def runInlineCall (p : Core.Program) : Core.Program := match (runProgram inlineCallCmd p .emp) with | ⟨.ok res, _⟩ => res | ⟨.error e, _⟩ => panic! e -def checkInlining (prog : Boogie.Program) (progAns : Boogie.Program) +def checkInlining (prog : Core.Program) (progAns : Core.Program) : Except Format Bool := do let prog' := runInlineCall prog let pp' := prog'.decls.zip progAns.decls @@ -252,7 +252,7 @@ def checkInlining (prog : Boogie.Program) (progAns : Boogie.Program) def Test1 := #strata -program Boogie; +program Core; procedure f(x : bool) returns (y : bool) { y := !x; }; @@ -266,7 +266,7 @@ procedure h() returns () { def Test1Ans := #strata -program Boogie; +program Core; procedure f(x : bool) returns (y : bool) { y := !x; }; @@ -291,7 +291,7 @@ procedure h() returns () { def Test2 := #strata -program Boogie; +program Core; procedure f(x : bool) returns (y : bool) { if (x) { goto end; @@ -310,7 +310,7 @@ procedure h() returns () { def Test2Ans := #strata -program Boogie; +program Core; procedure f(x : bool) returns (y : bool) { if (x) { goto end; @@ -348,7 +348,7 @@ procedure h() returns () { def Test3 := #strata -program Boogie; +program Core; procedure f(x : int) returns (y : int) { y := x; }; @@ -365,7 +365,7 @@ procedure g() returns () { def Test3Ans := #strata -program Boogie; +program Core; procedure f(x : int) returns (y : int) { y := x; }; diff --git a/StrataTest/Util/TestDiagnostics.lean b/StrataTest/Util/TestDiagnostics.lean index 312cfe54a..f2cb684c1 100644 --- a/StrataTest/Util/TestDiagnostics.lean +++ b/StrataTest/Util/TestDiagnostics.lean @@ -4,7 +4,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT -/ -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier import Lean.Elab.Command open Strata diff --git a/StrataToCBMC.lean b/StrataToCBMC.lean index d1abed99f..4d97039a8 100644 --- a/StrataToCBMC.lean +++ b/StrataToCBMC.lean @@ -6,8 +6,8 @@ import Lean.Data.Json import Strata.Backends.CBMC.StrataToCBMC -import Strata.Backends.CBMC.BoogieToCBMC -import Strata.Languages.Boogie.Verifier +import Strata.Backends.CBMC.CoreToCBMC +import Strata.Languages.Core.Verifier import Strata.Languages.C_Simp.Verify import Strata.Util.IO import Std.Internal.Parsec @@ -22,7 +22,7 @@ def main (args : List String) : IO Unit := do let text ← Strata.Util.readInputSource file let inputCtx := Lean.Parser.mkInputContext text (Strata.Util.displayName file) let dctx := Elab.LoadedDialects.builtin - let dctx := dctx.addDialect! Boogie + let dctx := dctx.addDialect! Core let dctx := dctx.addDialect! C_Simp let leanEnv ← Lean.mkEmptyEnvironment 0 match Strata.Elab.elabProgram dctx leanEnv inputCtx with @@ -33,11 +33,11 @@ def main (args : List String) : IO Unit := do if file.endsWith ".csimp.st" then let csimp_prog := C_Simp.get_program pgm IO.println (CSimp.testSymbols csimp_prog.funcs.head!) - else if file.endsWith ".boogie.st" then - let boogie_prog := (Boogie.getProgram pgm inputCtx).fst - match boogie_prog.decls.head! with - | .proc f => IO.println (Boogie.testSymbols f) - | _ => IO.println "Error: expected boogie procedure" + else if file.endsWith ".core.st" then + let core_prog := (Core.getProgram pgm inputCtx).fst + match core_prog.decls.head! with + | .proc f => IO.println (Core.testSymbols f) + | _ => IO.println "Error: expected Strata Core procedure" else IO.println "Error: Unrecognized file extension" | .error errors => diff --git a/StrataVerify.lean b/StrataVerify.lean index eec37005e..440eabce0 100644 --- a/StrataVerify.lean +++ b/StrataVerify.lean @@ -5,7 +5,7 @@ -/ -- Executable for verifying a Strata program from a file. -import Strata.Languages.Boogie.Verifier +import Strata.Languages.Core.Verifier import Strata.Languages.C_Simp.Verify import Strata.Util.IO import Std.Internal.Parsec @@ -31,7 +31,7 @@ def parseOptions (args : List String) : Except Std.Format (Options × String) := | _, args => .error f!"Unknown options: {args}" def usageMessage : Std.Format := - f!"Usage: StrataVerify [OPTIONS] {Std.Format.line}\ + f!"Usage: StrataVerify [OPTIONS] {Std.Format.line}\ {Std.Format.line}\ Options:{Std.Format.line}\ {Std.Format.line} \ @@ -49,7 +49,7 @@ def main (args : List String) : IO UInt32 := do let text ← Strata.Util.readInputSource file let inputCtx := Lean.Parser.mkInputContext text (Strata.Util.displayName file) let dctx := Elab.LoadedDialects.builtin - let dctx := dctx.addDialect! Boogie + let dctx := dctx.addDialect! Core let dctx := dctx.addDialect! C_Simp let leanEnv ← Lean.mkEmptyEnvironment 0 match Strata.Elab.elabProgram dctx leanEnv inputCtx with @@ -61,7 +61,7 @@ def main (args : List String) : IO UInt32 := do let ans := if file.endsWith ".csimp.st" then C_Simp.typeCheck pgm opts else - -- Boogie. + -- Strata Core. typeCheck inputCtx pgm opts match ans with | .error e => @@ -82,7 +82,7 @@ def main (args : List String) : IO UInt32 := do for vcResult in vcResults do let posStr := Imperative.MetaData.formatFileRangeD vcResult.obligation.metadata println! f!"{posStr} [{vcResult.obligation.label}]: {vcResult.result}" - let success := vcResults.all Boogie.VCResult.isSuccess + let success := vcResults.all Core.VCResult.isSuccess if success && !opts.checkOnly then println! f!"All {vcResults.size} goals passed." return 0 @@ -90,8 +90,8 @@ def main (args : List String) : IO UInt32 := do println! f!"Skipping verification." return 0 else - let provedGoalCount := (vcResults.filter Boogie.VCResult.isSuccess).size - let failedGoalCount := (vcResults.filter Boogie.VCResult.isNotSuccess).size + let provedGoalCount := (vcResults.filter Core.VCResult.isSuccess).size + let failedGoalCount := (vcResults.filter Core.VCResult.isNotSuccess).size println! f!"Finished with {provedGoalCount} goals passed, {failedGoalCount} failed." return 1 -- Strata.Elab.elabProgram diff --git a/Tools/BoogieToStrata/.gitignore b/Tools/BoogieToStrata/.gitignore index c526c45a0..f7478fd4a 100644 --- a/Tools/BoogieToStrata/.gitignore +++ b/Tools/BoogieToStrata/.gitignore @@ -4,6 +4,6 @@ bin obj vcs -Tests/*.boogie.st +Tests/*.core.st Tests/*.out Tests/*.err diff --git a/Tools/BoogieToStrata/IntegrationTests/BoogieToStrataIntegrationTests.cs b/Tools/BoogieToStrata/IntegrationTests/BoogieToStrataIntegrationTests.cs index 7629e0293..6c52e103e 100644 --- a/Tools/BoogieToStrata/IntegrationTests/BoogieToStrataIntegrationTests.cs +++ b/Tools/BoogieToStrata/IntegrationTests/BoogieToStrataIntegrationTests.cs @@ -113,7 +113,7 @@ public void VerifyTestFile(string fileName, string filePath) { Assert.Equal(0, exitCode); Assert.True(standardOutput.Length > 0, "Expected some output from BoogieToStrata"); Assert.True(errorOutput.Length == 0, "Expected no error output from BoogieToStrata"); - var strataFile = Path.ChangeExtension(filePath, "boogie.st"); + var strataFile = Path.ChangeExtension(filePath, "core.st"); File.WriteAllText(strataFile, standardOutput); var expectFile = Path.ChangeExtension(filePath, "expect"); string? expectString = null; diff --git a/Tools/BoogieToStrata/Source/StrataGenerator.cs b/Tools/BoogieToStrata/Source/StrataGenerator.cs index 795370e7b..1bd7448fe 100644 --- a/Tools/BoogieToStrata/Source/StrataGenerator.cs +++ b/Tools/BoogieToStrata/Source/StrataGenerator.cs @@ -212,7 +212,7 @@ private void EmitUniqueConstAxioms() { } private void EmitHeader() { - WriteLine("program Boogie;"); + WriteLine("program Core;"); WriteLine("type StrataHeap;"); WriteLine("type StrataRef;"); WriteLine("type StrataField (t: Type);"); diff --git a/Tools/BoogieToStrata/Tests/Arrays2.expect b/Tools/BoogieToStrata/Tests/Arrays2.expect index 88950a729..9dce9b04f 100644 --- a/Tools/BoogieToStrata/Tests/Arrays2.expect +++ b/Tools/BoogieToStrata/Tests/Arrays2.expect @@ -1,14 +1,14 @@ Successfully parsed. -Arrays2.boogie.st(22, 2) [P0_ensures_2]: ✅ pass -Arrays2.boogie.st(23, 2) [P0_ensures_3]: ✅ pass -Arrays2.boogie.st(39, 2) [P1_ensures_1]: ✅ pass -Arrays2.boogie.st(55, 2) [P2_ensures_1]: 🟡 unknown -Arrays2.boogie.st(72, 2) [Q0_ensures_2]: ✅ pass -Arrays2.boogie.st(73, 2) [Q0_ensures_3]: ✅ pass -Arrays2.boogie.st(89, 2) [Q1_ensures_1]: ✅ pass -Arrays2.boogie.st(106, 2) [Q2_ensures_2]: ✅ pass -Arrays2.boogie.st(123, 2) [Q3_ensures_2]: ✅ pass -Arrays2.boogie.st(139, 2) [Q4_ensures_1]: 🟡 unknown -Arrays2.boogie.st(156, 2) [Skip0_ensures_2]: ✅ pass -Arrays2.boogie.st(157, 2) [Skip0_ensures_3]: ✅ pass +Arrays2.core.st(22, 2) [P0_ensures_2]: ✅ pass +Arrays2.core.st(23, 2) [P0_ensures_3]: ✅ pass +Arrays2.core.st(39, 2) [P1_ensures_1]: ✅ pass +Arrays2.core.st(55, 2) [P2_ensures_1]: 🟡 unknown +Arrays2.core.st(72, 2) [Q0_ensures_2]: ✅ pass +Arrays2.core.st(73, 2) [Q0_ensures_3]: ✅ pass +Arrays2.core.st(89, 2) [Q1_ensures_1]: ✅ pass +Arrays2.core.st(106, 2) [Q2_ensures_2]: ✅ pass +Arrays2.core.st(123, 2) [Q3_ensures_2]: ✅ pass +Arrays2.core.st(139, 2) [Q4_ensures_1]: 🟡 unknown +Arrays2.core.st(156, 2) [Skip0_ensures_2]: ✅ pass +Arrays2.core.st(157, 2) [Skip0_ensures_3]: ✅ pass Finished with 10 goals passed, 2 failed. diff --git a/Tools/BoogieToStrata/Tests/Axioms.expect b/Tools/BoogieToStrata/Tests/Axioms.expect index 5d3d38c7c..fd1bf11c7 100644 --- a/Tools/BoogieToStrata/Tests/Axioms.expect +++ b/Tools/BoogieToStrata/Tests/Axioms.expect @@ -1,7 +1,7 @@ Successfully parsed. -Axioms.boogie.st(25, 4) [assert_0]: ✅ pass -Axioms.boogie.st(26, 4) [assert_1]: ✅ pass -Axioms.boogie.st(27, 4) [assert_2]: ✅ pass -Axioms.boogie.st(37, 4) [assert_3]: 🟡 unknown -Axioms.boogie.st(48, 4) [assert_4]: ✅ pass +Axioms.core.st(25, 4) [assert_0]: ✅ pass +Axioms.core.st(26, 4) [assert_1]: ✅ pass +Axioms.core.st(27, 4) [assert_2]: ✅ pass +Axioms.core.st(37, 4) [assert_3]: 🟡 unknown +Axioms.core.st(48, 4) [assert_4]: ✅ pass Finished with 4 goals passed, 1 failed. diff --git a/Tools/BoogieToStrata/Tests/B.expect b/Tools/BoogieToStrata/Tests/B.expect index 5011e0494..178125267 100644 --- a/Tools/BoogieToStrata/Tests/B.expect +++ b/Tools/BoogieToStrata/Tests/B.expect @@ -1,6 +1,6 @@ Successfully parsed. -B.boogie.st(36, 4) [assert_0]: ✅ pass -B.boogie.st(62, 4) [assert_1]: ✅ pass -B.boogie.st(88, 4) [assert_2]: ✅ pass -B.boogie.st(115, 4) [assert_3]: ✅ pass +B.core.st(36, 4) [assert_0]: ✅ pass +B.core.st(62, 4) [assert_1]: ✅ pass +B.core.st(88, 4) [assert_2]: ✅ pass +B.core.st(115, 4) [assert_3]: ✅ pass All 4 goals passed. diff --git a/Tools/BoogieToStrata/Tests/BooleanQuantification.expect b/Tools/BoogieToStrata/Tests/BooleanQuantification.expect index 57325b895..ded564550 100644 --- a/Tools/BoogieToStrata/Tests/BooleanQuantification.expect +++ b/Tools/BoogieToStrata/Tests/BooleanQuantification.expect @@ -1,9 +1,9 @@ Successfully parsed. -BooleanQuantification.boogie.st(22, 4) [assert_0]: ✅ pass -BooleanQuantification.boogie.st(31, 4) [assert_1]: ✅ pass -BooleanQuantification.boogie.st(40, 4) [assert_2]: ✅ pass -BooleanQuantification.boogie.st(41, 4) [assert_3]: 🟡 unknown -BooleanQuantification.boogie.st(50, 4) [assert_4]: ✅ pass -BooleanQuantification.boogie.st(51, 4) [assert_5]: ✅ pass -BooleanQuantification.boogie.st(52, 4) [assert_6]: ❌ fail +BooleanQuantification.core.st(22, 4) [assert_0]: ✅ pass +BooleanQuantification.core.st(31, 4) [assert_1]: ✅ pass +BooleanQuantification.core.st(40, 4) [assert_2]: ✅ pass +BooleanQuantification.core.st(41, 4) [assert_3]: 🟡 unknown +BooleanQuantification.core.st(50, 4) [assert_4]: ✅ pass +BooleanQuantification.core.st(51, 4) [assert_5]: ✅ pass +BooleanQuantification.core.st(52, 4) [assert_6]: ❌ fail Finished with 5 goals passed, 2 failed. diff --git a/Tools/BoogieToStrata/Tests/BooleanQuantification2.expect b/Tools/BoogieToStrata/Tests/BooleanQuantification2.expect index 492716be5..bebd6467a 100644 --- a/Tools/BoogieToStrata/Tests/BooleanQuantification2.expect +++ b/Tools/BoogieToStrata/Tests/BooleanQuantification2.expect @@ -1,5 +1,5 @@ Successfully parsed. -BooleanQuantification2.boogie.st(18, 4) [assert_0]: ✅ pass -BooleanQuantification2.boogie.st(19, 4) [assert_1]: ✅ pass -BooleanQuantification2.boogie.st(20, 4) [assert_2]: ❌ fail +BooleanQuantification2.core.st(18, 4) [assert_0]: ✅ pass +BooleanQuantification2.core.st(19, 4) [assert_1]: ✅ pass +BooleanQuantification2.core.st(20, 4) [assert_2]: ❌ fail Finished with 2 goals passed, 1 failed. diff --git a/Tools/BoogieToStrata/Tests/Bubble.expect b/Tools/BoogieToStrata/Tests/Bubble.expect index b4fe61f41..b587d3af1 100644 --- a/Tools/BoogieToStrata/Tests/Bubble.expect +++ b/Tools/BoogieToStrata/Tests/Bubble.expect @@ -1,16 +1,16 @@ Successfully parsed. -Bubble.boogie.st(31, 4) [entry_invariant_0]: ✅ pass -Bubble.boogie.st(31, 4) [arbitrary_iter_maintain_invariant_0]: ✅ pass -Bubble.boogie.st(43, 4) [entry_invariant_0]: ✅ pass -Bubble.boogie.st(20, 2) [BubbleSort_ensures_1]: ✅ pass -Bubble.boogie.st(21, 2) [BubbleSort_ensures_2]: ✅ pass -Bubble.boogie.st(22, 2) [BubbleSort_ensures_3]: ✅ pass -Bubble.boogie.st(23, 2) [BubbleSort_ensures_4]: ✅ pass -Bubble.boogie.st(57, 8) [entry_invariant_1]: ✅ pass -Bubble.boogie.st(57, 8) [arbitrary_iter_maintain_invariant_1]: ✅ pass -Bubble.boogie.st(43, 4) [arbitrary_iter_maintain_invariant_0]: ✅ pass -Bubble.boogie.st(20, 2) [BubbleSort_ensures_1]: ✅ pass -Bubble.boogie.st(21, 2) [BubbleSort_ensures_2]: ✅ pass -Bubble.boogie.st(22, 2) [BubbleSort_ensures_3]: ✅ pass -Bubble.boogie.st(23, 2) [BubbleSort_ensures_4]: ✅ pass +Bubble.core.st(31, 4) [entry_invariant_0]: ✅ pass +Bubble.core.st(31, 4) [arbitrary_iter_maintain_invariant_0]: ✅ pass +Bubble.core.st(43, 4) [entry_invariant_0]: ✅ pass +Bubble.core.st(20, 2) [BubbleSort_ensures_1]: ✅ pass +Bubble.core.st(21, 2) [BubbleSort_ensures_2]: ✅ pass +Bubble.core.st(22, 2) [BubbleSort_ensures_3]: ✅ pass +Bubble.core.st(23, 2) [BubbleSort_ensures_4]: ✅ pass +Bubble.core.st(57, 8) [entry_invariant_1]: ✅ pass +Bubble.core.st(57, 8) [arbitrary_iter_maintain_invariant_1]: ✅ pass +Bubble.core.st(43, 4) [arbitrary_iter_maintain_invariant_0]: ✅ pass +Bubble.core.st(20, 2) [BubbleSort_ensures_1]: ✅ pass +Bubble.core.st(21, 2) [BubbleSort_ensures_2]: ✅ pass +Bubble.core.st(22, 2) [BubbleSort_ensures_3]: ✅ pass +Bubble.core.st(23, 2) [BubbleSort_ensures_4]: ✅ pass All 14 goals passed. diff --git a/Tools/BoogieToStrata/Tests/DivMod.expect b/Tools/BoogieToStrata/Tests/DivMod.expect index 927ad90ab..8e9c51c8e 100644 --- a/Tools/BoogieToStrata/Tests/DivMod.expect +++ b/Tools/BoogieToStrata/Tests/DivMod.expect @@ -1,8 +1,8 @@ Successfully parsed. -DivMod.boogie.st(25, 2) [T_from_E_ensures_1]: ✅ pass -DivMod.boogie.st(26, 2) [T_from_E_ensures_2]: ✅ pass -DivMod.boogie.st(27, 2) [T_from_E_ensures_3]: ✅ pass -DivMod.boogie.st(45, 2) [E_from_T_ensures_1]: ✅ pass -DivMod.boogie.st(46, 2) [E_from_T_ensures_2]: ✅ pass -DivMod.boogie.st(47, 2) [E_from_T_ensures_3]: ✅ pass +DivMod.core.st(25, 2) [T_from_E_ensures_1]: ✅ pass +DivMod.core.st(26, 2) [T_from_E_ensures_2]: ✅ pass +DivMod.core.st(27, 2) [T_from_E_ensures_3]: ✅ pass +DivMod.core.st(45, 2) [E_from_T_ensures_1]: ✅ pass +DivMod.core.st(46, 2) [E_from_T_ensures_2]: ✅ pass +DivMod.core.st(47, 2) [E_from_T_ensures_3]: ✅ pass All 6 goals passed. diff --git a/Tools/BoogieToStrata/Tests/Gauss.expect b/Tools/BoogieToStrata/Tests/Gauss.expect index a7602384a..9524cb15a 100644 --- a/Tools/BoogieToStrata/Tests/Gauss.expect +++ b/Tools/BoogieToStrata/Tests/Gauss.expect @@ -1,5 +1,5 @@ Successfully parsed. -Gauss.boogie.st(18, 4) [entry_invariant_0]: ✅ pass -Gauss.boogie.st(18, 4) [arbitrary_iter_maintain_invariant_0]: ✅ pass -Gauss.boogie.st(11, 2) [sum_ensures_1]: ✅ pass +Gauss.core.st(18, 4) [entry_invariant_0]: ✅ pass +Gauss.core.st(18, 4) [arbitrary_iter_maintain_invariant_0]: ✅ pass +Gauss.core.st(11, 2) [sum_ensures_1]: ✅ pass All 3 goals passed. diff --git a/Tools/BoogieToStrata/Tests/IfThenElse1.expect b/Tools/BoogieToStrata/Tests/IfThenElse1.expect index 801f61136..cbb8e9854 100644 --- a/Tools/BoogieToStrata/Tests/IfThenElse1.expect +++ b/Tools/BoogieToStrata/Tests/IfThenElse1.expect @@ -1,8 +1,8 @@ Successfully parsed. -IfThenElse1.boogie.st(18, 4) [assert_0]: ✅ pass -IfThenElse1.boogie.st(19, 4) [assert_1]: ✅ pass -IfThenElse1.boogie.st(34, 4) [assert_2]: ✅ pass -IfThenElse1.boogie.st(36, 4) [assert_3]: ✅ pass -IfThenElse1.boogie.st(48, 4) [assert_4]: ❌ fail -IfThenElse1.boogie.st(60, 4) [assert_5]: ❌ fail +IfThenElse1.core.st(18, 4) [assert_0]: ✅ pass +IfThenElse1.core.st(19, 4) [assert_1]: ✅ pass +IfThenElse1.core.st(34, 4) [assert_2]: ✅ pass +IfThenElse1.core.st(36, 4) [assert_3]: ✅ pass +IfThenElse1.core.st(48, 4) [assert_4]: ❌ fail +IfThenElse1.core.st(60, 4) [assert_5]: ❌ fail Finished with 4 goals passed, 2 failed. diff --git a/Tools/BoogieToStrata/Tests/Implies.expect b/Tools/BoogieToStrata/Tests/Implies.expect index a79cf3bca..4f4109232 100644 --- a/Tools/BoogieToStrata/Tests/Implies.expect +++ b/Tools/BoogieToStrata/Tests/Implies.expect @@ -1,14 +1,14 @@ Successfully parsed. -Implies.boogie.st(24, 4) [assert_0]: ✅ pass -Implies.boogie.st(25, 4) [assert_1]: 🟡 unknown -Implies.boogie.st(26, 4) [assert_2]: ✅ pass -Implies.boogie.st(27, 4) [assert_3]: 🟡 unknown -Implies.boogie.st(36, 4) [assert_4]: 🟡 unknown -Implies.boogie.st(37, 4) [assert_5]: 🟡 unknown -Implies.boogie.st(46, 4) [assert_6]: 🟡 unknown -Implies.boogie.st(47, 4) [assert_7]: 🟡 unknown -Implies.boogie.st(56, 4) [assert_8]: 🟡 unknown -Implies.boogie.st(57, 4) [assert_9]: 🟡 unknown -Implies.boogie.st(66, 4) [assert_10]: 🟡 unknown -Implies.boogie.st(67, 4) [assert_11]: 🟡 unknown +Implies.core.st(24, 4) [assert_0]: ✅ pass +Implies.core.st(25, 4) [assert_1]: 🟡 unknown +Implies.core.st(26, 4) [assert_2]: ✅ pass +Implies.core.st(27, 4) [assert_3]: 🟡 unknown +Implies.core.st(36, 4) [assert_4]: 🟡 unknown +Implies.core.st(37, 4) [assert_5]: 🟡 unknown +Implies.core.st(46, 4) [assert_6]: 🟡 unknown +Implies.core.st(47, 4) [assert_7]: 🟡 unknown +Implies.core.st(56, 4) [assert_8]: 🟡 unknown +Implies.core.st(57, 4) [assert_9]: 🟡 unknown +Implies.core.st(66, 4) [assert_10]: 🟡 unknown +Implies.core.st(67, 4) [assert_11]: 🟡 unknown Finished with 2 goals passed, 10 failed. diff --git a/Tools/BoogieToStrata/Tests/Lambda.expect b/Tools/BoogieToStrata/Tests/Lambda.expect index 94a7c31b8..21b6b17cc 100644 --- a/Tools/BoogieToStrata/Tests/Lambda.expect +++ b/Tools/BoogieToStrata/Tests/Lambda.expect @@ -1,14 +1,14 @@ Successfully parsed. -Lambda.boogie.st(39, 2) [P_ensures_0]: ✅ pass -Lambda.boogie.st(52, 4) [assert_0]: ✅ pass -Lambda.boogie.st(61, 4) [assert_1]: ✅ pass -Lambda.boogie.st(74, 4) [assert_2]: ✅ pass -Lambda.boogie.st(75, 4) [assert_3]: ✅ pass -Lambda.boogie.st(76, 4) [assert_4]: ✅ pass -Lambda.boogie.st(89, 4) [assert_5]: 🟡 unknown -Lambda.boogie.st(90, 4) [assert_6]: 🟡 unknown -Lambda.boogie.st(103, 4) [assert_7]: ✅ pass -Lambda.boogie.st(104, 4) [assert_8]: ✅ pass -Lambda.boogie.st(106, 4) [assert_9]: ✅ pass -Lambda.boogie.st(107, 4) [assert_10]: ✅ pass +Lambda.core.st(39, 2) [P_ensures_0]: ✅ pass +Lambda.core.st(52, 4) [assert_0]: ✅ pass +Lambda.core.st(61, 4) [assert_1]: ✅ pass +Lambda.core.st(74, 4) [assert_2]: ✅ pass +Lambda.core.st(75, 4) [assert_3]: ✅ pass +Lambda.core.st(76, 4) [assert_4]: ✅ pass +Lambda.core.st(89, 4) [assert_5]: 🟡 unknown +Lambda.core.st(90, 4) [assert_6]: 🟡 unknown +Lambda.core.st(103, 4) [assert_7]: ✅ pass +Lambda.core.st(104, 4) [assert_8]: ✅ pass +Lambda.core.st(106, 4) [assert_9]: ✅ pass +Lambda.core.st(107, 4) [assert_10]: ✅ pass Finished with 10 goals passed, 2 failed. diff --git a/Tools/BoogieToStrata/Tests/McCarthy-91.expect b/Tools/BoogieToStrata/Tests/McCarthy-91.expect index 43c653c88..ad0e41e0c 100644 --- a/Tools/BoogieToStrata/Tests/McCarthy-91.expect +++ b/Tools/BoogieToStrata/Tests/McCarthy-91.expect @@ -1,4 +1,4 @@ Successfully parsed. -McCarthy-91.boogie.st(10, 2) [F_ensures_0]: ✅ pass -McCarthy-91.boogie.st(11, 2) [F_ensures_1]: ✅ pass +McCarthy-91.core.st(10, 2) [F_ensures_0]: ✅ pass +McCarthy-91.core.st(11, 2) [F_ensures_1]: ✅ pass All 2 goals passed. diff --git a/Tools/BoogieToStrata/Tests/Quantifiers.expect b/Tools/BoogieToStrata/Tests/Quantifiers.expect index 378050fa9..b7bca55e6 100644 --- a/Tools/BoogieToStrata/Tests/Quantifiers.expect +++ b/Tools/BoogieToStrata/Tests/Quantifiers.expect @@ -1,16 +1,16 @@ Successfully parsed. -Quantifiers.boogie.st(39, 4) [assert_0]: ✅ pass -Quantifiers.boogie.st(51, 4) [assert_1]: 🟡 unknown -Quantifiers.boogie.st(64, 4) [assert_2]: ✅ pass -Quantifiers.boogie.st(76, 4) [assert_3]: 🟡 unknown -Quantifiers.boogie.st(89, 4) [assert_4]: ✅ pass -Quantifiers.boogie.st(99, 4) [assert_5]: 🟡 unknown -Quantifiers.boogie.st(110, 4) [assert_6]: 🟡 unknown -Quantifiers.boogie.st(123, 4) [assert_7]: ✅ pass -Quantifiers.boogie.st(134, 4) [assert_8]: ✅ pass -Quantifiers.boogie.st(146, 4) [assert_9]: ✅ pass -Quantifiers.boogie.st(158, 4) [assert_10]: ✅ pass -Quantifiers.boogie.st(170, 4) [assert_11]: ✅ pass -Quantifiers.boogie.st(183, 4) [assert_12]: ✅ pass -Quantifiers.boogie.st(195, 4) [assert_13]: ✅ pass +Quantifiers.core.st(39, 4) [assert_0]: ✅ pass +Quantifiers.core.st(51, 4) [assert_1]: 🟡 unknown +Quantifiers.core.st(64, 4) [assert_2]: ✅ pass +Quantifiers.core.st(76, 4) [assert_3]: 🟡 unknown +Quantifiers.core.st(89, 4) [assert_4]: ✅ pass +Quantifiers.core.st(99, 4) [assert_5]: 🟡 unknown +Quantifiers.core.st(110, 4) [assert_6]: 🟡 unknown +Quantifiers.core.st(123, 4) [assert_7]: ✅ pass +Quantifiers.core.st(134, 4) [assert_8]: ✅ pass +Quantifiers.core.st(146, 4) [assert_9]: ✅ pass +Quantifiers.core.st(158, 4) [assert_10]: ✅ pass +Quantifiers.core.st(170, 4) [assert_11]: ✅ pass +Quantifiers.core.st(183, 4) [assert_12]: ✅ pass +Quantifiers.core.st(195, 4) [assert_13]: ✅ pass Finished with 10 goals passed, 4 failed. diff --git a/Tools/BoogieToStrata/Tests/TypeSynonyms2.expect b/Tools/BoogieToStrata/Tests/TypeSynonyms2.expect index d8a27a7e2..266a886bf 100644 --- a/Tools/BoogieToStrata/Tests/TypeSynonyms2.expect +++ b/Tools/BoogieToStrata/Tests/TypeSynonyms2.expect @@ -1,3 +1,3 @@ Successfully parsed. -TypeSynonyms2.boogie.st(27, 4) [assert_0]: ✅ pass +TypeSynonyms2.core.st(27, 4) [assert_0]: ✅ pass All 1 goals passed. diff --git a/Tools/BoogieToStrata/Tests/Unique.expect b/Tools/BoogieToStrata/Tests/Unique.expect index e130ab367..439745846 100644 --- a/Tools/BoogieToStrata/Tests/Unique.expect +++ b/Tools/BoogieToStrata/Tests/Unique.expect @@ -1,6 +1,6 @@ Successfully parsed. -Unique.boogie.st(28, 4) [assert_0]: ❌ fail -Unique.boogie.st(29, 4) [assert_1]: ✅ pass -Unique.boogie.st(38, 4) [assert_2]: ❌ fail -Unique.boogie.st(39, 4) [assert_3]: ✅ pass +Unique.core.st(28, 4) [assert_0]: ❌ fail +Unique.core.st(29, 4) [assert_1]: ✅ pass +Unique.core.st(38, 4) [assert_2]: ❌ fail +Unique.core.st(39, 4) [assert_3]: ✅ pass Finished with 2 goals passed, 2 failed. diff --git a/Tools/BoogieToStrata/Tests/Where.expect b/Tools/BoogieToStrata/Tests/Where.expect index ec3df71b9..f83b927b8 100644 --- a/Tools/BoogieToStrata/Tests/Where.expect +++ b/Tools/BoogieToStrata/Tests/Where.expect @@ -1,14 +1,14 @@ Successfully parsed. -Where.boogie.st(16, 4) [assert_0]: ✅ pass -Where.boogie.st(17, 4) [assert_1]: ✅ pass -Where.boogie.st(18, 4) [assert_2]: ❌ fail -Where.boogie.st(34, 4) [assert_3]: ✅ pass -Where.boogie.st(37, 4) [assert_4]: ✅ pass -Where.boogie.st(38, 4) [assert_5]: ❌ fail -Where.boogie.st(55, 4) [assert_6]: ❌ fail -Where.boogie.st(73, 4) [assert_7]: ✅ pass -Where.boogie.st(74, 4) [assert_8]: ❌ fail -Where.boogie.st(91, 4) [assert_9]: ✅ pass -Where.boogie.st(96, 4) [assert_10]: ✅ pass -Where.boogie.st(97, 4) [assert_11]: ❌ fail +Where.core.st(16, 4) [assert_0]: ✅ pass +Where.core.st(17, 4) [assert_1]: ✅ pass +Where.core.st(18, 4) [assert_2]: ❌ fail +Where.core.st(34, 4) [assert_3]: ✅ pass +Where.core.st(37, 4) [assert_4]: ✅ pass +Where.core.st(38, 4) [assert_5]: ❌ fail +Where.core.st(55, 4) [assert_6]: ❌ fail +Where.core.st(73, 4) [assert_7]: ✅ pass +Where.core.st(74, 4) [assert_8]: ❌ fail +Where.core.st(91, 4) [assert_9]: ✅ pass +Where.core.st(96, 4) [assert_10]: ✅ pass +Where.core.st(97, 4) [assert_11]: ❌ fail Finished with 7 goals passed, 5 failed. diff --git a/Tools/BoogieToStrata/Tests/bv9.expect b/Tools/BoogieToStrata/Tests/bv9.expect index 1ce03c2c9..a686951f7 100644 --- a/Tools/BoogieToStrata/Tests/bv9.expect +++ b/Tools/BoogieToStrata/Tests/bv9.expect @@ -1,3 +1,3 @@ Successfully parsed. -bv9.boogie.st(22, 4) [assert_0]: ✅ pass +bv9.core.st(22, 4) [assert_0]: ✅ pass All 1 goals passed. diff --git a/docs/Architecture.md b/docs/Architecture.md index 0cac5e463..2defda269 100644 --- a/docs/Architecture.md +++ b/docs/Architecture.md @@ -28,28 +28,15 @@ In the current implementation of Strata, composition of dialects can occur in tw Transformations (located in [`Strata.Transform`](../Strata/Transform/)) are a central part of the Strata infrastructure. For some dialects, semantics can be canonically defined in terms of reduction into simpler dialects. For other dialects, transformation of constructs from one form to another can make certain analyses more straightforward. For example, some analyses work better on structured programs and some are easier to implement on unstructured programs. Or some analyses might work best with imperative assignments preserved, while some forms of verification condition generation work better on “passive” programs consisting of only assertions and assumptions. -## Dialect Library +## Dialects in Strata -Strata includes several generic dialects that allow it to represent the semantics of a variety of common programming languages. These dialects are currently sufficient to represent the constructs available in Boogie, and allow some flexibility beyond what Boogie provides, as well. These dialects are located in the [`Strata.DL`](../Strata/DL/) namespace. +### 1. Strata Core -### Lambda - -The `Lambda` dialect ([`Strata.DL.Lambda`](../Strata/DL/Lambda/)) is intended to represent pure expressions of the sort that appear in essentially every programming or specification language. This dialect is parameterized by a set of built-in functions, allowing many first-order and higher-order expression languages as specific instantiations. - -### Imperative - -The `Imperative` dialect ([`Strata.DL.Imperative`](../Strata/DL/Imperative/)) is intended to represent imperative statements of the sort that appear in many programming languages. It is built of commands, which execute atomically, and currently has two mechanisms for combining commands: - -* deterministic structured statements (if and while statements with explicit conditions), -* non-deterministic structured statements (choice and repetition, with conditions encoded using assumptions), - -### Boogie - -The Boogie dialect ([`Strata.Languages.Boogie`](../Strata/Languages/Boogie/)) is intended to roughly mirror the capabilities of the [Boogie Intermediate Verification Language](https://github.com/boogie-org/boogie). As its foundation, it uses the `Imperative` dialect parameterized by the `Lambda` dialect. It specializes these dialects in several ways: +The Strata Core dialect ([`Strata.Languages.Core`](../Strata/Languages/Core/)) is intended to roughly mirror the capabilities of the [Boogie Intermediate Verification Language](https://github.com/boogie-org/boogie). As its foundation, it uses the `Imperative` semantic building block parameterized by the `Lambda` semantic building block. For the definition of semantic building block, please refer to the next section. It specializes these blocks in several ways: * It defines a type of identifiers that include scoping information, which is a parameter to `Lambda`. * It introduces data types to represent named functions and procedures with contracts. -* It extends the language of commands from the `Imperative` dialect to include procedure calls, and uses this extended set of commands as a parameter to the various statement types. +* It extends the language of commands from the `Imperative` block to include procedure calls, and uses this extended set of commands as a parameter to the various statement types. It currently provides the following features: @@ -65,9 +52,20 @@ The `Imperative` dialect also includes a verification condition generator (VCG) ### C_Simp -The C_Simp dialect ([`Strata.Languages.C_Simp`](../Strata//Languages/C_Simp/) is a vaguely C-like language intended to show how to model common programming language constructs in Strata. There are many examples in `C_Simp/Examples`. C_Simp builds on the `Imperative` dialect parameterized by the `Lambda` dialect. +The C_Simp dialect ([`Strata.Languages.C_Simp`](../Strata//Languages/C_Simp/)) is a vaguely C-like language intended to show how to model common programming language constructs in Strata. There are many examples in `C_Simp/Examples`. C_Simp builds on the `Imperative` dialect parameterized by the `Lambda` dialect. + +`C_Simp/Verify.lean` demonstrates verification via transformation to Strata Core. A loop elimination pass is first run to transform loops into the appropriate `assume` and `assert` commands, and then Strata Core's VCG, described above, is used to verify the program. + +### Laurel + +The Laurel dialect is supposed to serve as an intermediate verification language for at least Java, Python, JavaScript. It is translated to Strata Core during its deductive verification. +Please refer to the description in the [`Strata.Languages.Laurel.Laurel`](../Strata/Languages/Laurel/Laurel.lean). + +### SMTLib + +The SMTLib dialect exactly implements the syntax of SMTLib 2.7 +([The SMT-LIB Standard Version 2.7, Feb. 5, 2025](https://smt-lib.org/papers/smt-lib-reference-v2.7-r2025-02-05.pdf)). -`C_Simp/Verify.lean` demonstrates verification via transformation to Boogie. A loop elimination pass is first run to transform loops into the appropriate `assume` and `assert` commands, and then Boogie’s VCG, described above, is used to verify the program. ## Analysis @@ -76,11 +74,11 @@ Our intent is that analysis implementations in Strata become highly reusable by * An analysis can be defined over, for instance, imperative control flow graphs, while being generic over the types of commands and expressions that may appear in them, other than requiring that certain operations exist on them. This allows it to straightforwardly be applied to various instantiations of that type. * An analysis can be defined on one dialect, and transformations can move from other dialects into that one. This allows a single analysis implementation to be applied to multiple languages. -The current Strata implementation includes only one analysis: the Boogie dialect VCG. However, you can add your own analyses on top of the existing dialects. The Imperative dialect includes an inductively-defined operational semantics that can be used as a basis for verifying the correctness of analyses. +The current Strata implementation includes only one analysis: the Strata Core dialect VCG. However, you can add your own analyses on top of the existing dialects. The Imperative dialect includes an inductively-defined operational semantics that can be used as a basis for verifying the correctness of analyses. ## External Reasoning Tools -Strata was designed to be used with external reasoning tools such as SMT solvers, CHC solvers, abstract interpretation engines, model checkers, and others. Currently, the VCG for the Boogie language based on partial evaluation along with an interface to SMT solvers (in [`Strata.DL.SMT`](../Strata/DL/SMT/)). +Strata was designed to be used with external reasoning tools such as SMT solvers, CHC solvers, abstract interpretation engines, model checkers, and others. Currently, the VCG for the Strata Core language based on partial evaluation along with an interface to SMT solvers (in [`Strata.DL.SMT`](../Strata/DL/SMT/)). ## Third-Party Dialects and Analyses diff --git a/docs/Datatypes.md b/docs/Datatypes.md index bb255f996..46d39af3a 100644 --- a/docs/Datatypes.md +++ b/docs/Datatypes.md @@ -1,13 +1,13 @@ # Datatypes in Strata -This document describes the datatype system in Strata.Boogie. +This document describes the datatype system in Strata Core. For DDM-specific documentation on datatype annotations and the function template system, see the [DDM Manual](verso/DDMDoc.lean) (Datatypes section). ## Overview Strata supports algebraic datatypes (ADTs) similar to those found in functional programming languages. Datatypes allow one to define custom types with multiple constructors, each of which can have zero or more fields (constructor arguments). -Example in Boogie/Strata Core syntax: +Example in Strata Core syntax: ```boogie datatype Option () { None(), @@ -17,7 +17,7 @@ datatype Option () { ## Datatype Declaration Syntax -### Boogie/Strata Core Dialect +### Strata Core Dialect Datatypes are declared using the `datatype` keyword: @@ -72,7 +72,7 @@ datatype Tree () { ## Generated Functions -When a datatype is declared, Strata.Boogie automatically generates several auxiliary functions: +When a datatype is declared, Strata Core automatically generates several auxiliary functions: ### Constructors @@ -117,7 +117,7 @@ Datatypes are encoded in SMT-LIB using the `declare-datatypes` command: )) ``` -The generated functions (constructors, testers, accessors) are +The generated functions (constructors, testers, accessors) are mapped to the generated SMT functions (e.g. `Option..isNone` is automatically mapped to `is-None`). @@ -129,9 +129,9 @@ injectivity of constructors. 1. The DDM does not yet support polymorphic functions, including datatype constructors. Polymorphism is supported at the AST level. -Example: `StrataTest/Languages/Boogie/DatatypeVerificationTests.lean` +Example: `StrataTest/Languages/Core/DatatypeVerificationTests.lean` 2. Strata also generates eliminators per data type, allowing -the definition of terms defined by pattern matching and/or +the definition of terms defined by pattern matching and/or recursion, with the correct computational behavior. This is also not yet available at the DDM level. Example: `StrataTest/DL/Lambda/TypeFactoryTests.lean` @@ -140,7 +140,7 @@ Example: `StrataTest/DL/Lambda/TypeFactoryTests.lean` See the following test files for working examples: -- `StrataTest/Languages/Boogie/Examples/DatatypeEnum.lean` - Simple enums -- `StrataTest/Languages/Boogie/Examples/DatatypeOption.lean` - Option type -- `StrataTest/Languages/Boogie/Examples/DatatypeList.lean` - Recursive lists -- `StrataTest/Languages/Boogie/Examples/DatatypeTree.lean` - Binary trees +- `StrataTest/Languages/Core/Examples/DatatypeEnum.lean` - Simple enums +- `StrataTest/Languages/Core/Examples/DatatypeOption.lean` - Option type +- `StrataTest/Languages/Core/Examples/DatatypeList.lean` - Recursive lists +- `StrataTest/Languages/Core/Examples/DatatypeTree.lean` - Binary trees diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 89e1aee34..75b65b349 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -6,9 +6,9 @@ analyses. In this [example](../StrataTest/DL/Imperative), we show some of Strata's current capabilities by defining a simple Strata dialect called `ArithPrograms` and an associated deductive verifier based on the existing [Imperative](../Strata/DL/Imperative) -dialect in Strata's Dialect Library ([DL](../Strata/DL)). -`Imperative` provides basic commands and statements, is -parameterizable by expressions, and has a parameterizable partial +dialect in Strata's Dialect Library ([DL](../Strata/DL)). +`Imperative` provides basic commands and statements, is +parameterizable by expressions, and has a parameterizable partial evaluator that generates verification conditions. ### 1. Design the concrete syntax @@ -290,15 +290,15 @@ some next steps to explore: - **Study Existing Dialects**: Look at the implementation of the `Imperative` and `Lambda` dialects, and understand how they are used - as building blocks for the existing `Boogie` and `C_Simp` dialects. + as building blocks for the existing `Core` and `C_Simp` dialects. - **Add a New Dialect**: Create a new dialect that captures a language construct that you want to formalize and reason about. Perhaps you want to *transform* your new dialect into an existing Strata dialect to leverage any analysis available for the latter. You may also want to verify any such dialect transformations, i.e., prove that they - are semantics-preserving. One such example in Strata is for call - eliminiation in Boogie, [here](../Strata/Transform/). + are semantics-preserving. One such example in Strata is for call + eliminiation in Strata Core, [here](../Strata/Transform/). - **Create a Language Frontend**: Develop a parser to translate the concrete syntax of your language of interest to Strata. diff --git a/docs/verso/DDMDoc.lean b/docs/verso/DDMDoc.lean index 477cf933c..e7744491b 100644 --- a/docs/verso/DDMDoc.lean +++ b/docs/verso/DDMDoc.lean @@ -235,7 +235,7 @@ op assert (b : Bool) : Statement => "assert" b ";"; ``` For expressions, Strata supports polymorphic types. An example operator that uses -this is a polymorphic assignment operator in the Boogie statement dialect. +this is a polymorphic assignment operator in the Strata Core statement dialect. ``` op assign (tp : Type, v : Ident, e : tp) : Statement => v " := " e ";"; @@ -377,7 +377,7 @@ metadata declare(name : Ident, type : TypeOrCat); metadata nonempty; ``` -As an example, Boogie variable declaration syntax can be defined in Strata using the +As an example, Strata Core's variable declaration syntax can be defined in Strata using the following code: ``` @@ -444,7 +444,7 @@ be defined in user definable dialects. for special characters. * `Init.Num` represents numeric natural number literals. - + ## Datatypes %%% tag := "datatypes" @@ -461,12 +461,12 @@ constructors) _tester_ functions to identify to which constructor an instance be Dafny datatypes additionally produce an ordering relation, while Lean inductive types produce _eliminator_ instances defining induction principles. The DDM enables automatic creation of (a subset of) these auxiliary functions via a -configurable {deftech}_function template_ system. +configurable {deftech}_function template_ system. ### Example -In the Boogie dialect, the auxiliary functions are testers and accessors. That -is, one can define the following datatype in Strata.Boogie: +In the Strata Core dialect, the auxiliary functions are testers and accessors. That +is, one can define the following datatype in Strata Core: ``` datatype IntList { @@ -475,7 +475,7 @@ datatype IntList { }; ``` -This declares a list type with two constructors (`Nil` and `Cons`) and two fields (`head` and `tail`). The Boogie dialect automatically generates: +This declares a list type with two constructors (`Nil` and `Cons`) and two fields (`head` and `tail`). The Core dialect automatically generates: * Constructors: `Nil : IntList` and `Cons : int -> IntList -> IntList` * Testers: `IntList..isNil : IntList -> bool` and `IntList..isCons : IntList -> bool` @@ -484,7 +484,7 @@ This declares a list type with two constructors (`Nil` and `Cons`) and two field ### Defining Datatype Syntax in a Dialect To support datatypes in a dialect, you must define syntactic categories and -operators with appropriate annotations. The Boogie dialect provides a complete example. +operators with appropriate annotations. The Core dialect provides a complete example. #### Constructor Syntax @@ -517,7 +517,7 @@ arguments #### Datatype Command -The main datatype declaration uses `@[declareDatatype]` to tie everything together. It is best illustrated with an example (from the Boogie dialect): +The main datatype declaration uses `@[declareDatatype]` to tie everything together. It is best illustrated with an example (from the Core dialect): ``` @[declareDatatype(name, typeParams, constructors, @@ -532,7 +532,7 @@ op command_datatype (name : Ident, `@[declareDatatype]` declares a datatype command operator given the datatype name, the optional type parameters, the constructor list, and zero or more -[function templates](#datatypes-function-templates) to expand. Note that the `@[scopeDatatype]` +[function templates](#datatypes-function-templates) to expand. Note that the `@[scopeDatatype]` annotation brings the datatype name and type parameters into scope when parsing the constructors, enabling recursive type references. @@ -544,7 +544,7 @@ tag := "datatypes-function-templates" Function templates specify patterns for generating auxiliary functions from datatype declarations. Currently there are two supported templates: `perConstructor` generates one -function per constructor, while `perField` generates one function per field +function per constructor, while `perField` generates one function per field (note that the DDM enforces that fields are unique across all constructors in a datatype). @@ -575,7 +575,7 @@ Type references consist of the following components: ##### Example Templates -The Boogie dialect uses two templates: +The Strata Core dialect uses two templates: The tester template generates `IntList..isNil : IntList -> bool`: ``` diff --git a/lakefile.toml b/lakefile.toml index f70d9e7dc..ec73eb3d1 100644 --- a/lakefile.toml +++ b/lakefile.toml @@ -1,6 +1,6 @@ name = "Strata" version = "0.1.0" -defaultTargets = ["Strata", "strata", "StrataMain", "StrataVerify", "StrataToCBMC", "BoogieToGoto"] +defaultTargets = ["Strata", "strata", "StrataMain", "StrataVerify", "StrataToCBMC", "StrataCoreToGoto"] testDriver = "StrataTest" [leanOptions] @@ -33,4 +33,4 @@ name = "StrataVerify" name = "StrataToCBMC" [[lean_exe]] -name = "BoogieToGoto" +name = "StrataCoreToGoto"