-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.w
More file actions
2084 lines (1890 loc) · 117 KB
/
Copy pathbuild.w
File metadata and controls
2084 lines (1890 loc) · 117 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use std.build
use build.runtime
use build.selfhost
use build.pcre2
use build.zlib
use build.seed
use build.emit_c
use build.compiler
use build.clang_resource
use build.retention
use build.release_uat
use build.package
use build.sdk
use std.sysinfo
fn build_project_dirname(path: str) -> str:
var last_slash = -1
for i in 0..path.len() as i32:
if path.byte_at(i as i64) == 47:
last_slash = i
if last_slash < 0:
return "."
if last_slash == 0:
return "/"
path.slice(0, last_slash as i64)
fn with_object_target(name: str, compiler: str, source: str, output: str, opt: str, dep: str) -> Target:
var target = target_new(.Action, name, "").output(output)
target.action = run_with_compiler_build_action
target = target.compiler(compiler)
target = target.input(source)
target = target.arg("--emit-obj")
target = target.arg("--no-prelude")
target = target.arg(opt)
target = target.write_scope("out/command/" ++ name)
target = target.write_scope(build_project_dirname(output))
if dep.len() > 0:
target = target.dep(dep)
target
fn with_ir_target(name: str, compiler: str, source: str, output: str, dep: str) -> Target:
var target = target_new(.Action, name, "").output(output)
target.action = run_with_compiler_ir_action
target = target.compiler(compiler)
target = target.input(source)
target = target.arg("--no-prelude")
target = target.write_scope(build_project_dirname(output))
target = target.write_scope("out/command/" ++ name)
if dep.len() > 0:
target = target.dep(dep)
target
fn with_ir_target_overflow(name: str, compiler: str, source: str, output: str, dep: str, overflow: str) -> Target:
var target = with_ir_target(name, compiler, source, output, dep)
target = target.arg("overflow=" ++ overflow)
target
fn run_write_empty_file_action(ctx: ActionCtx) -> i32:
let output = ctx.output()
if output.len() == 0:
ctx.diagnostics().error(ctx.target_name() ++ ": missing output")
return 1
let dir = build_project_dirname(output)
let fs = ctx.fs()
if fs.mkdir_all(dir) != 0:
ctx.diagnostics().error(ctx.target_name() ++ ": could not create output directory: " ++ dir)
return 1
if fs.write_text(output, "") != 0:
ctx.diagnostics().error(ctx.target_name() ++ ": could not write: " ++ output)
return 1
0
fn run_cross_unsupported_action(ctx: ActionCtx) -> i32:
let args = ctx.args()
let target = if args.len() > 0: args.get(0) else: ""
if target.len() == 0:
ctx.diagnostics().error("cross: cross-target compilation is not implemented yet; set CROSS_TARGET=<triple> or use `with build --target <triple>` for the compiler diagnostic")
else:
ctx.diagnostics().error("cross: cross-target compilation for '" ++ target ++ "' is not implemented yet")
1
fn empty_file_target(name: str, output: str) -> Target:
var target = target_new(.Action, name, "").output(output)
target.action = run_write_empty_file_action
target = target.write_scope(build_project_dirname(output))
target
fn run_prepare_bootstrap_link_root_action(ctx: ActionCtx) -> i32:
// Old seed compilers may prefer out/lib before out/bootstrap-lib. Remove
// stale unversioned runtime probes so stage1 selects the freshly generated
// bootstrap runtime instead of yesterday's out/lib objects.
let fs = ctx.fs()
let stale_runtime_objects: Vec[str] = Vec.new()
stale_runtime_objects.push("out/lib/cimport_stubs.o")
stale_runtime_objects.push("out/lib/rt_core.o")
stale_runtime_objects.push("out/lib/rt_darwin_aarch64.o")
stale_runtime_objects.push("out/lib/rt_linux_x86_64.o")
stale_runtime_objects.push("out/lib/rt_windows_x86_64.o")
stale_runtime_objects.push("out/lib/compat_runtime.o")
stale_runtime_objects.push("out/lib/panic_runtime.o")
stale_runtime_objects.push("out/lib/regex_runtime.o")
stale_runtime_objects.push("out/lib/channel_runtime.o")
stale_runtime_objects.push("out/lib/fiber_runtime.o")
stale_runtime_objects.push("out/lib/fiber.o")
stale_runtime_objects.push("out/lib/fiber_asm.o")
stale_runtime_objects.push("out/lib/fiber_stubs.o")
for i in 0..stale_runtime_objects.len() as i32:
let _remove_stale = fs.remove_file(stale_runtime_objects.get(i as i64))
let output = ctx.output()
if fs.mkdir_all(build_project_dirname(output)) != 0:
ctx.diagnostics().error(ctx.target_name() ++ ": could not create output directory: " ++ build_project_dirname(output))
return 1
if fs.write_text(output, "ok\n") != 0:
ctx.diagnostics().error(ctx.target_name() ++ ": could not write: " ++ output)
return 1
0
fn target_with_embedded_stdlib_inputs(target: Target, ctx: &BuildCtx) -> Target:
var out = target
let files = ctx.fs().list_files("lib/std")
for i in 0..files.len() as i32:
let path = files.get(i as i64)
if path.ends_with(".w") and not path.starts_with("lib/std/re/"):
out = out.input(path)
out
fn target_with_compiler_c_export_audit_inputs(target: Target, ctx: &BuildCtx) -> Target:
var out = target
let roots: Vec[str] = Vec.new()
roots.push("src")
roots.push("rt")
roots.push("lib/std")
for ri in 0..roots.len() as i32:
let files = ctx.fs().list_files(roots.get(ri as i64))
for fi in 0..files.len() as i32:
let path = files.get(fi as i64)
if path.ends_with(".w"):
out = out.input(path)
out
fn target_with_compiler_source_inputs(target: Target, ctx: &BuildCtx) -> Target:
var out = target
let roots: Vec[str] = Vec.new()
roots.push("src")
roots.push("rt")
roots.push("build")
roots.push("lib/std")
for ri in 0..roots.len() as i32:
let files = ctx.fs().list_files(roots.get(ri as i64))
for fi in 0..files.len() as i32:
let path = files.get(fi as i64)
if path.ends_with(".w"):
out = out.input(path)
out.input("build.w")
fn build_project_trim_line(text: str) -> str:
var end = 0
while end < text.len() as i32:
let ch = text.byte_at(end as i64)
if ch == 10 or ch == 13:
break
end = end + 1
var start = 0
while start < end:
let ch = text.byte_at(start as i64)
if ch != 9 and ch != 32:
break
start = start + 1
while end > start:
let ch = text.byte_at((end - 1) as i64)
if ch != 9 and ch != 32:
break
end = end - 1
text.slice(start as i64, end as i64)
fn target_with_version_inputs(target: Target, ctx: &BuildCtx) -> Target:
var out = target
out = out.arg("version-env=" ++ env("WITH_VERSION"))
let fs = ctx.fs()
if not fs.exists(".git/HEAD"):
return out
out = out.input(".git/HEAD")
let head = build_project_trim_line(fs.read_text(".git/HEAD"))
if head.starts_with("ref: "):
let ref_path = ".git/" ++ head.slice(5, head.len())
if fs.exists(ref_path):
out = out.input(ref_path)
else if fs.exists(".git/packed-refs"):
out = out.input(".git/packed-refs")
out
fn target_with_live_targets(target: Target, graph: &Build) -> Target:
var out = target
for i in 0..graph.targets.len() as i32:
out = out.arg("live-target=" ++ graph.targets.get(i as i64).name)
out
type HostRuntimeSpec:
platform_source: str
compat_source: str
bootstrap_platform_object: str
platform_object: str
platform_install_object: str
platform_symbol: str
opposite_bootstrap_platform_blob: str
opposite_platform_blob: str
opposite_platform_symbol: str
second_opposite_bootstrap_platform_blob: str
second_opposite_platform_blob: str
second_opposite_platform_symbol: str
fiber_core_source: str
fiber_asm_source: str
fn host_exe_suffix() -> str:
if os() == "Windows":
return ".exe"
""
fn host_bin(path: str) -> str:
path ++ host_exe_suffix()
fn bootstrap_compiler_bin(name: str) -> str:
host_bin("out/bootstrap/bin/" ++ name)
fn stage_compiler_bin(name: str) -> str:
host_bin("out/stage/bin/" ++ name)
fn stage_compiler_obj(name: str) -> str:
"out/stage/bin/" ++ name
fn release_compiler_bin(name: str) -> str:
host_bin("out/release/bin/" ++ name)
fn release_platform_asset_bin() -> str:
let host_os = os()
let host_arch = arch()
if host_os == "Macos" and (host_arch == "armv8" or host_arch == "aarch64"):
return "out/release/with-darwin-aarch64"
if host_os == "Linux" and host_arch == "x86_64":
return "out/release/with-linux-x86_64"
if host_os == "Windows" and host_arch == "x86_64":
return "out/release/with-windows-x86_64.exe"
release_compiler_bin("with")
// The platform asset target only exists when the asset is a distinct copy of
// the release compiler; on unknown hosts release_platform_asset_bin() falls
// back to the compiler path itself and there is nothing separate to produce.
fn release_platform_asset_is_distinct() -> bool:
release_platform_asset_bin() != release_compiler_bin("with")
fn release_uat_platform_asset_dep(t: Target) -> Target:
if release_platform_asset_is_distinct():
return t.dep("release-platform-asset")
t
fn host_runtime_spec() -> HostRuntimeSpec:
if os() == "Linux" and arch() == "x86_64":
return HostRuntimeSpec {
platform_source: "rt/linux_x86_64.w",
compat_source: "rt/compat_runtime.w",
bootstrap_platform_object: "out/bootstrap-lib/rt_linux_x86_64.o",
platform_object: "out/lib/rt_linux_x86_64.o",
platform_install_object: "rt_linux_x86_64.o",
platform_symbol: "rt_linux_x86_64_o",
opposite_bootstrap_platform_blob: "out/bootstrap-lib/empty_rt_darwin_aarch64.bin",
opposite_platform_blob: "out/lib/empty_rt_darwin_aarch64.bin",
opposite_platform_symbol: "rt_darwin_aarch64_o",
second_opposite_bootstrap_platform_blob: "out/bootstrap-lib/empty_rt_windows_x86_64.bin",
second_opposite_platform_blob: "out/lib/empty_rt_windows_x86_64.bin",
second_opposite_platform_symbol: "rt_windows_x86_64_o",
fiber_core_source: "rt/fiber_core_darwin.w",
fiber_asm_source: "runtime/fiber_asm_linux_x86_64.s",
}
if os() == "Windows" and arch() == "x86_64":
return HostRuntimeSpec {
platform_source: "rt/windows_x86_64.w",
compat_source: "rt/compat_runtime.w",
bootstrap_platform_object: "out/bootstrap-lib/rt_windows_x86_64.o",
platform_object: "out/lib/rt_windows_x86_64.o",
platform_install_object: "rt_windows_x86_64.o",
platform_symbol: "rt_windows_x86_64_o",
opposite_bootstrap_platform_blob: "out/bootstrap-lib/empty_rt_darwin_aarch64.bin",
opposite_platform_blob: "out/lib/empty_rt_darwin_aarch64.bin",
opposite_platform_symbol: "rt_darwin_aarch64_o",
second_opposite_bootstrap_platform_blob: "out/bootstrap-lib/empty_rt_linux_x86_64.bin",
second_opposite_platform_blob: "out/lib/empty_rt_linux_x86_64.bin",
second_opposite_platform_symbol: "rt_linux_x86_64_o",
fiber_core_source: "rt/fiber_core_windows.w",
fiber_asm_source: "runtime/fiber_asm_windows_x86_64.s",
}
HostRuntimeSpec {
platform_source: "rt/darwin_aarch64.w",
compat_source: "rt/compat_runtime.w",
bootstrap_platform_object: "out/bootstrap-lib/rt_darwin_aarch64.o",
platform_object: "out/lib/rt_darwin_aarch64.o",
platform_install_object: "rt_darwin_aarch64.o",
platform_symbol: "rt_darwin_aarch64_o",
opposite_bootstrap_platform_blob: "out/bootstrap-lib/empty_rt_linux_x86_64.bin",
opposite_platform_blob: "out/lib/empty_rt_linux_x86_64.bin",
opposite_platform_symbol: "rt_linux_x86_64_o",
second_opposite_bootstrap_platform_blob: "out/bootstrap-lib/empty_rt_windows_x86_64.bin",
second_opposite_platform_blob: "out/lib/empty_rt_windows_x86_64.bin",
second_opposite_platform_symbol: "rt_windows_x86_64_o",
fiber_core_source: "rt/fiber_core_darwin.w",
fiber_asm_source: "runtime/fiber_asm_aarch64.s",
}
fn release_asset_for_host() -> str:
if os() == "Linux" and arch() == "x86_64":
return "with-linux-x86_64"
if os() == "Macos" and (arch() == "armv8" or arch() == "aarch64"):
return "with-darwin-aarch64"
if os() == "Windows" and arch() == "x86_64":
return "with-windows-x86_64.exe"
"with-darwin-aarch64"
// "with-darwin-aarch64" -> "darwin-aarch64"
fn release_platform_tag() -> str:
let asset = release_asset_for_host()
if asset.starts_with("with-"):
var tag = asset.slice(5, asset.len())
if tag.ends_with(".exe"):
tag = tag.slice(0, tag.len() - 4)
return tag
asset
fn supported_release_platform_tag() -> str:
if os() == "Linux" and arch() == "x86_64":
return "linux-x86_64"
if os() == "Macos" and (arch() == "armv8" or arch() == "aarch64"):
return "darwin-aarch64"
if os() == "Windows" and arch() == "x86_64":
return "windows-x86_64"
""
// ".deps/llvm-<ver>-<host>" -> "llvm-<ver>-<host>"
fn llvm_sdk_dir_basename() -> str:
let prefix = compiler_default_llvm_prefix()
if prefix.starts_with(".deps/"):
return prefix.slice(6, prefix.len())
prefix
fn llvm_sdk_asset_for_host() -> str:
"with-llvm-sdk-" ++ compiler_llvm_version() ++ "-" ++ release_platform_tag() ++ ".tar.gz"
fn release_package_asset_for_platform(platform: str) -> str:
if platform == "darwin-aarch64":
return "with-darwin-aarch64"
if platform == "linux_x86_64" or platform == "linux-x86_64":
return "with-linux-x86_64"
if platform == "windows_x86_64" or platform == "windows-x86_64":
return "with-windows-x86_64.exe"
"with-unsupported"
fn package_platform_target(name: str, platform: str, ctx: &BuildCtx) -> Target:
let asset = release_package_asset_for_platform(platform)
var target = target_new(.Action, name, "").output("out/release/" ++ name ++ ".passed")
target.action = run_package_platform_release_action
target = target.arg(asset)
target = target.arg(platform)
target = target.arg(release_compiler_bin("with"))
target = target.arg(compiler_default_llvm_prefix())
target = target.input("src/version")
target = target.input(release_compiler_bin("with"))
target = target.input("build/package.w")
target = target.extra_output("out/release/" ++ asset)
target = target.extra_output("out/release/" ++ asset ++ ".sha256")
target = target.write_scope("out/release")
target = target.write_scope("out/command/" ++ name)
target = target.timeout(600000)
target = target_with_version_inputs(move target, ctx)
if supported_release_platform_tag() == platform:
target = target.dep("build")
target = target.dep("fixpoint")
target = target.dep("release-uat")
target
fn package_current_host_target() -> Target:
var target = target_new(.Group, "package-current-host", "")
let platform = supported_release_platform_tag()
if platform == "darwin-aarch64":
return target.dep("package-darwin-aarch64")
if platform == "linux-x86_64":
return target.dep("package-linux-x86_64")
if platform == "windows-x86_64":
return target.dep("package-windows-x86_64")
target.dep("package-darwin-aarch64")
fn package_llvm_sdk_platform_target(name: str, platform: str, prefix: str, build_cache: str) -> Target:
let asset = sdk_asset_for_platform(platform)
let sdk_base = "llvm-" ++ compiler_llvm_version() ++ "-" ++ sdk_host_tag_for_platform(platform)
var target = target_new(.Action, name, "").output("out/release/" ++ name ++ ".passed")
target.action = run_package_llvm_sdk_action
target = target.arg(platform)
target = target.arg(prefix)
target = target.arg(build_cache)
target = target.arg(asset)
target = target.arg(sdk_base)
target = target.input(prefix)
target = target.input(build_cache)
target = target.input("build/sdk.w")
target = target.extra_output("out/release/" ++ asset)
target = target.extra_output("out/release/" ++ asset ++ ".sha256")
target = target.extra_output("out/release/" ++ asset ++ ".manifest")
target = target.write_scope("out/release")
target = target.write_scope("out/command/" ++ name)
target.timeout(1800000)
fn package_llvm_sdk_current_host_target() -> Target:
var target = target_new(.Group, "package-llvm-sdk", "")
let platform = sdk_current_platform()
if platform == "darwin-aarch64":
return target.dep("package-llvm-sdk-darwin-aarch64")
if platform == "linux-x86_64":
return target.dep("package-llvm-sdk-linux-x86_64")
if platform == "windows-x86_64":
return target.dep("package-llvm-sdk-windows-x86_64")
target.dep("package-llvm-sdk-darwin-aarch64")
fn sdk_source_target(name: str, url: str, sha256: str, archive: str, source_root: str, source_dir: str, marker: str) -> Target:
var target = target_new(.Action, name, "").output(marker)
target.action = run_sdk_source_tar_gz_action
target = target.arg(url)
target = target.arg(sha256)
target = target.arg(archive)
target = target.arg(source_root)
target = target.arg(source_dir)
target = target.input("build/https_fetch.w")
target = target.input("build/zlib_gunzip.w")
target = target.write_scope(source_root)
target = target.write_scope("out/command/" ++ name)
target = target.allow_network()
target.timeout(1800000)
fn sdk_bootstrap_prefix_arg(ctx: &BuildCtx, platform: str) -> str:
let explicit = ctx.env_input("SDK_BOOTSTRAP_PREFIX")
if explicit.len() > 0:
return explicit
let llvm_prefix = ctx.env_input("LLVM_PREFIX")
if llvm_prefix.len() > 0:
return llvm_prefix
sdk_default_prefix_for_platform(platform)
fn sdk_output_prefix_arg(ctx: &BuildCtx, platform: str) -> str:
let explicit = ctx.env_input("SDK_OUTPUT_PREFIX")
if explicit.len() > 0:
return explicit
sdk_output_prefix_for_platform(platform)
fn sdk_build_root_arg(ctx: &BuildCtx, platform: str) -> str:
let explicit = ctx.env_input("SDK_BUILD_ROOT")
if explicit.len() > 0:
return explicit
sdk_output_build_root_for_platform(platform)
fn sdk_jobs_arg(ctx: &BuildCtx) -> str:
ctx.env_input("PARALLEL_JOBS")
fn sdk_ninja_target(ctx: &BuildCtx) -> Target:
let platform = sdk_current_platform()
let bootstrap_prefix = sdk_bootstrap_prefix_arg(ctx, platform)
let output_prefix = sdk_output_prefix_arg(ctx, platform)
let build_root = sdk_build_root_arg(ctx, platform)
var target = target_new(.Action, "sdk-ninja", "").output(output_prefix ++ "/bin/ninja" ++ host_exe_suffix())
target.action = run_sdk_ninja_action
target = target.arg(bootstrap_prefix)
target = target.arg(output_prefix)
target = target.arg(sdk_ninja_source_dir())
target = target.arg(build_root ++ "/ninja-" ++ sdk_host_tag_for_platform(platform))
target = target.arg(sdk_jobs_arg(ctx))
target = target.input(sdk_ninja_source_marker())
target = target.input(bootstrap_prefix)
target = target.input("build/sdk.w")
target = target.write_scope(output_prefix)
target = target.write_scope(build_root)
target = target.write_scope("out/command/sdk-ninja")
target = target.dep("sdk-ninja-source")
target.timeout(1800000)
fn sdk_cmake_target(ctx: &BuildCtx) -> Target:
let platform = sdk_current_platform()
let bootstrap_prefix = sdk_bootstrap_prefix_arg(ctx, platform)
let output_prefix = sdk_output_prefix_arg(ctx, platform)
let build_root = sdk_build_root_arg(ctx, platform)
var target = target_new(.Action, "sdk-cmake", "").output(output_prefix ++ "/bin/cmake" ++ host_exe_suffix())
target.action = run_sdk_cmake_action
target = target.arg(bootstrap_prefix)
target = target.arg(output_prefix)
target = target.arg(sdk_cmake_source_dir())
target = target.arg(build_root ++ "/cmake-" ++ sdk_host_tag_for_platform(platform))
target = target.arg(sdk_jobs_arg(ctx))
target = target.input(sdk_cmake_source_marker())
target = target.input(output_prefix ++ "/bin/ninja" ++ host_exe_suffix())
target = target.input(bootstrap_prefix)
target = target.input("build/sdk.w")
target = target.write_scope(output_prefix)
target = target.write_scope(build_root)
target = target.write_scope("out/command/sdk-cmake")
target = target.dep("sdk-ninja")
target = target.dep("sdk-cmake-source")
target.timeout(3600000)
fn sdk_llvm_target(ctx: &BuildCtx) -> Target:
let platform = sdk_current_platform()
let bootstrap_prefix = sdk_bootstrap_prefix_arg(ctx, platform)
let output_prefix = sdk_output_prefix_arg(ctx, platform)
let build_root = sdk_build_root_arg(ctx, platform)
var target = target_new(.Action, "sdk-llvm", "").output(if platform == "windows-x86_64": output_prefix ++ "/lib/libclang.lib" else: output_prefix ++ "/lib/libclang.a")
target.action = run_sdk_llvm_action
target = target.arg(bootstrap_prefix)
target = target.arg(output_prefix)
target = target.arg(sdk_llvm_source_dir())
target = target.arg(build_root ++ "/llvm-" ++ compiler_llvm_version() ++ "-" ++ sdk_host_tag_for_platform(platform))
target = target.arg(sdk_jobs_arg(ctx))
target = target.arg(ctx.env_input("LLVM_TARGETS_TO_BUILD"))
target = target.arg(ctx.env_input("SDKROOT"))
target = target.arg(ctx.env_input("MACOSX_DEPLOYMENT_TARGET"))
target = target.arg(ctx.env_input("SDK_WINDOWS_MT"))
target = target.input(sdk_llvm_source_marker())
target = target.input(output_prefix ++ "/bin/cmake" ++ host_exe_suffix())
target = target.input(output_prefix ++ "/bin/ninja" ++ host_exe_suffix())
target = target.input(bootstrap_prefix)
target = target.input("build/sdk.w")
target = target.write_scope(output_prefix)
target = target.write_scope(build_root)
target = target.write_scope("out/command/sdk-llvm")
target = target.dep("sdk-cmake")
target = target.dep("sdk-llvm-source")
target.timeout(21600000)
fn sdk_group_target() -> Target:
var target = target_new(.Group, "sdk", "")
target = target.dep("sdk-ninja")
target = target.dep("sdk-cmake")
target.dep("sdk-llvm")
fn sdk_package_target(ctx: &BuildCtx) -> Target:
let platform = sdk_current_platform()
var target = package_llvm_sdk_platform_target("sdk-package", platform, sdk_output_prefix_arg(ctx, platform), sdk_output_llvm_cache_for_platform(platform))
target.dep("sdk")
fn install_file_target(name: str, source: str, dest: str, mode: str, dep: str) -> Target:
var target = target_new(.Install, name, source).output(dest)
target = target.input(source)
target = target.arg(mode)
if dep.len() > 0:
target = target.dep(dep)
target
fn build_project_join(left: str, right: str) -> str:
if left.len() == 0:
return right
if right.len() == 0:
return left
if left.ends_with("/"):
return left ++ right
left ++ "/" ++ right
fn build_project_abs(root: str, path: str) -> str:
if path.len() > 0 and path.byte_at(0) == 47:
return path
build_project_join(root, path)
fn build_trim_trailing_line_endings(text: str) -> str:
var end = text.len()
while end > 0:
let ch = text.byte_at(end - 1)
if ch != 10 and ch != 13:
break
end = end - 1
text.slice(0, end)
fn build_replace_once(text: str, needle: str, replacement: str) -> str:
let idx = text.find(needle)
if idx < 0:
return ""
text.slice(0, idx) ++ replacement ++ text.slice(idx + needle.len(), text.len())
fn issue61_fail(ctx: &ActionCtx, message: str) -> i32:
ctx.diagnostics().error("issue61-regression: " ++ message)
1
fn issue61_regression_action(ctx: ActionCtx) -> i32:
let inputs = ctx.inputs()
if inputs.len() == 0:
return issue61_fail(ctx, "missing compiler input")
let fs = ctx.fs()
let output_dir = ctx.output()
if fs.mkdir_all(output_dir) != 0:
return issue61_fail(ctx, "could not create output directory: " ++ output_dir)
let root = ctx.project_info().project_root()
let compiler_path = build_project_abs(root, inputs.get(0))
if not fs.exists(inputs.get(0)):
return issue61_fail(ctx, "missing compiler: " ++ inputs.get(0))
let repo_copy = build_project_join(output_dir, "repo")
if fs.exists(repo_copy) and fs.remove_tree(repo_copy) != 0:
return issue61_fail(ctx, "could not remove existing repo copy: " ++ repo_copy)
if fs.mkdir_all(repo_copy) != 0:
return issue61_fail(ctx, "could not create repo copy directory: " ++ repo_copy)
if fs.copy_tree("src", build_project_join(repo_copy, "src")) != 0:
return issue61_fail(ctx, "could not copy src into repo fixture")
let copied_seed = build_project_join(repo_copy, "src/main")
if fs.exists(copied_seed) and fs.remove_file(copied_seed) != 0:
return issue61_fail(ctx, "could not remove copied seed from repo fixture")
if fs.symlink("lib", build_project_join(repo_copy, "lib")) != 0:
return issue61_fail(ctx, "could not link lib into repo fixture")
let embedded_src = "out/gen/compiler/EmbeddedStdlibData.w"
let embedded_dst = build_project_join(repo_copy, "out/gen/compiler/EmbeddedStdlibData.w")
if fs.mkdir_all(build_project_join(repo_copy, "out/gen/compiler")) != 0:
return issue61_fail(ctx, "could not create embedded stdlib data directory")
if fs.write_text(embedded_dst, fs.read_text(embedded_src)) != 0:
return issue61_fail(ctx, "could not copy embedded stdlib data module")
let clang_res_src = "out/gen/compiler/EmbeddedClangResourceData.w"
let clang_res_dst = build_project_join(repo_copy, "out/gen/compiler/EmbeddedClangResourceData.w")
if fs.write_text(clang_res_dst, fs.read_text(clang_res_src)) != 0:
return issue61_fail(ctx, "could not copy embedded clang resource data module")
let sema_path = build_project_join(repo_copy, "src/SemaCheck.w")
let sema_text = fs.read_text(sema_path)
// Find the marker line and copy ITS leading whitespace for the injected
// local: a fixed-indent splice rots when the surrounding code nests
// deeper (the 4-space injection dedented out of the enclosing block and
// the canary spent months red on a parse error instead of its real job).
let marker_comment = "// Check all arguments (with expected-type propagation for Atomic ordering params)"
let marker_at = sema_text.find(marker_comment)
if marker_at < 0:
return issue61_fail(ctx, "missing insertion point in " ++ sema_path)
var indent_start = marker_at
while indent_start > 0 and sema_text.byte_at((indent_start - 1) as i64) != 10:
indent_start = indent_start - 1
let indent = sema_text.slice(indent_start as i64, marker_at as i64)
let marker = indent ++ marker_comment
let replacement = marker ++ "\n" ++ indent ++ "var mc_issue61_padding_local: i32 = 0"
let patched = build_replace_once(sema_text, marker, replacement)
if patched.len() == 0:
return issue61_fail(ctx, "missing insertion point in " ++ sema_path)
if fs.write_text(sema_path, patched) != 0:
return issue61_fail(ctx, "could not patch " ++ sema_path)
if not fs.read_text(sema_path).contains("mc_issue61_padding_local"):
return issue61_fail(ctx, "failed to inject noop local")
let stdout_path = build_project_abs(root, build_project_join(output_dir, "check.stdout"))
let stderr_path = build_project_abs(root, build_project_join(output_dir, "check.stderr"))
var check_args: Vec[str] = Vec.new()
check_args |> push(compiler_path)
check_args |> push("check")
check_args |> push("src/main.w")
let check = ctx.process_runner().run_capture_cwd(check_args, stdout_path, stderr_path, 180000, build_project_abs(root, repo_copy))
if check.rc == 124:
return issue61_fail(ctx, "check timed out; stdout=" ++ stdout_path ++ " stderr=" ++ stderr_path)
if check.rc != 0:
return issue61_fail(ctx, f"check failed with exit code {check.rc}; stdout=" ++ stdout_path ++ " stderr=" ++ stderr_path)
let output = build_trim_trailing_line_endings(check.stdout)
if output != "ok":
return issue61_fail(ctx, "check produced unexpected output: " ++ output)
0
// Benign-edit invariance: the compiler's verdict on its own tree must be
// invariant under meaning-preserving perturbations (a comment, a fresh
// local, a fresh top-level let, at any position). Every #660-class defect
// — untagged unions probed by content, silent id-alignment sensitivity —
// breaks exactly this property, so this harness catches the CLASS without
// knowing the instance. Variants are a fixed deterministic list; each is
// applied to a pristine repo copy and `check src/main.w` must still say ok.
fn invariance_fail(ctx: &ActionCtx, message: str) -> i32:
ctx.diagnostics().error("invariance-check: " ++ message)
1
fn invariance_run_check(ctx: &ActionCtx, compiler_path: str, repo_copy: str, label: str) -> i32:
let root = ctx.project_info().project_root()
let stdout_path = build_project_abs(root, build_project_join(ctx.output(), label ++ ".stdout"))
let stderr_path = build_project_abs(root, build_project_join(ctx.output(), label ++ ".stderr"))
var check_args: Vec[str] = Vec.new()
check_args |> push(compiler_path)
check_args |> push("check")
check_args |> push("src/main.w")
let check = ctx.process_runner().run_capture_cwd(check_args, stdout_path, stderr_path, 240000, build_project_abs(root, repo_copy))
if check.rc != 0:
return invariance_fail(ctx, f"variant '{label}' changed the verdict (exit {check.rc}); the perturbed tree is left at " ++ repo_copy ++ " — stderr=" ++ stderr_path)
if build_trim_trailing_line_endings(check.stdout) != "ok":
return invariance_fail(ctx, "variant '" ++ label ++ "' produced unexpected output; stdout=" ++ stdout_path)
0
fn invariance_check_action(ctx: ActionCtx) -> i32:
let inputs = ctx.inputs()
if inputs.len() == 0:
return invariance_fail(ctx, "missing compiler input")
let fs = ctx.fs()
let output_dir = ctx.output()
if fs.mkdir_all(output_dir) != 0:
return invariance_fail(ctx, "could not create output directory: " ++ output_dir)
let root = ctx.project_info().project_root()
let compiler_path = build_project_abs(root, inputs.get(0))
if not fs.exists(inputs.get(0)):
return invariance_fail(ctx, "missing compiler: " ++ inputs.get(0))
let repo_copy = build_project_join(output_dir, "repo")
if fs.exists(repo_copy) and fs.remove_tree(repo_copy) != 0:
return invariance_fail(ctx, "could not remove existing repo copy: " ++ repo_copy)
if fs.mkdir_all(repo_copy) != 0:
return invariance_fail(ctx, "could not create repo copy directory: " ++ repo_copy)
if fs.copy_tree("src", build_project_join(repo_copy, "src")) != 0:
return invariance_fail(ctx, "could not copy src into repo fixture")
let copied_seed = build_project_join(repo_copy, "src/main")
if fs.exists(copied_seed) and fs.remove_file(copied_seed) != 0:
return invariance_fail(ctx, "could not remove copied seed from repo fixture")
if fs.symlink("lib", build_project_join(repo_copy, "lib")) != 0:
return invariance_fail(ctx, "could not link lib into repo fixture")
if fs.mkdir_all(build_project_join(repo_copy, "out/gen/compiler")) != 0:
return invariance_fail(ctx, "could not create embedded gen directory")
if fs.write_text(build_project_join(repo_copy, "out/gen/compiler/EmbeddedStdlibData.w"), fs.read_text("out/gen/compiler/EmbeddedStdlibData.w")) != 0:
return invariance_fail(ctx, "could not copy embedded stdlib data module")
if fs.write_text(build_project_join(repo_copy, "out/gen/compiler/EmbeddedClangResourceData.w"), fs.read_text("out/gen/compiler/EmbeddedClangResourceData.w")) != 0:
return invariance_fail(ctx, "could not copy embedded clang resource data module")
// Pristine copies of the files the variants touch.
let sema_copy = build_project_join(repo_copy, "src/Sema.w")
let parser_copy = build_project_join(repo_copy, "src/Parser.w")
let main_copy = build_project_join(repo_copy, "src/main.w")
let sema_pristine = fs.read_text(sema_copy)
let parser_pristine = fs.read_text(parser_copy)
let main_pristine = fs.read_text(main_copy)
if sema_pristine.len() == 0 or parser_pristine.len() == 0 or main_pristine.len() == 0:
return invariance_fail(ctx, "could not read pristine sources from the repo copy")
// Variant 1: comment appended mid-merge (byte shift, no tokens).
if fs.write_text(sema_copy, sema_pristine ++ "\n// invariance probe comment\n") != 0:
return invariance_fail(ctx, "could not write variant comment-sema")
var rc = invariance_run_check(ctx, compiler_path, repo_copy, "comment-sema")
if rc != 0: return rc
// Variant 2: fresh top-level let mid-merge (the #660 killer shape:
// one new interned symbol shifts every later-first-seen symbol id).
if fs.write_text(sema_copy, sema_pristine ++ "\nlet __INVARIANCE_PAD_A: i32 = 0\n") != 0:
return invariance_fail(ctx, "could not write variant let-sema")
rc = invariance_run_check(ctx, compiler_path, repo_copy, "let-sema")
if rc != 0: return rc
// Variant 3: two fresh lets (larger id shift).
if fs.write_text(sema_copy, sema_pristine ++ "\nlet __INVARIANCE_PAD_B: i32 = 0\nlet __INVARIANCE_PAD_C: i32 = 0\n") != 0:
return invariance_fail(ctx, "could not write variant two-lets-sema")
rc = invariance_run_check(ctx, compiler_path, repo_copy, "two-lets-sema")
if rc != 0: return rc
if fs.write_text(sema_copy, sema_pristine) != 0:
return invariance_fail(ctx, "could not restore Sema.w")
// Variant 4: fresh let in a different merge position (Parser.w).
if fs.write_text(parser_copy, parser_pristine ++ "\nlet __INVARIANCE_PAD_D: i32 = 0\n") != 0:
return invariance_fail(ctx, "could not write variant let-parser")
rc = invariance_run_check(ctx, compiler_path, repo_copy, "let-parser")
if rc != 0: return rc
if fs.write_text(parser_copy, parser_pristine) != 0:
return invariance_fail(ctx, "could not restore Parser.w")
// Variant 5: fresh let in the root module (parsed first, ids lowest).
if fs.write_text(main_copy, main_pristine ++ "\nlet __INVARIANCE_PAD_E: i32 = 0\n") != 0:
return invariance_fail(ctx, "could not write variant let-main")
rc = invariance_run_check(ctx, compiler_path, repo_copy, "let-main")
if rc != 0: return rc
if fs.write_text(main_copy, main_pristine) != 0:
return invariance_fail(ctx, "could not restore main.w")
0
// Debug-allocator fixture lane: build tools/debug_drop.w, then run it in `check`
// mode over test/debug_alloc/*.w. Gives the floor eyes for the over/under-drop
// blind spot it is structurally unable to see. See docs/debug-allocator.md.
fn run_debug_alloc_tests_action(ctx: ActionCtx) -> i32:
let inputs = ctx.inputs()
if inputs.len() == 0:
ctx.diagnostics().error("debug-alloc-tests: missing compiler input")
return 1
let fs = ctx.fs()
let out_dir = ctx.output()
if fs.mkdir_all(out_dir) != 0:
ctx.diagnostics().error("debug-alloc-tests: could not create output dir: " ++ out_dir)
return 1
let root = ctx.project_info().project_root()
let compiler = build_project_abs(root, inputs.get(0))
let driver_bin = build_project_abs(root, build_project_join(out_dir, "debug_drop"))
var build_args: Vec[str] = Vec.new()
build_args.push(compiler)
build_args.push("build")
build_args.push("tools/debug_drop.w")
build_args.push("-o")
build_args.push(driver_bin)
let bout = build_project_abs(root, build_project_join(out_dir, "build.stdout"))
let berr = build_project_abs(root, build_project_join(out_dir, "build.stderr"))
let br = ctx.process_runner().run_capture_cwd(build_args, bout, berr, 180000, root)
if br.rc != 0:
ctx.diagnostics().error(f"debug-alloc-tests: driver build failed rc={br.rc}; stderr={berr}")
return 1
let fixtures = fs.list_files("test/debug_alloc")
var check_args: Vec[str] = Vec.new()
check_args.push(driver_bin)
check_args.push("check")
check_args.push(compiler)
for i in 0..fixtures.len() as i32:
let p = fixtures.get(i as i64)
if p.ends_with(".w"):
check_args.push(build_project_abs(root, p))
let cout = build_project_abs(root, build_project_join(out_dir, "check.stdout"))
let cerr = build_project_abs(root, build_project_join(out_dir, "check.stderr"))
let cr = ctx.process_runner().run_capture_cwd(check_args, cout, cerr, 240000, root)
if cr.rc != 0:
ctx.diagnostics().error(f"debug-alloc-tests: lane failed rc={cr.rc}\n" ++ cr.stdout)
return 1
let _ = fs.write_text(build_project_join(out_dir, ".stamp"), "ok")
0
fn run_fixpoint_diff_action(ctx: ActionCtx) -> i32:
let fs = ctx.fs()
let output = ctx.output()
let out_dir = build_project_dirname(output)
if fs.mkdir_all(out_dir) != 0:
ctx.diagnostics().error("fixpoint-diff: could not create output dir: " ++ out_dir)
return 1
let root = ctx.project_info().project_root()
let compiler = build_project_abs(root, stage_compiler_bin("with-stage2"))
let left = build_project_abs(root, stage_compiler_obj("with-stage2-fixpoint.o"))
let right = build_project_abs(root, stage_compiler_obj("with-stage3-fixpoint.o"))
let err_path = build_project_abs(root, build_project_join(out_dir, "stderr.txt"))
var args: Vec[str] = Vec.new()
args.push(compiler)
args.push("fixpoint-diff")
args.push(left)
args.push(right)
let result = ctx.process_runner().run_capture_cwd(args, build_project_abs(root, output), err_path, 120000, root)
if result.rc != 0:
ctx.diagnostics().error("fixpoint-diff: report command failed; stderr=" ++ err_path)
return result.rc
0
fn deep_debug_tool_expect(ctx: &ActionCtx, root: str, compiler: str, source_path: str, out_dir: str, name: str, opt_a: str, opt_b: str, needle: str) -> i32:
var args: Vec[str] = Vec.new()
args.push(compiler)
args.push("check")
if opt_a.len() > 0:
args.push(opt_a)
if opt_b.len() > 0:
args.push(opt_b)
args.push(source_path)
let stdout_rel = build_project_join(out_dir, name ++ ".stdout")
let stderr_rel = build_project_join(out_dir, name ++ ".stderr")
let stdout_path = build_project_abs(root, stdout_rel)
let stderr_path = build_project_abs(root, stderr_rel)
let result = ctx.process_runner().run_capture_cwd(args, stdout_path, stderr_path, 120000, root)
if result.rc != 0:
ctx.diagnostics().error(f"deep-debug-tool-tests: {name} failed rc={result.rc}; stdout={stdout_path} stderr={stderr_path}")
return result.rc
if not ctx.fs().read_text(stdout_rel).contains(needle):
ctx.diagnostics().error("deep-debug-tool-tests: " ++ name ++ " report missing '" ++ needle ++ "'; stdout=" ++ stdout_path)
return 1
0
fn deep_debug_analyze_expect(ctx: &ActionCtx, root: str, compiler: str, source_path: str, out_dir: str, name: str, request: str, needle: str) -> i32:
let args: Vec[str] = Vec.new()
args.push(compiler)
args.push("analyze")
args.push(source_path)
args.push(request)
let stdout_rel = build_project_join(out_dir, name ++ ".stdout")
let stderr_rel = build_project_join(out_dir, name ++ ".stderr")
let stdout_path = build_project_abs(root, stdout_rel)
let stderr_path = build_project_abs(root, stderr_rel)
let result = ctx.process_runner().run_capture_cwd(args, stdout_path, stderr_path, 120000, root)
if result.rc != 0:
ctx.diagnostics().error(f"deep-debug-tool-tests: {name} failed rc={result.rc}; stdout={stdout_path} stderr={stderr_path}")
return result.rc
if not ctx.fs().read_text(stdout_rel).contains(needle):
ctx.diagnostics().error("deep-debug-tool-tests: " ++ name ++ " report missing '" ++ needle ++ "'; stdout=" ++ stdout_path)
return 1
0
fn run_deep_debug_tool_tests_action(ctx: ActionCtx) -> i32:
let inputs = ctx.inputs()
if inputs.len() == 0:
ctx.diagnostics().error("deep-debug-tool-tests: missing compiler input")
return 1
let fs = ctx.fs()
let out_dir = ctx.output()
if fs.mkdir_all(out_dir) != 0:
ctx.diagnostics().error("deep-debug-tool-tests: could not create output dir: " ++ out_dir)
return 1
let root = ctx.project_info().project_root()
let compiler = build_project_abs(root, inputs.get(0))
let reduce_input = build_project_join(out_dir, "reduce-input.w")
let reduce_output = build_project_join(out_dir, "reduce-output.w")
let reduce_source =
"fn unused:\n" ++
" let ok = 1\n" ++
" let _ = ok\n\n" ++
"fn main:\n" ++
" missing_symbol\n"
if fs.write_text(reduce_input, reduce_source) != 0:
ctx.diagnostics().error("deep-debug-tool-tests: could not write reducer fixture")
return 1
var reduce_args: Vec[str] = Vec.new()
reduce_args.push(compiler)
reduce_args.push("reduce")
reduce_args.push(build_project_abs(root, reduce_input))
reduce_args.push("--out")
reduce_args.push(build_project_abs(root, reduce_output))
reduce_args.push("--contains")
reduce_args.push("undefined variable")
reduce_args.push("--")
reduce_args.push(compiler)
reduce_args.push("check")
reduce_args.push("{file}")
let reduce_stdout = build_project_abs(root, build_project_join(out_dir, "reduce.stdout"))
let reduce_stderr = build_project_abs(root, build_project_join(out_dir, "reduce.stderr"))
let reduce_result = ctx.process_runner().run_capture_cwd(reduce_args, reduce_stdout, reduce_stderr, 120000, root)
if reduce_result.rc != 0:
ctx.diagnostics().error("deep-debug-tool-tests: reduce failed; stderr=" ++ reduce_stderr)
return reduce_result.rc
let reduced_text = fs.read_text(reduce_output)
if not reduced_text.contains("missing_symbol"):
ctx.diagnostics().error("deep-debug-tool-tests: reducer output lost predicate line")
return 1
let left = build_project_join(out_dir, "left.bin")
let right = build_project_join(out_dir, "right.bin")
let report = build_project_join(out_dir, "fixpoint-diff.txt")
if fs.write_text(left, "abc") != 0 or fs.write_text(right, "abd") != 0:
ctx.diagnostics().error("deep-debug-tool-tests: could not write diff fixtures")
return 1
var diff_args: Vec[str] = Vec.new()
diff_args.push(compiler)
diff_args.push("fixpoint-diff")
diff_args.push(build_project_abs(root, left))
diff_args.push(build_project_abs(root, right))
let diff_stderr = build_project_abs(root, build_project_join(out_dir, "fixpoint-diff.stderr"))
let diff_result = ctx.process_runner().run_capture_cwd(diff_args, build_project_abs(root, report), diff_stderr, 120000, root)
if diff_result.rc != 0:
ctx.diagnostics().error("deep-debug-tool-tests: fixpoint-diff failed; stderr=" ++ diff_stderr)
return diff_result.rc
if not fs.read_text(report).contains("first-different-offset"):
ctx.diagnostics().error("deep-debug-tool-tests: fixpoint-diff report missing offset")
return 1
let ownership_input = build_project_join(out_dir, "ownership-input.w")
let ownership_source =
"type Resource { id: i32 }\n\n" ++
"type Plain { id: i32 }\n\n" ++
"type Matrix { n: i32 }\n\n" ++
"impl Matrix:\n" ++
" mut fn write(): self.n = self.n + 1\n" ++
" mut fn transitive_write(): self.write()\n" ++
" move fn take() -> Matrix: self\n\n" ++
"impl Drop for Resource:\n" ++
" fn drop(move self: Self):\n" ++
" let _ = self.id\n\n" ++
"fn consume(r: Resource):\n" ++
" let _ = r.id\n\n" ++
"fn choose(flag: bool):\n" ++
" if flag:\n" ++
" let x = 1\n" ++
" let _ = x\n" ++
" else:\n" ++
" let y = 2\n" ++
" let _ = y\n\n" ++
"fn main:\n" ++
" let p = Plain { id: 3 }\n" ++
" let value = p.id\n" ++
" let _ = value\n" ++
" let r = Resource { id: 7 }\n" ++
" consume(r)\n" ++
" choose(true)\n"
if fs.write_text(ownership_input, ownership_source) != 0:
ctx.diagnostics().error("deep-debug-tool-tests: could not write ownership fixture")
return 1
let ownership_abs = build_project_abs(root, ownership_input)
if deep_debug_tool_expect(ctx, root, compiler, ownership_abs, out_dir, "trace-ownership", "--trace-ownership", "main:", "event=") != 0:
return 1
if deep_debug_tool_expect(ctx, root, compiler, ownership_abs, out_dir, "dump-drop-plan", "--dump-drop-plan", "", "drop-plan module") != 0:
return 1
if deep_debug_tool_expect(ctx, root, compiler, ownership_abs, out_dir, "validate-ownership", "--validate-ownership", "", "validate-ownership: ok") != 0:
return 1
if deep_debug_tool_expect(ctx, root, compiler, ownership_abs, out_dir, "dump-place-map", "--dump-place-map", "", "projections=[Field") != 0:
return 1
if deep_debug_tool_expect(ctx, root, compiler, ownership_abs, out_dir, "trace-cleanup-edge", "--trace-cleanup-edge", "choose:bb0->bb1", "edge=bb0->bb1") != 0:
return 1
if deep_debug_analyze_expect(ctx, root, compiler, ownership_abs, out_dir, "analyze-audit", "audit:all", "compiler-analysis-audit") != 0:
return 1
if deep_debug_analyze_expect(ctx, root, compiler, ownership_abs, out_dir, "analyze-storage", "audit:storage", "storage-audit") != 0:
return 1
if deep_debug_analyze_expect(ctx, root, compiler, ownership_abs, out_dir, "analyze-matrix", "matrix:name~consume", "callee-place-alias") != 0:
return 1
if deep_debug_analyze_expect(ctx, root, compiler, ownership_abs, out_dir, "analyze-receiver-effects", "matrix:kind=receiver,name~Matrix.transitive_write", "declared=mut required=mut") != 0:
return 1
if deep_debug_analyze_expect(ctx, root, compiler, ownership_abs, out_dir, "analyze-path", "path:call:main:consume", "call-path: main -> consume") != 0:
return 1
let _ = fs.write_text(build_project_join(out_dir, ".stamp"), "ok")