Skip to content

Commit 0246d7b

Browse files
authored
fix: define every capability word, including the ones that read zero (#2)
⚠️ 在把一个「查询能力」的可移植程序移到这个后端时实测: ld.lld: error: undefined symbol: kal_fs_props >>> referenced by fs.cppm:136 >>> obj/main.o:(kal::fs::properties@openkal.fs()) ld.lld: error: undefined symbol: kal_task_props 那个程序**一次文件系统调用都没有**。引用来自「询问」本身 —— 规范的查询是这些对象上的 inline 函数: inline props properties() { return props{kal_fs_props}; } 所以一个只是**问**「这台机器有没有文件系统」的程序,就会取 `kal_fs_props` 的地址。在一台没有文件系统的机器上不定义它,等于让这个问题以最强的方式 无法回答:它链接不过去。 ⭐ 而「询问而不假定」正是整个规范建立其上的模式。一个后端不定义它没有的那些 层的属性字,就使该模式在它最需要服务的那类平台上失效。 零是正确的值,而且已经是规范里写下的读法:「未赋值的位读作零, 以使一个按更晚规范编译的程序在更早的实现上行为正确」。 一台没有文件系统也没有调度器的机器,是这句话推到极限的情形。 ⚠️ 读规范两轮没有发现这一条;写一个程序跑一次就挖出来了。 这在本生态里是同一教训的第三次。
1 parent c3ae70d commit 0246d7b

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/kal.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,32 @@ void* kal_alloc(kal_uintptr size, kal_uintptr align) {
236236
// rather than an omission.
237237
void kal_free(void*, kal_uintptr, kal_uintptr) {}
238238

239+
// ── Capability words for the layers this machine does not have ──────────────
240+
//
241+
// ⚠️ A BACKEND MUST DEFINE EVERY PROPERTY WORD, INCLUDING THE ONES THAT READ
242+
// ZERO, OR THE QUESTION ITSELF FAILS TO LINK.
243+
//
244+
// The specification's queries are inline functions over these objects:
245+
//
246+
// inline props properties() { return props{kal_fs_props}; }
247+
//
248+
// so a program that merely ASKS whether a filesystem exists takes the address
249+
// of `kal_fs_props`. Leaving it undefined on a machine that has no filesystem
250+
// makes the question unanswerable in the strongest sense: it does not link.
251+
//
252+
// ld.lld: error: undefined symbol: kal_fs_props
253+
// >>> referenced by fs.cppm:136
254+
// >>> obj/main.o:(kal::fs::properties@openkal.fs())
255+
//
256+
// Measured while porting a capability-querying program to this backend. The
257+
// program contained no filesystem call at all — the reference came from the
258+
// query, which is the pattern the whole specification is built on.
259+
//
260+
// Zero is the correct value and is already the specified reading: "an
261+
// unassigned position reads as zero, so that a program compiled against a later
262+
// specification behaves correctly against an earlier implementation". A machine
263+
// with no filesystem and no scheduler is that case taken to its limit.
264+
const kal_uintptr kal_fs_props = 0;
265+
const kal_uintptr kal_task_props = 0;
266+
239267
} // extern "C"

0 commit comments

Comments
 (0)