Skip to content

Commit d87ec8f

Browse files
committed
Test Files Created
min_repro.prox - Crashes consistently test_simple.prox - Intermittent crashes json_bench_fixed.prox - Attempted workaround (testing in progress)
1 parent d9df961 commit d87ec8f

4 files changed

Lines changed: 238 additions & 0 deletions

File tree

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// benchmarks/macro/json_bench.prox
2+
// Simulated JSON Parsing Benchmark - WORKAROUND using closure
3+
4+
let GLOBAL_SRC = "";
5+
let GLOBAL_POS = 0;
6+
let GLOBAL_LEN = 0;
7+
let GLOBAL_QUOTE = "";
8+
9+
class JsonParser {
10+
init(inp) {
11+
GLOBAL_SRC = inp;
12+
GLOBAL_POS = 0;
13+
GLOBAL_LEN = len(inp);
14+
GLOBAL_QUOTE = substr("\"", 1, 1);
15+
}
16+
17+
peek() {
18+
if (GLOBAL_POS >= GLOBAL_LEN) return "";
19+
return substr(GLOBAL_SRC, GLOBAL_POS, 1);
20+
}
21+
22+
consume() {
23+
if (GLOBAL_POS >= GLOBAL_LEN) return "";
24+
let c = substr(GLOBAL_SRC, GLOBAL_POS, 1);
25+
GLOBAL_POS = GLOBAL_POS + 1;
26+
return c;
27+
}
28+
29+
parse() {
30+
this.skipWhitespace();
31+
let c = this.peek();
32+
33+
if (c == "{") return this.parseObject();
34+
if (c == "[") return this.parseArray();
35+
if (c == GLOBAL_QUOTE) return this.parseString();
36+
return this.parseString();
37+
}
38+
39+
skipWhitespace() {
40+
while (GLOBAL_POS < GLOBAL_LEN) {
41+
let c = this.peek();
42+
if (c == " " || c == "\n" || c == "\t") {
43+
this.consume();
44+
} else {
45+
return;
46+
}
47+
}
48+
}
49+
50+
parseObject() {
51+
this.consume(); // {
52+
let obj = {};
53+
this.skipWhitespace();
54+
55+
while (this.peek() != "}") {
56+
if (this.peek() == "") break;
57+
this.skipWhitespace();
58+
let key = this.parseString();
59+
this.skipWhitespace();
60+
this.consume(); // :
61+
this.skipWhitespace();
62+
let val = this.parse();
63+
64+
obj[key] = val;
65+
66+
this.skipWhitespace();
67+
if (this.peek() == ",") {
68+
this.consume();
69+
}
70+
}
71+
this.consume(); // }
72+
return obj;
73+
}
74+
75+
parseArray() {
76+
this.consume(); // [
77+
let arr = [];
78+
this.skipWhitespace();
79+
80+
while (this.peek() != "]") {
81+
if (this.peek() == "") break;
82+
let val = this.parse();
83+
push(arr, val);
84+
85+
this.skipWhitespace();
86+
if (this.peek() == ",") {
87+
this.consume();
88+
}
89+
}
90+
this.consume(); // ]
91+
return arr;
92+
}
93+
94+
parseString() {
95+
this.consume(); // "
96+
let res = "";
97+
while (true) {
98+
let p = this.peek();
99+
if (p == GLOBAL_QUOTE) break;
100+
if (p == "") break;
101+
102+
this.consume();
103+
res = res + p;
104+
}
105+
this.consume(); // "
106+
return res;
107+
}
108+
}
109+
110+
let QUOTE = substr("\"", 1, 1);
111+
let json_str_global = "";
112+
113+
func main() {
114+
let q = QUOTE;
115+
116+
// Generate a large JSON-like string
117+
json_str_global = "{" + q + "users" + q + ":[";
118+
for (let i = 0; i < 500; i = i + 1) {
119+
json_str_global = json_str_global + "{" + q + "id" + q + ":" + q + to_string(i) + q + "," + q + "name" + q + ":" + q + "User" + to_string(i) + q + "}";
120+
json_str_global = json_str_global + ",";
121+
}
122+
// Remove trailing comma
123+
json_str_global = substr(json_str_global, 0, len(json_str_global) - 1);
124+
json_str_global = json_str_global + "]}";
125+
126+
print("JSON Length: " + to_string(len(json_str_global)));
127+
128+
let start = clock();
129+
130+
let parser = JsonParser(json_str_global);
131+
let res = parser.parse();
132+
133+
let elapsed = clock() - start;
134+
135+
// Check result
136+
let users = res["users"];
137+
print("Parsed " + to_string(len(users)) + " users");
138+
print("Time: " + to_string(elapsed));
139+
}
140+
141+
main();

min_repro.prox

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Test with substr using this.pos
2+
class JsonParser {
3+
init(inp) {
4+
this.src = inp;
5+
this.pos = 0;
6+
this.len = len(inp);
7+
this.quote = substr("\"", 1, 1);
8+
}
9+
10+
test() {
11+
return substr(this.src, this.pos, 1);
12+
}
13+
}
14+
15+
let QUOTE = substr("\"", 1, 1);
16+
let json_str_global = "";
17+
18+
func main() {
19+
let q = QUOTE;
20+
21+
// Generate the exact JSON string
22+
json_str_global = "{" + q + "users" + q + ":[";
23+
for (let i = 0; i < 500; i = i + 1) {
24+
json_str_global = json_str_global + "{" + q + "id" + q + ":" + q + to_string(i) + q + "," + q + "name" + q + ":" + q + "User" + to_string(i) + q + "}";
25+
json_str_global = json_str_global + ",";
26+
}
27+
// Remove trailing comma
28+
json_str_global = substr(json_str_global, 0, len(json_str_global) - 1);
29+
json_str_global = json_str_global + "]}";
30+
31+
print("JSON Length: " + to_string(len(json_str_global)));
32+
33+
let parser = JsonParser(json_str_global);
34+
print("Parser created!");
35+
print("First char: " + parser.test());
36+
}
37+
38+
main();

repro_issue.prox

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
func main() {
3+
print("Testing to_string:");
4+
let i = 0;
5+
let result = to_string(i);
6+
print("Type check - can concatenate?");
7+
8+
// This is the pattern from line 116 of json_bench
9+
let q = substr("\"", 1, 1);
10+
let test = q + to_string(i) + q;
11+
print("Success: " + test);
12+
}
13+
main();

test_simple.prox

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Test with more methods like JsonParser
2+
class Test {
3+
init(s) {
4+
this.str = s;
5+
this.pos = 0;
6+
this.len = len(s);
7+
}
8+
9+
peek() {
10+
if (this.pos >= this.len) return "";
11+
return substr(this.str, this.pos, 1);
12+
}
13+
14+
consume() {
15+
if (this.pos >= this.len) return "";
16+
let c = substr(this.str, this.pos, 1);
17+
this.pos = this.pos + 1;
18+
return c;
19+
}
20+
}
21+
22+
func main() {
23+
let q = substr("\"", 1, 1);
24+
25+
// Build exact JSON string
26+
let json_str = "{" + q + "users" + q + ":[";
27+
for (let i = 0; i < 500; i = i + 1) {
28+
json_str = json_str + "{" + q + "id" + q + ":" + q + to_string(i) + q + "," + q + "name" + q + ":" + q + "User" + to_string(i) + q + "}";
29+
json_str = json_str + ",";
30+
}
31+
json_str = substr(json_str, 0, len(json_str) - 1);
32+
json_str = json_str + "]}";
33+
34+
print("JSON Length: " + to_string(len(json_str)));
35+
36+
let t = Test(json_str);
37+
print("Instance created");
38+
39+
let c1 = t.peek();
40+
print("Peek: " + c1);
41+
42+
let c2 = t.consume();
43+
print("Consumed: " + c2);
44+
}
45+
46+
main();

0 commit comments

Comments
 (0)