Skip to content

Commit 8007d8d

Browse files
authored
Certifier: add the decision procedure for caseReduce into the certifier (#6939)
1 parent b433a05 commit 8007d8d

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

plutus-metatheory/plutus-metatheory.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,11 @@ library
355355
MAlonzo.Code.VerifiedCompilation.Equality
356356
MAlonzo.Code.VerifiedCompilation.Purity
357357
MAlonzo.Code.VerifiedCompilation.UCaseOfCase
358+
MAlonzo.Code.VerifiedCompilation.UCaseReduce
358359
MAlonzo.Code.VerifiedCompilation.UCSE
359360
MAlonzo.Code.VerifiedCompilation.UFloatDelay
360361
MAlonzo.Code.VerifiedCompilation.UForceDelay
362+
MAlonzo.Code.VerifiedCompilation.UInline
361363
MAlonzo.Code.VerifiedCompilation.UntypedTranslation
362364
MAlonzo.Code.VerifiedCompilation.UntypedViews
363365
MAlonzo.RTE
@@ -370,11 +372,13 @@ library
370372
MAlonzo.Code.Agda.Builtin.Float
371373
MAlonzo.Code.Agda.Builtin.Int
372374
MAlonzo.Code.Agda.Builtin.IO
375+
MAlonzo.Code.VerifiedCompilation.UInline
373376
MAlonzo.Code.Agda.Builtin.List
374377
MAlonzo.Code.Agda.Builtin.Maybe
375378
MAlonzo.Code.Agda.Builtin.Nat
376379
MAlonzo.Code.Agda.Builtin.Reflection
377380
MAlonzo.Code.Agda.Builtin.Sigma
381+
MAlonzo.Code.VerifiedCompilation.UCaseReduce
378382
MAlonzo.Code.Agda.Builtin.Strict
379383
MAlonzo.Code.Agda.Builtin.String
380384
MAlonzo.Code.Agda.Builtin.Unit

plutus-metatheory/src/VerifiedCompilation.lagda.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,33 @@ containing the generated proof object, a.k.a. the _certificate_. The certificate
2727
it into Agda and checking that it is correctly typed.
2828

2929
```
30-
{-# OPTIONS --allow-unsolved-metas #-}
3130
module VerifiedCompilation where
3231
```
3332

3433
## Imports
3534

3635
```
37-
import Data.Bool.Base using (Bool; true; false; T; _∧_; _∨_; not)
38-
open import Data.Nat using (ℕ; zero; suc)
3936
open import Relation.Nullary using (Dec; yes; no; ¬_)
4037
41-
import Relation.Nullary using (_×-dec_)
42-
import Relation.Binary using (Decidable)
4338
open import Untyped
4439
open import Utils as U using (Maybe;nothing;just;Either;inj₁;inj₂;List;[];_∷_;_×_;_,_)
4540
open import RawU using (Untyped)
46-
open import Data.String using (String;_++_)
41+
open import Data.String using (String)
4742
open import Agda.Builtin.IO using (IO)
48-
open import Agda.Builtin.Unit using (⊤;tt)
49-
import IO.Primitive.Core as IO using (return;_>>=_)
43+
open import Agda.Builtin.Unit using (⊤)
5044
import VerifiedCompilation.UCaseOfCase as UCC
5145
import VerifiedCompilation.UForceDelay as UFD
5246
import VerifiedCompilation.UFloatDelay as UFlD
5347
import VerifiedCompilation.UCSE as UCSE
48+
import VerifiedCompilation.UInline as UInline
49+
import VerifiedCompilation.UCaseReduce as UCR
5450
open import Data.Empty using (⊥)
55-
open import Scoped using (ScopeError;deBError)
5651
open import VerifiedCompilation.Equality using (DecEq)
57-
import Relation.Binary as Binary using (Decidable)
58-
open import VerifiedCompilation.UntypedTranslation using (Translation; Relation; translation?)
59-
import Relation.Binary as Binary using (Decidable)
52+
open import VerifiedCompilation.UntypedTranslation using (Relation)
6053
import Relation.Unary as Unary using (Decidable)
6154
import Agda.Builtin.Int
6255
import Relation.Nary as Nary using (Decidable)
56+
import IO.Primitive.Core as IO
6357
```
6458

6559
## Compiler optimisation traces
@@ -96,8 +90,10 @@ data Transformation : SimplifierTag → Relation where
9690
isFD : {X : Set}{{_ : DecEq X}} → {ast ast' : X ⊢} → UFD.ForceDelay ast ast' → Transformation forceDelayT ast ast'
9791
isFlD : {X : Set}{{_ : DecEq X}} → {ast ast' : X ⊢} → UFlD.FloatDelay ast ast' → Transformation floatDelayT ast ast'
9892
isCSE : {X : Set}{{_ : DecEq X}} → {ast ast' : X ⊢} → UCSE.UntypedCSE ast ast' → Transformation cseT ast ast'
93+
-- TODO: the decision procedure for Inline is broken, so we leave it as "not implemented"
94+
-- isUInline : {X : Set}{{_ : DecEq X}} → {ast ast' : X ⊢} → UInline.UInline ast ast' → Transformation inlineT ast ast'
9995
inlineNotImplemented : {X : Set}{{_ : DecEq X}} → {ast ast' : X ⊢} → Transformation inlineT ast ast'
100-
caseReduceNotImplemented : {X : Set}{{_ : DecEq X}} → {ast ast' : X ⊢} → Transformation caseReduceT ast ast'
96+
isCaseReduce : {X : Set}{{_ : DecEq X}} → {ast ast' : X ⊢} → UCR.UCaseReduce ast ast' → Transformation caseReduceT ast ast'
10197
10298
data Trace : { X : Set } {{_ : DecEq X}} → List (SimplifierTag × (X ⊢) × (X ⊢)) → Set₁ where
10399
empty : {X : Set}{{_ : DecEq X}} → Trace {X} []
@@ -120,8 +116,14 @@ isTransformation? tag ast ast' | forceDelayT with UFD.isForceDelay? ast ast'
120116
isTransformation? tag ast ast' | caseOfCaseT with UCC.isCaseOfCase? ast ast'
121117
... | no ¬p = no λ { (isCoC x) → ¬p x }
122118
... | yes p = yes (isCoC p)
123-
isTransformation? tag ast ast' | caseReduceT = yes caseReduceNotImplemented
119+
-- isTransformation? tag ast ast' | caseReduceT = yes caseReduceNotImplemented
120+
isTransformation? tag ast ast' | caseReduceT with UCR.isCaseReduce? ast ast'
121+
... | no ¬p = no λ { (isCaseReduce x) → ¬p x }
122+
... | yes p = yes (isCaseReduce p)
124123
isTransformation? tag ast ast' | inlineT = yes inlineNotImplemented
124+
-- isTransformation? tag ast ast' | inlineT with UInline.isInline? ast ast'
125+
-- ... | no ¬p = no λ { (isUInline x) → ¬p x }
126+
-- ... | yes p = yes (isUInline p)
125127
isTransformation? tag ast ast' | cseT with UCSE.isUntypedCSE? ast ast'
126128
... | no ¬p = no λ { (isCSE x) → ¬p x }
127129
... | yes p = yes (isCSE p)

plutus-metatheory/src/VerifiedCompilation/UCaseReduce.lagda.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ isCR? ast ast' with (isCase? (isConstr? allTerms?) allTerms?) ast
6666
6767
isCaseReduce? = translation? isCR?
6868
69+
UCaseReduce = Translation CaseReduce
70+
6971
```
7072
## An Example:
7173

plutus-metatheory/src/VerifiedCompilation/UInline.lagda.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module VerifiedCompilation.UInline where
1313
```
1414
open import VerifiedCompilation.Equality using (DecEq; _≟_; decPointwise)
1515
open import VerifiedCompilation.UntypedViews using (Pred; isCase?; isApp?; isLambda?; isForce?; isBuiltin?; isConstr?; isDelay?; isTerm?; allTerms?; iscase; isapp; islambda; isforce; isbuiltin; isconstr; isterm; allterms; isdelay)
16-
open import VerifiedCompilation.UntypedTranslation using (Translation; translation?; Relation; convert; reflexive)
16+
open import VerifiedCompilation.UntypedTranslation using (Translation; TransMatch; translation?; Relation; convert; reflexive)
1717
import Relation.Binary as Binary using (Decidable)
1818
open import Untyped.RenamingSubstitution using (_[_])
1919
open import Agda.Builtin.Maybe using (Maybe; just; nothing)
@@ -43,7 +43,7 @@ _ : pureInline {⊥} (ƛ (` nothing) · error) error
4343
_ = inline (tr reflexive)
4444
4545
_ : {X : Set} {a b : X} {{_ : DecEq X}} → pureInline (((ƛ (ƛ ((` (just nothing)) · (` nothing)))) · (` a)) · (` b)) ((` a) · (` b))
46-
_ = tr (Translation.app (Translation.istranslation (inline (tr reflexive))) reflexive) ⨾ inline (tr reflexive)
46+
_ = tr (Translation.match (TransMatch.app (Translation.istranslation (inline (tr reflexive))) reflexive)) ⨾ inline (tr reflexive)
4747
4848
```
4949
However, this has several intermediate values that are very hard to determine for a decision procedure.
@@ -76,7 +76,7 @@ _ = var (var (sub (last-sub reflexive)))
7676
7777
_ : {X : Set} {a b : X} {{_ : DecEq X}} → Translation (Inline □) (((ƛ (ƛ ((` (just nothing)) · (` nothing)))) · (` a)) · (` b)) ((ƛ ((` (just a)) · (` nothing))) · (` b))
7878
79-
_ = Translation.app (Translation.istranslation (var (last-sub reflexive))) reflexive
79+
_ = Translation.match (TransMatch.app (Translation.istranslation (var (last-sub reflexive))) reflexive)
8080
```
8181
# Inline implies pureInline
8282
```
@@ -108,4 +108,7 @@ isIl? ((e , v₁) , v) .(ƛ x) ast' | no ¬app | yes (islambda (isterm x)) with
108108
109109
isInline? = translation? (isIl? □)
110110
111+
UInline : {X : Set} {{_ : DecEq X}} → (ast : X ⊢) → (ast' : X ⊢) → Set₁
112+
UInline = Translation (Inline □)
113+
111114
```

0 commit comments

Comments
 (0)