Skip to content

Commit 7ea0e17

Browse files
author
Pavel Marek
committed
[GR-30714] [GR-38806] Get rid of interpreter-only warning.
PullRequest: fastr/2680
2 parents 3292ea9 + 465bf3e commit 7ea0e17

File tree

15 files changed

+1567
-1240
lines changed

15 files changed

+1567
-1240
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ overlay : '1c0e7b71c8d6a180de84d711b558db84f7253852' }
1+
{ overlay : '5eba2d1cff5b42403dee3128c8450e395817a2ae' }

com.oracle.truffle.r.native/run/R.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ else
4646
mx=`which mx`
4747
fi
4848

49-
exec $mx -J-Dpolyglot.engine.WarnInterpreterOnly=false --no-warning --primary-suite-path $PRIMARY_PATH $MX_R_GLOBAL_ARGS R $FASTR_INTERNAL_ARGS $MX_R_CMD_ARGS "$@"
49+
exec $mx --no-warning --primary-suite-path $PRIMARY_PATH $MX_R_GLOBAL_ARGS R $FASTR_INTERNAL_ARGS $MX_R_CMD_ARGS "$@"

com.oracle.truffle.r.native/run/Rscript_exec.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ else
4444
mx=`which mx`
4545
fi
4646

47-
exec $mx -J-Dpolyglot.engine.WarnInterpreterOnly=false --no-warning --primary-suite-path $PRIMARY_PATH $MX_R_GLOBAL_ARGS Rscript $FASTR_INTERNAL_ARGS $MX_R_CMD_ARGS "$@"
47+
exec $mx --no-warning --primary-suite-path $PRIMARY_PATH $MX_R_GLOBAL_ARGS Rscript $FASTR_INTERNAL_ARGS $MX_R_CMD_ARGS "$@"

com.oracle.truffle.r.test.packages/pkgtest/__init__.py

Lines changed: 199 additions & 135 deletions
Large diffs are not rendered by default.

com.oracle.truffle.r.test.packages/pkgtest/fuzzy_compare.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222
#
2323

2424
import logging
25+
from typing import List, Optional, Tuple, Set
2526

26-
def fuzzy_compare(gnur_content, fastr_content, gnur_filename, fastr_filename, custom_filters=None, dump_preprocessed=False):
27+
from pkgtest.output_filter import ContentFilter
28+
29+
30+
def fuzzy_compare(gnur_content: List[str], fastr_content: List[str], gnur_filename: str, fastr_filename: str,
31+
custom_filters: List[ContentFilter]=(), dump_preprocessed=False) -> Tuple[int, int, int]:
2732
"""
2833
Compares the test output of GnuR and FastR by ignoring implementation-specific differences like header, error,
2934
and warning messages.
@@ -33,8 +38,8 @@ def fuzzy_compare(gnur_content, fastr_content, gnur_filename, fastr_filename, cu
3338
output, respectively.
3439
"""
3540
logging.debug("Using custom filters:\n" + str(custom_filters))
36-
gnur_content = _preprocess_content(gnur_content, custom_filters)
37-
fastr_content = _preprocess_content(fastr_content, custom_filters)
41+
gnur_content: List[str] = _preprocess_content(gnur_content, custom_filters)
42+
fastr_content: List[str] = _preprocess_content(fastr_content, custom_filters)
3843
if dump_preprocessed:
3944
with open(gnur_filename + '.preprocessed', 'w') as f:
4045
f.writelines(gnur_content)
@@ -58,8 +63,8 @@ def fuzzy_compare(gnur_content, fastr_content, gnur_filename, fastr_filename, cu
5863
overall_result = 0
5964
# the local result, i.e., for the current statement
6065
result = 0
61-
statements_passed = set()
62-
statements_failed = set()
66+
statements_passed: Set[int] = set()
67+
statements_failed: Set[int] = set()
6368

6469
# the first line must start with the prompt, so capture it
6570
gnur_prompt = _capture_prompt(gnur_content, gnur_i)
@@ -82,7 +87,7 @@ def fuzzy_compare(gnur_content, fastr_content, gnur_filename, fastr_filename, cu
8287
sync = False
8388
if gnur_line != fastr_line:
8489
if fastr_line.startswith('Warning') and 'FastR does not support graphics package' in fastr_content[
85-
fastr_i + 1]:
90+
fastr_i + 1]:
8691
# ignore warning about FastR not supporting the graphics package
8792
fastr_i = fastr_i + 2
8893
if fastr_content[fastr_i].startswith('NULL') and not gnur_line.startswith('NULL'):
@@ -189,7 +194,7 @@ def fuzzy_compare(gnur_content, fastr_content, gnur_filename, fastr_filename, cu
189194
return overall_result, len(statements_passed), len(statements_failed)
190195

191196

192-
def _get_next_line(prompt, content, content_len, line_idx):
197+
def _get_next_line(prompt: Optional[str], content: List[str], content_len: int, line_idx: int) -> Tuple[Optional[str], int]:
193198
i = line_idx
194199
while i < content_len:
195200
line = content[i]
@@ -202,20 +207,21 @@ def _get_next_line(prompt, content, content_len, line_idx):
202207
return None, i
203208

204209

205-
def _ignore_whitespace(gnur_line, fastr_line):
210+
def _ignore_whitespace(gnur_line: str, fastr_line: str) -> bool:
206211
translate_table = {ord(' '): None, ord('\t'): None}
207212
return gnur_line.translate(translate_table) == fastr_line.translate(translate_table)
208213

209214

210-
def _capture_prompt(lines, idx):
215+
def _capture_prompt(lines: List[str], idx: int) -> Optional[str]:
211216
# The prompt can be anything, so it is hard to determine it in general.
212217
# We will therefore just consider the default prompt.
213218
default_prompt = "> "
214219
if idx < len(lines) and lines[idx].startswith(default_prompt):
215220
return default_prompt
216221
return None
217222

218-
def _find_start(content):
223+
224+
def _find_start(content: List[str]) -> Optional[int]:
219225
marker = "Type 'q()' to quit R."
220226
for i in range(len(content)):
221227
line = content[i]
@@ -230,7 +236,7 @@ def _find_start(content):
230236
return None
231237

232238

233-
def _find_end(content):
239+
def _find_end(content: List[str]) -> int:
234240
marker = "Time elapsed:"
235241
for i in range(len(content)):
236242
line = content[i]
@@ -240,7 +246,7 @@ def _find_end(content):
240246
return len(content)
241247

242248

243-
def _find_line(gnur_line, fastr_content, fastr_i):
249+
def _find_line(gnur_line: str, fastr_content: List[str], fastr_i: int) -> int:
244250
'''
245251
Search forward in fastr_content from fastr_i searching for a match with gnur_line.
246252
Do not match empty lines!
@@ -254,14 +260,13 @@ def _find_line(gnur_line, fastr_content, fastr_i):
254260
fastr_i = fastr_i + 1
255261
return -1
256262

257-
def _is_ignored_function(fun_name, gnur_content, gnur_stmt, fastr_content, fastr_stmt):
263+
264+
def _is_ignored_function(fun_name: str, gnur_content: List[str], gnur_stmt: int, fastr_content: List[str], fastr_stmt: int) -> bool:
258265
return gnur_stmt != -1 and fun_name in gnur_content[gnur_stmt] and fastr_stmt != -1 and fun_name in fastr_content[
259266
fastr_stmt]
260267

261268

262-
263-
264-
def _is_statement_begin(captured_prompt, line):
269+
def _is_statement_begin(captured_prompt: Optional[str], line: Optional[str]) -> bool:
265270
if captured_prompt is None:
266271
return False
267272
if line is not None:
@@ -270,7 +275,7 @@ def _is_statement_begin(captured_prompt, line):
270275
return False
271276

272277

273-
def _preprocess_content(output, custom_filters):
278+
def _preprocess_content(output: List[str], custom_filters: List[ContentFilter]) -> List[str]:
274279
# load file with replacement actions
275280
if custom_filters:
276281
for f in custom_filters:

com.oracle.truffle.r.test.packages/pkgtest/output_filter.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import re
2525
import logging
26+
from typing import List, Callable
2627

2728

2829
class ContentFilter:
@@ -33,15 +34,15 @@ class ContentFilter:
3334
remove_before = 0
3435
remove_after = 0
3536

36-
def __init__(self, pkg_pattern, action, args, remove_before=0, remove_after=0):
37+
def __init__(self, pkg_pattern: str, action: str, args: List[str], remove_before=0, remove_after=0):
3738
self.pkg_pattern = pkg_pattern
3839
self.pkg_prog = re.compile(pkg_pattern)
3940
self.action = action
4041
self.args = args
4142
self.remove_before = remove_before
4243
self.remove_after = remove_after
4344

44-
def _apply_to_lines(self, content, action):
45+
def _apply_to_lines(self, content: List[str], action: Callable[[str], str]) -> List[str]:
4546
if action is not None:
4647
idx = 0
4748
while idx < len(content):
@@ -55,7 +56,7 @@ def _apply_to_lines(self, content, action):
5556
idx += 1
5657
return content
5758

58-
def apply(self, content):
59+
def apply(self, content: List[str]) -> List[str]:
5960
filter_action = None
6061
if self.action == "r":
6162
filter_action = lambda l: l.replace(self.args[0], self.args[1])
@@ -67,23 +68,23 @@ def apply(self, content):
6768
filter_action = lambda l: "" if self.args[0] in l else l
6869
elif self.action == "s":
6970
class SubstituteAction:
70-
def __init__(self, pattern, repl):
71+
def __init__(self, pattern: str, repl: str):
7172
self.compiled_regex = re.compile(pattern)
7273
self.repl = repl
7374

74-
def __call__(self, l):
75+
def __call__(self, l: str) -> str:
7576
return re.sub(self.compiled_regex, self.repl, l)
7677

7778
filter_action = SubstituteAction(self.args[0], self.args[1])
7879
return self._apply_to_lines(content, filter_action)
7980

80-
def applies_to_pkg(self, pkg_name):
81+
def applies_to_pkg(self, pkg_name: str) -> bool:
8182
if pkg_name is None:
8283
return True
8384
else:
84-
return self.pkg_prog.match(pkg_name)
85+
return self.pkg_prog.match(pkg_name) is not None
8586

86-
def __repr__(self):
87+
def __repr__(self) -> str:
8788
fmt_str = "{!s} => {!s}"
8889
fmt_args = [self.pkg_pattern, self.action]
8990
for arg in self.args:
@@ -96,9 +97,9 @@ class InvalidFilterException(Exception):
9697
pass
9798

9899

99-
def load_filter_file(file_path):
100+
def load_filter_file(file_path: str) -> List[ContentFilter]:
100101
from os.path import isfile
101-
filters = []
102+
filters: List[ContentFilter] = []
102103
if isfile(file_path):
103104
with open(file_path) as f:
104105
for linenr, line in enumerate(f.readlines()):
@@ -111,22 +112,22 @@ def load_filter_file(file_path):
111112
return filters
112113

113114

114-
def _select_filters(filters, pkg):
115+
def _select_filters(filters: List[ContentFilter], pkg: str) -> List[ContentFilter]:
115116
pkg_filters = []
116117
for f in filters:
117118
if f.applies_to_pkg(pkg):
118119
pkg_filters.append(f)
119120
return pkg_filters
120121

121122

122-
def _parse_filter(line):
123+
def _parse_filter(line: str) -> ContentFilter:
123124
arrow_idx = line.find("=>")
124125
if arrow_idx < 0:
125126
raise InvalidFilterException("cannot find separator '=>'")
126127
pkg_pattern = line[:arrow_idx].strip()
127128
action_str = line[arrow_idx + 2:].strip()
128129
action = action_str[0]
129-
args = []
130+
args: List[str] = []
130131
remove_before = 0
131132
remove_after = 0
132133
if action == "d" or action == "D":
@@ -156,5 +157,5 @@ def _parse_filter(line):
156157
return ContentFilter(pkg_pattern, action, args, remove_before, remove_after)
157158

158159

159-
def select_filters_for_package(filter_file, pkg):
160+
def select_filters_for_package(filter_file: str, pkg: str) -> List[ContentFilter]:
160161
return _select_filters(load_filter_file(filter_file), pkg)

com.oracle.truffle.r.test.packages/pkgtest/subproc.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -24,15 +24,17 @@
2424
import logging
2525
from threading import Thread
2626
from threading import Lock
27+
from typing import List, Tuple, Optional, Any, Dict, Callable
28+
2729
import time, signal, errno, sys, os, subprocess
2830

2931
from .util import abort
3032

3133
ERROR_TIMEOUT = 0x700000000 # not 32 bits
32-
_currentSubprocesses = []
34+
_currentSubprocesses: List[Tuple[subprocess.Popen, List[str]]] = []
3335

3436

35-
def get_os():
37+
def get_os() -> str:
3638
"""
3739
Get a canonical form of sys.platform.
3840
"""
@@ -52,14 +54,14 @@ def get_os():
5254
abort(1, 'Unknown operating system ' + sys.platform)
5355

5456

55-
def _addSubprocess(p, args):
57+
def _addSubprocess(p: subprocess.Popen, args: List[str]) -> Tuple[subprocess.Popen, List[str]]:
5658
entry = (p, args)
5759
logging.debug('[{}: started subprocess {}: {}]'.format(os.getpid(), p.pid, args))
5860
_currentSubprocesses.append(entry)
5961
return entry
6062

6163

62-
def _removeSubprocess(entry):
64+
def _removeSubprocess(entry: Tuple[subprocess.Popen, List[str]]) -> None:
6365
if entry and entry in _currentSubprocesses:
6466
try:
6567
logging.debug('[{}: removing subprocess {}: {}]'.format(os.getpid(), entry[0], entry[1]))
@@ -68,7 +70,7 @@ def _removeSubprocess(entry):
6870
pass
6971

7072

71-
def waitOn(p):
73+
def waitOn(p: subprocess.Popen) -> int:
7274
if get_os() == 'windows':
7375
# on windows use a poll loop, otherwise signal does not get handled
7476
retcode = None
@@ -80,7 +82,7 @@ def waitOn(p):
8082
return retcode
8183

8284

83-
def _kill_process(pid, sig):
85+
def _kill_process(pid: int, sig: int) -> bool:
8486
"""
8587
Sends the signal `sig` to the process identified by `pid`. If `pid` is a process group
8688
leader, then signal is sent to the process group id.
@@ -98,8 +100,8 @@ def _kill_process(pid, sig):
98100
return False
99101

100102

101-
def _waitWithTimeout(process, args, timeout, nonZeroIsFatal=True):
102-
def _waitpid(pid):
103+
def _waitWithTimeout(process: subprocess.Popen, args: List[str], timeout: int, nonZeroIsFatal=True) -> int:
104+
def _waitpid(pid: int) -> Tuple[int, int]:
103105
while True:
104106
try:
105107
return os.waitpid(pid, os.WNOHANG)
@@ -136,7 +138,13 @@ def _returncode(status):
136138
time.sleep(delay)
137139

138140

139-
def pkgtest_run(args, nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None, env=None, **kwargs):
141+
def pkgtest_run(args: List[str], nonZeroIsFatal=True,
142+
out: Optional[Callable[[str], None]]=None,
143+
err: Optional[Callable[[str], None]]=None,
144+
cwd: Optional[str]=None,
145+
timeout: Optional[int]=None,
146+
env: Optional[Dict[str, str]]=None,
147+
**kwargs) -> int:
140148
"""
141149
Imported from MX.
142150
Run a command in a subprocess, wait for it to complete and return the exit status of the process.
@@ -158,11 +166,11 @@ def pkgtest_run(args, nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout
158166
else:
159167
msg = "Environment:\n"
160168
in_os = set(os.environ) - set(env)
161-
if (len(in_os) > 0):
169+
if len(in_os) > 0:
162170
msg = ' environment variables in OS environ but not in env:\n'
163171
msg += '\n'.join([' ' + key + '=' + os.environ[key] for key in list(in_os)])
164172
in_env = set(env) - set(os.environ)
165-
if (len(in_env) > 0):
173+
if len(in_env) > 0:
166174
msg += ' environment variables in env but not in OS environ:\n'
167175
msg += '\n'.join([' ' + key + '=' + env[key] for key in list(in_env)])
168176
logging.debug(msg)

0 commit comments

Comments
 (0)