compiler: Use .ril.bin for package images

4d9cca2e6084a3a98a22a8a2cced7e0c9344261e600fdb242491ca96a52d7c8d
Use .ril.bin for binary RIL package images and .ril for readable RIL.
Apply the image paths to compiler artifacts, kernel builds, and package,
verifier, and loader fixtures.

Assisted-by: Codex:gpt-6
Change-Id: I354c3ed16844f45965be576b952e9b0738e5e312
Alexis Sellier committed ago 1 parent 2f0ae73e
compiler/radiance/artifact.rad +2 -2
389 389
        throw binary::Error::Invalid;
390 390
    }
391 391
    let exports = try readId(&data, rootValue, "exports");
392 392
    let inputs = try readId(&data, rootValue, "inputs");
393 393
    let identity = try readId(&data, rootValue, "image");
394 -
    let image = try readFile(try join(arena, &[root, "/", name, ".ril"]), arena);
394 +
    let image = try readFile(try join(arena, &[root, "/", name, ".ril.bin"]), arena);
395 395
    if image.len < 12
396 396
        or mem::load32Le(image, 0) <> binary::MAGIC
397 397
        or mem::load32Le(image, 4) <> binary::FORMAT_VERSION
398 398
        or mem::load32Le(image, 8) <> binary::ABI_VERSION
399 399
        or (validation == Validation::Full and linkage::imageId(image) <> identity)
537 537
    for file in package.files {
538 538
        let path = try join(arena, &[tree, file.path]);
539 539
        try directories(path);
540 540
        try fs::writeFile(path, file.bytes);
541 541
    }
542 -
    let image = try join(arena, &[root, "/", package.name, ".ril"]);
542 +
    let image = try join(arena, &[root, "/", package.name, ".ril.bin"]);
543 543
    try directories(image);
544 544
    try fs::writeFile(image, publication.image);
545 545
    try fs::writeFile(try join(arena, &[tree, "package.metadata"]), publication.metadata);
546 546
}
547 547
kernel/Makefile +5 -5
21 21
# Combined assembly for the standard library native package.
22 22
$(BIN_DIR)/std.ras: $(filter %.ras,$(STD_LIB)) std.lib kernel/Makefile | $(BIN_DIR)
23 23
	@cat $(filter %.ras,$(STD_LIB)) > $@
24 24
25 25
# Native kernel image.
26 -
$(BIN_DIR)/kernel.ril $(BIN_DIR)/std.ril &: $(KERNEL_SRC) $(KERNEL_MANIFEST) $(STD_LIB) $(STD_MANIFEST) \
27 -
    $(RAD_BIN) kernel/Makefile
26 +
$(BIN_DIR)/kernel.ril.bin $(BIN_DIR)/std.ril.bin &: $(KERNEL_SRC) $(KERNEL_MANIFEST) \
27 +
    $(STD_LIB) $(STD_MANIFEST) $(RAD_BIN) kernel/Makefile
28 28
	@$(RADIANCE) $(STD) $(KERNEL) -entry kernel -ril $(BIN_DIR)
29 29
30 30
$(BIN_DIR)/kernel.build.rv64: kernel/tools/build.rad kernel/tools/build.manifest $(STD_LIB) $(STD_MANIFEST) $(RAD_BIN) \
31 31
    $(BIN_DIR)/std.ras kernel/Makefile
32 32
	@$(RADIANCE) $(STD) -pkg build -mod $< -entry build -o $@
33 33
34 -
$(BIN_DIR)/kernel.rv64: $(BIN_DIR)/std.ril $(BIN_DIR)/kernel.ril \
34 +
$(BIN_DIR)/kernel.rv64: $(BIN_DIR)/std.ril.bin $(BIN_DIR)/kernel.ril.bin \
35 35
    $(BIN_DIR)/kernel.build.rv64 $(KERNEL_ASM) kernel/Makefile
36 36
	@cat $(KERNEL_ASM) > $(BIN_DIR)/kernel.ras
37 -
	@$(HOSTED) $(BIN_DIR)/kernel.build.rv64 -std-asm $(BIN_DIR)/std.ras $(BIN_DIR)/std.ril \
38 -
	    $(BIN_DIR)/kernel.ril $(BIN_DIR)/kernel.ras $@
37 +
	@$(HOSTED) $(BIN_DIR)/kernel.build.rv64 -std-asm $(BIN_DIR)/std.ras $(BIN_DIR)/std.ril.bin \
38 +
	    $(BIN_DIR)/kernel.ril.bin $(BIN_DIR)/kernel.ras $@
lib/std/lang/il/binary.rad +4 -3
1 -
//! Binary RIL wire definitions. Integers use little-endian byte order.
2 -
//! Sequences have a u32 element count. Symbols, layouts and signatures use u32
3 -
//! table indices. Optional fields use a byte: zero for absent, one for present.
1 +
//! Wire definitions for `.ril.bin` package images.
2 +
//! Integers use little-endian byte order. Sequences have a u32 element count.
3 +
//! Symbols, layouts and signatures use u32 table indices. Optional fields use
4 +
//! a byte: zero for absent, one for present.
4 5
5 6
export mod writer;
6 7
export mod reader;
7 8
export mod program;
8 9
export mod collect;
test/integration/boot.rad +8 -8
110 110
export fn bootstrap(h: &mut Harness, args: *[*[u8]]) throws (sys::Error) {
111 111
    try h.begin("bootstrap");
112 112
    let root = kernel::package(h, "loaded", "test/bootstrap/root.rad", &[kernel::ABI, kernel::SYS]);
113 113
    let service = kernel::package(h, "service", "test/bootstrap/service.rad", &[]);
114 114
    let image = h.path(&["bootstrap.rv64"]);
115 -
    let packages = [h.path(&["loaded.ril"]), h.path(&["service.ril"])];
115 +
    let packages = [h.path(&["loaded.ril.bin"]), h.path(&["service.ril.bin"])];
116 116
    if root
117 117
        and service
118 118
        and try kernel::image(h, "bootstrap", image, &[], &packages[..])
119 119
        and h.boot("bootstrap", image, 1)
120 120
    {
144 144
    }
145 145
    try out.close();
146 146
    let loaded = kernel::package(h, "loaded", source, &[]);
147 147
    let image = h.path(&["dispatch.rv64"]);
148 148
    let inputs = [
149 -
        Embedded { name: "INPUT",   file: h.path(&["spin.ril"]) },
150 -
        Embedded { name: "PAYLOAD", file: h.path(&["loaded.ril"]) },
149 +
        Embedded { name: "INPUT",   file: h.path(&["spin.ril.bin"]) },
150 +
        Embedded { name: "PAYLOAD", file: h.path(&["loaded.ril.bin"]) },
151 151
    ];
152 152
    if spin
153 153
        and loaded
154 154
        and try kernel::image(h, "runtime", image, &inputs[..], &[])
155 155
        and h.boot("runtime", image, 1)
173 173
    }
174 174
    try h.begin("scheduling");
175 175
    let mods = [kernel::ABI, kernel::SYS, kernel::MMIO];
176 176
    let root = kernel::package(h, "root", "test/scheduling/root.rad", &mods[.. 2]);
177 177
    let scheduler = kernel::package(h, "scheduler", "test/scheduling/scheduler.rad", &mods[..]);
178 -
    let packages = [h.path(&["root.ril"]), h.path(&["scheduler.ril"])];
178 +
    let packages = [h.path(&["root.ril.bin"]), h.path(&["scheduler.ril.bin"])];
179 179
    let assembly = h.path(&["scheduling.ras"]);
180 180
    let image = h.path(&["scheduling.rv64"]);
181 181
    try kernel::concatAssembly(h, assembly, nil);
182 182
    let linked = kernel::link(
183 183
        h,
227 227
    );
228 228
    let hostile = h.path(&["hostile"]);
229 229
    try fs::makeDir(hostile);
230 230
    let mut entries: *mut [Embedded] = &mut [];
231 231
    try! entries.append(
232 -
        Embedded { name: "INPUT", file: h.path(&["loaded.ril"]) }, h.arena
232 +
        Embedded { name: "INPUT", file: h.path(&["loaded.ril.bin"]) }, h.arena
233 233
    );
234 234
    try! entries.append(
235 -
        Embedded { name: "GROWN", file: h.path(&["grown.ril"]) }, h.arena
235 +
        Embedded { name: "GROWN", file: h.path(&["grown.ril.bin"]) }, h.arena
236 236
    );
237 237
    for entry in &HOSTILE[..] {
238 -
        let file = h.join(&[hostile, "/", entry.file, ".ril"]);
238 +
        let file = h.join(&[hostile, "/", entry.file, ".ril.bin"]);
239 239
        try! entries.append(Embedded { name: entry.name, file }, h.arena);
240 240
    }
241 241
    let fixture = h.path(&["loader.rv64"]);
242 242
    let rejected = h.path(&["rejected.rv64"]);
243 243
    let work = h.work;
244 244
    let machine = h.path(&["machine.ras"]);
245 -
    let forged = [h.join(&[hostile, "/forged.ril"])];
245 +
    let forged = [h.join(&[hostile, "/forged.ril.bin"])];
246 246
    let diagnosed = [Expect::Contains("boot package fails verification: Type")];
247 247
    if il
248 248
        and image
249 249
        and h.run("hosted loaded package", hosted, Outcome::Exited(LOADED_STATUS), &[])
250 250
        and grownIl
test/integration/fixtures.rad +2 -2
53 53
    diagnostics: *[u8],
54 54
}
55 55
56 56
/// Collect the compiler arguments that compile a fixture to the executable
57 57
/// `output`, when it ends in `.rv64`, or otherwise to binary IL in the
58 -
/// directory `output`, which must then hold `test.ril`. Returns the file the
58 +
/// directory `output`, which must then hold `test.ril.bin`. Returns the file the
59 59
/// compilation must produce, after removing it.
60 60
export fn prepare(h: &mut Harness, source: *[u8], output: *[u8]) -> *[u8]
61 61
    throws (sys::Error)
62 62
{
63 63
    let content = try h.load(source);
64 64
    let base = harness::stripExt(source);
65 65
    let isImage = mem::endsWith(output, ".rv64");
66 -
    let produced = output if isImage else h.join(&[output, "/test.ril"]);
66 +
    let produced = output if isImage else h.join(&[output, "/test.ril.bin"]);
67 67
    // Rejection fixtures resolve against the complete standard library.
68 68
    let usesStd = harness::marker(content, "//! uses-std") <> nil
69 69
        or harness::marker(content, REJECTS) <> nil;
70 70
    if isImage {
71 71
        h.add(&["-o", output]);
test/integration/kernel.rad +2 -2
64 64
    }
65 65
    try out.close();
66 66
}
67 67
68 68
/// Link the packages into a machine image with the image tool, from the
69 -
/// kernel binary IL `std.ril` and `kernel.ril` in `ril`, the assembly
69 +
/// kernel binary IL `std.ril.bin` and `kernel.ril.bin` in `ril`, the assembly
70 70
/// `assembly`, and the boot packages. The tool must end with `want`, and its
71 71
/// output in `<image>.log` must meet the expectations.
72 72
export fn link(
73 73
    h: &mut Harness,
74 74
    what: *[u8],
78 78
    boot: &[*[u8]],
79 79
    want: Outcome,
80 80
    expects: &[Expect]
81 81
) -> bool {
82 82
    h.add(&["-std-asm", "bin/std.ras"]);
83 -
    h.add(&[h.join(&[ril, "/std.ril"]), h.join(&[ril, "/kernel.ril"]), assembly, image]);
83 +
    h.add(&[h.join(&[ril, "/std.ril.bin"]), h.join(&[ril, "/kernel.ril.bin"]), assembly, image]);
84 84
    h.add(boot);
85 85
    let output = Output::File(h.join(&[image, ".log"]));
86 86
    let tool = h.cmd(
87 87
        "bin/kernel.build.rv64", h.take(), Target::Inherit, harness::COMPILE_STEPS, output
88 88
    );
test/integration/linking.rad +1 -1
28 28
        );
29 29
        h.add(&["-pkg", "support", "-mod", source, "-ril", directory]);
30 30
        if not h.compile(h.join(&["compile package ", name]), h.out(&[name, ".log"])) {
31 31
            return;
32 32
        }
33 -
        let wire = try h.load(h.join(&[directory, "/support.ril"]));
33 +
        let wire = try h.load(h.join(&[directory, "/support.ril.bin"]));
34 34
        let decoded = try! program::decode(wire, h.arena, binary::Limits {
35 35
            registers: 1024, blocks: 1024
36 36
        });
37 37
        try! packages.append(decoded, h.arena);
38 38
    }
test/integration/machine.rad +8 -5
95 95
    h.add(&["-pkg", "support", "-mod", "test/shared/support.rad"]);
96 96
    let work = h.work;
97 97
    h.add(&["-pkg", "app", "-mod", "test/shared/app.rad", "-entry", "app", "-ril", work]);
98 98
    if h.compile("compile shared packages", h.out(&["compile.log"])) {
99 99
        let image = h.path(&["native.rv64"]);
100 -
        let packages = [h.path(&["support.ril"]), h.path(&["app.ril"]), image];
100 +
        let packages = [h.path(&["support.ril.bin"]), h.path(&["app.ril.bin"]), image];
101 101
        buildAndRun(h, "shared packages", "test/shared/build.rv64", &packages[..], image, 0);
102 102
    }
103 103
    h.done(
104 104
        mark, "shared packages: calls, callbacks, private pointers, and independent state passed"
105 105
    );
116 116
    ]);
117 117
    let second = h.compile("compile support beside noise", h.out(&["combined.log"]));
118 118
    if first and second {
119 119
        let image = h.path(&["errors.rv64"]);
120 120
        let packages = [
121 -
            h.join(&[alone, "/support.ril"]), h.join(&[combined, "/app.ril"]), image, "catch"
121 +
            h.join(&[alone, "/support.ril.bin"]),
122 +
            h.join(&[combined, "/app.ril.bin"]),
123 +
            image,
124 +
            "catch",
122 125
        ];
123 126
        buildAndRun(
124 127
            h, "typed catch across compilations", "test/shared/build.rv64", &packages[..], image, 0
125 128
        );
126 129
    }
205 208
        set mods[count] = mods[3];
206 209
        set count += 1;
207 210
    }
208 211
    let module = h.join(&["test/", fixture, "/spin.rad"]);
209 212
    let staged = h.path(&["dispatch.rv64"]);
210 -
    let inputs = [Embedded { name: "INPUT", file: h.path(&["spin.ril"]) }];
213 +
    let inputs = [Embedded { name: "INPUT", file: h.path(&["spin.ril.bin"]) }];
211 214
    if kernel::package(h, "spin", module, &mods[.. count])
212 215
        and try kernel::image(h, fixture, staged, &inputs[..], &[])
213 216
    {
214 217
        try fs::rename(staged, args[1]);
215 218
    }
222 225
    let mods = ["support=test/cycles/support.rad", kernel::ABI, kernel::SYS, kernel::MMIO];
223 226
    let spin = kernel::package(h, "spin", "test/cycles/spin.rad", &mods[..]);
224 227
    let job = kernel::package(h, "job", "test/cycles/job.rad", &mods[.. 3]);
225 228
    let staged = h.path(&["cycles.rv64"]);
226 229
    let inputs = [
227 -
        Embedded { name: "spin", file: h.path(&["spin.ril"]) },
228 -
        Embedded { name: "job",  file: h.path(&["job.ril"]) },
230 +
        Embedded { name: "spin", file: h.path(&["spin.ril.bin"]) },
231 +
        Embedded { name: "job",  file: h.path(&["job.ril.bin"]) },
229 232
    ];
230 233
    if spin and job and try kernel::image(h, "cycles", staged, &inputs[..], &[]) {
231 234
        try fs::rename(staged, args[0]);
232 235
    }
233 236
}
test/integration/packages.rad +5 -5
26 26
        layoutSize: 1048576,
27 27
        layoutDepth: 32,
28 28
        params: 16,
29 29
        envSize: 4096,
30 30
    };
31 -
    let dep = try h.load(h.join(&[root, "/dep.ril"]));
32 -
    let app = try h.load(h.join(&[root, "/app.ril"]));
31 +
    let dep = try h.load(h.join(&[root, "/dep.ril.bin"]));
32 +
    let app = try h.load(h.join(&[root, "/app.ril.bin"]));
33 33
    let mut provider = try! program::decode(dep, h.arena, limits);
34 34
    let mut client = try! program::decode(app, h.arena, limits);
35 35
    let scratch = heap::over(&mut VERIFY[..]);
36 36
    let keep = heap::over(&mut KEEP[..]);
37 37
    try verify::verifyPackage(&mut provider, config, scratch, keep) catch error {
370 370
                "cache hit forward"
371 371
            ));
372 372
            h.expect("implementation edit retains client", report, harness::Expect::Contains(
373 373
                "cache hit consumer"
374 374
            ));
375 -
            for name in &["forward.ril", "consumer.ril"] {
375 +
            for name in &["forward.ril.bin", "consumer.ril.bin"] {
376 376
                h.expect(
377 377
                    "implementation edit preserves client bytes",
378 378
                    h.join(&[output, "/", name]),
379 379
                    harness::Expect::Same(h.join(&[h.path(&["reuse-first"]), "/", name]))
380 380
                );
597 597
        h.path(&["interface.log"]),
598 598
        harness::Expect::Matching {
599 599
            text: "cache hit app", count: 0
600 600
        }
601 601
    );
602 -
    let originalImage = try h.load(h.join(&[exported, "/dep.ril"]));
603 -
    let changedImage = try h.load(h.join(&[changed, "/dep.ril"]));
602 +
    let originalImage = try h.load(h.join(&[exported, "/dep.ril.bin"]));
603 +
    let changedImage = try h.load(h.join(&[changed, "/dep.ril.bin"]));
604 604
    assert not mem::eq(originalImage, changedImage);
605 605
    try fs::writeFile(
606 606
        app, "use dep; @default fn main() { let value = dep::hidden(); let bad = value.value; }\n"
607 607
    );
608 608
    source(h, h.path(&["opaque.rv64"]), "-o");
test/integration/verify.rad +3 -3
110 110
        try! names.append(name, h.arena);
111 111
    }
112 112
    let outcomes = h.runAll(&batch[..]);
113 113
    let mut packages: *mut [*[u8]] = &mut [];
114 114
    for name, i in &names[..] {
115 -
        let produced = h.path(&[name, "/test.ril"]);
115 +
        let produced = h.path(&[name, "/test.ril.bin"]);
116 116
        if h.outcome(name, outcomes[i], harness::OK, h.path(&[name, ".log"]))
117 117
            and h.expect(name, produced, Expect::Present)
118 118
        {
119 119
            try! packages.append(produced, h.arena);
120 120
        }
149 149
        while end < verdict.len and char::isAlpha(verdict[end]) {
150 150
            set end += 1;
151 151
        }
152 152
        // The fixture is the directory that holds the package.
153 153
        let mut name = path;
154 -
        if mem::endsWith(path, "/test.ril") {
155 -
            let mut parts = mem::split(&path[.. path.len - "/test.ril".len], '/');
154 +
        if mem::endsWith(path, "/test.ril.bin") {
155 +
            let mut parts = mem::split(&path[.. path.len - "/test.ril.bin".len], '/');
156 156
            while let part = parts.next() {
157 157
                set name = part;
158 158
            }
159 159
        }
160 160
        try! reported.append(path, h.arena);
test/loader/hostile.rad +3 -3
1 1
//! Generate binary RIL packages that the kernel loader must reject.
2 2
//!
3 3
//! The language cannot express these programs, so each one is built as typed IL and
4 4
//! encoded. Every package is small and well formed for the decoder, and breaks exactly one
5 -
//! rule of the verifier. The tool writes `<name>.ril` for each package into the directory
5 +
//! rule of the verifier. The tool writes `<name>.ril.bin` for each package into the directory
6 6
//! given as the first argument.
7 7
8 8
use std::fs;
9 9
use std::lang::il;
10 10
use std::lang::il::binary;
135 135
    return il::Instr::Load {
136 136
        typ: il::Type::W64, dst: il::Reg { n: dst }, src: il::Reg { n: src }, offset
137 137
    };
138 138
}
139 139
140 -
/// Write one package to `<directory>/<name>.ril`.
140 +
/// Write one package to `<directory>/<name>.ril.bin`.
141 141
unsafe fn emit(
142 142
    directory: *[u8],
143 143
    name: *[u8],
144 144
    dependencies: *[*[u8]],
145 145
    data: &[il::Data],
181 181
    let length = try! program::encode(&mut output, &package);
182 182
    let mut path: *mut [u8] = &mut [];
183 183
    try! path.extend(directory, arena);
184 184
    try! path.extend("/", arena);
185 185
    try! path.extend(name, arena);
186 -
    try! path.extend(".ril", arena);
186 +
    try! path.extend(".ril.bin", arena);
187 187
    try! fs::writeFile(&path[..], &OUT[.. length]);
188 188
}
189 189
190 190
/// Generate every hostile package into the directory in the first argument.
191 191
@default unsafe fn main(env: *sys::Env) -> i32 {