cli: add explicit package source modules
Link manifest-selected source graphs with module-local names, qualified structs/enums/functions and task workers through ordinary AIR verification. Keep source inputs bounded, reject source symlinks and preserve explicit grants, diagnostics and deterministic canonical lowering. Integrate spec 12/15, RFC 0021, source reference budgets, roadmap, examples and CI coverage. Validate 579 conformance tests, unit tests, 76 source constructs, hosted smoke, 36 package CLI checks and task schedule stress.
This commit is contained in:
81 files changed
+1419
-234
No files matched your search
+75
-65
@@ -17,10 +17,10 @@ const usage =
|
||||
\\usage: aji <command> [args]
|
||||
\\
|
||||
\\commands:
|
||||
\\ check [--report unsafe] <file.air>
|
||||
\\ check [--report unsafe] <file.air | file.aji | --manifest aji.toml>
|
||||
\\ parse and verify a text AIR module; the unsafe report
|
||||
\\ lists trusted boundaries and unsafe operations
|
||||
\\ run [--fuel N] [--grant P=KIND[:SCOPE]]... <file.air | --manifest aji.toml>
|
||||
\\ run [--fuel N] [--grant P=KIND[:SCOPE]]... <file.air | file.aji | --manifest aji.toml>
|
||||
\\ verify, then run @main and print the run record;
|
||||
\\ --fuel stops after N executed instructions;
|
||||
\\ --grant binds capability parameter P of @main
|
||||
@@ -29,16 +29,16 @@ const usage =
|
||||
\\ --seed N; scheduler: --quantum N, --task-limit N,
|
||||
\\ --schedule-seed N; --profile hosted uses the real OS and
|
||||
\\ writes the record only to --result-file PATH
|
||||
\\ lower [--annotate | --stats] <file.aji>
|
||||
\\ lower [--annotate | --stats] <file.aji | --manifest aji.toml>
|
||||
\\ print the canonical AIR a source module lowers to;
|
||||
\\ --annotate adds source spans as comments (not canonical);
|
||||
\\ --stats prints source/AIR size and expansion ratio
|
||||
\\ explore [--max-runs N] [--grant P=KIND[:SCOPE]]... <file.air | file.aji>
|
||||
\\ explore [--max-runs N] [--grant P=KIND[:SCOPE]]... <file.air | file.aji | --manifest aji.toml>
|
||||
\\ run @main under every schedule and weak-memory choice
|
||||
\\ (depth first, up to N runs, default 100000) and print the
|
||||
\\ distinct outcomes; "complete" is true when the whole
|
||||
\\ choice tree was explored (spec 04 §20.5)
|
||||
\\ report <file.air> verify, then print the audit report (spec 10 §6.1)
|
||||
\\ report <file.air | file.aji | --manifest aji.toml> verify, then print the audit report (spec 10 §6.1)
|
||||
\\ codes list diagnostic codes as JSON Lines
|
||||
\\ features print supported AIR format, language version and features
|
||||
\\ explain <code> show one diagnostic code
|
||||
@@ -76,32 +76,43 @@ fn run(io: std.Io, arena: std.mem.Allocator, args: []const [:0]const u8, out: *s
|
||||
return .accepted;
|
||||
}
|
||||
if (std.mem.eql(u8, cmd, "report")) {
|
||||
if (args.len != 3) return usageError("report takes exactly one file");
|
||||
const path = args[2];
|
||||
const source = std.Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(64 << 20)) catch |err| {
|
||||
std.debug.print("aji: cannot read {s}: {t}\n", .{ path, err });
|
||||
return .usage;
|
||||
};
|
||||
const result = try aji.check.checkAir(arena, path, source);
|
||||
const from_manifest = args.len == 4 and std.mem.eql(u8, args[2], "--manifest");
|
||||
if (args.len != 3 and !from_manifest) return usageError("report takes a file or --manifest PATH");
|
||||
const input = try readInput(arena, io, args[args.len - 1], from_manifest) orelse return .usage;
|
||||
const result = try aji.check.checkWithModules(arena, input.path, input.source, input.modules);
|
||||
for (result.diagnostics) |d| {
|
||||
try d.writeJson(out);
|
||||
try out.writeByte('\n');
|
||||
}
|
||||
if (result.status == .unimplemented) return .unimplemented;
|
||||
const module = result.module orelse return .rejected;
|
||||
try aji.report.write(arena, module, out);
|
||||
try out.writeByte('\n');
|
||||
return .accepted;
|
||||
}
|
||||
if (std.mem.eql(u8, cmd, "lower")) {
|
||||
const annotate = args.len == 4 and std.mem.eql(u8, args[2], "--annotate");
|
||||
const stats = args.len == 4 and std.mem.eql(u8, args[2], "--stats");
|
||||
if (args.len != 3 and !annotate and !stats) return usageError("lower takes [--annotate | --stats] and one .aji file");
|
||||
const path = args[args.len - 1];
|
||||
const source = std.Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(64 << 20)) catch |err| {
|
||||
std.debug.print("aji: cannot read {s}: {t}\n", .{ path, err });
|
||||
return .usage;
|
||||
};
|
||||
switch (try aji.frontend.compile(arena, path, source)) {
|
||||
var annotate = false;
|
||||
var stats = false;
|
||||
var manifest_path: ?[]const u8 = null;
|
||||
var rest = args[2..];
|
||||
while (rest.len != 0) {
|
||||
if (std.mem.eql(u8, rest[0], "--annotate") and !annotate and !stats) {
|
||||
annotate = true;
|
||||
rest = rest[1..];
|
||||
} else if (std.mem.eql(u8, rest[0], "--stats") and !annotate and !stats) {
|
||||
stats = true;
|
||||
rest = rest[1..];
|
||||
} else if (std.mem.eql(u8, rest[0], "--manifest") and rest.len >= 2 and manifest_path == null) {
|
||||
manifest_path = rest[1];
|
||||
rest = rest[2..];
|
||||
} else break;
|
||||
}
|
||||
if ((manifest_path != null and rest.len != 0) or (manifest_path == null and rest.len != 1)) return usageError("lower takes [--annotate | --stats] and a file or --manifest PATH");
|
||||
const input = try readInput(arena, io, manifest_path orelse rest[0], manifest_path != null) orelse return .usage;
|
||||
const path = input.path;
|
||||
const source = input.source;
|
||||
if (manifest_path != null and !std.mem.endsWith(u8, path, ".aji")) return usageError("lower requires a .aji entry");
|
||||
switch (try aji.frontend.compileWithModules(arena, path, source, input.modules)) {
|
||||
.ok => |o| {
|
||||
if (stats) {
|
||||
// How much mechanical work the frontend took over.
|
||||
@@ -190,12 +201,16 @@ fn run(io: std.Io, arena: std.mem.Allocator, args: []const [:0]const u8, out: *s
|
||||
var result_file: ?[]const u8 = null;
|
||||
var rest = args[2..];
|
||||
var unsafe_report = false;
|
||||
if (std.mem.eql(u8, cmd, "check") and rest.len == 3 and std.mem.eql(u8, rest[0], "--report")) {
|
||||
if (std.mem.eql(u8, cmd, "check") and rest.len >= 3 and std.mem.eql(u8, rest[0], "--report")) {
|
||||
if (!std.mem.eql(u8, rest[1], "unsafe")) return usageError("--report takes unsafe");
|
||||
unsafe_report = true;
|
||||
rest = rest[2..];
|
||||
}
|
||||
var manifest_path: ?[]const u8 = null;
|
||||
if (std.mem.eql(u8, cmd, "check") and rest.len >= 2 and std.mem.eql(u8, rest[0], "--manifest")) {
|
||||
manifest_path = rest[1];
|
||||
rest = rest[2..];
|
||||
}
|
||||
while (std.mem.eql(u8, cmd, "run") and rest.len >= 2) {
|
||||
const flag = rest[0];
|
||||
const value = rest[1];
|
||||
@@ -229,46 +244,18 @@ fn run(io: std.Io, arena: std.mem.Allocator, args: []const [:0]const u8, out: *s
|
||||
rest = rest[2..];
|
||||
}
|
||||
options.world.files = files.items;
|
||||
var path: []const u8 = undefined;
|
||||
var input: aji.source_package.Input = undefined;
|
||||
if (manifest_path) |mp| {
|
||||
// spec 12 §1.2: the module is the manifest's entry; its grants
|
||||
// are applied, each replaced by a --grant for the same parameter.
|
||||
if (rest.len != 0) return usageError("a file argument cannot be combined with --manifest");
|
||||
const text = std.Io.Dir.cwd().readFileAlloc(io, mp, arena, .limited(1 << 20)) catch |err| {
|
||||
std.debug.print("aji: cannot read {s}: {t}\n", .{ mp, err });
|
||||
return .usage;
|
||||
};
|
||||
const m = switch (try aji.manifest.parse(arena, text)) {
|
||||
.ok => |m| m,
|
||||
.err => |e| {
|
||||
std.debug.print("aji: manifest {s}:{d}: {s}\n", .{ mp, e.line, e.message });
|
||||
return .usage;
|
||||
},
|
||||
};
|
||||
const entry = m.entry orelse {
|
||||
std.debug.print("aji: manifest {s}: [package] entry is required for aji run\n", .{mp});
|
||||
return .usage;
|
||||
};
|
||||
path = try std.fs.path.join(arena, &.{ std.fs.path.dirname(mp) orelse ".", entry });
|
||||
var merged: std.ArrayList(aji.interp.Grant) = .empty;
|
||||
for (m.grants) |g| {
|
||||
const overridden = for (grants.items) |cg| {
|
||||
if (std.mem.eql(u8, cg.parameter, g.parameter)) break true;
|
||||
} else false;
|
||||
if (!overridden) try merged.append(arena, .{ .parameter = g.parameter, .kind = g.kind, .scope = g.scope });
|
||||
}
|
||||
try merged.appendSlice(arena, grants.items);
|
||||
options.grants = merged.items;
|
||||
input = try readInput(arena, io, mp, true) orelse return .usage;
|
||||
options.grants = try mergeGrants(arena, input.grants, grants.items);
|
||||
} else {
|
||||
if (rest.len != 1) return usageError("check and run take exactly one file");
|
||||
path = rest[0];
|
||||
if (rest.len != 1) return usageError("check and run take a file or --manifest PATH");
|
||||
input = try readInput(arena, io, rest[0], false) orelse return .usage;
|
||||
options.grants = grants.items;
|
||||
}
|
||||
const source = std.Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(64 << 20)) catch |err| {
|
||||
std.debug.print("aji: cannot read {s}: {t}\n", .{ path, err });
|
||||
return .usage;
|
||||
};
|
||||
const report = try aji.check.checkFile(arena, path, source);
|
||||
const path = input.path;
|
||||
const report = try aji.check.checkWithModules(arena, path, input.source, input.modules);
|
||||
for (report.diagnostics) |d| {
|
||||
try d.writeJson(out);
|
||||
try out.writeByte('\n');
|
||||
@@ -335,21 +322,22 @@ fn explore(arena: std.mem.Allocator, io: std.Io, argv: []const []const u8, out:
|
||||
var max_runs: u64 = 100_000;
|
||||
var grants: std.ArrayList(aji.interp.Grant) = .empty;
|
||||
var rest = argv;
|
||||
var manifest_path: ?[]const u8 = null;
|
||||
while (rest.len >= 2) {
|
||||
if (std.mem.eql(u8, rest[0], "--max-runs")) {
|
||||
max_runs = std.fmt.parseInt(u64, rest[1], 10) catch return usageError("--max-runs takes a positive integer");
|
||||
} else if (std.mem.eql(u8, rest[0], "--grant")) {
|
||||
try grants.append(arena, parseGrant(rest[1]) orelse return usageError("--grant takes <parameter>=<kind>[:<scope>]"));
|
||||
} else if (std.mem.eql(u8, rest[0], "--manifest") and manifest_path == null) {
|
||||
manifest_path = rest[1];
|
||||
} else break;
|
||||
rest = rest[2..];
|
||||
}
|
||||
if (rest.len != 1) return usageError("explore takes exactly one file");
|
||||
const path = rest[0];
|
||||
const source = std.Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(64 << 20)) catch |err| {
|
||||
std.debug.print("aji: cannot read {s}: {t}\n", .{ path, err });
|
||||
return .usage;
|
||||
};
|
||||
const report = try aji.check.checkFile(arena, path, source);
|
||||
if ((manifest_path != null and rest.len != 0) or (manifest_path == null and rest.len != 1)) return usageError("explore takes a file or --manifest PATH");
|
||||
const input = try readInput(arena, io, manifest_path orelse rest[0], manifest_path != null) orelse return .usage;
|
||||
const all_grants = try mergeGrants(arena, input.grants, grants.items);
|
||||
const path = input.path;
|
||||
const report = try aji.check.checkWithModules(arena, path, input.source, input.modules);
|
||||
for (report.diagnostics) |d| {
|
||||
try d.writeJson(out);
|
||||
try out.writeByte('\n');
|
||||
@@ -366,7 +354,7 @@ fn explore(arena: std.mem.Allocator, io: std.Io, argv: []const []const u8, out:
|
||||
defer run_arena.deinit();
|
||||
var ex: aji.interp.Explore = .{ .prefix = prefix.items };
|
||||
const outcome = aji.interp.run(run_arena.allocator(), module, "main", .{
|
||||
.grants = grants.items,
|
||||
.grants = all_grants,
|
||||
.quantum = std.math.maxInt(u64),
|
||||
.explore = &ex,
|
||||
}) catch |err| switch (err) {
|
||||
@@ -496,3 +484,25 @@ test "standard library trap record identifies the bundled source" {
|
||||
try std.testing.expectEqualStrings("std/math.aji", location.get("file").?.string);
|
||||
try std.testing.expectEqual(@as(i64, 20), location.get("line").?.integer);
|
||||
}
|
||||
|
||||
fn readInput(arena: std.mem.Allocator, io: std.Io, path: []const u8, from_manifest: bool) !?aji.source_package.Input {
|
||||
return switch (if (from_manifest) try aji.source_package.load(arena, io, path) else try aji.source_package.single(arena, io, path)) {
|
||||
.ok => |input| input,
|
||||
.err => |err| blk: {
|
||||
std.debug.print("aji: {s}:{d}: {s}\n", .{ err.path, err.line, err.message });
|
||||
break :blk null;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
fn mergeGrants(arena: std.mem.Allocator, baseline: []const aji.manifest.Grant, overrides: []const aji.interp.Grant) ![]const aji.interp.Grant {
|
||||
var result: std.ArrayList(aji.interp.Grant) = .empty;
|
||||
for (baseline) |grant| {
|
||||
const replaced = for (overrides) |override| {
|
||||
if (std.mem.eql(u8, grant.parameter, override.parameter)) break true;
|
||||
} else false;
|
||||
if (!replaced) try result.append(arena, .{ .parameter = grant.parameter, .kind = grant.kind, .scope = grant.scope });
|
||||
}
|
||||
try result.appendSlice(arena, overrides);
|
||||
return result.items;
|
||||
}
|
||||
Reference in new issue
Block a user