1
1
/*
2
- * Copyright (c) 2021, 2022 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2021, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* The Universal Permissive License (UPL), Version 1.0
45
45
import static com .oracle .graal .python .util .PythonUtils .TS_ENCODING ;
46
46
47
47
import com .oracle .graal .python .builtins .objects .PNone ;
48
+ import com .oracle .graal .python .builtins .objects .bytes .BytesBuiltins ;
49
+ import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
48
50
import com .oracle .graal .python .builtins .objects .common .HashingStorageNodes .HashingStorageLen ;
49
51
import com .oracle .graal .python .builtins .objects .dict .PDict ;
50
52
import com .oracle .graal .python .builtins .objects .list .PList ;
59
61
import com .oracle .graal .python .nodes .PRaiseNode ;
60
62
import com .oracle .graal .python .nodes .call .special .CallUnaryMethodNode ;
61
63
import com .oracle .graal .python .nodes .call .special .LookupSpecialMethodSlotNode ;
62
- import com .oracle .graal .python .nodes .object .GetClassNode ;
64
+ import com .oracle .graal .python .nodes .object .InlinedGetClassNode ;
65
+ import com .oracle .graal .python .nodes .object .InlinedGetClassNode .GetPythonObjectClassNode ;
63
66
import com .oracle .graal .python .nodes .util .CastToJavaIntLossyNode ;
64
67
import com .oracle .graal .python .runtime .exception .PException ;
68
+ import com .oracle .truffle .api .dsl .Bind ;
65
69
import com .oracle .truffle .api .dsl .Cached ;
66
70
import com .oracle .truffle .api .dsl .Cached .Shared ;
67
71
import com .oracle .truffle .api .dsl .Fallback ;
@@ -94,39 +98,51 @@ static int doTruffleString(TruffleString str,
94
98
return codePointLengthNode .execute (str , TS_ENCODING );
95
99
}
96
100
97
- @ Specialization (guards = "cannotBeOverridden(object, getClassNode)" , limit = "1" )
101
+ @ Specialization (guards = "cannotBeOverridden(object, inliningTarget, getClassNode)" , limit = "1" )
98
102
static int doList (PList object ,
99
- @ Shared ("getClass" ) @ SuppressWarnings ("unused" ) @ Cached GetClassNode getClassNode ) {
103
+ @ SuppressWarnings ("unused" ) @ Bind ("this" ) Node inliningTarget ,
104
+ @ Shared ("getClass" ) @ SuppressWarnings ("unused" ) @ Cached GetPythonObjectClassNode getClassNode ) {
100
105
return object .getSequenceStorage ().length ();
101
106
}
102
107
103
- @ Specialization (guards = "cannotBeOverridden(object, getClassNode)" , limit = "1" )
108
+ @ Specialization (guards = "cannotBeOverridden(object, inliningTarget, getClassNode)" , limit = "1" )
104
109
static int doTuple (PTuple object ,
105
- @ Shared ("getClass" ) @ SuppressWarnings ("unused" ) @ Cached GetClassNode getClassNode ) {
110
+ @ SuppressWarnings ("unused" ) @ Bind ("this" ) Node inliningTarget ,
111
+ @ Shared ("getClass" ) @ SuppressWarnings ("unused" ) @ Cached GetPythonObjectClassNode getClassNode ) {
106
112
return object .getSequenceStorage ().length ();
107
113
}
108
114
109
- @ Specialization (guards = "cannotBeOverridden(object, getClassNode)" , limit = "1" )
115
+ @ Specialization (guards = "cannotBeOverridden(object, inliningTarget, getClassNode)" , limit = "1" )
110
116
static int doDict (PDict object ,
111
- @ Shared ("getClass" ) @ SuppressWarnings ("unused" ) @ Cached GetClassNode getClassNode ,
117
+ @ SuppressWarnings ("unused" ) @ Bind ("this" ) Node inliningTarget ,
118
+ @ Shared ("getClass" ) @ SuppressWarnings ("unused" ) @ Cached GetPythonObjectClassNode getClassNode ,
112
119
@ Shared ("hashingStorageLen" ) @ Cached HashingStorageLen lenNode ) {
113
120
return lenNode .execute (object .getDictStorage ());
114
121
}
115
122
116
- @ Specialization (guards = "cannotBeOverridden(object, getClassNode)" , limit = "1" )
123
+ @ Specialization (guards = "cannotBeOverridden(object, inliningTarget, getClassNode)" , limit = "1" )
117
124
static int doSet (PSet object ,
118
- @ Shared ("getClass" ) @ SuppressWarnings ("unused" ) @ Cached GetClassNode getClassNode ,
125
+ @ SuppressWarnings ("unused" ) @ Bind ("this" ) Node inliningTarget ,
126
+ @ Shared ("getClass" ) @ SuppressWarnings ("unused" ) @ Cached GetPythonObjectClassNode getClassNode ,
119
127
@ Shared ("hashingStorageLen" ) @ Cached HashingStorageLen lenNode ) {
120
128
return lenNode .execute (object .getDictStorage ());
121
129
}
122
130
123
- @ Specialization (guards = "cannotBeOverridden(object, getClassNode)" , limit = "1" )
131
+ @ Specialization (guards = "cannotBeOverridden(object, inliningTarget, getClassNode)" , limit = "1" )
124
132
static int doPString (PString object ,
125
- @ Shared ("getClass" ) @ SuppressWarnings ("unused" ) @ Cached GetClassNode getClassNode ,
133
+ @ SuppressWarnings ("unused" ) @ Bind ("this" ) Node inliningTarget ,
134
+ @ Shared ("getClass" ) @ SuppressWarnings ("unused" ) @ Cached GetPythonObjectClassNode getClassNode ,
126
135
@ Cached StringNodes .StringLenNode lenNode ) {
127
136
return lenNode .execute (object );
128
137
}
129
138
139
+ @ Specialization (guards = "cannotBeOverridden(object, inliningTarget, getClassNode)" , limit = "1" )
140
+ static int doPBytes (PBytes object ,
141
+ @ SuppressWarnings ("unused" ) @ Bind ("this" ) Node inliningTarget ,
142
+ @ Shared ("getClass" ) @ SuppressWarnings ("unused" ) @ Cached GetPythonObjectClassNode getClassNode ) {
143
+ return BytesBuiltins .LenNode .len (object );
144
+ }
145
+
130
146
@ Fallback
131
147
static int doOthers (VirtualFrame frame , Object object ,
132
148
@ Cached PyObjectSizeGenericNode genericNode ) {
@@ -142,14 +158,15 @@ abstract static class PyObjectSizeGenericNode extends Node {
142
158
143
159
@ Specialization (rewriteOn = UnexpectedResultException .class )
144
160
static int doInt (VirtualFrame frame , Object object ,
145
- @ Shared ("getClass" ) @ Cached GetClassNode getClassNode ,
161
+ @ Bind ("this" ) Node inliningTarget ,
162
+ @ Shared ("getClass" ) @ Cached InlinedGetClassNode getClassNode ,
146
163
@ Shared ("lookupLen" ) @ Cached (parameters = "Len" ) LookupSpecialMethodSlotNode lookupLen ,
147
164
@ Shared ("callLen" ) @ Cached CallUnaryMethodNode callLen ,
148
165
@ Shared ("index" ) @ Cached PyNumberIndexNode indexNode ,
149
166
@ Shared ("castLossy" ) @ Cached CastToJavaIntLossyNode castLossy ,
150
167
@ Shared ("asSize" ) @ Cached PyNumberAsSizeNode asSizeNode ,
151
168
@ Shared ("raise" ) @ Cached PRaiseNode raiseNode ) throws UnexpectedResultException {
152
- Object lenDescr = lookupLen .execute (frame , getClassNode .execute (object ), object );
169
+ Object lenDescr = lookupLen .execute (frame , getClassNode .execute (inliningTarget , object ), object );
153
170
if (lenDescr == PNone .NO_VALUE ) {
154
171
throw raiseNode .raise (TypeError , ErrorMessages .OBJ_HAS_NO_LEN , object );
155
172
}
@@ -163,14 +180,15 @@ static int doInt(VirtualFrame frame, Object object,
163
180
164
181
@ Specialization (replaces = "doInt" )
165
182
static int doObject (VirtualFrame frame , Object object ,
166
- @ Shared ("getClass" ) @ Cached GetClassNode getClassNode ,
183
+ @ Bind ("this" ) Node inliningTarget ,
184
+ @ Shared ("getClass" ) @ Cached InlinedGetClassNode getClassNode ,
167
185
@ Shared ("lookupLen" ) @ Cached (parameters = "Len" ) LookupSpecialMethodSlotNode lookupLen ,
168
186
@ Shared ("callLen" ) @ Cached CallUnaryMethodNode callLen ,
169
187
@ Shared ("index" ) @ Cached PyNumberIndexNode indexNode ,
170
188
@ Shared ("castLossy" ) @ Cached CastToJavaIntLossyNode castLossy ,
171
189
@ Shared ("asSize" ) @ Cached PyNumberAsSizeNode asSizeNode ,
172
190
@ Shared ("raise" ) @ Cached PRaiseNode raiseNode ) {
173
- Object lenDescr = lookupLen .execute (frame , getClassNode .execute (object ), object );
191
+ Object lenDescr = lookupLen .execute (frame , getClassNode .execute (inliningTarget , object ), object );
174
192
if (lenDescr == PNone .NO_VALUE ) {
175
193
throw raiseNode .raise (TypeError , ErrorMessages .OBJ_HAS_NO_LEN , object );
176
194
}
0 commit comments