MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / clsp_chain_source

Function clsp_chain_source

tests/test_c_lsp.c:16565–16593  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

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. */
16565static 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
16595TEST(clsp_issue1527_fluent_chain_work_is_polynomial) {
16596 enum { LINKS = 14, STMTS = 3 };

Callers 1

test_c_lsp.cFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected