78
78
import com .oracle .graal .python .nodes .PNodeWithContext ;
79
79
import com .oracle .graal .python .nodes .PRaiseNode ;
80
80
import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
81
+ import com .oracle .graal .python .nodes .attributes .ReadAttributeFromObjectNode ;
81
82
import com .oracle .graal .python .nodes .call .CallNode ;
82
83
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
83
84
import com .oracle .graal .python .nodes .function .builtins .PythonSenaryBuiltinNode ;
@@ -595,15 +596,15 @@ abstract static class CreateMatchFromTRegexResultNode extends PNodeWithContext {
595
596
596
597
@ Specialization
597
598
static Object createMatch (VirtualFrame frame , Node inliningTarget , Object pattern , int pos , int endPos , Object regexResult , Object input ,
598
- @ Cached ( "lookupMatchConstructor()" ) Object matchConstructor ,
599
+ @ Cached GetMatchConstructorNode getConstructor ,
599
600
@ Cached InlinedConditionProfile matchProfile ,
600
601
@ CachedLibrary (limit = "1" ) InteropLibrary libResult ,
601
602
@ Cached PyObjectLookupAttr lookupIndexGroupNode ,
602
603
@ Cached (inline = false ) CallNode constructResultNode ) {
603
604
try {
604
605
if (matchProfile .profile (inliningTarget , (boolean ) libResult .readMember (regexResult , "isMatch" ))) {
605
606
Object indexGroup = lookupIndexGroupNode .execute (frame , inliningTarget , pattern , T__PATTERN__INDEXGROUP );
606
- return constructResultNode .execute (frame , matchConstructor , pattern , pos , endPos , regexResult , input , indexGroup );
607
+ return constructResultNode .execute (frame , getConstructor . execute ( inliningTarget ) , pattern , pos , endPos , regexResult , input , indexGroup );
607
608
} else {
608
609
return PNone .NONE ;
609
610
}
@@ -612,11 +613,31 @@ static Object createMatch(VirtualFrame frame, Node inliningTarget, Object patter
612
613
}
613
614
}
614
615
615
- @ TruffleBoundary
616
- @ NeverDefault
617
- protected Object lookupMatchConstructor () {
618
- PythonModule module = getContext ().lookupBuiltinModule (BuiltinNames .T__SRE );
619
- return PyObjectLookupAttr .executeUncached (module , T_MATCH_CONSTRUCTOR );
616
+ @ GenerateInline
617
+ @ GenerateCached (false )
618
+ abstract static class GetMatchConstructorNode extends PNodeWithContext {
619
+ public abstract Object execute (Node inliningTarget );
620
+
621
+ @ Specialization (guards = "isSingleContext()" )
622
+ static Object doSingleContext (
623
+ @ Cached ("lookupMatchConstructor()" ) Object constructor ) {
624
+ return constructor ;
625
+ }
626
+
627
+ @ Specialization (replaces = "doSingleContext" )
628
+ static Object doRead (
629
+ @ Bind PythonContext context ,
630
+ @ Cached ReadAttributeFromObjectNode read ) {
631
+ PythonModule module = context .lookupBuiltinModule (BuiltinNames .T__SRE );
632
+ return read .execute (module , T_MATCH_CONSTRUCTOR );
633
+ }
634
+
635
+ @ TruffleBoundary
636
+ @ NeverDefault
637
+ protected static Object lookupMatchConstructor () {
638
+ PythonModule module = PythonContext .get (null ).lookupBuiltinModule (BuiltinNames .T__SRE );
639
+ return PyObjectLookupAttr .executeUncached (module , T_MATCH_CONSTRUCTOR );
640
+ }
620
641
}
621
642
}
622
643
0 commit comments