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
86b219fc
Commit
86b219fc
authored
9 years ago
by
Regis Blanc
Browse files
Options
Downloads
Patches
Plain Diff
use implicit state for random with correct execution
parent
2454f640
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
library/leon/util/Random.scala
+69
-8
69 additions, 8 deletions
library/leon/util/Random.scala
testcases/verification/xlang/DataRacing.scala
+2
-1
2 additions, 1 deletion
testcases/verification/xlang/DataRacing.scala
with
71 additions
and
9 deletions
library/leon/util/Random.scala
+
69
−
8
View file @
86b219fc
...
@@ -7,30 +7,91 @@ import leon.lang.xlang._
...
@@ -7,30 +7,91 @@ import leon.lang.xlang._
object
Random
{
object
Random
{
@library
case
class
State
(
var
seed
:
BigInt
)
@library
def
newState
:
State
=
State
(
0
)
@library
@library
@isabelle
.
noBody
()
@isabelle
.
noBody
()
def
nextBoolean
()
:
Boolean
=
epsilon
((
x
:
Boolean
)
=>
true
)
def
nextBoolean
(
implicit
state
:
State
)
:
Boolean
=
{
state
.
seed
+=
1
nativeNextBoolean
}
ensuring
((
x
:
Boolean
)
=>
true
)
@library
@library
@extern
@isabelle
.
noBody
()
@isabelle
.
noBody
()
def
nextInt
()
:
Int
=
epsilon
((
x
:
Int
)
=>
true
)
private
def
nativeNextBoolean
(
implicit
state
:
State
)
:
Boolean
=
{
scala
.
util
.
Random
.
nextBoolean
}
ensuring
((
x
:
Boolean
)
=>
true
)
@library
@isabelle
.
noBody
()
def
nextInt
(
implicit
state
:
State
)
:
Int
=
{
state
.
seed
+=
1
nativeNextInt
}
ensuring
((
x
:
Int
)
=>
true
)
@library
@extern
@isabelle
.
noBody
()
private
def
nativeNextInt
(
implicit
state
:
State
)
:
Int
=
{
scala
.
util
.
Random
.
nextInt
}
ensuring
((
x
:
Int
)
=>
true
)
@library
@library
@isabelle
.
noBody
()
@isabelle
.
noBody
()
def
nextInt
(
max
:
Int
)
:
Int
=
{
def
nextInt
(
max
:
Int
)
(
implicit
state
:
State
)
:
Int
=
{
require
(
max
>
0
)
require
(
max
>
0
)
epsilon
((
x
:
Int
)
=>
x
>=
0
&&
x
<
max
)
state
.
seed
+=
1
nativeNextInt
(
max
)
}
ensuring
(
res
=>
res
>=
0
&&
res
<
max
)
}
ensuring
(
res
=>
res
>=
0
&&
res
<
max
)
@library
@library
@extern
@isabelle
.
noBody
()
@isabelle
.
noBody
()
def
nextBigInt
()
:
BigInt
=
epsilon
((
x
:
BigInt
)
=>
true
)
def
nativeNextInt
(
max
:
Int
)(
implicit
state
:
State
)
:
Int
=
{
scala
.
util
.
Random
.
nextInt
(
max
)
}
ensuring
(
res
=>
res
>=
0
&&
res
<
max
)
@library
@isabelle
.
noBody
()
def
nextBigInt
(
implicit
state
:
State
)
:
BigInt
=
{
state
.
seed
+=
1
nativeNextBigInt
}
ensuring
((
x
:
BigInt
)
=>
true
)
@library
@library
@extern
@isabelle
.
noBody
()
@isabelle
.
noBody
()
def
nextBigInt
(
max
:
BigInt
)
:
BigInt
=
{
private
def
nativeNextBigInt
(
implicit
state
:
State
)
:
BigInt
=
{
BigInt
(
scala
.
util
.
Random
.
nextInt
)
}
ensuring
((
x
:
BigInt
)
=>
true
)
@library
@isabelle
.
noBody
()
def
nextBigInt
(
max
:
BigInt
)(
implicit
state
:
State
)
:
BigInt
=
{
require
(
max
>
0
)
require
(
max
>
0
)
epsilon
((
x
:
BigInt
)
=>
x
>=
0
&&
x
<
max
)
state
.
seed
+=
1
}
ensuring
(
res
=>
res
>=
0
&&
res
<
max
)
nativeNextBigInt
(
max
)
}
ensuring
((
res
:
BigInt
)
=>
res
>=
0
&&
res
<
max
)
@library
@extern
@isabelle
.
noBody
()
private
def
nativeNextBigInt
(
max
:
BigInt
)(
implicit
state
:
State
)
:
BigInt
=
{
BigInt
(
scala
.
util
.
Random
.
nextInt
(
max
.
toInt
))
}
ensuring
((
x
:
BigInt
)
=>
x
>=
0
&&
x
<
max
)
}
}
This diff is collapsed.
Click to expand it.
testcases/verification/xlang/DataRacing.scala
+
2
−
1
View file @
86b219fc
...
@@ -16,7 +16,7 @@ object DataRacing {
...
@@ -16,7 +16,7 @@ object DataRacing {
case
class
RunnableCons
(
instr
:
AtomicInstr
,
tail
:
Runnable
)
extends
Runnable
case
class
RunnableCons
(
instr
:
AtomicInstr
,
tail
:
Runnable
)
extends
Runnable
case
class
RunnableNil
()
extends
Runnable
case
class
RunnableNil
()
extends
Runnable
def
execute
(
t1
:
Runnable
,
t2
:
Runnable
,
state
:
SharedState
)
:
Unit
=
(
t1
,
t2
)
match
{
def
execute
(
t1
:
Runnable
,
t2
:
Runnable
,
state
:
SharedState
)
(
implicit
randomState
:
Random.State
)
:
Unit
=
(
t1
,
t2
)
match
{
case
(
RunnableCons
(
x
,
xs
),
RunnableCons
(
y
,
ys
))
=>
case
(
RunnableCons
(
x
,
xs
),
RunnableCons
(
y
,
ys
))
=>
if
(
Random
.
nextBoolean
)
{
if
(
Random
.
nextBoolean
)
{
x
.
instr
(
state
)
x
.
instr
(
state
)
...
@@ -37,6 +37,7 @@ object DataRacing {
...
@@ -37,6 +37,7 @@ object DataRacing {
//z3 finds counterexample in 0.5
//z3 finds counterexample in 0.5
//cvc4 needs 130 seconds
//cvc4 needs 130 seconds
def
main
()
:
Int
=
{
def
main
()
:
Int
=
{
implicit
val
randomState
=
Random
.
newState
val
state
=
SharedState
(
0
)
val
state
=
SharedState
(
0
)
val
t1
=
RunnableCons
((
s
:
SharedState
)
=>
s
.
i
=
s
.
i
+
1
,
RunnableNil
())
val
t1
=
RunnableCons
((
s
:
SharedState
)
=>
s
.
i
=
s
.
i
+
1
,
RunnableNil
())
val
t2
=
RunnableCons
((
s
:
SharedState
)
=>
s
.
i
=
s
.
i
*
2
,
RunnableNil
())
val
t2
=
RunnableCons
((
s
:
SharedState
)
=>
s
.
i
=
s
.
i
*
2
,
RunnableNil
())
...
...
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