40
40
*/
41
41
package com .oracle .graal .python .nodes .argument .keywords ;
42
42
43
- import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
44
-
45
43
import com .oracle .graal .python .builtins .objects .common .EmptyStorage ;
46
44
import com .oracle .graal .python .builtins .objects .common .HashingStorageLibrary ;
47
45
import com .oracle .graal .python .builtins .objects .common .KeywordsStorage ;
48
46
import com .oracle .graal .python .builtins .objects .dict .PDict ;
49
47
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
50
- import com .oracle .graal .python .builtins .objects .str .PString ;
51
- import com .oracle .graal .python .nodes .ErrorMessages ;
52
48
import com .oracle .graal .python .nodes .PGuards ;
53
49
import com .oracle .graal .python .nodes .PNodeWithContext ;
54
- import com .oracle .graal .python .nodes .PRaiseNode ;
55
50
import com .oracle .graal .python .nodes .argument .keywords .ExecuteKeywordStarargsNodeGen .ExpandKeywordStarargsNodeGen ;
56
51
import com .oracle .graal .python .nodes .expression .ExpressionNode ;
57
52
import com .oracle .graal .python .runtime .PythonOptions ;
62
57
import com .oracle .truffle .api .dsl .Specialization ;
63
58
import com .oracle .truffle .api .frame .VirtualFrame ;
64
59
import com .oracle .truffle .api .library .CachedLibrary ;
65
- import com .oracle .truffle .api .nodes .ControlFlowException ;
66
60
import com .oracle .truffle .api .nodes .Node ;
67
- import com .oracle .truffle .api .profiles .BranchProfile ;
68
61
69
62
@ NodeChild (value = "starargs" , type = ExpressionNode .class )
70
63
public abstract class ExecuteKeywordStarargsNode extends PNodeWithContext {
@@ -102,26 +95,17 @@ static PKeyword[] doEmptyStorage(@SuppressWarnings("unused") PDict starargs) {
102
95
static PKeyword [] doDictCached (PDict starargs ,
103
96
@ Cached CopyKeywordsNode copyKeywordsNode ,
104
97
@ SuppressWarnings ("unused" ) @ CachedLibrary ("starargs.getDictStorage()" ) HashingStorageLibrary lib ,
105
- @ Cached ("len(lib, starargs)" ) int cachedLen ,
106
- @ Cached PRaiseNode raise ,
107
- @ Cached BranchProfile errorProfile ) {
108
- try {
109
- PKeyword [] keywords = new PKeyword [cachedLen ];
110
- copyKeywordsNode .executeWithoutState (starargs , keywords );
111
- return keywords ;
112
- } catch (KeywordNotStringException e ) {
113
- errorProfile .enter ();
114
- throw raise .raise (TypeError , ErrorMessages .MUST_BE_STRINGS , "keywords" );
115
- }
98
+ @ Cached ("len(lib, starargs)" ) int cachedLen ) {
99
+ PKeyword [] keywords = new PKeyword [cachedLen ];
100
+ copyKeywordsNode .executeWithoutState (starargs , keywords );
101
+ return keywords ;
116
102
}
117
103
118
104
@ Specialization (replaces = "doDictCached" , limit = "1" )
119
105
static PKeyword [] doDict (PDict starargs ,
120
106
@ Cached CopyKeywordsNode copyKeywordsNode ,
121
- @ CachedLibrary ("starargs.getDictStorage()" ) HashingStorageLibrary lib ,
122
- @ Cached PRaiseNode raise ,
123
- @ Cached BranchProfile errorProfile ) {
124
- return doDictCached (starargs , copyKeywordsNode , lib , len (lib , starargs ), raise , errorProfile );
107
+ @ CachedLibrary ("starargs.getDictStorage()" ) HashingStorageLibrary lib ) {
108
+ return doDictCached (starargs , copyKeywordsNode , lib , len (lib , starargs ));
125
109
}
126
110
127
111
@ Specialization (guards = "!isDict(object)" )
@@ -132,30 +116,19 @@ static PKeyword[] doNonMapping(@SuppressWarnings("unused") Object object) {
132
116
@ Specialization (replaces = {"doKeywordsArray" , "doKeywordsStorage" , "doEmptyStorage" , "doDictCached" , "doDict" , "doNonMapping" })
133
117
static PKeyword [] doGeneric (Object kwargs ,
134
118
@ Cached CopyKeywordsNode copyKeywordsNode ,
135
- @ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ,
136
- @ Cached PRaiseNode raise ,
137
- @ Cached BranchProfile errorProfile ) {
119
+ @ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ) {
138
120
if (kwargs instanceof PDict ) {
139
121
PDict d = (PDict ) kwargs ;
140
122
if (isKeywordsStorage (d )) {
141
123
return doKeywordsStorage (d );
142
124
} else if (isEmptyStorage (d )) {
143
125
return doEmptyStorage (d );
144
126
}
145
- return doDict (d , copyKeywordsNode , lib , raise , errorProfile );
127
+ return doDict (d , copyKeywordsNode , lib );
146
128
}
147
129
return PKeyword .EMPTY_KEYWORDS ;
148
130
}
149
131
150
- private static String castToString (Object key ) throws KeywordNotStringException {
151
- if (key instanceof String ) {
152
- return (String ) key ;
153
- } else if (key instanceof PString ) {
154
- return ((PString ) key ).getValue ();
155
- }
156
- throw new KeywordNotStringException ();
157
- }
158
-
159
132
static boolean isKeywordsStorage (PDict dict ) {
160
133
return dict .getDictStorage () instanceof KeywordsStorage ;
161
134
}
@@ -168,10 +141,6 @@ static int len(HashingStorageLibrary lib, PDict dict) {
168
141
return lib .length (dict .getDictStorage ());
169
142
}
170
143
171
- private static final class KeywordNotStringException extends ControlFlowException {
172
- private static final long serialVersionUID = 1L ;
173
- }
174
-
175
144
public static ExpandKeywordStarargsNode create () {
176
145
return ExpandKeywordStarargsNodeGen .create ();
177
146
}
0 commit comments