prometeu-studio/discussion/lessons/DSC-0007-pbs-learn-to-discussion-lessons-migration/LSN-0022-pbs-globals-lifecycle-and-published-entrypoint-legacy.md

53 lines
2.3 KiB
Markdown

---
id: LSN-0022
ticket: pbs-learn-to-discussion-lessons-migration
title: PBS Globals, Lifecycle, and Published Entrypoint Legacy Import
created: 2026-03-27
tags: [compiler, pbs, legacy-import, globals, lifecycle, entrypoint, lowering]
---
## Context
Legacy import from `docs/compiler/pbs/learn/05. Globals, Lifecycle, and Published Entrypoint.md`.
This lesson preserves the final topic-19 executable model after the workflow history was pruned from the PBS domain.
## Key Decisions
### Logical frame root and physical entrypoint are separate
**What:** The user `[Frame]` callable is the logical frame root, while the compiler-published wrapper is the physical executable entrypoint.
**Why:** The language surface should stay clean and semantically owned by user code, while the compiler owns the executable boot protocol.
**Trade-offs:** The model introduces synthetic artifacts, but it makes lifecycle orchestration explicit and deterministic.
### Boot is one-shot and compiler-owned
**What:** PBS boot orchestration is enforced through compiler-generated lifecycle artifacts plus a hidden boot guard.
**Why:** One-shot bootstrap semantics cannot depend on naming convention or informal runtime discipline.
**Trade-offs:** Lowering must carry more structure and metadata, but backend and runtime contracts become much less ambiguous.
## Patterns and Algorithms
- Model globals as explicit source-level declarations with stable module ownership.
- Model lifecycle through `[Init]`, `[Frame]`, and compiler-owned synthetic lowering artifacts.
- Publish the wrapper at physical entrypoint index `0`.
- Keep `FRAME_RET` in the wrapper path, not at the end of userland `frame()`.
- Keep hidden lifecycle state structurally distinguishable from ordinary user globals and callables.
## Pitfalls
- Treating `frame()` itself as the physical entrypoint.
- Reintroducing manifest-driven entrypoint authority.
- Recognizing hidden lifecycle artifacts only by naming convention.
- Proving only artifact presence without proving one-shot bootstrap semantics.
## Takeaways
- Userland owns frame semantics; the compiler owns executable boot protocol.
- Hidden lifecycle artifacts must be first-class structure, not naming folklore.
- Topic 19 is the closure that made PBS executable publication deterministic end-to-end.