Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: src/typing.cc

Issue 18337003: Revert^2 "Derive synthetic type bounds for expressions"" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/typing.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 27 matching lines...) Expand all
38 : info_(info), 38 : info_(info),
39 oracle_( 39 oracle_(
40 Handle<Code>(info->closure()->shared()->code()), 40 Handle<Code>(info->closure()->shared()->code()),
41 Handle<Context>(info->closure()->context()->native_context()), 41 Handle<Context>(info->closure()->context()->native_context()),
42 info->isolate(), 42 info->isolate(),
43 info->zone()) { 43 info->zone()) {
44 InitializeAstVisitor(); 44 InitializeAstVisitor();
45 } 45 }
46 46
47 47
48 #define RECURSE(call) \ 48 #define CHECK_ALIVE(call) \
49 do { \ 49 do { \
50 ASSERT(!visitor->HasStackOverflow()); \
51 call; \ 50 call; \
52 if (visitor->HasStackOverflow()) return; \ 51 if (visitor->HasStackOverflow()) return; \
53 } while (false) 52 } while (false)
54 53
54
55 void AstTyper::Run(CompilationInfo* info) { 55 void AstTyper::Run(CompilationInfo* info) {
56 AstTyper* visitor = new(info->zone()) AstTyper(info); 56 AstTyper* visitor = new(info->zone()) AstTyper(info);
57 Scope* scope = info->scope(); 57 Scope* scope = info->scope();
58 58
59 // Handle implicit declaration of the function name in named function 59 // Handle implicit declaration of the function name in named function
60 // expressions before other declarations. 60 // expressions before other declarations.
61 if (scope->is_function_scope() && scope->function() != NULL) { 61 if (scope->is_function_scope() && scope->function() != NULL) {
62 RECURSE(visitor->VisitVariableDeclaration(scope->function())); 62 CHECK_ALIVE(visitor->VisitVariableDeclaration(scope->function()));
63 } 63 }
64 RECURSE(visitor->VisitDeclarations(scope->declarations())); 64 CHECK_ALIVE(visitor->VisitDeclarations(scope->declarations()));
65 RECURSE(visitor->VisitStatements(info->function()->body())); 65 CHECK_ALIVE(visitor->VisitStatements(info->function()->body()));
66 } 66 }
67 67
68 #undef RECURSE
69 68
70 #define RECURSE(call) \ 69 #undef CHECK_ALIVE
70 #define CHECK_ALIVE(call) \
71 do { \ 71 do { \
72 ASSERT(!HasStackOverflow()); \
73 call; \ 72 call; \
74 if (HasStackOverflow()) return; \ 73 if (HasStackOverflow()) return; \
75 } while (false) 74 } while (false)
76 75
77 76
78 void AstTyper::VisitStatements(ZoneList<Statement*>* stmts) { 77 void AstTyper::VisitStatements(ZoneList<Statement*>* stmts) {
78 ASSERT(!HasStackOverflow());
79 for (int i = 0; i < stmts->length(); ++i) { 79 for (int i = 0; i < stmts->length(); ++i) {
80 Statement* stmt = stmts->at(i); 80 Statement* stmt = stmts->at(i);
81 RECURSE(Visit(stmt)); 81 CHECK_ALIVE(Visit(stmt));
82 } 82 }
83 } 83 }
84 84
85 85
86 void AstTyper::VisitBlock(Block* stmt) { 86 void AstTyper::VisitBlock(Block* stmt) {
87 RECURSE(VisitStatements(stmt->statements())); 87 ASSERT(!HasStackOverflow());
88 CHECK_ALIVE(VisitStatements(stmt->statements()));
88 } 89 }
89 90
90 91
91 void AstTyper::VisitExpressionStatement(ExpressionStatement* stmt) { 92 void AstTyper::VisitExpressionStatement(ExpressionStatement* stmt) {
92 RECURSE(Visit(stmt->expression())); 93 ASSERT(!HasStackOverflow());
94 CHECK_ALIVE(Visit(stmt->expression()));
93 } 95 }
94 96
95 97
96 void AstTyper::VisitEmptyStatement(EmptyStatement* stmt) { 98 void AstTyper::VisitEmptyStatement(EmptyStatement* stmt) {
99 ASSERT(!HasStackOverflow());
97 } 100 }
98 101
99 102
100 void AstTyper::VisitIfStatement(IfStatement* stmt) { 103 void AstTyper::VisitIfStatement(IfStatement* stmt) {
101 RECURSE(Visit(stmt->condition())); 104 ASSERT(!HasStackOverflow());
102 RECURSE(Visit(stmt->then_statement())); 105 CHECK_ALIVE(Visit(stmt->condition()));
103 RECURSE(Visit(stmt->else_statement())); 106 CHECK_ALIVE(Visit(stmt->then_statement()));
107 CHECK_ALIVE(Visit(stmt->else_statement()));
104 108
105 if (!stmt->condition()->ToBooleanIsTrue() && 109 if (!stmt->condition()->ToBooleanIsTrue() &&
106 !stmt->condition()->ToBooleanIsFalse()) { 110 !stmt->condition()->ToBooleanIsFalse()) {
107 stmt->condition()->RecordToBooleanTypeFeedback(oracle()); 111 stmt->condition()->RecordToBooleanTypeFeedback(oracle());
108 } 112 }
109 } 113 }
110 114
111 115
112 void AstTyper::VisitContinueStatement(ContinueStatement* stmt) { 116 void AstTyper::VisitContinueStatement(ContinueStatement* stmt) {
117 ASSERT(!HasStackOverflow());
113 } 118 }
114 119
115 120
116 void AstTyper::VisitBreakStatement(BreakStatement* stmt) { 121 void AstTyper::VisitBreakStatement(BreakStatement* stmt) {
122 ASSERT(!HasStackOverflow());
117 } 123 }
118 124
119 125
120 void AstTyper::VisitReturnStatement(ReturnStatement* stmt) { 126 void AstTyper::VisitReturnStatement(ReturnStatement* stmt) {
121 RECURSE(Visit(stmt->expression())); 127 ASSERT(!HasStackOverflow());
128 CHECK_ALIVE(Visit(stmt->expression()));
122 129
123 // TODO(rossberg): we only need this for inlining into test contexts... 130 // TODO(rossberg): we only need this for inlining into test contexts...
124 stmt->expression()->RecordToBooleanTypeFeedback(oracle()); 131 stmt->expression()->RecordToBooleanTypeFeedback(oracle());
125 } 132 }
126 133
127 134
128 void AstTyper::VisitWithStatement(WithStatement* stmt) { 135 void AstTyper::VisitWithStatement(WithStatement* stmt) {
129 RECURSE(stmt->expression()); 136 ASSERT(!HasStackOverflow());
130 RECURSE(stmt->statement()); 137 CHECK_ALIVE(stmt->expression());
138 CHECK_ALIVE(stmt->statement());
131 } 139 }
132 140
133 141
134 void AstTyper::VisitSwitchStatement(SwitchStatement* stmt) { 142 void AstTyper::VisitSwitchStatement(SwitchStatement* stmt) {
135 RECURSE(Visit(stmt->tag())); 143 ASSERT(!HasStackOverflow());
144 CHECK_ALIVE(Visit(stmt->tag()));
136 ZoneList<CaseClause*>* clauses = stmt->cases(); 145 ZoneList<CaseClause*>* clauses = stmt->cases();
137 SwitchStatement::SwitchType switch_type = stmt->switch_type(); 146 SwitchStatement::SwitchType switch_type = stmt->switch_type();
138 for (int i = 0; i < clauses->length(); ++i) { 147 for (int i = 0; i < clauses->length(); ++i) {
139 CaseClause* clause = clauses->at(i); 148 CaseClause* clause = clauses->at(i);
140 if (!clause->is_default()) { 149 if (!clause->is_default()) {
141 Expression* label = clause->label(); 150 Expression* label = clause->label();
142 RECURSE(Visit(label)); 151 CHECK_ALIVE(Visit(label));
143 152
144 SwitchStatement::SwitchType label_switch_type = 153 SwitchStatement::SwitchType label_switch_type =
145 label->IsSmiLiteral() ? SwitchStatement::SMI_SWITCH : 154 label->IsSmiLiteral() ? SwitchStatement::SMI_SWITCH :
146 label->IsStringLiteral() ? SwitchStatement::STRING_SWITCH : 155 label->IsStringLiteral() ? SwitchStatement::STRING_SWITCH :
147 SwitchStatement::GENERIC_SWITCH; 156 SwitchStatement::GENERIC_SWITCH;
148 if (switch_type == SwitchStatement::UNKNOWN_SWITCH) 157 if (switch_type == SwitchStatement::UNKNOWN_SWITCH)
149 switch_type = label_switch_type; 158 switch_type = label_switch_type;
150 else if (switch_type != label_switch_type) 159 else if (switch_type != label_switch_type)
151 switch_type = SwitchStatement::GENERIC_SWITCH; 160 switch_type = SwitchStatement::GENERIC_SWITCH;
152 } 161 }
153 RECURSE(VisitStatements(clause->statements())); 162 CHECK_ALIVE(VisitStatements(clause->statements()));
154 } 163 }
155 if (switch_type == SwitchStatement::UNKNOWN_SWITCH) 164 if (switch_type == SwitchStatement::UNKNOWN_SWITCH)
156 switch_type = SwitchStatement::GENERIC_SWITCH; 165 switch_type = SwitchStatement::GENERIC_SWITCH;
157 stmt->set_switch_type(switch_type); 166 stmt->set_switch_type(switch_type);
158 167
159 // TODO(rossberg): can we eliminate this special case and extra loop? 168 // TODO(rossberg): can we eliminate this special case and extra loop?
160 if (switch_type == SwitchStatement::SMI_SWITCH) { 169 if (switch_type == SwitchStatement::SMI_SWITCH) {
161 for (int i = 0; i < clauses->length(); ++i) { 170 for (int i = 0; i < clauses->length(); ++i) {
162 CaseClause* clause = clauses->at(i); 171 CaseClause* clause = clauses->at(i);
163 if (!clause->is_default()) 172 if (!clause->is_default())
164 clause->RecordTypeFeedback(oracle()); 173 clause->RecordTypeFeedback(oracle());
165 } 174 }
166 } 175 }
167 } 176 }
168 177
169 178
170 void AstTyper::VisitDoWhileStatement(DoWhileStatement* stmt) { 179 void AstTyper::VisitDoWhileStatement(DoWhileStatement* stmt) {
171 RECURSE(Visit(stmt->body())); 180 ASSERT(!HasStackOverflow());
172 RECURSE(Visit(stmt->cond())); 181 CHECK_ALIVE(Visit(stmt->body()));
182 CHECK_ALIVE(Visit(stmt->cond()));
173 183
174 if (!stmt->cond()->ToBooleanIsTrue()) { 184 if (!stmt->cond()->ToBooleanIsTrue()) {
175 stmt->cond()->RecordToBooleanTypeFeedback(oracle()); 185 stmt->cond()->RecordToBooleanTypeFeedback(oracle());
176 } 186 }
177 } 187 }
178 188
179 189
180 void AstTyper::VisitWhileStatement(WhileStatement* stmt) { 190 void AstTyper::VisitWhileStatement(WhileStatement* stmt) {
181 RECURSE(Visit(stmt->cond())); 191 ASSERT(!HasStackOverflow());
182 RECURSE(Visit(stmt->body())); 192 CHECK_ALIVE(Visit(stmt->cond()));
193 CHECK_ALIVE(Visit(stmt->body()));
183 194
184 if (!stmt->cond()->ToBooleanIsTrue()) { 195 if (!stmt->cond()->ToBooleanIsTrue()) {
185 stmt->cond()->RecordToBooleanTypeFeedback(oracle()); 196 stmt->cond()->RecordToBooleanTypeFeedback(oracle());
186 } 197 }
187 } 198 }
188 199
189 200
190 void AstTyper::VisitForStatement(ForStatement* stmt) { 201 void AstTyper::VisitForStatement(ForStatement* stmt) {
202 ASSERT(!HasStackOverflow());
191 if (stmt->init() != NULL) { 203 if (stmt->init() != NULL) {
192 RECURSE(Visit(stmt->init())); 204 CHECK_ALIVE(Visit(stmt->init()));
193 } 205 }
194 if (stmt->cond() != NULL) { 206 if (stmt->cond() != NULL) {
195 RECURSE(Visit(stmt->cond())); 207 CHECK_ALIVE(Visit(stmt->cond()));
196 208
197 stmt->cond()->RecordToBooleanTypeFeedback(oracle()); 209 stmt->cond()->RecordToBooleanTypeFeedback(oracle());
198 } 210 }
199 RECURSE(Visit(stmt->body())); 211 CHECK_ALIVE(Visit(stmt->body()));
200 if (stmt->next() != NULL) { 212 if (stmt->next() != NULL) {
201 RECURSE(Visit(stmt->next())); 213 CHECK_ALIVE(Visit(stmt->next()));
202 } 214 }
203 } 215 }
204 216
205 217
206 void AstTyper::VisitForInStatement(ForInStatement* stmt) { 218 void AstTyper::VisitForInStatement(ForInStatement* stmt) {
207 RECURSE(Visit(stmt->enumerable())); 219 ASSERT(!HasStackOverflow());
208 RECURSE(Visit(stmt->body())); 220 CHECK_ALIVE(Visit(stmt->enumerable()));
221 CHECK_ALIVE(Visit(stmt->body()));
209 222
210 stmt->RecordTypeFeedback(oracle()); 223 stmt->RecordTypeFeedback(oracle());
211 } 224 }
212 225
213 226
214 void AstTyper::VisitForOfStatement(ForOfStatement* stmt) { 227 void AstTyper::VisitForOfStatement(ForOfStatement* stmt) {
215 RECURSE(Visit(stmt->iterable())); 228 ASSERT(!HasStackOverflow());
216 RECURSE(Visit(stmt->body())); 229 CHECK_ALIVE(Visit(stmt->iterable()));
230 CHECK_ALIVE(Visit(stmt->body()));
217 } 231 }
218 232
219 233
220 void AstTyper::VisitTryCatchStatement(TryCatchStatement* stmt) { 234 void AstTyper::VisitTryCatchStatement(TryCatchStatement* stmt) {
221 RECURSE(Visit(stmt->try_block())); 235 ASSERT(!HasStackOverflow());
222 RECURSE(Visit(stmt->catch_block())); 236 CHECK_ALIVE(Visit(stmt->try_block()));
237 CHECK_ALIVE(Visit(stmt->catch_block()));
223 } 238 }
224 239
225 240
226 void AstTyper::VisitTryFinallyStatement(TryFinallyStatement* stmt) { 241 void AstTyper::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
227 RECURSE(Visit(stmt->try_block())); 242 ASSERT(!HasStackOverflow());
228 RECURSE(Visit(stmt->finally_block())); 243 CHECK_ALIVE(Visit(stmt->try_block()));
244 CHECK_ALIVE(Visit(stmt->finally_block()));
229 } 245 }
230 246
231 247
232 void AstTyper::VisitDebuggerStatement(DebuggerStatement* stmt) { 248 void AstTyper::VisitDebuggerStatement(DebuggerStatement* stmt) {
249 ASSERT(!HasStackOverflow());
233 } 250 }
234 251
235 252
236 void AstTyper::VisitFunctionLiteral(FunctionLiteral* expr) { 253 void AstTyper::VisitFunctionLiteral(FunctionLiteral* expr) {
254 ASSERT(!HasStackOverflow());
237 } 255 }
238 256
239 257
240 void AstTyper::VisitSharedFunctionInfoLiteral(SharedFunctionInfoLiteral* expr) { 258 void AstTyper::VisitSharedFunctionInfoLiteral(SharedFunctionInfoLiteral* expr) {
259 ASSERT(!HasStackOverflow());
241 } 260 }
242 261
243 262
244 void AstTyper::VisitConditional(Conditional* expr) { 263 void AstTyper::VisitConditional(Conditional* expr) {
245 RECURSE(Visit(expr->condition())); 264 ASSERT(!HasStackOverflow());
246 RECURSE(Visit(expr->then_expression())); 265 CHECK_ALIVE(Visit(expr->condition()));
247 RECURSE(Visit(expr->else_expression())); 266 CHECK_ALIVE(Visit(expr->then_expression()));
267 CHECK_ALIVE(Visit(expr->else_expression()));
248 268
249 expr->condition()->RecordToBooleanTypeFeedback(oracle()); 269 expr->condition()->RecordToBooleanTypeFeedback(oracle());
250
251 MergeLowerType(expr, Type::Intersect(
252 expr->then_expression()->lower_type(),
253 expr->else_expression()->lower_type()));
254 MergeUpperType(expr, Type::Union(
255 expr->then_expression()->upper_type(),
256 expr->else_expression()->upper_type()));
257 } 270 }
258 271
259 272
260 void AstTyper::VisitVariableProxy(VariableProxy* expr) { 273 void AstTyper::VisitVariableProxy(VariableProxy* expr) {
261 // TODO(rossberg): typing of variables 274 ASSERT(!HasStackOverflow());
262 } 275 }
263 276
264 277
265 void AstTyper::VisitLiteral(Literal* expr) { 278 void AstTyper::VisitLiteral(Literal* expr) {
266 Type* type = Type::Constant(expr->value(), isolate_); 279 ASSERT(!HasStackOverflow());
267 MergeLowerType(expr, type);
268 MergeUpperType(expr, type);
269 } 280 }
270 281
271 282
272 void AstTyper::VisitRegExpLiteral(RegExpLiteral* expr) { 283 void AstTyper::VisitRegExpLiteral(RegExpLiteral* expr) {
273 MergeLowerType(expr, Type::RegExp()); 284 ASSERT(!HasStackOverflow());
274 MergeUpperType(expr, Type::RegExp());
275 } 285 }
276 286
277 287
278 void AstTyper::VisitObjectLiteral(ObjectLiteral* expr) { 288 void AstTyper::VisitObjectLiteral(ObjectLiteral* expr) {
289 ASSERT(!HasStackOverflow());
279 ZoneList<ObjectLiteral::Property*>* properties = expr->properties(); 290 ZoneList<ObjectLiteral::Property*>* properties = expr->properties();
280 for (int i = 0; i < properties->length(); ++i) { 291 for (int i = 0; i < properties->length(); ++i) {
281 ObjectLiteral::Property* prop = properties->at(i); 292 ObjectLiteral::Property* prop = properties->at(i);
282 RECURSE(Visit(prop->value())); 293 CHECK_ALIVE(Visit(prop->value()));
283 294
284 if ((prop->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL && 295 if ((prop->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL &&
285 !CompileTimeValue::IsCompileTimeValue(prop->value())) || 296 !CompileTimeValue::IsCompileTimeValue(prop->value())) ||
286 prop->kind() == ObjectLiteral::Property::COMPUTED) { 297 prop->kind() == ObjectLiteral::Property::COMPUTED) {
287 if (prop->key()->value()->IsInternalizedString() && prop->emit_store()) { 298 if (prop->key()->value()->IsInternalizedString() && prop->emit_store())
288 prop->RecordTypeFeedback(oracle()); 299 prop->RecordTypeFeedback(oracle());
289 }
290 } 300 }
291 } 301 }
292
293 MergeLowerType(expr, Type::Object());
294 MergeUpperType(expr, Type::Object());
295 } 302 }
296 303
297 304
298 void AstTyper::VisitArrayLiteral(ArrayLiteral* expr) { 305 void AstTyper::VisitArrayLiteral(ArrayLiteral* expr) {
306 ASSERT(!HasStackOverflow());
299 ZoneList<Expression*>* values = expr->values(); 307 ZoneList<Expression*>* values = expr->values();
300 for (int i = 0; i < values->length(); ++i) { 308 for (int i = 0; i < values->length(); ++i) {
301 Expression* value = values->at(i); 309 Expression* value = values->at(i);
302 RECURSE(Visit(value)); 310 CHECK_ALIVE(Visit(value));
303 } 311 }
304
305 MergeLowerType(expr, Type::Array());
306 MergeUpperType(expr, Type::Array());
307 } 312 }
308 313
309 314
310 void AstTyper::VisitAssignment(Assignment* expr) { 315 void AstTyper::VisitAssignment(Assignment* expr) {
316 ASSERT(!HasStackOverflow());
317 CHECK_ALIVE(Visit(expr->target()));
318 CHECK_ALIVE(Visit(expr->value()));
319
311 // TODO(rossberg): Can we clean this up? 320 // TODO(rossberg): Can we clean this up?
312 if (expr->is_compound()) { 321 if (expr->is_compound()) {
313 RECURSE(Visit(expr->binary_operation())); 322 CHECK_ALIVE(Visit(expr->binary_operation()));
314 323
315 Expression* target = expr->target(); 324 Expression* target = expr->target();
316 Property* prop = target->AsProperty(); 325 Property* prop = target->AsProperty();
317 if (prop != NULL) { 326 if (prop != NULL) {
318 prop->RecordTypeFeedback(oracle(), zone()); 327 prop->RecordTypeFeedback(oracle(), zone());
319 if (!prop->key()->IsPropertyName()) { // i.e., keyed 328 if (!prop->key()->IsPropertyName()) // i.e., keyed
320 expr->RecordTypeFeedback(oracle(), zone()); 329 expr->RecordTypeFeedback(oracle(), zone());
321 }
322 } 330 }
323 } else { 331 return;
324 RECURSE(Visit(expr->target()));
325 RECURSE(Visit(expr->value()));
326
327 if (expr->target()->AsProperty()) {
328 expr->RecordTypeFeedback(oracle(), zone());
329 }
330
331 MergeLowerType(expr, expr->value()->lower_type());
332 MergeUpperType(expr, expr->value()->upper_type());
333 } 332 }
334 // TODO(rossberg): handle target variables 333 if (expr->target()->AsProperty())
334 expr->RecordTypeFeedback(oracle(), zone());
335 } 335 }
336 336
337 337
338 void AstTyper::VisitYield(Yield* expr) { 338 void AstTyper::VisitYield(Yield* expr) {
339 RECURSE(Visit(expr->generator_object())); 339 ASSERT(!HasStackOverflow());
340 RECURSE(Visit(expr->expression())); 340 CHECK_ALIVE(Visit(expr->generator_object()));
341 341 CHECK_ALIVE(Visit(expr->expression()));
342 // We don't know anything about the type.
343 } 342 }
344 343
345 344
346 void AstTyper::VisitThrow(Throw* expr) { 345 void AstTyper::VisitThrow(Throw* expr) {
347 RECURSE(Visit(expr->exception())); 346 ASSERT(!HasStackOverflow());
348 347 CHECK_ALIVE(Visit(expr->exception()));
349 // Lower type is None already.
350 MergeUpperType(expr, Type::None());
351 } 348 }
352 349
353 350
354 void AstTyper::VisitProperty(Property* expr) { 351 void AstTyper::VisitProperty(Property* expr) {
355 RECURSE(Visit(expr->obj())); 352 ASSERT(!HasStackOverflow());
356 RECURSE(Visit(expr->key())); 353 CHECK_ALIVE(Visit(expr->obj()));
354 CHECK_ALIVE(Visit(expr->key()));
357 355
358 expr->RecordTypeFeedback(oracle(), zone()); 356 expr->RecordTypeFeedback(oracle(), zone());
359
360 // We don't know anything about the type.
361 } 357 }
362 358
363 359
364 void AstTyper::VisitCall(Call* expr) { 360 void AstTyper::VisitCall(Call* expr) {
365 RECURSE(Visit(expr->expression())); 361 ASSERT(!HasStackOverflow());
362 CHECK_ALIVE(Visit(expr->expression()));
366 ZoneList<Expression*>* args = expr->arguments(); 363 ZoneList<Expression*>* args = expr->arguments();
367 for (int i = 0; i < args->length(); ++i) { 364 for (int i = 0; i < args->length(); ++i) {
368 Expression* arg = args->at(i); 365 Expression* arg = args->at(i);
369 RECURSE(Visit(arg)); 366 CHECK_ALIVE(Visit(arg));
370 } 367 }
371 368
372 Expression* callee = expr->expression(); 369 Expression* callee = expr->expression();
373 Property* prop = callee->AsProperty(); 370 Property* prop = callee->AsProperty();
374 if (prop != NULL) { 371 if (prop != NULL) {
375 if (prop->key()->IsPropertyName()) 372 if (prop->key()->IsPropertyName())
376 expr->RecordTypeFeedback(oracle(), CALL_AS_METHOD); 373 expr->RecordTypeFeedback(oracle(), CALL_AS_METHOD);
377 } else { 374 } else {
378 expr->RecordTypeFeedback(oracle(), CALL_AS_FUNCTION); 375 expr->RecordTypeFeedback(oracle(), CALL_AS_FUNCTION);
379 } 376 }
380
381 // We don't know anything about the type.
382 } 377 }
383 378
384 379
385 void AstTyper::VisitCallNew(CallNew* expr) { 380 void AstTyper::VisitCallNew(CallNew* expr) {
386 RECURSE(Visit(expr->expression())); 381 ASSERT(!HasStackOverflow());
382 CHECK_ALIVE(Visit(expr->expression()));
387 ZoneList<Expression*>* args = expr->arguments(); 383 ZoneList<Expression*>* args = expr->arguments();
388 for (int i = 0; i < args->length(); ++i) { 384 for (int i = 0; i < args->length(); ++i) {
389 Expression* arg = args->at(i); 385 Expression* arg = args->at(i);
390 RECURSE(Visit(arg)); 386 CHECK_ALIVE(Visit(arg));
391 } 387 }
392 388
393 expr->RecordTypeFeedback(oracle()); 389 expr->RecordTypeFeedback(oracle());
394
395 // We don't know anything about the type.
396 } 390 }
397 391
398 392
399 void AstTyper::VisitCallRuntime(CallRuntime* expr) { 393 void AstTyper::VisitCallRuntime(CallRuntime* expr) {
394 ASSERT(!HasStackOverflow());
400 ZoneList<Expression*>* args = expr->arguments(); 395 ZoneList<Expression*>* args = expr->arguments();
401 for (int i = 0; i < args->length(); ++i) { 396 for (int i = 0; i < args->length(); ++i) {
402 Expression* arg = args->at(i); 397 Expression* arg = args->at(i);
403 RECURSE(Visit(arg)); 398 CHECK_ALIVE(Visit(arg));
404 } 399 }
405
406 // We don't know anything about the type.
407 } 400 }
408 401
409 402
410 void AstTyper::VisitUnaryOperation(UnaryOperation* expr) { 403 void AstTyper::VisitUnaryOperation(UnaryOperation* expr) {
411 RECURSE(Visit(expr->expression())); 404 ASSERT(!HasStackOverflow());
405 CHECK_ALIVE(Visit(expr->expression()));
412 406
413 // Collect type feedback. 407 // Collect type feedback.
414 Handle<Type> op_type = oracle()->UnaryType(expr->UnaryOperationFeedbackId()); 408 Handle<Type> op_type = oracle()->UnaryType(expr->UnaryOperationFeedbackId());
415 MergeLowerType(expr->expression(), op_type); 409 MergeLowerType(expr->expression(), op_type);
416 if (expr->op() == Token::NOT) { 410 if (expr->op() == Token::NOT) {
417 // TODO(rossberg): only do in test or value context. 411 // TODO(rossberg): only do in test or value context.
418 expr->expression()->RecordToBooleanTypeFeedback(oracle()); 412 expr->expression()->RecordToBooleanTypeFeedback(oracle());
419 } 413 }
420
421 switch (expr->op()) {
422 case Token::NOT:
423 case Token::DELETE:
424 MergeLowerType(expr, Type::Boolean());
425 MergeUpperType(expr, Type::Boolean());
426 break;
427 case Token::VOID:
428 MergeLowerType(expr, Type::Undefined());
429 MergeUpperType(expr, Type::Undefined());
430 break;
431 case Token::ADD:
432 case Token::SUB: {
433 MergeLowerType(expr, Type::Smi());
434 Type* upper = *expr->expression()->upper_type();
435 MergeUpperType(expr, upper->Is(Type::Number()) ? upper : Type::Number());
436 break;
437 }
438 case Token::BIT_NOT:
439 MergeLowerType(expr, Type::Smi());
440 MergeUpperType(expr, Type::Signed32());
441 break;
442 case Token::TYPEOF:
443 MergeLowerType(expr, Type::InternalizedString());
444 MergeUpperType(expr, Type::InternalizedString());
445 break;
446 default:
447 UNREACHABLE();
448 }
449 } 414 }
450 415
451 416
452 void AstTyper::VisitCountOperation(CountOperation* expr) { 417 void AstTyper::VisitCountOperation(CountOperation* expr) {
453 RECURSE(Visit(expr->expression())); 418 ASSERT(!HasStackOverflow());
419 CHECK_ALIVE(Visit(expr->expression()));
454 420
455 expr->RecordTypeFeedback(oracle(), zone()); 421 expr->RecordTypeFeedback(oracle(), zone());
456 Property* prop = expr->expression()->AsProperty(); 422 Property* prop = expr->expression()->AsProperty();
457 if (prop != NULL) { 423 if (prop != NULL) {
458 prop->RecordTypeFeedback(oracle(), zone()); 424 prop->RecordTypeFeedback(oracle(), zone());
459 } 425 }
460
461 MergeLowerType(expr, Type::Smi());
462 MergeUpperType(expr, Type::Number());
463 } 426 }
464 427
465 428
466 void AstTyper::VisitBinaryOperation(BinaryOperation* expr) { 429 void AstTyper::VisitBinaryOperation(BinaryOperation* expr) {
467 RECURSE(Visit(expr->left())); 430 ASSERT(!HasStackOverflow());
468 RECURSE(Visit(expr->right())); 431 CHECK_ALIVE(Visit(expr->left()));
432 CHECK_ALIVE(Visit(expr->right()));
469 433
470 // Collect type feedback. 434 // Collect type feedback.
471 Handle<Type> type, left_type, right_type; 435 Handle<Type> type, left_type, right_type;
472 Maybe<int> fixed_right_arg; 436 Maybe<int> fixed_right_arg;
473 oracle()->BinaryType(expr->BinaryOperationFeedbackId(), 437 oracle()->BinaryType(expr->BinaryOperationFeedbackId(),
474 &left_type, &right_type, &type, &fixed_right_arg); 438 &left_type, &right_type, &type, &fixed_right_arg);
475 MergeLowerType(expr, type); 439 MergeLowerType(expr, type);
476 MergeLowerType(expr->left(), left_type); 440 MergeLowerType(expr->left(), left_type);
477 MergeLowerType(expr->right(), right_type); 441 MergeLowerType(expr->right(), right_type);
478 expr->set_fixed_right_arg(fixed_right_arg); 442 expr->set_fixed_right_arg(fixed_right_arg);
479 if (expr->op() == Token::OR || expr->op() == Token::AND) { 443 if (expr->op() == Token::OR || expr->op() == Token::AND) {
480 expr->left()->RecordToBooleanTypeFeedback(oracle()); 444 expr->left()->RecordToBooleanTypeFeedback(oracle());
481 } 445 }
482
483 switch (expr->op()) {
484 case Token::COMMA:
485 MergeLowerType(expr, expr->right()->lower_type());
486 MergeUpperType(expr, expr->right()->upper_type());
487 break;
488 case Token::OR:
489 case Token::AND:
490 MergeLowerType(expr, Type::Intersect(
491 expr->left()->lower_type(), expr->right()->lower_type()));
492 MergeUpperType(expr, Type::Union(
493 expr->left()->upper_type(), expr->right()->upper_type()));
494 break;
495 case Token::BIT_OR:
496 case Token::BIT_AND: {
497 MergeLowerType(expr, Type::Smi());
498 Type* upper =
499 Type::Union(expr->left()->upper_type(), expr->right()->upper_type());
500 MergeUpperType(expr,
501 upper->Is(Type::Signed32()) ? upper : Type::Signed32());
502 break;
503 }
504 case Token::BIT_XOR:
505 case Token::SHL:
506 case Token::SAR:
507 MergeLowerType(expr, Type::Smi());
508 MergeUpperType(expr, Type::Signed32());
509 break;
510 case Token::SHR:
511 MergeLowerType(expr, Type::Smi());
512 MergeUpperType(expr, Type::Unsigned32());
513 break;
514 case Token::ADD: {
515 Handle<Type> l = expr->left()->lower_type();
516 Handle<Type> r = expr->right()->lower_type();
517 MergeLowerType(expr,
518 l->Is(Type::Number()) && r->Is(Type::Number()) ? Type::Smi() :
519 l->Is(Type::String()) || r->Is(Type::String()) ? Type::String() :
520 Type::None());
521 l = expr->left()->upper_type();
522 r = expr->right()->upper_type();
523 MergeUpperType(expr,
524 l->Is(Type::Number()) && r->Is(Type::Number()) ? Type::Number() :
525 l->Is(Type::String()) || r->Is(Type::String()) ? Type::String() :
526 Type::NumberOrString());
527 break;
528 }
529 case Token::SUB:
530 case Token::MUL:
531 case Token::DIV:
532 case Token::MOD:
533 MergeLowerType(expr, Type::Smi());
534 MergeUpperType(expr, Type::Number());
535 break;
536 default:
537 UNREACHABLE();
538 }
539 } 446 }
540 447
541 448
542 void AstTyper::VisitCompareOperation(CompareOperation* expr) { 449 void AstTyper::VisitCompareOperation(CompareOperation* expr) {
543 RECURSE(Visit(expr->left())); 450 ASSERT(!HasStackOverflow());
544 RECURSE(Visit(expr->right())); 451 CHECK_ALIVE(Visit(expr->left()));
452 CHECK_ALIVE(Visit(expr->right()));
545 453
546 // Collect type feedback. 454 // Collect type feedback.
547 Handle<Type> left_type, right_type, combined_type; 455 Handle<Type> left_type, right_type, combined_type;
548 oracle()->CompareType(expr->CompareOperationFeedbackId(), 456 oracle()->CompareType(expr->CompareOperationFeedbackId(),
549 &left_type, &right_type, &combined_type); 457 &left_type, &right_type, &combined_type);
550 MergeLowerType(expr->left(), left_type); 458 MergeLowerType(expr->left(), left_type);
551 MergeLowerType(expr->right(), right_type); 459 MergeLowerType(expr->right(), right_type);
552 expr->set_combined_type(combined_type); 460 expr->set_combined_type(combined_type);
553
554 MergeLowerType(expr, Type::Boolean());
555 MergeUpperType(expr, Type::Boolean());
556 } 461 }
557 462
558 463
559 void AstTyper::VisitThisFunction(ThisFunction* expr) { 464 void AstTyper::VisitThisFunction(ThisFunction* expr) {
465 ASSERT(!HasStackOverflow());
560 } 466 }
561 467
562 468
563 void AstTyper::VisitDeclarations(ZoneList<Declaration*>* decls) { 469 void AstTyper::VisitDeclarations(ZoneList<Declaration*>* decls) {
470 ASSERT(!HasStackOverflow());
564 for (int i = 0; i < decls->length(); ++i) { 471 for (int i = 0; i < decls->length(); ++i) {
565 Declaration* decl = decls->at(i); 472 Declaration* decl = decls->at(i);
566 RECURSE(Visit(decl)); 473 CHECK_ALIVE(Visit(decl));
567 } 474 }
568 } 475 }
569 476
570 477
571 void AstTyper::VisitVariableDeclaration(VariableDeclaration* declaration) { 478 void AstTyper::VisitVariableDeclaration(VariableDeclaration* declaration) {
479 ASSERT(!HasStackOverflow());
572 } 480 }
573 481
574 482
575 void AstTyper::VisitFunctionDeclaration(FunctionDeclaration* declaration) { 483 void AstTyper::VisitFunctionDeclaration(FunctionDeclaration* declaration) {
576 RECURSE(Visit(declaration->fun())); 484 ASSERT(!HasStackOverflow());
485 CHECK_ALIVE(Visit(declaration->fun()));
577 } 486 }
578 487
579 488
580 void AstTyper::VisitModuleDeclaration(ModuleDeclaration* declaration) { 489 void AstTyper::VisitModuleDeclaration(ModuleDeclaration* declaration) {
581 RECURSE(Visit(declaration->module())); 490 ASSERT(!HasStackOverflow());
491 CHECK_ALIVE(Visit(declaration->module()));
582 } 492 }
583 493
584 494
585 void AstTyper::VisitImportDeclaration(ImportDeclaration* declaration) { 495 void AstTyper::VisitImportDeclaration(ImportDeclaration* declaration) {
586 RECURSE(Visit(declaration->module())); 496 ASSERT(!HasStackOverflow());
497 CHECK_ALIVE(Visit(declaration->module()));
587 } 498 }
588 499
589 500
590 void AstTyper::VisitExportDeclaration(ExportDeclaration* declaration) { 501 void AstTyper::VisitExportDeclaration(ExportDeclaration* declaration) {
502 ASSERT(!HasStackOverflow());
591 } 503 }
592 504
593 505
594 void AstTyper::VisitModuleLiteral(ModuleLiteral* module) { 506 void AstTyper::VisitModuleLiteral(ModuleLiteral* module) {
595 RECURSE(Visit(module->body())); 507 ASSERT(!HasStackOverflow());
508 CHECK_ALIVE(Visit(module->body()));
596 } 509 }
597 510
598 511
599 void AstTyper::VisitModuleVariable(ModuleVariable* module) { 512 void AstTyper::VisitModuleVariable(ModuleVariable* module) {
513 ASSERT(!HasStackOverflow());
600 } 514 }
601 515
602 516
603 void AstTyper::VisitModulePath(ModulePath* module) { 517 void AstTyper::VisitModulePath(ModulePath* module) {
604 RECURSE(Visit(module->module())); 518 ASSERT(!HasStackOverflow());
519 CHECK_ALIVE(Visit(module->module()));
605 } 520 }
606 521
607 522
608 void AstTyper::VisitModuleUrl(ModuleUrl* module) { 523 void AstTyper::VisitModuleUrl(ModuleUrl* module) {
524 ASSERT(!HasStackOverflow());
609 } 525 }
610 526
611 527
612 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) { 528 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) {
613 RECURSE(Visit(stmt->body())); 529 ASSERT(!HasStackOverflow());
530 CHECK_ALIVE(Visit(stmt->body()));
614 } 531 }
615 532
616 533
617 } } // namespace v8::internal 534 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/typing.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698