Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
69f84164
Commit
69f84164
authored
9 years ago
by
Manos Koukoutos
Browse files
Options
Downloads
Patches
Plain Diff
EpsilonElimination should create FunDefs with all binders in scope as params
parent
676dea74
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/scala/leon/purescala/ExprOps.scala
+33
-0
33 additions, 0 deletions
src/main/scala/leon/purescala/ExprOps.scala
src/main/scala/leon/xlang/EpsilonElimination.scala
+16
-16
16 additions, 16 deletions
src/main/scala/leon/xlang/EpsilonElimination.scala
with
49 additions
and
16 deletions
src/main/scala/leon/purescala/ExprOps.scala
+
33
−
0
View file @
69f84164
...
...
@@ -306,8 +306,40 @@ object ExprOps {
})(
expr
)
}
def
preTransformWithBinders
(
f
:
(
Expr
,
Set
[
Identifier
])
=>
Expr
,
initBinders
:
Set
[
Identifier
]
=
Set
())(
e
:
Expr
)
=
{
import
xlang.Expressions.LetVar
def
rec
(
binders
:
Set
[
Identifier
],
e
:
Expr
)
:
Expr
=
(
f
(
e
,
binders
)
match
{
case
LetDef
(
fd
,
bd
)
=>
fd
.
fullBody
=
rec
(
binders
++
fd
.
paramIds
,
fd
.
fullBody
)
LetDef
(
fd
,
rec
(
binders
,
bd
))
case
Let
(
i
,
v
,
b
)
=>
Let
(
i
,
rec
(
binders
+
i
,
v
),
rec
(
binders
+
i
,
b
))
case
LetVar
(
i
,
v
,
b
)
=>
LetVar
(
i
,
rec
(
binders
+
i
,
v
),
rec
(
binders
+
i
,
b
))
case
MatchExpr
(
scrut
,
cses
)
=>
MatchExpr
(
rec
(
binders
,
scrut
),
cses
map
{
case
MatchCase
(
pat
,
og
,
rhs
)
=>
val
newBs
=
binders
++
pat
.
binders
MatchCase
(
pat
,
og
map
(
rec
(
newBs
,
_
)),
rec
(
newBs
,
rhs
))
})
case
Passes
(
in
,
out
,
cses
)
=>
Passes
(
rec
(
binders
,
in
),
rec
(
binders
,
out
),
cses
map
{
case
MatchCase
(
pat
,
og
,
rhs
)
=>
val
newBs
=
binders
++
pat
.
binders
MatchCase
(
pat
,
og
map
(
rec
(
newBs
,
_
)),
rec
(
newBs
,
rhs
))
})
case
Lambda
(
args
,
bd
)
=>
Lambda
(
args
,
rec
(
binders
++
args
.
map
(
_
.
id
),
bd
))
case
Forall
(
args
,
bd
)
=>
Forall
(
args
,
rec
(
binders
++
args
.
map
(
_
.
id
),
bd
))
case
Operator
(
subs
,
builder
)
=>
builder
(
subs
map
(
rec
(
binders
,
_
)))
}).
copiedFrom
(
e
)
rec
(
initBinders
,
e
)
}
/** Returns the set of identifiers in an expression */
def
variablesOf
(
expr
:
Expr
)
:
Set
[
Identifier
]
=
{
import
leon.xlang.Expressions.LetVar
fold
[
Set
[
Identifier
]]
{
case
(
e
,
subs
)
=>
val
subvs
=
subs
.
flatten
.
toSet
...
...
@@ -315,6 +347,7 @@ object ExprOps {
case
Variable
(
i
)
=>
subvs
+
i
case
LetDef
(
fd
,
_
)
=>
subvs
--
fd
.
params
.
map
(
_
.
id
)
case
Let
(
i
,
_
,
_
)
=>
subvs
-
i
case
LetVar
(
i
,
_
,
_
)
=>
subvs
-
i
case
MatchExpr
(
_
,
cses
)
=>
subvs
--
cses
.
flatMap
(
_
.
pattern
.
binders
)
case
Passes
(
_
,
_
,
cses
)
=>
subvs
--
cses
.
flatMap
(
_
.
pattern
.
binders
)
case
Lambda
(
args
,
_
)
=>
subvs
--
args
.
map
(
_
.
id
)
...
...
This diff is collapsed.
Click to expand it.
src/main/scala/leon/xlang/EpsilonElimination.scala
+
16
−
16
View file @
69f84164
...
...
@@ -16,24 +16,24 @@ object EpsilonElimination extends UnitPhase[Program] {
def
apply
(
ctx
:
LeonContext
,
pgm
:
Program
)
=
{
for
{
fd
<-
pgm
.
definedFunctions
body
<-
fd
.
body
}
{
val
newBody
=
postMap
{
case
eps
@Epsilon
(
pred
,
tpe
)
=>
val
freshName
=
FreshIdentifier
(
"epsilon"
)
val
newFunDef
=
new
FunDef
(
freshName
,
Nil
,
tpe
,
Seq
())
val
epsilonVar
=
EpsilonVariable
(
eps
.
getPos
,
tpe
)
val
resId
=
FreshIdentifier
(
"res"
,
tpe
)
val
postcondition
=
replace
(
Map
(
epsilonVar
->
Variable
(
resId
)),
pred
)
for
(
fd
<-
pgm
.
definedFunctions
)
{
fd
.
fullBody
=
preTransformWithBinders
({
case
(
eps
@Epsilon
(
pred
,
tpe
),
binders
)
=>
val
freshName
=
FreshIdentifier
(
"epsilon"
)
val
bSeq
=
binders
.
toSeq
val
freshParams
=
bSeq
.
map
{
_
.
freshen
}
val
newFunDef
=
new
FunDef
(
freshName
,
Nil
,
tpe
,
freshParams
map
(
ValDef
(
_
)))
val
epsilonVar
=
EpsilonVariable
(
eps
.
getPos
,
tpe
)
val
resId
=
FreshIdentifier
(
"res"
,
tpe
)
val
eMap
:
Map
[
Expr
,
Expr
]
=
bSeq
.
zip
(
freshParams
).
map
{
case
(
from
,
to
)
=>
(
Variable
(
from
),
Variable
(
to
))
}.
toMap
++
Seq
((
epsilonVar
,
Variable
(
resId
)))
val
postcondition
=
replace
(
eMap
,
pred
)
newFunDef
.
postcondition
=
Some
(
Lambda
(
Seq
(
ValDef
(
resId
)),
postcondition
))
Some
(
LetDef
(
newFunDef
,
FunctionInvocation
(
newFunDef
.
typed
,
Seq
())
))
LetDef
(
newFunDef
,
FunctionInvocation
(
newFunDef
.
typed
,
b
Seq
map
Variable
))
case
_
=>
None
}(
body
)
fd
.
body
=
Some
(
newBody
)
case
(
other
,
_
)
=>
other
},
fd
.
paramIds
.
toSet
)(
fd
.
fullBody
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment