compiler: Build packages from manifests

d4960d4966e11fc2e6c36f1ac4619c23397dc8cf4d7d09c1e8f4138dfbccd6a5
Every build described its packages with command-line flags: `-pkg`
and one `-mod` per module, `-manifest` with one dependency name per
line, `-artifact`, `-start`, `-embed` and `-entry`. The Makefiles, the
module lists `std.lib` and `std.lib.test`, and the integration driver
each assembled those flags their own way, and a listed module that its
parent did not declare crashed lowering.

A package is now a directory that holds the manifest `<name>.manifest`,
the root module `<name>.rad`, and its other modules. The manifest is a
`Package` record literal with the name, version, dependencies, modules
listed by name, test modules, assembly, startup assembly and embedded
files; `std::lang::manifest` reads it with the Radiance parser.
`radiance [-lib <dir>].. [-dep <name>=<dir>].. [<package dir>]` builds
the package and its dependencies. A dependency comes from `-dep`, or is
found by name in the `-lib` directories and then in the `lib` directory
of the package and of each of its parents, as a source package or as
compiled `-ril` output, and is checked against the required version.
`radiance [-name <name>] <module.rad>` builds one module as a package
that depends on the packages it imports. The compiler rejects a listed
module that its parent does not declare.

Source packages and compiled packages share one dependency graph.
Builds and source dumps visit providers before their consumers. An
export carries its assembly inputs in link order under `native/`, so a
native build can link a compiled package with the same assembly as a
source build.

The standard library, compiler and kernel move to `lib/std`,
`compiler/radiance` and `kernel/kernel`, and the Makefiles and kernel
build tool use manifests. Fixtures compile as single modules, or as
package directories `test/tests/NAME/` when they have submodules or
assembly. The checks of `testgen` and `metadata` stay standalone builds
with the old flags, since the compiler's test image does not fit in
emulator memory.

The seed only knows the old flags, and `seed/update` passes the same
flags to every stage, so the old flags stay until the seed is updated.
The seed reads its dependency lists from `seed/dependencies` and maps
modules to their files with `logical=path`.

Assisted-by: Claude:opus-5.5
Assisted-by: Codex:gpt-6
Change-Id: Ide3ec784541497ce6dd3b4c7f056965e568d6c78
Alexis Sellier committed ago 1 parent b1a6d95a
AGENTS.md +4 -4
105 105
Use timeouts for builds, tests, scripts, and emulator runs. These limits are
106 106
starting points; investigate timeouts before increasing them. Export
107 107
`RAD_EMULATOR` when selecting an emulator so Make and `seed/update` use the
108 108
same one. The integration driver `test/integration.rv64` runs the tests that
109 109
start other programs; Make starts it with the compiler and job count. Its
110 -
commands are listed in `test/integration.rad`. Child programs have instruction
110 +
commands are listed in `test/integration/integration.rad`. Child programs have instruction
111 111
budgets instead of wall-clock timeouts.
112 112
113 113
```bash
114 114
timeout 300 make           # Build bin/radiance.rv64.dev from the seed
115 115
timeout 600 make test      # All test suites, including kernel and machine tests
131 131
`test/integration.rv64` before running the driver. The driver runs existing
132 132
binaries; it does not build them.
133 133
134 134
## Task-specific references
135 135
136 -
- Compiler work: `compiler/radiance.rad` is the entry point; `lib/std/lang/`
136 +
- Compiler work: `compiler/radiance/radiance.rad` is the entry point; `lib/std/lang/`
137 137
  contains scanner, parser, resolver, lowering, and code generation modules.
138 138
  RV64 backend and assembler code is in `lib/std/arch/rv64/`.
139 139
- Tests: read nearby fixtures and `test/integration/fixtures.rad` for supported
140 140
  checks. `.ril` files check IL; `//! returns: N` requests an executable check.
141 141
  Success fixtures use `@default fn main`, assertions, and a zero return.
142 142
  Inspect generated IL before accepting a new snapshot.
143 -
- Test production std behavior in std unit suites. Module lists are in
144 -
  `std.lib` and `std.lib.test`.
143 +
- Test production std behavior in std unit suites. Modules are listed in
144 +
  `lib/std/std.manifest`, and again for the seed in `std.lib` and `std.lib.test`.
145 145
- Backend debugging: locate the first incorrect stage, from AST and resolution
146 146
  through IL, assembly, and execution. Use Make recipes with the existing
147 147
  `RADIANCE` settings for diagnostic compilation.
148 148
- Bootstrap changes: read `seed/README`. The seed must compile checked-in source.
149 149
  Update it only when needed, through `timeout 600 make seed` or the documented
Makefile +19 -9
1 1
# Radiance build file.
2 2
3 -
# Standard library source manifests.
4 -
STD_MANIFEST := lib/std.manifest
3 +
# Standard library manifest and sources. `std.lib` and `std.lib.test` list
4 +
# the same modules as the manifest for the seed, which predates manifests.
5 +
STD_MANIFEST := lib/std/std.manifest
5 6
STD_LIB      := $(shell cat std.lib)
6 7
STD_TEST_LIB := $(STD_LIB) $(shell cat std.lib.test)
7 -
STD          := -pkg std $(patsubst %,-mod %,$(STD_LIB))
8 -
STD_TEST     := -pkg std $(patsubst %,-mod %,$(STD_TEST_LIB))
9 8
10 9
# Compiler output.
11 10
BIN_DIR := bin
12 11
RAD_BIN := $(BIN_DIR)/radiance.rv64.dev
13 12
24 23
default: $(RAD_BIN)
25 24
26 25
# Compiler build
27 26
28 27
SEED              := seed/radiance.rv64
29 -
COMPILER_SRC      := compiler/radiance.rad compiler/radiance/codegen.rad \
28 +
COMPILER_SRC      := compiler/radiance/radiance.rad compiler/radiance/codegen.rad \
30 29
    compiler/radiance/testgen.rad compiler/radiance/link.rad \
31 30
    compiler/radiance/artifact.rad compiler/radiance/metadata.rad \
32 31
    compiler/radiance/build.rad compiler/radiance/cache.rad compiler/radiance/locations.rad
33 -
COMPILER_MANIFEST := $(STD_MANIFEST) compiler/radiance.manifest
34 -
SEED_OPTS         := $(STD) -pkg radiance $(patsubst %,-mod %,$(COMPILER_SRC)) -entry radiance
35 -
36 -
$(RAD_BIN): Makefile $(SEED) std.lib $(STD_LIB) $(COMPILER_SRC) $(COMPILER_MANIFEST) | $(BIN_DIR)
32 +
# Package flags for the seed, which predates manifests. Its dependency lists
33 +
# are in `seed/dependencies`. Module files are in the package directory, so
34 +
# each module after the root is mapped to its logical path.
35 +
# `$(call modules,DIR,ROOT,FILES)` gives the `-mod` flags of the files FILES
36 +
# of the package in DIR whose root module is ROOT.
37 +
modules = -mod $(2) $(foreach f,$(filter-out $(2),$(filter %.rad,$(3))), \
38 +
    -mod $(patsubst $(1)/%.rad,%,$(f))=$(f)) $(patsubst %,-mod %,$(filter %.ras,$(3)))
39 +
STD               := -pkg std -manifest seed/dependencies/none \
40 +
    $(call modules,lib/std,lib/std/std.rad,$(STD_LIB))
41 +
SEED_OPTS         := $(STD) -pkg radiance -manifest seed/dependencies/std \
42 +
    $(call modules,compiler/radiance,compiler/radiance/radiance.rad,$(COMPILER_SRC)) \
43 +
    -entry radiance
44 +
45 +
$(RAD_BIN): Makefile $(SEED) std.lib $(STD_LIB) $(COMPILER_SRC) seed/dependencies/none \
46 +
    seed/dependencies/std | $(BIN_DIR)
37 47
	@echo "radiance $(SEED) => $@"
38 48
	@$(HOSTED) $(SEED) $(SEED_OPTS) -o $@
39 49
40 50
# Compiler inputs shared by the normal build and bootstrap stages.
41 51
compiler-options:
README +28 -4
50 50
  `seed/README` for full details on the seed workflow, verification, and
51 51
  how to handle breaking changes.
52 52
53 53
USAGE
54 54
55 -
  Compile a Radiance program:
56 -
57 -
      emulator -run bin/radiance.rv64.dev \
58 -
          -pkg example -mod example.rad -o example.rv64
55 +
  A package is a directory that holds its manifest `<name>.manifest`, its root
56 +
  module `<name>.rad`, and its other modules. For example,
57 +
  `example/example.manifest`:
58 +
59 +
      Package {
60 +
          name: "example",
61 +
          version: "0.1.0",
62 +
          dependencies: [
63 +
              Dependency { name: "std", version: "0.1.0" },
64 +
          ],
65 +
          modules: ["util"],
66 +
      }
67 +
68 +
  `modules` names the modules below the root module: `util` is the file
69 +
  `example/util.rad`. Dependencies are found by name: in the directories
70 +
  given with `-lib`, then in the `lib` directory of the package and of each
71 +
  of its parents, such as this repository's `lib`, which holds the standard
72 +
  library. `-dep <name>=<directory>` selects the package for one name.
73 +
  `lib/std/lang/manifest.rad` describes every field.
74 +
75 +
  Compile the package and its dependencies:
76 +
77 +
      emulator -run bin/radiance.rv64.dev example -o example.rv64
78 +
79 +
  A single module compiles as a package of its own, which depends on the
80 +
  packages it imports:
81 +
82 +
      emulator -run bin/radiance.rv64.dev hello.rad -o hello.rv64
59 83
60 84
  Run a compiled binary:
61 85
62 86
      emulator -run example.rv64
63 87
compiler/radiance/artifact.rad +108 -8
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 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 9
//! * `name.ril.debug`, the optional source location table for native debug output.
10 +
//! * `native/`, the exported assembly files in link order and optional startup code.
10 11
//!
11 12
//! The image's metadata identity covers the interface tree, so the trees need no
12 13
//! descriptor.
13 14
14 15
use std::char;
43 44
    Trusted,
44 45
    /// Compare the image's metadata identity with the interface tree.
45 46
    Full,
46 47
}
47 48
49 +
/// Errors in the assembly file list of a compiled package.
50 +
export union NativeError: Copy {
51 +
    /// The file name is not a canonical assembly index or `startup.ras`.
52 +
    InvalidFilename(*[u8]),
53 +
    /// The assembly file indices have a gap.
54 +
    MissingIndex,
55 +
}
56 +
48 57
/// One generated interface module.
49 58
export record Module: Copy {
50 59
    /// Relative path in the interface tree, including the `.rid` extension.
51 60
    path: *[u8],
52 61
    /// Complete immutable interface text.
87 96
88 97
/// Package artifact retained in immutable compiler storage.
89 98
export record Package: Copy {
90 99
    /// Package name and root module identity.
91 100
    name: *[u8],
101 +
    /// Package release version from the RIL header.
102 +
    version: ?*[u8],
92 103
    /// Text modules in parent-before-child order.
93 104
    modules: *[Module],
94 105
    /// Interface embeds and source locations retained with the package.
95 106
    files: *[File],
96 107
    /// Dependency names and required compiler metadata.
300 311
}
301 312
302 313
/// Read package files. Full validation checks the interface tree against the
303 314
/// image's metadata identity; trusted validation accepts that identity.
304 315
export fn read(
305 -
    root: *[u8],
316 +
    directory: *[u8],
306 317
    name: *[u8],
307 318
    validation: Validation,
308 319
    scratch: *heap::Heap,
309 320
    arena: &heap::Heap
310 321
) -> Package throws (sys::Error) {
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]);
322 +
    let image = try readFile(try join(arena, &[directory, "/", name, ".ril.bin"]), arena);
323 +
    let tree = try join(arena, &[directory, "/", INTERFACE]);
314 324
    let mut paths: *mut [*[u8]] = &mut [];
315 325
    try walk(tree, "", &mut paths, arena);
316 326
    let mut modules: *mut [Module] = &mut [];
317 327
    let mut files: *mut [File] = &mut [];
318 328
    // Sorted paths list each parent module before its children.
332 342
    }
333 343
    if modules.len == 0 or not mem::eq(modules[0].path, try join(arena, &[name, ".rid"])) {
334 344
        throw sys::Error::Invalid;
335 345
    }
336 346
    let path = try join(arena, &[name, DEBUG_EXT]);
337 -
    let origin = try join(arena, &[directory, path]);
347 +
    let origin = try join(arena, &[directory, "/", path]);
338 348
    if let bytes = try readOptional(origin, arena) {
339 349
        try files.append(
340 350
            File { path, origin, bytes, role: FileRole::Debug }, arena
341 351
        ) catch {
342 352
            throw sys::Error::TooLarge;
401 411
            arena
402 412
        ) catch {
403 413
            throw binary::Error::Storage;
404 414
        };
405 415
    }
416 +
    let mut version: ?*[u8] = nil;
417 +
    if let release = header.version {
418 +
        set version = try join(arena, &[release]);
419 +
    }
406 420
    let package = Package {
407 421
        name,
422 +
        version,
408 423
        modules,
409 424
        files,
410 425
        dependencies: &dependencies[..],
411 426
        declarations: header.links.metadata,
412 427
        image,
502 517
        return path;
503 518
    }
504 519
    throw sys::Error::Limit;
505 520
}
506 521
522 +
/// Return the path of an assembly file in link order.
523 +
fn assemblyPath(directory: *[u8], index: u32, arena: &heap::Heap) -> *[u8] throws (sys::Error) {
524 +
    let mut digits: [u8; fmt::U32_STR_LEN] = undefined;
525 +
    let number = try alloc::copyBytes(arena, fmt::formatU32(index, &mut digits[..])) catch {
526 +
        throw sys::Error::TooLarge;
527 +
    };
528 +
    return try join(arena, &[directory, "/", &number[..], ".ras"]);
529 +
}
530 +
531 +
/// Read assembly from the package's `native` directory in link order.
532 +
/// Include `startup.ras` when the caller requests it.
533 +
export fn readNative(native: *[u8], startup: bool, arena: &heap::Heap) -> *[File]
534 +
    throws (sys::Error, NativeError)
535 +
{
536 +
    let info = try fs::stat(native) else return &[];
537 +
    if info.kind <> fs::Kind::Directory {
538 +
        throw sys::Error::Invalid;
539 +
    }
540 +
    let mut names = mem::split(try list(native, arena), 0);
541 +
    let mut count: u32 = 0;
542 +
    let mut highest: u64 = 0;
543 +
    let mut hasStartup = false;
544 +
    while let name = names.next() {
545 +
        if mem::eq(name, "startup.ras") {
546 +
            set hasStartup = true;
547 +
        } else {
548 +
            let suffix = ".ras";
549 +
            if name.len <= suffix.len
550 +
                or not mem::endsWith(name, suffix)
551 +
                or (name[0] == '0' and name.len <> suffix.len + 1)
552 +
            {
553 +
                throw NativeError::InvalidFilename(name);
554 +
            }
555 +
            let index = try fmt::parseUint(&name[.. name.len - suffix.len], 10) catch {
556 +
                throw NativeError::InvalidFilename(name);
557 +
            };
558 +
            if index > highest {
559 +
                set highest = index;
560 +
            }
561 +
            set count += 1;
562 +
        }
563 +
    }
564 +
    if count > 0 and highest >= count as u64 {
565 +
        throw NativeError::MissingIndex;
566 +
    }
567 +
    let mut files: *mut [File] = &mut [];
568 +
    let length = count + (1 if hasStartup and startup else 0);
569 +
    for i in 0 .. length {
570 +
        let path = try join(arena, &[native, "/startup.ras"])
571 +
            if i == count
572 +
            else try assemblyPath(native, i, arena);
573 +
        let role = FileRole::Startup if i == count else FileRole::Assembly;
574 +
        let bytes = try readFile(path, arena);
575 +
        try files.append(File { path, origin: path, bytes, role }, arena) catch {
576 +
            throw sys::Error::TooLarge;
577 +
        };
578 +
    }
579 +
    return &files[..];
580 +
}
581 +
582 +
/// Write the native link inputs alongside the package image.
583 +
fn writeNative(directory: *[u8], files: &[File], arena: &heap::Heap) throws (sys::Error) {
584 +
    if files.len == 0 {
585 +
        return;
586 +
    }
587 +
    let native = try join(arena, &[directory, "/native"]);
588 +
    try fs::makeDir(native);
589 +
    let mut index: u32 = 0;
590 +
    for file in files {
591 +
        let mut path: *[u8] = undefined;
592 +
        match file.role {
593 +
            case FileRole::Startup => set path = try join(arena, &[native, "/startup.ras"]),
594 +
            case FileRole::Assembly => {
595 +
                set path = try assemblyPath(native, index, arena);
596 +
                set index += 1;
597 +
            }
598 +
            else => panic "writeNative: invalid file role",
599 +
        }
600 +
        try fs::writeFile(path, file.bytes);
601 +
    }
602 +
}
603 +
507 604
/// Write a complete staged package and install it at its final path.
508 -
fn install(package: &Package, stage: *[u8], destination: *[u8], arena: &heap::Heap)
605 +
fn install(package: &Package, stage: *[u8], destination: *[u8], files: &[File], arena: &heap::Heap)
509 606
    throws (sys::Error)
510 607
{
511 608
    let staged = try join(arena, &[stage, "/", package.name]);
512 609
    try write(package, stage, arena);
610 +
    try writeNative(staged, files, arena);
513 611
    try fs::rename(staged, destination) catch error {
514 612
        if error <> sys::Error::NotEmpty and error <> sys::Error::Exists {
515 613
            throw error;
516 614
        }
517 615
        let image = try join(arena, &[destination, "/", package.name, ".ril.bin"]);
522 620
        try fs::exchange(staged, destination);
523 621
    };
524 622
}
525 623
526 624
/// Replace the package directory below `root` with a complete export.
527 -
export fn publish(package: &Package, root: *[u8], arena: &heap::Heap) throws (sys::Error) {
625 +
export fn publish(package: &Package, root: *[u8], files: &[File], arena: &heap::Heap)
626 +
    throws (sys::Error)
627 +
{
528 628
    try fs::createDirAll(root);
529 629
    let destination = try join(arena, &[root, "/", package.name]);
530 630
    let stage = try temporary(destination, arena);
531 -
    try install(package, stage, destination, arena) catch error {
631 +
    try install(package, stage, destination, files, arena) catch error {
532 632
        try fs::removeTree(stage, arena) catch {};
533 633
        throw error;
534 634
    };
535 635
    try fs::removeTree(stage, arena);
536 636
}
compiler/radiance/build.rad +286 -92
18 18
use std::lang::il::binary::program;
19 19
use std::lang::il::binary::reader;
20 20
use std::lang::il::binary::writer;
21 21
use std::lang::layout;
22 22
use std::lang::lower;
23 +
use std::lang::manifest;
23 24
use std::lang::module;
24 25
use std::lang::package;
25 26
use std::lang::parser;
26 27
use std::lang::pretty;
27 28
use std::lang::resolver;
84 85
    manifest: *[u8],
85 86
}
86 87
87 88
/// Selected representation of a package.
88 89
union Contents: Copy {
89 -
    /// Implementation input whose image can be compiled or reused.
90 -
    Source(Source),
90 +
    /// Exact source manifest bytes.
91 +
    Source(*[u8]),
91 92
    /// Explicitly selected compiled artifact.
92 93
    Compiled(artifact::Package),
93 94
}
94 95
96 +
/// Native files to read for a selected package.
97 +
export union NativeInputs: Copy {
98 +
    /// No native files are used by package compilation.
99 +
    None,
100 +
    /// The assembly dump reads source paths during code generation.
101 +
    DumpPaths,
102 +
    /// Assembly linked into an executable's dependency code.
103 +
    Assembly,
104 +
    /// Assembly and startup used by the entry or exported with the package.
105 +
    All,
106 +
}
107 +
95 108
/// Manifest graph and selected representation of one package.
96 109
record Input: Copy {
97 110
    /// Command-line input descriptions.
98 111
    options: super::PackageInput,
99 112
    /// Declared dependency names in deterministic order.
100 113
    dependencies: *[*[u8]],
114 +
    /// Declared provider indices in the ordered graph.
115 +
    providers: *[u16],
101 116
    /// Assembly and startup inputs linked into native output.
102 117
    nativeFiles: *[artifact::File],
103 118
    /// Source snapshots or a complete compiled artifact.
104 119
    contents: Contents,
105 120
}
208 223
        };
209 224
    }
210 225
    return &names[..];
211 226
}
212 227
213 -
/// Capture source snapshots and load compiled package metadata.
228 +
/// Read dependency names, native inputs, and compiled package metadata.
214 229
fn snapshot(
215 230
    options: super::PackageInput,
231 +
    mode: NativeInputs,
216 232
    scratch: *heap::Heap,
217 233
    arena: &heap::Heap,
218 234
    artifacts: &heap::Heap
219 235
) -> Input
220 -
    throws (sys::Error)
236 +
    throws (sys::Error, super::Error)
221 237
{
222 238
    let mut nativeFiles: *mut [artifact::File] = &mut [];
223 -
    let count = options.asmPathCount + 1;
239 +
    let startup: u32 = 1 if mode == NativeInputs::All else 0;
240 +
    let count: u32 = 0 if mode == NativeInputs::None else options.asmPathCount + startup;
224 241
    for i in 0 .. count {
225 242
        let mut origin: *[u8] = "";
226 243
        let mut role = artifact::FileRole::Assembly;
227 244
        if i == options.asmPathCount {
228 245
            let startup = options.startupPath else continue;
234 251
        let bytes = try artifact::readFile(origin, arena);
235 252
        try nativeFiles.append(artifact::File { path: origin, origin, bytes, role }, arena) catch {
236 253
            throw sys::Error::TooLarge;
237 254
        };
238 255
    }
239 -
    if let root = options.artifactRoot {
256 +
    if let directory = options.artifactDirectory {
240 257
        let compiled = try artifact::read(
241 -
            root, options.name, artifact::Validation::Full, scratch, artifacts
258 +
            directory, options.name, artifact::Validation::Full, scratch, artifacts
242 259
        );
260 +
        if mode <> NativeInputs::None {
261 +
            let startup = mode == NativeInputs::All and options.startupPath == nil;
262 +
            let native = try artifact::join(arena, &[directory, "/native"]);
263 +
            let published = try artifact::readNative(
264 +
                native, startup, arena
265 +
            ) catch err as sys::Error {
266 +
                throw err;
267 +
            } catch err as artifact::NativeError {
268 +
                match err {
269 +
                    case artifact::NativeError::InvalidFilename(name) =>
270 +
                        throw super::error(&[
271 +
                            "invalid native assembly filename", name, "in", native
272 +
                        ]),
273 +
                    case artifact::NativeError::MissingIndex => {
274 +
                        let message = "native assembly indices must be consecutive from zero in";
275 +
                        throw super::error(&[message, native]);
276 +
                    }
277 +
                }
278 +
            };
279 +
            try nativeFiles.extend(published, arena) catch {
280 +
                throw sys::Error::TooLarge;
281 +
            };
282 +
        }
243 283
        let mut dependencies: *mut [*[u8]] = &mut [];
244 284
        for dependency in compiled.dependencies {
245 285
            try dependencies.append(dependency.name, arena) catch {
246 286
                throw sys::Error::TooLarge;
247 287
            };
248 288
        }
249 289
        return Input {
250 290
            options,
251 291
            dependencies: &dependencies[..],
292 +
            providers: &[],
252 293
            nativeFiles: &nativeFiles[..],
253 294
            contents: Contents::Compiled(compiled),
254 295
        };
255 296
    }
297 +
    let mut manifest: *[u8] = "";
298 +
    let mut dependencies: *[*[u8]] = &[];
299 +
    if let declared = options.manifest {
300 +
        set manifest = declared.text;
301 +
        set dependencies = declared.dependencies;
302 +
    } else {
303 +
        let path = options.manifestPath else try artifact::join(arena, &[
304 +
            rootDirectory(options), options.name, ".manifest"
305 +
        ]);
306 +
        if try fs::stat(path) <> nil {
307 +
            set manifest = try artifact::readFile(path, arena);
308 +
        } else if options.manifestPath <> nil {
309 +
            throw sys::Error::NotFound;
310 +
        }
311 +
        set dependencies = try dependencyNames(manifest, arena);
312 +
    }
313 +
    return Input {
314 +
        options,
315 +
        dependencies,
316 +
        providers: &[],
317 +
        nativeFiles: &nativeFiles[..],
318 +
        contents: Contents::Source(manifest),
319 +
    };
320 +
}
321 +
322 +
/// Capture a source package's implementation after its dependencies are selected.
323 +
fn source(options: super::PackageInput, manifest: *[u8], arena: &heap::Heap) -> Source
324 +
    throws (sys::Error)
325 +
{
256 326
    let mut modules: *mut [Snapshot] = &mut [];
257 327
    for i in 0 .. options.radPathCount {
258 328
        let path = options.radPaths[i];
259 329
        if not mem::endsWith(sourcePath(path), ".rad") {
260 330
            throw sys::Error::Invalid;
288 358
            Snapshot { path, logical, text }, arena
289 359
        ) catch {
290 360
            throw sys::Error::TooLarge;
291 361
        };
292 362
    }
293 -
    let path = options.manifestPath else try artifact::join(arena, &[
294 -
        rootDirectory(options), options.name, ".manifest"
295 -
    ]);
296 -
    let mut manifest: *[u8] = "";
297 -
    if try fs::stat(path) <> nil {
298 -
        set manifest = try artifact::readFile(path, arena);
299 -
    } else if options.manifestPath <> nil {
300 -
        throw sys::Error::NotFound;
301 -
    }
302 -
    let dependencies = try dependencyNames(manifest, arena);
303 -
    let mut files: *mut [artifact::File] = &mut [];
304 -
    try files.extend(try embeds(options, arena), arena) catch {
305 -
        throw sys::Error::TooLarge;
306 -
    };
307 -
    return Input {
308 -
        options,
309 -
        dependencies,
310 -
        nativeFiles: &nativeFiles[..],
311 -
        contents: Contents::Source(Source {
312 -
            modules: &modules[..], files: &files[..], manifest
313 -
        }),
314 -
    };
363 +
    let files = try embeds(options, arena);
364 +
    return Source { modules: &modules[..], files, manifest };
315 365
}
316 366
317 367
/// Return the package root: the directory of the root module, with its final `/`.
318 368
fn rootDirectory(options: super::PackageInput) -> *[u8] {
319 369
    let first = sourcePath(options.radPaths[0]);
322 372
}
323 373
324 374
/// Read the files that a source package declares for `@embed`. Each one must lie
325 375
/// under the package root, and is stored at its path from the root in the interface
326 376
/// tree.
327 -
export fn embeds(options: super::PackageInput, arena: &heap::Heap) -> *[artifact::File]
377 +
fn embeds(options: super::PackageInput, arena: &heap::Heap) -> *[artifact::File]
328 378
    throws (sys::Error)
329 379
{
330 380
    let root = rootDirectory(options);
331 381
    let mut files: *mut [artifact::File] = &mut [];
332 382
    for origin in &options.embedPaths[.. options.embedPathCount] {
354 404
    }
355 405
    return &files[..];
356 406
}
357 407
358 408
/// Return the files that a package's modules can embed, keyed by path from the package root.
359 -
export fn embedded(files: &[artifact::File], arena: &heap::Heap) -> *[module::Embed]
409 +
fn embedded(files: &[artifact::File], arena: &heap::Heap) -> *[module::Embed]
360 410
    throws (super::Error)
361 411
{
362 412
    let mut result: *mut [module::Embed] = &mut [];
363 413
    for file in files {
364 414
        if file.role == artifact::FileRole::Embed {
384 434
fn inputs(
385 435
    ctx: &mut super::CompileContext,
386 436
    scratch: *heap::Heap,
387 437
    arena: &heap::Heap,
388 438
    artifacts: &heap::Heap
389 -
) -> *[Input] throws (sys::Error) {
439 +
) -> *[Input] throws (sys::Error, super::Error) {
440 +
    let entry = ctx.entryPkgIdx else panic "inputs: missing entry package";
441 +
    let native = NativeInputs::None
442 +
        if ctx.nativeInputs == NativeInputs::DumpPaths
443 +
        else ctx.nativeInputs;
390 444
    let mut selected: *mut [Input] = &mut [];
391 445
    for i in 0 .. ctx.packageCount {
392 446
        let checked = try dependencyNames(ctx.inputs[i].name, arena);
393 447
        if checked.len <> 1 or not mem::eq(checked[0], ctx.inputs[i].name) {
394 448
            throw sys::Error::Invalid;
396 450
        for j in 0 .. i {
397 451
            if mem::eq(ctx.inputs[j].name, ctx.inputs[i].name) {
398 452
                throw sys::Error::Invalid;
399 453
            }
400 454
        }
401 -
        try selected.append(
402 -
            try snapshot(ctx.inputs[i], scratch, arena, artifacts), arena
403 -
        ) catch {
455 +
        let mode = NativeInputs::All if native == NativeInputs::Assembly and i == entry else native;
456 +
        let input = try snapshot(ctx.inputs[i], mode, scratch, arena, artifacts);
457 +
        try selected.append(input, arena) catch {
404 458
            throw sys::Error::TooLarge;
405 459
        };
406 460
    }
461 +
    let mut used: [bool; package::MAX_PACKAGES] = [false; package::MAX_PACKAGES];
407 462
    let mut i: u32 = 0;
408 463
    while i < selected.len {
409 464
        let item = selected[i];
410 465
        for name in item.dependencies {
411 466
            if find(&selected[..], name) <> nil {
412 467
                continue;
413 468
            }
414 -
            let root = item.options.artifactRoot else {
415 -
                io::printError("radiance: unresolved package dependency: ");
416 -
                io::printError(name);
417 -
                io::printError("\n");
418 -
                throw sys::Error::Invalid;
419 -
            };
420 469
            if selected.len >= package::MAX_PACKAGES {
421 470
                throw sys::Error::TooLarge;
422 471
            }
423 -
            let mut options = super::packageInput(name);
424 -
            set options.artifactRoot = root;
425 -
            let provider = try snapshot(options, scratch, arena, artifacts);
472 +
            let mut options: super::PackageInput = undefined;
473 +
            if let search = ctx.manifestSearch {
474 +
                set options = try super::discover(
475 +
                    name, search, ctx.nativeInputs, &mut used, &mut ctx.parser, arena
476 +
                );
477 +
            } else {
478 +
                let directory = item.options.artifactDirectory else {
479 +
                    throw super::error(&["unresolved package dependency:", name]);
480 +
                };
481 +
                let slash = mem::rfind(directory, "/") else panic "inputs: missing artifact parent";
482 +
                set options = super::packageInput(name);
483 +
                set options.artifactDirectory = try artifact::join(arena, &[
484 +
                    &directory[.. slash + 1], name
485 +
                ]);
486 +
            }
487 +
            let provider = try snapshot(options, native, scratch, arena, artifacts);
426 488
            try selected.append(provider, arena) catch {
427 489
                throw sys::Error::TooLarge;
428 490
            };
429 491
        }
430 492
        set i += 1;
431 493
    }
494 +
    if let search = ctx.manifestSearch {
495 +
        for given, i in search.providers {
496 +
            if not used[i] {
497 +
                throw super::error(&[
498 +
                    "`-dep` names no dependency of the package graph:", given.name
499 +
                ]);
500 +
            }
501 +
        }
502 +
    }
503 +
    try checkVersions(&selected[..]);
432 504
    let mut ordered: *mut [Input] = &mut [];
433 505
    let mut emitted: [bool; package::MAX_PACKAGES] = [false; package::MAX_PACKAGES];
434 506
    while ordered.len < selected.len {
435 507
        let mut next: ?u32 = nil;
436 508
        for i in 0 .. selected.len {
455 527
        }
456 528
        let index = next else {
457 529
            io::printError("radiance: cyclic source package dependencies\n");
458 530
            throw sys::Error::Invalid;
459 531
        };
460 -
        try ordered.append(selected[index], arena) catch {
532 +
        let mut item = selected[index];
533 +
        set item.providers = try providers(item.dependencies, &ordered[..], arena);
534 +
        try ordered.append(item, arena) catch {
461 535
            throw sys::Error::TooLarge;
462 536
        };
463 537
        set emitted[index] = true;
464 538
    }
465 539
    return &ordered[..];
466 540
}
467 541
542 +
/// Check release constraints declared by each source manifest.
543 +
fn checkVersions(selected: &[Input]) throws (super::Error) {
544 +
    for input in selected {
545 +
        let declared = input.options.manifest else continue;
546 +
        for dependency in declared.requirements {
547 +
            let i = find(selected, dependency.name) else panic "checkVersions: missing provider";
548 +
            let provider = selected[i];
549 +
            let mut location: *[u8] = undefined;
550 +
            let mut version: ?*[u8] = nil;
551 +
            match provider.contents {
552 +
                case Contents::Compiled(package) => {
553 +
                    let directory = provider.options.artifactDirectory
554 +
                        else panic "checkVersions: missing artifact directory";
555 +
                    set location = directory;
556 +
                    set version = package.version;
557 +
                }
558 +
                case Contents::Source(_) => {
559 +
                    let path = provider.options.manifestPath
560 +
                        else sourcePath(provider.options.radPaths[0]);
561 +
                    set location = path;
562 +
                    if let manifest = provider.options.manifest {
563 +
                        set version = manifest.version;
564 +
                    }
565 +
                }
566 +
            }
567 +
            let release = version else {
568 +
                throw super::error(
569 +
                    &[
570 +
                        "package", input.options.name, "requires", dependency.name, "version",
571 +
                        dependency.version, "but", location, "has no version",
572 +
                    ]
573 +
                );
574 +
            };
575 +
            if not manifest::compatible(dependency.version, release) {
576 +
                throw super::error(
577 +
                    &[
578 +
                        "package", input.options.name, "requires", dependency.name, "version",
579 +
                        dependency.version, "but", location, "has version", release,
580 +
                    ]
581 +
                );
582 +
            }
583 +
        }
584 +
    }
585 +
}
586 +
468 587
/// Return provider indices in the current graph from declared dependency names.
469 -
fn providers(input: &Input, packages: &[Input], arena: &heap::Heap) -> *[u16]
588 +
fn providers(dependencies: &[*[u8]], packages: &[Input], arena: &heap::Heap) -> *[u16]
470 589
    throws (sys::Error)
471 590
{
472 591
    let mut result: *mut [u16] = &mut [];
473 -
    for name in input.dependencies {
474 -
        let mut found: ?u16 = nil;
475 -
        for package, i in packages {
476 -
            if mem::eq(package.options.name, name) {
477 -
                set found = i as u16;
478 -
                break;
479 -
            }
480 -
        }
481 -
        let index = found else throw sys::Error::Invalid;
482 -
        try result.append(index, arena) catch {
592 +
    for name in dependencies {
593 +
        let index = find(packages, name) else panic "providers: missing provider";
594 +
        try result.append(index as u16, arena) catch {
483 595
            throw sys::Error::TooLarge;
484 596
        };
485 597
    }
486 598
    return &result[..];
487 599
}
542 654
            throw super::Error::Other;
543 655
        };
544 656
    }
545 657
    let root = ctx.packages[id].rootModuleId else panic "load: package has no root module";
546 658
    set graph.entries[root as u32].embeds = embeds;
659 +
    if role == module::Role::Source
660 +
        and ctx.dump <> super::Dump::Ast
661 +
        and ctx.dump <> super::Dump::Graph
662 +
    {
663 +
        try checkDeclared(ctx, graph, id);
664 +
    }
665 +
}
666 +
667 +
/// Check that the parent of each module of package `id` declares it with
668 +
/// `mod`, so that no module is compiled without analysis. A test module is
669 +
/// declared only in a test build.
670 +
fn checkDeclared(ctx: &super::CompileContext, graph: &module::ModuleGraph, id: u32)
671 +
    throws (super::Error)
672 +
{
673 +
    for entry in &graph.entries[.. graph.entriesLen] {
674 +
        if entry.packageId as u32 <> id {
675 +
            continue;
676 +
        }
677 +
        let parent = entry.parent else continue;
678 +
        let parentAst = graph.entries[parent as u32].ast
679 +
            else panic "checkDeclared: parent not parsed";
680 +
        let case ast::NodeValue::Module(block) = parentAst.value
681 +
            else panic "checkDeclared: expected a module";
682 +
        let mut declared = false;
683 +
        for node in block.statements {
684 +
            let case ast::NodeValue::Mod(decl) = node.value else continue;
685 +
            let case ast::NodeValue::Ident(name) = decl.name.value else continue;
686 +
            if mem::eq(name, entry.name) {
687 +
                let mut testOnly = false;
688 +
                if let attrs = decl.attrs {
689 +
                    set testOnly = ast::attributesContains(&attrs, ast::Attribute::Test);
690 +
                }
691 +
                set declared = ctx.config.buildTest or not testOnly;
692 +
            }
693 +
        }
694 +
        if not declared {
695 +
            throw super::error(&["module", entry.filePath, "is not declared by its parent module"]);
696 +
        }
697 +
    }
547 698
}
548 699
549 700
/// Publish immutable module entry copies while the source graph appends new modules.
550 701
fn table(graph: &module::ModuleGraph, arena: &heap::Heap) -> module::ModuleTable
551 702
    throws (super::Error)
624 775
            throw super::error(&["missing package dependency", dependency.name]);
625 776
        }
626 777
    }
627 778
}
628 779
780 +
/// Resolve and order the package inputs and set the entry package index.
781 +
fn selectInputs(
782 +
    ctx: &mut super::CompileContext,
783 +
    scratch: *heap::Heap,
784 +
    sourceArena: &heap::Heap,
785 +
    artifacts: &heap::Heap
786 +
) -> *[Input] throws (super::Error) {
787 +
    let selected = try inputs(ctx, scratch, sourceArena, artifacts) catch failure as sys::Error {
788 +
        throw super::error(&["cannot read package inputs or dependency manifests"]);
789 +
    } catch failure as super::Error {
790 +
        throw failure;
791 +
    };
792 +
    let entryIndex = ctx.entryPkgIdx else panic "selectInputs: missing entry package";
793 +
    let entryName = ctx.inputs[entryIndex].name;
794 +
    let entry = find(&selected[..], entryName)
795 +
        else panic "selectInputs: entry package not selected";
796 +
    set ctx.entryPkgIdx = entry;
797 +
    return selected;
798 +
}
799 +
800 +
/// Register source modules in dependency order for a whole-program dump.
801 +
export fn inspect(
802 +
    ctx: &mut super::CompileContext,
803 +
    graph: &mut module::ModuleGraph,
804 +
    scratch: *heap::Heap,
805 +
    sourceArena: &heap::Heap,
806 +
    artifacts: &heap::Heap,
807 +
    driverArena: &heap::Heap
808 +
) throws (super::Error) {
809 +
    let selected = try selectInputs(ctx, scratch, sourceArena, artifacts);
810 +
    resetFrontend(ctx, graph, scratch);
811 +
    set ctx.packageCount = selected.len;
812 +
    for input, i in selected {
813 +
        set ctx.inputs[i] = input.options;
814 +
        let case Contents::Source(manifest) = input.contents else {
815 +
            throw super::error(&["source inspection requires implementation source"]);
816 +
        };
817 +
        let implementation = try source(input.options, manifest, sourceArena) catch {
818 +
            throw super::error(&["cannot read sources of package", input.options.name]);
819 +
        };
820 +
        let files = try embedded(implementation.files, driverArena);
821 +
        try load(
822 +
            ctx, graph, i, implementation.modules, module::Role::Source, input.providers, files
823 +
        );
824 +
    }
825 +
}
826 +
629 827
/// Compile selected packages and produce the requested final output.
630 828
export fn run(
631 829
    ctx: &mut super::CompileContext,
632 830
    graph: &mut module::ModuleGraph,
633 831
    work: &mut Workspace,
634 832
    sourceArena: &heap::Heap,
635 833
    driverArena: &heap::Heap,
636 834
    compiler: binary::Id
637 835
) throws (super::Error) {
638 -
    let selected = try inputs(ctx, work.main, sourceArena, work.artifacts) catch {
639 -
        throw super::error(&["cannot read package inputs or dependency manifests"]);
640 -
    };
641 -
    let entryIndex = ctx.entryPkgIdx else panic "run: missing entry package";
642 -
    let entryName = ctx.inputs[entryIndex].name;
643 -
    // Package slots follow the selected order from here on.
644 -
    let mut found: ?u32 = nil;
645 -
    for input, index in selected {
646 -
        if mem::eq(input.options.name, entryName) {
647 -
            set found = index;
648 -
        }
649 -
    }
650 -
    let entry = found else panic "run: entry package not selected";
651 -
    set ctx.entryPkgIdx = entry;
836 +
    let selected = try selectInputs(ctx, work.main, sourceArena, work.artifacts);
837 +
    let entry = ctx.entryPkgIdx else panic "run: missing entry package";
838 +
    let entryName = selected[entry].options.name;
652 839
    let built = try buildPackages(
653 -
        ctx, graph, work, selected, entryName, driverArena, compiler
840 +
        ctx, graph, work, selected, entryName, sourceArena, driverArena, compiler
654 841
    );
655 842
    let case BuiltPackages { packages, native, data, sourcePaths, asmData } = built
656 843
        else panic "run: expected package results";
657 844
    if let directory = ctx.rilDirectory {
658 -
        try writePackages(packages, directory, driverArena);
845 +
        try writePackages(packages, selected, directory, driverArena);
659 846
    }
660 847
    if let output = ctx.outputPath {
661 848
        resetFrontend(ctx, graph, work.main);
662 849
        let case locations::Native::Program(native) = native
663 850
            else panic "run: missing native generator";
673 860
    ctx: &mut super::CompileContext,
674 861
    graph: &mut module::ModuleGraph,
675 862
    work: &mut Workspace,
676 863
    selected: *[Input],
677 864
    entryName: *[u8],
865 +
    sourceArena: &heap::Heap,
678 866
    driverArena: &heap::Heap,
679 867
    compiler: binary::Id
680 868
) -> BuiltPackages throws (super::Error) {
681 869
    let entry = ctx.entryPkgIdx else panic "buildPackages: missing entry package";
682 870
    let initial = try nativeOutput(ctx, selected[entry], work);
689 877
    let mut published: *mut [link::Provider] = &mut [];
690 878
    for input, index in selected {
691 879
        set ctx.inputs[index] = input.options;
692 880
        // Only the current package and its predecessors are registered.
693 881
        set ctx.packageCount = index + 1;
694 -
        let providerIds = try providers(&input, &selected[.. index], driverArena) catch {
695 -
            throw super::error(&["cannot select package providers"]);
696 -
        };
882 +
        let providerIds = input.providers;
697 883
        let mut built: artifact::Package = undefined;
698 884
        let mut fresh = false;
699 885
        match input.contents {
700 886
            case Contents::Compiled(package) => set built = package,
701 -
            case Contents::Source(source) => {
887 +
            case Contents::Source(manifest) => {
888 +
                let source = try source(input.options, manifest, sourceArena) catch {
889 +
                    throw super::error(&["cannot read sources of package", input.options.name]);
890 +
                };
702 891
                resetFrontend(ctx, graph, work.main);
703 892
                let request: ?binary::Id = key(
704 893
                    ctx,
705 894
                    &input.options,
706 895
                    &source,
872 1061
    selected: &[Input],
873 1062
    compiled: &[artifact::Package],
874 1063
    driverArena: &heap::Heap
875 1064
) throws (super::Error) {
876 1065
    for i in 0 .. compiled.len {
877 -
        let deps = try providers(&selected[i], &selected[.. i], driverArena) catch {
878 -
            throw super::Error::Other;
879 -
        };
880 1066
        let mut modules: *mut [Snapshot] = &mut [];
881 1067
        for item in compiled[i].modules {
882 1068
            try modules.append(
883 1069
                Snapshot {
884 1070
                    path: item.path, logical: item.path, text: item.text
888 1074
                throw super::Error::Other;
889 1075
            };
890 1076
        }
891 1077
        let embeds = try embedded(compiled[i].files, driverArena);
892 1078
        try load(
893 -
            ctx, graph, i, &modules[..], module::Role::Interface, deps, embeds
1079 +
            ctx, graph, i, &modules[..], module::Role::Interface, selected[i].providers, embeds
894 1080
        );
895 1081
    }
896 1082
}
897 1083
898 1084
/// Write package artifact trees.
899 -
fn writePackages(compiled: &[artifact::Package], directory: *[u8], driverArena: &heap::Heap)
1085 +
fn writePackages(
1086 +
    compiled: &[artifact::Package], selected: &[Input], directory: *[u8], arena: &heap::Heap
1087 +
)
900 1088
    throws (super::Error)
901 1089
{
902 -
    for package in compiled {
903 -
        try artifact::publish(&package, directory, driverArena) catch {
1090 +
    for package, i in compiled {
1091 +
        let saved = heap::mark(arena);
1092 +
        try artifact::publish(&package, directory, selected[i].nativeFiles, arena) catch {
904 1093
            throw super::error(&["cannot write package artifacts", package.name]);
905 1094
        };
1095 +
        // Publication retains no paths or directory listings.
1096 +
        unsafe {
1097 +
            heap::rewind(arena, saved);
1098 +
        }
906 1099
    }
907 1100
}
908 1101
909 1102
/// Begin native generation and assemble the selected startup input.
910 1103
fn nativeOutput(
1268 1461
        &references[..],
1269 1462
        index as u16
1270 1463
    ) catch {
1271 1464
        throw super::error(&["cannot resolve package imports"]);
1272 1465
    };
1466 +
    if let declared = ctx.inputs[index].manifest {
1467 +
        set plan.image.version = declared.version;
1468 +
    }
1273 1469
    super::pkgLog(&pkg, &["encoding package tables"]);
1274 1470
    let functionCount = spool.count;
1275 1471
    // The spool kept the exported signatures, so the contract is hashed from the tables
1276 1472
    // in memory, before the head that records its metadata is encoded.
1277 1473
    let declaredFunctions = spool.declared.take();
1310 1506
            throw super::error(&["package encoding storage exhausted", pkg.name]);
1311 1507
        };
1312 1508
    }
1313 1509
    let mut result = artifact::Package {
1314 1510
        name: pkg.name,
1511 +
        version: plan.image.version,
1315 1512
        modules: declarations,
1316 1513
        files: &packageFiles[..],
1317 1514
        dependencies: &dependencies[..],
1318 1515
        declarations: binary::Id { bytes: [0; linkage::ID_BYTES] },
1319 1516
        image: nil,
1457 1654
    let mut debug = reader::new(debugBytes);
1458 1655
    if debugBytes.len > 0 {
1459 1656
        set sourceCount = try debug.count(4) catch {
1460 1657
            throw super::Error::Other;
1461 1658
        };
1462 -
        if sourceCount <> package.modules.len {
1659 +
        if sourceCount <> package.modules.len
1660 +
            or (selected.options.artifactDirectory == nil
1661 +
                and sourceCount <> selected.options.radPathCount)
1662 +
        {
1463 1663
            throw super::error(&["package debug module count mismatch", package.name]);
1464 1664
        }
1465 1665
        for i in 0 .. sourceCount {
1466 1666
            let mut path = try debug.bytes(work.emitter) catch {
1467 1667
                throw super::Error::Other;
1468 1668
            };
1469 -
            if let case Contents::Source(source) = selected.contents {
1470 -
                if i >= source.modules.len
1471 -
                    or not mem::endsWith(path, ".rad")
1472 -
                    or not mem::eq(&path[.. path.len - 4], source.modules[i].logical)
1473 -
                {
1474 -
                    throw super::error(&["invalid cached debug module", path]);
1475 -
                }
1476 -
                set path = sourcePath(source.modules[i].path);
1669 +
            if selected.options.artifactDirectory == nil {
1670 +
                set path = sourcePath(selected.options.radPaths[i]);
1477 1671
            }
1478 1672
            try sourcePaths.append(path, work.emitter) catch {
1479 1673
                throw super::Error::Other;
1480 1674
            };
1481 1675
        }
compiler/radiance/cache.rad +1 -1
31 31
    key: binary::Id,
32 32
    scratch: *heap::Heap,
33 33
    arena: &heap::Heap
34 34
) -> ?artifact::Package throws (sys::Error) {
35 35
    let saved = heap::mark(arena);
36 -
    let path = try entry(root, key, arena);
36 +
    let path = try artifact::join(arena, &[try entry(root, key, arena), "/", name]);
37 37
    let result = try artifact::read(
38 38
        path, name, artifact::Validation::Trusted, scratch, arena
39 39
    ) catch error {
40 40
        // Failed reads publish no pointers into their temporary allocations.
41 41
        unsafe {
compiler/radiance/radiance.manifest added +18 -0
1 +
// The Radiance compiler.
2 +
Package {
3 +
    name: "radiance",
4 +
    version: "1.0.0",
5 +
    dependencies: [
6 +
        Dependency { name: "std", version: "0.1.0" },
7 +
    ],
8 +
    modules: [
9 +
        "codegen",
10 +
        "testgen",
11 +
        "link",
12 +
        "artifact",
13 +
        "metadata",
14 +
        "build",
15 +
        "cache",
16 +
        "locations",
17 +
    ],
18 +
}
compiler/radiance.rad → compiler/radiance/radiance.rad renamed +488 -87
10 10
11 11
use std::arch::rv64;
12 12
use std::arch::rv64::asm;
13 13
use std::arch::rv64::image;
14 14
use std::arch::rv64::printer;
15 +
use std::char;
15 16
use std::collections::dict;
16 17
use std::fmt;
17 18
use std::fs;
18 19
use std::io;
19 20
use std::lang::alloc::AllocError;
22 23
use std::lang::gen::labels;
23 24
use std::lang::il;
24 25
use std::lang::il::binary;
25 26
use std::lang::layout;
26 27
use std::lang::lower;
28 +
use std::lang::manifest;
27 29
use std::lang::module;
28 30
use std::lang::package;
29 31
use std::lang::parser;
30 32
use std::lang::pretty;
31 33
use std::lang::resolver;
95 97
/// Default directory for package cache entries.
96 98
constant DEFAULT_CACHE_DIR: *[u8] = "cache";
97 99
98 100
/// Usage string.
99 101
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.\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";
102 +
    "usage: radiance [-lib <directory>].. [-dep <name>=<directory>].. [<package directory>] [-o <output> | -ril <directory>]\n       radiance [-lib <directory>].. [-dep <name>=<directory>].. [-name <name>] <module.rad> [-o <output> | -ril <directory>]\nThe package directory holds <name>.manifest; the default is the current directory.\nA module.rad is a package of one module, named after the file unless -name is given,\nwhich depends on the packages it imports.\nDependencies are found by name: with -dep, in the -lib directories in order, then in\nthe lib directory of the package and of each of its parents. A directory holds the\nsource package <name>/<name>.manifest or the compiled package <name>/<name>.ril.bin.\n       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.\nWith -pkg, assembly inputs require -o or -dump asm.\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 103
102 104
/// Compiler error.
103 105
export union Error: Copy {
104 106
    Other,
105 107
}
124 126
    Il,
125 127
    /// Dump the generated assembly.
126 128
    Asm,
127 129
}
128 130
131 +
/// Dependency declarations of a package read from a package manifest.
132 +
export record ManifestInput: Copy {
133 +
    /// Exact manifest bytes.
134 +
    text: *[u8],
135 +
    /// Release version from a package manifest.
136 +
    version: ?*[u8],
137 +
    /// Version constraints in dependency order. Single modules have none.
138 +
    requirements: *[manifest::Dependency],
139 +
    /// Declared dependency names in manifest order.
140 +
    dependencies: *[*[u8]],
141 +
}
142 +
143 +
/// Name of the library directories searched from the entry package upward.
144 +
constant LIBRARY: *[u8] = "lib";
145 +
/// Extension of a root module given in place of a package directory.
146 +
constant MODULE_EXT: *[u8] = ".rad";
147 +
148 +
/// A package found by name.
149 +
export union Found: Copy {
150 +
    /// Source package with this manifest.
151 +
    Source(*[u8]),
152 +
    /// Compiled package in this directory.
153 +
    Compiled(*[u8]),
154 +
}
155 +
156 +
/// Provider of one dependency, selected with `-dep`.
157 +
export record Provider: Copy {
158 +
    /// Dependency name.
159 +
    name: *[u8],
160 +
    /// The selected package.
161 +
    found: Found,
162 +
}
163 +
164 +
/// How to discover package inputs in a manifest graph.
165 +
export record ManifestSearch: Copy {
166 +
    /// Library directories from `-lib`, searched in order before the
167 +
    /// [`LIBRARY`] directories of the entry package and its parents.
168 +
    libraries: *[*[u8]],
169 +
    /// Providers from `-dep`, which override the library search.
170 +
    providers: *[Provider],
171 +
    /// Whether test modules are added.
172 +
    tests: bool,
173 +
}
174 +
175 +
/// Command-line options for a manifest-based invocation.
176 +
record ManifestArgs {
177 +
    /// Directory of the entry package, or a single root module.
178 +
    path: ?*[u8],
179 +
    /// Package name of a single root module.
180 +
    name: ?*[u8],
181 +
    /// Dependency search locations and input roles.
182 +
    search: ManifestSearch,
183 +
}
184 +
129 185
/// Source inputs belonging to one command-line package.
130 186
export record PackageInput: Copy {
131 187
    /// Package name from the `-pkg` argument.
132 188
    name: *[u8],
133 -
    /// Explicit artifact root for a compiled package.
134 -
    artifactRoot: ?*[u8],
135 -
    /// Explicit source dependency manifest.
189 +
    /// Directory of a compiled package.
190 +
    artifactDirectory: ?*[u8],
191 +
    /// Location of a source dependency manifest.
136 192
    manifestPath: ?*[u8],
193 +
    /// Dependencies read from a package manifest, which replace `manifestPath`.
194 +
    manifest: ?ManifestInput,
137 195
    /// Optional startup assembly emitted before generated text.
138 196
    startupPath: ?*[u8],
139 197
    /// Radiance source paths or logical path mappings for this package.
140 198
    radPaths: [*[u8]; MAX_LOADED_MODULES],
141 199
    /// Number of Radiance source paths.
158 216
    inputs: [PackageInput; package::MAX_PACKAGES],
159 217
    /// Number of packages.
160 218
    packageCount: u32,
161 219
    /// Index of entry package.
162 220
    entryPkgIdx: ?u32,
221 +
    /// Search locations for manifest-based builds.
222 +
    manifestSearch: ?ManifestSearch,
163 223
    /// Parser and string pool for the current frontend pass or artifact read.
164 224
    parser: parser::Parser,
165 225
    /// Resolver configuration.
166 226
    config: resolver::Config,
167 227
    /// What to dump during compilation.
168 228
    dump: Dump,
169 229
    /// Output path for binary.
170 230
    outputPath: ?*[u8],
231 +
    /// Native files required for this invocation.
232 +
    nativeInputs: build::NativeInputs,
171 233
    /// Output directory for separate binary RIL packages.
172 234
    rilDirectory: ?*[u8],
173 235
    /// Automatic package cache root, absent when caching is bypassed.
174 236
    cacheDirectory: ?*[u8],
175 237
    /// Whether to emit debug info (.debug file).
315 377
316 378
/// Create an empty source input set for one package.
317 379
export fn packageInput(name: *[u8]) -> PackageInput {
318 380
    return PackageInput {
319 381
        name,
320 -
        artifactRoot: nil,
382 +
        artifactDirectory: nil,
321 383
        manifestPath: nil,
384 +
        manifest: nil,
322 385
        startupPath: nil,
323 386
        radPaths: [""; MAX_LOADED_MODULES],
324 387
        radPathCount: 0,
325 388
        asmPaths: [""; MAX_ASM_MODULES],
326 389
        asmPathCount: 0,
327 390
        embedPaths: [""; MAX_EMBEDS],
328 391
        embedPathCount: 0,
329 392
    };
330 393
}
331 394
332 -
/// Register, load, and parse a source path or `logical/path=source.rad` mapping.
333 -
fn processModule(
334 -
    pkg: &mut package::Package,
335 -
    graph: &mut module::ModuleGraph,
336 -
    input: *[u8],
337 -
    frontend: &mut parser::Parser,
338 -
    sourceArena: &heap::Heap
339 -
) throws (Error) {
340 -
    let mut path = input;
341 -
    let mut logical: ?*[u8] = nil;
342 -
    for byte, i in input {
343 -
        if byte == '=' {
344 -
            set logical = &input[.. i];
345 -
            set path = &input[i + 1 ..];
346 -
            break;
347 -
        }
395 +
/// Add a Radiance module path to a package input.
396 +
fn addModule(input: &mut PackageInput, path: *[u8]) throws (Error) {
397 +
    if input.radPathCount >= MAX_LOADED_MODULES {
398 +
        throw error(&["too many modules specified for package", input.name]);
348 399
    }
349 -
    pkgLog(pkg, &["parsing", "(", path, ")", ".."]);
400 +
    set input.radPaths[input.radPathCount] = path;
401 +
    set input.radPathCount += 1;
402 +
}
350 403
351 -
    let mut moduleId: u16 = 0;
352 -
    if let name = logical {
353 -
        let root = pkg.rootModuleId else {
354 -
            throw error(&["error registering module: mapped source needs a package root"]);
404 +
/// Add an assembly path to a package input.
405 +
fn addAssembly(input: &mut PackageInput, path: *[u8]) throws (Error) {
406 +
    if input.asmPathCount >= MAX_ASM_MODULES {
407 +
        throw error(&["too many assembly modules specified for package", input.name]);
408 +
    }
409 +
    set input.asmPaths[input.asmPathCount] = path;
410 +
    set input.asmPathCount += 1;
411 +
}
412 +
413 +
/// Add an embedded file path to a package input.
414 +
fn addEmbed(input: &mut PackageInput, path: *[u8]) throws (Error) {
415 +
    if input.embedPathCount >= MAX_EMBEDS {
416 +
        throw error(&["too many embedded files specified for package", input.name]);
417 +
    }
418 +
    set input.embedPaths[input.embedPathCount] = path;
419 +
    set input.embedPathCount += 1;
420 +
}
421 +
422 +
/// Return the location of `path`, written in the manifest at `manifestPath`.
423 +
fn locate(manifestPath: *[u8], path: *[u8], arena: &heap::Heap) -> *[u8] throws (Error) {
424 +
    return try manifest::resolve(manifestPath, path, arena) catch {
425 +
        throw error(&["path too long in manifest", manifestPath]);
426 +
    };
427 +
}
428 +
429 +
/// Return `list` with `item` added.
430 +
fn appended(list: *[*[u8]], item: *[u8], arena: &heap::Heap) -> *[*[u8]] throws (Error) {
431 +
    let mut result: *mut [*[u8]] = &mut [];
432 +
    try result.extend(list, arena) catch {
433 +
        throw error(&["source arena exhausted"]);
434 +
    };
435 +
    try result.append(item, arena) catch {
436 +
        throw error(&["source arena exhausted"]);
437 +
    };
438 +
    return &result[..];
439 +
}
440 +
441 +
/// Check whether a file or directory exists at `path`.
442 +
fn exists(path: *[u8]) -> bool throws (Error) {
443 +
    let found = try fs::stat(path) catch {
444 +
        throw error(&["cannot read", path]);
445 +
    };
446 +
    return found <> nil;
447 +
}
448 +
449 +
/// Return the library directories searched for the dependencies of the
450 +
/// package in `directory`: `-lib` directories in order, then [`LIBRARY`] in
451 +
/// `directory` and in each of its parents, up to the current directory.
452 +
fn libraryPath(directory: *[u8], libraries: *[*[u8]], arena: &heap::Heap) -> *[*[u8]]
453 +
    throws (Error)
454 +
{
455 +
    let mut result: *mut [*[u8]] = &mut [];
456 +
    try result.extend(libraries, arena) catch {
457 +
        throw error(&["source arena exhausted"]);
458 +
    };
459 +
    let mut current = try locate("", directory, arena);
460 +
    loop {
461 +
        let candidate = try artifact::join(arena, &[current, "/", LIBRARY]) catch {
462 +
            throw error(&["source arena exhausted"]);
355 463
        };
356 -
        set moduleId = try module::registerAtPath(
357 -
            graph, &mut frontend.pool, root, name, path
358 -
        ) catch {
359 -
            throw error(&["error registering module:", path]);
464 +
        let library = try locate("", candidate, arena);
465 +
        try result.append(library, arena) catch {
466 +
            throw error(&["source arena exhausted"]);
360 467
        };
361 -
    } else {
362 -
        set moduleId = try package::registerModule(
363 -
            pkg, graph, &mut frontend.pool, path
364 -
        ) catch failure {
365 -
            if let rootId = pkg.rootModuleId; failure == module::ModuleError::InvalidPath {
366 -
                let root = module::entry(graph, rootId)
367 -
                    else panic "processModule: package root is missing";
368 -
                let prefix = module::trimExtension(root.filePath)
369 -
                    else panic "processModule: root extension is invalid";
370 -
                throw error(
371 -
                    &[
372 -
                        "error registering module:", path,
373 -
                        "expected child path under", prefix,
374 -
                    ]
375 -
                );
376 -
            }
377 -
            throw error(&["error registering module:", path]);
468 +
        if mem::eq(current, ".")
469 +
            or mem::eq(current, "/")
470 +
            or mem::eq(current, "..")
471 +
            or mem::endsWith(current, "/..")
472 +
        {
473 +
            break;
474 +
        }
475 +
        if let slash = mem::rfind(current, "/") {
476 +
            set current = "/" if slash == 0 else &current[.. slash];
477 +
        } else {
478 +
            set current = ".";
479 +
        }
480 +
    }
481 +
    return &result[..];
482 +
}
483 +
484 +
/// Find package `name` in the directory `directory`: the source package with
485 +
/// the manifest `directory/name.manifest`, or the compiled package
486 +
/// `directory/name.ril.bin`.
487 +
fn findPackage(directory: *[u8], name: *[u8], arena: &heap::Heap) -> ?Found throws (Error) {
488 +
    let file = try manifest::file(directory, name, arena) catch {
489 +
        throw error(&["path too long:", directory]);
490 +
    };
491 +
    if try exists(file) {
492 +
        return Found::Source(file);
493 +
    }
494 +
    let image = try artifact::join(arena, &[directory, "/", name, ".ril.bin"]) catch {
495 +
        throw error(&["source arena exhausted"]);
496 +
    };
497 +
    if try exists(image) {
498 +
        return Found::Compiled(directory);
499 +
    }
500 +
    return nil;
501 +
}
502 +
503 +
/// Find package `name` in the library directories `libraries`, as the
504 +
/// package directory `name` of the first one that holds it.
505 +
fn findLibrary(name: *[u8], libraries: *[*[u8]], arena: &heap::Heap) -> Found throws (Error) {
506 +
    for library in libraries {
507 +
        let joined = try artifact::join(arena, &[library, "/", name]) catch {
508 +
            throw error(&["source arena exhausted"]);
378 509
        };
510 +
        if let found = try findPackage(try locate("", joined, arena), name, arena) {
511 +
            return found;
512 +
        }
379 513
    }
380 -
    let source = try readModuleSource(sourceArena, path);
514 +
    io::printError("radiance: library directories searched:");
515 +
    for library in libraries {
516 +
        io::printError(" ");
517 +
        io::printError(library);
518 +
    }
519 +
    io::printError("\n");
520 +
    throw error(&["package", name, "not found"]);
521 +
}
522 +
523 +
/// Return `providers` with the provider of a `-dep <name>=<directory>`
524 +
/// argument added.
525 +
fn withProvider(providers: *[Provider], arg: *[u8], arena: &heap::Heap) -> *[Provider]
526 +
    throws (Error)
527 +
{
528 +
    let at = mem::find(arg, "=") else throw error(&["`-dep` requires <name>=<directory>"]);
529 +
    let name = &arg[.. at];
530 +
    if name.len == 0 or at + 1 >= arg.len {
531 +
        throw error(&["`-dep` requires <name>=<directory>"]);
532 +
    }
533 +
    let directory = try locate("", &arg[at + 1 ..], arena);
534 +
    let found = try findPackage(directory, name, arena) else {
535 +
        throw error(&["`-dep`:", directory, "holds no package", name]);
536 +
    };
537 +
    let mut result: *mut [Provider] = &mut [];
538 +
    try result.extend(providers, arena) catch {
539 +
        throw error(&["source arena exhausted"]);
540 +
    };
541 +
    try result.append(Provider { name, found }, arena) catch {
542 +
        throw error(&["source arena exhausted"]);
543 +
    };
544 +
    return &result[..];
545 +
}
546 +
547 +
/// Return the packages that the module `root` imports: the first name of
548 +
/// each `use` path, other than `super` and the package `own` itself.
549 +
fn imports(root: *ast::Node, own: *[u8], arena: &heap::Heap) -> *[*[u8]] throws (Error) {
550 +
    let case ast::NodeValue::Module(block) = root.value else panic "imports: expected a module";
551 +
    let mut result: *mut [*[u8]] = &mut [];
552 +
    for node in block.statements {
553 +
        let case ast::NodeValue::Use(decl) = node.value else continue;
554 +
        let mut path = decl.path;
555 +
        while let case ast::NodeValue::ScopeAccess(access) = path.value {
556 +
            set path = access.parent;
557 +
        }
558 +
        let case ast::NodeValue::Ident(name) = path.value else continue;
559 +
        let mut known = mem::eq(name, own) or mem::eq(name, "super");
560 +
        for i in 0 .. result.len {
561 +
            set known = known or mem::eq(result[i], name);
562 +
        }
563 +
        if not known {
564 +
            try result.append(name, arena) catch {
565 +
                throw error(&["source arena exhausted"]);
566 +
            };
567 +
        }
568 +
    }
569 +
    return &result[..];
570 +
}
571 +
572 +
/// Return the package name of the root module `path` given without a
573 +
/// manifest: `name`, or the file name without its extension.
574 +
fn moduleName(path: *[u8], name: ?*[u8]) -> *[u8] throws (Error) {
575 +
    if let given = name {
576 +
        return given;
577 +
    }
578 +
    let mut start: u32 = 0;
579 +
    if let slash = mem::rfind(path, "/") {
580 +
        set start = slash + 1;
581 +
    }
582 +
    let stem = &path[start .. path.len - MODULE_EXT.len];
583 +
    for byte, i in stem {
584 +
        if not (char::isAlpha(byte) or byte == '_' or (i > 0 and char::isDigit(byte))) {
585 +
            throw error(&["cannot name a package after", path, "; use `-name`"]);
586 +
        }
587 +
    }
588 +
    return stem;
589 +
}
381 590
382 -
    let ast = try parser::parseModule(frontend, scanner::SourceLoc::File(path), source) catch {
591 +
/// Read the entry package of a root module given without a manifest.
592 +
fn loadSingle(
593 +
    path: *[u8], name: ?*[u8], syntax: &mut parser::Parser, arena: &heap::Heap
594 +
) -> PackageInput throws (Error) {
595 +
    let mut input = packageInput(try moduleName(path, name));
596 +
    try addModule(&mut input, path);
597 +
    let text = try readModuleSource(arena, path);
598 +
    let root = try parser::parseModule(syntax, scanner::SourceLoc::File(path), text) catch {
383 599
        throw Error::Other;
384 600
    };
385 -
    try module::setAst(graph, moduleId, ast) catch {
386 -
        throw error(&["error setting AST"]);
601 +
    let dependencies = try imports(root, input.name, arena);
602 +
    set input.manifest = ManifestInput {
603 +
        text: "", version: nil, requirements: &[], dependencies
387 604
    };
388 -
    try module::setSource(graph, moduleId, source) catch {
389 -
        throw error(&["error setting source"]);
605 +
    return input;
606 +
}
607 +
608 +
/// Load the source input of the package described by the manifest at `location`.
609 +
fn loadManifest(
610 +
    location: *[u8],
611 +
    expected: ?*[u8],
612 +
    tests: bool,
613 +
    native: build::NativeInputs,
614 +
    syntax: &mut parser::Parser,
615 +
    arena: &heap::Heap
616 +
) -> PackageInput throws (Error) {
617 +
    let text = try readModuleSource(arena, location);
618 +
    let declared = try manifest::read(syntax, location, text, arena) catch {
619 +
        throw error(&["invalid package manifest", location]);
620 +
    };
621 +
    let directory = try locate(location, ".", arena);
622 +
    let file = try manifest::file(directory, declared.name, arena) catch {
623 +
        throw error(&["path too long:", location]);
390 624
    };
625 +
    if not mem::eq(file, location) {
626 +
        throw error(&[
627 +
            "manifest", location, "of package", declared.name, "must be named", file
628 +
        ]);
629 +
    }
630 +
    if let name = expected; not mem::eq(declared.name, name) {
631 +
        throw error(&[
632 +
            "manifest", location, "describes package", declared.name, "instead of", name
633 +
        ]);
634 +
    }
635 +
    let mut input = packageInput(declared.name);
636 +
    let rootFile = try artifact::join(arena, &[declared.name, MODULE_EXT]) catch {
637 +
        throw error(&["source arena exhausted"]);
638 +
    };
639 +
    try addModule(&mut input, try locate(location, rootFile, arena));
640 +
    try addModules(&mut input, location, declared.modules, arena);
641 +
    if tests {
642 +
        try addModules(&mut input, location, declared.tests, arena);
643 +
    }
644 +
    if native <> build::NativeInputs::None {
645 +
        for file in declared.assembly {
646 +
            try addAssembly(&mut input, try locate(location, file, arena));
647 +
        }
648 +
        if let file = declared.startup {
649 +
            set input.startupPath = try locate(location, file, arena);
650 +
        }
651 +
    }
652 +
    for file in declared.embed {
653 +
        try addEmbed(&mut input, try locate(location, file, arena));
654 +
    }
655 +
    let mut names: *mut [*[u8]] = &mut [];
656 +
    for dependency in declared.dependencies {
657 +
        try names.append(dependency.name, arena) catch {
658 +
            throw error(&["source arena exhausted"]);
659 +
        };
660 +
    }
661 +
    set input.manifestPath = location;
662 +
    set input.manifest = ManifestInput {
663 +
        text,
664 +
        version: declared.version,
665 +
        requirements: declared.dependencies,
666 +
        dependencies: &names[..],
667 +
    };
668 +
    return input;
669 +
}
670 +
671 +
/// Select a manifest dependency from an override or the library search path.
672 +
export fn discover(
673 +
    name: *[u8],
674 +
    search: ManifestSearch,
675 +
    native: build::NativeInputs,
676 +
    used: &mut [bool; package::MAX_PACKAGES],
677 +
    syntax: &mut parser::Parser,
678 +
    arena: &heap::Heap
679 +
) -> PackageInput throws (Error) {
680 +
    let mut provider: ?Found = nil;
681 +
    for given, i in search.providers {
682 +
        if mem::eq(given.name, name) {
683 +
            set provider = given.found;
684 +
            set used[i] = true;
685 +
        }
686 +
    }
687 +
    let found = provider else try findLibrary(name, search.libraries, arena);
688 +
    match found {
689 +
        case Found::Source(file) => {
690 +
            return try loadManifest(
691 +
                file, name, search.tests, native, syntax, arena
692 +
            );
693 +
        }
694 +
        case Found::Compiled(directory) => {
695 +
            let mut input = packageInput(name);
696 +
            set input.artifactDirectory = directory;
697 +
            return input;
698 +
        }
699 +
    }
700 +
}
701 +
702 +
/// Read the entry package and the library search path for its graph.
703 +
fn manifestEntry(
704 +
    args: &mut ManifestArgs,
705 +
    native: build::NativeInputs,
706 +
    syntax: &mut parser::Parser,
707 +
    arena: &heap::Heap
708 +
) -> PackageInput throws (Error) {
709 +
    if args.search.providers.len > package::MAX_PACKAGES {
710 +
        throw error(&["too many `-dep` arguments"]);
711 +
    }
712 +
    let path = args.path else ".";
713 +
    if mem::endsWith(path, MODULE_EXT) {
714 +
        let directory = try locate(path, ".", arena);
715 +
        set args.search.libraries = try libraryPath(directory, args.search.libraries, arena);
716 +
        return try loadSingle(path, args.name, syntax, arena);
717 +
    }
718 +
    set args.search.libraries = try libraryPath(path, args.search.libraries, arena);
719 +
    let location = try manifest::find(path, arena) catch failure {
720 +
        if failure == manifest::Error::NotFound {
721 +
            throw error(&["expected one package manifest (*.manifest) in", path]);
722 +
        }
723 +
        throw error(&["cannot read directory", path]);
724 +
    };
725 +
    return try loadManifest(
726 +
        location, nil, args.search.tests, native, syntax, arena
727 +
    );
728 +
}
729 +
730 +
/// Add the module files of the module names `names`, listed in the manifest
731 +
/// at `location`. Each is mapped to its logical path, since module files
732 +
/// are in the package directory and not below the root module's stem.
733 +
fn addModules(input: &mut PackageInput, location: *[u8], names: *[*[u8]], arena: &heap::Heap)
734 +
    throws (Error)
735 +
{
736 +
    for name in names {
737 +
        let relative = try manifest::modulePath(name, arena) catch {
738 +
            throw error(&["source arena exhausted"]);
739 +
        };
740 +
        let fileName = try artifact::join(arena, &[relative, ".rad"]) catch {
741 +
            throw error(&["source arena exhausted"]);
742 +
        };
743 +
        let file = try locate(location, fileName, arena);
744 +
        let mapped = try artifact::join(arena, &[relative, "=", file]) catch {
745 +
            throw error(&["source arena exhausted"]);
746 +
        };
747 +
        try addModule(input, mapped);
748 +
    }
391 749
}
392 750
393 751
/// Consume the next argument, or print an error and throw.
394 752
fn nextArg(args: *[*[u8]], idx: &mut u32, msg: &[*[u8]]) -> *[u8] throws (Error) {
395 753
    set *idx += 1;
402 760
/// Parse CLI arguments and return compilation context. The context takes the
403 761
/// node arena and the string pool for its parser. Module sources are read into
404 762
/// `sourceArena`, which must outlive the program.
405 763
fn processCommand(
406 764
    args: *[*[u8]],
407 -
    graph: &mut module::ModuleGraph,
408 765
    nodes: ast::NodeArena,
409 766
    pool: strings::Pool,
410 767
    sourceArena: &heap::Heap
411 768
) -> CompileContext throws (Error) {
412 769
    let mut buildTest = false;
415 772
    let mut outputPath: ?*[u8] = nil;
416 773
    let mut rilDirectory: ?*[u8] = nil;
417 774
    let mut cacheDirectory: ?*[u8] = DEFAULT_CACHE_DIR;
418 775
    let mut dump = Dump::None;
419 776
    let mut entryPkgName: ?*[u8] = nil;
777 +
    let mut manifestArgs = ManifestArgs {
778 +
        path: nil,
779 +
        name: nil,
780 +
        search: ManifestSearch { libraries: &[], providers: &[], tests: false },
781 +
    };
420 782
421 783
    // Per-package source path tracking.
422 784
    let mut inputs: [PackageInput; package::MAX_PACKAGES] =
423 785
        [packageInput(""); package::MAX_PACKAGES];
424 786
    let mut pkgCount: u32 = 0;
441 803
            set currentPkgIdx = pkgCount;
442 804
            set pkgCount += 1;
443 805
        } else if mem::eq(arg, "-artifact") {
444 806
            let root = try nextArg(args, &mut idx, &["`-artifact` requires a directory"]);
445 807
            let selected = currentPkgIdx else throw error(&["`-artifact` must follow `-pkg`"]);
446 -
            set inputs[selected].artifactRoot = root;
808 +
            set inputs[selected].artifactDirectory = try artifact::join(sourceArena, &[
809 +
                root, "/", inputs[selected].name
810 +
            ]) catch {
811 +
                throw error(&["source arena exhausted"]);
812 +
            };
447 813
        } else if mem::eq(arg, "-manifest") {
448 814
            let path = try nextArg(args, &mut idx, &["`-manifest` requires a path"]);
449 815
            let selected = currentPkgIdx else throw error(&["`-manifest` must follow `-pkg`"]);
450 816
            set inputs[selected].manifestPath = path;
451 817
        } else if mem::eq(arg, "-cache") {
500 866
            }
501 867
            if not mem::endsWith(args[idx], ASM_SOURCE_EXT) {
502 868
                throw error(&["`-start` requires a `.ras` assembly file"]);
503 869
            }
504 870
            set input.startupPath = args[idx];
871 +
        } else if mem::eq(arg, "-name") {
872 +
            set manifestArgs.name = try nextArg(args, &mut idx, &[
873 +
                "`-name` requires a package name"
874 +
            ]);
875 +
        } else if mem::eq(arg, "-dep") {
876 +
            let value = try nextArg(args, &mut idx, &["`-dep` requires <name>=<directory>"]);
877 +
            set manifestArgs.search.providers = try withProvider(
878 +
                manifestArgs.search.providers, value, sourceArena
879 +
            );
880 +
        } else if mem::eq(arg, "-lib") {
881 +
            let value = try nextArg(args, &mut idx, &["`-lib` requires a directory"]);
882 +
            set manifestArgs.search.libraries = try appended(
883 +
                manifestArgs.search.libraries, value, sourceArena
884 +
            );
885 +
        } else if arg.len > 0 and arg[0] <> '-' {
886 +
            if manifestArgs.path <> nil {
887 +
                throw error(&["more than one package manifest specified"]);
888 +
            }
889 +
            set manifestArgs.path = arg;
505 890
        } else if mem::eq(arg, "-entry") {
506 891
            try nextArg(args, &mut idx, &["`-entry` requires a package name"]);
507 892
            set entryPkgName = args[idx];
508 893
        } else if mem::eq(arg, "-test") {
509 894
            set buildTest = true;
534 919
        } else {
535 920
            throw error(&["unknown argument", arg]);
536 921
        }
537 922
        set idx += 1;
538 923
    }
539 -
    if pkgCount == 0 {
540 -
        throw error(&["no package specified"]);
924 +
    let mut syntax = parser::newParser(nodes, pool);
925 +
    let manifestMode = pkgCount == 0;
926 +
    let native = outputPath <> nil or dump == Dump::Asm;
927 +
    let mut nativeInputs = build::NativeInputs::None;
928 +
    if dump == Dump::Asm {
929 +
        set nativeInputs = build::NativeInputs::DumpPaths;
930 +
    } else if dump == Dump::None {
931 +
        if rilDirectory <> nil {
932 +
            set nativeInputs = build::NativeInputs::All;
933 +
        } else if outputPath <> nil {
934 +
            set nativeInputs = build::NativeInputs::Assembly;
935 +
        }
936 +
    }
937 +
    if manifestMode {
938 +
        // Without `-pkg`, the package is in the given or current directory.
939 +
        if entryPkgName <> nil {
940 +
            throw error(&["`-entry` requires `-pkg`"]);
941 +
        }
942 +
        set manifestArgs.search.tests = buildTest;
943 +
        set inputs[0] = try manifestEntry(
944 +
            &mut manifestArgs, nativeInputs, &mut syntax, sourceArena
945 +
        );
946 +
        set pkgCount = 1;
947 +
    } else if manifestArgs.path <> nil
948 +
        or manifestArgs.name <> nil
949 +
        or manifestArgs.search.libraries.len > 0
950 +
        or manifestArgs.search.providers.len > 0
951 +
    {
952 +
        throw error(&["`-pkg` cannot be combined with a package, `-name`, `-lib` or `-dep`"]);
541 953
    }
542 954
    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`"]);
955 +
        if not manifestMode
956 +
            and not native
957 +
            and (inputs[i].asmPathCount > 0 or inputs[i].startupPath <> nil)
958 +
        {
959 +
            throw error(&["assembly inputs require native output with `-o` or `-dump asm`"]);
545 960
        }
546 -
        if inputs[i].artifactRoot <> nil and (inputs[i].radPathCount > 0
961 +
        if inputs[i].artifactDirectory <> nil and (inputs[i].radPathCount > 0
547 962
            or inputs[i].embedPathCount > 0)
548 963
        {
549 964
            throw error(&["package", inputs[i].name, "has both source and artifact inputs"]);
550 965
        }
551 -
        if inputs[i].radPathCount == 0 and inputs[i].artifactRoot == nil {
966 +
        if inputs[i].radPathCount == 0 and inputs[i].artifactDirectory == nil {
552 967
            throw error(&["package", inputs[i].name, "has no Radiance modules specified"]);
553 968
        }
554 969
    }
555 970
    // Determine entry package index.
556 971
    let mut entryPkgIdx: ?u32 = nil;
557 972
    if pkgCount == 1 {
558 -
        // Single package: it is the entry.
973 +
        // A single package, or the package of the manifest, is the entry.
559 974
        set entryPkgIdx = 0;
560 975
    } else {
561 976
        // Multiple packages: need -entry.
562 977
        let entryName = entryPkgName else {
563 978
            throw error(&["`-entry` required when multiple packages specified"]);
581 996
        }
582 997
    }
583 998
    if rilDirectory <> nil and (outputPath <> nil or dump <> Dump::None) {
584 999
        throw error(&["`-ril` requires a separate invocation from `-o` or `-dump`"]);
585 1000
    }
586 -
    let mut ctx = CompileContext {
1001 +
    return CompileContext {
587 1002
        packages: [
588 1003
            package::Package { id: 0, name: "", rootModuleId: nil }; package::MAX_PACKAGES
589 1004
        ],
590 1005
        inputs,
591 1006
        packageCount: pkgCount,
592 1007
        entryPkgIdx,
593 -
        parser: parser::newParser(nodes, pool),
1008 +
        manifestSearch: manifestArgs.search if manifestMode else nil,
1009 +
        parser: syntax,
594 1010
        config: resolver::Config { buildTest },
595 1011
        dump,
596 1012
        outputPath,
1013 +
        nativeInputs,
597 1014
        rilDirectory,
598 1015
        cacheDirectory,
599 1016
        debug: debugEnabled,
600 1017
        stackCheck: stackChecked,
601 1018
    };
602 -
    // Initialize and parse all packages.
603 -
    for i in 0 .. pkgCount {
604 -
        let name = ctx.inputs[i].name;
605 -
        package::init(&mut ctx.packages[i], i as u16, name, &mut ctx.parser.pool);
606 -
607 -
        if dump == Dump::None {
608 -
            continue;
609 -
        }
610 -
        if ctx.inputs[i].artifactRoot <> nil {
611 -
            throw error(&["source inspection requires implementation source"]);
612 -
        }
613 -
        for j in 0 .. ctx.inputs[i].radPathCount {
614 -
            let path = ctx.inputs[i].radPaths[j];
615 -
            try processModule(&mut ctx.packages[i], graph, path, &mut ctx.parser, sourceArena);
616 -
        }
617 -
        let files = try build::embeds(ctx.inputs[i], sourceArena) catch {
618 -
            throw error(&["cannot read embedded files of package", name]);
619 -
        };
620 -
        let root = ctx.packages[i].rootModuleId else panic "processCommand: package has no root";
621 -
        set graph.entries[root as u32].embeds = try build::embedded(files, sourceArena);
622 -
    }
623 -
    return ctx;
624 1019
}
625 1020
626 1021
/// Get the entry package from the context.
627 1022
fn getEntryPackage(ctx: &CompileContext) -> package::Package throws (Error) {
628 1023
    let entryIdx = ctx.entryPkgIdx else {
1406 1801
    let sourceArena = heap::over(&mut storage.moduleSources[..]);
1407 1802
    let mut graph = module::moduleGraph(&mut storage.moduleEntries[..]);
1408 1803
    let frontendArena = heap::over(&mut storage.frontend[..]);
1409 1804
    let nodes = ast::NodeArena { heap: frontendArena, nextId: 0 };
1410 1805
    let pool = strings::freshPool(&mut storage.poolTable[..]);
1411 -
    let mut ctx = try processCommand(env.args, &mut graph, nodes, pool, sourceArena) catch {
1806 +
    let mut ctx = try processCommand(env.args, nodes, pool, sourceArena) catch {
1412 1807
        return 1;
1413 1808
    };
1414 1809
    let native = codegen::NativeStorage {
1415 1810
        dataSyms: &mut storage.dataSyms[..],
1416 1811
        dataSymTable: &mut storage.dataSymTable[..],
1434 1829
            return 1;
1435 1830
        };
1436 1831
        return 0;
1437 1832
    }
1438 1833
    let mainArena = frontendArena;
1834 +
    let artifactArena = heap::over(&mut storage.artifacts[..]);
1835 +
    try build::inspect(
1836 +
        &mut ctx, &mut graph, mainArena, sourceArena, artifactArena, driverArena
1837 +
    ) catch {
1838 +
        return 1;
1839 +
    };
1439 1840
    match ctx.dump {
1440 1841
        case Dump::Ast => {
1441 1842
            try dumpAst(&ctx, module::freeze(graph), mainArena) catch {
1442 1843
                return 1;
1443 1844
            };
compiler/radiance/testgen.manifest deleted +0 -1
1 -
std
kernel/Makefile +19 -22
1 1
# Kernel artifacts. Run from the repository root.
2 2
3 -
# Kernel modules and tests use a separate package and test entry point.
4 -
KERNEL_MODULES  := $(filter-out kernel/kernel/tests.rad, \
3 +
# The kernel manifest lists the kernel modules, test modules and assembly.
4 +
# These variables name the same files for Make dependencies.
5 +
KERNEL_MANIFEST := kernel/kernel/kernel.manifest
6 +
KERNEL_MODULES  := $(filter-out kernel/kernel/tests.rad kernel/kernel/kernel.rad, \
5 7
    $(wildcard kernel/kernel/*.rad))
6 -
KERNEL_MANIFEST := kernel/kernel.manifest
7 -
KERNEL_SRC      := kernel/kernel.rad $(KERNEL_MODULES)
8 -
KERNEL_ASM      := kernel/kernel/boot.ras kernel/kernel/physical.ras \
9 -
    kernel/kernel/sync.ras kernel/kernel/trap.ras kernel/kernel/loader.ras \
10 -
    kernel/kernel/domains.ras kernel/kernel/dispatch.ras kernel/kernel/registers.ras
8 +
KERNEL_SRC      := kernel/kernel/kernel.rad $(KERNEL_MODULES)
9 +
KERNEL_ASM      := $(wildcard kernel/kernel/*.ras)
11 10
KERNEL_TEST_SRC := kernel/kernel/tests.rad $(wildcard kernel/kernel/tests/*.rad)
12 -
KERNEL          := -pkg kernel $(patsubst %,-mod %,$(sort $(KERNEL_SRC)))
13 11
KERNEL_TEST     := $(BIN_DIR)/kernel.test.rv64
14 12
15 13
$(KERNEL_TEST): $(KERNEL_SRC) $(KERNEL_MANIFEST) $(STD_MANIFEST) $(KERNEL_TEST_SRC) $(KERNEL_ASM) \
16 -
    $(STD_TEST_LIB) std.lib.test $(RAD_BIN) kernel/Makefile
14 +
    $(STD_TEST_LIB) $(RAD_BIN) kernel/Makefile
17 15
	@echo "radiance kernel tests => $@"
18 -
	@$(RADIANCE) -test $(STD_TEST) $(KERNEL) $(patsubst %,-mod %,$(KERNEL_TEST_SRC) \
19 -
	    $(KERNEL_ASM)) -entry kernel -o $@
20 -
21 -
# Combined assembly for the standard library native package.
22 -
$(BIN_DIR)/std.ras: $(filter %.ras,$(STD_LIB)) std.lib kernel/Makefile | $(BIN_DIR)
23 -
	@cat $(filter %.ras,$(STD_LIB)) > $@
16 +
	@$(RADIANCE) -test kernel/kernel -o $@
24 17
25 18
# Native kernel image.
26 19
$(BIN_DIR)/kernel/kernel.ril.bin $(BIN_DIR)/std/std.ril.bin &: $(KERNEL_SRC) $(KERNEL_MANIFEST) \
27 20
    $(STD_LIB) $(STD_MANIFEST) $(RAD_BIN) kernel/Makefile
28 -
	@$(RADIANCE) -pkg std $(patsubst %,-mod %,$(filter %.rad,$(STD_LIB))) \
29 -
	    $(KERNEL) -entry kernel -ril $(BIN_DIR)
21 +
	@$(RADIANCE) kernel/kernel -ril $(BIN_DIR)
22 +
23 +
# Combined standard library assembly, for test images that the integration
24 +
# driver links with `-std-asm`.
25 +
$(BIN_DIR)/std.ras: $(filter %.ras,$(STD_LIB)) std.lib kernel/Makefile | $(BIN_DIR)
26 +
	@cat $(filter %.ras,$(STD_LIB)) > $@
30 27
31 28
$(BIN_DIR)/kernel.build.rv64: kernel/tools/build.rad kernel/tools/build.manifest $(STD_LIB) $(STD_MANIFEST) $(RAD_BIN) \
32 29
    $(BIN_DIR)/std.ras kernel/Makefile
33 -
	@$(RADIANCE) $(STD) -pkg build -mod $< -entry build -o $@
30 +
	@$(RADIANCE) kernel/tools -o $@
34 31
35 32
$(BIN_DIR)/kernel.rv64: $(BIN_DIR)/std/std.ril.bin $(BIN_DIR)/kernel/kernel.ril.bin \
36 -
    $(BIN_DIR)/kernel.build.rv64 $(KERNEL_ASM) kernel/Makefile
37 -
	@cat $(KERNEL_ASM) > $(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 $@
33 +
    $(BIN_DIR)/kernel.build.rv64 $(KERNEL_MANIFEST) $(STD_MANIFEST) $(KERNEL_ASM) \
34 +
    $(filter %.ras,$(STD_LIB)) kernel/Makefile
35 +
	@$(HOSTED) $(BIN_DIR)/kernel.build.rv64 -package kernel/kernel $(BIN_DIR)/std/std.ril.bin \
36 +
	    $(BIN_DIR)/kernel/kernel.ril.bin $@
kernel/kernel.manifest deleted +0 -1
1 -
std
kernel/kernel/kernel.manifest added +86 -0
1 +
// The RadiantOS kernel.
2 +
Package {
3 +
    name: "kernel",
4 +
    version: "0.1.0",
5 +
    dependencies: [
6 +
        Dependency { name: "std", version: "0.1.0" },
7 +
    ],
8 +
    modules: [
9 +
        "abi",
10 +
        "access",
11 +
        "backing",
12 +
        "boot",
13 +
        "budgets",
14 +
        "calls",
15 +
        "capability",
16 +
        "devices",
17 +
        "dispatch",
18 +
        "domains",
19 +
        "events",
20 +
        "fdt",
21 +
        "frames",
22 +
        "instances",
23 +
        "interrupts",
24 +
        "lifecycle",
25 +
        "limits",
26 +
        "loader",
27 +
        "locked",
28 +
        "pages",
29 +
        "physical",
30 +
        "platform",
31 +
        "plic",
32 +
        "range",
33 +
        "registers",
34 +
        "registry",
35 +
        "remote",
36 +
        "slots",
37 +
        "startup",
38 +
        "state",
39 +
        "sync",
40 +
        "sys",
41 +
        "timers",
42 +
        "transactions",
43 +
        "trap",
44 +
    ],
45 +
    tests: [
46 +
        "tests",
47 +
        "tests::abi",
48 +
        "tests::backing",
49 +
        "tests::boot",
50 +
        "tests::budgets",
51 +
        "tests::calls",
52 +
        "tests::capability",
53 +
        "tests::devices",
54 +
        "tests::dispatch",
55 +
        "tests::domains",
56 +
        "tests::events",
57 +
        "tests::fdt",
58 +
        "tests::frames",
59 +
        "tests::instances",
60 +
        "tests::interrupts",
61 +
        "tests::lifecycle",
62 +
        "tests::loader",
63 +
        "tests::pages",
64 +
        "tests::physical",
65 +
        "tests::platform",
66 +
        "tests::range",
67 +
        "tests::registers",
68 +
        "tests::registry",
69 +
        "tests::remote",
70 +
        "tests::slots",
71 +
        "tests::support",
72 +
        "tests::timers",
73 +
        "tests::transactions",
74 +
        "tests::trap",
75 +
    ],
76 +
    assembly: [
77 +
        "boot.ras",
78 +
        "physical.ras",
79 +
        "sync.ras",
80 +
        "trap.ras",
81 +
        "loader.ras",
82 +
        "domains.ras",
83 +
        "dispatch.ras",
84 +
        "registers.ras",
85 +
    ],
86 +
}
kernel/kernel.rad → kernel/kernel/kernel.rad renamed +0 -0
kernel/tools/build.manifest +8 -1
1 -
std
1 +
// Kernel image linker.
2 +
Package {
3 +
    name: "build",
4 +
    version: "0.1.0",
5 +
    dependencies: [
6 +
        Dependency { name: "std", version: "0.1.0" },
7 +
    ],
8 +
}
kernel/tools/build.rad +151 -19
15 15
use std::lang::gen::regalloc::liveness;
16 16
use std::lang::il::binary;
17 17
use std::lang::il::binary::program;
18 18
use std::lang::il::verify;
19 19
use std::lang::il::verify::linking;
20 +
use std::lang::ast;
21 +
use std::lang::manifest;
22 +
use std::lang::parser;
20 23
use std::lang::strings;
21 24
use std::mem;
22 25
use std::mem::heap;
23 26
use std::sys;
24 27
37 40
constant DECODE_CAPACITY: u32 = 83886080;
38 41
/// Number of elements reserved for input storage.
39 42
constant INPUT_CAPACITY: u32 = 8388608;
40 43
/// Number of elements reserved for source storage.
41 44
constant SOURCE_CAPACITY: u32 = 65536;
45 +
/// Number of elements reserved for manifest syntax and value storage.
46 +
constant MANIFEST_CAPACITY: u32 = 1048576;
42 47
/// Number of elements reserved for assembly storage.
43 48
constant ASSEMBLY_CAPACITY: u32 = 4194304;
44 49
/// Number of elements reserved for text storage.
45 50
constant TEXT_CAPACITY: u32 = 16384;
46 51
/// Number of elements reserved for data storage.
78 83
unsafe static INPUT: [[u8; INPUT_CAPACITY]; PACKAGES] = undefined;
79 84
/// Combined startup and boundary assembly source.
80 85
static SOURCE: [u8; SOURCE_CAPACITY] = [0; SOURCE_CAPACITY];
81 86
/// Standard library assembly source.
82 87
static LIBRARY_SOURCE: [u8; SOURCE_CAPACITY] = [0; SOURCE_CAPACITY];
88 +
/// Manifest syntax trees, reused for each manifest.
89 +
static MANIFEST_SYNTAX: [u8; MANIFEST_CAPACITY] = [0; MANIFEST_CAPACITY];
90 +
/// Manifest text and the values read from it.
91 +
static MANIFESTS: [u8; MANIFEST_CAPACITY] = [0; MANIFEST_CAPACITY];
92 +
/// String pool table of the manifest parser.
93 +
unsafe static MANIFEST_NAMES: [*[u8]; strings::TABLE_SIZE] = undefined;
83 94
/// Standard library assembly words.
84 95
static LIBRARY_TEXT: [u32; TEXT_CAPACITY] = [0; TEXT_CAPACITY];
85 96
/// Assembler workspace.
86 97
static ASSEMBLY: [u8; ASSEMBLY_CAPACITY] = [0; ASSEMBLY_CAPACITY];
87 98
/// Assembled startup words.
245 256
        set output[i] = shared::Symbol { name: imported.exported, target, startable: false };
246 257
    }
247 258
    return &providers[..];
248 259
}
249 260
261 +
/// Library directory that holds the standard library package.
262 +
constant LIBRARY: *[u8] = "lib/std";
263 +
264 +
/// Read the manifest at `path`, from which its relative paths are resolved.
265 +
fn readManifest(path: *[u8], arena: &heap::Heap) -> ManifestFile {
266 +
    let text = try fs::readFileAlloc(path, arena) catch {
267 +
        panic "readManifest: cannot read manifest";
268 +
    };
269 +
    let mut syntax: parser::Parser = undefined;
270 +
    // Each call starts the syntax storage and string pool over. `manifest::read`
271 +
    // copies everything it returns into `arena`, so no result of an earlier call
272 +
    // refers to the reused storage.
273 +
    unsafe {
274 +
        set syntax = parser::newParser(ast::nodeArena(&mut MANIFEST_SYNTAX[..]), strings::pool(
275 +
            &mut MANIFEST_NAMES[..]
276 +
        ));
277 +
    }
278 +
    let package = try manifest::read(&mut syntax, path, text, arena) catch {
279 +
        panic "readManifest: invalid manifest";
280 +
    };
281 +
    return ManifestFile { path, package };
282 +
}
283 +
284 +
/// A package manifest and its location.
285 +
record ManifestFile: Copy {
286 +
    /// Manifest path.
287 +
    path: *[u8],
288 +
    /// Package that the manifest describes.
289 +
    package: manifest::Package,
290 +
}
291 +
292 +
/// Concatenate the assembly sources that `file` lists into `buffer`, and
293 +
/// return the text.
294 +
fn assemblySources(file: &ManifestFile, buffer: *mut [u8], arena: &heap::Heap) -> *[u8] {
295 +
    let mut length: u32 = 0;
296 +
    for assembly in file.package.assembly {
297 +
        let location = try manifest::resolve(file.path, assembly, arena) catch {
298 +
            panic "assemblySources: path too long";
299 +
        };
300 +
        let size = try fs::readFile(location, &mut buffer[length ..]) catch {
301 +
            panic "assemblySources: cannot read assembly";
302 +
        };
303 +
        set length += size;
304 +
    }
305 +
    return &buffer[.. length];
306 +
}
307 +
308 +
/// Assembly text and the name used in its diagnostics.
309 +
record AssemblySource: Copy {
310 +
    /// Source name for diagnostics.
311 +
    name: *[u8],
312 +
    /// Assembly text.
313 +
    text: *[u8],
314 +
}
315 +
316 +
/// Inputs and output named on the command line.
317 +
record Arguments: Copy {
318 +
    /// Binary IL of the standard library, the kernel, and the boot packages.
319 +
    packages: *[*[u8]],
320 +
    /// Output image path.
321 +
    output: *[u8],
322 +
    /// Kernel assembly.
323 +
    kernel: AssemblySource,
324 +
    /// Standard library assembly, if any.
325 +
    library: ?AssemblySource,
326 +
}
327 +
328 +
/// Read the command line `args`:
329 +
///
330 +
/// `[-std-asm <std.ras>] <std.ril.bin> <kernel.ril.bin> <kernel.ras> <output> [<boot.ril.bin>..]`
331 +
/// `-package <kernel directory> <std.ril.bin> <kernel.ril.bin> <output> [<boot.ril.bin>..]`
332 +
///
333 +
/// With `-package`, the assembly is what the manifests of the kernel package
334 +
/// and of the standard library package in [`LIBRARY`] list.
335 +
unsafe fn arguments(args: *[*[u8]]) -> Arguments {
336 +
    if args.len >= 2 and mem::eq(args[0], "-package") {
337 +
        let rest = &args[2 ..];
338 +
        assert rest.len >= 3 and rest.len <= PACKAGES + 1;
339 +
        let manifests = heap::over(&mut MANIFESTS[..]);
340 +
        let kernelPath = try manifest::find(args[1], manifests) catch {
341 +
            panic "arguments: no kernel package manifest";
342 +
        };
343 +
        let libraryPath = try manifest::file(LIBRARY, "std", manifests) catch {
344 +
            panic "arguments: path too long";
345 +
        };
346 +
        let kernelFile = readManifest(kernelPath, manifests);
347 +
        let libraryFile = readManifest(libraryPath, manifests);
348 +
        let mut packages: *mut [*[u8]] = &mut [];
349 +
        try! packages.extend(&rest[.. 2], manifests);
350 +
        try! packages.extend(&rest[3 ..], manifests);
351 +
        return Arguments {
352 +
            packages: &packages[..],
353 +
            output: rest[2],
354 +
            kernel: AssemblySource {
355 +
                name: kernelFile.path,
356 +
                text: assemblySources(&kernelFile, &mut SOURCE[..], manifests),
357 +
            },
358 +
            library: AssemblySource {
359 +
                name: libraryFile.path,
360 +
                text: assemblySources(&libraryFile, &mut LIBRARY_SOURCE[..], manifests),
361 +
            },
362 +
        };
363 +
    }
364 +
    let mut rest = &args[..];
365 +
    let mut library: ?AssemblySource = nil;
366 +
    if args.len >= 2 and mem::eq(args[0], "-std-asm") {
367 +
        let size = try fs::readFile(args[1], &mut LIBRARY_SOURCE[..]) catch {
368 +
            panic "arguments: standard library assembly";
369 +
        };
370 +
        set library = AssemblySource { name: args[1], text: &LIBRARY_SOURCE[.. size] };
371 +
        set rest = &args[2 ..];
372 +
    }
373 +
    assert rest.len >= 4 and rest.len <= PACKAGES + 2;
374 +
    let size = try fs::readFile(rest[2], &mut SOURCE[..]) catch {
375 +
        panic "arguments: kernel assembly";
376 +
    };
377 +
    let manifests = heap::over(&mut MANIFESTS[..]);
378 +
    let mut packages: *mut [*[u8]] = &mut [];
379 +
    try! packages.extend(&rest[.. 2], manifests);
380 +
    try! packages.extend(&rest[4 ..], manifests);
381 +
    return Arguments {
382 +
        packages: &packages[..],
383 +
        output: rest[3],
384 +
        kernel: AssemblySource { name: rest[2], text: &SOURCE[.. size] },
385 +
        library,
386 +
    };
387 +
}
388 +
250 389
/// Link shared boot packages, retain their catalog, and instantiate the kernel graph.
390 +
/// [`arguments`] describes the command line.
251 391
@default unsafe fn main(env: *sys::Env) -> i32 {
252 -
    let withLibraryAssembly = env.args.len >= 2 and mem::eq(env.args[0], "-std-asm");
253 -
    let args = &env.args[2 ..] if withLibraryAssembly else &env.args[..];
254 -
    assert args.len >= 4 and args.len <= PACKAGES + 2;
255 -
    let count = args.len - 2;
392 +
    let args = arguments(env.args);
393 +
    let count = args.packages.len;
256 394
    let decoder = heap::over(&mut DECODE[..]);
257 -
    let libraryBytesLength = try fs::readFile(args[0], &mut INPUT[0][..]) catch {
395 +
    let libraryBytesLength = try fs::readFile(args.packages[0], &mut INPUT[0][..]) catch {
258 396
        panic "main: std RIL";
259 397
    };
260 398
    let libraryBytes = &INPUT[0][.. libraryBytesLength];
261 399
    let libraryInput = try! program::decode(libraryBytes, decoder, binary::Limits {
262 400
        registers: liveness::MAX_SSA_REGS, blocks: labels::MAX_BLOCKS_PER_FN
263 401
    });
264 -
    let kernelBytesLength = try fs::readFile(args[1], &mut INPUT[1][..]) catch {
402 +
    let kernelBytesLength = try fs::readFile(args.packages[1], &mut INPUT[1][..]) catch {
265 403
        panic "main: kernel RIL";
266 404
    };
267 405
    let kernelBytes = &INPUT[1][.. kernelBytesLength];
268 406
    let kernelInput = try! program::decode(kernelBytes, decoder, binary::Limits {
269 407
        registers: liveness::MAX_SSA_REGS, blocks: labels::MAX_BLOCKS_PER_FN
271 409
    assert mem::eq(libraryInput.name, "std") and mem::eq(kernelInput.name, "kernel");
272 410
    assert libraryInput.dependencies.len == 0;
273 411
    for dependency in kernelInput.dependencies {
274 412
        assert mem::eq(dependency, "std");
275 413
    }
276 -
    let sourceLength = try fs::readFile(args[2], &mut SOURCE[..]) catch {
277 -
        panic "main: kernel assembly";
278 -
    };
279 -
    let source = &SOURCE[.. sourceLength];
414 +
    let source = args.kernel.text;
280 415
    let assemblyArena = heap::over(&mut ASSEMBLY[..]);
281 416
    let empty: *mut [u8] = &mut [];
282 417
    let mut names = strings::pool(&mut NAMES[..]);
283 418
    let assembly = try asm::assemble(
284 419
        asm::scanner::SourceKind::String,
287 422
        empty,
288 423
        assemblyArena,
289 424
        &mut names,
290 425
        0
291 426
    ) catch error {
292 -
        asm::printError(error, &args[2][..], source);
427 +
        asm::printError(error, args.kernel.name, source);
293 428
        return 1;
294 429
    };
295 430
    let mut libraryAssembly = asm::Program {
296 431
        text: &[], data: &[], symbols: &[], externalFixups: &[]
297 432
    };
298 -
    if withLibraryAssembly {
299 -
        let size = try fs::readFile(env.args[1], &mut LIBRARY_SOURCE[..]) catch {
300 -
            panic "main: standard library assembly";
301 -
        };
302 -
        let source = &LIBRARY_SOURCE[.. size];
433 +
    if let library = args.library {
434 +
        let source = library.text;
303 435
        let empty: *mut [u8] = &mut [];
304 436
        set libraryAssembly = try asm::assemble(
305 437
            asm::scanner::SourceKind::String,
306 438
            source,
307 439
            &mut LIBRARY_TEXT[..],
308 440
            empty,
309 441
            assemblyArena,
310 442
            &mut names,
311 443
            0
312 444
        ) catch error {
313 -
            asm::printError(error, &env.args[1][..], source);
445 +
            asm::printError(error, library.name, source);
314 446
            return 1;
315 447
        };
316 448
    }
317 449
    let library = try compile(
318 450
        &libraryInput,
342 474
    set catalogEntries[1] = catalog::Entry { source: kernelBytes, package: kernel };
343 475
    let mut codeEnd = kernel.codeAddress
344 476
        + kernel.code.len as u64 * rv64::INSTR_SIZE as u64;
345 477
    for slot in 2 .. count {
346 478
        let bytesLength = try fs::readFile(
347 -
            args[slot + 2], &mut INPUT[slot][..]
479 +
            args.packages[slot], &mut INPUT[slot][..]
348 480
        ) catch {
349 481
            panic "main: boot package RIL";
350 482
        };
351 483
        let bytes = &INPUT[slot][.. bytesLength];
352 484
        let mut input = try! program::decode(bytes, decoder, binary::Limits {
438 570
        code: image::Segment { address: CODE_ADDRESS, size: codeSize },
439 571
        roData: image::Segment { address: roAddress, size: roSize },
440 572
        rwData: image::Segment { address: rwAddress, size: rwSize },
441 573
        rwTail: 0,
442 574
    });
443 -
    let mut out = try! fs::create(args[3]);
575 +
    let mut out = try! fs::create(args.output);
444 576
    out.write(&header[..]);
445 577
    out.write(@sliceOf(&NATIVE[0] as *u8, codeSize));
446 578
    out.write(&RO[.. roSize]);
447 579
    out.write(&RW[.. rwSize]);
448 580
    try! out.close();
lib/std/lang.rad +1 -0
5 5
export mod strings;
6 6
export mod scanner;
7 7
export mod ast;
8 8
export mod layout;
9 9
export mod parser;
10 +
export mod manifest;
10 11
export mod pretty;
11 12
export mod module;
12 13
export mod resolver;
13 14
export mod package;
14 15
export mod il;
lib/std/lang/manifest.rad added +577 -0
1 +
//! Package manifests.
2 +
//!
3 +
//! A package is a directory that holds the manifest `<name>.manifest`, the
4 +
//! root module `<name>.rad`, and the package's other files. The manifest
5 +
//! describes the package as a single Radiance expression, a `Package` record
6 +
//! literal:
7 +
//!
8 +
//!     Package {
9 +
//!         name: "app",
10 +
//!         version: "1.0.0",
11 +
//!         dependencies: [
12 +
//!             Dependency { name: "std", version: "0.1.0" },
13 +
//!         ],
14 +
//!         modules: ["util", "util::text"],
15 +
//!     }
16 +
//!
17 +
//! The reader walks the syntax tree without resolving names. Values are
18 +
//! string literals, `nil`, array literals, and record literals with or
19 +
//! without their type name. `name` and `version` are required; omitted lists
20 +
//! are empty and an omitted `startup` is `nil`.
21 +
//!
22 +
//! Modules are named by their path below the root module, and their files
23 +
//! are in the package directory: module `mem::heap` of the package in
24 +
//! `lib/std` is the file `lib/std/mem/heap.rad`.
25 +
//!
26 +
//! A dependency names a package and the oldest compatible version. A
27 +
//! version is compatible with the requested one when it is not older, and
28 +
//! has the same major version, or for major version zero, the same minor
29 +
//! version.
30 +
31 +
@test mod tests;
32 +
33 +
use std::char;
34 +
use std::fmt;
35 +
use std::fs;
36 +
use std::io;
37 +
use std::mem;
38 +
use std::mem::heap;
39 +
use std::sys;
40 +
use std::lang::alloc;
41 +
use std::lang::ast;
42 +
use std::lang::il::binary;
43 +
use std::lang::parser;
44 +
use std::lang::scanner;
45 +
46 +
/// File name extension of a manifest.
47 +
export constant EXTENSION: *[u8] = ".manifest";
48 +
/// Bytes of directory listing storage that [`find`] uses.
49 +
constant LIST_BYTES: u32 = 65536;
50 +
51 +
/// Largest number of path components that [`resolve`] keeps.
52 +
constant MAX_COMPONENTS: u32 = 64;
53 +
54 +
/// A package that another package imports.
55 +
export record Dependency: Copy {
56 +
    /// Package name.
57 +
    name: *[u8],
58 +
    /// Oldest compatible version, `MAJOR.MINOR.PATCH`.
59 +
    version: *[u8],
60 +
}
61 +
62 +
/// One package.
63 +
export record Package: Copy {
64 +
    /// Package name, used by `use` in clients.
65 +
    name: *[u8],
66 +
    /// Release version, `MAJOR.MINOR.PATCH`.
67 +
    version: *[u8],
68 +
    /// Packages that this package can import.
69 +
    dependencies: *[Dependency],
70 +
    /// Modules below the root module, by name relative to the package.
71 +
    modules: *[*[u8]],
72 +
    /// Modules that are compiled only for tests, named as in `modules`.
73 +
    tests: *[*[u8]],
74 +
    /// Assembly sources linked after generated code.
75 +
    assembly: *[*[u8]],
76 +
    /// Assembly source emitted before generated code.
77 +
    startup: ?*[u8],
78 +
    /// Files under the package root that `@embed` can read.
79 +
    embed: *[*[u8]],
80 +
}
81 +
82 +
/// Manifest reading failure. The reader prints a diagnostic before it throws,
83 +
/// except for failures to find or read a file.
84 +
export union Error: Copy {
85 +
    /// The text is not one Radiance expression.
86 +
    Syntax,
87 +
    /// The value does not describe a package.
88 +
    Invalid,
89 +
    /// Storage ran out.
90 +
    TooLarge,
91 +
    /// A directory holds no manifest, or several.
92 +
    NotFound,
93 +
    /// A file or directory cannot be read.
94 +
    Unreadable,
95 +
}
96 +
97 +
/// Manifest text, for diagnostics.
98 +
record Reader: Copy {
99 +
    /// Manifest path.
100 +
    path: *[u8],
101 +
    /// Manifest text.
102 +
    text: *[u8],
103 +
}
104 +
105 +
/// Read the manifest `text` from `path`. Syntax nodes go to the arena of
106 +
/// `syntax`; the returned strings are copied to `arena`.
107 +
export fn read(syntax: &mut parser::Parser, path: *[u8], text: *[u8], arena: &heap::Heap) -> Package
108 +
    throws (Error)
109 +
{
110 +
    let root = try parser::parseValue(syntax, scanner::SourceLoc::File(path), text) catch failure {
111 +
        if failure == parser::ParseError::AllocationFailed {
112 +
            throw Error::TooLarge;
113 +
        }
114 +
        throw Error::Syntax;
115 +
    };
116 +
    let r = Reader { path, text };
117 +
    let mut package = Package {
118 +
        name: "",
119 +
        version: "",
120 +
        dependencies: &[],
121 +
        modules: &[],
122 +
        tests: &[],
123 +
        assembly: &[],
124 +
        startup: nil,
125 +
        embed: &[],
126 +
    };
127 +
    let mut named = false;
128 +
    let mut versioned = false;
129 +
    let fields = try recordFields(r, root, "Package");
130 +
    for field in fields {
131 +
        let label = try fieldName(r, field);
132 +
        let item = fieldValue(field);
133 +
        if mem::eq(label, "name") {
134 +
            set package.name = try identifier(r, item, arena);
135 +
            set named = true;
136 +
        } else if mem::eq(label, "version") {
137 +
            set package.version = try version(r, item, arena);
138 +
            set versioned = true;
139 +
        } else if mem::eq(label, "dependencies") {
140 +
            set package.dependencies = try dependencies(r, item, arena);
141 +
        } else if mem::eq(label, "modules") {
142 +
            set package.modules = try moduleNames(r, item, arena);
143 +
        } else if mem::eq(label, "tests") {
144 +
            set package.tests = try moduleNames(r, item, arena);
145 +
        } else if mem::eq(label, "assembly") {
146 +
            set package.assembly = try paths(r, item, arena);
147 +
        } else if mem::eq(label, "startup") {
148 +
            if let case ast::NodeValue::Nil = item.value {
149 +
                set package.startup = nil;
150 +
            } else {
151 +
                set package.startup = try relativePath(r, item, arena);
152 +
            }
153 +
        } else if mem::eq(label, "embed") {
154 +
            set package.embed = try paths(r, item, arena);
155 +
        } else {
156 +
            throw invalid(r, field, &["unknown field `", label, "`"]);
157 +
        }
158 +
    }
159 +
    if not named {
160 +
        throw invalid(r, root, &["missing field `name`"]);
161 +
    }
162 +
    if not versioned {
163 +
        throw invalid(r, root, &["missing field `version`"]);
164 +
    }
165 +
    try checkModules(r, root, package.modules, package.tests);
166 +
    set package.modules = try orderModules(package.modules, &[], arena);
167 +
    set package.tests = try orderModules(package.tests, package.modules, arena);
168 +
    return package;
169 +
}
170 +
171 +
/// Return the path of module `name` from the package directory, without
172 +
/// the `.rad` extension: `mem::heap` gives `mem/heap`.
173 +
export fn modulePath(name: *[u8], arena: &heap::Heap) -> *[u8] throws (Error) {
174 +
    let mut result: *mut [u8] = &mut [];
175 +
    let mut i: u32 = 0;
176 +
    while i < name.len {
177 +
        let mut byte = name[i];
178 +
        set i += 1;
179 +
        if byte == ':' {
180 +
            set byte = '/';
181 +
            set i += 1;
182 +
        }
183 +
        try result.append(byte, arena) catch {
184 +
            throw Error::TooLarge;
185 +
        };
186 +
    }
187 +
    return &result[..];
188 +
}
189 +
190 +
/// Return the location of the manifest of package `name` in `directory`.
191 +
export fn file(directory: *[u8], name: *[u8], arena: &heap::Heap) -> *[u8] throws (Error) {
192 +
    let parts: [*[u8]; 4] = [directory, "/", name, EXTENSION];
193 +
    let joined = try alloc::concatBytes(arena, &parts[..]) catch {
194 +
        throw Error::TooLarge;
195 +
    };
196 +
    let text: *[u8] = &joined[..];
197 +
    return try resolve(&text[.. directory.len + 1], &text[directory.len + 1 ..], arena);
198 +
}
199 +
200 +
/// Return the location of the one manifest in `directory`.
201 +
export fn find(directory: *[u8], arena: &heap::Heap) -> *[u8] throws (Error) {
202 +
    let listing = try fs::listDirAlloc(directory, LIST_BYTES, arena) catch failure as sys::Error {
203 +
        throw Error::Unreadable;
204 +
    } catch failure as alloc::AllocError {
205 +
        throw Error::TooLarge;
206 +
    };
207 +
    let mut found: ?*[u8] = nil;
208 +
    let mut names = mem::split(listing, 0);
209 +
    while let name = names.next() {
210 +
        if name.len > EXTENSION.len and mem::endsWith(name, EXTENSION) {
211 +
            if found <> nil {
212 +
                throw Error::NotFound;
213 +
            }
214 +
            set found = &name[.. name.len - EXTENSION.len];
215 +
        }
216 +
    }
217 +
    let name = found else throw Error::NotFound;
218 +
    return try file(directory, name, arena);
219 +
}
220 +
221 +
/// Check whether the package version `found` satisfies the dependency
222 +
/// version `required`. Both are valid `MAJOR.MINOR.PATCH` versions.
223 +
export fn compatible(required: *[u8], found: *[u8]) -> bool {
224 +
    let want = binary::versionParts(required) else return false;
225 +
    let have = binary::versionParts(found) else return false;
226 +
    if not mem::eq(want[0], have[0])
227 +
        or (mem::eq(want[0], "0") and not mem::eq(want[1], have[1]))
228 +
    {
229 +
        return false;
230 +
    }
231 +
    for i in 1 .. 3 {
232 +
        if have[i].len <> want[i].len {
233 +
            return have[i].len > want[i].len;
234 +
        }
235 +
        let order = mem::cmp(have[i], want[i]);
236 +
        if order <> 0 {
237 +
            return order > 0;
238 +
        }
239 +
    }
240 +
    return true;
241 +
}
242 +
243 +
/// Return the location of `path`, written in the manifest at `manifest`, as
244 +
/// a path from the current directory. `.` components are removed, and `..`
245 +
/// components cancel earlier ones, so that equal locations compare equal.
246 +
export fn resolve(manifest: *[u8], path: *[u8], arena: &heap::Heap) -> *[u8] throws (Error) {
247 +
    let mut parts: [*[u8]; MAX_COMPONENTS] = [""; MAX_COMPONENTS];
248 +
    let mut count: u32 = 0;
249 +
    let mut directory: *[u8] = "";
250 +
    if let slash = mem::rfind(manifest, "/") {
251 +
        set directory = &manifest[.. slash];
252 +
    }
253 +
    let rooted = path.len > 0 and path[0] == '/';
254 +
    let absolute = rooted or (directory.len > 0 and directory[0] == '/');
255 +
    let texts: [*[u8]; 2] = [directory, path];
256 +
    let first: u32 = 1 if rooted else 0;
257 +
    for text in &texts[first ..] {
258 +
        let mut components = mem::split(text, '/');
259 +
        while let part = components.next() {
260 +
            if part.len == 0 or mem::eq(part, ".") {
261 +
                continue;
262 +
            }
263 +
            if mem::eq(part, "..") and count > 0 and not mem::eq(parts[count - 1], "..") {
264 +
                set count -= 1;
265 +
                continue;
266 +
            }
267 +
            if mem::eq(part, "..") and absolute and count == 0 {
268 +
                continue;
269 +
            }
270 +
            if count >= MAX_COMPONENTS {
271 +
                throw Error::TooLarge;
272 +
            }
273 +
            set parts[count] = part;
274 +
            set count += 1;
275 +
        }
276 +
    }
277 +
    let mut result: *mut [u8] = &mut [];
278 +
    if absolute {
279 +
        try result.append('/', arena) catch {
280 +
            throw Error::TooLarge;
281 +
        };
282 +
    }
283 +
    for part, i in &parts[.. count] {
284 +
        if i > 0 {
285 +
            try result.append('/', arena) catch {
286 +
                throw Error::TooLarge;
287 +
            };
288 +
        }
289 +
        try result.extend(part, arena) catch {
290 +
            throw Error::TooLarge;
291 +
        };
292 +
    }
293 +
    if result.len == 0 {
294 +
        return ".";
295 +
    }
296 +
    return &result[..];
297 +
}
298 +
299 +
/// Print a diagnostic made of `parts` at `node`, and return [`Error::Invalid`].
300 +
fn invalid(r: Reader, node: *ast::Node, parts: &[*[u8]]) -> Error {
301 +
    io::printError(r.path);
302 +
    if let loc = scanner::getLocation(
303 +
        scanner::SourceLoc::File(r.path), r.text, node.span.offset
304 +
    ) {
305 +
        let mut buffer: [u8; fmt::U32_STR_LEN] = [0; fmt::U32_STR_LEN];
306 +
        io::printError(":");
307 +
        io::printError(fmt::formatU32(loc.line as u32, &mut buffer[..]));
308 +
        io::printError(":");
309 +
        io::printError(fmt::formatU32(loc.col as u32, &mut buffer[..]));
310 +
    }
311 +
    io::printError(": error: ");
312 +
    for part in parts {
313 +
        io::printError(part);
314 +
    }
315 +
    io::printError("\n");
316 +
    return Error::Invalid;
317 +
}
318 +
319 +
/// Return the fields of a record literal of type `typeName`, written with
320 +
/// that name or without one. Each field is labeled and appears once.
321 +
fn recordFields(r: Reader, node: *ast::Node, typeName: *[u8]) -> *[*ast::Node]
322 +
    throws (Error)
323 +
{
324 +
    let case ast::NodeValue::RecordLit(literal) = node.value else {
325 +
        throw invalid(r, node, &["expected a `", typeName, "` record"]);
326 +
    };
327 +
    if let name = literal.typeName {
328 +
        let mut matches = false;
329 +
        if let case ast::NodeValue::Ident(text) = name.value {
330 +
            set matches = mem::eq(text, typeName);
331 +
        }
332 +
        if not matches {
333 +
            throw invalid(r, name, &["expected a `", typeName, "` record"]);
334 +
        }
335 +
    }
336 +
    if literal.ignoreRest {
337 +
        throw invalid(r, node, &["`..` is not allowed in a manifest"]);
338 +
    }
339 +
    for field, i in literal.fields {
340 +
        let label = try fieldName(r, field);
341 +
        for previous in &literal.fields[.. i] {
342 +
            if mem::eq(try fieldName(r, previous), label) {
343 +
                throw invalid(r, field, &["duplicate field `", label, "`"]);
344 +
            }
345 +
        }
346 +
    }
347 +
    return literal.fields;
348 +
}
349 +
350 +
/// Return the label of a record literal field.
351 +
fn fieldName(r: Reader, field: *ast::Node) -> *[u8] throws (Error) {
352 +
    let case ast::NodeValue::RecordLitField(arg) = field.value
353 +
        else panic "fieldName: expected a record literal field";
354 +
    let label = arg.label else throw invalid(r, field, &["expected `name: value`"]);
355 +
    let case ast::NodeValue::Ident(text) = label.value
356 +
        else throw invalid(r, label, &["expected a field name"]);
357 +
    return text;
358 +
}
359 +
360 +
/// Return the value of a record literal field.
361 +
fn fieldValue(field: *ast::Node) -> *ast::Node {
362 +
    let case ast::NodeValue::RecordLitField(arg) = field.value
363 +
        else panic "fieldValue: expected a record literal field";
364 +
    return arg.value;
365 +
}
366 +
367 +
/// Copy a string literal to `arena`.
368 +
fn string(r: Reader, node: *ast::Node, arena: &heap::Heap) -> *[u8] throws (Error) {
369 +
    let case ast::NodeValue::String(text) = node.value
370 +
        else throw invalid(r, node, &["expected a string"]);
371 +
    let copy = try alloc::copyBytes(arena, text) catch {
372 +
        throw Error::TooLarge;
373 +
    };
374 +
    return &copy[..];
375 +
}
376 +
377 +
/// Return the elements of an array literal.
378 +
fn elements(r: Reader, node: *ast::Node) -> *[*ast::Node] throws (Error) {
379 +
    let case ast::NodeValue::ArrayLit(items) = node.value
380 +
        else throw invalid(r, node, &["expected an array"]);
381 +
    return items;
382 +
}
383 +
384 +
/// Check that `text` is an identifier: letters, digits and `_`, not starting
385 +
/// with a digit.
386 +
fn isIdentifier(text: *[u8]) -> bool {
387 +
    if text.len == 0 {
388 +
        return false;
389 +
    }
390 +
    for byte, i in text {
391 +
        if not (char::isAlpha(byte) or byte == '_' or (i > 0 and char::isDigit(byte))) {
392 +
            return false;
393 +
        }
394 +
    }
395 +
    return true;
396 +
}
397 +
398 +
/// Read a package name.
399 +
fn identifier(r: Reader, node: *ast::Node, arena: &heap::Heap) -> *[u8] throws (Error) {
400 +
    let text = try string(r, node, arena);
401 +
    if not isIdentifier(text) {
402 +
        throw invalid(r, node, &["invalid package name `", text, "`"]);
403 +
    }
404 +
    return text;
405 +
}
406 +
407 +
/// Read a `MAJOR.MINOR.PATCH` version.
408 +
fn version(r: Reader, node: *ast::Node, arena: &heap::Heap) -> *[u8] throws (Error) {
409 +
    let text = try string(r, node, arena);
410 +
    if binary::versionParts(text) == nil {
411 +
        throw invalid(r, node, &["invalid version `", text, "`, expected MAJOR.MINOR.PATCH"]);
412 +
    }
413 +
    return text;
414 +
}
415 +
416 +
/// Read a clean relative path below the package root.
417 +
fn relativePath(r: Reader, node: *ast::Node, arena: &heap::Heap) -> *[u8] throws (Error) {
418 +
    let text = try string(r, node, arena);
419 +
    if not fs::isNormalRelativePath(text) {
420 +
        throw invalid(r, node, &["path `", text, "` is not a clean path below the package root"]);
421 +
    }
422 +
    return text;
423 +
}
424 +
425 +
/// Read an array of paths below the package root.
426 +
fn paths(r: Reader, node: *ast::Node, arena: &heap::Heap) -> *[*[u8]] throws (Error) {
427 +
    let mut result: *mut [*[u8]] = &mut [];
428 +
    for item in try elements(r, node) {
429 +
        let text = try relativePath(r, item, arena);
430 +
        try result.append(text, arena) catch {
431 +
            throw Error::TooLarge;
432 +
        };
433 +
    }
434 +
    return &result[..];
435 +
}
436 +
437 +
/// Read an array of module names, `::`-separated identifiers.
438 +
fn moduleNames(r: Reader, node: *ast::Node, arena: &heap::Heap) -> *[*[u8]] throws (Error) {
439 +
    let mut result: *mut [*[u8]] = &mut [];
440 +
    for item in try elements(r, node) {
441 +
        let text = try string(r, item, arena);
442 +
        let mut valid = true;
443 +
        let mut start: u32 = 0;
444 +
        loop {
445 +
            let rest = &text[start ..];
446 +
            let end = mem::find(rest, "::") else {
447 +
                set valid = valid and isIdentifier(rest);
448 +
                break;
449 +
            };
450 +
            set valid = valid and isIdentifier(&rest[.. end]);
451 +
            set start += end + 2;
452 +
        }
453 +
        if not valid {
454 +
            throw invalid(r, item, &["invalid module name `", text, "`"]);
455 +
        }
456 +
        try result.append(text, arena) catch {
457 +
            throw Error::TooLarge;
458 +
        };
459 +
    }
460 +
    return &result[..];
461 +
}
462 +
463 +
/// Return the parent of module `name`, or `nil` for a child of the root module.
464 +
fn parentModule(name: *[u8]) -> ?*[u8] {
465 +
    let end = mem::rfind(name, "::") else return nil;
466 +
    return &name[.. end];
467 +
}
468 +
469 +
/// Check whether `names` contains `name`.
470 +
fn contains(names: *[*[u8]], name: *[u8]) -> bool {
471 +
    for item in names {
472 +
        if mem::eq(item, name) {
473 +
            return true;
474 +
        }
475 +
    }
476 +
    return false;
477 +
}
478 +
479 +
/// Check that each module name appears once in `modules` and `tests`, and
480 +
/// that the parent of a module is listed. The parent of a test module can
481 +
/// also be a test module.
482 +
fn checkModules(r: Reader, root: *ast::Node, modules: *[*[u8]], tests: *[*[u8]])
483 +
    throws (Error)
484 +
{
485 +
    for name, i in modules {
486 +
        if contains(&modules[.. i], name) {
487 +
            throw invalid(r, root, &["module `", name, "` is listed twice"]);
488 +
        }
489 +
        if let parent = parentModule(name); not contains(modules, parent) {
490 +
            throw invalid(r, root, &[
491 +
                "module `", name, "` is listed without its parent `", parent, "`"
492 +
            ]);
493 +
        }
494 +
    }
495 +
    for name, i in tests {
496 +
        if contains(&tests[.. i], name) or contains(modules, name) {
497 +
            throw invalid(r, root, &["module `", name, "` is listed twice"]);
498 +
        }
499 +
        if let parent = parentModule(name);
500 +
            not contains(modules, parent) and not contains(tests, parent)
501 +
        {
502 +
            throw invalid(r, root, &[
503 +
                "module `", name, "` is listed without its parent `", parent, "`"
504 +
            ]);
505 +
        }
506 +
    }
507 +
}
508 +
509 +
/// Put each listed parent before its children. `earlier` holds parents
510 +
/// already registered from another list.
511 +
fn orderModules(names: *[*[u8]], earlier: *[*[u8]], arena: &heap::Heap) -> *[*[u8]]
512 +
    throws (Error)
513 +
{
514 +
    let mut ordered: *mut [*[u8]] = &mut [];
515 +
    try ordered.reserve(names.len, arena) catch {
516 +
        throw Error::TooLarge;
517 +
    };
518 +
    for name in names {
519 +
        try orderModule(name, earlier, &mut ordered, arena);
520 +
    }
521 +
    return &ordered[..];
522 +
}
523 +
524 +
/// Add a listed module and any of its parents not yet in order.
525 +
fn orderModule(name: *[u8], earlier: *[*[u8]], ordered: &mut *mut [*[u8]], arena: &heap::Heap)
526 +
    throws (Error)
527 +
{
528 +
    if contains(&ordered[..], name) or contains(earlier, name) {
529 +
        return;
530 +
    }
531 +
    if let parent = parentModule(name) {
532 +
        try orderModule(parent, earlier, ordered, arena);
533 +
    }
534 +
    try ordered.append(name, arena) catch {
535 +
        throw Error::TooLarge;
536 +
    };
537 +
}
538 +
539 +
/// Read an array of dependencies. Each provider name appears once.
540 +
fn dependencies(r: Reader, node: *ast::Node, arena: &heap::Heap) -> *[Dependency]
541 +
    throws (Error)
542 +
{
543 +
    let mut result: *mut [Dependency] = &mut [];
544 +
    for item in try elements(r, node) {
545 +
        let entry = try dependency(r, item, arena);
546 +
        for i in 0 .. result.len {
547 +
            if mem::eq(result[i].name, entry.name) {
548 +
                throw invalid(r, item, &["duplicate dependency `", entry.name, "`"]);
549 +
            }
550 +
        }
551 +
        try result.append(entry, arena) catch {
552 +
            throw Error::TooLarge;
553 +
        };
554 +
    }
555 +
    return &result[..];
556 +
}
557 +
558 +
/// Read one dependency record.
559 +
fn dependency(r: Reader, node: *ast::Node, arena: &heap::Heap) -> Dependency throws (Error) {
560 +
    let mut name: ?*[u8] = nil;
561 +
    let mut required: ?*[u8] = nil;
562 +
    let fields = try recordFields(r, node, "Dependency");
563 +
    for field in fields {
564 +
        let label = try fieldName(r, field);
565 +
        let item = fieldValue(field);
566 +
        if mem::eq(label, "name") {
567 +
            set name = try identifier(r, item, arena);
568 +
        } else if mem::eq(label, "version") {
569 +
            set required = try version(r, item, arena);
570 +
        } else {
571 +
            throw invalid(r, field, &["unknown field `", label, "`"]);
572 +
        }
573 +
    }
574 +
    let found = name else throw invalid(r, node, &["missing field `name`"]);
575 +
    let oldest = required else throw invalid(r, node, &["missing field `version`"]);
576 +
    return Dependency { name: found, version: oldest };
577 +
}
lib/std/lang/manifest/tests.rad added +207 -0
1 +
//! Tests for package manifests.
2 +
3 +
use std::mem;
4 +
use std::mem::heap;
5 +
use std::testing;
6 +
use std::lang::ast;
7 +
use std::lang::parser;
8 +
use std::lang::strings;
9 +
10 +
/// Syntax and result storage size.
11 +
constant ARENA_SIZE: u32 = 262144;
12 +
13 +
/// Syntax tree storage, reused by each test.
14 +
unsafe static SYNTAX: [u8; ARENA_SIZE] = undefined;
15 +
/// Result storage, reused by each test.
16 +
unsafe static RESULTS: [u8; ARENA_SIZE] = undefined;
17 +
/// Table storage for the string pool.
18 +
unsafe static STRING_TABLE: [*[u8]; strings::TABLE_SIZE] = undefined;
19 +
20 +
/// Read the manifest `text`, with fresh storage.
21 +
unsafe fn read(text: *[u8]) -> super::Package throws (super::Error) {
22 +
    let mut syntax = parser::newParser(ast::nodeArena(&mut SYNTAX[..]), strings::pool(
23 +
        &mut STRING_TABLE[..]
24 +
    ));
25 +
    return try super::read(&mut syntax, "test.manifest", text, heap::over(&mut RESULTS[..]));
26 +
}
27 +
28 +
/// Check that reading `text` fails with `expected`.
29 +
unsafe fn expectError(text: *[u8], expected: super::Error) throws (testing::TestError) {
30 +
    try read(text) catch failure {
31 +
        try testing::expect(failure == expected);
32 +
        return;
33 +
    };
34 +
    throw testing::TestError::Failed;
35 +
}
36 +
37 +
/// Check that two string lists are equal.
38 +
fn expectNames(actual: *[*[u8]], expected: *[*[u8]]) throws (testing::TestError) {
39 +
    try testing::expect(actual.len == expected.len);
40 +
    for name, i in expected {
41 +
        try testing::expect(mem::eq(actual[i], name));
42 +
    }
43 +
}
44 +
45 +
@test unsafe fn testReadPackage() throws (testing::TestError) {
46 +
    let package = try read(@embed("lang/manifest/tests/fixtures/kernel.manifest")) catch {
47 +
        throw testing::TestError::Failed;
48 +
    };
49 +
    try testing::expect(mem::eq(package.name, "kernel"));
50 +
    try testing::expect(mem::eq(package.version, "0.4.10"));
51 +
    try testing::expect(package.dependencies.len == 2);
52 +
    try testing::expect(mem::eq(package.dependencies[0].name, "std"));
53 +
    try testing::expect(mem::eq(package.dependencies[0].version, "0.1.0"));
54 +
    try testing::expect(mem::eq(package.dependencies[1].name, "util"));
55 +
    try testing::expect(mem::eq(package.dependencies[1].version, "2.3.4"));
56 +
    try expectNames(package.modules, &["abi", "abi::calls", "trap"]);
57 +
    try expectNames(package.tests, &["tests", "tests::abi", "abi::tests"]);
58 +
    try expectNames(package.assembly, &["kernel/boot.ras"]);
59 +
    let startup = package.startup else throw testing::TestError::Failed;
60 +
    try testing::expect(mem::eq(startup, "start.ras"));
61 +
    try expectNames(package.embed, &["data/table.bin"]);
62 +
}
63 +
64 +
@test unsafe fn testReadDefaults() throws (testing::TestError) {
65 +
    let package = try read("{ version: \"1.0.0\", name: \"app\", startup: nil }") catch {
66 +
        throw testing::TestError::Failed;
67 +
    };
68 +
    try testing::expect(mem::eq(package.name, "app"));
69 +
    try testing::expect(package.dependencies.len == 0);
70 +
    try testing::expect(package.modules.len == 0);
71 +
    try testing::expect(package.tests.len == 0);
72 +
    try testing::expect(package.assembly.len == 0);
73 +
    try testing::expect(package.startup == nil);
74 +
    try testing::expect(package.embed.len == 0);
75 +
}
76 +
77 +
/// Check parent-first order in both module lists.
78 +
@test unsafe fn testReadModulesInParentOrder() throws (testing::TestError) {
79 +
    let package = try read(@embed("lang/manifest/tests/fixtures/module_order.manifest")) catch {
80 +
        throw testing::TestError::Failed;
81 +
    };
82 +
    try expectNames(package.modules, &["a", "a::b", "a::b::c"]);
83 +
    try expectNames(package.tests, &["a::b::tests", "a::b::tests::c", "top"]);
84 +
}
85 +
86 +
@test unsafe fn testRejectFields() throws (testing::TestError) {
87 +
    let invalid = super::Error::Invalid;
88 +
    try expectError("Package { version: \"1.0.0\" }", invalid);
89 +
    try expectError("Package { name: \"app\" }", invalid);
90 +
    try expectError("Package { name: \"app\", version: \"1.0.0\", extra: [] }", invalid);
91 +
    try expectError("Package { name: \"app\", name: \"app\", version: \"1.0.0\" }", invalid);
92 +
    try expectError("Other { name: \"app\", version: \"1.0.0\" }", invalid);
93 +
    try expectError("Package { name: \"app\", version: \"1.0.0\", .. }", invalid);
94 +
    try expectError("[\"app\"]", invalid);
95 +
}
96 +
97 +
@test unsafe fn testRejectValues() throws (testing::TestError) {
98 +
    let invalid = super::Error::Invalid;
99 +
    try expectError("{ name: \"1app\", version: \"1.0.0\" }", invalid);
100 +
    try expectError("{ name: NAME, version: \"1.0.0\" }", invalid);
101 +
    try expectError("{ name: \"app\", version: \"1.0\" }", invalid);
102 +
    try expectError("{ name: \"app\", version: \"1.x.0\" }", invalid);
103 +
    try expectError("{ name: \"app\", version: \"1.0.0\", assembly: [\"../a.ras\"] }", invalid);
104 +
    try expectError("{ name: \"app\", version: \"1.0.0\", embed: [\"/a\"] }", invalid);
105 +
    try expectError("{ name: \"app\", version: \"1.0.0\", modules: [\"a::\"] }", invalid);
106 +
    try expectError("{ name: \"app\", version: \"1.0.0\", modules: [\"a/b\"] }", invalid);
107 +
    try expectError("{ name: \"app\", version: \"1.0.0\", modules: \"a\" }", invalid);
108 +
    try expectError(
109 +
        "{ name: \"app\", version: \"1.0.0\", dependencies: [{ name: \"std\" }] }", invalid
110 +
    );
111 +
    try expectError(
112 +
        "{ name: \"app\", version: \"1.0.0\", dependencies: [{ version: \"1.0.0\" }] }", invalid
113 +
    );
114 +
    try expectError(
115 +
        "{ name: \"app\", version: \"1.0.0\", dependencies: [{ name: \"std\", version: \"1\" }] }",
116 +
        invalid
117 +
    );
118 +
    try expectError(
119 +
        "{ name: \"app\", version: \"1.0.0\", dependencies: [Other { name: \"std\", version: \"1.0.0\" }] }",
120 +
        invalid
121 +
    );
122 +
    try expectError("{ name: \"app\", version: \"1.0.0\" } + 1", invalid);
123 +
    try expectError("{ name: \"app\", version: \"1.0.0\"", super::Error::Syntax);
124 +
}
125 +
126 +
@test unsafe fn testRejectDuplicates() throws (testing::TestError) {
127 +
    let invalid = super::Error::Invalid;
128 +
    try expectError(
129 +
        "{ name: \"app\", version: \"1.0.0\", dependencies: [{ name: \"std\", version: \"1.0.0\" }, { name: \"std\", version: \"2.0.0\" }] }",
130 +
        invalid
131 +
    );
132 +
    try expectError("{ name: \"app\", version: \"1.0.0\", modules: [\"a\", \"a\"] }", invalid);
133 +
    try expectError(
134 +
        "{ name: \"app\", version: \"1.0.0\", modules: [\"a\"], tests: [\"a\"] }", invalid
135 +
    );
136 +
}
137 +
138 +
@test unsafe fn testRejectMissingParents() throws (testing::TestError) {
139 +
    let invalid = super::Error::Invalid;
140 +
    try expectError("{ name: \"app\", version: \"1.0.0\", modules: [\"a::b\"] }", invalid);
141 +
    try expectError(
142 +
        "{ name: \"app\", version: \"1.0.0\", modules: [\"tests::a\"], tests: [\"tests\"] }",
143 +
        invalid
144 +
    );
145 +
    try expectError("{ name: \"app\", version: \"1.0.0\", tests: [\"a::tests\"] }", invalid);
146 +
}
147 +
148 +
@test unsafe fn testModulePath() throws (testing::TestError) {
149 +
    let arena = heap::over(&mut RESULTS[..]);
150 +
    let nested = try super::modulePath("mem::heap", arena) catch {
151 +
        throw testing::TestError::Failed;
152 +
    };
153 +
    try testing::expect(mem::eq(nested, "mem/heap"));
154 +
    let top = try super::modulePath("util", arena) catch {
155 +
        throw testing::TestError::Failed;
156 +
    };
157 +
    try testing::expect(mem::eq(top, "util"));
158 +
}
159 +
160 +
@test unsafe fn testFile() throws (testing::TestError) {
161 +
    let arena = heap::over(&mut RESULTS[..]);
162 +
    let cases: [[*[u8]; 3]; 4] = [
163 +
        ["lib/std",      "std", "lib/std/std.manifest"],
164 +
        [".",            "app", "app.manifest"],
165 +
        ["../lib/util/", "util", "../lib/util/util.manifest"],
166 +
        ["/srv/app",     "app", "/srv/app/app.manifest"],
167 +
    ];
168 +
    for item in &cases[..] {
169 +
        let path = try super::file(item[0], item[1], arena) catch {
170 +
            throw testing::TestError::Failed;
171 +
        };
172 +
        try testing::expect(mem::eq(path, item[2]));
173 +
    }
174 +
}
175 +
176 +
@test fn testCompatible() throws (testing::TestError) {
177 +
    assert not super::compatible("1.0.0", "18446744073709551617.0.0");
178 +
    assert super::compatible("1.18446744073709551615.0", "1.18446744073709551616.0");
179 +
    assert super::compatible("1.2.3", "1.2.3");
180 +
    assert super::compatible("1.2.3", "1.2.4");
181 +
    assert super::compatible("1.2.3", "1.10.0");
182 +
    assert not super::compatible("1.2.3", "1.2.2");
183 +
    assert not super::compatible("1.2.3", "1.1.9");
184 +
    assert not super::compatible("1.2.3", "2.0.0");
185 +
    assert super::compatible("0.1.0", "0.1.7");
186 +
    assert not super::compatible("0.1.0", "0.2.0");
187 +
    assert not super::compatible("0.1.2", "0.1.1");
188 +
}
189 +
190 +
@test unsafe fn testResolve() throws (testing::TestError) {
191 +
    let arena = heap::over(&mut RESULTS[..]);
192 +
    let cases: [[*[u8]; 3]; 7] = [
193 +
        ["kernel/kernel.manifest", "../lib/std.manifest", "lib/std.manifest"],
194 +
        ["kernel/kernel.manifest", "kernel/boot.ras", "kernel/kernel/boot.ras"],
195 +
        ["app.manifest",           "./util/../util.manifest", "util.manifest"],
196 +
        ["app.manifest",           "../x.manifest", "../x.manifest"],
197 +
        ["a/b.manifest",           "../../c", "../c"],
198 +
        ["/srv/a/b.manifest",      "../../../c", "/c"],
199 +
        ["a/b.manifest",           "/abs/c", "/abs/c"],
200 +
    ];
201 +
    for item in &cases[..] {
202 +
        let path = try super::resolve(item[0], item[1], arena) catch {
203 +
            throw testing::TestError::Failed;
204 +
        };
205 +
        try testing::expect(mem::eq(path, item[2]));
206 +
    }
207 +
}
lib/std/lang/manifest/tests/fixtures/kernel.manifest added +14 -0
1 +
// Kernel.
2 +
Package {
3 +
    name: "kernel",
4 +
    version: "0.4.10",
5 +
    dependencies: [
6 +
        Dependency { name: "std", version: "0.1.0" },
7 +
        { name: "util", version: "2.3.4" },
8 +
    ],
9 +
    modules: ["abi", "abi::calls", "trap"],
10 +
    tests: ["tests", "tests::abi", "abi::tests"],
11 +
    assembly: ["kernel/boot.ras"],
12 +
    startup: "start.ras",
13 +
    embed: ["data/table.bin"],
14 +
}
lib/std/lang/manifest/tests/fixtures/module_order.manifest added +6 -0
1 +
{
2 +
    name: "app",
3 +
    version: "1.0.0",
4 +
    modules: ["a::b::c", "a::b", "a"],
5 +
    tests: ["a::b::tests::c", "a::b::tests", "top"],
6 +
}
lib/std/std.manifest added +133 -0
1 +
// The Radiance standard library.
2 +
Package {
3 +
    name: "std",
4 +
    version: "0.1.0",
5 +
    modules: [
6 +
        "char",
7 +
        "fmt",
8 +
        "mem",
9 +
        "bits",
10 +
        "mem::heap",
11 +
        "vec",
12 +
        "io",
13 +
        "intrinsics",
14 +
        "sys",
15 +
        "collections",
16 +
        "collections::dict",
17 +
        "sys::host",
18 +
        "fs",
19 +
        "process",
20 +
        "arch",
21 +
        "arch::rv64",
22 +
        "arch::rv64::image",
23 +
        "arch::rv64::encode",
24 +
        "arch::rv64::decode",
25 +
        "arch::rv64::emit",
26 +
        "arch::rv64::isel",
27 +
        "arch::rv64::printer",
28 +
        "arch::rv64::asm",
29 +
        "arch::rv64::asm::scanner",
30 +
        "arch::rv64::asm::parser",
31 +
        "arch::rv64::asm::emit",
32 +
        "lang",
33 +
        "lang::alloc",
34 +
        "lang::types",
35 +
        "lang::strings",
36 +
        "lang::sexpr",
37 +
        "lang::ast",
38 +
        "lang::ast::printer",
39 +
        "lang::layout",
40 +
        "lang::layout::text",
41 +
        "lang::scanner",
42 +
        "lang::parser",
43 +
        "lang::manifest",
44 +
        "lang::pretty",
45 +
        "lang::il",
46 +
        "lang::il::printer",
47 +
        "lang::il::binary",
48 +
        "lang::il::binary::writer",
49 +
        "lang::il::binary::reader",
50 +
        "lang::il::binary::program",
51 +
        "lang::il::binary::collect",
52 +
        "lang::il::binary::cfg",
53 +
        "lang::il::verify",
54 +
        "lang::il::verify::layout",
55 +
        "lang::il::verify::flow",
56 +
        "lang::il::verify::data",
57 +
        "lang::resolver",
58 +
        "lang::resolver::metadata",
59 +
        "lang::resolver::printer",
60 +
        "lang::resolver::refs",
61 +
        "lang::lower",
62 +
        "lang::lower::regions",
63 +
        "lang::module",
64 +
        "lang::module::printer",
65 +
        "lang::package",
66 +
        "lang::gen",
67 +
        "lang::gen::labels",
68 +
        "lang::gen::bitset",
69 +
        "lang::gen::data",
70 +
        "lang::gen::types",
71 +
        "lang::gen::regalloc",
72 +
        "lang::gen::regalloc::liveness",
73 +
        "lang::gen::regalloc::spill",
74 +
        "lang::gen::regalloc::assign",
75 +
        "arch::rv64::shared",
76 +
        "arch::rv64::shared::catalog",
77 +
        "arch::rv64::atomics",
78 +
        "hash",
79 +
        "hash::blake3",
80 +
        "lang::il::link",
81 +
        "lang::il::binary::linkage",
82 +
        "lang::il::verify::linking",
83 +
        "arch::rv64::vector",
84 +
    ],
85 +
    tests: [
86 +
        "testing",
87 +
        "tests",
88 +
        "fs::tests",
89 +
        "char::tests",
90 +
        "mem::heap::tests",
91 +
        "arch::rv64::tests",
92 +
        "arch::rv64::asm::tests",
93 +
        "arch::rv64::asm::scanner::tests",
94 +
        "lang::alloc::tests",
95 +
        "lang::sexpr::tests",
96 +
        "lang::layout::tests",
97 +
        "lang::il::printer::tests",
98 +
        "lang::ast::tests",
99 +
        "lang::lower::tests",
100 +
        "lang::parser::tests",
101 +
        "lang::manifest::tests",
102 +
        "lang::module::tests",
103 +
        "lang::scanner::tests",
104 +
        "lang::resolver::tests",
105 +
        "lang::resolver::tests::core",
106 +
        "lang::resolver::tests::structure",
107 +
        "lang::resolver::tests::safety",
108 +
        "lang::resolver::tests::opacity",
109 +
        "lang::resolver::tests::regions",
110 +
        "lang::gen::bitset::tests",
111 +
        "lang::il::binary::tests",
112 +
        "lang::il::binary::tests::decode",
113 +
        "lang::il::verify::tests",
114 +
        "arch::rv64::image::tests",
115 +
        "arch::rv64::shared::tests",
116 +
        "arch::rv64::shared::tests::run",
117 +
        "arch::rv64::tests::bounds",
118 +
        "arch::rv64::tests::atomics",
119 +
        "bits::tests",
120 +
        "mem::tests",
121 +
        "hash::blake3::tests",
122 +
        "lang::il::link::tests",
123 +
    ],
124 +
    assembly: [
125 +
        "hash/blake3.ras",
126 +
        "mem.ras",
127 +
        "lang/gen/bitset.ras",
128 +
    ],
129 +
    embed: [
130 +
        "lang/manifest/tests/fixtures/kernel.manifest",
131 +
        "lang/manifest/tests/fixtures/module_order.manifest",
132 +
    ],
133 +
}
lib/std.rad → lib/std/std.rad renamed +0 -0
scripts/check-fmt +1 -1
14 14
# The scope globs below are git pathspecs, not shell patterns.
15 15
set -f
16 16
17 17
# Sources that are kept in the canonical style.
18 18
scope="lib/*.rad compiler/*.rad kernel/*.rad test/integration/*.rad
19 -
    test/host/*.rad test/integration.rad"
19 +
    test/host/*.rad"
20 20
21 21
# Memory and stack limits of hosted build tools.
22 22
limits=$(cat seed/emulator-args) || exit 2
23 23
24 24
rad=bin/radiance.rv64.dev
lib/std.manifest → seed/dependencies/none renamed +0 -0
compiler/radiance.manifest → seed/dependencies/std renamed +0 -0
seed/update +1 -1
59 59
# Compile one stage using a native (s0) binary.
60 60
#   stageS0 <input> <output>
61 61
# ---------------------------------------------------------------------------
62 62
63 63
stageS0() {
64 -
  time -p "$1" compiler/radiance.rad $OPTS -o "$2"
64 +
  time -p "$1" compiler/radiance/radiance.rad $OPTS -o "$2"
65 65
}
66 66
67 67
# ---------------------------------------------------------------------------
68 68
# Compare two stage binaries. Returns 0 if identical, 1 if they differ.
69 69
# ---------------------------------------------------------------------------
std.lib +2 -1
1 -
lib/std.rad
1 +
lib/std/std.rad
2 2
lib/std/char.rad
3 3
lib/std/fmt.rad
4 4
lib/std/mem.rad
5 5
lib/std/bits.rad
6 6
lib/std/mem/heap.rad
34 34
lib/std/lang/ast/printer.rad
35 35
lib/std/lang/layout.rad
36 36
lib/std/lang/layout/text.rad
37 37
lib/std/lang/scanner.rad
38 38
lib/std/lang/parser.rad
39 +
lib/std/lang/manifest.rad
39 40
lib/std/lang/pretty.rad
40 41
lib/std/lang/il.rad
41 42
lib/std/lang/il/printer.rad
42 43
lib/std/lang/il/binary.rad
43 44
lib/std/lang/il/binary/writer.rad
std.lib.test +1 -0
11 11
lib/std/lang/layout/tests.rad
12 12
lib/std/lang/il/printer/tests.rad
13 13
lib/std/lang/ast/tests.rad
14 14
lib/std/lang/lower/tests.rad
15 15
lib/std/lang/parser/tests.rad
16 +
lib/std/lang/manifest/tests.rad
16 17
lib/std/lang/module/tests.rad
17 18
lib/std/lang/scanner/tests.rad
18 19
lib/std/lang/resolver/tests.rad
19 20
lib/std/lang/resolver/tests/core.rad
20 21
lib/std/lang/resolver/tests/structure.rad
test/Makefile +33 -25
35 35
TEST_TOOL_SRC := test/runner.rad test/native/build.rad \
36 36
    test/shared/build.rad test/sync/build.rad test/loader/hostile.rad \
37 37
    test/verify/check.rad test/host/child.rad
38 38
TEST_TOOLS := $(TEST_TOOL_SRC:.rad=.rv64)
39 39
40 -
$(TEST_TOOLS): %.rv64: %.rad $(STD_LIB) $(STD_MANIFEST) test/std.manifest $(RAD_BIN) test/Makefile
41 -
	@$(RADIANCE) $(STD) -pkg tool -manifest test/std.manifest -mod $< -entry tool -o $@
40 +
$(TEST_TOOLS): %.rv64: %.rad $(STD_LIB) $(STD_MANIFEST) $(RAD_BIN) test/Makefile
41 +
	@$(RADIANCE) -name tool $< -o $@
42 42
43 43
# The integration driver runs the checks that start other programs: the
44 44
# compiler, the test tools and the emulator. Each of its commands works in
45 45
# bin/test/NAME.
46 46
INTEGRATION      := test/integration.rv64
47 47
INTEGRATION_SRC  := $(sort $(wildcard test/integration/*.rad))
48 +
INTEGRATION_FIXTURES := $(wildcard test/integration/fixtures/*/*)
48 49
INTEGRATION_OPTS := -compiler $(RAD_BIN) -jobs $(JOBS)
49 50
# Run the driver command $(1) with the arguments $(2).
50 51
integration = $(HOSTED) $(INTEGRATION) $(1) $(INTEGRATION_OPTS) $(2)
51 52
52 -
$(INTEGRATION): test/integration.rad $(INTEGRATION_SRC) $(STD_LIB) $(STD_MANIFEST) test/std.manifest $(RAD_BIN) \
53 -
    test/Makefile
54 -
	@$(RADIANCE) $(STD) -pkg integration -manifest test/std.manifest -mod test/integration.rad \
55 -
	    $(patsubst %,-mod %,$(INTEGRATION_SRC)) -entry integration -o $@
53 +
$(INTEGRATION): $(INTEGRATION_FIXTURES) $(INTEGRATION_SRC) $(STD_LIB) $(STD_MANIFEST) \
54 +
    test/integration/integration.manifest $(RAD_BIN) test/Makefile
55 +
	@$(RADIANCE) test/integration -o $@
56 56
57 57
seed-test: $(INTEGRATION)
58 58
	@$(call integration,seed)
59 59
60 60
# std::process against the emulator.
70 70
71 71
# Standard Library Tests
72 72
73 73
STD_LIB_TEST := lib/std.test.rv64
74 74
75 +
STD_TEST_FIXTURES := $(wildcard lib/std/lang/manifest/tests/fixtures/*.manifest \
76 +
    lib/std/lang/resolver/tests/fixtures/*/*.rad)
77 +
75 78
std-test: $(STD_LIB_TEST)
76 79
	@$(HOSTED) $(STD_LIB_TEST)
77 80
78 -
$(STD_LIB_TEST): $(STD_TEST_LIB) $(STD_MANIFEST) std.lib.test $(RAD_BIN) test/Makefile
79 -
	@$(RADIANCE) -test $(STD_TEST) -entry std -o $@
81 +
$(STD_LIB_TEST): $(STD_TEST_FIXTURES) $(STD_TEST_LIB) $(STD_MANIFEST) $(RAD_BIN) test/Makefile
82 +
	@$(RADIANCE) -test lib/std -o $@
80 83
81 84
clean-std-test:
82 85
	@rm -f lib/std.test.rv64 lib/std.test.rv64.debug \
83 86
	    lib/std.test.rv64.s lib/std.test.rv64.o
84 87
85 88
# The source formatter keeps the AST of every standard library and compiler
86 89
# source, and formats its own output to itself.
87 -
FMT_TEST_SRC := $(shell find lib compiler test/integration test/host -name '*.rad' | sort) \
88 -
    test/integration.rad
90 +
FMT_TEST_SRC := $(shell find lib compiler test/integration test/host -name '*.rad' | sort)
89 91
90 92
fmt-test: $(RAD_BIN) $(INTEGRATION)
91 93
	@$(call integration,fmt,$(FMT_TEST_SRC))
92 94
93 95
kernel-test: $(KERNEL_TEST) $(INTEGRATION) $(RAD_BIN)
113 115
	@$(call integration,sync)
114 116
115 117
# Binary Tests
116 118
117 119
# Only tests with `//! returns:` are compiled to binaries and executed.
118 -
BIN_TEST_SRC   := $(shell grep -l '^//! returns:' $(wildcard test/tests/*.rad test/tests/*.ras))
120 +
BIN_TEST_SRC   := $(shell grep -l '^//! returns:' $(wildcard test/tests/*.rad test/tests/*.ras \
121 +
    test/tests/*/test.rad))
119 122
BIN_TEST_BIN   := $(addsuffix .rv64,$(basename $(BIN_TEST_SRC)))
120 -
FIXTURE_INPUTS := test/std.manifest $(wildcard test/**/*.manifest) $(wildcard test/tests/*.ras test/tests/*/*.rad)
121 123
122 124
bin-test: test/runner.rv64 $(INTEGRATION) $(BIN_TEST_BIN)
123 125
	@$(call integration,bin)
124 126
125 -
# A `.rad` executable test can have a same-basename `.ras` module.
126 -
# Compile each executable test to a binary. A test with `//! uses-std` links
127 -
# the standard library. Child modules and assembly inputs are dependencies.
127 +
# Compile each executable test to a binary. A test is one module, or a package
128 +
# directory `test/tests/NAME/` with `test.manifest` and the root `test.rad`
129 +
# when it has submodules or assembly. A test links the packages it imports.
128 130
# Fixtures that use std must rebuild when a library source changes.
129 -
# The compiler depends on the standard library source manifest and its modules.
130 -
test/tests/%.rv64: test/tests/%.rad $(FIXTURE_INPUTS) $(RAD_BIN) $(INTEGRATION) test/Makefile
131 +
# A package fixture also depends on its own module and assembly inputs.
132 +
.SECONDEXPANSION:
133 +
$(filter %/test.rv64,$(BIN_TEST_BIN)): test/tests/%/test.rv64: test/tests/%/test.manifest \
134 +
    $$(wildcard test/tests/$$*/*.rad test/tests/$$*/*.ras)
135 +
136 +
test/tests/%.rv64: test/tests/%.rad $(RAD_BIN) $(INTEGRATION) test/Makefile
131 137
	@$(call integration,compile,$< $@)
132 138
133 139
test/tests/%.rv64: test/tests/%.ras test/runner.rv64 test/Makefile
134 140
	@$(HOSTED) test/runner.rv64 assemble $< $@
135 141
215 221
# The verifier accepts or rejects the binary RIL of each fixture as
216 222
# test/verify/expected says.
217 223
verify-test: test/verify/check.rv64 $(INTEGRATION) $(RAD_BIN)
218 224
	@$(call integration,verify)
219 225
220 -
# Exercise the production test discovery module with bounded storage.
221 -
test/compiler/discovery.rv64: test/compiler/discovery.rad \
222 -
    compiler/radiance/testgen.rad compiler/radiance/testgen.manifest \
223 -
    test/compiler/checks.manifest $(STD_LIB) $(STD_MANIFEST) test/std.manifest $(RAD_BIN) test/Makefile
224 -
	@$(RADIANCE) $(STD) -pkg testgen -mod compiler/radiance/testgen.rad \
226 +
# Exercise the production test discovery module with bounded storage. The
227 +
# compiler modules have no package directory, so these builds use package flags.
228 +
test/compiler/discovery.rv64: test/compiler/discovery.rad compiler/radiance/testgen.rad \
229 +
    test/compiler/checks.manifest $(STD_LIB) $(RAD_BIN) test/Makefile
230 +
	@$(RADIANCE) $(STD) -pkg testgen -manifest seed/dependencies/std \
231 +
	    -mod compiler/radiance/testgen.rad \
225 232
	    -pkg checks -mod test/compiler/discovery.rad -entry checks -o $@
226 233
227 234
# Check canonical exported metadata through the production compiler module.
228 235
test/compiler/metadata.rv64: test/compiler/metadata.rad compiler/radiance/metadata.rad \
229 -
    test/compiler/metachecks.manifest $(STD_LIB) $(STD_MANIFEST) test/std.manifest $(RAD_BIN) test/Makefile
230 -
	@$(RADIANCE) $(STD) -pkg metadata -manifest test/std.manifest -mod compiler/radiance/metadata.rad \
231 -
	    -pkg metachecks -mod test/compiler/metadata.rad -entry metachecks -o $@
236 +
    test/compiler/metachecks.manifest $(STD_LIB) $(RAD_BIN) test/Makefile
237 +
	@$(RADIANCE) $(STD) -pkg metadata -manifest seed/dependencies/std \
238 +
	    -mod compiler/radiance/metadata.rad -pkg metachecks -mod test/compiler/metadata.rad \
239 +
	    -entry metachecks -o $@
232 240
233 241
.PHONY: test $(TESTS) $(SMP_TESTS) $(CYCLES_TESTS) clean-std-test clean-bin-test
test/integration/fixtures.rad +30 -30
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 66
    let produced = output if isImage else h.join(&[output, "/test/test.ril.bin"]);
67 -
    // Rejection fixtures resolve against the complete standard library.
68 -
    let usesStd = harness::marker(content, "//! uses-std") <> nil
69 -
        or harness::marker(content, REJECTS) <> nil;
70 67
    if isImage {
71 68
        h.add(&["-o", output]);
72 69
    } else {
73 70
        try harness::makeDirs(output);
74 71
        h.add(&["-ril", output]);
75 72
    }
76 -
    if usesStd {
77 -
        try h.addStd("" if isImage else ".rad");
78 -
    }
79 73
    if harness::marker(content, "//! stack-check") <> nil {
80 74
        h.add(&["-stack-check"]);
81 75
    }
82 -
    h.add(&["-pkg", "test", "-mod", source]);
83 -
    if usesStd {
84 -
        h.add(&["-manifest", "test/std.manifest"]);
85 -
    }
86 -
    if try harness::exists(base) {
87 -
        for path in try h.listFiles(base, ".rad") {
88 -
            h.add(&["-mod", path]);
89 -
        }
90 -
    }
91 -
    let assembly = h.join(&[base, ".ras"]);
92 -
    if try harness::exists(assembly) {
93 -
        h.add(&["-mod", assembly]);
94 -
    }
95 -
    let start = h.join(&[base, ".start.ras"]);
96 -
    if try harness::exists(start) {
97 -
        h.add(&["-start", start]);
98 -
    }
99 -
    if usesStd {
100 -
        h.add(&["-entry", "test"]);
76 +
    // A fixture with submodules or assembly is a package directory that
77 +
    // holds `test.rad`; any other is one module, which depends on the
78 +
    // packages that it imports.
79 +
    let directory = harness::directory(source);
80 +
    if try harness::exists(h.join(&[directory, "/test.manifest"])) {
81 +
        h.add(&[directory]);
82 +
    } else {
83 +
        h.add(&["-name", "test", source]);
101 84
    }
102 85
    try fs::remove(produced) catch err {
103 86
        if err <> sys::Error::NotFound {
104 87
            throw err;
105 88
        }
255 238
        printErrors(output);
256 239
    }
257 240
    verdict(h, c.source, what, reason);
258 241
}
259 242
243 +
/// Directory of the compiler test fixtures.
244 +
export constant TESTS: *[u8] = "test/tests";
245 +
246 +
/// Return the root modules of the Radiance fixtures in [`TESTS`]: its `.rad`
247 +
/// files, and `test.rad` in each of its package directories, which hold
248 +
/// `test.manifest`.
249 +
export fn fixtures(h: &mut Harness) -> *[*[u8]] throws (sys::Error) {
250 +
    let mut result: *mut [*[u8]] = &mut [];
251 +
    try! result.extend(try h.listFiles(TESTS, ".rad"), h.arena);
252 +
    let mut packages: *mut [*[u8]] = &mut [];
253 +
    for path in try h.children(TESTS) {
254 +
        if try harness::exists(h.join(&[path, "/test.manifest"])) {
255 +
            try! packages.append(h.join(&[path, "/test.rad"]), h.arena);
256 +
        }
257 +
    }
258 +
    harness::sort(&mut packages[..]);
259 +
    try! result.extend(&packages[..], h.arena);
260 +
    return &result[..];
261 +
}
262 +
260 263
/// Run the checks of the fixtures: the IL snapshot of each fixture that has
261 264
/// one, the exit status of each that declares one, the stored size of its
262 265
/// read-write data when declared, and the diagnostics of each that must be
263 266
/// rejected. All children run in one batch; results are printed in the order
264 267
/// of the fixtures. With no `tests`, all fixtures in `test/tests` are checked.
273 276
    let mut sources: *mut [*[u8]] = &mut [];
274 277
    for source in tests {
275 278
        try! sources.append(source, h.arena);
276 279
    }
277 280
    if tests.len == 0 {
278 -
        for ext in &[".rad", ".ras"] {
279 -
            for path in try h.listFiles("test/tests", ext) {
280 -
                try! sources.append(path, h.arena);
281 -
            }
282 -
        }
281 +
        try! sources.extend(try fixtures(h), h.arena);
282 +
        try! sources.extend(try h.listFiles(TESTS, ".ras"), h.arena);
283 283
    }
284 284
    let mut cases: *mut [Case] = &mut [];
285 285
    let mut batch: *mut [Command] = &mut [];
286 286
    for source in &sources[..] {
287 287
        let image = h.join(&[harness::stripExt(source), ".rv64"]);
test/integration/fixtures/native_modes/missing_assembly.manifest added +6 -0
1 +
Package {
2 +
    name: "app",
3 +
    version: "1.0.0",
4 +
    dependencies: [{ name: "util", version: "1.0.0" }],
5 +
    assembly: ["missing.ras"],
6 +
}
test/integration/fixtures/native_modes/no_assembly.manifest added +5 -0
1 +
Package {
2 +
    name: "app",
3 +
    version: "1.0.0",
4 +
    dependencies: [{ name: "util", version: "1.0.0" }],
5 +
}
test/integration/harness.rad +43 -2
8 8
use std::io;
9 9
use std::mem;
10 10
use std::process;
11 11
use std::sys;
12 12
use std::lang::alloc;
13 +
use std::lang::ast;
14 +
use std::lang::manifest;
15 +
use std::lang::parser;
16 +
use std::lang::strings;
13 17
use std::mem::heap;
14 18
15 19
/// Capacity of the string arena, in bytes (128 MB). It holds every path,
16 20
/// argument list and file the command reads, and is never reset.
17 21
export constant ARENA_CAPACITY: u32 = 134217728;
292 296
    }
293 297
    sort(&mut found[..]);
294 298
    return &found[..];
295 299
}
296 300
301 +
/// Return the directory part of `path`, or `.` when it has none.
302 +
export fn directory(path: *[u8]) -> *[u8] {
303 +
    let slash = mem::rfind(path, "/") else return ".";
304 +
    return &path[.. slash];
305 +
}
306 +
297 307
/// Return the path without its last extension, or the path itself when it has
298 308
/// none.
299 309
export fn stripExt(path: *[u8]) -> *[u8] {
300 310
    let mut end = path.len;
301 311
    while end > 0 and path[end - 1] <> '.' {
594 604
/// `name`, which may contain `/` to place it in a child module.
595 605
export fn (h: &mut Harness) named(name: *[u8], path: *[u8]) {
596 606
    h.add(&["-mod", h.join(&[name, "=", path])]);
597 607
}
598 608
609 +
/// Directory of the standard library package.
610 +
constant STD_DIR: *[u8] = "lib/std";
611 +
/// Root module of the standard library package.
612 +
constant STD_ROOT: *[u8] = "lib/std/std.rad";
613 +
599 614
/// Add standard library inputs with `extension`, or all inputs when it is empty.
600 615
export fn (h: &mut Harness) addStd(extension: *[u8]) throws (sys::Error) {
601 -
    h.add(&["-pkg", "std"]);
616 +
    h.add(&["-pkg", "std", "-manifest", "seed/dependencies/none"]);
602 617
    for path in try h.manifest("std.lib") {
603 618
        if mem::endsWith(path, extension) {
604 -
            h.add(&["-mod", path]);
619 +
            h.addStdModule(path);
605 620
        }
606 621
    }
607 622
}
608 623
624 +
/// Add the standard library input `path`. Modules after the root are in the
625 +
/// package directory, so each is mapped to its logical path.
626 +
export fn (h: &mut Harness) addStdModule(path: *[u8]) {
627 +
    if mem::eq(path, STD_ROOT) or not mem::endsWith(path, ".rad") {
628 +
        h.add(&["-mod", path]);
629 +
    } else {
630 +
        h.named(&path[STD_DIR.len + 1 .. path.len - ".rad".len], path);
631 +
    }
632 +
}
633 +
634 +
/// Read the standard library package for builds that take explicit module flags.
635 +
export fn (h: &mut Harness) stdPackage() -> manifest::Package throws (sys::Error) {
636 +
    let path = "lib/std/std.manifest";
637 +
    let text = try h.load(path);
638 +
    let mut table: *mut [*[u8]] = &mut [];
639 +
    try table.resize(strings::TABLE_SIZE, "", h.arena) catch {
640 +
        throw sys::Error::TooLarge;
641 +
    };
642 +
    let nodes = ast::NodeArena { heap: h.arena, nextId: 0 };
643 +
    let mut syntax = parser::newParser(nodes, strings::freshPool(table));
644 +
645 +
    return try manifest::read(&mut syntax, path, text, h.arena) catch {
646 +
        throw sys::Error::Invalid;
647 +
    };
648 +
}
649 +
609 650
/// Return a copy of the compiler arguments collected since the last call.
610 651
export fn (h: &mut Harness) take() -> *[*[u8]] {
611 652
    let mut list: *mut [*[u8]] = &mut [];
612 653
    for arg in &h.args[h.taken ..] {
613 654
        try! list.append(arg, h.arena);
test/integration/integration.manifest added +24 -0
1 +
// Integration test driver.
2 +
Package {
3 +
    name: "integration",
4 +
    version: "0.1.0",
5 +
    dependencies: [
6 +
        Dependency { name: "std", version: "0.1.0" },
7 +
    ],
8 +
    modules: [
9 +
        "boot",
10 +
        "fixtures",
11 +
        "format",
12 +
        "harness",
13 +
        "host",
14 +
        "kernel",
15 +
        "linking",
16 +
        "machine",
17 +
        "packages",
18 +
        "verify",
19 +
    ],
20 +
    embed: [
21 +
        "fixtures/native_modes/missing_assembly.manifest",
22 +
        "fixtures/native_modes/no_assembly.manifest",
23 +
    ],
24 +
}
test/integration.rad → test/integration/integration.rad renamed +1 -1
47 47
constant DEFAULT_COMPILER: *[u8] = "bin/radiance.rv64.dev";
48 48
/// Exit status of a command line that cannot be run.
49 49
constant USAGE_STATUS: i32 = 2;
50 50
/// Usage message.
51 51
constant USAGE: *[u8] =
52 -
    "usage: integration <command> [-compiler <path>] [-jobs <n>] [arguments...]\nSee test/integration.rad for the commands.\n";
52 +
    "usage: integration <command> [-compiler <path>] [-jobs <n>] [arguments...]\nSee test/integration/integration.rad for the commands.\n";
53 53
54 54
/// A command, how many arguments it takes, and its handler.
55 55
record Entry: Copy {
56 56
    /// Name given on the command line.
57 57
    name: *[u8],
test/integration/kernel.rad +3 -2
137 137
    boot: &[*[u8]]
138 138
) -> bool throws (sys::Error) {
139 139
    let dir = h.join(&["test/", fixture]);
140 140
    let work = h.work;
141 141
    try h.addStd(".rad");
142 -
    h.add(&["-pkg", "kernel", "-manifest", "test/std.manifest", "-mod", "test/kernel.rad"]);
142 +
    h.add(&["-pkg", "kernel", "-manifest", "seed/dependencies/std", "-mod", "test/kernel.rad"]);
143 143
    for path in try h.listFiles(KERNEL_DIR, ".rad") {
144 144
        let name = &path[KERNEL_DIR.len + 1 .. path.len - ".rad".len];
145 -
        if not mem::eq(name, "tests") {
145 +
        // The fixture replaces the kernel's root module and its tests.
146 +
        if not mem::eq(name, "tests") and not mem::eq(name, "kernel") {
146 147
            h.named(name, path);
147 148
        }
148 149
    }
149 150
    h.named("fixture", "test/kernel/fixture.rad");
150 151
    h.named("dispatchcheck", h.join(&[dir, "/kernel/dispatchcheck.rad"]));
test/integration/packages.rad +233 -1
137 137
fn large(h: &mut Harness) throws (sys::Error) {
138 138
    let root = h.path(&["large"]);
139 139
    h.add(&["-no-cache", "-test"]);
140 140
    try h.addStd(".rad");
141 141
    for path in try h.manifest("std.lib.test") {
142 -
        h.add(&["-mod", path]);
142 +
        h.addStdModule(path);
143 +
    }
144 +
    let standard = try h.stdPackage();
145 +
    for path in standard.embed {
146 +
        h.add(&["-embed", h.join(&["lib/std/", path])]);
143 147
    }
144 148
    let provider = h.path(&["large-provider.rad"]);
145 149
    let client = h.path(&["large-client.rad"]);
146 150
    try fs::writeFile(provider, "export fn value() -> u32 { return 42; }\n");
147 151
    try fs::writeFile(
540 544
    if h.compile("read the replacement package", h.out(&["read-replacement.log"])) {
541 545
        execute(h, image);
542 546
    }
543 547
}
544 548
549 +
/// Reject the compilation of the package in `directory` with `flags`, and
550 +
/// require `message` in the compiler output.
551 +
fn rejectPackage(
552 +
    h: &mut Harness, what: *[u8], flags: &[*[u8]], directory: *[u8], message: *[u8]
553 +
) {
554 +
    h.add(&["-no-cache"]);
555 +
    h.add(flags);
556 +
    h.add(&[directory]);
557 +
    let command = h.cc(h.take(), h.out(&["manifest-rejected.log"]));
558 +
    h.run(what, command, process::Outcome::Exited(1), &[harness::Expect::Contains(message)]);
559 +
}
560 +
561 +
/// Package directories of the manifest checks.
562 +
constant MANIFESTS: *[u8] = "test/manifests";
563 +
564 +
/// Build the packages in [`MANIFESTS`]: listed modules, dependencies found by
565 +
/// name and version in the library directory of a parent, in `-lib`
566 +
/// directories and with `-dep`, compiled libraries, single modules, and
567 +
/// rejected graphs.
568 +
fn manifests(h: &mut Harness) throws (sys::Error) {
569 +
    let lib = h.join(&[MANIFESTS, "/lib"]);
570 +
    let app = h.join(&[MANIFESTS, "/app"]);
571 +
    let image = h.path(&["manifest-app.rv64"]);
572 +
    h.add(&["-no-cache", app, "-o", image]);
573 +
    if not h.compile("find a library in the lib directory of a parent", h.out(&["manifest.log"])) {
574 +
        return;
575 +
    }
576 +
    execute(h, image);
577 +
    let exported = h.path(&["manifest-exported"]);
578 +
    h.add(&["-no-cache", app, "-ril", exported]);
579 +
    if not h.compile("export a package graph", h.out(&["manifest-export.log"])) {
580 +
        return;
581 +
    }
582 +
    let linked = h.path(&["manifest-linked.rv64"]);
583 +
    h.add(&["-no-cache", "-lib", exported, app, "-o", linked]);
584 +
    if not h.compile("find a compiled library with -lib first", h.out(&["manifest-lib.log"])) {
585 +
        return;
586 +
    }
587 +
    h.expect(
588 +
        "compiled library is not parsed",
589 +
        h.path(&["manifest-lib.log"]),
590 +
        harness::Expect::Matching {
591 +
            text: "util: parsing", count: 0
592 +
        }
593 +
    );
594 +
    execute(h, linked);
595 +
    let facade = h.join(&[lib, "/facade"]);
596 +
    let bridge = h.join(&[MANIFESTS, "/bridge"]);
597 +
    let separate = h.path(&["manifest-separate"]);
598 +
    h.add(&["-no-cache", facade, "-ril", separate]);
599 +
    if not h.compile("export a package with a dependency", h.out(&["manifest-facade.log"])) {
600 +
        return;
601 +
    }
602 +
    let moved = h.join(&[separate, "/renamed"]);
603 +
    try fs::rename(h.join(&[separate, "/util"]), moved);
604 +
    h.add(&["-no-cache", "-lib", separate, "-lib", exported, bridge, "-o", linked]);
605 +
    let transitiveLib = h.out(&["manifest-transitive-lib.log"]);
606 +
    if h.compile("find a compiled package's provider in the next -lib", transitiveLib) {
607 +
        h.expect(
608 +
            "use the compiled provider from -lib",
609 +
            h.path(&["manifest-transitive-lib.log"]),
610 +
            harness::Expect::Matching { text: "util: parsing", count: 0 }
611 +
        );
612 +
        execute(h, linked);
613 +
    }
614 +
    h.add(&[
615 +
        "-no-cache", "-lib", separate, "-dep", h.join(&["util=", moved]), bridge, "-o", linked
616 +
    ]);
617 +
    let transitiveDep = h.out(&["manifest-transitive-dep.log"]);
618 +
    if h.compile("override a compiled package's provider with -dep", transitiveDep) {
619 +
        h.expect(
620 +
            "use the renamed compiled provider from -dep",
621 +
            h.path(&["manifest-transitive-dep.log"]),
622 +
            harness::Expect::Matching { text: "util: parsing", count: 0 }
623 +
        );
624 +
        execute(h, linked);
625 +
    }
626 +
    h.add(&["-no-cache", app, "-dump", "il"]);
627 +
    if h.compile("dump IL for a manifest dependency graph", h.out(&["manifest-il.log"])) {
628 +
        h.expect(
629 +
            "dump includes dependency IL",
630 +
            h.path(&["manifest-il.log"]),
631 +
            harness::Expect::Contains("util::answer")
632 +
        );
633 +
    }
634 +
    h.add(&["-no-cache", app, "-dump", "asm"]);
635 +
    if h.compile("dump assembly for a manifest dependency graph", h.out(&["manifest-asm.log"])) {
636 +
        h.expect(
637 +
            "dump includes dependency assembly",
638 +
            h.path(&["manifest-asm.log"]),
639 +
            harness::Expect::Contains("util::answer")
640 +
        );
641 +
    }
642 +
    h.add(&["-no-cache", "test/tests/asm.link", "-dump", "asm"]);
643 +
    if h.compile("dump linked assembly", h.out(&["manifest-native.log"])) {
644 +
        h.expect(
645 +
            "dump includes the assembly symbol",
646 +
            h.path(&["manifest-native.log"]),
647 +
            harness::Expect::Contains("test::asmAddOne")
648 +
        );
649 +
    }
650 +
    rejectPackage(
651 +
        h,
652 +
        "reject an incompatible compiled package",
653 +
        &["-lib", exported],
654 +
        h.join(&[MANIFESTS, "/newer"]),
655 +
        "requires util version 1.3.0"
656 +
    );
657 +
    let unversioned = h.path(&["unversioned"]);
658 +
    h.add(&["-no-cache", "-name", "util", h.join(&[lib, "/util/text.rad"]), "-ril", unversioned]);
659 +
    if not h.compile("export a single module", h.out(&["unversioned.log"])) {
660 +
        return;
661 +
    }
662 +
    rejectPackage(
663 +
        h,
664 +
        "reject a provider without the required version",
665 +
        &["-lib", unversioned],
666 +
        app,
667 +
        "has no version"
668 +
    );
669 +
    let wrongUtil = h.join(&["util=", unversioned, "/util"]);
670 +
    rejectPackage(
671 +
        h,
672 +
        "verify compiled dependency pins with an override",
673 +
        &["-lib", separate, "-lib", exported, "-dep", wrongUtil],
674 +
        bridge,
675 +
        "package dependency artifact mismatch util"
676 +
    );
677 +
    let pinned = h.path(&["manifest-pinned.rv64"]);
678 +
    h.add(&["-no-cache", "-dep", h.join(&["util=", exported, "/util"]), app, "-o", pinned]);
679 +
    if not h.compile("select a compiled library with -dep", h.out(&["manifest-dep.log"])) {
680 +
        return;
681 +
    }
682 +
    h.expect(
683 +
        "selected library is not parsed",
684 +
        h.path(&["manifest-dep.log"]),
685 +
        harness::Expect::Matching {
686 +
            text: "util: parsing", count: 0
687 +
        }
688 +
    );
689 +
    execute(h, pinned);
690 +
    let single = h.path(&["manifest-single.rv64"]);
691 +
    h.add(&["-no-cache", h.join(&[app, "/other.rad"]), "-o", single]);
692 +
    if not h.compile("compile one module that imports a library", h.out(&["manifest-single.log"])) {
693 +
        return;
694 +
    }
695 +
    execute(h, single);
696 +
    let client = h.join(&[MANIFESTS, "/client"]);
697 +
    rejectPackage(h, "reject a package that is not found", &[], client, "package other not found");
698 +
    rejectPackage(
699 +
        h,
700 +
        "reject an incompatible version",
701 +
        &[],
702 +
        h.join(&[MANIFESTS, "/newer"]),
703 +
        "requires util version 1.3.0"
704 +
    );
705 +
    rejectPackage(
706 +
        h,
707 +
        "reject an undeclared listed module",
708 +
        &[],
709 +
        h.join(&[MANIFESTS, "/loose"]),
710 +
        "is not declared by its parent"
711 +
    );
712 +
    let wrong: [*[u8]; 2] = ["-lib", h.join(&[MANIFESTS, "/wrong"])];
713 +
    rejectPackage(
714 +
        h, "reject a manifest named after another package", &wrong[..], client, "must be named"
715 +
    );
716 +
    rejectPackage(h, "reject a dependency cycle", &[], h.join(&[lib, "/cycle"]), "cyclic");
717 +
    let unused: [*[u8]; 2] = ["-dep", h.join(&["other=", MANIFESTS, "/wrong/other"])];
718 +
    rejectPackage(h, "reject -dep for no dependency", &unused[..], app, "names no dependency");
719 +
    rejectPackage(
720 +
        h, "reject a package directory with -pkg", &["-pkg", "x"], app, "cannot be combined"
721 +
    );
722 +
    let native = h.join(&[exported, "/util/native/"]);
723 +
    try fs::writeFile(h.join(&[native, "extra.ras"]), "");
724 +
    rejectPackage(
725 +
        h,
726 +
        "reject an unexpected native file",
727 +
        &["-lib", exported, "-o", pinned],
728 +
        app,
729 +
        "invalid native assembly filename extra.ras"
730 +
    );
731 +
    try fs::remove(h.join(&[native, "extra.ras"]));
732 +
    try fs::rename(h.join(&[native, "0.ras"]), h.join(&[native, "1.ras"]));
733 +
    rejectPackage(
734 +
        h,
735 +
        "reject a missing assembly index",
736 +
        &["-lib", exported, "-o", pinned],
737 +
        app,
738 +
        "native assembly indices must be consecutive from zero"
739 +
    );
740 +
}
741 +
742 +
/// Read native manifest inputs only for the requested output.
743 +
fn manifestNativeModes(h: &mut Harness) throws (sys::Error) {
744 +
    let root = h.path(&["manifest-native-modes"]);
745 +
    let app = h.join(&[root, "/app"]);
746 +
    let dependency = h.join(&[root, "/lib/util"]);
747 +
    try harness::makeDirs(app);
748 +
    try harness::makeDirs(dependency);
749 +
    let manifest = h.join(&[app, "/app.manifest"]);
750 +
    try fs::writeFile(manifest, @embed("fixtures/native_modes/missing_assembly.manifest"));
751 +
    try fs::writeFile(
752 +
        h.join(&[app, "/app.rad"]),
753 +
        "use util; @default fn main() -> u32 { assert util::answer() == 42; return 0; }\n"
754 +
    );
755 +
    try fs::writeFile(
756 +
        h.join(&[dependency, "/util.manifest"]),
757 +
        "Package { name: \"util\", version: \"1.0.0\", startup: \"missing.ras\" }\n"
758 +
    );
759 +
    try fs::writeFile(
760 +
        h.join(&[dependency, "/util.rad"]), "export fn answer() -> u32 { return 42; }\n"
761 +
    );
762 +
    let unused = h.join(&[root, "/unused.rv64"]);
763 +
    h.add(&["-no-cache", app, "-dump", "il", "-o", unused]);
764 +
    if h.compile("dump IL without reading native files", h.out(&["manifest-il-only.log"])) {
765 +
        h.expect("IL dump produces no executable", unused, harness::Expect::Absent);
766 +
    }
767 +
    try fs::writeFile(manifest, @embed("fixtures/native_modes/no_assembly.manifest"));
768 +
    let image = h.join(&[root, "/app.rv64"]);
769 +
    h.add(&["-no-cache", app, "-o", image]);
770 +
    if h.compile("link without reading dependency startup", h.out(&["manifest-start.log"])) {
771 +
        execute(h, image);
772 +
    }
773 +
}
774 +
545 775
/// Print the compiler identity.
546 776
fn version(h: &mut Harness) {
547 777
    h.add(&["-version"]);
548 778
    h.compile("print the compiler identity", h.out(&["compiler-version.log"]));
549 779
    h.expect(
779 1009
    source(h, exported, "-ril");
780 1010
    if not h.compile("export complete package closure", h.out(&["export.log"])) {
781 1011
        return;
782 1012
    }
783 1013
    try nativeInputs(h);
1014 +
    try manifests(h);
1015 +
    try manifestNativeModes(h);
784 1016
    try compilerImage(h, exported);
785 1017
    version(h);
786 1018
    try integrity(h, exported);
787 1019
    let declarations = h.join(&[exported, "/dep/interface/dep.rid"]);
788 1020
    h.expect("interface omits implementation helpers", declarations, harness::Expect::Matching {
test/integration/verify.rad +18 -9
40 40
    try! table.resize(strings::TABLE_SIZE, "", h.arena);
41 41
    let mut pool = strings::freshPool(table);
42 42
    for item in rejected {
43 43
        let end = mem::find(item, " ") else panic "checkSafeRejections: no verdict";
44 44
        let name = &item[.. end];
45 -
        let source = try h.load(h.join(&["test/tests/", name, ".rad"]));
45 +
        // A package fixture's root module is `test.rad` in its directory.
46 +
        let mut path = h.join(&["test/tests/", name, ".rad"]);
47 +
        if not try harness::exists(path) {
48 +
            set path = h.join(&["test/tests/", name, "/test.rad"]);
49 +
        }
50 +
        let source = try h.load(path);
46 51
        if harness::marker(source, "//! uses-std") <> nil or usesUnsafe(source, &mut pool) {
47 52
            continue;
48 53
        }
49 54
        h.fail("verify", h.join(&["safe fixture fails verification: ", item]));
50 55
    }
88 93
    try h.begin("verify");
89 94
    let mut checker: *[u8] = "test/verify/check.rv64";
90 95
    if args.len == 1 {
91 96
        set checker = args[0];
92 97
    }
93 -
    // Native assembly inputs cannot be emitted as binary IL.
94 98
    let mut names: *mut [*[u8]] = &mut [];
95 99
    let mut batch: *mut [Command] = &mut [];
96 -
    for source in try h.listFiles("test/tests", ".rad") {
97 -
        let base = harness::stripExt(source);
98 -
        if try harness::exists(h.join(&[base, ".ras"]))
99 -
            or try harness::exists(h.join(&[base, ".start.ras"]))
100 -
        {
101 -
            continue;
100 +
    for source in try fixtures::fixtures(h) {
101 +
        // A package fixture's name is its directory.
102 +
        let mut base = harness::stripExt(source);
103 +
        let directory = harness::directory(source);
104 +
        if try harness::exists(h.join(&[directory, "/test.manifest"])) {
105 +
            set base = directory;
106 +
            // Native assembly inputs cannot be emitted as binary IL.
107 +
            let assembly = try h.listFiles(directory, ".ras");
108 +
            if assembly.len > 0 {
109 +
                continue;
110 +
            }
102 111
        }
112 +
        let name = &base["test/tests/".len ..];
103 113
        // Rejection fixtures produce no IL.
104 114
        if harness::marker(try h.load(source), fixtures::REJECTS) <> nil {
105 115
            continue;
106 116
        }
107 -
        let name = &base["test/tests/".len ..];
108 117
        try fixtures::prepare(h, source, h.path(&[name]));
109 118
        try! batch.append(h.cc(h.take(), h.out(&[name, ".log"])), h.arena);
110 119
        try! names.append(name, h.arena);
111 120
    }
112 121
    let outcomes = h.runAll(&batch[..]);
test/manifests/app/app.manifest added +8 -0
1 +
// Program that uses the library `util` from the lib directory of its parent.
2 +
Package {
3 +
    name: "app",
4 +
    version: "0.1.0",
5 +
    dependencies: [
6 +
        Dependency { name: "util", version: "1.1.0" },
7 +
    ],
8 +
}
test/manifests/app/app.rad added +6 -0
1 +
use util;
2 +
3 +
@default fn main() -> u32 {
4 +
    assert util::answer() == 42;
5 +
    return 0;
6 +
}
test/manifests/app/other.rad added +6 -0
1 +
use util;
2 +
3 +
@default fn main() -> u32 {
4 +
    assert util::answer() == 42;
5 +
    return 0;
6 +
}
test/manifests/bridge/bridge.manifest added +7 -0
1 +
Package {
2 +
    name: "bridge",
3 +
    version: "1.0.0",
4 +
    dependencies: [
5 +
        Dependency { name: "facade", version: "1.0.0" },
6 +
    ],
7 +
}
test/manifests/bridge/bridge.rad added +9 -0
1 +
//! Program that calls a library with its own dependency.
2 +
3 +
use facade;
4 +
5 +
/// Check that the library returns its provider's answer.
6 +
@default fn main() -> u32 {
7 +
    assert facade::answer() == 42;
8 +
    return 0;
9 +
}
test/manifests/client/client.manifest added +8 -0
1 +
// Requires `other`, which the library directory `wrong` holds under the wrong name.
2 +
Package {
3 +
    name: "client",
4 +
    version: "0.1.0",
5 +
    dependencies: [
6 +
        Dependency { name: "other", version: "1.0.0" },
7 +
    ],
8 +
}
test/manifests/lib/back/back.manifest added +8 -0
1 +
// Depends on `cycle`, which depends on `back`.
2 +
Package {
3 +
    name: "back",
4 +
    version: "0.1.0",
5 +
    dependencies: [
6 +
        Dependency { name: "cycle", version: "0.1.0" },
7 +
    ],
8 +
}
test/manifests/lib/back/back.rad added +4 -0
1 +
/// Return one.
2 +
export fn one() -> u32 {
3 +
    return 1;
4 +
}
test/manifests/lib/cycle/cycle.manifest added +8 -0
1 +
// Depends on `back`, which depends on `cycle`.
2 +
Package {
3 +
    name: "cycle",
4 +
    version: "0.1.0",
5 +
    dependencies: [
6 +
        Dependency { name: "back", version: "0.1.0" },
7 +
    ],
8 +
}
test/manifests/lib/cycle/cycle.rad added +4 -0
1 +
/// Return one.
2 +
export fn one() -> u32 {
3 +
    return 1;
4 +
}
test/manifests/lib/facade/facade.manifest added +7 -0
1 +
Package {
2 +
    name: "facade",
3 +
    version: "1.0.0",
4 +
    dependencies: [
5 +
        Dependency { name: "util", version: "1.1.0" },
6 +
    ],
7 +
}
test/manifests/lib/facade/facade.rad added +8 -0
1 +
//! Library with a dependency that provides its answer.
2 +
3 +
use util;
4 +
5 +
/// Return the provider's answer.
6 +
export fn answer() -> u32 {
7 +
    return util::answer();
8 +
}
test/manifests/lib/util/forty.ras added +5 -0
1 +
.text;
2 +
.export @"util::forty";
3 +
@"util::forty"
4 +
    li %a0 40;
5 +
    ret;
test/manifests/lib/util/text.rad added +4 -0
1 +
/// Return two.
2 +
export fn two() -> u32 {
3 +
    return 2;
4 +
}
test/manifests/lib/util/util.manifest added +7 -0
1 +
// Library with one listed module.
2 +
Package {
3 +
    name: "util",
4 +
    version: "1.2.0",
5 +
    modules: ["text"],
6 +
    assembly: ["forty.ras"],
7 +
}
test/manifests/lib/util/util.rad added +9 -0
1 +
mod text;
2 +
3 +
/// Return forty in a native program.
4 +
fn forty() -> u32;
5 +
6 +
/// Return the answer.
7 +
export fn answer() -> u32 {
8 +
    return forty() + text::two();
9 +
}
test/manifests/loose/loose.manifest added +6 -0
1 +
// Lists a module that the root module does not declare.
2 +
Package {
3 +
    name: "loose",
4 +
    version: "1.0.0",
5 +
    modules: ["text"],
6 +
}
test/manifests/loose/loose.rad added +4 -0
1 +
/// Return one.
2 +
export fn one() -> u32 {
3 +
    return 1;
4 +
}
test/manifests/loose/text.rad added +4 -0
1 +
/// Return two.
2 +
fn two() -> u32 {
3 +
    return 2;
4 +
}
test/manifests/newer/newer.manifest added +8 -0
1 +
// Requires a newer `util` than the library directory holds.
2 +
Package {
3 +
    name: "newer",
4 +
    version: "0.1.0",
5 +
    dependencies: [
6 +
        Dependency { name: "util", version: "1.3.0" },
7 +
    ],
8 +
}
test/manifests/newer/newer.rad added +5 -0
1 +
//! Entry for the package version checks.
2 +
3 +
@default fn main() -> u32 {
4 +
    return 0;
5 +
}
test/manifests/wrong/other/other.manifest added +5 -0
1 +
// Describes `util` but is named after the package `other`.
2 +
Package {
3 +
    name: "util",
4 +
    version: "1.2.0",
5 +
}
test/std.manifest deleted +0 -1
1 -
std
test/tests/asm.link.ras → test/tests/asm.link/asm.link.ras renamed +0 -0
test/tests/asm.link/test.manifest added +6 -0
1 +
// Fixture package `asm.link`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    assembly: ["asm.link.ras"],
6 +
}
test/tests/asm.link.rad → test/tests/asm.link/test.rad renamed +0 -0
test/tests/asm.rodata.prefix.ras → test/tests/asm.rodata.prefix/asm.rodata.prefix.ras renamed +0 -0
test/tests/asm.rodata.prefix/test.manifest added +6 -0
1 +
// Fixture package `asm.rodata.prefix`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    assembly: ["asm.rodata.prefix.ras"],
6 +
}
test/tests/asm.rodata.prefix.rad → test/tests/asm.rodata.prefix/test.rad renamed +0 -0
test/tests/assign.qualified.static/test.manifest added +6 -0
1 +
// Fixture package `assign.qualified.static`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    modules: ["storage"],
6 +
}
test/tests/assign.qualified.static.rad → test/tests/assign.qualified.static/test.rad renamed +0 -0
test/tests/entry.storage.start.start.ras → test/tests/entry.storage.start/entry.storage.start.start.ras renamed +0 -0
test/tests/entry.storage.start/test.manifest added +6 -0
1 +
// Fixture package `entry.storage.start`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    startup: "entry.storage.start.start.ras",
6 +
}
test/tests/entry.storage.start.rad → test/tests/entry.storage.start/test.rad renamed +0 -0
test/tests/fn.unsafe.callbacks/test.manifest added +6 -0
1 +
// Fixture package `fn.unsafe.callbacks`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    modules: ["operations"],
6 +
}
test/tests/fn.unsafe.callbacks.rad → test/tests/fn.unsafe.callbacks/test.rad renamed +0 -0
test/tests/method.module/test.manifest added +6 -0
1 +
// Fixture package `method.module`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    modules: ["counter"],
6 +
}
test/tests/method.module.rad → test/tests/method.module/test.rad renamed +0 -0
test/tests/optional.union.const.match/test.manifest added +6 -0
1 +
// Fixture package `optional.union.const.match`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    modules: ["consts"],
6 +
}
test/tests/optional.union.const.match.rad → test/tests/optional.union.const.match/test.rad renamed +0 -0
test/tests/record.opaque/test.manifest added +6 -0
1 +
// Fixture package `record.opaque`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    modules: ["model"],
6 +
}
test/tests/record.opaque.rad → test/tests/record.opaque/test.rad renamed +0 -0
test/tests/ref.qualified.static/test.manifest added +6 -0
1 +
// Fixture package `ref.qualified.static`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    modules: ["storage"],
6 +
}
test/tests/ref.qualified.static.rad → test/tests/ref.qualified.static/test.rad renamed +0 -0
test/tests/return.never.ras → test/tests/return.never/return.never.ras renamed +0 -0
test/tests/return.never/test.manifest added +6 -0
1 +
// Fixture package `return.never`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    assembly: ["return.never.ras"],
6 +
}
test/tests/return.never.rad → test/tests/return.never/test.rad renamed +0 -0
test/tests/stack.limit.ok.start.ras → test/tests/stack.limit.ok/stack.limit.ok.start.ras renamed +0 -0
test/tests/stack.limit.ok/test.manifest added +6 -0
1 +
// Fixture package `stack.limit.ok`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    startup: "stack.limit.ok.start.ras",
6 +
}
test/tests/stack.limit.ok.rad → test/tests/stack.limit.ok/test.rad renamed +0 -0
test/tests/stack.limit.trap.start.ras → test/tests/stack.limit.trap/stack.limit.trap.start.ras renamed +0 -0
test/tests/stack.limit.trap/test.manifest added +6 -0
1 +
// Fixture package `stack.limit.trap`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    startup: "stack.limit.trap.start.ras",
6 +
}
test/tests/stack.limit.trap.rad → test/tests/stack.limit.trap/test.rad renamed +0 -0
test/tests/start.default.start.ras → test/tests/start.default/start.default.start.ras renamed +0 -0
test/tests/start.default/test.manifest added +6 -0
1 +
// Fixture package `start.default`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    startup: "start.default.start.ras",
6 +
}
test/tests/start.default.rad → test/tests/start.default/test.rad renamed +0 -0
test/tests/start.exit.start.ras → test/tests/start.exit/start.exit.start.ras renamed +0 -0
test/tests/start.exit/test.manifest added +6 -0
1 +
// Fixture package `start.exit`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    startup: "start.exit.start.ras",
6 +
}
test/tests/start.exit.rad → test/tests/start.exit/test.rad renamed +0 -0
test/tests/wildcard.import.owner/test.manifest added +6 -0
1 +
// Fixture package `wildcard.import.owner`.
2 +
Package {
3 +
    name: "test",
4 +
    version: "0.1.0",
5 +
    modules: ["wildcard_import_owner"],
6 +
}
test/tests/wildcard.import.owner.rad → test/tests/wildcard.import.owner/test.rad renamed +0 -0