OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <functional> | 5 #include <functional> |
6 | 6 |
7 #include "src/codegen.h" | 7 #include "src/codegen.h" |
8 #include "src/compiler/js-operator.h" | 8 #include "src/compiler/js-operator.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 #include "test/cctest/types-fuzz.h" | 10 #include "test/cctest/types-fuzz.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 218 |
219 | 219 |
220 //------------------------------------------------------------------------------ | 220 //------------------------------------------------------------------------------ |
221 // Soundness | 221 // Soundness |
222 // For simplicity, we currently only test soundness on expression operators | 222 // For simplicity, we currently only test soundness on expression operators |
223 // that have a direct equivalent in C++. Also, testing is currently limited | 223 // that have a direct equivalent in C++. Also, testing is currently limited |
224 // to ranges as input types. | 224 // to ranges as input types. |
225 | 225 |
226 | 226 |
227 TEST_F(TyperTest, TypeJSAdd) { | 227 TEST_F(TyperTest, TypeJSAdd) { |
228 TestBinaryArithOp(javascript_.Add(), std::plus<double>()); | 228 TestBinaryArithOp(javascript_.Add(LanguageMode::SLOPPY), std::plus<double>()); |
| 229 TestBinaryArithOp(javascript_.Add(LanguageMode::STRONG), std::plus<double>()); |
229 } | 230 } |
230 | 231 |
231 | 232 |
232 TEST_F(TyperTest, TypeJSSubtract) { | 233 TEST_F(TyperTest, TypeJSSubtract) { |
233 TestBinaryArithOp(javascript_.Subtract(), std::minus<double>()); | 234 TestBinaryArithOp(javascript_.Subtract(LanguageMode::SLOPPY), |
| 235 std::minus<double>()); |
| 236 TestBinaryArithOp(javascript_.Subtract(LanguageMode::STRONG), |
| 237 std::minus<double>()); |
234 } | 238 } |
235 | 239 |
236 | 240 |
237 TEST_F(TyperTest, TypeJSMultiply) { | 241 TEST_F(TyperTest, TypeJSMultiply) { |
238 TestBinaryArithOp(javascript_.Multiply(), std::multiplies<double>()); | 242 TestBinaryArithOp(javascript_.Multiply(LanguageMode::SLOPPY), |
| 243 std::multiplies<double>()); |
| 244 TestBinaryArithOp(javascript_.Multiply(LanguageMode::STRONG), |
| 245 std::multiplies<double>()); |
239 } | 246 } |
240 | 247 |
241 | 248 |
242 TEST_F(TyperTest, TypeJSDivide) { | 249 TEST_F(TyperTest, TypeJSDivide) { |
243 TestBinaryArithOp(javascript_.Divide(), std::divides<double>()); | 250 TestBinaryArithOp(javascript_.Divide(LanguageMode::SLOPPY), |
| 251 std::divides<double>()); |
| 252 TestBinaryArithOp(javascript_.Divide(LanguageMode::STRONG), |
| 253 std::divides<double>()); |
244 } | 254 } |
245 | 255 |
246 | 256 |
247 TEST_F(TyperTest, TypeJSModulus) { | 257 TEST_F(TyperTest, TypeJSModulus) { |
248 TestBinaryArithOp(javascript_.Modulus(), modulo); | 258 TestBinaryArithOp(javascript_.Modulus(LanguageMode::SLOPPY), modulo); |
| 259 TestBinaryArithOp(javascript_.Modulus(LanguageMode::STRONG), modulo); |
249 } | 260 } |
250 | 261 |
251 | 262 |
252 TEST_F(TyperTest, TypeJSBitwiseOr) { | 263 TEST_F(TyperTest, TypeJSBitwiseOr) { |
253 TestBinaryBitOp(javascript_.BitwiseOr(), bit_or); | 264 TestBinaryBitOp(javascript_.BitwiseOr(LanguageMode::SLOPPY), bit_or); |
| 265 TestBinaryBitOp(javascript_.BitwiseOr(LanguageMode::STRONG), bit_or); |
254 } | 266 } |
255 | 267 |
256 | 268 |
257 TEST_F(TyperTest, TypeJSBitwiseAnd) { | 269 TEST_F(TyperTest, TypeJSBitwiseAnd) { |
258 TestBinaryBitOp(javascript_.BitwiseAnd(), bit_and); | 270 TestBinaryBitOp(javascript_.BitwiseAnd(LanguageMode::SLOPPY), bit_and); |
| 271 TestBinaryBitOp(javascript_.BitwiseAnd(LanguageMode::STRONG), bit_and); |
259 } | 272 } |
260 | 273 |
261 | 274 |
262 TEST_F(TyperTest, TypeJSBitwiseXor) { | 275 TEST_F(TyperTest, TypeJSBitwiseXor) { |
263 TestBinaryBitOp(javascript_.BitwiseXor(), bit_xor); | 276 TestBinaryBitOp(javascript_.BitwiseXor(LanguageMode::SLOPPY), bit_xor); |
| 277 TestBinaryBitOp(javascript_.BitwiseXor(LanguageMode::STRONG), bit_xor); |
264 } | 278 } |
265 | 279 |
266 | 280 |
267 TEST_F(TyperTest, TypeJSShiftLeft) { | 281 TEST_F(TyperTest, TypeJSShiftLeft) { |
268 TestBinaryBitOp(javascript_.ShiftLeft(), shift_left); | 282 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::SLOPPY), shift_left); |
| 283 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::STRONG), shift_left); |
269 } | 284 } |
270 | 285 |
271 | 286 |
272 TEST_F(TyperTest, TypeJSShiftRight) { | 287 TEST_F(TyperTest, TypeJSShiftRight) { |
273 TestBinaryBitOp(javascript_.ShiftRight(), shift_right); | 288 TestBinaryBitOp(javascript_.ShiftRight(LanguageMode::SLOPPY), shift_right); |
| 289 TestBinaryBitOp(javascript_.ShiftRight(LanguageMode::STRONG), shift_right); |
274 } | 290 } |
275 | 291 |
276 | 292 |
277 TEST_F(TyperTest, TypeJSLessThan) { | 293 TEST_F(TyperTest, TypeJSLessThan) { |
278 TestBinaryCompareOp(javascript_.LessThan(), std::less<double>()); | 294 TestBinaryCompareOp(javascript_.LessThan(LanguageMode::SLOPPY), |
| 295 std::less<double>()); |
| 296 TestBinaryCompareOp(javascript_.LessThan(LanguageMode::STRONG), |
| 297 std::less<double>()); |
279 } | 298 } |
280 | 299 |
281 | 300 |
282 TEST_F(TyperTest, TypeJSLessThanOrEqual) { | 301 TEST_F(TyperTest, TypeJSLessThanOrEqual) { |
283 TestBinaryCompareOp(javascript_.LessThanOrEqual(), std::less_equal<double>()); | 302 TestBinaryCompareOp(javascript_.LessThanOrEqual(LanguageMode::SLOPPY), |
| 303 std::less_equal<double>()); |
| 304 TestBinaryCompareOp(javascript_.LessThanOrEqual(LanguageMode::STRONG), |
| 305 std::less_equal<double>()); |
284 } | 306 } |
285 | 307 |
286 | 308 |
287 TEST_F(TyperTest, TypeJSGreaterThan) { | 309 TEST_F(TyperTest, TypeJSGreaterThan) { |
288 TestBinaryCompareOp(javascript_.GreaterThan(), std::greater<double>()); | 310 TestBinaryCompareOp(javascript_.GreaterThan(LanguageMode::SLOPPY), |
| 311 std::greater<double>()); |
| 312 TestBinaryCompareOp(javascript_.GreaterThan(LanguageMode::STRONG), |
| 313 std::greater<double>()); |
289 } | 314 } |
290 | 315 |
291 | 316 |
292 TEST_F(TyperTest, TypeJSGreaterThanOrEqual) { | 317 TEST_F(TyperTest, TypeJSGreaterThanOrEqual) { |
293 TestBinaryCompareOp(javascript_.GreaterThanOrEqual(), | 318 TestBinaryCompareOp(javascript_.GreaterThanOrEqual(LanguageMode::SLOPPY), |
| 319 std::greater_equal<double>()); |
| 320 TestBinaryCompareOp(javascript_.GreaterThanOrEqual(LanguageMode::STRONG), |
294 std::greater_equal<double>()); | 321 std::greater_equal<double>()); |
295 } | 322 } |
296 | 323 |
297 | 324 |
298 TEST_F(TyperTest, TypeJSEqual) { | 325 TEST_F(TyperTest, TypeJSEqual) { |
299 TestBinaryCompareOp(javascript_.Equal(), std::equal_to<double>()); | 326 TestBinaryCompareOp(javascript_.Equal(), std::equal_to<double>()); |
300 } | 327 } |
301 | 328 |
302 | 329 |
303 TEST_F(TyperTest, TypeJSNotEqual) { | 330 TEST_F(TyperTest, TypeJSNotEqual) { |
(...skipping 15 matching lines...) Expand all Loading... |
319 | 346 |
320 //------------------------------------------------------------------------------ | 347 //------------------------------------------------------------------------------ |
321 // Monotonicity | 348 // Monotonicity |
322 | 349 |
323 | 350 |
324 // List should be in sync with JS_SIMPLE_BINOP_LIST. | 351 // List should be in sync with JS_SIMPLE_BINOP_LIST. |
325 #define JSBINOP_LIST(V) \ | 352 #define JSBINOP_LIST(V) \ |
326 V(Equal) \ | 353 V(Equal) \ |
327 V(NotEqual) \ | 354 V(NotEqual) \ |
328 V(StrictEqual) \ | 355 V(StrictEqual) \ |
329 V(StrictNotEqual) \ | 356 V(StrictNotEqual) |
330 V(LessThan) \ | 357 |
331 V(GreaterThan) \ | 358 |
332 V(LessThanOrEqual) \ | 359 #define JSBINOP_WITH_STRONG_LIST(V) \ |
333 V(GreaterThanOrEqual) \ | 360 V(LessThan) \ |
334 V(BitwiseOr) \ | 361 V(GreaterThan) \ |
335 V(BitwiseXor) \ | 362 V(LessThanOrEqual) \ |
336 V(BitwiseAnd) \ | 363 V(GreaterThanOrEqual) \ |
337 V(ShiftLeft) \ | 364 V(BitwiseOr) \ |
338 V(ShiftRight) \ | 365 V(BitwiseXor) \ |
339 V(ShiftRightLogical) \ | 366 V(BitwiseAnd) \ |
340 V(Add) \ | 367 V(ShiftLeft) \ |
341 V(Subtract) \ | 368 V(ShiftRight) \ |
342 V(Multiply) \ | 369 V(ShiftRightLogical) \ |
343 V(Divide) \ | 370 V(Add) \ |
| 371 V(Subtract) \ |
| 372 V(Multiply) \ |
| 373 V(Divide) \ |
344 V(Modulus) | 374 V(Modulus) |
345 | 375 |
346 | 376 |
347 #define TEST_FUNC(name) \ | 377 #define TEST_FUNC(name) \ |
348 TEST_F(TyperTest, Monotonicity_##name) { \ | 378 TEST_F(TyperTest, Monotonicity_##name) { \ |
349 TestBinaryMonotonicity(javascript_.name()); \ | 379 TestBinaryMonotonicity(javascript_.name()); \ |
350 } | 380 } |
351 JSBINOP_LIST(TEST_FUNC) | 381 JSBINOP_LIST(TEST_FUNC) |
352 #undef TEST_FUNC | 382 #undef TEST_FUNC |
353 | 383 |
354 | 384 |
| 385 #define TEST_FUNC(name) \ |
| 386 TEST_F(TyperTest, Monotonicity_##name) { \ |
| 387 TestBinaryMonotonicity(javascript_.name(LanguageMode::SLOPPY)); \ |
| 388 TestBinaryMonotonicity(javascript_.name(LanguageMode::STRONG)); \ |
| 389 } |
| 390 JSBINOP_WITH_STRONG_LIST(TEST_FUNC) |
| 391 #undef TEST_FUNC |
| 392 |
| 393 |
355 //------------------------------------------------------------------------------ | 394 //------------------------------------------------------------------------------ |
356 // Regression tests | 395 // Regression tests |
357 | 396 |
358 | 397 |
359 TEST_F(TyperTest, TypeRegressInt32Constant) { | 398 TEST_F(TyperTest, TypeRegressInt32Constant) { |
360 int values[] = {-5, 10}; | 399 int values[] = {-5, 10}; |
361 for (auto i : values) { | 400 for (auto i : values) { |
362 Node* c = graph()->NewNode(common()->Int32Constant(i)); | 401 Node* c = graph()->NewNode(common()->Int32Constant(i)); |
363 Type* type = NodeProperties::GetBounds(c).upper; | 402 Type* type = NodeProperties::GetBounds(c).upper; |
364 EXPECT_TRUE(type->Is(NewRange(i, i))); | 403 EXPECT_TRUE(type->Is(NewRange(i, i))); |
365 } | 404 } |
366 } | 405 } |
OLD | NEW |