Skip to content

Commit 804da69

Browse files
committed
Optimize playground: extract JS, use file-based examples, remove unused clangd
- Extract JavaScript from HTML to separate playground.js file for better maintainability - Move all code examples to individual .c files in examples/ directory - Load examples via fetch() to avoid template literal escaping issues - Fix initial page load to show default example immediately - Update UI: smaller, right-aligned compilation timing display - Remove unused clangd WASM files and LSP worker (42MB savings) - Optimize CI workflow to only build clang (not clang-tools-extra) - Update .gitignore to reflect simplified build artifacts
1 parent 29d6c55 commit 804da69

20 files changed

+839
-934
lines changed

.github/workflows/build-playground.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
cd build-wasm
4343
emcmake cmake -G Ninja \
4444
-DCMAKE_BUILD_TYPE=Release \
45-
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" \
45+
-DLLVM_ENABLE_PROJECTS="clang" \
4646
-DLLVM_TARGETS_TO_BUILD="WebAssembly" \
4747
-DLLVM_ENABLE_THREADS=OFF \
4848
-DLLVM_ENABLE_EH=OFF \
@@ -59,24 +59,20 @@ jobs:
5959
-DCMAKE_EXE_LINKER_FLAGS="-sEXPORTED_RUNTIME_METHODS=callMain -sEXIT_RUNTIME=0 -sALLOW_MEMORY_GROWTH=1" \
6060
../llvm
6161
62-
- name: Build Null-Safe Clang and clangd WASM
62+
- name: Build Null-Safe Clang WASM
6363
run: |
6464
cd build-wasm
65-
ninja clang clangd
65+
ninja clang
6666
6767
- name: Prepare artifacts
6868
run: |
6969
mkdir -p artifacts
7070
cp build-wasm/bin/clang.wasm artifacts/clang-nullsafe.wasm
7171
cp build-wasm/bin/clang.js artifacts/clang-nullsafe.js
72-
cp build-wasm/bin/clangd.wasm artifacts/clangd-nullsafe.wasm
73-
cp build-wasm/bin/clangd.js artifacts/clangd-nullsafe.js
7472
7573
# Compress for better download speeds
7674
gzip -k artifacts/clang-nullsafe.wasm
7775
gzip -k artifacts/clang-nullsafe.js
78-
gzip -k artifacts/clangd-nullsafe.wasm
79-
gzip -k artifacts/clangd-nullsafe.js
8076
8177
ls -lh artifacts/
8278
@@ -95,20 +91,14 @@ jobs:
9591
artifacts/clang-nullsafe.js
9692
artifacts/clang-nullsafe.wasm.gz
9793
artifacts/clang-nullsafe.js.gz
98-
artifacts/clangd-nullsafe.wasm
99-
artifacts/clangd-nullsafe.js
100-
artifacts/clangd-nullsafe.wasm.gz
101-
artifacts/clangd-nullsafe.js.gz
10294
body: |
10395
## Null-Safe Clang Playground WASM Files
10496
105-
This release contains the WebAssembly build of Null-Safe Clang and clangd for use in the browser playground.
97+
This release contains the WebAssembly build of Null-Safe Clang for use in the browser playground.
10698
10799
### Files:
108100
- `clang-nullsafe.wasm` - WebAssembly compiler binary (~63MB)
109101
- `clang-nullsafe.js` - Emscripten JavaScript glue code
110-
- `clangd-nullsafe.wasm` - WebAssembly language server binary (~80MB)
111-
- `clangd-nullsafe.js` - Emscripten JavaScript glue code for clangd
112102
- `*.gz` - Compressed versions for faster downloads
113103
114104
### Usage:

nullsafe-playground/.gitignore

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
# Generated WASM files (too large to commit, will be built from source or downloaded from releases)
22
clang.wasm
33
clang.js
4-
clangd.wasm
5-
clangd.js
6-
clang-nullsafe.wasm
7-
clang-nullsafe.js
8-
clangd-nullsafe.wasm
9-
clangd-nullsafe.js
10-
clang-mainline.wasm
11-
clang-mainline.js
124

135
# Python cache
146
__pycache__/

nullsafe-playground/clangd.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

nullsafe-playground/clangd.wasm

-41.2 MB
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// AND pattern narrows both operands
2+
void process(int* p, int* q) {
3+
if (p && q) {
4+
*p = *q; // OK - both non-null
5+
}
6+
}
7+
8+
void either_or(int* p, int* q) {
9+
if (p || q) {
10+
*p = 42; // warning - p might still be null!
11+
}
12+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// From cJSON.c:1019-1027 (print_string_ptr function)
2+
// https://github.com/DaveGamble/cJSON/blob/c859b25da0/cJSON.c#L1019-L1027
3+
// Null-safety warning: dereferencing nullable pointer at line 1022
4+
#define NULL ((void*)0)
5+
6+
typedef unsigned char * output_t;
7+
8+
// Simplified version of actual cJSON code with null-safety warning
9+
void escape_json_string(const unsigned char *input, output_t output_pointer) {
10+
*output_pointer++ = '"';
11+
12+
// Line 1022: warning on *input_pointer dereference
13+
for (const unsigned char *input_pointer = input;
14+
*input_pointer != '\0'; // warning: input_pointer might be NULL!
15+
(void)input_pointer++, output_pointer++) {
16+
17+
if ((*input_pointer > 31) && (*input_pointer != '"')) {
18+
*output_pointer = *input_pointer; // warnings here too
19+
} else {
20+
*output_pointer++ = '\\';
21+
*output_pointer = *input_pointer;
22+
}
23+
}
24+
*output_pointer = '"';
25+
}
26+
27+
void example(void) {
28+
unsigned char buf[100];
29+
escape_json_string(NULL, buf); // Crash!
30+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Null check required before dereference
2+
void process(int* data) {
3+
if (!data) {
4+
// process...
5+
}
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Early returns narrow type for rest of function
2+
void process(char* str) {
3+
if (!str) return; // guard clause
4+
5+
// str is now proven non-null
6+
*str = 'x'; // OK
7+
}
8+
9+
void multi_guard(char* p, char* q) {
10+
if (!p || !q) return;
11+
12+
// Both p and q are non-null here
13+
*p = *q; // OK
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Else branch knows condition was false
2+
void example(int* data) {
3+
if (data) {
4+
*data = 42; // OK
5+
} else {
6+
*data = 0; // warning - data is null here!
7+
}
8+
}
9+
10+
void inverted(int* data) {
11+
if (!data) {
12+
return;
13+
}
14+
*data = 42; // OK - data is non-null
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Functions can invalidate narrowing
2+
void may_modify(int** ptr);
3+
4+
void example(int* data) {
5+
if (data) {
6+
may_modify(&data); // might set data to null
7+
*data = 42; // warning - data might be null now!
8+
}
9+
}

0 commit comments

Comments
 (0)