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
7d652be1
Commit
7d652be1
authored
9 years ago
by
Mikaël Mayer
Browse files
Options
Downloads
Patches
Plain Diff
ExampleAdder can now update the passes construct
inside top-level Choose statements in functions
parent
96449c61
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/scala/leon/synthesis/disambiguation/ExamplesAdder.scala
+35
-29
35 additions, 29 deletions
...n/scala/leon/synthesis/disambiguation/ExamplesAdder.scala
with
35 additions
and
29 deletions
src/main/scala/leon/synthesis/disambiguation/ExamplesAdder.scala
+
35
−
29
View file @
7d652be1
...
...
@@ -4,7 +4,7 @@ package synthesis
package
disambiguation
import
purescala.Types.FunctionType
import
purescala.Common.FreshIdentifier
import
purescala.Common.
{
FreshIdentifier
,
Identifier
}
import
purescala.Constructors.
{
and
,
tupleWrap
}
import
purescala.Definitions.
{
FunDef
,
Program
,
ValDef
}
import
purescala.ExprOps
...
...
@@ -53,6 +53,36 @@ class ExamplesAdder(ctx0: LeonContext, program: Program) {
private
def
filterCases
(
cases
:
Seq
[
MatchCase
])
=
cases
.
filter
(
c
=>
c
.
optGuard
!=
Some
(
BooleanLiteral
(
false
)))
def
addToExpr
(
post
:
Expr
,
id
:
Identifier
,
inputVariables
:
Expr
,
newCases
:
Seq
[
MatchCase
])
:
Expr
=
{
if
(
purescala
.
ExprOps
.
exists
(
_
.
isInstanceOf
[
Passes
])(
post
))
{
post
match
{
case
TopLevelAnds
(
exprs
)
=>
val
i
=
exprs
.
lastIndexWhere
{
x
=>
x
match
{
case
Passes
(
in
,
out
,
cases
)
if
in
==
inputVariables
&&
out
==
Variable
(
id
)
=>
true
case
_
=>
false
}
}
if
(
i
==
-
1
)
{
Lambda
(
Seq
(
ValDef
(
id
)),
and
(
post
,
Passes
(
inputVariables
,
Variable
(
id
),
newCases
)))
//ctx0.reporter.info("No top-level passes in postcondition, adding it: " + fd)
}
else
{
val
newPasses
=
exprs
(
i
)
match
{
case
Passes
(
in
,
out
,
cases
)
=>
Passes
(
in
,
out
,
(
filterCases
(
cases
)
++
newCases
).
distinct
)
case
_
=>
???
}
val
newPost
=
and
(
exprs
.
updated
(
i
,
newPasses
)
:
_
*
)
Lambda
(
Seq
(
ValDef
(
id
)),
newPost
)
//ctx0.reporter.info("Adding the example to the passes postcondition: " + fd)
}
}
}
else
{
Lambda
(
Seq
(
ValDef
(
id
)),
and
(
post
,
Passes
(
inputVariables
,
Variable
(
id
),
newCases
)))
//ctx0.reporter.info("No passes in postcondition, adding it:" + fd)
}
}
/** Adds the given input/output examples to the function definitions */
def
addToFunDef
(
fd
:
FunDef
,
examples
:
Seq
[(
Expr
,
Expr
)])
:
Unit
=
{
val
params
=
if
(
_removeFunctionParameters
)
fd
.
params
.
filter
(
x
=>
!
x
.
getType
.
isInstanceOf
[
FunctionType
])
else
fd
.
params
...
...
@@ -60,38 +90,14 @@ class ExamplesAdder(ctx0: LeonContext, program: Program) {
val
newCases
=
examples
.
map
{
case
(
in
,
out
)
=>
exampleToCase
(
in
,
out
)
}
fd
.
postcondition
match
{
case
Some
(
Lambda
(
Seq
(
ValDef
(
id
)),
post
))
=>
if
(
fd
.
postcondition
.
exists
{
e
=>
purescala
.
ExprOps
.
exists
(
_
.
isInstanceOf
[
Passes
])(
e
)
})
{
post
match
{
case
TopLevelAnds
(
exprs
)
=>
val
i
=
exprs
.
lastIndexWhere
{
x
=>
x
match
{
case
Passes
(
in
,
out
,
cases
)
if
in
==
inputVariables
&&
out
==
Variable
(
id
)
=>
true
case
_
=>
false
}
}
if
(
i
==
-
1
)
{
fd
.
postcondition
=
Some
(
Lambda
(
Seq
(
ValDef
(
id
)),
and
(
post
,
Passes
(
inputVariables
,
Variable
(
id
),
newCases
))))
//ctx0.reporter.info("No top-level passes in postcondition, adding it: " + fd)
}
else
{
val
newPasses
=
exprs
(
i
)
match
{
case
Passes
(
in
,
out
,
cases
)
=>
Passes
(
in
,
out
,
(
filterCases
(
cases
)
++
newCases
).
distinct
)
case
_
=>
???
}
val
newPost
=
and
(
exprs
.
updated
(
i
,
newPasses
)
:
_
*
)
fd
.
postcondition
=
Some
(
Lambda
(
Seq
(
ValDef
(
id
)),
newPost
))
//ctx0.reporter.info("Adding the example to the passes postcondition: " + fd)
}
}
}
else
{
fd
.
postcondition
=
Some
(
Lambda
(
Seq
(
ValDef
(
id
)),
and
(
post
,
Passes
(
inputVariables
,
Variable
(
id
),
newCases
))))
//ctx0.reporter.info("No passes in postcondition, adding it:" + fd)
}
fd
.
postcondition
=
Some
(
addToExpr
(
post
,
id
,
inputVariables
,
newCases
))
case
None
=>
val
id
=
FreshIdentifier
(
"res"
,
fd
.
returnType
,
false
)
fd
.
postcondition
=
Some
(
Lambda
(
Seq
(
ValDef
(
id
)),
Passes
(
inputVariables
,
Variable
(
id
),
newCases
)))
//ctx0.reporter.info("No postcondition, adding it: " + fd)
fd
.
postcondition
=
Some
(
addToExpr
(
BooleanLiteral
(
true
),
id
,
inputVariables
,
newCases
))
}
fd
.
body
match
{
// TODO: Is it correct to discard the choose construct inside the body?
case
Some
(
Choose
(
Lambda
(
Seq
(
ValDef
(
id
)),
bodyChoose
)))
=>
fd
.
body
=
Some
(
Hole
(
id
.
getType
,
Nil
))
case
Some
(
Choose
(
Lambda
(
Seq
(
ValDef
(
id
)),
bodyChoose
)))
=>
fd
.
body
=
Some
(
Choose
(
addToExpr
(
bodyChoose
,
id
,
inputVariables
,
newCases
)))
case
_
=>
}
}
...
...
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