A versionbits-style fluent chain (the #323 hang): every link returns * Tester&, and the evaluator re-evaluates a call's receiver for template * substitution, so without a memo an N-link chain costs 2^N evaluations. The * per-file step cap that used to contain it is gone; the per-evaluation memo * must keep the work polynomial AND every link must resolve. */
| 16563 | * per-file step cap that used to contain it is gone; the per-evaluation memo |
| 16564 | * must keep the work polynomial AND every link must resolve. */ |
| 16565 | static char *clsp_chain_source(int links, int stmts) { |
| 16566 | size_t sz = 512 + (size_t)stmts * (32 + (size_t)links * 40); |
| 16567 | char *src = malloc(sz); |
| 16568 | if (!src) |
| 16569 | return NULL; |
| 16570 | size_t pos = (size_t)snprintf(src, sz, |
| 16571 | "struct Tester {\n" |
| 16572 | " Tester& Mine(int h, int t, int v);\n" |
| 16573 | " Tester& TestDefined();\n" |
| 16574 | " Tester& TestStateSinceHeight(int h);\n" |
| 16575 | " Tester& Reset();\n" |
| 16576 | "};\n" |
| 16577 | "void run() {\n" |
| 16578 | " Tester t;\n"); |
| 16579 | for (int s = 0; s < stmts; s++) { |
| 16580 | pos += (size_t)snprintf(src + pos, sz - pos, " t.Reset()"); |
| 16581 | for (int l = 0; l < links; l++) { |
| 16582 | if (l % 3 == 0) |
| 16583 | pos += (size_t)snprintf(src + pos, sz - pos, ".Mine(%d, %d, 0x100)", l, l); |
| 16584 | else if (l % 3 == 1) |
| 16585 | pos += (size_t)snprintf(src + pos, sz - pos, ".TestDefined()"); |
| 16586 | else |
| 16587 | pos += (size_t)snprintf(src + pos, sz - pos, ".TestStateSinceHeight(%d)", l); |
| 16588 | } |
| 16589 | pos += (size_t)snprintf(src + pos, sz - pos, ";\n"); |
| 16590 | } |
| 16591 | snprintf(src + pos, sz - pos, "}\n"); |
| 16592 | return src; |
| 16593 | } |
| 16594 | |
| 16595 | TEST(clsp_issue1527_fluent_chain_work_is_polynomial) { |
| 16596 | enum { LINKS = 14, STMTS = 3 }; |