compiler: Store each package in its own directory

b1a6d95a9654f65aba27364d9933b9c0b871afec2208dbc0aa580092e8e6060a
A package artifact was stored as three entries next to those of other
packages: `name.ril.bin`, `name.interface/`, and an optional
`name.native/` with the assembly files, the startup assembly and the
source location table. Assembly was stored with the image although it
is only an input of native linking, so `-ril` copied it into every
exported graph and every cache entry.

Store each package in the directory `name/` below the artifact root,
with `name.ril.bin`, the interface tree `interface/`, and the optional
location table `name.ril.debug`. Assembly and startup assembly are no
longer artifact files: the driver keeps them as native link inputs of
the invocation, and `-ril` rejects them. The integration driver reads
the new paths, and builds the standard library from its Radiance
modules alone when it writes RIL. Stage each export and install the
complete directory with a rename or atomic filesystem exchange.

Keep the native assembly client in a source fixture file.

Assisted-by: Claude:opus-5.5
Assisted-by: Codex:gpt-6
Change-Id: Ie85024a8e11edba1f16d1089fa8c744afdd72286
Alexis Sellier committed ago 1 parent c51f0fc0
compiler/radiance.rad +5 -4
95 95
/// Default directory for package cache entries.
96 96
constant DEFAULT_CACHE_DIR: *[u8] = "cache";
97 97
98 98
/// Usage string.
99 99
constant USAGE: *[u8] =
100 -
    "usage: radiance -pkg <name> [-start <input.ras>] -mod <input>.. [-pkg <name> -mod <input>..] -entry <pkg> [-o <output> | -ril <directory>]\n-artifact <directory> selects a compiled package tree.\n-manifest <path> selects dependency names; the default is <package>.manifest beside the root module.\n-cache <directory> selects cache storage; -no-cache bypasses cache reads and writes.\n-mod accepts a source path or logical/path=source.rad relative to the package root.\n-embed <path> declares a file under the package root for @embed.\n       radiance -fmt [-fmt.wrap <columns>] <input.rad>\n       radiance -fmt.check [-fmt.wrap <columns>] <input.rad>\n-fmt prints the source of a module in the canonical style, wrapped at 100 columns unless -fmt.wrap sets another width.\n-fmt.check prints nothing and fails if the source of a module is not in the canonical style.\n       radiance clean [-cache <directory>]\nclean removes completed and temporary package cache entries.\n       radiance -version\n-version prints the compiler identity.\n";
100 +
    "usage: radiance -pkg <name> [-start <input.ras>] -mod <input>.. [-pkg <name> -mod <input>..] -entry <pkg> [-o <output> | -ril <directory>]\n-artifact <directory> selects a compiled package tree.\nAssembly inputs require native output with -o.\n-manifest <path> selects dependency names; the default is <package>.manifest beside the root module.\n-cache <directory> selects cache storage; -no-cache bypasses cache reads and writes.\n-mod accepts a source path or logical/path=source.rad relative to the package root.\n-embed <path> declares a file under the package root for @embed.\n       radiance -fmt [-fmt.wrap <columns>] <input.rad>\n       radiance -fmt.check [-fmt.wrap <columns>] <input.rad>\n-fmt prints the source of a module in the canonical style, wrapped at 100 columns unless -fmt.wrap sets another width.\n-fmt.check prints nothing and fails if the source of a module is not in the canonical style.\n       radiance clean [-cache <directory>]\nclean removes completed and temporary package cache entries.\n       radiance -version\n-version prints the compiler identity.\n";
101 101
102 102
/// Compiler error.
103 103
export union Error: Copy {
104 104
    Other,
105 105
}
538 538
    }
539 539
    if pkgCount == 0 {
540 540
        throw error(&["no package specified"]);
541 541
    }
542 542
    for i in 0 .. pkgCount {
543 +
        if outputPath == nil and (inputs[i].asmPathCount > 0 or inputs[i].startupPath <> nil) {
544 +
            throw error(&["assembly inputs require native output with `-o`"]);
545 +
        }
543 546
        if inputs[i].artifactRoot <> nil and (inputs[i].radPathCount > 0
544 -
            or inputs[i].asmPathCount > 0
545 -
            or inputs[i].embedPathCount > 0
546 -
            or inputs[i].startupPath <> nil)
547 +
            or inputs[i].embedPathCount > 0)
547 548
        {
548 549
            throw error(&["package", inputs[i].name, "has both source and artifact inputs"]);
549 550
        }
550 551
        if inputs[i].radPathCount == 0 and inputs[i].artifactRoot == nil {
551 552
            throw error(&["package", inputs[i].name, "has no Radiance modules specified"]);
compiler/radiance/artifact.rad +85 -43
1 -
//! Package images with their compiler interface and native input trees.
1 +
//! Package images, compiler interfaces, and source locations.
2 2
//!
3 -
//! A package `name` is stored below an artifact root as three entries:
3 +
//! A package `name` is stored in its own directory below an artifact root:
4 4
//!
5 5
//! * `name.ril.bin`, the binary RIL image. Its header names the dependencies,
6 6
//!   their metadata pins, and the package's own metadata identity.
7 -
//! * `name.interface/`, the interface modules `name.rid` and `name/**.rid`, and the
7 +
//! * `interface/`, the interface modules `name.rid` and `name/**.rid`, and the
8 8
//!   embedded files that they read, at their paths from the package root.
9 -
//! * `name.native/`, the optional native inputs: assembly files `0.ras`, `1.ras`
10 -
//!   and so on, the startup assembly `startup.ras`, and the source location table
11 -
//!   `locations`.
9 +
//! * `name.ril.debug`, the optional source location table for native debug output.
12 10
//!
13 11
//! The image's metadata identity covers the interface tree, so the trees need no
14 12
//! descriptor.
15 13
16 14
use std::char;
25 23
use std::mem;
26 24
use std::mem::heap;
27 25
use std::sys;
28 26
use super::metadata;
29 27
30 -
/// Suffix of the interface tree of a package.
31 -
constant INTERFACE: *[u8] = ".interface/";
32 -
/// Suffix of the native input tree of a package.
33 -
constant NATIVE: *[u8] = ".native/";
34 -
/// Name of the startup assembly in a native tree.
35 -
export constant STARTUP: *[u8] = "startup.ras";
36 -
/// Name of the source location table in a native tree.
37 -
export constant LOCATIONS: *[u8] = "locations";
28 +
/// Bound on temporary directory reservations left by concurrent or interrupted writers.
29 +
export constant TEMPORARY_SLOTS: u32 = 4096;
30 +
/// Suffix that identifies a private cache publication directory.
31 +
export constant TEMPORARY_MARKER: *[u8] = ".tmp.";
32 +
33 +
/// Path of the interface tree in a package directory.
34 +
constant INTERFACE: *[u8] = "interface/";
35 +
/// Suffix of a package RIL debug file.
36 +
export constant DEBUG_EXT: *[u8] = ".ril.debug";
38 37
/// Initial storage for one directory listing.
39 38
constant LISTING_BYTES: u32 = 65536;
40 39
41 40
/// Content validation required when loading a package artifact set.
42 41
export union Validation: Copy {
60 59
    name: *[u8],
61 60
    /// Hash of its compiler declarations and exported runtime contracts.
62 61
    declarations: binary::Id,
63 62
}
64 63
65 -
/// Use of a file stored with an artifact.
64 +
/// Use of a compiler file input.
66 65
export union FileRole: Copy {
67 66
    /// Assembly instructions linked after generated functions.
68 67
    Assembly,
69 68
    /// Entry assembly linked before all generated functions.
70 69
    Startup,
72 71
    Debug,
73 72
    /// File contents that modules read with `@embed`.
74 73
    Embed,
75 74
}
76 75
77 -
/// An immutable non-Radiance artifact input.
76 +
/// An immutable compiler file input.
78 77
export record File: Copy {
79 -
    /// Path in the native tree, or the package-relative path of an embedded file.
78 +
    /// Input path, or the package-relative path of an embedded file.
80 79
    path: *[u8],
81 80
    /// Path of the file that was read, for diagnostics.
82 81
    origin: *[u8],
83 82
    /// Complete input contents.
84 83
    bytes: *[u8],
90 89
export record Package: Copy {
91 90
    /// Package name and root module identity.
92 91
    name: *[u8],
93 92
    /// Text modules in parent-before-child order.
94 93
    modules: *[Module],
95 -
    /// Assembly, interface embeds, and source locations retained with the package.
94 +
    /// Interface embeds and source locations retained with the package.
96 95
    files: *[File],
97 96
    /// Dependency names and required compiler metadata.
98 97
    dependencies: *[Dependency],
99 98
    /// Digest of compiler declarations and dependency metadata.
100 99
    declarations: binary::Id,
307 306
    name: *[u8],
308 307
    validation: Validation,
309 308
    scratch: *heap::Heap,
310 309
    arena: &heap::Heap
311 310
) -> Package throws (sys::Error) {
312 -
    let image = try readFile(try join(arena, &[root, "/", name, ".ril.bin"]), arena);
313 -
    let tree = try join(arena, &[root, "/", name, INTERFACE]);
311 +
    let directory = try join(arena, &[root, "/", name, "/"]);
312 +
    let image = try readFile(try join(arena, &[directory, name, ".ril.bin"]), arena);
313 +
    let tree = try join(arena, &[directory, INTERFACE]);
314 314
    let mut paths: *mut [*[u8]] = &mut [];
315 315
    try walk(tree, "", &mut paths, arena);
316 316
    let mut modules: *mut [Module] = &mut [];
317 317
    let mut files: *mut [File] = &mut [];
318 318
    // Sorted paths list each parent module before its children.
331 331
        }
332 332
    }
333 333
    if modules.len == 0 or not mem::eq(modules[0].path, try join(arena, &[name, ".rid"])) {
334 334
        throw sys::Error::Invalid;
335 335
    }
336 -
    let native = try join(arena, &[root, "/", name, NATIVE]);
337 -
    for i in 0 .. mem::U32_MAX {
338 -
        let mut digits: [u8; fmt::U32_STR_LEN] = undefined;
339 -
        let number = try alloc::copyBytes(arena, fmt::formatU32(i, &mut digits[..])) catch {
340 -
            throw sys::Error::TooLarge;
341 -
        };
342 -
        let path = try join(arena, &[&number[..], ".ras"]);
343 -
        let origin = try join(arena, &[native, path]);
344 -
        let bytes = try readOptional(origin, arena) else break;
345 -
        try files.append(File { path, origin, bytes, role: FileRole::Assembly }, arena) catch {
336 +
    let path = try join(arena, &[name, DEBUG_EXT]);
337 +
    let origin = try join(arena, &[directory, path]);
338 +
    if let bytes = try readOptional(origin, arena) {
339 +
        try files.append(
340 +
            File { path, origin, bytes, role: FileRole::Debug }, arena
341 +
        ) catch {
346 342
            throw sys::Error::TooLarge;
347 343
        };
348 344
    }
349 -
    for path, i in &[STARTUP, LOCATIONS] {
350 -
        let origin = try join(arena, &[native, path]);
351 -
        if let bytes = try readOptional(origin, arena) {
352 -
            let role = FileRole::Startup if i == 0 else FileRole::Debug;
353 -
            try files.append(File { path, origin, bytes, role }, arena) catch {
354 -
                throw sys::Error::TooLarge;
355 -
            };
356 -
        }
357 -
    }
358 345
    // Decoded artifact fields own copies outside the temporary decoder storage.
359 346
    let mark = heap::mark(scratch);
360 347
    let result = try decode(
361 348
        name, image, &modules[..], &files[..], validation, scratch, arena
362 349
    ) catch err as binary::Error {
476 463
        io::printError("radiance: artifact path conflicts with another stored path: ");
477 464
        io::printError(path);
478 465
        io::printError("\n");
479 466
        throw sys::Error::Invalid;
480 467
    }
481 -
    let tree = try join(arena, &[root, "/", package.name, INTERFACE]);
482 -
    let native = try join(arena, &[root, "/", package.name, NATIVE]);
468 +
    let directory = try join(arena, &[root, "/", package.name, "/"]);
469 +
    let tree = try join(arena, &[directory, INTERFACE]);
483 470
    for module in package.modules {
484 471
        let path = try join(arena, &[tree, module.path]);
485 472
        try directories(path);
486 473
        try fs::writeFile(path, module.text);
487 474
    }
488 475
    for file in package.files {
489 -
        let path = try join(arena, &[tree if file.role == FileRole::Embed else native, file.path]);
476 +
        if file.role <> FileRole::Embed and file.role <> FileRole::Debug {
477 +
            throw sys::Error::Invalid;
478 +
        }
479 +
        let path = try join(arena, &[
480 +
            tree if file.role == FileRole::Embed else directory, file.path
481 +
        ]);
490 482
        try directories(path);
491 483
        try fs::writeFile(path, file.bytes);
492 484
    }
493 -
    try fs::writeFile(try join(arena, &[root, "/", package.name, ".ril.bin"]), image);
485 +
    try fs::writeFile(try join(arena, &[directory, package.name, ".ril.bin"]), image);
486 +
}
487 +
488 +
/// Reserve a private directory with an atomic creation operation.
489 +
export fn temporary(base: *[u8], arena: &heap::Heap) -> *[u8] throws (sys::Error) {
490 +
    for i in 0 .. TEMPORARY_SLOTS {
491 +
        let mut digits: [u8; fmt::U32_STR_LEN] = undefined;
492 +
        let number = try alloc::copyBytes(arena, fmt::formatU32(i, &mut digits[..])) catch {
493 +
            throw sys::Error::TooLarge;
494 +
        };
495 +
        let path = try join(arena, &[base, TEMPORARY_MARKER, &number[..]]);
496 +
        try fs::makeDir(path) catch error {
497 +
            if error == sys::Error::Exists {
498 +
                continue;
499 +
            }
500 +
            throw error;
501 +
        };
502 +
        return path;
503 +
    }
504 +
    throw sys::Error::Limit;
505 +
}
506 +
507 +
/// Write a complete staged package and install it at its final path.
508 +
fn install(package: &Package, stage: *[u8], destination: *[u8], arena: &heap::Heap)
509 +
    throws (sys::Error)
510 +
{
511 +
    let staged = try join(arena, &[stage, "/", package.name]);
512 +
    try write(package, stage, arena);
513 +
    try fs::rename(staged, destination) catch error {
514 +
        if error <> sys::Error::NotEmpty and error <> sys::Error::Exists {
515 +
            throw error;
516 +
        }
517 +
        let image = try join(arena, &[destination, "/", package.name, ".ril.bin"]);
518 +
        let info = try fs::stat(image) else throw sys::Error::Invalid;
519 +
        if info.kind <> fs::Kind::File {
520 +
            throw sys::Error::Invalid;
521 +
        }
522 +
        try fs::exchange(staged, destination);
523 +
    };
524 +
}
525 +
526 +
/// Replace the package directory below `root` with a complete export.
527 +
export fn publish(package: &Package, root: *[u8], arena: &heap::Heap) throws (sys::Error) {
528 +
    try fs::createDirAll(root);
529 +
    let destination = try join(arena, &[root, "/", package.name]);
530 +
    let stage = try temporary(destination, arena);
531 +
    try install(package, stage, destination, arena) catch error {
532 +
        try fs::removeTree(stage, arena) catch {};
533 +
        throw error;
534 +
    };
535 +
    try fs::removeTree(stage, arena);
494 536
}
compiler/radiance/build.rad +32 -37
2 2
3 3
use std::arch::rv64;
4 4
use std::arch::rv64::asm;
5 5
use std::char;
6 6
use std::collections::dict;
7 -
use std::fmt;
8 7
use std::fs;
9 8
use std::hash::blake3;
10 9
use std::io;
11 10
use std::lang::alloc;
12 11
use std::lang::ast;
97 96
record Input: Copy {
98 97
    /// Command-line input descriptions.
99 98
    options: super::PackageInput,
100 99
    /// Declared dependency names in deterministic order.
101 100
    dependencies: *[*[u8]],
101 +
    /// Assembly and startup inputs linked into native output.
102 +
    nativeFiles: *[artifact::File],
102 103
    /// Source snapshots or a complete compiled artifact.
103 104
    contents: Contents,
104 105
}
105 106
106 107
/// Source request and non-Radiance inputs for a fresh package.
109 110
    declared: *[u16],
110 111
    /// Completed provider contracts used to select imports.
111 112
    providers: &'providers [link::Provider],
112 113
    /// Content key when cache or artifact publication is required.
113 114
    key: ?binary::Id,
114 -
    /// Captured assembly and embedded file inputs.
115 +
    /// Captured embedded file inputs.
115 116
    files: *[artifact::File],
116 117
}
117 118
118 119
/// Artifacts of one source compilation.
119 120
record Compilation {
216 217
    arena: &heap::Heap,
217 218
    artifacts: &heap::Heap
218 219
) -> Input
219 220
    throws (sys::Error)
220 221
{
222 +
    let mut nativeFiles: *mut [artifact::File] = &mut [];
223 +
    let count = options.asmPathCount + 1;
224 +
    for i in 0 .. count {
225 +
        let mut origin: *[u8] = "";
226 +
        let mut role = artifact::FileRole::Assembly;
227 +
        if i == options.asmPathCount {
228 +
            let startup = options.startupPath else continue;
229 +
            set origin = startup;
230 +
            set role = artifact::FileRole::Startup;
231 +
        } else {
232 +
            set origin = options.asmPaths[i];
233 +
        }
234 +
        let bytes = try artifact::readFile(origin, arena);
235 +
        try nativeFiles.append(artifact::File { path: origin, origin, bytes, role }, arena) catch {
236 +
            throw sys::Error::TooLarge;
237 +
        };
238 +
    }
221 239
    if let root = options.artifactRoot {
222 240
        let compiled = try artifact::read(
223 241
            root, options.name, artifact::Validation::Full, scratch, artifacts
224 242
        );
225 243
        let mut dependencies: *mut [*[u8]] = &mut [];
227 245
            try dependencies.append(dependency.name, arena) catch {
228 246
                throw sys::Error::TooLarge;
229 247
            };
230 248
        }
231 249
        return Input {
232 -
            options, dependencies: &dependencies[..], contents: Contents::Compiled(compiled)
250 +
            options,
251 +
            dependencies: &dependencies[..],
252 +
            nativeFiles: &nativeFiles[..],
253 +
            contents: Contents::Compiled(compiled),
233 254
        };
234 255
    }
235 256
    let mut modules: *mut [Snapshot] = &mut [];
236 257
    for i in 0 .. options.radPathCount {
237 258
        let path = options.radPaths[i];
278 299
    } else if options.manifestPath <> nil {
279 300
        throw sys::Error::NotFound;
280 301
    }
281 302
    let dependencies = try dependencyNames(manifest, arena);
282 303
    let mut files: *mut [artifact::File] = &mut [];
283 -
    let count = options.asmPathCount + 1;
284 -
    for i in 0 .. count {
285 -
        let mut origin: *[u8] = "";
286 -
        let mut path = artifact::STARTUP;
287 -
        let mut role = artifact::FileRole::Assembly;
288 -
        if i == options.asmPathCount {
289 -
            let startup = options.startupPath else continue;
290 -
            set origin = startup;
291 -
            set role = artifact::FileRole::Startup;
292 -
        } else {
293 -
            set origin = options.asmPaths[i];
294 -
            let mut digits: [u8; fmt::U32_STR_LEN] = undefined;
295 -
            let number = try keep(arena, fmt::formatU32(i, &mut digits[..]));
296 -
            set path = try artifact::join(arena, &[number, ".ras"]);
297 -
        }
298 -
        let bytes = try artifact::readFile(origin, arena);
299 -
        try files.append(artifact::File { path, origin, bytes, role }, arena) catch {
300 -
            throw sys::Error::TooLarge;
301 -
        };
302 -
    }
303 304
    try files.extend(try embeds(options, arena), arena) catch {
304 305
        throw sys::Error::TooLarge;
305 306
    };
306 307
    return Input {
307 308
        options,
308 309
        dependencies,
310 +
        nativeFiles: &nativeFiles[..],
309 311
        contents: Contents::Source(Source {
310 312
            modules: &modules[..], files: &files[..], manifest
311 313
        }),
312 314
    };
313 315
}
896 898
/// Write package artifact trees.
897 899
fn writePackages(compiled: &[artifact::Package], directory: *[u8], driverArena: &heap::Heap)
898 900
    throws (super::Error)
899 901
{
900 902
    for package in compiled {
901 -
        try artifact::write(&package, directory, driverArena) catch {
903 +
        try artifact::publish(&package, directory, driverArena) catch {
902 904
            throw super::error(&["cannot write package artifacts", package.name]);
903 905
        };
904 906
    }
905 907
}
906 908
912 914
) -> NativeSetup throws (super::Error) {
913 915
    let mut asmData: *mut [u8] = &mut [];
914 916
    let mut native = locations::Native::None;
915 917
    if ctx.outputPath <> nil {
916 918
        let mut startup: ?artifact::File = nil;
917 -
        let mut files: *[artifact::File] = &[];
918 -
        match entry.contents {
919 -
            case Contents::Source(source)    => set files = source.files,
920 -
            case Contents::Compiled(package) => set files = package.files,
921 -
        }
922 -
        for file in files {
919 +
        for file in entry.nativeFiles {
923 920
            if file.role == artifact::FileRole::Startup {
924 921
                set startup = file;
925 922
            }
926 923
        }
927 924
        let mut generator = try rv64::beginProgram(rv64::ProgramOptions {
1220 1217
        let bytes = try keep(
1221 1218
            work.artifacts, &sink.locations.bytes[.. sink.locations.offset]
1222 1219
        ) catch {
1223 1220
            throw super::Error::Other;
1224 1221
        };
1222 +
        let path = try artifact::join(work.artifacts, &[pkg.name, artifact::DEBUG_EXT]) catch {
1223 +
            throw super::error(&["package debug locations storage exhausted", pkg.name]);
1224 +
        };
1225 1225
        try packageFiles.append(
1226 1226
            artifact::File {
1227 -
                path: artifact::LOCATIONS, origin: "", bytes, role: artifact::FileRole::Debug
1227 +
                path, origin: "", bytes, role: artifact::FileRole::Debug
1228 1228
            },
1229 1229
            work.artifacts
1230 1230
        ) catch {
1231 1231
            throw super::Error::Other;
1232 1232
        };
1555 1555
    work: &mut Workspace
1556 1556
) throws (super::Error) {
1557 1557
    let mut generator = generated;
1558 1558
    let mut asmData = asmBytes;
1559 1559
    for input in inputs {
1560 -
        let mut files: *[artifact::File] = &[];
1561 -
        match input.contents {
1562 -
            case Contents::Source(source)    => set files = source.files,
1563 -
            case Contents::Compiled(package) => set files = package.files,
1564 -
        }
1565 -
        for file in files {
1560 +
        for file in input.nativeFiles {
1566 1561
            if file.role == artifact::FileRole::Assembly {
1567 1562
                try assembly(
1568 1563
                    &mut generator, &file, &mut asmData, work.functions, &mut ctx.parser.pool
1569 1564
                );
1570 1565
            }
compiler/radiance/cache.rad +5 -28
8 8
use std::mem;
9 9
use std::mem::heap;
10 10
use std::sys;
11 11
use super::artifact;
12 12
13 -
/// Bound on temporary directory reservations left by concurrent or interrupted writers.
14 -
constant TEMPORARY_SLOTS: u32 = 4096;
15 13
/// Hexadecimal characters in a 256-bit cache key.
16 14
constant KEY_LENGTH: u32 = 64;
17 -
/// Suffix that identifies a private cache publication directory.
18 -
constant TEMPORARY_MARKER: *[u8] = ".tmp.";
19 15
20 16
/// Build the lowercase hexadecimal directory name of a request key.
21 17
fn entry(root: *[u8], key: binary::Id, arena: &heap::Heap) -> *[u8] throws (sys::Error) {
22 18
    let mut text: [u8; KEY_LENGTH] = [0; KEY_LENGTH];
23 19
    fmt::formatHex(&key.bytes[..], &mut text[..]);
51 47
        throw error;
52 48
    };
53 49
    return result;
54 50
}
55 51
56 -
/// Reserve a private directory with an atomic creation operation.
57 -
fn temporary(base: *[u8], arena: &heap::Heap) -> *[u8] throws (sys::Error) {
58 -
    for i in 0 .. TEMPORARY_SLOTS {
59 -
        let mut digits: [u8; fmt::U32_STR_LEN] = undefined;
60 -
        let number = try alloc::copyBytes(arena, fmt::formatU32(i, &mut digits[..])) catch {
61 -
            throw sys::Error::TooLarge;
62 -
        };
63 -
        let path = try artifact::join(arena, &[base, TEMPORARY_MARKER, &number[..]]);
64 -
        try fs::makeDir(path) catch error {
65 -
            if error == sys::Error::Exists {
66 -
                continue;
67 -
            }
68 -
            throw error;
69 -
        };
70 -
        return path;
71 -
    }
72 -
    throw sys::Error::Limit;
73 -
}
74 -
75 -
/// Test for a lowercase request key or a reservation made by `temporary`.
52 +
/// Test for a lowercase request key or a reservation made by the publisher.
76 53
fn owned(name: *[u8]) -> bool {
77 54
    if name.len < KEY_LENGTH {
78 55
        return false;
79 56
    }
80 57
    for byte in &name[.. KEY_LENGTH] {
84 61
    }
85 62
    let suffix = &name[KEY_LENGTH ..];
86 63
    if suffix.len == 0 {
87 64
        return true;
88 65
    }
89 -
    if not mem::startsWith(suffix, TEMPORARY_MARKER) {
66 +
    if not mem::startsWith(suffix, artifact::TEMPORARY_MARKER) {
90 67
        return false;
91 68
    }
92 -
    let digits = &suffix[TEMPORARY_MARKER.len ..];
69 +
    let digits = &suffix[artifact::TEMPORARY_MARKER.len ..];
93 70
    if digits.len > 1 and digits[0] == '0' {
94 71
        return false;
95 72
    }
96 73
    let slot = try fmt::parseUint(digits, 10) catch {
97 74
        return false;
98 75
    };
99 -
    return slot < TEMPORARY_SLOTS as u64;
76 +
    return slot < artifact::TEMPORARY_SLOTS as u64;
100 77
}
101 78
102 79
/// Remove completed and temporary cache entries below `root`.
103 80
/// Missing caches are empty. Other files in the cache root are retained.
104 81
export fn clean(root: *[u8], arena: &heap::Heap) throws (sys::Error) {
128 105
export fn publish(root: *[u8], key: binary::Id, package: &artifact::Package, arena: &heap::Heap)
129 106
    throws (sys::Error)
130 107
{
131 108
    let path = try entry(root, key, arena);
132 109
    try artifact::directories(try artifact::join(arena, &[root, "/"]));
133 -
    let stage = try temporary(path, arena);
110 +
    let stage = try artifact::temporary(path, arena);
134 111
    try artifact::write(package, stage, arena) catch error {
135 112
        try fs::removeTree(stage, arena) catch {};
136 113
        throw error;
137 114
    };
138 115
    try fs::rename(stage, path) catch error {
kernel/Makefile +6 -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 $(BIN_DIR)/std.ril.bin &: $(KERNEL_SRC) $(KERNEL_MANIFEST) \
26 +
$(BIN_DIR)/kernel/kernel.ril.bin $(BIN_DIR)/std/std.ril.bin &: $(KERNEL_SRC) $(KERNEL_MANIFEST) \
27 27
    $(STD_LIB) $(STD_MANIFEST) $(RAD_BIN) kernel/Makefile
28 -
	@$(RADIANCE) $(STD) $(KERNEL) -entry kernel -ril $(BIN_DIR)
28 +
	@$(RADIANCE) -pkg std $(patsubst %,-mod %,$(filter %.rad,$(STD_LIB))) \
29 +
	    $(KERNEL) -entry kernel -ril $(BIN_DIR)
29 30
30 31
$(BIN_DIR)/kernel.build.rv64: kernel/tools/build.rad kernel/tools/build.manifest $(STD_LIB) $(STD_MANIFEST) $(RAD_BIN) \
31 32
    $(BIN_DIR)/std.ras kernel/Makefile
32 33
	@$(RADIANCE) $(STD) -pkg build -mod $< -entry build -o $@
33 34
34 -
$(BIN_DIR)/kernel.rv64: $(BIN_DIR)/std.ril.bin $(BIN_DIR)/kernel.ril.bin \
35 +
$(BIN_DIR)/kernel.rv64: $(BIN_DIR)/std/std.ril.bin $(BIN_DIR)/kernel/kernel.ril.bin \
35 36
    $(BIN_DIR)/kernel.build.rv64 $(KERNEL_ASM) kernel/Makefile
36 37
	@cat $(KERNEL_ASM) > $(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 $@
38 +
	@$(HOSTED) $(BIN_DIR)/kernel.build.rv64 -std-asm $(BIN_DIR)/std.ras $(BIN_DIR)/std/std.ril.bin \
39 +
	    $(BIN_DIR)/kernel/kernel.ril.bin $(BIN_DIR)/kernel.ras $@
lib/std/fs.rad +5 -0
311 311
/// Rename `from` to `to`. An existing file at `to` is replaced.
312 312
export fn rename(from: &[u8], to: &[u8]) throws (sys::Error) {
313 313
    try host::callPath(host::RENAME, from, host::addr(to), to.len as i64);
314 314
}
315 315
316 +
/// Atomically swap two existing directory entries on the same filesystem.
317 +
export fn exchange(left: &[u8], right: &[u8]) throws (sys::Error) {
318 +
    try host::callPath(host::EXCHANGE, left, host::addr(right), right.len as i64);
319 +
}
320 +
316 321
/// List the directory at `path` into `buf`. Returns the names, each followed
317 322
/// by a zero byte, in host order, which `mem::split(names, 0)` iterates. Throws
318 323
/// `TooLarge` when they do not fit.
319 324
export fn listDir(path: &[u8], buf: *mut [u8]) -> *[u8] throws (sys::Error) {
320 325
    let n = try host::callPath(host::LIST_DIR, path, host::addr(buf), buf.len as i64);
lib/std/sys/host.rad +2 -0
28 28
export constant SPAWN: u32 = 0x40A;
29 29
/// Call number of `wait`.
30 30
export constant WAIT: u32 = 0x40B;
31 31
/// Call number of `waitAny`.
32 32
export constant WAIT_ANY: u32 = 0x40C;
33 +
/// Call number of `exchange`.
34 +
export constant EXCHANGE: u32 = 0x40D;
33 35
34 36
/// Standard input descriptor.
35 37
export constant STDIN: i64 = 0;
36 38
/// Standard output descriptor.
37 39
export constant STDOUT: i64 = 1;
test/integration/boot.rad +6 -6
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.bin"]), h.path(&["service.ril.bin"])];
115 +
    let packages = [h.path(&["loaded/loaded.ril.bin"]), h.path(&["service/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.bin"]) },
150 -
        Embedded { name: "PAYLOAD", file: h.path(&["loaded.ril.bin"]) },
149 +
        Embedded { name: "INPUT",   file: h.path(&["spin/spin.ril.bin"]) },
150 +
        Embedded { name: "PAYLOAD", file: h.path(&["loaded/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.bin"]), h.path(&["scheduler.ril.bin"])];
178 +
    let packages = [h.path(&["root/root.ril.bin"]), h.path(&["scheduler/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.bin"]) }, h.arena
232 +
        Embedded { name: "INPUT", file: h.path(&["loaded/loaded.ril.bin"]) }, h.arena
233 233
    );
234 234
    try! entries.append(
235 -
        Embedded { name: "GROWN", file: h.path(&["grown.ril.bin"]) }, h.arena
235 +
        Embedded { name: "GROWN", file: h.path(&["grown/grown.ril.bin"]) }, h.arena
236 236
    );
237 237
    for entry in &HOSTILE[..] {
238 238
        let file = h.join(&[hostile, "/", entry.file, ".ril.bin"]);
239 239
        try! entries.append(Embedded { name: entry.name, file }, h.arena);
240 240
    }
test/integration/fixtures.rad +4 -4
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.bin`. Returns the file the
59 -
/// compilation must produce, after removing it.
58 +
/// directory `output`, which must then hold `test/test.ril.bin`. Returns the
59 +
/// file the 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.bin"]);
66 +
    let produced = output if isImage else h.join(&[output, "/test/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]);
72 72
    } else {
73 73
        try harness::makeDirs(output);
74 74
        h.add(&["-ril", output]);
75 75
    }
76 76
    if usesStd {
77 -
        try h.addStd();
77 +
        try h.addStd("" if isImage else ".rad");
78 78
    }
79 79
    if harness::marker(content, "//! stack-check") <> nil {
80 80
        h.add(&["-stack-check"]);
81 81
    }
82 82
    h.add(&["-pkg", "test", "-mod", source]);
test/integration/harness.rad +5 -3
594 594
/// `name`, which may contain `/` to place it in a child module.
595 595
export fn (h: &mut Harness) named(name: *[u8], path: *[u8]) {
596 596
    h.add(&["-mod", h.join(&[name, "=", path])]);
597 597
}
598 598
599 -
/// Add the standard library as a package named `std`.
600 -
export fn (h: &mut Harness) addStd() throws (sys::Error) {
599 +
/// Add standard library inputs with `extension`, or all inputs when it is empty.
600 +
export fn (h: &mut Harness) addStd(extension: *[u8]) throws (sys::Error) {
601 601
    h.add(&["-pkg", "std"]);
602 602
    for path in try h.manifest("std.lib") {
603 -
        h.add(&["-mod", path]);
603 +
        if mem::endsWith(path, extension) {
604 +
            h.add(&["-mod", path]);
605 +
        }
604 606
    }
605 607
}
606 608
607 609
/// Return a copy of the compiler arguments collected since the last call.
608 610
export fn (h: &mut Harness) take() -> *[*[u8]] {
test/integration/kernel.rad +12 -5
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.bin` and `kernel.ril.bin` in `ril`, the assembly
70 -
/// `assembly`, and the boot packages. The tool must end with `want`, and its
71 -
/// output in `<image>.log` must meet the expectations.
69 +
/// kernel binary IL `std/std.ril.bin` and `kernel/kernel.ril.bin` in `ril`,
70 +
/// the assembly `assembly`, and the boot packages. The tool must end with
71 +
/// `want`, and its output in `<image>.log` must meet the expectations.
72 72
export fn link(
73 73
    h: &mut Harness,
74 74
    what: *[u8],
75 75
    ril: *[u8],
76 76
    assembly: *[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.bin"]), h.join(&[ril, "/kernel.ril.bin"]), assembly, image]);
83 +
    h.add(
84 +
        &[
85 +
            h.join(&[ril, "/std/std.ril.bin"]),
86 +
            h.join(&[ril, "/kernel/kernel.ril.bin"]),
87 +
            assembly,
88 +
            image,
89 +
        ]
90 +
    );
84 91
    h.add(boot);
85 92
    let output = Output::File(h.join(&[image, ".log"]));
86 93
    let tool = h.cmd(
87 94
        "bin/kernel.build.rv64", h.take(), Target::Inherit, harness::COMPILE_STEPS, output
88 95
    );
129 136
    entries: &[Embedded],
130 137
    boot: &[*[u8]]
131 138
) -> bool throws (sys::Error) {
132 139
    let dir = h.join(&["test/", fixture]);
133 140
    let work = h.work;
134 -
    try h.addStd();
141 +
    try h.addStd(".rad");
135 142
    h.add(&["-pkg", "kernel", "-manifest", "test/std.manifest", "-mod", "test/kernel.rad"]);
136 143
    for path in try h.listFiles(KERNEL_DIR, ".rad") {
137 144
        let name = &path[KERNEL_DIR.len + 1 .. path.len - ".rad".len];
138 145
        if not mem::eq(name, "tests") {
139 146
            h.named(name, path);
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.bin"]));
33 +
        let wire = try h.load(h.join(&[directory, "/support/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 +6 -6
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.bin"]), h.path(&["app.ril.bin"]), image];
100 +
        let packages = [h.path(&["support/support.ril.bin"]), h.path(&["app/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.bin"]),
122 -
            h.join(&[combined, "/app.ril.bin"]),
121 +
            h.join(&[alone, "/support/support.ril.bin"]),
122 +
            h.join(&[combined, "/app/app.ril.bin"]),
123 123
            image,
124 124
            "catch",
125 125
        ];
126 126
        buildAndRun(
127 127
            h, "typed catch across compilations", "test/shared/build.rv64", &packages[..], image, 0
208 208
        set mods[count] = mods[3];
209 209
        set count += 1;
210 210
    }
211 211
    let module = h.join(&["test/", fixture, "/spin.rad"]);
212 212
    let staged = h.path(&["dispatch.rv64"]);
213 -
    let inputs = [Embedded { name: "INPUT", file: h.path(&["spin.ril.bin"]) }];
213 +
    let inputs = [Embedded { name: "INPUT", file: h.path(&["spin/spin.ril.bin"]) }];
214 214
    if kernel::package(h, "spin", module, &mods[.. count])
215 215
        and try kernel::image(h, fixture, staged, &inputs[..], &[])
216 216
    {
217 217
        try fs::rename(staged, args[1]);
218 218
    }
225 225
    let mods = ["support=test/cycles/support.rad", kernel::ABI, kernel::SYS, kernel::MMIO];
226 226
    let spin = kernel::package(h, "spin", "test/cycles/spin.rad", &mods[..]);
227 227
    let job = kernel::package(h, "job", "test/cycles/job.rad", &mods[.. 3]);
228 228
    let staged = h.path(&["cycles.rv64"]);
229 229
    let inputs = [
230 -
        Embedded { name: "spin", file: h.path(&["spin.ril.bin"]) },
231 -
        Embedded { name: "job",  file: h.path(&["job.ril.bin"]) },
230 +
        Embedded { name: "spin", file: h.path(&["spin/spin.ril.bin"]) },
231 +
        Embedded { name: "job",  file: h.path(&["job/job.ril.bin"]) },
232 232
    ];
233 233
    if spin and job and try kernel::image(h, "cycles", staged, &inputs[..], &[]) {
234 234
        try fs::rename(staged, args[0]);
235 235
    }
236 236
}
test/integration/packages.rad +127 -32
27 27
        layoutSize: 1048576,
28 28
        layoutDepth: 32,
29 29
        params: 16,
30 30
        envSize: 4096,
31 31
    };
32 -
    let dep = try h.load(h.join(&[root, "/dep.ril.bin"]));
33 -
    let app = try h.load(h.join(&[root, "/app.ril.bin"]));
32 +
    let dep = try h.load(h.join(&[root, "/dep/dep.ril.bin"]));
33 +
    let app = try h.load(h.join(&[root, "/app/app.ril.bin"]));
34 34
    let mut provider = try! program::decode(dep, h.arena, limits);
35 35
    let mut client = try! program::decode(app, h.arena, limits);
36 36
    let scratch = heap::over(&mut VERIFY[..]);
37 37
    let keep = heap::over(&mut KEEP[..]);
38 38
    try verify::verifyPackage(&mut provider, config, scratch, keep) catch error {
65 65
fn execute(h: &mut Harness, image: *[u8]) {
66 66
    let command = h.cmd(image, &[], harness::HOSTED, harness::RUN_STEPS, harness::INHERIT);
67 67
    h.run("execute package client", command, harness::OK, &[]);
68 68
}
69 69
70 +
/// Assembly inputs require native output and link with source or artifact packages.
71 +
fn nativeInputs(h: &mut Harness) throws (sys::Error) {
72 +
    let root = h.path(&["native-inputs"]);
73 +
    try harness::makeDirs(root);
74 +
    let source = h.join(&[root, "/entry.rad"]);
75 +
    let assembly = h.join(&[root, "/entry.ras"]);
76 +
    let exported = h.join(&[root, "/packages"]);
77 +
    let image = h.join(&[root, "/entry.rv64"]);
78 +
    try fs::writeFile(source, try h.load("test/packages/native-inputs/entry.rad"));
79 +
    let mut previous: ?*[u8] = nil;
80 +
    for increment in 1 .. 3 {
81 +
        try fs::writeFileParts(
82 +
            assembly,
83 +
            &[
84 +
                ".text; .export @entry::native; @entry::native addi %a0 %a0 ",
85 +
                h.num(increment), "; ret;\n",
86 +
            ]
87 +
        );
88 +
        h.add(
89 +
            &[
90 +
                "-cache", h.join(&[root, "/cache"]), "-pkg", "entry", "-mod", source,
91 +
                "-mod", assembly, "-o", image,
92 +
            ]
93 +
        );
94 +
        if not h.compile("link assembly with native output", h.out(&["native-link.log"])) {
95 +
            return;
96 +
        }
97 +
        execute(h, image);
98 +
        let bytes = try h.load(image);
99 +
        if let earlier = previous {
100 +
            assert not mem::eq(earlier, bytes);
101 +
        }
102 +
        set previous = bytes;
103 +
        if increment == 2 {
104 +
            h.expect(
105 +
                "assembly edits reuse package RIL",
106 +
                h.path(&["native-link.log"]),
107 +
                harness::Expect::Contains("cache hit entry")
108 +
            );
109 +
        }
110 +
    }
111 +
    for flag in &["", "-ril", "-dump"] {
112 +
        h.add(&["-pkg", "entry", "-mod", source, "-mod", assembly]);
113 +
        if flag.len > 0 {
114 +
            h.add(&[flag, exported if mem::eq(flag, "-ril") else "il"]);
115 +
        }
116 +
        let command = h.cc(h.take(), h.out(&["native-rejected.log"]));
117 +
        h.run("reject assembly without native output", command, process::Outcome::Exited(1), &[
118 +
            harness::Expect::Contains("assembly inputs require native output with `-o`")
119 +
        ]);
120 +
    }
121 +
    h.add(&["-pkg", "entry", "-mod", source, "-start", assembly, "-ril", exported]);
122 +
    let command = h.cc(h.take(), h.out(&["startup-rejected.log"]));
123 +
    h.run("reject startup assembly without native output", command, process::Outcome::Exited(1), &[
124 +
        harness::Expect::Contains("assembly inputs require native output with `-o`")
125 +
    ]);
126 +
    h.add(&["-pkg", "entry", "-mod", source, "-ril", exported]);
127 +
    if not h.compile("export Radiance declarations and code", h.out(&["native-export.log"])) {
128 +
        return;
129 +
    }
130 +
    h.add(&["-pkg", "entry", "-artifact", exported, "-mod", assembly, "-o", image]);
131 +
    if h.compile("link assembly with an artifact package", h.out(&["native-artifact.log"])) {
132 +
        execute(h, image);
133 +
    }
134 +
}
135 +
70 136
/// Compile a large std test artifact, then use its complete interfaces in a test client.
71 137
fn large(h: &mut Harness) throws (sys::Error) {
72 138
    let root = h.path(&["large"]);
73 139
    h.add(&["-no-cache", "-test"]);
74 -
    try h.addStd();
140 +
    try h.addStd(".rad");
75 141
    for path in try h.manifest("std.lib.test") {
76 142
        h.add(&["-mod", path]);
77 143
    }
78 144
    let provider = h.path(&["large-provider.rad"]);
79 145
    let client = h.path(&["large-client.rad"]);
92 158
    try fs::writeFile(
93 159
        source,
94 160
        "use std::testing; @test unsafe fn check() throws (testing::TestError) { assert true; }\n"
95 161
    );
96 162
    try fs::writeFile(h.path(&["checks.manifest"]), "std\n");
97 -
    h.add(
98 -
        &[
99 -
            "-no-cache", "-test", "-pkg", "std", "-artifact", root,
100 -
            "-pkg", "checks", "-mod", source, "-entry", "checks", "-o", h.path(&["large.rv64"]),
101 -
        ]
102 -
    );
163 +
    h.add(&["-no-cache", "-test", "-pkg", "std", "-artifact", root]);
164 +
    for path in try h.manifest("std.lib") {
165 +
        if mem::endsWith(path, ".ras") {
166 +
            h.add(&["-mod", path]);
167 +
        }
168 +
    }
169 +
    h.add(&[
170 +
        "-pkg", "checks", "-mod", source, "-entry", "checks", "-o", h.path(&["large.rv64"])
171 +
    ]);
103 172
    if h.compile("use the large std artifact without source", h.out(&["large-client.log"])) {
104 173
        execute(h, h.path(&["large.rv64"]));
105 174
    }
106 175
}
107 176
150 219
    if not h.compile("export embedded package files", h.out(&["embed-export.log"])) {
151 220
        return;
152 221
    }
153 222
    h.expect(
154 223
        "interfaces keep embed calls",
155 -
        h.join(&[exported, "/text.interface/text.rid"]),
224 +
        h.join(&[exported, "/text/interface/text.rid"]),
156 225
        harness::Expect::Contains("@embed(\"data/hello.txt\")")
157 226
    );
158 227
    h.expect(
159 228
        "interface trees hold embedded files",
160 -
        h.join(&[exported, "/text.interface/data/hello.txt"]),
229 +
        h.join(&[exported, "/text/interface/data/hello.txt"]),
161 230
        harness::Expect::Contains("hullo")
162 231
    );
163 232
    try fs::remove(provider);
164 233
    try fs::remove(data);
165 234
    h.add(
250 319
            ]
251 320
        );
252 321
        if not h.compile("compile private embedded inputs", process::Output::File(report)) {
253 322
            return;
254 323
        }
255 -
        let wire = try h.load(h.join(&[output, "/text.ril.bin"]));
324 +
        let wire = try h.load(h.join(&[output, "/text/text.ril.bin"]));
256 325
        let mut input = reader::new(wire);
257 326
        let header = try! program::header(&mut input, h.arena);
258 327
        if let expected = original {
259 328
            assert header.links.metadata == expected;
260 329
            h.expect("private embed edits retain clients", report, harness::Expect::Contains(
263 332
            h.expect("private embeds remain build inputs", report, harness::Expect::Matching {
264 333
                text: "cache hit text", count: 0
265 334
            });
266 335
            h.expect(
267 336
                "private embed edits preserve client images",
268 -
                h.join(&[output, "/app.ril.bin"]),
269 -
                harness::Expect::Same(h.join(&[first, "/app.ril.bin"]))
337 +
                h.join(&[output, "/app/app.ril.bin"]),
338 +
                harness::Expect::Same(h.join(&[first, "/app/app.ril.bin"]))
270 339
            );
271 340
        } else {
272 341
            set original = header.links.metadata;
273 342
        }
274 343
        if version == 1 {
275 -
            assert not mem::eq(wire, try h.load(h.join(&[first, "/text.ril.bin"])));
344 +
            assert not mem::eq(wire, try h.load(h.join(&[first, "/text/text.ril.bin"])));
276 345
        }
277 346
        h.expect(
278 347
            "retain embeds reached through private interface declarations",
279 -
            h.join(&[output, "/text.interface/data/public.txt"]),
348 +
            h.join(&[output, "/text/interface/data/public.txt"]),
280 349
            harness::Expect::Present
281 350
        );
282 351
        for name in &["private.txt", "unused.txt"] {
283 352
            h.expect(
284 353
                "store only interface embeds",
285 -
                h.join(&[output, "/text.interface/data/", name]),
354 +
                h.join(&[output, "/text/interface/data/", name]),
286 355
                harness::Expect::Absent
287 356
            );
288 357
        }
289 358
    }
290 359
    for path in &[provider, child, private, unused, public] {
349 418
    h.expect("remove completed cache entries", entries[0], harness::Expect::Absent);
350 419
    h.expect("remove interrupted cache entries", partial, harness::Expect::Absent);
351 420
    h.expect("retain unrelated cache-root files", unrelated, harness::Expect::Present);
352 421
    h.expect(
353 422
        "retain exported packages",
354 -
        h.join(&[exported, "/cleancheck.ril.bin"]),
423 +
        h.join(&[exported, "/cleancheck/cleancheck.ril.bin"]),
355 424
        harness::Expect::Present
356 425
    );
357 426
    h.add(&["clean", "-cache", cache]);
358 427
    h.compile("clean an empty cache", h.out(&["clean-empty.log"]));
359 428
    h.add(&["clean", "-cache", h.join(&[root, "/missing"])]);
374 443
    for i in 0 .. 3 {
375 444
        let checkout = h.join(&[root, "/", h.num(i)]);
376 445
        try harness::makeDirs(checkout);
377 446
        let source = h.join(&[checkout, "/entry.rad" if i == 0 else "/renamed.rad"]);
378 447
        let child = h.join(&[checkout, "/implementation.rad"]);
379 -
        let assembly = h.join(&[checkout, "/renamed.ras" if i == 2 else "/native.ras"]);
380 448
        let data = h.join(&[checkout, "/asset.bin"]);
381 449
        try fs::writeFile(source, entry);
382 450
        try fs::writeFile(child, "export fn answer() -> u32 { return 42; }\n");
383 -
        try fs::writeFile(assembly, ".text;\n");
384 451
        try fs::writeFile(data, "x");
385 452
        let output = h.join(&[checkout, "/exported"]);
386 453
        let report = h.join(&[checkout, "/build.log"]);
387 454
        h.add(
388 455
            &[
389 456
                "-cache", h.join(&[root, "/cache"]), "-debug",
390 457
                "-pkg", "portable", "-mod", source,
391 -
                "-mod", h.join(&["detail=", child]), "-mod", assembly, "-embed", data,
458 +
                "-mod", h.join(&["detail=", child]), "-embed", data,
392 459
                "-entry", "portable", "-ril", output,
393 460
            ]
394 461
        );
395 462
        if not h.compile("compile a relocated package", process::Output::File(report)) {
396 463
            return;
399 466
        let nativeLog = h.out(&["relocated-native.log"]);
400 467
        h.add(
401 468
            &[
402 469
                "-cache", h.join(&[root, "/cache"]), "-debug",
403 470
                "-pkg", "portable", "-mod", source, "-mod", h.join(&["detail=", child]),
404 -
                "-mod", assembly, "-embed", data, "-entry", "portable", "-o", native,
471 +
                "-embed", data, "-entry", "portable", "-o", native,
405 472
            ]
406 473
        );
407 474
        if not h.compile("link from the relocated cache", nativeLog) {
408 475
            return;
409 476
        }
419 486
                harness::Expect::Contains(path)
420 487
            );
421 488
        }
422 489
        h.expect(
423 490
            "artifacts omit checkout paths",
424 -
            h.join(&[output, "/portable.native/locations"]),
491 +
            h.join(&[output, "/portable/portable.ril.debug"]),
425 492
            harness::Expect::Matching { text: root, count: 0 }
426 493
        );
427 494
        if i > 0 {
428 -
            // Renamed root and assembly files keep their logical module and storage paths.
495 +
            // Renamed source files keep their logical module paths.
429 496
            h.expect("relocation reuses compiled packages", report, harness::Expect::Contains(
430 497
                "cache hit portable"
431 498
            ));
432 499
            for path in &[
433 -
                "portable.ril.bin", "portable.native/locations", "portable.native/0.ras",
434 -
                "portable.interface/asset.bin",
500 +
                "portable/portable.ril.bin", "portable/portable.ril.debug",
501 +
                "portable/interface/asset.bin",
435 502
            ] {
436 503
                h.expect(
437 504
                    "relocation preserves package artifacts",
438 505
                    h.join(&[output, "/", path]),
439 506
                    harness::Expect::Same(h.join(&[first, "/", path]))
444 511
    let image = h.join(&[root, "/portable.rv64"]);
445 512
    h.add(&["-no-cache", "-debug", "-pkg", "portable", "-artifact", second, "-o", image]);
446 513
    if h.compile("link a relocated artifact", h.out(&["relocation-link.log"])) {
447 514
        execute(h, image);
448 515
    }
516 +
    let single = h.join(&[root, "/single.rad"]);
517 +
    try fs::writeFile(single, "@default fn main() -> u32 { return 0; }");
518 +
    h.add(&["-no-cache", "-pkg", "sibling", "-mod", single, "-ril", second]);
519 +
    if not h.compile("export a sibling package", h.out(&["sibling.log"])) {
520 +
        return;
521 +
    }
522 +
    h.add(&["-no-cache", "-pkg", "portable", "-mod", single, "-ril", second]);
523 +
    if not h.compile("replace the exported package", h.out(&["replace.log"])) {
524 +
        return;
525 +
    }
526 +
    for path in &[
527 +
        "portable/interface/portable/detail.rid", "portable/interface/asset.bin",
528 +
        "portable/portable.ril.debug",
529 +
    ] {
530 +
        h.expect(
531 +
            "remove obsolete package inputs", h.join(&[second, "/", path]), harness::Expect::Absent
532 +
        );
533 +
    }
534 +
    h.expect(
535 +
        "preserve the sibling export",
536 +
        h.join(&[second, "/sibling/sibling.ril.bin"]),
537 +
        harness::Expect::Present
538 +
    );
539 +
    h.add(&["-no-cache", "-pkg", "portable", "-artifact", second, "-o", image]);
540 +
    if h.compile("read the replacement package", h.out(&["read-replacement.log"])) {
541 +
        execute(h, image);
542 +
    }
449 543
}
450 544
451 545
/// Print the compiler identity.
452 546
fn version(h: &mut Harness) {
453 547
    h.add(&["-version"]);
507 601
}
508 602
509 603
/// Reject explicit artifacts whose interface tree differs from the one that the image's
510 604
/// metadata identity covers.
511 605
fn integrity(h: &mut Harness, root: *[u8]) throws (sys::Error) {
512 -
    let extra = h.join(&[root, "/dep.interface/extra.txt"]);
606 +
    let extra = h.join(&[root, "/dep/interface/extra.txt"]);
513 607
    try fs::writeFile(extra, "");
514 608
    h.add(&["-no-cache", "-pkg", "dep", "-artifact", root]);
515 609
    let added = h.cc(h.take(), h.out(&["extra-interface.log"]));
516 610
    h.run("reject unlisted interface files", added, process::Outcome::Exited(1), &[]);
517 611
    try fs::remove(extra);
518 -
    let module = h.join(&[root, "/dep.interface/dep.rid"]);
612 +
    let module = h.join(&[root, "/dep/interface/dep.rid"]);
519 613
    let original = try h.load(module);
520 614
    try fs::remove(module);
521 615
    h.add(&["-no-cache", "-pkg", "dep", "-artifact", root]);
522 616
    let missing = h.cc(h.take(), h.out(&["missing-interface.log"]));
523 617
    h.run("reject a missing root interface", missing, process::Outcome::Exited(1), &[]);
564 658
                "cache hit forward"
565 659
            ));
566 660
            h.expect("implementation edit retains client", report, harness::Expect::Contains(
567 661
                "cache hit consumer"
568 662
            ));
569 -
            for name in &["forward.ril.bin", "consumer.ril.bin"] {
663 +
            for name in &["forward/forward.ril.bin", "consumer/consumer.ril.bin"] {
570 664
                h.expect(
571 665
                    "implementation edit preserves client bytes",
572 666
                    h.join(&[output, "/", name]),
573 667
                    harness::Expect::Same(h.join(&[h.path(&["reuse-first"]), "/", name]))
574 668
                );
684 778
    h.expect("warm executable parity", h.path(&["warm.rv64"]), harness::Expect::Same(image));
685 779
    source(h, exported, "-ril");
686 780
    if not h.compile("export complete package closure", h.out(&["export.log"])) {
687 781
        return;
688 782
    }
783 +
    try nativeInputs(h);
689 784
    try compilerImage(h, exported);
690 785
    version(h);
691 786
    try integrity(h, exported);
692 -
    let declarations = h.join(&[exported, "/dep.interface/dep.rid"]);
787 +
    let declarations = h.join(&[exported, "/dep/interface/dep.rid"]);
693 788
    h.expect("interface omits implementation helpers", declarations, harness::Expect::Matching {
694 789
        text: "fn helper(", count: 0
695 790
    });
696 791
    h.expect(
697 792
        "interface retains callbacks from empty arrays",
777 872
        h.path(&["interface.log"]),
778 873
        harness::Expect::Matching {
779 874
            text: "cache hit app", count: 0
780 875
        }
781 876
    );
782 -
    let originalImage = try h.load(h.join(&[exported, "/dep.ril.bin"]));
783 -
    let changedImage = try h.load(h.join(&[changed, "/dep.ril.bin"]));
877 +
    let originalImage = try h.load(h.join(&[exported, "/dep/dep.ril.bin"]));
878 +
    let changedImage = try h.load(h.join(&[changed, "/dep/dep.ril.bin"]));
784 879
    assert not mem::eq(originalImage, changedImage);
785 880
    try fs::writeFile(
786 881
        app, "use dep; @default fn main() { let value = dep::hidden(); let bad = value.value; }\n"
787 882
    );
788 883
    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.bin"]);
115 +
        let produced = h.path(&[name, "/test/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.bin") {
155 -
            let mut parts = mem::split(&path[.. path.len - "/test.ril.bin".len], '/');
154 +
        if mem::endsWith(path, "/test/test.ril.bin") {
155 +
            let mut parts = mem::split(&path[.. path.len - "/test/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/packages/native-inputs/entry.rad added +8 -0
1 +
unsafe fn native(value: u32) -> u32;
2 +
@default fn main() -> u32 {
3 +
    unsafe {
4 +
        let value = native(40);
5 +
        assert value >= 41 and value <= 42;
6 +
    }
7 +
    return 0;
8 +
}