Skip to content

Commit fa7cc39

Browse files
committed
Use PythonMethod values directly in SREModuleBuiltins nodes
1 parent a798e5f commit fa7cc39

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

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

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
128128
public void initialize(Python3Core core) {
129129
addBuiltinConstant("_with_tregex", core.getContext().getLanguage().getEngineOption(PythonOptions.WithTRegex));
130130
addBuiltinConstant("_with_sre", core.getContext().getLanguage().getEngineOption(PythonOptions.TRegexUsesSREFallback));
131-
addBuiltinConstant("_METHOD_SEARCH", PythonMethod.search.ordinal());
132-
addBuiltinConstant("_METHOD_MATCH", PythonMethod.match.ordinal());
133-
addBuiltinConstant("_METHOD_FULLMATCH", PythonMethod.fullmatch.ordinal());
131+
addBuiltinConstant("_METHOD_SEARCH", PythonMethod.search);
132+
addBuiltinConstant("_METHOD_MATCH", PythonMethod.match);
133+
addBuiltinConstant("_METHOD_FULLMATCH", PythonMethod.fullmatch);
134134
super.initialize(core);
135135
}
136136

@@ -481,45 +481,43 @@ abstract static class TRegexCompile extends PythonTernaryBuiltinNode {
481481
private static final TruffleString T__GETLOCALE = tsLiteral("_getlocale");
482482

483483
@Specialization(guards = {"tRegexCache == cachedTRegexCache", "method == cachedMethod", "mustAdvance == cachedMustAdvance", "!cachedTRegexCache.isLocaleSensitive()"}, limit = "2")
484-
Object cached(TRegexCache tRegexCache, int method, boolean mustAdvance,
484+
Object cached(TRegexCache tRegexCache, PythonMethod method, boolean mustAdvance,
485485
@Cached("tRegexCache") TRegexCache cachedTRegexCache,
486-
@Cached("method") int cachedMethod,
486+
@Cached("method") PythonMethod cachedMethod,
487487
@Cached("mustAdvance") boolean cachedMustAdvance,
488488
@Cached("getCompiledRegex(tRegexCache, method, mustAdvance)") Object compiledRegex) {
489489
return compiledRegex;
490490
}
491491

492-
protected Object getCompiledRegex(TRegexCache tRegexCache, int method, boolean mustAdvance) {
493-
return localeNonSensitive(tRegexCache, method, mustAdvance, method, mustAdvance, PythonMethod.fromOrdinal(method));
492+
protected Object getCompiledRegex(TRegexCache tRegexCache, PythonMethod method, boolean mustAdvance) {
493+
return localeNonSensitive(tRegexCache, method, mustAdvance, method, mustAdvance);
494494
}
495495

496496
@Specialization(guards = {"method == cachedMethod", "mustAdvance == cachedMustAdvance", "!tRegexCache.isLocaleSensitive()"}, limit = "6")
497-
Object localeNonSensitive(TRegexCache tRegexCache, int method, boolean mustAdvance,
498-
@Cached("method") int cachedMethod,
499-
@Cached("mustAdvance") boolean cachedMustAdvance,
500-
@Cached("fromOrdinal(method)") PythonMethod pythonMethod) {
501-
final Object tRegex = tRegexCache.getRegexp(pythonMethod, mustAdvance);
497+
Object localeNonSensitive(TRegexCache tRegexCache, PythonMethod method, boolean mustAdvance,
498+
@Cached("method") PythonMethod cachedMethod,
499+
@Cached("mustAdvance") boolean cachedMustAdvance) {
500+
final Object tRegex = tRegexCache.getRegexp(method, mustAdvance);
502501
if (tRegex != null) {
503502
return tRegex;
504503
} else {
505-
return tRegexCache.compile(getContext(), pythonMethod, mustAdvance, null);
504+
return tRegexCache.compile(getContext(), method, mustAdvance, null);
506505
}
507506
}
508507

509508
@Specialization(guards = {"method == cachedMethod", "mustAdvance == cachedMustAdvance", "tRegexCache.isLocaleSensitive()"}, limit = "6")
510-
Object localeSensitive(TRegexCache tRegexCache, int method, boolean mustAdvance,
511-
@Cached("method") int cachedMethod,
509+
Object localeSensitive(TRegexCache tRegexCache, PythonMethod method, boolean mustAdvance,
510+
@Cached("method") PythonMethod cachedMethod,
512511
@Cached("mustAdvance") boolean cachedMustAdvance,
513-
@Cached("fromOrdinal(method)") PythonMethod pythonMethod,
514512
@Cached("lookupGetLocaleFunction()") Object getLocale,
515513
@Cached CallNode callGetLocale,
516514
@Cached CastToTruffleStringNode castToTruffleStringNode) {
517515
TruffleString locale = castToTruffleStringNode.execute(callGetLocale.execute(getLocale));
518-
final Object tRegex = tRegexCache.getLocaleSensitiveRegexp(pythonMethod, mustAdvance, locale);
516+
final Object tRegex = tRegexCache.getLocaleSensitiveRegexp(method, mustAdvance, locale);
519517
if (tRegex != null) {
520518
return tRegex;
521519
} else {
522-
return tRegexCache.compile(getContext(), pythonMethod, mustAdvance, locale);
520+
return tRegexCache.compile(getContext(), method, mustAdvance, locale);
523521
}
524522
}
525523

@@ -613,10 +611,10 @@ abstract static class TRegexSearch extends PythonSenaryBuiltinNode {
613611

614612
@Specialization(guards = {"isSingleContext()", "pattern == cachedPattern", "method == cachedMethod", "mustAdvance == cachedMustAdvance", "!tRegexCache.isLocaleSensitive()"}, limit = "1")
615613
@SuppressWarnings("truffle-static-method")
616-
protected Object doCached(VirtualFrame frame, Object pattern, Object input, Object posArg, Object endPosArg, int method, boolean mustAdvance,
614+
protected Object doCached(VirtualFrame frame, Object pattern, Object input, Object posArg, Object endPosArg, PythonMethod method, boolean mustAdvance,
617615
@Bind("this") Node inliningTarget,
618616
@Cached("pattern") Object cachedPattern,
619-
@Cached("method") int cachedMethod,
617+
@Cached("method") PythonMethod cachedMethod,
620618
@Cached("mustAdvance") boolean cachedMustAdvance,
621619
@Cached @Shared ReadAttributeFromObjectNode readCacheNode,
622620
@Cached @Shared TRegexCompile tRegexCompileNode,
@@ -629,7 +627,7 @@ protected Object doCached(VirtualFrame frame, Object pattern, Object input, Obje
629627
@Cached @Shared PyNumberAsSizeNode asSizeNode,
630628
@Cached @Shared PyObjectSizeNode lengthNode,
631629
@CachedLibrary(limit = "1") @Shared InteropLibrary libCompiledRegex,
632-
@Cached("create(getMethodName(method))") GetAttributeNode getFallbackMethodNode,
630+
@Cached("create(method.getMethodName())") GetAttributeNode getFallbackMethodNode,
633631
@Cached @Shared TRegexCallExec tRegexCallExec,
634632
@Cached @Shared CreateMatchFromTRegexResultNode createMatchFromTRegexResultNode) {
635633
reCheckInputTypeNode.execute(frame, input, tRegexCache.isBinary());
@@ -665,9 +663,9 @@ protected Object doCached(VirtualFrame frame, Object pattern, Object input, Obje
665663
@Specialization(guards = {"tRegexCompileNode.execute(frame, getTRegexCache(readCacheNode, pattern), method, mustAdvance) == compiledRegex", "method == cachedMethod",
666664
"mustAdvance == cachedMustAdvance", "!tRegexCache.isLocaleSensitive()"}, limit = "1")
667665
@SuppressWarnings("truffle-static-method")
668-
protected Object doCachedRegex(VirtualFrame frame, Object pattern, Object input, Object posArg, Object endPosArg, int method, boolean mustAdvance,
666+
protected Object doCachedRegex(VirtualFrame frame, Object pattern, Object input, Object posArg, Object endPosArg, PythonMethod method, boolean mustAdvance,
669667
@Bind("this") Node inliningTarget,
670-
@Cached("method") int cachedMethod,
668+
@Cached("method") PythonMethod cachedMethod,
671669
@Cached("mustAdvance") boolean cachedMustAdvance,
672670
@Cached @Shared ReadAttributeFromObjectNode readCacheNode,
673671
@Cached @Shared TRegexCompile tRegexCompileNode,
@@ -680,7 +678,7 @@ protected Object doCachedRegex(VirtualFrame frame, Object pattern, Object input,
680678
@Cached @Shared PyNumberAsSizeNode asSizeNode,
681679
@Cached @Shared PyObjectSizeNode lengthNode,
682680
@CachedLibrary(limit = "1") @Shared InteropLibrary libCompiledRegex,
683-
@Cached("create(getMethodName(method))") GetAttributeNode getFallbackMethodNode,
681+
@Cached("create(method.getMethodName())") GetAttributeNode getFallbackMethodNode,
684682
@Cached @Shared TRegexCallExec tRegexCallExec,
685683
@Cached @Shared CreateMatchFromTRegexResultNode createMatchFromTRegexResultNode) {
686684
return doCached(frame, pattern, input, posArg, endPosArg, method, mustAdvance, inliningTarget, pattern, cachedMethod, mustAdvance, readCacheNode, tRegexCompileNode, tRegexCache,
@@ -691,9 +689,9 @@ protected Object doCachedRegex(VirtualFrame frame, Object pattern, Object input,
691689
@Specialization(guards = "method == cachedMethod", limit = "3", replaces = {"doCached", "doCachedRegex"})
692690
@SuppressWarnings("truffle-static-method")
693691
@ReportPolymorphism.Megamorphic
694-
protected Object doDynamic(VirtualFrame frame, Object pattern, Object input, Object posArg, Object endPosArg, int method, boolean mustAdvance,
692+
protected Object doDynamic(VirtualFrame frame, Object pattern, Object input, Object posArg, Object endPosArg, PythonMethod method, boolean mustAdvance,
695693
@Bind("this") Node inliningTarget,
696-
@Cached("method") int cachedMethod,
694+
@Cached("method") PythonMethod cachedMethod,
697695
@Cached @Shared ReadAttributeFromObjectNode readCacheNode,
698696
@Cached @Shared TRegexCompile tRegexCompileNode,
699697
@Cached @Shared PyNumberIndexNode indexNode,
@@ -703,7 +701,7 @@ protected Object doDynamic(VirtualFrame frame, Object pattern, Object input, Obj
703701
@Cached @Shared InlinedConditionProfile fallbackProfile,
704702
@Cached @Shared InlinedConditionProfile truncatingInputProfile,
705703
@CachedLibrary(limit = "1") @Shared InteropLibrary libCompiledRegex,
706-
@Cached("create(getMethodName(method))") GetAttributeNode getFallbackMethodNode,
704+
@Cached("create(method.getMethodName())") GetAttributeNode getFallbackMethodNode,
707705
@Cached @Shared TRegexCallExec tRegexCallExec,
708706
@Cached @Shared CreateMatchFromTRegexResultNode createMatchFromTRegexResultNode) {
709707
TRegexCache tRegexCache = getTRegexCache(readCacheNode, pattern);
@@ -717,10 +715,6 @@ protected static TRegexCache getTRegexCache(ReadAttributeFromObjectNode readCach
717715
return (TRegexCache) readCacheNode.execute(pattern, T__PATTERN__TREGEX_CACHE);
718716
}
719717

720-
protected static TruffleString getMethodName(int method) {
721-
return PythonMethod.fromOrdinal(method).getMethodName();
722-
}
723-
724718
private GetAttributeNode getGetFallbackCompileNode() {
725719
if (getFallbackCompileNode == null) {
726720
CompilerDirectives.transferToInterpreterAndInvalidate();

0 commit comments

Comments
 (0)