Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QueryR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
Julien Lopez
QueryR
Commits
aab32f76
Commit
aab32f76
authored
8 years ago
by
Lukas Stadler
Browse files
Options
Downloads
Patches
Plain Diff
adapt and extends tests for special calls
parent
52869ac6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/test/SpecialCallTest.java
+112
-54
112 additions, 54 deletions
.../src/com/oracle/truffle/r/nodes/test/SpecialCallTest.java
with
112 additions
and
54 deletions
com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/test/SpecialCallTest.java
+
112
−
54
View file @
aab32f76
...
...
@@ -28,11 +28,6 @@ import org.junit.Test;
import
com.oracle.truffle.api.RootCallTarget
;
import
com.oracle.truffle.api.source.Source
;
import
com.oracle.truffle.r.engine.TruffleRLanguage
;
import
com.oracle.truffle.r.nodes.access.WriteVariableSyntaxNode
;
import
com.oracle.truffle.r.nodes.control.BlockNode
;
import
com.oracle.truffle.r.nodes.control.ReplacementDispatchNode
;
import
com.oracle.truffle.r.nodes.function.RCallNode
;
import
com.oracle.truffle.r.nodes.function.RCallSpecialNode
;
import
com.oracle.truffle.r.runtime.ArgumentsSignature
;
import
com.oracle.truffle.r.runtime.FastROptions
;
import
com.oracle.truffle.r.runtime.RError
;
...
...
@@ -59,12 +54,23 @@ public class SpecialCallTest extends TestBase {
@Override
protected
Void
visit
(
RSyntaxCall
element
)
{
if
(
element
instanceof
RCallSpecialNode
)
{
special
++;
}
else
if
(
element
instanceof
RCallNode
)
{
normal
++;
}
else
{
assert
element
instanceof
ReplacementDispatchNode
||
element
instanceof
WriteVariableSyntaxNode
||
element
instanceof
BlockNode
:
"unexpected node while testing"
;
switch
(
element
.
getClass
().
getSimpleName
())
{
case
"SpecialReplacementNode"
:
case
"SpecialVoidReplacementNode"
:
case
"RCallSpecialNode"
:
special
++;
break
;
case
"RCallNodeGen"
:
case
"GenericReplacementNode"
:
normal
++;
break
;
case
"ReplacementDispatchNode"
:
case
"WriteVariableSyntaxNode"
:
case
"BlockNode"
:
// ignored
break
;
default
:
throw
new
AssertionError
(
"unexpected class: "
+
element
.
getClass
().
getSimpleName
());
}
accept
(
element
.
getSyntaxLHS
());
for
(
RSyntaxElement
arg
:
element
.
getSyntaxArguments
())
{
...
...
@@ -158,81 +164,133 @@ public class SpecialCallTest extends TestBase {
assertCallCounts
(
"1 + 1"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"1 + 1 * 2 + 4"
,
3
,
0
,
3
,
0
);
assertCallCounts
(
"{ a <- 1; b <- 2
;
a + b
}
"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"{ a <- 1; b <- 2; c <- 3
;
a + b * 2 * c
}
"
,
3
,
0
,
3
,
0
);
assertCallCounts
(
"{ a <- 1; b <- 2
}"
,
"
a + b"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"{ a <- 1; b <- 2; c <- 3
}"
,
"
a + b * 2 * c"
,
3
,
0
,
3
,
0
);
assertCallCounts
(
"{ a <- data.frame(a=1); b <- 2; c <- 3
;
a + b * 2 * c
}
"
,
3
,
1
,
2
,
2
);
assertCallCounts
(
"{ a <- 1; b <- data.frame(a=1); c <- 3
;
a + b * 2 * c
}
"
,
3
,
1
,
0
,
4
);
assertCallCounts
(
"{ a <- data.frame(a=1); b <- 2; c <- 3
}"
,
"
a + b * 2 * c"
,
3
,
0
,
2
,
1
);
assertCallCounts
(
"{ a <- 1; b <- data.frame(a=1); c <- 3
}"
,
"
a + b * 2 * c"
,
3
,
0
,
0
,
3
);
assertCallCounts
(
"1 %*% 1"
,
0
,
1
,
0
,
1
);
}
@Test
public
void
testSubset
()
{
assertCallCounts
(
"{ a <- 1:10; a[1] }"
,
1
,
1
,
1
,
1
);
assertCallCounts
(
"{ a <- c(1,2,3,4); a[2] }"
,
1
,
1
,
1
,
1
);
assertCallCounts
(
"{ a <- c(1,2,3,4); a[4] }"
,
1
,
1
,
1
,
1
);
assertCallCounts
(
"{ a <- list(c(1,2,3,4),2,3); a[1] }"
,
1
,
2
,
1
,
2
);
assertCallCounts
(
"{ a <- c(1,2,3,4); a[0.1] }"
,
1
,
1
,
0
,
2
);
assertCallCounts
(
"{ a <- c(1,2,3,4); a[5] }"
,
1
,
1
,
0
,
2
);
assertCallCounts
(
"{ a <- c(1,2,3,4); a[0] }"
,
1
,
1
,
0
,
2
);
assertCallCounts
(
"{ a <- c(1,2,3,4); a[-1] }"
,
0
,
3
,
0
,
3
);
// "-1" is a unary expression
assertCallCounts
(
"{ a <- c(1,2,3,4); b <- -1; a[b] }"
,
1
,
2
,
0
,
3
);
assertCallCounts
(
"{ a <- c(1,2,3,4); a[NA_integer_] }"
,
1
,
1
,
0
,
2
);
assertCallCounts
(
"a <- 1:10"
,
"a[1]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[2]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[4]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- list(c(1,2,3,4),2,3)"
,
"a[1]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[0.1]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[5]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[0]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"{ a <- c(1,2,3,4); b <- -1 }"
,
"a[b]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[NA_integer_]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[-1]"
,
0
,
2
,
0
,
2
);
// "-1" is a unary expression
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[drop=T, 1]"
,
0
,
1
,
0
,
1
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[drop=F, 1]"
,
0
,
1
,
0
,
1
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[1, drop=F]"
,
0
,
1
,
0
,
1
);
}
@Test
public
void
testSubscript
()
{
assertCallCounts
(
"{ a <- 1:10; a[[1]] }"
,
1
,
1
,
1
,
1
);
assertCallCounts
(
"{ a <- c(1,2,3,4); a[[2]] }"
,
1
,
1
,
1
,
1
);
assertCallCounts
(
"{ a <- c(1,2,3,4); a[[4]] }"
,
1
,
1
,
1
,
1
);
assertCallCounts
(
"{ a <- list(c(1,2,3,4),2,3); a[[1]] }"
,
1
,
2
,
1
,
2
);
assertCallCounts
(
"{ a <- list(a=c(1,2,3,4),2,3); a[[1]] }"
,
1
,
2
,
1
,
2
);
assertCallCounts
(
"{ a <- c(1,2,3,4); a[[0.1]] }"
,
1
,
1
,
1
,
1
);
assertCallCounts
(
"{ a <- c(1,2,3,4); a[[5]] }"
,
1
,
1
,
0
,
2
);
assertCallCounts
(
"{ a <- c(1,2,3,4); a[[0]] }"
,
1
,
1
,
0
,
2
);
assertCallCounts
(
"{ a <- c(1,2,3,4); b <- -1; a[[b]] }"
,
1
,
2
,
0
,
3
);
assertCallCounts
(
"{ a <- c(1,2,3,4); a[[NA_integer_]] }"
,
1
,
1
,
0
,
2
);
assertCallCounts
(
"a <- 1:10"
,
"a[[1]]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[2]]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[4]]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- list(c(1,2,3,4),2,3)"
,
"a[[1]]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- list(a=c(1,2,3,4),2,3)"
,
"a[[1]]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[0.1]]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[5]]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[0]]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"{ a <- c(1,2,3,4); b <- -1 }"
,
"a[[b]]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[NA_integer_]]"
,
1
,
0
,
1
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[drop=T, 1]]"
,
0
,
1
,
0
,
1
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[drop=F, 1]]"
,
0
,
1
,
0
,
1
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[1, drop=F]]"
,
0
,
1
,
0
,
1
);
}
private
static
void
assertCallCounts
(
String
str
,
int
initialSpecialCount
,
int
initialNormalCount
,
int
finalSpecialCount
,
int
finalNormalCount
)
{
@Test
public
void
testUpdateSubset
()
{
assertCallCounts
(
"a <- 1:10"
,
"a[1] <- 1"
,
1
,
0
,
1
,
1
);
// sequence
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[2] <- 1"
,
1
,
0
,
2
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[4] <- 1"
,
1
,
0
,
2
,
0
);
assertCallCounts
(
"a <- list(c(1,2,3,4),2,3)"
,
"a[1] <- 1"
,
1
,
0
,
2
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[0.1] <- 1"
,
1
,
0
,
1
,
1
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[5] <- 1"
,
1
,
0
,
1
,
1
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[0] <- 1"
,
1
,
0
,
1
,
1
);
assertCallCounts
(
"{ a <- c(1,2,3,4); b <- -1 }"
,
"a[b] <- 1"
,
1
,
0
,
1
,
1
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[NA_integer_] <- 1"
,
1
,
0
,
1
,
1
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[-1] <- 1"
,
0
,
2
,
0
,
3
);
// "-1" is a unary expression
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[drop=T, 1] <- 1"
,
0
,
1
,
0
,
2
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[drop=F, 1] <- 1"
,
0
,
1
,
0
,
2
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[1, drop=F] <- 1"
,
0
,
1
,
0
,
2
);
}
@Test
public
void
testUpdateSubscript
()
{
assertCallCounts
(
"a <- 1:10"
,
"a[[1]] <- 1"
,
1
,
0
,
1
,
1
);
// sequence
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[2]] <- 1"
,
1
,
0
,
2
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[4]] <- 1"
,
1
,
0
,
2
,
0
);
assertCallCounts
(
"a <- list(c(1,2,3,4),2,3)"
,
"a[[1]] <- 1"
,
1
,
0
,
2
,
0
);
assertCallCounts
(
"a <- list(a=c(1,2,3,4),2,3)"
,
"a[[1]] <- 1"
,
1
,
0
,
2
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[0.1]] <- 1"
,
1
,
0
,
2
,
0
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[5]] <- 1"
,
1
,
0
,
1
,
1
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[0]] <- 1"
,
1
,
0
,
1
,
1
);
assertCallCounts
(
"{ a <- c(1,2,3,4); b <- -1 }"
,
"a[[b]] <- 1"
,
1
,
0
,
1
,
1
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[NA_integer_]] <- 1"
,
1
,
0
,
1
,
1
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[drop=T, 1]] <- 1"
,
0
,
1
,
0
,
2
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[drop=F, 1]] <- 1"
,
0
,
1
,
0
,
2
);
assertCallCounts
(
"a <- c(1,2,3,4)"
,
"a[[1, drop=F]] <- 1"
,
0
,
1
,
0
,
2
);
}
private
static
void
assertCallCounts
(
String
test
,
int
initialSpecialCount
,
int
initialNormalCount
,
int
finalSpecialCount
,
int
finalNormalCount
)
{
assertCallCounts
(
"{}"
,
test
,
initialSpecialCount
,
initialNormalCount
,
finalSpecialCount
,
finalNormalCount
);
}
private
static
void
assertCallCounts
(
String
setup
,
String
test
,
int
initialSpecialCount
,
int
initialNormalCount
,
int
finalSpecialCount
,
int
finalNormalCount
)
{
if
(!
FastROptions
.
UseSpecials
.
getBooleanValue
())
{
return
;
}
Source
source
=
Source
.
newBuilder
(
str
).
mimeType
(
TruffleRLanguage
.
MIME
).
name
(
"test"
).
build
();
Source
setupSource
=
Source
.
newBuilder
(
setup
).
mimeType
(
TruffleRLanguage
.
MIME
).
name
(
"test"
).
build
();
Source
testSource
=
Source
.
newBuilder
(
test
).
mimeType
(
TruffleRLanguage
.
MIME
).
name
(
"test"
).
build
();
RExpression
expression
=
testVMContext
.
getThisEngine
().
parse
(
source
);
assert
expression
.
getLength
()
==
1
;
RootCallTarget
callTarget
=
testVMContext
.
getThisEngine
().
makePromiseCallTarget
(((
RLanguage
)
expression
.
getDataAt
(
0
)).
getRep
().
asRSyntaxNode
().
asRNode
(),
"test"
);
RExpression
setupExpression
=
testVMContext
.
getThisEngine
().
parse
(
setupSource
);
RExpression
testExpression
=
testVMContext
.
getThisEngine
().
parse
(
testSource
);
assert
setupExpression
.
getLength
()
==
1
;
assert
testExpression
.
getLength
()
==
1
;
RootCallTarget
setupCallTarget
=
testVMContext
.
getThisEngine
().
makePromiseCallTarget
(((
RLanguage
)
setupExpression
.
getDataAt
(
0
)).
getRep
().
asRSyntaxNode
().
asRNode
(),
"test"
);
RootCallTarget
testCallTarget
=
testVMContext
.
getThisEngine
().
makePromiseCallTarget
(((
RLanguage
)
testExpression
.
getDataAt
(
0
)).
getRep
().
asRSyntaxNode
().
asRNode
(),
"test"
);
try
{
CountCallsVisitor
count1
=
new
CountCallsVisitor
(
c
allTarget
);
Assert
.
assertEquals
(
"initial special call count '"
+
st
r
+
"': "
,
initialSpecialCount
,
count1
.
special
);
Assert
.
assertEquals
(
"initial normal call count '"
+
st
r
+
"': "
,
initialNormalCount
,
count1
.
normal
);
CountCallsVisitor
count1
=
new
CountCallsVisitor
(
testC
allTarget
);
Assert
.
assertEquals
(
"initial special call count '"
+
s
etup
+
"; "
+
tes
t
+
"': "
,
initialSpecialCount
,
count1
.
special
);
Assert
.
assertEquals
(
"initial normal call count '"
+
s
etup
+
"; "
+
tes
t
+
"': "
,
initialNormalCount
,
count1
.
normal
);
try
{
callTarget
.
call
(
REnvironment
.
globalEnv
().
getFrame
());
setupCallTarget
.
call
(
REnvironment
.
globalEnv
().
getFrame
());
testCallTarget
.
call
(
REnvironment
.
globalEnv
().
getFrame
());
}
catch
(
RError
e
)
{
// ignore
}
CountCallsVisitor
count2
=
new
CountCallsVisitor
(
c
allTarget
);
Assert
.
assertEquals
(
"special call count after first call '"
+
st
r
+
"': "
,
finalSpecialCount
,
count2
.
special
);
Assert
.
assertEquals
(
"normal call count after first call '"
+
st
r
+
"': "
,
finalNormalCount
,
count2
.
normal
);
CountCallsVisitor
count2
=
new
CountCallsVisitor
(
testC
allTarget
);
Assert
.
assertEquals
(
"special call count after first call '"
+
s
etup
+
"; "
+
tes
t
+
"': "
,
finalSpecialCount
,
count2
.
special
);
Assert
.
assertEquals
(
"normal call count after first call '"
+
s
etup
+
"; "
+
tes
t
+
"': "
,
finalNormalCount
,
count2
.
normal
);
try
{
callTarget
.
call
(
REnvironment
.
globalEnv
().
getFrame
());
setupCallTarget
.
call
(
REnvironment
.
globalEnv
().
getFrame
());
testCallTarget
.
call
(
REnvironment
.
globalEnv
().
getFrame
());
}
catch
(
RError
e
)
{
// ignore
}
CountCallsVisitor
count3
=
new
CountCallsVisitor
(
c
allTarget
);
Assert
.
assertEquals
(
"special call count after second call '"
+
st
r
+
"': "
,
finalSpecialCount
,
count3
.
special
);
Assert
.
assertEquals
(
"normal call count after second call '"
+
st
r
+
"': "
,
finalNormalCount
,
count3
.
normal
);
CountCallsVisitor
count3
=
new
CountCallsVisitor
(
testC
allTarget
);
Assert
.
assertEquals
(
"special call count after second call '"
+
s
etup
+
"; "
+
tes
t
+
"': "
,
finalSpecialCount
,
count3
.
special
);
Assert
.
assertEquals
(
"normal call count after second call '"
+
s
etup
+
"; "
+
tes
t
+
"': "
,
finalNormalCount
,
count3
.
normal
);
}
catch
(
AssertionError
e
)
{
new
PrintCallsVisitor
().
print
(
c
allTarget
);
new
PrintCallsVisitor
().
print
(
testC
allTarget
);
throw
e
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Julien Lopez
@jlopez
mentioned in commit
02753a4d
·
8 years ago
mentioned in commit
02753a4d
mentioned in commit 02753a4da34ba1078b3e525e5ba843249fa5a39e
Toggle commit list
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