Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Find Rust owners in the [compiler map](source-rust/README.md#where-code-belongs)

## Immediate product closure

- **SELFHOST-SAMPLE-VERDICTS.** Make the Omega-written compiler reject the same invalid projects as the Rust sample gate for the expected reasons. The audit at `86090d7` found 56 confirmed disagreements across 29 fixture families. Reproduce ordinary source checks with the [nominal type owner](samples/cli/facts/extended/nominal_declaration_owner) and [domain carrier](samples/cli/facts/core/domain_carrier_identity) twins. Reproduce Build checks with the [required output path](samples/cli/facts/extended/required_output_path) twins. Run each valid partner alongside its negative and compare the first diagnostic with the fixture expectation. [The audit](https://github.com/CathedralOS/Omega/pull/8468) records the 57 accepted paths and the Rust result for each.
- **SELFHOST-SAMPLE-VERDICTS.** Make the Omega-written compiler reject the same invalid projects as the Rust sample gate for the expected reasons. The audit at `86090d7` found 56 confirmed disagreements across 29 fixture families. Reproduce ordinary source checks with the [nominal type owner](samples/cli/facts/extended/nominal_declaration_owner) and [domain carrier](samples/cli/facts/core/domain_carrier_identity) twins. Check the authored Build and its helpers against the toolchain Build declarations before following any Product selection. In all nine [required output path](samples/cli/facts/extended/required_output_path) pairs, the invalid helper requires mutable access to the shared byte view supplied by `RequiredOutput::path`. Verify that it rejects at that call and that the valid Build executes and seals `answer.dat`. Run each valid partner alongside its negative and compare the first diagnostic with the fixture expectation. [The audit](https://github.com/CathedralOS/Omega/pull/8468) records the 57 accepted paths and the Rust result for each.

- **SELFHOST-LINUX-EMISSION-STORAGE.** Make `omega build --target linux_x86_64 source/application/build.omg` publish a runnable Omega-written compiler. At [#8405](https://github.com/CathedralOS/Omega/pull/8405) the full product passes source checking and publishes Psi. The native entry needs 14,903,528 bytes of stack on its deepest call path. Linux supplies 8,388,608 bytes, including 65,536 reserved for loader and host calls. The streaming build currently puts its 10 MiB code buffer in a local in [cli_live.omg](source/application/cli_live.omg). Preserve the supported emission capacity and the checked stack bound. Verify the resulting Linux compiler can run `batch-check` and build and run `samples/cli/arithmetic/led_mixer`.

Expand Down
3 changes: 3 additions & 0 deletions source/application/cli_live.omg
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,9 @@ reaches |process_authority|::StandardError terminates? {
stage == |loader|::LOAD_ERR_INDEX -> report_err_compiler_fail("load", path, "index", ts, prog, @ir_z, @cs_z),
stage == |loader|::LOAD_ERR_IO_READ -> report_err_simple("io", path, "cannot read source file"),
stage == |loader|::LOAD_ERR_BUILD_PARSE -> report_err_simple("build", path, "cannot parse build.omg"),
stage == |loader|::LOAD_ERR_AMBIGUOUS_BUILD -> report_err_simple("build", path, "multiple free build machines"),
stage == |loader|::LOAD_ERR_BUILD_RECEIVER -> report_err_simple("build", path, "Build activation requires its one original BuildPlan parameter and a machine body"),
stage == |loader|::LOAD_ERR_MISSING_SUCCESSOR_ENTRY -> report_err_simple("build", path, "successor Build entry declares no free build machine"),
stage == |loader|::LOAD_ERR_MISSING_DEP -> report_err_simple("dep", path, "unresolved package dependency"),
stage == |loader|::LOAD_ERR_POOL_CAP -> report_err_simple("pool", path, "project source pool capacity exceeded"),
stage == |loader|::LOAD_ERR_INVALID_PATH -> report_err_simple("path", path, "invalid source path"),
Expand Down
68 changes: 63 additions & 5 deletions source/application/project_loader.omg
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public const LOAD_ERR_POOL_CAP: u8 = 4;
public const LOAD_ERR_INDEX: u8 = 5;
public const LOAD_ERR_INVALID_PATH: u8 = 6;

public const LOAD_ERR_NO_BUILD_ENTRY: u8 = 7;
public const LOAD_ERR_AMBIGUOUS_BUILD: u8 = 8;
public const LOAD_ERR_BUILD_RECEIVER: u8 = 9;
public const LOAD_ERR_MISSING_SUCCESSOR_ENTRY: u8 = 10;

public data ProjectPool {
// Partitioned 256 KiB arena:
// [0 .. META_CAP) : persistent metadata (pkg names/dirs, file rel paths, entry name)
Expand Down Expand Up @@ -3008,6 +3013,46 @@ reaches |fsauth|::FilesystemContentRead
}
}

// The selected file's declaration scope decides which machine receives the
// plan. A nested machine named build belongs to its parent and cannot receive it.
machine build_entry_status(src: @[u8], ts: @|lex|::TokenStream, prog: @mutable |arena|::ProgramArena) -> u8 terminates? {
let parsed: bool = |index|::scan_declarations(src, ts, prog);
let status: u8 = match parsed {
true -> find_entry(src, prog, 1, 0),
_ -> LOAD_ERR_BUILD_PARSE
};
|arena|::reset_program_keep_deps(prog);
status

machine find_entry(src: @[u8], prog: @|arena|::ProgramArena, i: u64, found: u64) -> u8 terminates? {
transition {
i <= prog.decl_count && i < 512 -> inspect(src, prog, i, found),
found > 0 && found < 512 -> receiver(prog, found),
_ -> LOAD_ERR_NO_BUILD_ENTRY
}
}
machine inspect(src: @[u8], prog: @|arena|::ProgramArena, i: u64, found: u64) -> u8
requires i < 512 terminates? {
let d: |arena|::Decl = prog.decls[i];
let free_build: bool = d.kind == |arena|::DECL_MACHINE && d.parent_decl == 0
&& d.name_start <= src.length && d.name_len <= src.length - d.name_start
&& slice_eq_lit(@src[d.name_start..d.name_start + d.name_len], "build");
transition {
free_build && found != 0 -> LOAD_ERR_AMBIGUOUS_BUILD,
free_build -> find_entry(src, prog, i + 1, i),
_ -> find_entry(src, prog, i + 1, found)
}
}
machine receiver(prog: @|arena|::ProgramArena, id: u64) -> u8
requires id < 512 terminates? {
let d: |arena|::Decl = prog.decls[id];
transition d.body_len > 0 && d.param_count == 1 && d.first_param > 0 && d.first_param < 1024 {
true -> match (prog.param_flags[d.first_param] & |arena|::PARAM_ERASED) == 0 { true -> LOAD_ERR_NONE, _ -> LOAD_ERR_BUILD_RECEIVER },
_ -> LOAD_ERR_BUILD_RECEIVER
}
}
}

// --- Public Entry Point: Load `build.omg` or Standalone `.omg` Project off Disk ---

public machine load_project_from_disk(
Expand Down Expand Up @@ -3092,9 +3137,15 @@ reaches |fsauth|::FilesystemContentRead
+ |fsauth|::FilesystemContentWrite
+ |fsauth|::FilesystemMetadataMutation
+ |fsauth|::FilesystemNamespaceMutation terminates? {
transition path_is_build_omg(root_path) {
true -> blocks? start_build_chain(root_path, dir_s, dir_l, pool, ts, prog, sidx),
_ -> blocks? load_standalone(root_path, dlen, dir_s, dir_l, pool, ts, prog, sidx)
let is_build_path: bool = path_is_build_omg(root_path);
let planned: bool = is_build_path && blocks? start_build_chain(root_path, dir_s, dir_l, pool, ts, prog, sidx);
transition {
planned -> true,
!is_build_path || pool.err_stage == LOAD_ERR_NO_BUILD_ENTRY -> {
pool.err_stage = LOAD_ERR_NONE;
blocks? load_standalone(root_path, dlen, dir_s, dir_l, pool, ts, prog, sidx)
},
_ -> false
}
}

Expand Down Expand Up @@ -3318,11 +3369,18 @@ reaches |fsauth|::FilesystemContentRead
+ |fsauth|::FilesystemMetadataMutation
+ |fsauth|::FilesystemNamespaceMutation terminates? {
let lex_ok: bool = |lex|::lex_slice(@pool.buf[bsrc_s .. bsrc_s + bsrc_l], ts);
transition lex_ok {
let status: u8 = match lex_ok {
true -> build_entry_status(@pool.buf[bsrc_s .. bsrc_s + bsrc_l], ts, prog),
_ -> LOAD_ERR_BUILD_PARSE
};
transition status == LOAD_ERR_NONE {
true -> blocks? process_build(bsrc_s, dir_s, dir_l, pool, ts, prog, sidx, chain_depth),
_ -> {
|lex|::reset_tokens(ts);
pool_fail(pool, LOAD_ERR_BUILD_PARSE)
pool_fail(pool, match status == LOAD_ERR_NO_BUILD_ENTRY && chain_depth > 0 {
true -> LOAD_ERR_MISSING_SUCCESSOR_ENTRY,
_ -> status
})
}
}
}
Expand Down
62 changes: 62 additions & 0 deletions source/application/tests/build_entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Check Build entry selection through a built Omega CLI."""

import argparse
import shutil
import subprocess
import tempfile
from pathlib import Path


FIXTURES = Path(__file__).resolve().parents[3] / "samples/cli/facts/extended/required_output_path"
ENTRY = """use main.omg as app;
machine build(plan: @mutable BuildPlan) {
plan.product = BuildProduct::Application { name: "example" };
Build::bind(plan, windows_x86_64::ProgramEntry, |app|::main);
}
"""


def check(compiler, directory, diagnostic=None):
result = subprocess.run(
[compiler, "--check", "--target", "windows_x86_64", "build.omg"],
cwd=directory, stdin=subprocess.DEVNULL, capture_output=True, text=True, timeout=120,
)
if result.returncode != int(diagnostic is not None) or (diagnostic and diagnostic not in result.stderr):
raise AssertionError(f"{directory.name}: exit {result.returncode}\n{result.stdout}{result.stderr}")


def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("compiler", type=Path)
compiler = parser.parse_args().compiler.resolve(strict=True)
with tempfile.TemporaryDirectory() as temp:
root = Path(temp)
for name, build, diagnostic in (
("valid", ENTRY + "machine helper() { machine build(x: u8) {} }\n", None),
("ambiguous", ENTRY + "machine build(other: @mutable BuildPlan) {}\n", "multiple free build machines"),
("extra_parameter", ENTRY.replace("plan: @mutable BuildPlan", "plan: @mutable BuildPlan, other: u8"), "one original BuildPlan parameter"),
("default", "machine main() {}\n", None),
):
directory = root / name
directory.mkdir()
(directory / "build.omg").write_text(build)
(directory / "main.omg").write_text("machine main() {}\n")
check(compiler, directory, diagnostic)

successor = root / "successor"
successor.mkdir()
(successor / "build.omg").write_text(
'machine build(plan: @mutable BuildPlan) {\n'
' plan.product = BuildProduct::InterpretedBuild { entry: "next.omg" };\n}\n'
)
(successor / "next.omg").write_text("machine main() {}\n")
check(compiler, successor, "declares no free build machine")

for placement in ("local", "other_machine", "target_body"):
directory = root / placement
shutil.copytree(FIXTURES / placement, directory, ignore=shutil.ignore_patterns("build"))
check(compiler, directory)


if __name__ == "__main__":
main()
11 changes: 9 additions & 2 deletions source/subsystems/compiler/source-to-psi/index.omg
Original file line number Diff line number Diff line change
Expand Up @@ -9160,6 +9160,13 @@ machine fail_lex_at(ts: @mutable |lex|::TokenStream, prog: @mutable |arena|::Pro
|arena|::fail_program(prog, pos)
}

// Build entry selection reads the file's free declarations before the Build
// prelude and dependency types are resolved. Product indexing uses the same grammar.
public machine scan_declarations(src: @[u8], ts: @|lex|::TokenStream, prog: @mutable |arena|::ProgramArena) -> bool terminates? {
check_no_carry_tokens(src, ts, prog) && check_m18_retired_tokens(src, ts, prog)
&& loop_items_stream(src, ts, 1, prog)
}

machine loop_items_stream(src: @[u8], ts: @|lex|::TokenStream, idx: u64, prog: @mutable |arena|::ProgramArena) -> bool terminates? {
transition idx <= ts.count && idx < 4093 {
true -> dispatch(src, ts, idx, prog),
Expand Down Expand Up @@ -9639,7 +9646,7 @@ requires item_s < item_e, item_e <= src.length terminates? {

machine finish_small(src: @[u8], item_s: u64, ts: @mutable |lex|::TokenStream, prog: @mutable |arena|::ProgramArena) -> bool terminates? {
shift_tokens(ts, item_s);
let ok: bool = check_no_carry_tokens(src, ts, prog) && check_m18_retired_tokens(src, ts, prog) && loop_items_stream(src, ts, 1, prog);
let ok: bool = scan_declarations(src, ts, prog);
|lex|::reset_tokens(ts);
ok
}
Expand Down Expand Up @@ -9805,7 +9812,7 @@ public machine scan_file_in_pkg(src: @[u8], pkg_id: u16, is_gen: u8, path_start:
true -> shift_tokens(ts, start),
_ -> {}
};
let ok: bool = check_no_carry_tokens(src, ts, prog) && check_m18_retired_tokens(src, ts, prog) && loop_items_stream(src, ts, 1, prog);
let ok: bool = scan_declarations(src, ts, prog);
let res: bool = match ok {
true -> mark_ok_range(src, ts, prog, fid, old_imp, old_decl, old_decl == 0),
_ -> false
Expand Down
Loading