40
40
import org .truffleruby .annotations .CoreModule ;
41
41
import org .truffleruby .annotations .Primitive ;
42
42
import org .truffleruby .builtins .PrimitiveArrayArgumentsNode ;
43
- import org .truffleruby .builtins .PrimitiveNode ;
44
43
import org .truffleruby .builtins .ReRaiseInlinedExceptionNode ;
45
44
import org .truffleruby .collections .ConcurrentOperations ;
46
45
import org .truffleruby .core .CoreLibrary ;
54
53
import org .truffleruby .core .cast .ToPathNode ;
55
54
import org .truffleruby .core .cast .ToStrNode ;
56
55
import org .truffleruby .core .cast .ToStringOrSymbolNode ;
57
- import org .truffleruby .core .cast .ToStringOrSymbolNodeGen ;
58
56
import org .truffleruby .core .cast .ToSymbolNode ;
59
57
import org .truffleruby .core .constant .WarnAlreadyInitializedNode ;
60
58
import org .truffleruby .core .encoding .Encodings ;
78
76
import org .truffleruby .language .LexicalScope ;
79
77
import org .truffleruby .language .Nil ;
80
78
import org .truffleruby .language .RubyBaseNode ;
81
- import org .truffleruby .language .RubyBaseNodeWithExecute ;
82
79
import org .truffleruby .language .RubyConstant ;
83
80
import org .truffleruby .language .RubyContextSourceNode ;
84
81
import org .truffleruby .language .RubyDynamicObject ;
131
128
import com .oracle .truffle .api .dsl .Cached ;
132
129
import com .oracle .truffle .api .dsl .Cached .Shared ;
133
130
import com .oracle .truffle .api .dsl .Cached .Exclusive ;
134
- import com .oracle .truffle .api .dsl .CreateCast ;
135
131
import com .oracle .truffle .api .dsl .ImportStatic ;
136
- import com .oracle .truffle .api .dsl .NodeChild ;
137
132
import com .oracle .truffle .api .dsl .Specialization ;
138
133
import com .oracle .truffle .api .frame .Frame ;
139
134
import com .oracle .truffle .api .frame .FrameInstance .FrameAccess ;
144
139
import com .oracle .truffle .api .profiles .BranchProfile ;
145
140
import com .oracle .truffle .api .source .SourceSection ;
146
141
142
+ import static org .truffleruby .builtins .PrimitiveNode .FAILURE ;
147
143
import static org .truffleruby .core .module .ModuleNodes .GenerateAccessorNode .Accessor .BOTH ;
148
144
import static org .truffleruby .core .module .ModuleNodes .GenerateAccessorNode .Accessor .READER ;
149
145
import static org .truffleruby .core .module .ModuleNodes .GenerateAccessorNode .Accessor .WRITER ;
@@ -941,51 +937,41 @@ protected boolean isConstDefined(
941
937
}
942
938
943
939
@ Primitive (name = "module_const_get" )
944
- @ NodeChild (value = "moduleNode" , type = RubyNode .class )
945
- @ NodeChild (value = "nameNode" , type = RubyBaseNodeWithExecute .class )
946
- @ NodeChild (value = "inheritNode" , type = RubyNode .class )
947
- @ NodeChild (value = "lookInObjectNode" , type = RubyNode .class )
948
- @ NodeChild (value = "checkNameNode" , type = RubyNode .class )
949
- public abstract static class ConstGetNode extends PrimitiveNode {
950
-
951
- @ Child private LookupConstantNode lookupConstantLookInObjectNode = LookupConstantNode .create (true , true );
952
- @ Child private LookupConstantNode lookupConstantNode = LookupConstantNode .create (true , false );
953
- @ Child private GetConstantNode getConstantNode = GetConstantNode .create ();
954
- @ Child private ByteIndexOfStringNode byteIndexOfStringNode ;
955
-
956
- public static ConstGetNode create (RubyNode module , RubyBaseNodeWithExecute name , RubyNode inherit ,
957
- RubyNode lookInObject , RubyNode checkName ) {
958
- return ModuleNodesFactory .ConstGetNodeFactory .create (module , name , inherit , lookInObject , checkName );
940
+ public abstract static class ConstGetNodePrimitiveNode extends PrimitiveArrayArgumentsNode {
941
+ @ Specialization
942
+ protected Object getConst (
943
+ RubyModule module , Object nameObject , boolean inherit , boolean lookInObject , boolean checkName ,
944
+ @ Cached ConstGetNode constGetNode ,
945
+ @ Cached ToStringOrSymbolNode toStringOrSymbolNode ) {
946
+ var name = toStringOrSymbolNode .execute (this , nameObject );
947
+ return constGetNode .execute (this , module , name , inherit , lookInObject , checkName );
959
948
}
949
+ }
960
950
961
- abstract RubyNode getModuleNode ();
962
-
963
- abstract RubyBaseNodeWithExecute getNameNode ();
964
-
965
- abstract RubyNode getInheritNode ();
966
-
967
- abstract RubyNode getLookInObjectNode ();
968
-
969
- abstract RubyNode getCheckNameNode ();
951
+ @ GenerateCached (false )
952
+ @ GenerateInline
953
+ public abstract static class ConstGetNode extends RubyBaseNode {
970
954
971
- @ CreateCast ("nameNode" )
972
- protected RubyBaseNodeWithExecute coerceToSymbolOrString (RubyBaseNodeWithExecute name ) {
973
- // We want to know if the name is a Symbol, as then scoped lookup is not tried
974
- return ToStringOrSymbolNodeGen .create (name );
975
- }
955
+ public abstract Object execute (Node node , RubyModule module , Object name , boolean inherit ,
956
+ boolean lookInObject , boolean checkName );
976
957
977
958
// Symbol
978
959
979
960
@ Specialization (guards = "inherit" )
980
- protected Object getConstant (
981
- RubyModule module , RubySymbol name , boolean inherit , boolean lookInObject , boolean checkName ) {
982
- return getConstant (module , name .getString (), checkName , lookInObject );
961
+ protected static Object getConstant (
962
+ Node node , RubyModule module , RubySymbol name , boolean inherit , boolean lookInObject , boolean checkName ,
963
+ @ Cached @ Shared GetConstantNode getConstantNode ,
964
+ @ Cached ("create(true, false)" ) @ Shared LookupConstantNode lookupConstantNode ,
965
+ @ Cached ("create(true, true)" ) @ Shared LookupConstantNode lookupConstantLookInObjectNode ) {
966
+ return getConstant (module , name .getString (), checkName , lookInObject , getConstantNode , lookupConstantNode ,
967
+ lookupConstantLookInObjectNode );
983
968
}
984
969
985
970
@ Specialization (guards = "!inherit" )
986
- protected Object getConstantNoInherit (
987
- RubyModule module , RubySymbol name , boolean inherit , boolean lookInObject , boolean checkName ) {
988
- return getConstantNoInherit (module , name .getString (), checkName );
971
+ protected static Object getConstantNoInherit (
972
+ RubyModule module , RubySymbol name , boolean inherit , boolean lookInObject , boolean checkName ,
973
+ @ Cached @ Shared GetConstantNode getConstantNode ) {
974
+ return getConstantNoInherit (module , name .getString (), checkName , getConstantNode );
989
975
}
990
976
991
977
// String
@@ -998,46 +984,67 @@ protected Object getConstantNoInherit(
998
984
"!scoped" ,
999
985
"checkName == cachedCheckName" },
1000
986
limit = "getLimit()" )
1001
- protected Object getConstantStringCached (
987
+ protected static Object getConstantStringCached (
1002
988
RubyModule module , Object name , boolean inherit , boolean lookInObject , boolean checkName ,
1003
989
@ Cached @ Shared RubyStringLibrary stringsName ,
990
+ @ Cached @ Shared GetConstantNode getConstantNode ,
991
+ @ Cached ("create(true, false)" ) @ Shared LookupConstantNode lookupConstantNode ,
992
+ @ Cached ("create(true, true)" ) @ Shared LookupConstantNode lookupConstantLookInObjectNode ,
1004
993
@ Cached ("asTruffleStringUncached(name)" ) TruffleString cachedTString ,
1005
994
@ Cached ("stringsName.getEncoding(name)" ) RubyEncoding cachedEncoding ,
1006
995
@ Cached ("getJavaString(name)" ) String cachedString ,
1007
996
@ Cached ("checkName" ) boolean cachedCheckName ,
1008
997
@ Cached StringHelperNodes .EqualNode equalNode ,
1009
998
@ Cached ("isScoped(cachedString)" ) boolean scoped ) {
1010
- return getConstant (module , cachedString , checkName , lookInObject );
999
+ return getConstant (module , cachedString , checkName , lookInObject , getConstantNode , lookupConstantNode ,
1000
+ lookupConstantLookInObjectNode );
1011
1001
}
1012
1002
1013
1003
@ Specialization (
1014
- guards = { "stringsName.isRubyString(name)" , "inherit" , "!isScoped(stringsName, name)" },
1004
+ guards = {
1005
+ "stringsName.isRubyString(name)" ,
1006
+ "inherit" ,
1007
+ "!isScoped(stringsName, name, byteIndexOfStringNode)" },
1015
1008
replaces = "getConstantStringCached" )
1016
- protected Object getConstantString (
1017
- RubyModule module , Object name , boolean inherit , boolean lookInObject , boolean checkName ,
1009
+ protected static Object getConstantString (
1010
+ Node node , RubyModule module , Object name , boolean inherit , boolean lookInObject , boolean checkName ,
1011
+ @ Cached @ Shared GetConstantNode getConstantNode ,
1012
+ @ Cached @ Shared ByteIndexOfStringNode byteIndexOfStringNode ,
1013
+ @ Cached ("create(true, false)" ) @ Shared LookupConstantNode lookupConstantNode ,
1014
+ @ Cached ("create(true, true)" ) @ Shared LookupConstantNode lookupConstantLookInObjectNode ,
1018
1015
@ Cached @ Shared RubyStringLibrary stringsName ,
1019
1016
@ Cached @ Shared ToJavaStringNode toJavaStringNode ) {
1020
- return getConstant (module , toJavaStringNode .execute (this , name ), checkName , lookInObject );
1017
+ return getConstant (module , toJavaStringNode .execute (node , name ), checkName , lookInObject , getConstantNode ,
1018
+ lookupConstantNode , lookupConstantLookInObjectNode );
1021
1019
}
1022
1020
1023
1021
@ Specialization (
1024
- guards = { "stringsName.isRubyString(name)" , "!inherit" , "!isScoped(stringsName, name)" })
1025
- protected Object getConstantNoInheritString (
1026
- RubyModule module , Object name , boolean inherit , boolean lookInObject , boolean checkName ,
1022
+ guards = {
1023
+ "stringsName.isRubyString(name)" ,
1024
+ "!inherit" ,
1025
+ "!isScoped(stringsName, name, byteIndexOfStringNode)" })
1026
+ protected static Object getConstantNoInheritString (
1027
+ Node node , RubyModule module , Object name , boolean inherit , boolean lookInObject , boolean checkName ,
1027
1028
@ Cached @ Shared RubyStringLibrary stringsName ,
1029
+ @ Cached @ Shared ByteIndexOfStringNode byteIndexOfStringNode ,
1030
+ @ Cached @ Shared GetConstantNode getConstantNode ,
1028
1031
@ Cached @ Shared ToJavaStringNode toJavaStringNode ) {
1029
- return getConstantNoInherit (module , toJavaStringNode .execute (this , name ), checkName );
1032
+ return getConstantNoInherit (module , toJavaStringNode .execute (node , name ), checkName , getConstantNode );
1030
1033
}
1031
1034
1032
1035
// Scoped String
1033
- @ Specialization (guards = { "stringsName.isRubyString(name)" , "isScoped(stringsName, name)" })
1034
- protected Object getConstantScoped (
1036
+ @ Specialization (
1037
+ guards = { "stringsName.isRubyString(name)" , "isScoped(stringsName, name, byteIndexOfStringNode)" })
1038
+ protected static Object getConstantScoped (
1035
1039
RubyModule module , Object name , boolean inherit , boolean lookInObject , boolean checkName ,
1040
+ @ Cached @ Shared ByteIndexOfStringNode byteIndexOfStringNode ,
1036
1041
@ Cached @ Shared RubyStringLibrary stringsName ) {
1037
1042
return FAILURE ;
1038
1043
}
1039
1044
1040
- private Object getConstant (RubyModule module , String name , boolean checkName , boolean lookInObject ) {
1045
+ private static Object getConstant (RubyModule module , String name , boolean checkName , boolean lookInObject ,
1046
+ GetConstantNode getConstantNode , LookupConstantNode lookupConstantNode ,
1047
+ LookupConstantNode lookupConstantLookInObjectNode ) {
1041
1048
CompilerAsserts .partialEvaluationConstant (lookInObject );
1042
1049
if (lookInObject ) {
1043
1050
return getConstantNode
@@ -1050,55 +1057,36 @@ private Object getConstant(RubyModule module, String name, boolean checkName, bo
1050
1057
}
1051
1058
}
1052
1059
1053
- private Object getConstantNoInherit (RubyModule module , String name , boolean checkName ) {
1054
- final LookupConstantInterface lookup = this ::lookupConstantNoInherit ;
1060
+ private static Object getConstantNoInherit (RubyModule module , String name , boolean checkName ,
1061
+ GetConstantNode getConstantNode ) {
1062
+ final LookupConstantInterface lookup = ConstGetNode ::lookupConstantNoInherit ;
1055
1063
return getConstantNode .lookupAndResolveConstant (LexicalScope .IGNORE , module , name , checkName , lookup , true );
1056
1064
}
1057
1065
1058
1066
@ TruffleBoundary
1059
- private RubyConstant lookupConstantNoInherit (LexicalScope lexicalScope , RubyModule module , String name ,
1060
- boolean checkName ) {
1067
+ private static RubyConstant lookupConstantNoInherit (Node node , LexicalScope lexicalScope , RubyModule module ,
1068
+ String name , boolean checkName ) {
1061
1069
return ModuleOperations
1062
- .lookupConstantWithInherit (getContext (), module , name , false , this , checkName )
1070
+ .lookupConstantWithInherit (getContext (node ), module , name , false , node , checkName )
1063
1071
.getConstant ();
1064
1072
}
1065
1073
1066
- boolean isScoped (RubyStringLibrary libString , Object string ) {
1067
- if (byteIndexOfStringNode == null ) {
1068
- CompilerDirectives .transferToInterpreterAndInvalidate ();
1069
- byteIndexOfStringNode = insert (ByteIndexOfStringNode .create ());
1070
- }
1071
-
1074
+ static boolean isScoped (RubyStringLibrary libString , Object string ,
1075
+ ByteIndexOfStringNode byteIndexOfStringNode ) {
1072
1076
var tstring = libString .getTString (string );
1073
1077
var encoding = libString .getTEncoding (string );
1074
1078
int byteLength = tstring .byteLength (encoding );
1075
1079
return byteIndexOfStringNode .execute (tstring , TStringConstants .COLON_COLON , 0 , byteLength , encoding ) >= 0 ;
1076
1080
}
1077
1081
1078
1082
@ TruffleBoundary
1079
- boolean isScoped (String name ) {
1083
+ static boolean isScoped (String name ) {
1080
1084
return name .contains ("::" );
1081
1085
}
1082
1086
1083
1087
protected int getLimit () {
1084
1088
return getLanguage ().options .CONSTANT_CACHE ;
1085
1089
}
1086
-
1087
- RubyBaseNodeWithExecute getNameBeforeCasting () {
1088
- return ((ToStringOrSymbolNode ) getNameNode ()).getChildNode ();
1089
- }
1090
-
1091
- @ Override
1092
- public RubyNode cloneUninitialized () {
1093
- var copy = create (
1094
- getModuleNode ().cloneUninitialized (),
1095
- getNameBeforeCasting ().cloneUninitialized (),
1096
- getInheritNode ().cloneUninitialized (),
1097
- getLookInObjectNode ().cloneUninitialized (),
1098
- getCheckNameNode ().cloneUninitialized ());
1099
- return copy .copyFlags (this );
1100
- }
1101
-
1102
1090
}
1103
1091
1104
1092
@ CoreMethod (names = "const_missing" , required = 1 )
@@ -1122,7 +1110,7 @@ protected Object constSourceLocation(RubyModule module, Object nameObject, Objec
1122
1110
@ Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode ,
1123
1111
@ Cached ToStringOrSymbolNode toStringOrSymbolNode ) {
1124
1112
final boolean inherit = booleanCastWithDefaultNode .execute (this , maybeInherit , true );
1125
- final var name = toStringOrSymbolNode .execute (nameObject );
1113
+ final var name = toStringOrSymbolNode .execute (this , nameObject );
1126
1114
return constSourceLocationNode .execute (this , module , name , inherit );
1127
1115
}
1128
1116
}
0 commit comments