E5004
E5004 — A call ofmain, ormainused as a value. Only the runtime startsmain. Amainthat takes aRootmakes the capabilities of the program, so a second start would give them to code that did not get them.
What the compiler reports
Error[E5004] at {{.*}}a_program_cannot_call_main.vx:[[@LINE+1]]:10: A program cannot call `main` or use it as a value
Error[E5004] at {{.*}}a_program_cannot_call_main.vx:[[@LINE+1]]:16: A program cannot call `main` or use it as a value
2 error(s) emitted
The fragments the test suite holds the compiler to. An ellipsis marks text the test does not constrain; the emitted message also carries a source location.
A program that triggers it
//
// Part of the Vx Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Only the runtime starts `main`. This `main` takes a `Root`, so each start makes a new `Root`.
// `helper` gets no capability, and a call of `main` would give it every capability of the
// program. `main` as a value is the same error.
fn apply(f : fn() -> i32) -> i32 {
return f();
}
fn helper() -> i32 {
return main();
}
fn pass_main() -> i32 {
return apply(main);
}
fn main(root : Root) -> i32 {
println!("main has a Root");
return helper() + pass_main();
}
From tests/frontend/fail/a_program_cannot_call_main.vx, which asserts this diagnostic on every commit.
Related
Unsafe and FFIThe chapter covering the rule this code enforces.
All diagnosticsEvery code the compiler can emit, grouped by stage.
E5003Trusted code in a package that
vxc --no-trusted-code NAME names: an unsafe block or unsafe fn, an mlir! block, an extern function, an extern impl or an unsafe impl. The program that uses the package gives the flag, so a new version of the package cannot add trusted code without an error. vxc --audit lists the trusted code of a program.