Skip to content

Commit 89a63eb

Browse files
committed
Deprecate WithTRegex and TRegexUsesSREFallback options
1 parent d742435 commit 89a63eb

File tree

4 files changed

+11
-18
lines changed

4 files changed

+11
-18
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
106106
import com.oracle.graal.python.runtime.IndirectCallData.InteropCallData;
107107
import com.oracle.graal.python.runtime.PythonContext;
108-
import com.oracle.graal.python.runtime.PythonOptions;
109108
import com.oracle.graal.python.runtime.exception.PException;
110109
import com.oracle.graal.python.runtime.exception.PythonErrorType;
111110
import com.oracle.graal.python.runtime.formatting.ErrorMessageFormatter;
@@ -160,8 +159,6 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
160159

161160
@Override
162161
public void initialize(Python3Core core) {
163-
addBuiltinConstant("_with_tregex", core.getContext().getLanguage().getEngineOption(PythonOptions.WithTRegex));
164-
addBuiltinConstant("_with_sre", core.getContext().getLanguage().getEngineOption(PythonOptions.TRegexUsesSREFallback));
165162
addBuiltinConstant("_METHOD_SEARCH", PythonMethod.Search);
166163
addBuiltinConstant("_METHOD_MATCH", PythonMethod.Match);
167164
addBuiltinConstant("_METHOD_FULLMATCH", PythonMethod.FullMatch);
@@ -524,7 +521,7 @@ static TRegexCache getTRegexCache(Node inliningTarget, PythonObject pattern, Hid
524521

525522
@GenerateCached
526523
@ImportStatic(PythonMethod.class)
527-
@SuppressWarnings("truffle-inlining") // TODO
524+
@SuppressWarnings("truffle-inlining")
528525
abstract static class TRegexCompileInner extends PNodeWithContext {
529526

530527
private static final TruffleString T__GETLOCALE = tsLiteral("_getlocale");
@@ -949,8 +946,8 @@ static Object doCached(VirtualFrame frame, PythonObject pattern, Object input, i
949946
Object compiledRegex = tRegexCompile.execute(frame, tRegexCache, PythonMethod.Search, false);
950947
Object compiledRegexMustAdvance = tRegexCompile.execute(frame, tRegexCache, PythonMethod.Search, true);
951948
if (compiledRegex == PNone.NONE || compiledRegexMustAdvance == PNone.NONE) {
952-
// TODO: Fallback
953-
throw CompilerDirectives.shouldNotReachHere();
949+
CompilerDirectives.transferToInterpreterAndInvalidate();
950+
throw CompilerDirectives.shouldNotReachHere("unsupported regular expression: /" + tRegexCache.pattern + "/" + tRegexCache.flags);
954951
}
955952
checkInputTypeNode.execute(frame, input, tRegexCache.binary);
956953
int groupCount = TRegexUtil.TRegexCompiledRegexAccessor.groupCount(compiledRegex, inliningTarget, readGroupCountNode);
@@ -1134,8 +1131,8 @@ private static Object doSubn(VirtualFrame frame, PythonObject pattern, Object re
11341131
Object compiledRegex = tRegexCompile.execute(frame, tRegexCache, PythonMethod.Search, false);
11351132
Object compiledRegexMustAdvance = tRegexCompile.execute(frame, tRegexCache, PythonMethod.Search, true);
11361133
if (compiledRegex == PNone.NONE || compiledRegexMustAdvance == PNone.NONE) {
1137-
// TODO: Fallback
1138-
throw CompilerDirectives.shouldNotReachHere();
1134+
CompilerDirectives.transferToInterpreterAndInvalidate();
1135+
throw CompilerDirectives.shouldNotReachHere("unsupported regular expression: /" + tRegexCache.pattern + "/" + tRegexCache.flags);
11391136
}
11401137
checkInputTypeNode.execute(frame, input, tRegexCache.binary);
11411138
return innerNode1.execute(inliningTarget, frame, pattern, compiledRegex, compiledRegexMustAdvance, replacement, input, count, tRegexCache.binary,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextHashBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.Py_hash_t;
4949
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.Py_ssize_t;
5050
import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.Void;
51+
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING_BINARY;
5152

5253
import com.oracle.graal.python.builtins.modules.SysModuleBuiltins;
5354
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
@@ -62,7 +63,6 @@
6263
import com.oracle.truffle.api.dsl.Cached;
6364
import com.oracle.truffle.api.dsl.Specialization;
6465
import com.oracle.truffle.api.strings.TruffleString;
65-
import com.oracle.truffle.api.strings.TruffleString.Encoding;
6666
import com.oracle.truffle.api.strings.TruffleString.HashCodeNode;
6767

6868
public final class PythonCextHashBuiltins {
@@ -118,7 +118,7 @@ static long doI(Object value, long size,
118118
@Cached TruffleString.FromByteArrayNode toString,
119119
@Cached HashCodeNode hashNode) {
120120
byte[] array = readNode.readByteArray(value, (int) size);
121-
TruffleString string = toString.execute(array, Encoding.US_ASCII, false);
121+
TruffleString string = toString.execute(array, TS_ENCODING_BINARY, false);
122122
return PyObjectHashNode.hash(string, hashNode);
123123
}
124124
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@ public static void checkBytecodeDSLEnv() {
281281

282282
// disabling TRegex has an effect on the _sre Python functions that are
283283
// dynamically created, so we cannot change that option again.
284-
@EngineOption @Option(category = OptionCategory.EXPERT, usageSyntax = "true|false", help = "Use the optimized TRegex engine. Default true") //
284+
@EngineOption @Option(category = OptionCategory.EXPERT, usageSyntax = "true|false", help = "Use the optimized TRegex engine. Default true", deprecated = true, deprecationMessage = "TRegex is now for all regexes, this option is ignored") //
285285
public static final OptionKey<Boolean> WithTRegex = new OptionKey<>(true);
286286

287-
@EngineOption @Option(category = OptionCategory.EXPERT, usageSyntax = "true|false", help = "Use the CPython sre engine as a fallback to the TRegex engine.") //
287+
@EngineOption @Option(category = OptionCategory.EXPERT, usageSyntax = "true|false", help = "Use the CPython sre engine as a fallback to the TRegex engine.", deprecated = true, deprecationMessage = "TRegex is used for all regexes, this option is ignored") //
288288
public static final OptionKey<Boolean> TRegexUsesSREFallback = new OptionKey<>(true);
289289

290290
@Option(category = OptionCategory.EXPERT, usageSyntax = "true|false", help = "Switch on/off using lazy strings for performance reasons. Default true.") //

graalpython/lib-graalpython/_sre.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _getlocale():
7777
return '.'.join((lang, encoding))
7878

7979
def _new_compile(p, flags=0):
80-
if _with_tregex and isinstance(p, (str, bytes, bytearray, memoryview, array, mmap)):
80+
if isinstance(p, (str, bytes, bytearray, memoryview, array, mmap)):
8181
return _t_compile(p, flags)
8282
else:
8383
return _sre_compile(p, flags)
@@ -279,11 +279,7 @@ def __check_input_type(self, input):
279279
raise TypeError("cannot use a bytes pattern on a string-like object")
280280

281281
def __fallback_compile(self):
282-
if self.__compiled_fallback is None:
283-
if not _with_sre:
284-
raise ValueError("regular expression not supported, no fallback engine present") from None
285-
self.__compiled_fallback = _sre_compile(self.pattern, self.__input_flags)
286-
return self.__compiled_fallback
282+
raise ValueError("regular expression not supported, no fallback engine present") from None
287283

288284
def __repr__(self):
289285
flags = self.flags

0 commit comments

Comments
 (0)