From 731920008efa9af2b0629783a338bece639e4561 Mon Sep 17 00:00:00 2001 From: Florian Angerer <florian.angerer@oracle.com> Date: Thu, 7 Sep 2017 13:19:05 +0200 Subject: [PATCH] Reusing temporary vectors in 'as.*' builtins. --- .../r/nodes/builtin/base/AsCharacter.java | 12 ++- .../r/nodes/builtin/base/AsDouble.java | 10 +-- .../r/nodes/builtin/base/AsInteger.java | 12 ++- .../r/nodes/builtin/base/AsLogical.java | 12 ++- .../truffle/r/nodes/builtin/base/AsRaw.java | 12 ++- .../function/opt/ReuseTemporaryNode.java | 86 +++++++++++++++++++ .../truffle/r/test/ExpectedTestOutput.test | 30 +++++++ .../builtins/TestBuiltin_ascharacter.java | 1 + .../r/test/builtins/TestBuiltin_asdouble.java | 1 + .../test/builtins/TestBuiltin_asinteger.java | 1 + .../test/builtins/TestBuiltin_aslogical.java | 1 + .../r/test/builtins/TestBuiltin_asraw.java | 1 + 12 files changed, 170 insertions(+), 9 deletions(-) create mode 100644 com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/opt/ReuseTemporaryNode.java diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsCharacter.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsCharacter.java index ece1e6e7b9..4fd255b84a 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsCharacter.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsCharacter.java @@ -31,9 +31,11 @@ import static com.oracle.truffle.r.runtime.RDispatch.INTERNAL_GENERIC; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; +import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.nodes.function.opt.ReuseTemporaryNode; import com.oracle.truffle.r.runtime.RDeparse; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.builtins.RBuiltin; @@ -48,6 +50,8 @@ public abstract class AsCharacter extends RBuiltinNode.Arg2 { private final ConditionProfile noAttributes = ConditionProfile.createBinaryProfile(); + @Child private ReuseTemporaryNode reuseTemporaryNode; + static { Casts casts = new Casts(AsCharacter.class); casts.arg("x").returnIf(missingValue().or(nullValue()), emptyStringVector()).mapIf(instanceOf(RAbstractListVector.class).not(), asStringVector()); @@ -58,7 +62,13 @@ public abstract class AsCharacter extends RBuiltinNode.Arg2 { if (noAttributes.profile(v.getAttributes() == null)) { return v; } else { - return (RAbstractStringVector) v.copyDropAttributes(); + if (reuseTemporaryNode == null) { + CompilerDirectives.transferToInterpreterAndInvalidate(); + reuseTemporaryNode = insert(ReuseTemporaryNode.create()); + } + RAbstractStringVector res = (RAbstractStringVector) reuseTemporaryNode.execute(v); + res.resetAllAttributes(true); + return res; } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsDouble.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsDouble.java index 2a372462c9..003429bba4 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsDouble.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsDouble.java @@ -32,7 +32,7 @@ import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; -import com.oracle.truffle.r.nodes.function.opt.ReuseNonSharedNode; +import com.oracle.truffle.r.nodes.function.opt.ReuseTemporaryNode; import com.oracle.truffle.r.runtime.RDispatch; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; @@ -43,7 +43,7 @@ public abstract class AsDouble extends RBuiltinNode.Arg2 { private final ConditionProfile noAttributes = ConditionProfile.createBinaryProfile(); - @Child protected ReuseNonSharedNode reuseNonShared; + @Child private ReuseTemporaryNode reuseTemporaryNode; static { Casts casts = new Casts(AsDouble.class); @@ -55,11 +55,11 @@ public abstract class AsDouble extends RBuiltinNode.Arg2 { if (noAttributes.profile(v.getAttributes() == null)) { return v; } else { - if (reuseNonShared == null) { + if (reuseTemporaryNode == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); - reuseNonShared = insert(ReuseNonSharedNode.create()); + reuseTemporaryNode = insert(ReuseTemporaryNode.create()); } - RAbstractDoubleVector res = (RAbstractDoubleVector) reuseNonShared.execute(v); + RAbstractDoubleVector res = (RAbstractDoubleVector) reuseTemporaryNode.execute(v); res.resetAllAttributes(true); return res; } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsInteger.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsInteger.java index bed3577395..51f426a46b 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsInteger.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsInteger.java @@ -29,9 +29,11 @@ import static com.oracle.truffle.r.runtime.RDispatch.INTERNAL_GENERIC; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; +import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.nodes.function.opt.ReuseTemporaryNode; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; @@ -41,6 +43,8 @@ public abstract class AsInteger extends RBuiltinNode.Arg2 { private final ConditionProfile noAttributes = ConditionProfile.createBinaryProfile(); + @Child private ReuseTemporaryNode reuseTemporaryNode; + static { Casts casts = new Casts(AsInteger.class); casts.arg("x").returnIf(missingValue().or(nullValue()), emptyIntegerVector()).asIntegerVector(); @@ -51,7 +55,13 @@ public abstract class AsInteger extends RBuiltinNode.Arg2 { if (noAttributes.profile(v.getAttributes() == null)) { return v; } else { - return (RAbstractIntVector) v.copyDropAttributes(); + if (reuseTemporaryNode == null) { + CompilerDirectives.transferToInterpreterAndInvalidate(); + reuseTemporaryNode = insert(ReuseTemporaryNode.create()); + } + RAbstractIntVector res = (RAbstractIntVector) reuseTemporaryNode.execute(v); + res.resetAllAttributes(true); + return res; } } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsLogical.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsLogical.java index 0932f15105..bfefbf78db 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsLogical.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsLogical.java @@ -29,9 +29,11 @@ import static com.oracle.truffle.r.runtime.RDispatch.INTERNAL_GENERIC; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; +import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.nodes.function.opt.ReuseTemporaryNode; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; @@ -41,6 +43,8 @@ public abstract class AsLogical extends RBuiltinNode.Arg2 { private final ConditionProfile noAttributes = ConditionProfile.createBinaryProfile(); + @Child private ReuseTemporaryNode reuseTemporaryNode; + static { Casts casts = new Casts(AsLogical.class); casts.arg("x").returnIf(missingValue().or(nullValue()), emptyLogicalVector()).asLogicalVector(); @@ -51,7 +55,13 @@ public abstract class AsLogical extends RBuiltinNode.Arg2 { if (noAttributes.profile(v.getAttributes() == null)) { return v; } else { - return (RAbstractLogicalVector) v.copyDropAttributes(); + if (reuseTemporaryNode == null) { + CompilerDirectives.transferToInterpreterAndInvalidate(); + reuseTemporaryNode = insert(ReuseTemporaryNode.create()); + } + RAbstractLogicalVector res = (RAbstractLogicalVector) reuseTemporaryNode.execute(v); + res.resetAllAttributes(true); + return res; } } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsRaw.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsRaw.java index e430bfc593..363b8b2e9e 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsRaw.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsRaw.java @@ -27,9 +27,11 @@ import static com.oracle.truffle.r.runtime.RDispatch.INTERNAL_GENERIC; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; +import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.nodes.function.opt.ReuseTemporaryNode; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RDataFactory; @@ -41,6 +43,8 @@ public abstract class AsRaw extends RBuiltinNode.Arg1 { private final ConditionProfile noAttributes = ConditionProfile.createBinaryProfile(); + @Child private ReuseTemporaryNode reuseTemporaryNode; + static { Casts casts = new Casts(AsRaw.class); casts.arg("x").mustBe(missingValue().not(), RError.Message.ARGUMENTS_PASSED, 0, "'as.raw'", 1).asRawVector(); @@ -56,7 +60,13 @@ public abstract class AsRaw extends RBuiltinNode.Arg1 { if (noAttributes.profile(v.getAttributes() == null)) { return v; } else { - return (RAbstractRawVector) v.copyDropAttributes(); + if (reuseTemporaryNode == null) { + CompilerDirectives.transferToInterpreterAndInvalidate(); + reuseTemporaryNode = insert(ReuseTemporaryNode.create()); + } + RAbstractRawVector res = (RAbstractRawVector) reuseTemporaryNode.execute(v); + res.resetAllAttributes(true); + return res; } } } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/opt/ReuseTemporaryNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/opt/ReuseTemporaryNode.java new file mode 100644 index 0000000000..ff7a98dceb --- /dev/null +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/opt/ReuseTemporaryNode.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.r.nodes.function.opt; + +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.Fallback; +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.nodes.Node; +import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.r.runtime.data.RShareable; +import com.oracle.truffle.r.runtime.data.RSharingAttributeStorage; +import com.oracle.truffle.r.runtime.data.RVector; +import com.oracle.truffle.r.runtime.data.model.RAbstractVector; + +public abstract class ReuseTemporaryNode extends Node { + + protected static final int LIMIT = 5; + + public static ReuseTemporaryNode create() { + return ReuseTemporaryNodeGen.create(); + } + + public abstract RVector<?> execute(RAbstractVector value); + + @Specialization(limit = "LIMIT", guards = "value.getClass() == valueClass") + protected RVector<?> reuseNonShareable(RAbstractVector value, + @Cached("value.getClass()") Class<? extends RAbstractVector> valueClass, + @Cached("createBinaryProfile()") ConditionProfile isNotTemporaryProfile) { + RAbstractVector profiledValue = valueClass.cast(value); + if (RShareable.class.isAssignableFrom(valueClass)) { + RShareable shareable = (RShareable) profiledValue; + if (isNotTemporaryProfile.profile(!shareable.isTemporary())) { + RShareable res = shareable.copy(); + assert res.isTemporary(); + return (RVector<?>) res; + } else { + return (RVector<?>) profiledValue; + } + } else { + RVector<?> res = profiledValue.materialize(); + assert res.isTemporary(); + return res; + } + } + + @Fallback + @TruffleBoundary + public static RVector<?> reuseSlow(RAbstractVector value) { + RSharingAttributeStorage.verify(value); + if (value instanceof RSharingAttributeStorage) { + RShareable shareable = (RShareable) value; + if (!shareable.isTemporary()) { + RShareable res = shareable.copy(); + assert res.isTemporary(); + return (RVector<?>) res; + } else { + return (RVector<?>) value; + } + } else { + RVector<?> res = value.materialize(); + assert res.isTemporary(); + return res; + } + } +} diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index d33d3e838a..48d190f60b 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -5885,6 +5885,12 @@ character(0) ##com.oracle.truffle.r.test.builtins.TestBuiltin_ascharacter.testAsCharacter# #{ x<-as.character(Sys.time()) } +##com.oracle.truffle.r.test.builtins.TestBuiltin_ascharacter.testAsCharacter# +#{ y <- c('a', 'b'); attr(y, 'someAttr') <- 'someValue'; x <- as.character(y); x[[1]] <- '42'; y } +[1] "a" "b" +attr(,"someAttr") +[1] "someValue" + ##com.oracle.truffle.r.test.builtins.TestBuiltin_ascharacter.testascharacter1# #argv <- list('bessel_y(2,nu=181.2): precision lost in result');as.character(argv[[1]]); [1] "bessel_y(2,nu=181.2): precision lost in result" @@ -6427,6 +6433,12 @@ NULL #{ x<-c(a=1L, b=2L); dim(x)<-c(1,2); attr(x, "foo")<-"foo"; y<-as.double(x); attributes(y) } NULL +##com.oracle.truffle.r.test.builtins.TestBuiltin_asdouble.testAsDouble# +#{ y <- c(3.1, 3.2); attr(y, 'someAttr') <- 'someValue'; x <- as.double(y); x[[1]] <- 42; y } +[1] 3.1 3.2 +attr(,"someAttr") +[1] "someValue" + ##com.oracle.truffle.r.test.builtins.TestBuiltin_asdouble.testasdouble1# #argv <- list(c(3.14159265358979, 3.14159265358981, 3.14159265358981, 3.14159265358981, 3.14159265358978, 3.1415926535898, 3.1415926535898, 3.14159265358978, 3.14159265358981, 3.14159265358979, 3.14159265358979, 3.14159265358978, 3.14159265358979, 3.14159265358981, 3.1415926535898, 3.14159265358978, 3.14159265358978, 3.14159265358978, 3.14159265358978, 3.14159265358981, 3.14159265358981, 3.14159265358978, 3.14159265358979, 3.14159265358978, 3.14159265358978, 3.14159265358978, 3.1415926535898, 3.14159265358977, 3.14159265358979, 3.14159265358979, 3.1415926535898, 3.14159265358979, 3.1415926535898, 3.14159265358979, 3.14159265358979, 3.14159265358981, 3.14159265358978, 3.1415926535898, 3.14159265358979, 3.14159265358981, 3.1415926535898, 3.14159265358981, 3.14159265358978, 3.1415926535898, 3.14159265358981, 3.1415926535898, 3.14159265358978, 3.14159265358979, 3.14159265358978, 3.14159265358979, 3.1415926535898, 3.14159265358981, 3.14159265358978, 3.1415926535898, 3.14159265358979, 3.1415926535898, 3.14159265358978, 3.1415926535898, 3.14159265358978, 3.14159265358979, 3.1415926535898, 3.14159265358978, 3.1415926535898, 3.14159265358981, 3.14159265358977, 3.14159265358981, 3.14159265358978, 3.14159265358978, 3.14159265358981, 3.14159265358979, 3.14159265358977, 3.14159265358978, 3.14159265358981, 3.14159265358979, 3.14159265358981, 3.1415926535898, 3.14159265358979, 3.14159265358979, 3.1415926535898, 3.14159265358979, 3.14159265358981, 3.14159265358979, 3.14159265358979, 3.14159265358981, 3.14159265358977, 3.1415926535898, 3.14159265358979, 3.1415926535898, 3.14159265358979, 3.1415926535898, 3.1415926535898, 3.1415926535898, 3.14159265358978, 3.1415926535898, 3.1415926535898, 3.1415926535898, 3.14159265358981, 3.14159265358979, 3.14159265358978, 3.14159265358981, 3.14159265358981));as.double(argv[[1]]); [1] 3.141593 3.141593 3.141593 3.141593 3.141593 3.141593 3.141593 3.141593 @@ -6968,6 +6980,12 @@ NULL #{ x<-c(a=1L, b=2L); dim(x)<-c(1,2); attr(x, "foo")<-"foo"; y<-as.integer(x); attributes(y) } NULL +##com.oracle.truffle.r.test.builtins.TestBuiltin_asinteger.testAsInteger# +#{ y <- c(3L, 4L); attr(y, 'someAttr') <- 'someValue'; x <- as.integer(y); x[[1]] <- 42L; y } +[1] 3 4 +attr(,"someAttr") +[1] "someValue" + ##com.oracle.truffle.r.test.builtins.TestBuiltin_asinteger.testasinteger1# #argv <- list(structure(c(4L, 5L, 3L, 2L, 2L, 1L, 6L), .Label = c('McNeil', 'Ripley', 'Tierney', 'Tukey', 'Venables', 'R Core'), class = 'factor'));as.integer(argv[[1]]); [1] 4 5 3 2 2 1 6 @@ -7141,6 +7159,12 @@ NULL #{ x<-c(a=1L, b=2L); dim(x)<-c(1,2); attr(x, "foo")<-"foo"; y<-as.logical(x); attributes(y) } NULL +##com.oracle.truffle.r.test.builtins.TestBuiltin_aslogical.testAsLogical# +#{ y <- c(T, F); attr(y, 'someAttr') <- 'someValue'; x <- as.logical(y); x[[1]] <- F; y } +[1] TRUE FALSE +attr(,"someAttr") +[1] "someValue" + ##com.oracle.truffle.r.test.builtins.TestBuiltin_aslogical.testaslogical1# #argv <- list(structure(c(0L, 0L, 0L, 1L), .Names = c('Y', 'B', 'V', 'N')));as.logical(argv[[1]]); [1] FALSE FALSE FALSE TRUE @@ -7583,6 +7607,12 @@ out-of-range values treated as 0 in coercion to raw #{ as.raw.cls <- function(x) 42; as.raw(structure(c(1,2), class='cls')); } [1] 42 +##com.oracle.truffle.r.test.builtins.TestBuiltin_asraw.testAsRaw# +#{ y <- as.raw(c(5L, 6L)); attr(y, 'someAttr') <- 'someValue'; x <- as.raw(y); x[[1]] <- as.raw(42); y } +[1] 05 06 +attr(,"someAttr") +[1] "someValue" + ##com.oracle.truffle.r.test.builtins.TestBuiltin_asraw.testasraw1# #argv <- list(structure(numeric(0), .Dim = c(0L, 0L)));as.raw(argv[[1]]); raw(0) diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ascharacter.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ascharacter.java index 52ee6cfe6c..37728abb37 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ascharacter.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ascharacter.java @@ -268,5 +268,6 @@ public class TestBuiltin_ascharacter extends TestBase { assertEval("{ f1<-function() 7; f2<-function(x) { sys.call() }; as.character(f2(f1())) }"); assertEval("{ f1<-function(x) 7; f2<-function(y) { sys.call() }; as.character(f2(f1(42))) }"); assertEval("{ as.character.cls <- function(x) 42; as.character(structure(c(1,2), class='cls')); }"); + assertEval("{ y <- c('a', 'b'); attr(y, 'someAttr') <- 'someValue'; x <- as.character(y); x[[1]] <- '42'; y }"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asdouble.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asdouble.java index a8bf3d2060..f19ec33a69 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asdouble.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asdouble.java @@ -186,5 +186,6 @@ public class TestBuiltin_asdouble extends TestBase { assertEval("{ x<-c(a=1L, b=2L); dim(x)<-c(1,2); attr(x, \"foo\")<-\"foo\"; y<-as.double(x); attributes(y) }"); assertEval("{ as.double(NULL) }"); assertEval("{ as.double.cls <- function(x) 42; as.double(structure(c(1,2), class='cls')); }"); + assertEval("{ y <- c(3.1, 3.2); attr(y, 'someAttr') <- 'someValue'; x <- as.double(y); x[[1]] <- 42; y }"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asinteger.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asinteger.java index a50e12c6b8..4acacea766 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asinteger.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asinteger.java @@ -148,5 +148,6 @@ public class TestBuiltin_asinteger extends TestBase { assertEval("{ as.integer(\"1\", as.character(NA)) }"); assertEval("{ as.integer.cls <- function(x) 42; as.integer(structure(c(1,2), class='cls')); }"); assertEval("{ as.integer(c(100, -1e-13, Inf, -Inf, NaN, 3.14159265358979, NA)) }"); + assertEval("{ y <- c(3L, 4L); attr(y, 'someAttr') <- 'someValue'; x <- as.integer(y); x[[1]] <- 42L; y }"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_aslogical.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_aslogical.java index 528771ad78..dc2291bb96 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_aslogical.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_aslogical.java @@ -100,5 +100,6 @@ public class TestBuiltin_aslogical extends TestBase { assertEval("{ as.logical(c(3+3i, 4+4i)) }"); assertEval("{ as.logical(NULL) }"); assertEval("{ as.logical.cls <- function(x) 42; as.logical(structure(c(1,2), class='cls')); }"); + assertEval("{ y <- c(T, F); attr(y, 'someAttr') <- 'someValue'; x <- as.logical(y); x[[1]] <- F; y }"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asraw.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asraw.java index 6432d859ef..2b4247bda5 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asraw.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asraw.java @@ -72,5 +72,6 @@ public class TestBuiltin_asraw extends TestBase { assertEval(Output.IgnoreWarningContext, "{ as.raw(c(1L, -2L, NA)) }"); assertEval(Output.IgnoreWarningContext, "{ as.raw('10000001') }"); assertEval(Output.IgnoreWarningContext, "{ as.raw(c('10000001', '42')) }"); + assertEval("{ y <- as.raw(c(5L, 6L)); attr(y, 'someAttr') <- 'someValue'; x <- as.raw(y); x[[1]] <- as.raw(42); y }"); } } -- GitLab