Skip to content

Commit dc156c4

Browse files
Miloslav Metelkaansalond
authored andcommitted
Remove usages of deprecated Truffle API (truffle rev. 8eb52e74643).
(cherry picked from commit 4cd0ad3)
1 parent 2eeb883 commit dc156c4

File tree

10 files changed

+47
-46
lines changed

10 files changed

+47
-46
lines changed

com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ private EngineRootNode createRScriptRoot(Source fullSource, MaterializedFrame fr
387387
break;
388388
}
389389
sb.append(input);
390-
Source src = Source.newBuilder(sb.toString()).language(RRuntime.R_LANGUAGE_ID).name(file + "#" + startLine + "-" + lineIndex).uri(uri).build();
390+
Source src = Source.newBuilder(RRuntime.R_LANGUAGE_ID, sb.toString(), file + "#" + startLine + "-" + lineIndex).uri(uri).build();
391391
lineIndex++;
392392
List<RSyntaxNode> currentStmts = null;
393393
try {

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_DLL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ private static CallTarget parseBinary(String libName, LLVM_IR.Binary ir) {
378378
long start = System.nanoTime();
379379
RContext context = RContext.getInstance();
380380
long nanos = 1000 * 1000 * 1000;
381-
Source source = Source.newBuilder(ir.base64).name(ir.name).mimeType("application/x-llvm-ir-bitcode-base64").build();
381+
Source source = Source.newBuilder("", ir.base64, ir.name).mimeType("application/x-llvm-ir-bitcode-base64").build();
382382
CallTarget result = context.getEnv().parse(source);
383383
if (System.getenv("LLVM_PARSE_TIME") != null) {
384384
long end = System.nanoTime();

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public ContextState initialize(RContext context) {
309309
// new thread, initialize properly
310310
assert defaultLibrary == null && rlibDLLInfo == null;
311311
rlibDLLInfo = DLL.findLibraryContainingSymbol(context, "dot_call0");
312-
defaultLibrary = (TruffleObject) RContext.getInstance().getEnv().parse(Source.newBuilder("default").name("(load default)").language("native").build()).call();
312+
defaultLibrary = (TruffleObject) RContext.getInstance().getEnv().parse(Source.newBuilder("native", "default", "(load default)").build()).call();
313313
initCallbacks(context);
314314
break;
315315
case SHARE_PARENT_RO:

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_DLL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private static class TruffleNFI_DLOpenNode extends Node implements DLLRFFI.DLOpe
5757
public Object execute(String path, boolean local, boolean now) {
5858
String libName = DLL.libName(path);
5959
Env env = RContext.getInstance().getEnv();
60-
TruffleObject libHandle = (TruffleObject) env.parse(Source.newBuilder(prepareLibraryOpen(path, local, now)).name(path).language("native").build()).call();
60+
TruffleObject libHandle = (TruffleObject) env.parse(Source.newBuilder("native", prepareLibraryOpen(path, local, now), path).build()).call();
6161
return new NFIHandle(libName, libHandle);
6262
}
6363
}

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,12 @@ private static Source createSource(Object srcFile, String coalescedLines) {
217217
assert result != null : "Source created from environment should not be null";
218218
return result;
219219
} else {
220-
return Source.newBuilder(coalescedLines).name("<parse>").language(RRuntime.R_LANGUAGE_ID).build();
220+
return Source.newBuilder(RRuntime.R_LANGUAGE_ID, coalescedLines, "<parse>").build();
221221
}
222222
} else {
223223
String srcFileText = RRuntime.asString(srcFile);
224224
if (srcFileText.equals("<text>")) {
225-
return Source.newBuilder(coalescedLines).name("<parse>").language(RRuntime.R_LANGUAGE_ID).build();
225+
return Source.newBuilder(RRuntime.R_LANGUAGE_ID, coalescedLines, "<parse>").build();
226226
} else {
227227
return createFileSource(ConnectionSupport.removeFileURLPrefix(srcFileText), coalescedLines, false);
228228
}
@@ -241,11 +241,7 @@ private static Source createFileSource(String path, String chars, boolean intern
241241
return RSource.fromFileName(chars, path, internal);
242242
} catch (URISyntaxException e) {
243243
// Note: to be compatible with GnuR we construct Source even with a malformed path
244-
Source.Builder<RuntimeException, RuntimeException, RuntimeException> builder = Source.newBuilder(chars).name(path).language(RRuntime.R_LANGUAGE_ID);
245-
if (internal) {
246-
builder.internal();
247-
}
248-
return builder.build();
244+
return Source.newBuilder(RRuntime.R_LANGUAGE_ID, chars, path).internal(internal).build();
249245
}
250246
}
251247

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRInterop.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
import com.oracle.truffle.api.profiles.BranchProfile;
6363
import com.oracle.truffle.api.profiles.ConditionProfile;
6464
import com.oracle.truffle.api.source.Source;
65-
import com.oracle.truffle.api.source.Source.Builder;
65+
import com.oracle.truffle.api.source.Source.SourceBuilder;
6666
import com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef;
6767
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.instanceOf;
6868
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.logicalValue;
@@ -206,17 +206,19 @@ private Object parseFileAndCall(String path, String languageId) {
206206
return parseFile(path, languageId).call();
207207
}
208208

209-
protected CallTarget parseFile(String path, String languageId) {
209+
protected CallTarget parseFile(String path, String languageIdArg) {
210210
CompilerAsserts.neverPartOfCompilation();
211211

212212
File file = new File(path);
213213
try {
214-
Builder<IOException, RuntimeException, RuntimeException> sourceBuilder = Source.newBuilder(file).name(file.getName());
215-
if (languageId != null) {
216-
sourceBuilder.language(languageId);
214+
String languageId = languageIdArg;
215+
if (languageId == null) { // null languageId not allowed in newBuilder()
216+
languageId = RRuntime.R_LANGUAGE_ID;
217217
}
218+
Env env = RContext.getInstance().getEnv();
219+
SourceBuilder sourceBuilder = Source.newBuilder(languageId, env.getTruffleFile(file.getAbsolutePath())).name(file.getName());
218220
Source sourceObject = sourceBuilder.build();
219-
return RContext.getInstance().getEnv().parse(sourceObject);
221+
return env.parse(sourceObject);
220222
} catch (IOException e) {
221223
throw error(RError.Message.GENERIC, "Error reading file: " + e.getMessage());
222224
} catch (Throwable t) {

com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/test/SpecialCallTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ private static void assertCallCounts(String setup, String test, int initialSpeci
287287
if (!FastROptions.UseSpecials.getBooleanValue()) {
288288
return;
289289
}
290-
Source setupSource = Source.newBuilder("{" + setup + "}").language(RRuntime.R_LANGUAGE_ID).name("test").build();
291-
Source testSource = Source.newBuilder(test).language(RRuntime.R_LANGUAGE_ID).name("test").build();
290+
Source setupSource = Source.newBuilder(RRuntime.R_LANGUAGE_ID, "{" + setup + "}", "test").build();
291+
Source testSource = Source.newBuilder(RRuntime.R_LANGUAGE_ID, test, "test").build();
292292

293293
RExpression setupExpression = testVMContext.getThisEngine().parse(setupSource);
294294
RExpression testExpression = testVMContext.getThisEngine().parse(testSource);

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSource.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import java.util.WeakHashMap;
3535

3636
import com.oracle.truffle.api.CompilerAsserts;
37+
import com.oracle.truffle.api.TruffleFile;
38+
import com.oracle.truffle.api.TruffleLanguage.Env;
3739
import com.oracle.truffle.api.source.Source;
3840
import com.oracle.truffle.api.source.SourceSection;
3941
import com.oracle.truffle.r.runtime.RSrcref.SrcrefFields;
@@ -110,18 +112,14 @@ public enum Internal {
110112
public static Source fromFileName(String text, String path, boolean internal) throws URISyntaxException {
111113
File file = new File(path).getAbsoluteFile();
112114
URI uri = new URI("file://" + file.getAbsolutePath());
113-
Source.Builder<RuntimeException, RuntimeException, RuntimeException> builder = Source.newBuilder(file).content(text).uri(uri).language(RRuntime.R_LANGUAGE_ID);
114-
if (internal) {
115-
builder.internal();
116-
}
117-
return builder.build();
115+
return Source.newBuilder(RRuntime.R_LANGUAGE_ID, text, path).content(text).uri(uri).internal(internal).build();
118116
}
119117

120118
/**
121119
* Create a cached source from {@code text} and {@code name}.
122120
*/
123121
public static Source fromText(String text, String name) {
124-
return getCachedByOrigin(text, origin -> Source.newBuilder(text).name(name).language(RRuntime.R_LANGUAGE_ID).build());
122+
return getCachedByOrigin(text, origin -> Source.newBuilder(RRuntime.R_LANGUAGE_ID, text, name).build());
125123
}
126124

127125
/**
@@ -144,7 +142,7 @@ public static Source fromTextInternalInvisible(String text, Internal description
144142
*/
145143

146144
public static Source fromTextInternal(String text, Internal description, String languageId) {
147-
return Source.newBuilder(text).name(description.string).language(languageId).internal().interactive().build();
145+
return Source.newBuilder(languageId, text, description.string).internal(true).interactive(true).build();
148146
}
149147

150148
/**
@@ -153,7 +151,7 @@ public static Source fromTextInternal(String text, Internal description, String
153151
*/
154152

155153
public static Source fromTextInternalInvisible(String text, Internal description, String languageId) {
156-
return Source.newBuilder(text).name(description.string).language(languageId).internal().build();
154+
return Source.newBuilder(languageId, text, description.string).internal(true).build();
157155
}
158156

159157
/**
@@ -162,7 +160,7 @@ public static Source fromTextInternalInvisible(String text, Internal description
162160
*/
163161
public static Source fromPackageTextInternal(String text, String packageName) {
164162
String name = String.format(Internal.PACKAGE.string, packageName);
165-
return Source.newBuilder(text).name(name).language(RRuntime.R_LANGUAGE_ID).build();
163+
return Source.newBuilder(RRuntime.R_LANGUAGE_ID, text, name).build();
166164
}
167165

168166
/**
@@ -174,7 +172,7 @@ public static Source fromPackageTextInternalWithName(String text, String package
174172
if (functionName == null) {
175173
return fromPackageTextInternal(text, packageName);
176174
} else {
177-
return Source.newBuilder(text).name(packageName + "::" + functionName).language(RRuntime.R_LANGUAGE_ID).build();
175+
return Source.newBuilder(RRuntime.R_LANGUAGE_ID, text, packageName + "::" + functionName).build();
178176
}
179177
}
180178

@@ -184,33 +182,39 @@ public static Source fromPackageTextInternalWithName(String text, String package
184182
public static Source fromFileName(String path, boolean internal) throws IOException {
185183
File file = new File(path);
186184
return getCachedByOrigin(file, origin -> {
187-
Source.Builder<IOException, RuntimeException, RuntimeException> builder = Source.newBuilder(file).language(RRuntime.R_LANGUAGE_ID);
188-
if (internal) {
189-
builder.internal();
190-
}
191-
return builder.build();
185+
Env env = RContext.getInstance().getEnv();
186+
TruffleFile tFile = env.getTruffleFile(file.getAbsolutePath());
187+
return Source.newBuilder(RRuntime.R_LANGUAGE_ID, tFile).internal(internal).build();
192188
});
193189
}
194190

195191
/**
196192
* Create an (external) source from the file system path denoted by {@code file}.
197193
*/
198194
public static Source fromFile(File file) throws IOException {
199-
return getCachedByOrigin(file, origin -> Source.newBuilder(file).name(file.getName()).language(RRuntime.R_LANGUAGE_ID).build());
195+
return getCachedByOrigin(file, origin -> {
196+
Env env = RContext.getInstance().getEnv();
197+
TruffleFile tFile = env.getTruffleFile(file.getAbsolutePath());
198+
return Source.newBuilder(RRuntime.R_LANGUAGE_ID, tFile).name(file.getName()).build();
199+
});
200200
}
201201

202202
/**
203203
* Create a source from the file system path denoted by {@code file}.
204204
*/
205205
public static Source fromTempFile(File file) throws IOException {
206-
return getCachedByOrigin(file, origin -> Source.newBuilder(file).name(file.getName()).language(RRuntime.R_LANGUAGE_ID).internal().build());
206+
return getCachedByOrigin(file, origin -> {
207+
Env env = RContext.getInstance().getEnv();
208+
TruffleFile tFile = env.getTruffleFile(file.getAbsolutePath());
209+
return Source.newBuilder(RRuntime.R_LANGUAGE_ID, tFile).name(file.getName()).internal(true).build();
210+
});
207211
}
208212

209213
/**
210214
* Create an (external) source from {@code url}.
211215
*/
212216
public static Source fromURL(URL url, String name) throws IOException {
213-
return getCachedByOrigin(url, origin -> Source.newBuilder(url).name(name).language(RRuntime.R_LANGUAGE_ID).build());
217+
return getCachedByOrigin(url, origin -> Source.newBuilder(RRuntime.R_LANGUAGE_ID, url).name(name).build());
214218
}
215219

216220
/**
@@ -248,7 +252,7 @@ private static String getPath(REnvironment env, String name) {
248252
* Create an unknown source with the given name.
249253
*/
250254
public static SourceSection createUnknown(String name) {
251-
return Source.newBuilder("").name(name).language(RRuntime.R_LANGUAGE_ID).build().createSection(0, 0);
255+
return Source.newBuilder(RRuntime.R_LANGUAGE_ID, "", name).build().createSection(0, 0);
252256
}
253257

254258
/**

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
*/
2323
package com.oracle.truffle.r.runtime.context;
2424

25-
import java.beans.PropertyChangeEvent;
26-
import java.beans.PropertyChangeListener;
2725
import java.io.IOException;
2826
import java.io.InputStream;
2927
import java.io.OutputStream;
@@ -45,6 +43,7 @@
4543
import java.util.concurrent.ConcurrentHashMap;
4644
import java.util.concurrent.Executor;
4745
import java.util.concurrent.Executors;
46+
import java.util.function.Consumer;
4847
import java.util.function.Supplier;
4948

5049
import com.oracle.truffle.api.Assumption;
@@ -460,7 +459,7 @@ private RContext(TruffleRLanguage language, Env env, Instrumenter instrumenter,
460459
state.add(State.CONSTRUCTED);
461460

462461
this.allocationReporter = env.lookup(AllocationReporter.class);
463-
this.allocationReporter.addPropertyChangeListener(ALLOCATION_ACTIVATION_LISTENER);
462+
this.allocationReporter.addActiveListener(ALLOCATION_ACTIVATION_LISTENER);
464463
RDataFactory.setAllocationTracingEnabled(allocationReporter.isActive());
465464
}
466465

@@ -610,7 +609,7 @@ public synchronized void dispose() {
610609

611610
assert !initial || EvalThread.threadCnt.get() == 0 : "Did not close all children contexts";
612611

613-
this.allocationReporter.removePropertyChangeListener(ALLOCATION_ACTIVATION_LISTENER);
612+
this.allocationReporter.removeActiveListener(ALLOCATION_ACTIVATION_LISTENER);
614613
}
615614
}
616615

@@ -836,10 +835,10 @@ public AllocationReporter getAllocationReporter() {
836835
return this.allocationReporter;
837836
}
838837

839-
private static final PropertyChangeListener ALLOCATION_ACTIVATION_LISTENER = new PropertyChangeListener() {
838+
private static final Consumer<Boolean> ALLOCATION_ACTIVATION_LISTENER = new Consumer<Boolean>() {
840839
@Override
841-
public void propertyChange(PropertyChangeEvent event) {
842-
RDataFactory.setAllocationTracingEnabled(event.getNewValue() == Boolean.TRUE);
840+
public void accept(Boolean active) {
841+
RDataFactory.setAllocationTracingEnabled(active);
843842
}
844843
};
845844

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/instrument/memprof/MemAllocProfilerPaths.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public void set(long allocated, long count) {
238238
this.id = paths.idGen.getAndIncrement();
239239
this.parent = parent;
240240
this.name = name;
241-
this.sourceSection = sourceSection == null ? Source.newBuilder("").name(name).mimeType("").build().createUnavailableSection() : sourceSection;
241+
this.sourceSection = sourceSection == null ? Source.newBuilder("", "", name).mimeType("").build().createUnavailableSection() : sourceSection;
242242
this.paths.entryMap.put(id, this);
243243
if (parent != null) {
244244
parent.children.put(this.sourceSection, this);

0 commit comments

Comments
 (0)