Say which side of a rejected --bind is missing, or who already binds it
Build check / check (push) Canceled after 0s

A --bind that failed said only "host capability or exported Ziran provider
is missing or already bound". It now names the case: a host capability
the module does not declare, a provider the module does not export, or a
capability already bound by another provider, with both providers and
their files. A model that had two files exporting Frame could not tell
which one competed.

tests/host_bindings_cases.zi checks all three messages.
This commit is contained in:
waozi committed 2026-11-23 05:01:14 -03:00
1 parent 4499383fb7
commit 5ec1bf02f5
4 files changed
+158 -15

No files matched your search

+98 -12
View File
@@ -6787,28 +6787,114 @@ BindHostProvider(ZirProgram* program, uint8_t* spec)
m = (int32_t)((uint32_t)m + 1u);
}
}
bool value_64 = matched == ((void *)0) || implementation == ((void *)0);
if (value_64 || compiler_zx_link_BoundToZiran(&(matched->target[0]))) {
ZirSourceSpan value_65 = compiler_zx_link_CommandSpan();
String value_66 = StringLiteral("host.bind");
uint8_t* value_67 = (void *)0;
if (matched == ((void *)0)) {
ZirSourceSpan value_64 = compiler_zx_link_CommandSpan();
String value_65 = StringLiteral("host.bind");
uint8_t* value_66 = (void *)0;
{
String s = value_66;
value_67 = ((StaticText*)(&(s)))->data;
String s = value_65;
value_66 = ((StaticText*)(&(s)))->data;
}
String value_69 = StringLiteral("host capability or exported Ziran provider is missing or already bound: %s");
uint8_t* value_70 = (void *)0;
String value_68 = StringLiteral("host capability is missing: %s; module %s declares no host capability %s");
uint8_t* value_69 = (void *)0;
{
String s = value_69;
value_70 = ((StaticText*)(&(s)))->data;
String s = value_68;
value_69 = ((StaticText*)(&(s)))->data;
}
zir_f_a880a0694b9f00fc_Diagnostic(value_65, value_67, value_70, spec);
zir_f_a880a0694b9f00fc_Diagnostic(value_64, value_66, value_69, spec, &(source_module[0]), &(source_function[0]));
return 0;
}
if (implementation == ((void *)0)) {
ZirSourceSpan value_71 = compiler_zx_link_CommandSpan();
String value_72 = StringLiteral("host.bind");
uint8_t* value_73 = (void *)0;
{
String s = value_72;
value_73 = ((StaticText*)(&(s)))->data;
}
String value_75 = StringLiteral("exported Ziran provider is missing: %s; no module %s exports %s");
uint8_t* value_76 = (void *)0;
{
String s = value_75;
value_76 = ((StaticText*)(&(s)))->data;
}
zir_f_a880a0694b9f00fc_Diagnostic(value_71, value_73, value_76, spec, &(provider_module[0]), &(provider_function[0]));
return 0;
}
if (compiler_zx_link_BoundToZiran(&(matched->target[0]))) {
compiler_zx_link_BoundTwice(program, matched, &(source[0]), &(provider_module[0]), &(provider_function[0]));
return 0;
}
compiler_zx_link_BindImport(matched, &(provider_module[0]), &(provider_function[0]));
return 1;
}
uint8_t*
compiler_zx_link_ModuleFile(ZirProgram* program, uint8_t* name)
{
{
int32_t range_first_0 = 0;
int32_t range_last_0 = (int32_t)((uint32_t)(program->module_count) - 1u);
int32_t m = range_first_0;
if (m <= range_last_0) for (;;) {
ZirProgram* value_0 = program;
ZirModule* value_1 = (void *)0;
{
ZirProgram* program = value_0;
int32_t index = m;
value_1 = &(program->modules[index]);
}
ZirModule* module = value_1;
if (compiler_zx_link_Same(&(module->name[0]), name)) {
return &(module->source_path[0]);
}
if (m == range_last_0) {
break;
}
m = (int32_t)((uint32_t)m + 1u);
}
}
String value_3 = StringLiteral("\?");
uint8_t* value_4 = (void *)0;
{
String s = value_3;
value_4 = ((StaticText*)(&(s)))->data;
}
return value_4;
}
void
compiler_zx_link_BoundTwice(ZirProgram* program, ZirImport* matched, uint8_t* capability, uint8_t* module, uint8_t* function)
{
uint8_t* value_0 = &(matched->target[0]);
uint8_t* value_1 = (void *)0;
{
uint8_t* p = value_0;
size_t n = 6;
value_1 = (uint8_t*)(((size_t)(p) + n));
}
uint8_t* bound = value_1;
ZirSourceSpan value_3 = compiler_zx_link_CommandSpan();
String value_4 = StringLiteral("host.bind");
uint8_t* value_5 = (void *)0;
{
String s = value_4;
value_5 = ((StaticText*)(&(s)))->data;
}
String value_7 = StringLiteral("host capability %s is already bound by %s:%s (%s); %s:%s (%s) also provides it");
uint8_t* value_8 = (void *)0;
{
String s = value_7;
value_8 = ((StaticText*)(&(s)))->data;
}
uint8_t* value_10 = capability;
uint8_t* value_11 = bound;
uint8_t* value_12 = compiler_zx_link_ModuleFile(program, bound);
uint8_t* value_13 = module;
uint8_t* value_14 = function;
zir_f_a880a0694b9f00fc_Diagnostic(value_3, value_5, value_8, value_10, value_11, &(matched->extern_symbol[0]), value_12, value_13, value_14, compiler_zx_link_ModuleFile(program, module));
}
int32_t
BindHostModule(ZirProgram* program, uint8_t* spec)
{
@@ -928,6 +928,8 @@ bool compiler_zx_link_SplitBindingName(uint8_t* text, uint8_t* module, uint8_t*
bool compiler_zx_link_ResolveBindingModule(uint8_t* module);
void compiler_zx_link_BindImport(ZirImport* matched, uint8_t* provider_module, uint8_t* function);
int32_t BindHostProvider(ZirProgram* program, uint8_t* spec);
uint8_t* compiler_zx_link_ModuleFile(ZirProgram* program, uint8_t* name);
void compiler_zx_link_BoundTwice(ZirProgram* program, ZirImport* matched, uint8_t* capability, uint8_t* module, uint8_t* function);
int32_t BindHostModule(ZirProgram* program, uint8_t* spec);
int32_t compiler_zx_link_ModuleNameOrder(void* left, void* right);
uint8_t* compiler_zx_link_CopyRecords(uint8_t* source, int32_t count, size_t size, bool* failed);
+31 -2
View File
@@ -219,14 +219,43 @@ BindHostProvider :: (program: *IR.ZirProgram, spec: *u8) -> s32 {
}
}
}
if matched == null || implementation == null || BoundToZiran(*matched.target[0]) {
Diagnostic(CommandSpan(), CStr("host.bind"), CStr("host capability or exported Ziran provider is missing or already bound: %s"), spec)
if matched == null {
Diagnostic(CommandSpan(), CStr("host.bind"), CStr("host capability is missing: %s; module %s declares no host capability %s"),
spec, *source_module[0], *source_function[0])
return 0
}
if implementation == null {
Diagnostic(CommandSpan(), CStr("host.bind"), CStr("exported Ziran provider is missing: %s; no module %s exports %s"),
spec, *provider_module[0], *provider_function[0])
return 0
}
if BoundToZiran(*matched.target[0]) {
BoundTwice(program, matched, *source[0], *provider_module[0], *provider_function[0])
return 0
}
BindImport(matched, *provider_module[0], *provider_function[0])
return 1
}
// The source file of the module named NAME in PROGRAM, or "?".
ModuleFile :: (program: *IR.ZirProgram, name: *u8) -> *u8 {
for m: 0..program.module_count - 1 {
module := ModuleAt(program, m)
if Same(*module.name[0], name) { return *module.source_path[0] }
}
return CStr("?")
}
// Reports a second binding of CAPABILITY, already bound to a Ziran
// provider, naming both providers and their files.
BoundTwice :: (program: *IR.ZirProgram, matched: *IR.ZirImport, capability: *u8, module: *u8, function: *u8) {
bound := PtrAdd(*matched.target[0], 6)
Diagnostic(CommandSpan(), CStr("host.bind"),
CStr("host capability %s is already bound by %s:%s (%s); %s:%s (%s) also provides it"),
capability, bound, *matched.extern_symbol[0], ModuleFile(program, bound),
module, function, ModuleFile(program, module))
}
// Binds every host capability no --bind has claimed to the exported Ziran
// function of the same name in the provider module, as a C program links a
// host's exported symbols by name. One Ziran host module, such as Kryon's
+27 -1
View File
@@ -54,6 +54,32 @@ QualifiedHostCalls :: (test: *NativeTest) -> bool {
CheckConcat("qualified call dropped a required result\n", discarded.error))
}
// A rejected --bind names the side that is missing, or both providers when
// a capability is bound twice. Uses the solo host module and the
// implementation provider QualifiedHostCalls writes.
BindingDiagnostics :: (test: *NativeTest) -> bool {
source := CheckPath(test.work, "qualified.zi")
implementation := CheckPath(test.work, "implementation.zi")
second := CheckPath(test.work, "second.zi")
if !NativeWrite(test, source, "using Host :: #import \"solo\";\n#program_export\nAnswer :: () -> s64 { return Host.Only(Host.seed) }\n") ||
!NativeWrite(test, second, "#program_export\nOnly :: (value: s64) -> s64 { return value + 2 }\n") { return false }
specs: [3]string = .["solo:Nope=implementation:Only", "solo:Only=implementation:Nope", "solo:Only=second:Only"]
errors: [3]string = .["host capability is missing: solo:Nope=implementation:Only; module solo declares no host capability Nope",
"exported Ziran provider is missing: solo:Only=implementation:Nope; no module implementation exports Nope",
"host capability solo:Only is already bound by implementation:Only ("]
for spec, index: specs {
command: [15]string = .[test.ziran, "run", "--backend", "engine", "--root", test.work, "--entry", "qualified:Answer",
"--bind", "solo:Only=implementation:Only", "--bind", spec, source, implementation, second]
if index < 2 { command[9] = spec }
rejected := NativeInvoke(test, command[:])
if !NativeAssert(test, rejected.code != 0 && TextContains(rejected.error, errors[index]),
CheckConcat("unexpected --bind diagnostic for ", CheckConcat(spec, CheckConcat("\n", rejected.error)))) { return false }
if index == 2 && !NativeAssert(test, TextContains(rejected.error, "implementation.zi); second:Only (") &&
TextContains(rejected.error, "second.zi) also provides it"), CheckConcat("--bind diagnostic names no files\n", rejected.error)) { return false }
}
return true
}
#program_export
main :: (argc: s32, argv: **u8) -> s32 {
test := NativeStart(argc, argv, "host-bindings-")
@@ -114,7 +140,7 @@ main :: (argc: s32, argv: **u8) -> s32 {
unused NativeRun(*test, run[:])
}
if !NativeAssert(*test, NativeSameFile(CheckPath(test.work, "single-source.zx"), CheckPath(test.work, "single-saved.zx")), "single host bundles differ") { return 1 }
if !QualifiedHostCalls(*test) { return 1 }
if !QualifiedHostCalls(*test) || !BindingDiagnostics(*test) { return 1 }
// A host result record whose name is longer than eight bytes, as
// Kryon's ReadBundleInput returns BundleInput: lowering keeps the whole
// name and resolves the record.