Compare commits

..
Author SHA1 Message Date
bquarkz e809ce63d3 implements PLN-0129
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 62.10% (17811/28682) * Branch Coverage: 52.81% (6878/13025) * Lines of Code: 28682 * Cyclomatic Complexity: 11494 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 654
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good
Add ArchUnit guards for Java multi-frontend boundaries in a test-only
module. Identify PBS by frontend-module origin, allow only the registry
as composition root, and lock the wording in specs 19, 20, and 22.

Housekeep DSC-0064 with LSN-0066.
2026-09-19 03:32:43 +01:00
bquarkz 59c0d0c3b4 Merge pull request 'implements PLN-0128' (#22) from dev/multi-frontend-synthetic-test-frontend into master
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 62.10% (17811/28682) * Branch Coverage: 52.81% (6878/13025) * Lines of Code: 28682 * Cyclomatic Complexity: 11494 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 653
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Reviewed-on: #22
2026-09-19 02:10:09 +00:00
bquarkz 79a682b8ec implements PLN-0128
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 62.10% (17811/28682) * Branch Coverage: 52.81% (6878/13025) * Lines of Code: 28682 * Cyclomatic Complexity: 11494 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 653
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Add a test-only synth FrontendProvider that traverses compile() to
verified bytecode without PBS. Expose register/unregister on the static
registry and lock the obligation in specs 23 and 22.

Housekeep DSC-0063 with LSN-0065.
2026-09-19 03:03:37 +01:00
bquarkz d0b91f8526 Merge pull request 'implements PLN-0127' (#21) from dev/multi-frontend-sdk-canonical-definition into master
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 61.95% (17766/28676) * Branch Coverage: 52.69% (6860/13019) * Lines of Code: 28676 * Cyclomatic Complexity: 11490 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 648
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Reviewed-on: #21
2026-09-19 01:39:18 +00:00
bquarkz 2b881f5a76 implements PLN-0127
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 61.95% (17766/28676) * Branch Coverage: 52.69% (6860/13019) * Lines of Code: 28676 * Cyclomatic Complexity: 11490 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 648
Publish the console ABI authority map: runtime catalogs win, PBS stdlib is
delivery. Recut specs 18, 8, and 6.2 and lock them with ConsoleAbiAuthoritySpecTest.

Housekeep DSC-0061 with LSN-0064.
2026-09-19 02:35:05 +01:00
bquarkz 4d8dcf28bb Merge pull request 'implements PLN-0126' (#20) from dev/multi-frontend-validation-boundaries into master
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 61.95% (17766/28676) * Branch Coverage: 52.69% (6860/13019) * Lines of Code: 28676 * Cyclomatic Complexity: 11490 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 645
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Reviewed-on: #20
2026-09-19 00:16:57 +00:00
bquarkz d7c2ec880f implements PLN-0126
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 61.95% (17766/28676) * Branch Coverage: 52.69% (6860/13019) * Lines of Code: 28676 * Cyclomatic Complexity: 11490 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 645
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Publish the language-versus-platform validation matrix in compiler-general
specs, retitle spec 19, and recut PBS diagnostics so common structural
failures are not PBS coverage.

Housekeep DSC-0060 with LSN-0063.
2026-09-19 01:11:50 +01:00
bquarkz c248b91147 Merge pull request 'implements PLN-0125' (#19) from dev/multi-frontend-common-lifecycle into master
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 61.95% (17766/28676) * Branch Coverage: 52.69% (6860/13019) * Lines of Code: 28676 * Cyclomatic Complexity: 11490 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 643
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Reviewed-on: #19
2026-09-18 23:40:50 +00:00
bquarkz 46bd0c42d3 implements PLN-0125
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 61.95% (17766/28676) * Branch Coverage: 52.69% (6860/13019) * Lines of Code: 28676 * Cyclomatic Complexity: 11490 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 643
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good
Move lifecycle assembly out of the PBS frontend into a common
AssembleLifecyclePipelineStage. PBS emits a typed IRLifecycleDeclaration;
the assembler owns wrappers, boot guard, and single project-init execution.

Housekeep DSC-0059 with LSN-0062, and include the DSC-0062 PVM/PBX
neutrality spec and lesson already present on this branch.
2026-09-19 00:19:45 +01:00
bquarkz c6ef56114f Merge pull request 'dev/multi-frontend-serializable-ir' (#18) from dev/multi-frontend-serializable-ir into master
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 61.73% (17590/28493) * Branch Coverage: 52.45% (6778/12924) * Lines of Code: 28493 * Cyclomatic Complexity: 11423 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 624
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Reviewed-on: #18
2026-07-15 12:47:12 +00:00
bquarkz 701f5b0339 housekeep DSC-0058
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 61.73% (17590/28493) * Branch Coverage: 52.45% (6778/12924) * Lines of Code: 28493 * Cyclomatic Complexity: 11423 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 624
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good
2026-07-15 13:12:36 +01:00
bquarkz cc4cb23b76 implements PLN-0123 2026-07-15 13:03:57 +01:00
bquarkz f42c83bdca implements PLN-0122 2026-07-15 13:02:09 +01:00
bquarkz cf14039077 implements PLN-0121 2026-07-15 12:59:35 +01:00
bquarkz 1f1a92d43f implements PLN-0120 2026-07-15 12:57:36 +01:00
bquarkz 38790c0b45 implements PLN-0119 2026-07-15 12:55:50 +01:00
bquarkz 5f6bd408a4 Unique and Serializable IR 2026-07-15 12:54:39 +01:00
bquarkz a77dce1c56 Merge pull request 'dev/multi-frontend-frontend-backend-contract' (#17) from dev/multi-frontend-frontend-backend-contract into master
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 61.73% (17588/28493) * Branch Coverage: 52.44% (6777/12924) * Lines of Code: 28493 * Cyclomatic Complexity: 11423 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 619
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Reviewed-on: #17
2026-07-15 11:45:42 +00:00
bquarkz b9a32e460a housekeep DSC-0057
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 61.73% (17588/28493) * Branch Coverage: 52.44% (6777/12924) * Lines of Code: 28493 * Cyclomatic Complexity: 11423 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 619
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
2026-07-15 12:18:44 +01:00
bquarkz e8079b67fb implements PLN-0118 2026-07-15 12:13:40 +01:00
bquarkz bde999f1fe implements PLN-0117 2026-07-15 12:10:10 +01:00
bquarkz 26c69d5660 Stable contract FE/BE 2026-07-15 12:07:07 +01:00
77 changed files with 4745 additions and 1412 deletions
+9 -9
View File
@@ -1,13 +1,13 @@
{"type":"meta","next_id":{"DSC":66,"AGD":69,"DEC":43,"PLN":117,"LSN":59,"CLSN":1}} {"type":"meta","next_id":{"DSC":66,"AGD":69,"DEC":51,"PLN":130,"LSN":67,"CLSN":1}}
{"type":"discussion","id":"DSC-0065","status":"open","ticket":"multi-frontend-avoid-premature-abstractions","title":"Evitar abstracoes prematuras na preparacao multi-frontend","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","studio","frontend","architecture","multi-frontend","simplicity"],"agendas":[{"id":"AGD-0068","file":"AGD-0068-multi-frontend-avoid-premature-abstractions.md","status":"open","created_at":"2026-07-15","updated_at":"2026-07-15"}],"decisions":[],"plans":[],"lessons":[]} {"type":"discussion","id":"DSC-0065","status":"open","ticket":"multi-frontend-avoid-premature-abstractions","title":"Evitar abstracoes prematuras na preparacao multi-frontend","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","studio","frontend","architecture","multi-frontend","simplicity"],"agendas":[{"id":"AGD-0068","file":"AGD-0068-multi-frontend-avoid-premature-abstractions.md","status":"open","created_at":"2026-07-15","updated_at":"2026-07-15"}],"decisions":[],"plans":[],"lessons":[]}
{"type":"discussion","id":"DSC-0064","status":"open","ticket":"multi-frontend-architectural-tests","title":"Testes arquiteturais para fronteiras multi-frontend","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","studio","frontend","architecture","tests","multi-frontend"],"agendas":[{"id":"AGD-0067","file":"AGD-0067-multi-frontend-architectural-tests.md","status":"open","created_at":"2026-07-15","updated_at":"2026-07-15"}],"decisions":[],"plans":[],"lessons":[]} {"type":"discussion","id":"DSC-0064","status":"done","ticket":"multi-frontend-architectural-tests","title":"Testes arquiteturais para fronteiras multi-frontend","created_at":"2026-07-15","updated_at":"2026-09-19","tags":["compiler","compiler-general","studio","frontend","architecture","tests","multi-frontend"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0066","file":"discussion/lessons/DSC-0064-multi-frontend-architectural-tests/LSN-0066-archunit-guards-java-multi-frontend-boundaries.md","status":"done","created_at":"2026-09-19","updated_at":"2026-09-19"}]}
{"type":"discussion","id":"DSC-0063","status":"open","ticket":"multi-frontend-synthetic-test-frontend","title":"Frontend sintetico de teste para provar neutralidade do pipeline","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","frontend","tests","backend","multi-frontend"],"agendas":[{"id":"AGD-0066","file":"AGD-0066-multi-frontend-synthetic-test-frontend.md","status":"open","created_at":"2026-07-15","updated_at":"2026-07-15"}],"decisions":[],"plans":[],"lessons":[]} {"type":"discussion","id":"DSC-0063","status":"done","ticket":"multi-frontend-synthetic-test-frontend","title":"Frontend sintetico de teste para provar neutralidade do pipeline","created_at":"2026-07-15","updated_at":"2026-09-19","tags":["compiler","compiler-general","frontend","tests","backend","multi-frontend"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0065","file":"discussion/lessons/DSC-0063-multi-frontend-synthetic-test-frontend/LSN-0065-synthetic-test-frontend-proves-pipeline-neutrality.md","status":"done","created_at":"2026-09-19","updated_at":"2026-09-19"}]}
{"type":"discussion","id":"DSC-0062","status":"open","ticket":"multi-frontend-pvm-neutrality","title":"Neutralidade da PVM e identificacao PBX independente de PBS","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["vm-arch","runtime","pvm","pbx","compiler","multi-frontend"],"agendas":[{"id":"AGD-0065","file":"AGD-0065-multi-frontend-pvm-neutrality.md","status":"open","created_at":"2026-07-15","updated_at":"2026-07-15"}],"decisions":[],"plans":[],"lessons":[]} {"type":"discussion","id":"DSC-0062","status":"done","ticket":"multi-frontend-pvm-neutrality","title":"Neutralidade da PVM e identificacao PBX independente de PBS","created_at":"2026-07-15","updated_at":"2026-09-18","tags":["vm-arch","runtime","pvm","pbx","compiler","multi-frontend"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0061","file":"discussion/lessons/DSC-0062-multi-frontend-pvm-neutrality/LSN-0061-pbx-runtime-boundary.md","status":"done","created_at":"2026-09-18","updated_at":"2026-09-18"}]}
{"type":"discussion","id":"DSC-0061","status":"open","ticket":"multi-frontend-sdk-canonical-definition","title":"Auditoria e centralizacao gradual da definicao canonica do SDK","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","sdk","stdlib","hostcalls","intrinsics","multi-frontend"],"agendas":[{"id":"AGD-0064","file":"AGD-0064-multi-frontend-sdk-canonical-definition.md","status":"open","created_at":"2026-07-15","updated_at":"2026-07-15"}],"decisions":[],"plans":[],"lessons":[]} {"type":"discussion","id":"DSC-0061","status":"done","ticket":"multi-frontend-sdk-canonical-definition","title":"Auditoria e centralizacao gradual da definicao canonica do SDK","created_at":"2026-07-15","updated_at":"2026-09-19","tags":["compiler","compiler-general","sdk","stdlib","hostcalls","intrinsics","multi-frontend"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0064","file":"discussion/lessons/DSC-0061-multi-frontend-sdk-canonical-definition/LSN-0064-runtime-owns-console-abi-pbs-is-delivery.md","status":"done","created_at":"2026-09-19","updated_at":"2026-09-19"}]}
{"type":"discussion","id":"DSC-0060","status":"open","ticket":"multi-frontend-validation-boundaries","title":"Separar validacoes de linguagem e validacoes de plataforma","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","compiler-pbs","backend","validation","multi-frontend"],"agendas":[{"id":"AGD-0063","file":"AGD-0063-multi-frontend-validation-boundaries.md","status":"open","created_at":"2026-07-15","updated_at":"2026-07-15"}],"decisions":[],"plans":[],"lessons":[]} {"type":"discussion","id":"DSC-0060","status":"done","ticket":"multi-frontend-validation-boundaries","title":"Separar validacoes de linguagem e validacoes de plataforma","created_at":"2026-07-15","updated_at":"2026-09-19","tags":["compiler","compiler-general","compiler-pbs","backend","validation","multi-frontend"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0063","file":"discussion/lessons/DSC-0060-multi-frontend-validation-boundaries/LSN-0063-language-vs-platform-validation-ownership.md","status":"done","created_at":"2026-09-19","updated_at":"2026-09-19"}]}
{"type":"discussion","id":"DSC-0059","status":"open","ticket":"multi-frontend-common-lifecycle","title":"Extrair lifecycle comum das responsabilidades do frontend PBS","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","compiler-pbs","lifecycle","backend","multi-frontend"],"agendas":[{"id":"AGD-0062","file":"AGD-0062-multi-frontend-common-lifecycle.md","status":"open","created_at":"2026-07-15","updated_at":"2026-07-15"}],"decisions":[],"plans":[],"lessons":[]} {"type":"discussion","id":"DSC-0059","status":"done","ticket":"multi-frontend-common-lifecycle","title":"Extrair lifecycle comum das responsabilidades do frontend PBS","created_at":"2026-07-15","updated_at":"2026-09-19","tags":["compiler","compiler-general","compiler-pbs","lifecycle","backend","multi-frontend"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0062","file":"discussion/lessons/DSC-0059-multi-frontend-common-lifecycle/LSN-0062-common-lifecycle-assembly-stage.md","status":"done","created_at":"2026-09-19","updated_at":"2026-09-19"}]}
{"type":"discussion","id":"DSC-0058","status":"open","ticket":"multi-frontend-serializable-ir","title":"Manter a IR comum serializavel por design","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","ir","backend","serialization","multi-frontend"],"agendas":[{"id":"AGD-0061","file":"AGD-0061-multi-frontend-serializable-ir.md","status":"open","created_at":"2026-07-15","updated_at":"2026-07-15"}],"decisions":[],"plans":[],"lessons":[]} {"type":"discussion","id":"DSC-0058","status":"done","ticket":"multi-frontend-serializable-ir","title":"Manter a IR comum serializavel por design","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","ir","backend","serialization","multi-frontend"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0060","file":"discussion/lessons/DSC-0058-multi-frontend-serializable-ir/LSN-0060-data-contract-first-for-serializable-irbackend.md","status":"done","created_at":"2026-07-15","updated_at":"2026-07-15"}]}
{"type":"discussion","id":"DSC-0057","status":"open","ticket":"multi-frontend-frontend-backend-contract","title":"Estabilizar contrato entre frontend e backend comum","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","compiler-pbs","ir","backend","multi-frontend"],"agendas":[{"id":"AGD-0060","file":"AGD-0060-multi-frontend-frontend-backend-contract.md","status":"open","created_at":"2026-07-15","updated_at":"2026-07-15"}],"decisions":[],"plans":[],"lessons":[]} {"type":"discussion","id":"DSC-0057","status":"done","ticket":"multi-frontend-frontend-backend-contract","title":"Estabilizar contrato entre frontend e backend comum","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","compiler-pbs","ir","backend","multi-frontend"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0059","file":"discussion/lessons/DSC-0057-multi-frontend-frontend-backend-contract/LSN-0059-common-irbackend-handoff-and-backend-guardrails.md","status":"done","created_at":"2026-07-15","updated_at":"2026-07-15"}]}
{"type":"discussion","id":"DSC-0056","status":"done","ticket":"multi-frontend-remove-pbs-branches","title":"Generalizar o contrato LSP/editorial para frontends","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","compiler-pbs","studio","frontend","coupling","multi-frontend"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0058","file":"discussion/lessons/DSC-0056-multi-frontend-remove-pbs-branches/LSN-0058-generic-frontend-editorial-contract-for-lsp.md","status":"done","created_at":"2026-07-15","updated_at":"2026-07-15"}]} {"type":"discussion","id":"DSC-0056","status":"done","ticket":"multi-frontend-remove-pbs-branches","title":"Generalizar o contrato LSP/editorial para frontends","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","compiler-pbs","studio","frontend","coupling","multi-frontend"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0058","file":"discussion/lessons/DSC-0056-multi-frontend-remove-pbs-branches/LSN-0058-generic-frontend-editorial-contract-for-lsp.md","status":"done","created_at":"2026-07-15","updated_at":"2026-07-15"}]}
{"type":"discussion","id":"DSC-0055","status":"done","ticket":"multi-frontend-compiler-vs-language-services","title":"Separar compilacao de servicos editoriais de frontend","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","studio","lsp","editor","frontend","multi-frontend"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0056","file":"discussion/lessons/DSC-0055-multi-frontend-compiler-vs-language-services/LSN-0056-compile-first-frontends-with-optional-editorial-capabilities.md","status":"done","created_at":"2026-07-15","updated_at":"2026-07-15"}]} {"type":"discussion","id":"DSC-0055","status":"done","ticket":"multi-frontend-compiler-vs-language-services","title":"Separar compilacao de servicos editoriais de frontend","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","studio","lsp","editor","frontend","multi-frontend"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0056","file":"discussion/lessons/DSC-0055-multi-frontend-compiler-vs-language-services/LSN-0056-compile-first-frontends-with-optional-editorial-capabilities.md","status":"done","created_at":"2026-07-15","updated_at":"2026-07-15"}]}
{"type":"discussion","id":"DSC-0054","status":"done","ticket":"multi-frontend-provider-contract","title":"Introduzir provider completo de frontend","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","studio","frontend","registry","multi-frontend"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0055","file":"discussion/lessons/DSC-0054-multi-frontend-provider-contract/LSN-0055-static-frontend-providers-before-plugin-architecture.md","status":"done","created_at":"2026-07-15","updated_at":"2026-07-15"}]} {"type":"discussion","id":"DSC-0054","status":"done","ticket":"multi-frontend-provider-contract","title":"Introduzir provider completo de frontend","created_at":"2026-07-15","updated_at":"2026-07-15","tags":["compiler","compiler-general","studio","frontend","registry","multi-frontend"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0055","file":"discussion/lessons/DSC-0054-multi-frontend-provider-contract/LSN-0055-static-frontend-providers-before-plugin-architecture.md","status":"done","created_at":"2026-07-15","updated_at":"2026-07-15"}]}
@@ -0,0 +1,98 @@
---
id: LSN-0059
ticket: multi-frontend-frontend-backend-contract
title: Common IRBackend handoff and backend guardrails
created: 2026-07-15
tags: [compiler, compiler-general, compiler-pbs, ir, backend, multi-frontend]
---
# Common IRBackend handoff and backend guardrails
## Context
The multi-frontend work needed a clear boundary between language-specific frontends and common backend stages.
The existing code was already close to the desired architecture: PBS parsing, AST construction, and semantic analysis lowered into `IRBackend`, while the backend consumed `IRBackend` and lowered it into `IRVM`. The risk was not a known broken dependency. The risk was that common backend behavior still looked PBS-owned in specs, names, and missing guardrails, which could invite future coupling when another frontend is introduced.
## Key Decisions
### `IRBackend` is the common executable handoff
**What:** `IRBackend` remains the normative frontend-to-backend executable handoff. Frontends emit it; common backend stages consume it.
**Why:** The existing model already provides a language-neutral executable contract with modules, callable identities, executable functions, instruction metadata, globals, synthetic functions, host calls, intrinsics, spans, and capabilities. Renaming or redesigning it without a concrete leak would add churn without improving the boundary.
**Trade-offs:** Keeping the name `IRBackend` means the architecture relies on documentation and tests to communicate its common role. That is acceptable because the name is already established and the guardrails now enforce the boundary.
### PBS owns lowering into `IRBackend`, not backend consumption of it
**What:** PBS specs describe PBS admission and translation into `IRBackend`. Compiler-general specs describe the common `IRBackend -> IRVM` contract and backend obligations.
**Why:** PBS is currently the only rich frontend producing executable `IRBackend`, so many examples naturally come from PBS. Specs must still separate source-language obligations from backend obligations so future frontends do not inherit PBS-specific rules by accident.
**Trade-offs:** Some PBS-facing examples remain useful, especially around lifecycle wrappers and asset metadata. They must be phrased as current frontend sources of a common backend obligation, not as backend ownership by PBS.
## Implementation Result
The completed work:
1. rewrote the general backend spec so `IRBackend -> IRVM` is explicitly compiler-general;
2. rewrote the PBS lowering spec so PBS emits the common handoff instead of owning backend behavior;
3. updated the conformance matrix with DEC-0043 guardrail rows;
4. added a direct backend test that manually constructs common `IRBackend` and lowers it without PBS parser or frontend services;
5. added an architectural test preventing common backend imports from `p.studio.compiler.pbs`;
6. added a reflection-based contract test preventing public `IRBackend` model types from exposing PBS packages;
7. renamed the common lifecycle helper from `validatePbsLifecycleStructure` to `validateCommonLifecycleStructure`.
## Patterns and Algorithms
### Boundary consolidation before abstraction
When an existing boundary is already technically sound, prefer consolidation over redesign:
1. document the current contract as normative;
2. identify only concrete leaks;
3. add tests that would fail if the boundary regresses;
4. avoid renames or model extraction until there is evidence of real coupling.
This keeps multi-frontend preparation focused on preventing regressions rather than inventing abstractions prematurely.
### Guardrails for common backend neutrality
A useful backend neutrality guardrail has two layers:
1. source/package guard: common backend source must not import language frontend packages;
2. public-contract guard: common handoff types must not expose language-owned types through fields, constructors, methods, or record components.
The package guard catches implementation coupling. The reflection guard catches API coupling.
### Direct handoff construction test
A backend test should be able to construct executable `IRBackend` manually using only common model types and lower it through `LowerToIRVMService`.
That test proves the backend consumes the contract, not a specific frontend pipeline.
## Pitfalls
- Do not treat the presence of PBS examples as proof that the backend is PBS-owned.
- Do not move PBS source rules into compiler-general specs.
- Do not let lifecycle terms such as published wrapper, boot guard, or frame root hide whether the obligation is common or PBS-specific.
- Do not rename `IRBackend` for aesthetics when the real problem is missing ownership language and missing guardrails.
- Do not use a future synthetic test frontend as a substitute for simple direct `IRBackend` construction tests.
## Takeaways
- `IRBackend` is the common executable handoff.
- PBS owns PBS-to-`IRBackend` lowering; compiler-general owns `IRBackend -> IRVM`.
- Common backend code must not depend on `p.studio.compiler.pbs`.
- Public `IRBackend` contract types must not expose PBS AST, token, parser, semantic, or editorial types.
- Multi-frontend preparation should first lock existing good boundaries before introducing new abstractions.
## References
- `docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md`
- `docs/specs/compiler/22. Backend Spec-to-Test Conformance Matrix.md`
- `docs/specs/compiler-languages/pbs/13. Lowering IRBackend Specification.md`
- `prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/irvm/LowerToIRVMServiceTest.java`
- `prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/specs/CommonBackendArchitectureTest.java`
- `prometeu-compiler/prometeu-frontend-api/src/test/java/p/studio/compiler/models/IRBackendExecutableContractTest.java`
@@ -0,0 +1,82 @@
---
id: LSN-0060
ticket: multi-frontend-serializable-ir
title: Data contract first for serializable IRBackend
created: 2026-07-15
tags: [compiler, compiler-general, ir, backend, serialization, multi-frontend]
---
# Data contract first for serializable IRBackend
## Original Problem
The compiler already had a common executable handoff: `IRBackend`. PBS emits it, and common backend stages consume it before lowering to `IRVM`.
The remaining risk was subtler than direct PBS coupling. A Java-only handoff can accidentally grow around process-local assumptions: callbacks, services, object identity, mutable global state, unordered collections, lazy values, or direct references between live objects. Those shapes can work inside one JVM and still make a future external frontend or out-of-process boundary expensive to add.
The work needed to keep the handoff serializable by design without choosing JSON, Protobuf, RPC, plugin loading, or a separate process too early.
## Consolidated Decision
`IRBackend` is a data contract first.
Public `IRBackend` contract types must remain modelable as an acyclic, deterministic data graph made from primitives, strings, enums, immutable values, ordered lists, explicit ids, stable symbolic keys, and source attribution values such as file ids and spans.
The public handoff must not expose callbacks, lambdas, service objects, registries, visitors, live compiler services, frontend AST/parser/token/semantic/editorial objects, mutable global state, object identity semantics, unordered output-affecting collections, cyclic public references, process-dependent lazy values, or a selected wire format.
The important boundary is the data shape, not a codec. A future serializer should be able to consume the handoff because the public model is already disciplined, but this decision does not require a serializer to exist now.
## Final Implementation
The implementation updated the compiler-general backend spec with a new `IRBackend` serializability-by-design subsection. The spec now states the allowed and forbidden public shapes and keeps wire format selection explicitly deferred.
The conformance matrix added `G20-4.2.x` rows for the new requirements:
- public `IRBackend` modelability as an acyclic deterministic data graph;
- rejection of callbacks, services, mutable or unordered collections, frontend-owned objects, process-dependent lazy values, cyclic public references, and wire-format commitments;
- use of explicit ids or stable symbolic keys for cross-object references.
The executable guardrails live in `IRBackendExecutableContractTest`:
- the public contract audit covers all current `p.studio.compiler.models` handoff types and nested value types;
- support types such as `FileId`, `ModuleId`, `CallableId`, `IntrinsicId`, `Span`, table reference records, and `ReadOnlyList` are explicitly classified;
- reflection checks inspect public fields, record components, public constructors, public methods, and generic type arguments;
- guardrails reject PBS/frontend exposure, callback shapes, service-like public shapes, mutable/unordered collection contracts, and other non-serializable public exposures;
- deterministic aggregation tests prove stable ordering for functions, synthetic functions, globals, executable functions, module pools, callable signatures, intrinsic pools, reserved metadata, and required capabilities;
- known references are locked to explicit ids or stable keys rather than direct object references.
The audit found no concrete public serialization leak that required changing the production model. That result is meaningful: the current `IRBackend` shape was already close to the target, so the correct implementation was spec clarification plus tests, not a redesign.
## Examples
Good public handoff shapes:
- `ModuleId`, `CallableId`, `IntrinsicId`, and `FileId` for table-scoped references;
- `ReadOnlyList<T>` for ordered collections;
- `ModuleReference`, `CallableSignatureRef`, and `IntrinsicReference` as stable table values;
- `Span` for source attribution;
- enums and records for fixed value surfaces.
Bad public handoff shapes:
- `Map`, `Set`, or mutable collection interfaces where output order matters;
- `Runnable`, `Callable`, `Function`, visitors, or callbacks;
- compiler services or registries exposed as public fields or constructor parameters;
- frontend AST, parser, token, semantic, or editor types;
- direct references to another handoff object where an id or ordered table entry is the stable contract.
## Pitfalls
- Do not confuse "serializable by design" with "serialize it now." A codec is a future implementation detail.
- Do not add typed ids everywhere by taste. Add them when a real public field would otherwise depend on textual identity, object identity, or direct object references.
- Do not treat `ReadOnlyList` as cosmetic. Ordered collections are part of the deterministic contract.
- Do not let a private assembler or aggregator implementation shape leak into public handoff semantics.
- Do not move the rule into PBS specs. PBS owns how it populates the handoff; compiler-general owns the common handoff contract.
## References
- `docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md`
- `docs/specs/compiler/22. Backend Spec-to-Test Conformance Matrix.md`
- `prometeu-compiler/prometeu-frontend-api/src/test/java/p/studio/compiler/models/IRBackendExecutableContractTest.java`
- `prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/specs/BackendConformanceMatrixSpecTest.java`
- `prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/irvm/LowerToIRVMServiceTest.java`
@@ -0,0 +1,143 @@
---
id: LSN-0062
ticket: multi-frontend-common-lifecycle
title: Common lifecycle assembly after frontend declaration
created: 2026-09-19
tags: [compiler, compiler-general, compiler-pbs, lifecycle, backend, multi-frontend]
---
# Common lifecycle assembly after frontend declaration
## Original Problem
`IRBackend` was already the common executable handoff, but the PBS frontend still
owned two different jobs. It admitted language markers `[Init]`, `[Frame]`, and
`InitAllowed`, and it also assembled the platform lifecycle: module init,
project-init wrapper, published frame wrapper, physical entrypoint, and boot
guard.
That second job discovered roles through `__pbs.*` names and lived inside
`PBSFrontendPhaseService`. Another frontend could not reuse the boot sequence
without copying PBS. Common backend code also risked treating PBS naming as the
integration contract.
The old path had a concrete defect. The `[Init]` colocated with `[Frame]` is
project init, but it was also included in the file-init fragment. The published
wrapper then called module init and project init separately, so the same
callable could run twice. Specs required project init exactly once, after all
module initializers and before the frame root.
## Consolidated Decision
Declaration and assembly are separate.
An executable frontend emits an immutable, ordered, typed
`IRLifecycleDeclaration` on `IRBackend`. The declaration carries:
- modules in explicit dependency order;
- each module's ordered file-init fragment references;
- an optional project-init callable;
- exactly one frame-root callable.
References use `ModuleId`, `FileId`, `CallableId`, a typed role, and source
attribution. Absence of a declaration means a deliberately non-executable
handoff. It must not synthesize a default `main`.
`FrontendPhasePipelineStage` stops at that declarative backend.
`AssembleLifecyclePipelineStage` runs immediately after it and is the terminal
stage of `analyze()`. `LifecycleAssemblerService` is the only owner of derived
lifecycle artifacts. `compile()` and `build()` reuse that single assembly pass.
`ResolveDepsPipelineStage` remains the ordering authority. Frontends propagate
that order; the assembler validates and applies it. Neither side may rebuild
order from synthetic names, `FileId`, textual module names, or incidental map
order.
Project init is excluded from file-init fragments and runs exactly once. Common
derived identities are neutral and deterministic. Common code must not import
PBS packages or inspect `__pbs.*` prefixes. Typed roles, ids, and origins are
the stable inspection surface; synthetic names are internal.
## Final Implementation
PBS now emits per-file lifecycle contributions and a project-level declaration.
A colocated `[Init]` is the project-init reference only. File-init fragments
remain frontend-lowered executables, consumed by id and role rather than by
name prefix. `synthesizePublishedLifecycle` was removed.
The common assembler validates the declaration and materializes:
1. module init callables in declared module/file order;
2. an optional project-init wrapper, invoked once;
3. the published frame wrapper, which is the physical entrypoint;
4. a hidden boot guard that prevents a second bootstrap after success.
The declaration remains on the assembled `IRBackend` as provenance. IRVM
lowering keeps only assembled-graph preconditions such as wrapper identity,
synthetic origin, and boot-guard presence. It does not reconstruct lifecycle
from names.
`analyze()` still returns a fully assembled executable backend, without IRVM,
bytecode, or file output. Neutral names use the `__prometeu.lifecycle.*` prefix.
Diagnostics stay split: PBS reports marker, signature, placement, cardinality,
and colocation errors; the common layer reports unresolved ids, incompatible
roles, missing frame root, invalid origins, and frontend-preassembled derived
artifacts.
## Examples
Good frontend output:
- a file with globals or a non-project `[Init]` contributes a
`FILE_INIT_FRAGMENT`;
- the `[Init]` next to `[Frame]` is `PROJECT_INIT` only;
- `[Frame]` is `FRAME_ROOT`;
- module order follows the resolved dependency graph even when names or file
ids would sort the other way.
Good assembled output:
- wrapper call order is module inits, then project init once, then frame root;
- boot guard is a hidden global, not a user global;
- `getLifecycleDeclaration()` still exposes the original typed references.
Bad output:
- PBS emitting `MODULE_INIT`, `PROJECT_INIT` wrappers, published wrappers, or
boot guards;
- common code matching `__pbs.frame_wrapper$m0` to discover the entrypoint;
- sorting modules by `FileId` or textual path because the declaration order was
inconvenient;
- leaving both the PBS assembler and the common stage active.
## Pitfalls
- Do not treat `analyze()` as "frontend only." It now includes common lifecycle
assembly so callers still receive an executable `IRBackend`.
- Do not keep a temporary dual path. Two assemblers duplicate wrappers or init.
- Do not infer missing frame roots or repair invalid declarations in the common
layer. Fail deterministically.
- Do not move PBS marker rules into the assembler. Language admission stays in
PBS; structural handoff checks stay common.
- Do not preserve `__pbs.*` names for common-derived artifacts as compatibility
behavior. They were never a public ABI.
- Do not confuse a frontend file-init fragment name with a common-derived
identity. PBS may still name its own fragments; common code must not parse
those names.
## References
- Decision: `DEC-0046`
- Plan: `PLN-0125`
- Related lessons: `LSN-0059`, `LSN-0060`
- `docs/specs/compiler/23. Compiler Pipeline Entry Points Specification.md`
- `docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md`
- `docs/specs/compiler/22. Backend Spec-to-Test Conformance Matrix.md`
- `docs/specs/compiler-languages/pbs/4. Static Semantics Specification.md`
- `docs/specs/compiler-languages/pbs/9. Dynamic Semantics Specification.md`
- `docs/specs/compiler-languages/pbs/12. Diagnostics Specification.md`
- `docs/specs/compiler-languages/pbs/13. Lowering IRBackend Specification.md`
- `prometeu-compiler/prometeu-frontend-api/src/main/java/p/studio/compiler/models/IRLifecycleDeclaration.java`
- `prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler/lifecycle/LifecycleAssemblerService.java`
- `prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler/workspaces/stages/AssembleLifecyclePipelineStage.java`
@@ -0,0 +1,129 @@
---
id: LSN-0063
ticket: multi-frontend-validation-boundaries
title: Language vs platform validation ownership
created: 2026-09-19
tags: [compiler, compiler-general, compiler-pbs, backend, validation, multi-frontend]
---
# Language vs platform validation ownership
## Original Problem
PBS mixed two kinds of rejection. Some failures only make sense with the
language: syntax, types, markers, barrel files, imports. Others belong to any
executable frontend: malformed `IRBackend`, invalid lifecycle declarations,
missing assembled wrappers, host-capability identity, bytecode/preload.
Without an ownership rule, the next frontend would copy PBS validators, or the
common layer would start knowing `[Init]`, barrel, and `E_SEM_*`. Spec 19 was
still titled as PBS verification, and the PBS diagnostics catalog listed
wrapper and boot-guard failures as PBS coverage.
Lifecycle assembly had already moved (`LSN-0062`). That proved the pattern. It
did not inventory the rest.
## Consolidated Decision
A validation lives at the lowest layer that understands the failure without
knowing the source language.
- Language: needs AST, tokens, a language marker, a barrel, or another source
rule.
- Platform: can be checked on `IRBackend`, `IRLifecycleDeclaration`, IRVM, PBX,
host/capability tables, or ids.
The discussion published that matrix. It did not extract a generic
validator-core and did not move validators whose common contract is not closed.
Host admission is split. PBS owns the source shape of `[Host]` and
`[Capability]`. Platform owns canonical `(module, name, version)` identity and
capability consistency once those facts exist on `IRReservedMetadata`. The
current validator may stay in the PBS package until a later plan. `E_HOST_*`
is not eternal PBS semantics.
The same fact may exist on both sides with distinct identities. PBS can report
`E_SEM_MISSING_PROJECT_FRAME`; the common layer still rejects an executable
declaration with no frame root.
Platform codes are `COMMON_*`, `LOWER_IRVM_*`, or `MARSHAL_*`. PBS keeps
`E_PARSE_*`, `E_SEM_*`, `E_LINK_*`, and `E_HOST_*`. Copy origin/span when
present; a missing origin is a structural error, not a reason to invent a span.
Linking and barrel stay language-owned. `Addressable` is platform-owned and was
classified only. SDK canonical source and the broad architectural harness stay
on adjacent discussions.
## Final Implementation
The work was editorial and test-facing.
Spec 19 is now `Compiler Verification and Safety Checks Specification`. Gates
S-U and S-I are unchanged. Section 11 states the classification rule, the
English ownership matrix, diagnostic identity, dual reporting, and the
host-admission split. It explicitly refuses validator-core extraction and
package moves.
PBS diagnostics spec 12 keeps marker, syntax, semantics, linking, and
host-attribute coverage. Common structural failures now point at spec 19
section 11 and spec 20 instead of appearing as PBS required coverage.
Spec 20 cross-references that same compiler-general ownership. The conformance
matrix added `G19-11.1` through `G19-11.6` and `PBS12-11`.
`CommonBackendArchitectureTest` now guards `backend/`, `lifecycle/`, and all
common pipeline stages. `ValidationOwnershipSpecTest` locks the title, matrix,
and PBS recut.
`PbsHostAdmissionValidator` remains under `p.studio.compiler.pbs`. No linking
or asset production code moved.
## Examples
Language-owned:
- parse errors;
- `[Init]` / `[Frame]` signature and colocation;
- barrel and import failures;
- `host call not allowed during init`.
Platform-owned and already implemented:
- invalid `IRLifecycleDeclaration`;
- assembled wrapper, boot guard, and synthetic origin preconditions;
- IRVM and marshal rejection families.
Classified as platform, not moved:
- canonical host-binding identity on `IRReservedMetadata`;
- `Addressable` / asset path.
Dual reporting:
- missing `[Frame]` in PBS source is `E_SEM_MISSING_PROJECT_FRAME`;
- an executable declaration without frame root is a common structural error.
## Pitfalls
- Do not treat “classified as platform” as “move the class now.” Host admission
still waits on the SDK source discussion.
- Do not merge language and platform failures into one hybrid code. Two
identities are cheaper than a lost message.
- Do not put PBS governance or PBS diagnostics in charge of compiler-general
safety gates.
- Do not scan PBS frontend sources with the platform architecture guard. The
guard is for common validators, not for the language package that must remain.
- Do not invent a validator-core because several common checks exist. They
already live on their stages.
## References
- Decision: `DEC-0047`
- Plan: `PLN-0126`
- Related lesson: `LSN-0062` - Common lifecycle assembly after frontend declaration
- Related lesson: `LSN-0059` - Common IRBackend handoff and backend guardrails
- `docs/specs/compiler/19. Verification and Safety Checks Specification.md`
- `docs/specs/compiler-languages/pbs/12. Diagnostics Specification.md`
- `docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md`
- `docs/specs/compiler/22. Backend Spec-to-Test Conformance Matrix.md`
- `prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/specs/ValidationOwnershipSpecTest.java`
- `prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/specs/CommonBackendArchitectureTest.java`
@@ -0,0 +1,121 @@
---
id: LSN-0064
ticket: multi-frontend-sdk-canonical-definition
title: Runtime owns console ABI; PBS is delivery
created: 2026-09-19
tags: [compiler, compiler-general, sdk, stdlib, hostcalls, intrinsics, multi-frontend]
---
# Runtime owns console ABI; PBS is delivery
## Original Problem
"SDK" mixed three layers: platform ABI, PBS stdlib shells, and docs. The PBS
compiler reads `[Host]` and `[IntrinsicCall]` from `.pbs` files. It does not
read the runtime registry. Intrinsics already had a CSV in the runtime
repository, a handwritten Java enum, and a disabled parity test. Spec 8
documented `audio` and `@core:math`. Disk had `game/stdlib/1` with `color`,
`asset`, `composer`, `gfx`, `input`, and `log`. Spec 18 preferred `@sdk:*` for
host APIs while `@sdk:input` was a builtin.
There is no second language in this phase. The risk was not a missing generic
SDK. The risk was treating PBS shells, or a stale spec, as console ABI.
DEC-0047 had already classified canonical host identity as platform-owned and
left `PbsHostAdmissionValidator` in the PBS package until a shared source
existed.
## Consolidated Decision
This discussion was an audit. It published an authority map. It did not create
a canonical schema, generate bindings, enable intrinsic parity, or move the
host-admission validator.
The console has two distinct axes:
- VM-owned intrinsics, identity `canonical_name@version` plus `final_id`;
- host-backed calls, identity `(module, name, version)` plus capability.
Do not unify those axes into one catalog while PBS is the only frontend.
Conflict resolution:
- Intrinsic conflict: `runtime/docs/vm-arch/INTRINSICS.csv` wins. Studio
`docs/vm-arch/INTRINSICS.csv` is a mirror. `IRVMIntrinsicDefinition` is
derived. PBS `[BuiltinType]` / `[IntrinsicCall]` shells are delivery.
- Host conflict: runtime spec 16 and `SyscallMeta` win. PBS `[Host]` attributes
must not define ABI. They declare the shell the PBS compiler reads today.
`@sdk:*` / `@core:*` paths must not imply ownership. `@sdk:input` is a
registered builtin exception. It was not moved to `@core`.
PBS conformance means PBS shells and docs match runtime ABI, not the reverse.
`PbsHostAdmissionValidator` may stay in the PBS package. `E_HOST_*` is not
eternal PBS semantics.
## Final Implementation
The work was editorial and test-facing.
Spec 18 now states that PBS stdlib is delivery and must not define syscall IDs,
intrinsic `final_id` values, or `SyscallMeta`. Runtime catalogs outrank it.
`@sdk:input` is recorded as the current builtin exception.
Spec 8 now documents `<target>/stdlib/<N>/...` with current line `1` at
`game/stdlib/1`: `core/color` and `sdk/{asset,composer,gfx,input,log}`. It no
longer ships `audio` or `@core:math` as current modules.
Spec 6.2 now requires PBS host shells to repeat the runtime registry and forbids
inventing `(module, name, version)`. The authority example is
`("gfx2d", "clear", 1)`.
`ConsoleAbiAuthoritySpecTest` locks those sentences. No production compiler
code, stdlib `.pbs`, or validator package moved. The intrinsic parity test
stays disabled.
## Examples
Runtime wins:
- `color.rgb@1` / `final_id` `0x1101` come from `INTRINSICS.csv`;
- `("gfx2d", "clear", 1)` and `("asset", "load", 1)` come from `SyscallMeta`.
PBS delivers, and does not own, those identities:
- `@core:color` with `[BuiltinType(name = "color", version = 1)]`;
- `@sdk:gfx` `LowGfx.clear` with `[Host(module = "gfx2d", name = "clear", version = 1)]`;
- `@sdk:input` with `[BuiltinType]` / `[IntrinsicCall]` under `@sdk`.
Stale docs that the recut removed as current line-1 inventory:
- `stdlib/1/sdk/audio`;
- `@core:math` as a packaged module.
## Pitfalls
- Do not treat PBS stdlib as the ABI catalog because the compiler already reads
it. That is convenience, not authority.
- Do not create `HOSTCALLS.csv` or generate the Java enum because the map now
exists. A catalog waits on a second consumer.
- Do not move `PbsHostAdmissionValidator` on the strength of this map. DEC-0047
classified identity as platform; this discussion published who wins; the
validator still has no shared catalog to consume.
- Do not read `@sdk` as host and `@core` as VM. Path is packaging. `@sdk:input`
is builtin.
- Do not enable `IRVMIntrinsicRegistryParityTest` as a side effect of a doc
recut. That is compiler/runtime sync, not PBS packaging conformance.
- Do not put the authority map only in a decision. Housekeep deletes workflow
artifacts. Specs and this lesson keep the map.
## References
- Decision: `DEC-0048`
- Plan: `PLN-0127`
- Related lesson: `LSN-0063` - Language vs platform validation ownership
- Related lesson: `LSN-0061` - PBX is the language-neutral runtime boundary
- `docs/specs/compiler/18. Standard Library Surface Specification.md`
- `docs/specs/compiler-languages/pbs/8. Stdlib Environment Packaging and Loading Specification.md`
- `docs/specs/compiler-languages/pbs/6.2. Host ABI Binding and Loader Resolution Specification.md`
- `docs/vm-arch/README.md`
- `../runtime/docs/vm-arch/INTRINSICS.csv`
- `../runtime/docs/specs/runtime/16-host-abi-and-syscalls.md`
- `prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/specs/ConsoleAbiAuthoritySpecTest.java`
@@ -0,0 +1,136 @@
---
id: LSN-0061
ticket: multi-frontend-pvm-neutrality
title: PBX is the language-neutral runtime boundary
created: 2026-09-18
tags: [vm-arch, runtime, pvm, pbx, compiler, multi-frontend]
---
# PBX is the language-neutral runtime boundary
## Original Problem
PBS was the first implemented frontend, so its name still appeared in a few
common compiler specification titles. That editorial residue made it easier to
misread the architecture as if PBS owned bytecode, IRVM, or the PVM execution
model.
The implementation was already mostly neutral: the compiler emitted PBX, the
runtime loaded PBX, and the common backend did not import PBS frontend packages.
The real risk was future drift. In particular, IRVM could be mistaken for a
runtime input, `PBS\0` could be confused with the executable magic, and duplicated
VM-architecture documents could silently become competing authorities.
## Consolidated Decision
The executable pipeline is:
```text
language frontend -> IRBackend -> IRVM -> PBX -> loader/verifier -> PVM
```
`IRBackend`, `IRVM`, optimization, and PBX emission are compiler-owned.
`IRVM` is an internal compiler representation and never crosses the runtime
boundary. PBX is the only executable artifact consumed by the runtime.
The runtime repository owns PBX binary layout, Core ISA, loader behavior,
verification, and PVM execution. Studio owns the common compiler transformations
that produce conforming PBX. Studio copies of VM-architecture documents are
mirrors, not independent authorities.
`PBS` names a language, frontend, stdlib, and explicitly language-specific
integration. It does not name the executable format, magic, ISA, ABI, program
image, or runtime type. The canonical persisted artifact is `program.pbx`, and
its binary magic is `PBX\0`.
## Final Implementation
The common compiler specifications now identify bytecode/PBX and IRVM
optimization as language-neutral surfaces. They explicitly state that IRVM is
internal to the compiler and that PBX is the compiler/runtime boundary. Existing
PBS references were retained where they describe legitimate frontend-specific
publication or metadata behavior.
Studio's copies of `ARCHITECTURE.md`, `ISA_CORE.md`, and `INTRINSICS.csv` were
synchronized with the runtime repository. A mirror policy now identifies the
runtime repository as canonical and provides byte-for-byte comparison commands.
Existing Studio tests already proved two important invariants:
- `BytecodeModule` serializes the exact `PBX\0` header;
- common backend contracts neither import nor publicly expose PBS frontend
types.
Runtime conformance was strengthened in three focused places:
- the bytecode invalid-magic regression now explicitly proves that legacy
`PBS\0` is rejected;
- the PVM initialization regression now creates a `BytecodeModule` directly,
serializes it, loads and verifies it, prepares the boot call, and executes it
through `HALT` without any frontend;
- a quality check inspects the `prometeu-bytecode` and `prometeu-vm` manifests
and rejects dependencies whose identities belong to compiler or frontend
layers.
No production VM behavior, ISA, ABI, or binary format changed.
## Examples
Language-specific work stops before the common backend:
```text
PBS AST and semantic model
-> PBS lowering
-> neutral IRBackend data
-> common IRVM lowering and optimization
-> PBX\0
```
A future frontend follows the same boundary:
```text
FutureLanguage AST and semantic model
-> FutureLanguage lowering
-> neutral IRBackend data
-> the same common IRVM and PBX stages
```
The runtime sees the same PBX contract in both cases. It does not receive a
`languageId`, source extension, AST object, IRVM object, or frontend service.
## Pitfalls and Anti-Patterns
- Do not expose IRVM as a convenient runtime protocol. It is optimized for
compiler transformations, not binary compatibility or runtime loading.
- Do not rename PBX concepts after the first frontend. `PBS\0` is invalid even
when PBS produced the program.
- Do not globally ban the word `PBS` from runtime documentation. PBS is a valid
guest-language example; guards should inspect dependencies, public types, and
format identities instead of raw text.
- Do not duplicate tests when an existing guard proves the entire invariant.
Extend coverage only for the missing distinction, such as explicit `PBS\0`
rejection.
- Do not let a documentation mirror become a second authority. Synchronize it
against runtime or replace it with an explicit reference.
- Loading a PBX image is not the same as beginning execution. The PVM boot test
must prepare the published boot call before running the instruction budget.
## References
- `docs/specs/compiler/15. Bytecode and PBX Mapping Specification.md`
- `docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md`
- `docs/specs/compiler/21. IRVM Optimization Pipeline Specification.md`
- `docs/vm-arch/README.md`
- `prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler/backend/bytecode/BytecodeModule.java`
- `prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/specs/CommonBackendArchitectureTest.java`
- Runtime: `crates/console/prometeu-bytecode/src/model.rs`
- Runtime: `crates/console/prometeu-vm/src/virtual_machine.rs`
- Runtime: `crates/dev/prometeu-quality-checks/tests/pvm_frontend_neutrality.rs`
## Takeaways
- PBX is the stable, language-neutral executable boundary.
- IRVM stays private to the compiler pipeline.
- Runtime authority and compiler authority are complementary, not competing.
- Small dependency and artifact tests are enough to protect this boundary
without introducing a plugin platform or a second language.
@@ -0,0 +1,148 @@
---
id: LSN-0065
ticket: multi-frontend-synthetic-test-frontend
title: Synthetic test frontend proves common pipeline neutrality
created: 2026-09-19
tags: [compiler, compiler-general, frontend, tests, backend, multi-frontend]
---
# Synthetic test frontend proves common pipeline neutrality
## Original Problem
The common pipeline already had `FrontendProvider`, `IRBackend` as the
executable handoff, common lifecycle assembly, and `IRBackend -> IRVM -> PBX`.
Direct construction tests proved the backend could lower a handmade
`IRBackend`. Import guards proved common backend code did not depend on PBS
packages.
That was not enough. Nothing proved that a second provider, resolved by
`languageId`, could enter through `DiscoverPhase` and
`FrontendPhasePipelineStage`, assemble lifecycle, and finish
`BuilderPipelineService.compile()` at verified bytecode without instantiating
PBS, reading `.pbs` files, or loading PBS stdlib.
`CompileOnlyFrontendProvider` already existed as a local test double. It was
not registered, returned an empty `IRBackend`, and never called the pipeline.
It did not close this gap.
## Consolidated Decision
Pipeline neutrality is proved by a **test-only** compile-only
`FrontendProvider`, not by a second product language and not by injecting IR
into compile stages.
Locked shape (former Option A):
- `languageId` is `synth`.
- The provider and `FrontendPhaseService` live only in
`prometeu-build-pipeline` test sources.
- `languageService()` is empty. There is no parser, grammar, semantic
presentation, or stdlib catalog.
- `sourceRoots` is `src`. `allowedExtensions` must not collide with `pbs` /
`barrel`. The fixture must **not** create a source file of that extension.
An empty `src/` directory must still exist because `WireProjectsPhase`
resolves `toRealPath()`.
- The compiler ignores source text and emits one module, one `frame` body
that is a single `RET`, and an `IRLifecycleDeclaration` with exactly one
`FRAME_ROOT` whose origin span is filled.
- The handoff must not declare `FILE_INIT_FRAGMENT` or `PROJECT_INIT`, and
must not pre-materialize wrappers, module-init, or `BOOT_GUARD`. The common
assembler produces `__prometeu.lifecycle.frame_wrapper$mN` and the boot
guard.
- The IR must not contain host bindings, capabilities, intrinsics, PBS types,
PBS stdlib, or `__pbs.` names.
The acceptance path is `compile()` through `VerifyBytecode`. Writing
`program.pbx` is not the criterion. `build()` only adds disk I/O.
Registration stays on the existing static `FrontendRegistryService`.
`register` and `unregister` are public. `unregister` refuses to remove the
default PBS provider and is a no-op for unknown ids. Tests register `synth`
for the duration of the run and unregister in `try/finally`.
`bootstrapDefaults()`, `AppContainer`, and the Studio language catalog must
not register `synth`.
Do not inject a `Registry` into the pipeline, add a `frontends/synth` module,
scan the classpath, or treat a dummy on-disk extension as a language. Do not
replace `LifecycleAssemblerServiceTest`, `LowerToIRVMServiceTest`, or
`IRBackendExecutableContractTest` with this fixture.
A blank `prometeu.json` `language` field still defaults to PBS. The synthetic
project must set `language: synth` explicitly.
## Final Implementation
`FrontendRegistryService.register(FrontendProvider)` is the explicit
registration API. `unregister(String languageId)` removes a non-PBS provider
or no-ops if the id is absent. Duplicate `register` still fails.
`bootstrapDefaults()` still registers only PBS.
The test fixture is:
- `p.studio.compiler.synth.SyntheticFrontendProvider`
- `p.studio.compiler.synth.SyntheticFrontendPhaseService`
`SyntheticFrontendPipelineTest` writes a temporary project
(`language: synth`, `target: Game`, numeric `stdlib`, empty `src/`),
registers the provider, calls `BuilderPipelineService.compile()`, and
asserts:
- the synthetic compiler ran;
- resolved `languageId` is `synth`, not `pbs`;
- diagnostics have no errors;
- in-memory bytecode is non-empty and verified;
- assembled entrypoint is `__prometeu.lifecycle.frame_wrapper$m0`;
- a hidden boot guard is present;
- no `__pbs.` names;
- no `.pbs` / `.barrel` sources were required;
- after `unregister`, `listProviders()` is PBS-only.
Spec 23 section 8.3 records that a compile-only registered provider is a
valid pipeline participant and that the common pipeline must not require PBS
types, PBS sources, or PBS stdlib to emit verified bytecode. Spec 22 row
`G23-8.3` binds that obligation to the synthetic pipeline test.
PBS production code, Studio, and `AppContainer` were not changed.
## Examples
Good:
- register `synth`, compile a temp project with empty `src/`, unregister;
- `FRAME_ROOT` with `FileId(0)` and a non-none span, even with no source file
in `FileTable`;
- assert the synthetic compiler was invoked instead of importing
`PBSFrontendPhaseService` from build-pipeline tests.
Bad:
- omitting `language` in the manifest so discovery silently uses PBS;
- creating `main.dummy` and calling that a second frontend;
- putting the provider under `prometeu-compiler/frontends/`;
- leaving `synth` registered after the test so later tests see two providers;
- using this pipeline test as a substitute for assembler or IRVM unit tests.
## Pitfalls
- `WireProjectsPhase` still needs `src/` on disk. Empty is not the same as
missing.
- Origin span `Span.none()` is rejected by the assembler. Use a real
`FileId` even when no file was loaded.
- `unregister("pbs")` must fail. A cleanup path that blindly unregisters the
resolved language would delete the product default.
- `listProviders()` feeds the Studio catalog. A leaked test registration
would show `synth` as a new-project language.
- Direct `IRBackend` construction tests still own backend-only proofs. The
synthetic frontend owns the registry-plus-pipeline proof. Keep both.
## References
- Decision: `DEC-0049`
- Plan: `PLN-0128`
- Related lessons: `LSN-0055`, `LSN-0056`, `LSN-0059`, `LSN-0062`, `LSN-0061`
- `docs/specs/compiler/23. Compiler Pipeline Entry Points Specification.md`
- `docs/specs/compiler/22. Backend Spec-to-Test Conformance Matrix.md`
- `prometeu-compiler/prometeu-frontend-registry/src/main/java/p/studio/compiler/FrontendRegistryService.java`
- `prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/synth/SyntheticFrontendProvider.java`
- `prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/integration/SyntheticFrontendPipelineTest.java`
@@ -0,0 +1,151 @@
---
id: LSN-0066
ticket: multi-frontend-architectural-tests
title: ArchUnit guards Java multi-frontend boundaries
created: 2026-09-19
tags: [compiler, compiler-general, studio, frontend, architecture, tests, multi-frontend]
---
# ArchUnit guards Java multi-frontend boundaries
## Original Problem
The multi-frontend boundaries already existed in specs and lessons: common
code selects a frontend by `languageId`, `IRBackend` is language-neutral,
lifecycle assembly is common, and PBS is one provider. The automated
protection did not match that model.
The old guards walked Java source and searched for substrings:
- `import p.studio.compiler.pbs`
- `new PBSFrontendPhaseService(`
- `new PbsEditorialSupportService(`
Those checks missed field, signature, and constructor coupling. They also
treated `p.studio.compiler.pbs` as the whole PBS surface. Facades such as
`PBSFrontendProvider`, `PBSDefinitions`, and `PBSFrontendPhaseService` live
in the PBS module but not in that package. `prometeu-app` and
`prometeu-lsp-v1` declared an `implementation` dependency on PBS without
importing any PBS type.
## Consolidated Decision
Java multi-frontend boundaries are enforced by **ArchUnit + JUnit 5**, not by
source substring search, except for the `__pbs.` literal scan that bytecode
cannot see.
Durable locks from DEC-0050:
- ArchUnit is test-only, pinned in `gradle/libs.versions.toml`.
- Rules live in the test-only Gradle project `:prometeu-architecture-tests`.
That project has no production sources. It is not a plugin loader.
- A PBS type is a class whose bytecode originates from
`:prometeu-compiler:frontends:prometeu-frontend-pbs`. Package
`p.studio.compiler.pbs` is not the complete boundary. Name prefixes
`PBS*` / `Pbs*` are not the identity.
- Production may depend on PBS types only in:
- the PBS module itself;
- `prometeu-frontend-registry` / `FrontendRegistryService`, and only on
`PBSFrontendProvider` and `PBSDefinitions`.
- `AppContainer` is not a PBS composition root. It may call
`FrontendRegistryService.bootstrapDefaults()`. It must not instantiate PBS
types.
- `synth` is not in the production allowlist and must not be registered in
`bootstrapDefaults()`.
- Runtime, PVM, and the Rust repository stay out of this discussion
(LSN-0061).
- `IRBackendExecutableContractTest` remains the public-contract shape audit.
ArchUnit covers module-origin dependence.
Do not migrate PBS facades into another package just to make the test
easier. Do not ban the word `PBS` in docs, fixtures, or comments.
## Final Implementation
`:prometeu-architecture-tests` imports production classes under `p.studio`
with `ImportOption.DoNotIncludeTests` and applies three ArchUnit rules:
1. classes outside the PBS module and the registry must not depend on
PBS-module types;
2. registry production may depend only on `PBSFrontendProvider` and
`PBSDefinitions` from that module;
3. frontend-api `p.studio.compiler.models` must not depend on PBS-module
types.
A separate JUnit test walks `build.gradle.kts` files and allows the PBS
project dependency only for:
- `:prometeu-compiler:prometeu-frontend-registry` as `implementation`/`api`;
- `:prometeu-architecture-tests` as `testImplementation` (needed to classify
class origin).
The `__pbs.` source scan moved to
`CommonBackendPbsPrefixScanTest` and still covers `backend/`, `lifecycle/`,
and `workspaces/stages/`.
Gradle graph cleanup:
- `prometeu-app` and `prometeu-lsp-v1` no longer `implementation` PBS.
Runtime classloading of `PBSFrontendProvider` still comes through the
registry's implementation dependency.
- `prometeu-studio` no longer `testImplementation` PBS. No studio test
compiled against PBS types.
Source-walk import/constructor tests were deleted.
`FrontendProviderBoundaryTest` keeps only
`compileOnlyFrontendProviderMayOmitLanguageService`.
Specs 19 §11 and 20 now say common/platform code must not depend on types
from the PBS frontend module. Matrix rows G19-11.6, G20-4.1.2, and G20-4.3.3
point at the ArchUnit rules and the `__pbs.` scan.
## Examples
Good:
- ArchUnit failure names the class that depends on a PBS-module type,
including a facade in package `p.studio.compiler`.
- Registry `bootstrapDefaults()` constructs `PBSFrontendProvider`. That is
the allowed composition root.
- App calls `FrontendRegistryService.bootstrapDefaults()` and has no PBS
project dependency.
Bad:
- Searching source for `import p.studio.compiler.pbs` and calling the
boundary protected.
- Treating `AppContainer` as the place that may `new PBSFrontendProvider()`.
- Identifying PBS by class name prefix, so a future `PbsLike` helper in
common code is banned or a PBS facade is missed.
- Adding ArchUnit to `java-common-conventions` for every module.
## Pitfalls
- Same Java package does not mean same Gradle module.
`FrontendRegistryService` and `PBSFrontendProvider` both sit in
`p.studio.compiler`. Origin is the module path or JAR name.
- `@AnalyzeClasses` classes must not mix `@ArchTest` and Jupiter `@Test` on
the same class. The ArchUnit engine owns `@ArchTest`.
- `DoNotIncludeTests` is required. The architecture-test sources themselves
reference PBS types in order to name the allowlist.
- Removing PBS from app/lsp compile classpath is safe only because registry
still `implementation`s PBS, which is runtime-transitive.
- `testImplementation` of PBS on studio is not a production leak, but if no
studio test needs PBS types it is still a lying graph. The allowlist test
rejects it.
- Do not point ArchUnit at the Rust runtime. `__pbs.` in Java source is a
string contract, not a type dependency.
## References
- Decision: `DEC-0050`
- Plan: `PLN-0129`
- Related lessons: `LSN-0055`, `LSN-0059`, `LSN-0062`, `LSN-0063`,
`LSN-0061`, `LSN-0065`
- `docs/specs/compiler/19. Verification and Safety Checks Specification.md`
- `docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md`
- `docs/specs/compiler/22. Backend Spec-to-Test Conformance Matrix.md`
- `prometeu-architecture-tests/src/test/java/p/studio/architecture/PbsModuleBoundaryArchTest.java`
- `prometeu-architecture-tests/src/test/java/p/studio/architecture/PbsGradleDependencyAllowlistTest.java`
- `prometeu-compiler/prometeu-frontend-registry/src/main/java/p/studio/compiler/FrontendRegistryService.java`
- `prometeu-compiler/prometeu-frontend-api/src/test/java/p/studio/compiler/models/IRBackendExecutableContractTest.java`
@@ -1,78 +0,0 @@
---
id: AGD-0060
ticket: multi-frontend-frontend-backend-contract
title: Estabilizar contrato entre frontend e backend comum
status: open
created: 2026-07-15
resolved:
decision:
tags: [compiler, compiler-general, compiler-pbs, ir, backend, multi-frontend]
---
# Agenda - Estabilizar o contrato entre frontend e backend
## Objetivo
Domain owner: `compiler/general`, com impacto em `compiler/pbs`.
Definir o limite exato entre frontend e backend para garantir que o backend receba IR comum, e nao AST, tokens, simbolos ou objetos semanticos PBS.
## Contexto atual
As specs citam `IRBackend` como handoff executavel em `docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md` e `docs/specs/compiler-languages/pbs/13. Lowering IRBackend Specification.md`. Testes como `IRBackendExecutableContractTest` e `LowerToIRVMServiceTest` ja sugerem um contrato backend direto.
## Escopo
- Auditar tipos publicos de `IRBackend` e modelos associados.
- Confirmar se a estrutura atual ja representa uma IR comum.
- Identificar qualquer dependencia em AST ou semantica PBS no backend.
## Fora de escopo
- Renomear `IRBackend` por preferencia estetica.
- Redesenhar o lowering para IRVM.
- Implementar serializacao.
## Arquivos e componentes a inspecionar
- `prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler/models/...`
- `prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler/backend/...`
- `prometeu-compiler/frontends/prometeu-frontend-pbs/...`
- `docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md`
- `docs/specs/compiler-languages/pbs/13. Lowering IRBackend Specification.md`
## Alteracoes propostas
Opcao A: manter `IRBackend` e documentar/adaptar o contrato como `Prometeu Frontend IR`.
Opcao B: criar um novo nome de dominio quando houver divergencia real entre modelo atual e fronteira desejada.
Recomendacao inicial: auditar antes de renomear; mudar nomes so quando o modelo atual impedir clareza operacional.
## Estrategia de implementacao
Listar campos e tipos transitivos da IR, classificar cada item como comum ou especifico de PBS, e planejar extracoes pequenas para qualquer vazamento.
## Testes necessarios
- Teste construindo IR comum diretamente sem parser PBS.
- Teste de backend sem imports de packages PBS.
- Teste negativo para tipos AST PBS no contrato publico da IR.
## Criterios de aceitacao
- Backend e testavel com IR montada manualmente.
- Contrato contem modulos, funcoes, tipos, blocos, calls, exports, lifecycle, spans, diagnostics e capabilities em termos neutros.
- Contrato nao contem `PbsExpression`, `PbsStatement`, `PbsToken` ou equivalentes.
## Riscos
- Confundir IR comum com modelo de lowering interno de PBS.
- Quebrar fixtures existentes por mudanca ampla demais.
## Decisoes que devem ser registradas
- Nome normativo do handoff.
- Lista de tipos permitidos no contrato.
- Limite entre spec geral e spec PBS.
@@ -1,76 +0,0 @@
---
id: AGD-0061
ticket: multi-frontend-serializable-ir
title: Manter a IR comum serializavel por design
status: open
created: 2026-07-15
resolved:
decision:
tags: [compiler, compiler-general, ir, backend, serialization, multi-frontend]
---
# Agenda - Manter a IR serializavel por design
## Objetivo
Domain owner: `compiler/general`.
Avaliar se a IR comum pode atravessar futuramente uma fronteira de processo sem redesenho, evitando callbacks, estado global, ciclos e identity equality como parte do contrato.
## Contexto atual
O pipeline atual roda na JVM, mas frontends futuros podem ser externos. O alinhamento proibe escolher JSON, Protobuf, RPC ou processo externo agora; a discussao deve focar no formato dos dados.
## Escopo
- Auditar records/classes da IR comum.
- Identificar referencias a servicos, objetos mutaveis, ciclos e IDs implicitos.
- Definir principios de modelagem: IDs explicitos, listas ordenadas, enums e valores primitivos.
## Fora de escopo
- Implementar codec.
- Serializar a saida do PBS dentro do mesmo processo.
- Escolher wire format.
## Arquivos e componentes a inspecionar
- `prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler/models/...`
- `prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler/backend/...`
- testes `IRBackendExecutableContractTest` e `LowerToIRVMServiceTest`
- docs de specs do compiler geral
## Alteracoes propostas
Opcao A: documentar invariantes de serializabilidade e corrigir apenas vazamentos claros.
Opcao B: criar tipos de ID e spans onde hoje houver identidade textual ou referencias diretas instaveis.
Recomendacao inicial: comecar por auditoria e testes de reflexao leves antes de qualquer migracao estrutural.
## Estrategia de implementacao
Gerar uma lista de tipos publicos da IR, revisar construtores e campos, e propor correcoes incrementais para pontos que impediriam um codec futuro.
## Testes necessarios
- Teste de reflexao sobre campos publicos/record components da IR.
- Teste de determinismo de ordenacao.
- Teste de ausencia de referencias a AST, servicos ou callbacks.
## Criterios de aceitacao
- A IR pode ser descrita como grafo de dados aciclico ou com referencias por ID.
- Nenhuma escolha prematura de wire format e introduzida.
## Riscos
- Overengineering de IDs onde o contrato ainda nao exige.
- Quebrar ergonomia de testes ao tornar todos os objetos verbosos.
## Decisoes que devem ser registradas
- Regras minimas de serializabilidade.
- Tipos de ID que devem existir agora.
- Itens explicitamente adiados para codec futuro.
@@ -1,77 +0,0 @@
---
id: AGD-0062
ticket: multi-frontend-common-lifecycle
title: Extrair lifecycle comum das responsabilidades do frontend PBS
status: open
created: 2026-07-15
resolved:
decision:
tags: [compiler, compiler-general, compiler-pbs, lifecycle, backend, multi-frontend]
---
# Agenda - Extrair o lifecycle do frontend PBS
## Objetivo
Domain owner: `compiler/general`, com impacto em `compiler/pbs`.
Separar declaracao de lifecycle feita por uma linguagem da montagem comum de init, frame, module initializers e entrypoint publicado.
## Contexto atual
As lessons e specs antigas indicam que PBS ja trata lifecycle e wrapper/entrypoint. O alinhamento pede que `PBSFrontendPhaseService` deixe de conter regras universais da plataforma.
## Escopo
- Localizar onde PBS sintetiza ou valida lifecycle.
- Definir contrato comum de `LifecycleDeclaration` ou equivalente.
- Planejar servico comum para validar, ordenar e montar entrypoint.
## Fora de escopo
- Alterar sintaxe PBS.
- Mudar comportamento observavel de projetos existentes.
- Refatorar todo o backend junto da extracao.
## Arquivos e componentes a inspecionar
- `prometeu-compiler/frontends/prometeu-frontend-pbs/...PBSFrontendPhaseService...`
- `prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler/backend/irvm/LowerToIRVMService.java`
- `docs/specs/compiler/16. Runtime Execution and Initialization Specification.md`
- `docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md`
- `docs/specs/compiler-languages/pbs/13. Lowering IRBackend Specification.md`
## Alteracoes propostas
Opcao A: frontend PBS emite declaracoes neutras de lifecycle e backend/common assembler monta o entrypoint.
Opcao B: manter montagem no PBS por enquanto, mas isolar regras comuns em um servico compartilhado chamado pelo PBS.
Recomendacao inicial: extrair primeiro o servico comum com testes de caracterizacao, depois migrar o PBS para produzir apenas declaracoes.
## Estrategia de implementacao
Identificar fixture positiva atual, proteger com teste, criar contrato comum minimo, mover validacoes universais e manter mensagens PBS onde forem sintaxe/semantica da linguagem.
## Testes necessarios
- Lifecycle valido PBS continua gerando mesmo PBX/IRVM.
- Lifecycle ausente ou frame invalido falha no nivel comum quando aplicavel.
- Teste de IR comum com lifecycle sem parser PBS.
## Criterios de aceitacao
- PBS traduz a forma da linguagem para declaracoes neutras.
- Servico comum valida e monta lifecycle da plataforma.
## Riscos
- Mover validacoes PBS-especificas para camada comum por engano.
- Alterar ordem de inicializadores sem perceber.
## Decisoes que devem ser registradas
- Nome e ownership do servico comum.
- Forma canonica das declaracoes de lifecycle.
- Separacao entre erro de linguagem e erro de plataforma.
@@ -1,76 +0,0 @@
---
id: AGD-0063
ticket: multi-frontend-validation-boundaries
title: Separar validacoes de linguagem e validacoes de plataforma
status: open
created: 2026-07-15
resolved:
decision:
tags: [compiler, compiler-general, compiler-pbs, backend, validation, multi-frontend]
---
# Agenda - Separar validacoes de linguagem e plataforma
## Objetivo
Domain owner: `compiler/general`, com impacto em `compiler/pbs`.
Definir onde cada validacao deve viver: PBS para sintaxe e semantica da linguagem; compiler core/backend para entrypoints, exports, hostcalls, capabilities, layouts, IR e bytecode.
## Contexto atual
O PBS concentra parsing, semantica, lowering e algumas validacoes que podem ser universais. O backend ja possui validadores para IRVM, bytecode e precondicoes de lowering.
## Escopo
- Mapear diagnostics e validacoes atuais.
- Classificar cada uma como linguagem ou plataforma.
- Definir regra: colocar a validacao no nivel mais baixo que a compreende sem conhecer a linguagem.
## Fora de escopo
- Reescrever todas as mensagens diagnosticas.
- Mudar codigos de erro sem necessidade.
- Transferir validacoes antes de existir contrato comum suficiente.
## Arquivos e componentes a inspecionar
- `prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/java/p/studio/compiler/pbs/semantics/...`
- `prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler/backend/...`
- `prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/...`
- `docs/specs/compiler/19. Verification and Safety Checks Specification.md`
- `docs/specs/compiler-languages/pbs/12. Diagnostics Specification.md`
## Alteracoes propostas
Opcao A: criar matriz de ownership de validacoes antes de mover codigo.
Opcao B: mover validacoes junto com lifecycle/IR quando cada fronteira for tocada.
Recomendacao inicial: matriz primeiro; migracao so quando uma decisao posterior fechar lifecycle e IR.
## Estrategia de implementacao
Auditar testes de erro existentes, agrupar por origem, decidir ownership e adicionar testes de regressao para impedir que o backend importe PBS.
## Testes necessarios
- Testes PBS para erros de sintaxe/semantica continuam no frontend.
- Testes comuns para IR malformada, hostcall inexistente, export duplicado e lifecycle invalido.
- Teste arquitetural de ausencia de imports PBS em validadores comuns.
## Criterios de aceitacao
- Validacoes da plataforma sao expressas sem conceitos PBS.
- Validacoes PBS continuam preservadas e especificas.
## Riscos
- Perder qualidade de diagnostico ao mover validacao para camada comum.
- Duplicar validacoes em vez de estabelecer ownership.
## Decisoes que devem ser registradas
- Matriz de validacoes e ownership.
- Politica de diagnosticos quando o erro comum ainda precisa de source span de frontend.
@@ -1,78 +0,0 @@
---
id: AGD-0064
ticket: multi-frontend-sdk-canonical-definition
title: Auditoria e centralizacao gradual da definicao canonica do SDK
status: open
created: 2026-07-15
resolved:
decision:
tags: [compiler, compiler-general, sdk, stdlib, hostcalls, intrinsics, multi-frontend]
---
# Agenda - Centralizar a definicao do SDK
## Objetivo
Domain owner: `compiler/general`, com referencias a `compiler/pbs` e `vm-arch`.
Auditar onde hostcalls, intrinsics, tipos fundamentais e APIs do console sao definidos hoje antes de propor uma fonte canonica do SDK.
## Contexto atual
Existem specs em `docs/vm-arch/INTRINSICS.csv`, docs de stdlib em `docs/specs/compiler/18. Standard Library Surface Specification.md`, specs PBS de stdlib e host ABI, alem de possiveis registries em codigo e fixtures.
## Escopo
- Mapear fontes atuais da verdade.
- Identificar definicoes geradas, duplicadas e manuais.
- Propor caminho gradual para um schema canonico.
## Fora de escopo
- Migracao grande do SDK.
- Gerar bindings para C#, Kotlin, TypeScript ou outras linguagens.
- Escolher formato definitivo antes da auditoria.
## Arquivos e componentes a inspecionar
- `docs/vm-arch/INTRINSICS.csv`
- `docs/specs/compiler/18. Standard Library Surface Specification.md`
- `docs/specs/compiler-languages/pbs/5. Manifest, Stdlib, and SDK Resolution Specification.md`
- `docs/specs/compiler-languages/pbs/6.1. Intrinsics and Builtin Types Specification.md`
- `prometeu-compiler/...` registries de hostcalls/intrinsics/stdlib
- runtime/PVM quando presente no workspace ou submodulos relacionados
## Alteracoes propostas
Opcao A: agenda de auditoria pura, produzindo mapa de fontes e duplicacoes.
Opcao B: criar schema canonico minimo depois da auditoria, sem migrar todos os consumidores.
Recomendacao inicial: primeiro fechar auditoria; so uma decision posterior deve escolher formato e migracao.
## Estrategia de implementacao
Listar cada hostcall/intrinsic/tipo fundamental em suas fontes atuais, comparar assinatura, capability, versao e docs, e classificar divergencias.
## Testes necessarios
- Testes de paridade entre registry runtime/backend e specs existentes, se ja houver fonte estruturada.
- Testes de nao divergencia para IDs e assinaturas apos qualquer centralizacao.
## Criterios de aceitacao
- Existe mapa claro de fonte real da verdade.
- Duplicacoes e divergencias ficam registradas.
- Nenhuma migracao ampla e iniciada sem nova decisao.
## Riscos
- Tratar docs como fonte real quando o codigo ja diverge.
- Iniciar geracao antes de saber quem consome cada definicao.
## Decisoes que devem ser registradas
- Fonte canonica proposta.
- Campos obrigatorios do SDK.
- Sequencia de migracao segura.
@@ -1,78 +0,0 @@
---
id: AGD-0065
ticket: multi-frontend-pvm-neutrality
title: Neutralidade da PVM e identificacao PBX independente de PBS
status: open
created: 2026-07-15
resolved:
decision:
tags: [vm-arch, runtime, pvm, pbx, compiler, multi-frontend]
---
# Agenda - Manter a PVM neutra
## Objetivo
Domain owner: `vm-arch`, com impacto em `compiler/general`.
Garantir que a PVM conheca apenas PBX/IRVM e conceitos runtime neutros, incluindo identificacao correta do formato como `PBX`/`PBX\0`, nao `PBS`.
## Contexto atual
O documento e focado no Studio, mas runtime neutrality e uma fronteira transversal. A PVM nao deve conhecer `PBS service`, `PBS struct`, `PBS optional` ou qualquer conceito de linguagem.
## Escopo
- Auditar nomenclatura e imports runtime/PVM disponiveis no repo.
- Verificar magic/header de PBX quando o codigo estiver no workspace.
- Confirmar que linguagem e convertida antes da execucao.
## Fora de escopo
- Modificar a PVM se o acoplamento estiver apenas no Studio ou compiler.
- Alterar ISA sem necessidade.
- Adicionar suporte a qualquer linguagem nova.
## Arquivos e componentes a inspecionar
- `docs/vm-arch/ARCHITECTURE.md`
- `docs/vm-arch/ISA_CORE.md`
- `docs/specs/compiler/15. Bytecode and PBX Mapping Specification.md`
- `prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler/backend/bytecode/...`
- runtime/PVM em repositorio ou modulo relacionado, quando presente
## Alteracoes propostas
Opcao A: auditoria documental e de codigo para nomes PBS indevidos em runtime/bytecode.
Opcao B: corrigir imediatamente apenas identificacao `PBS` vs `PBX` se houver bug confirmado e isolado.
Recomendacao inicial: auditar primeiro; corrigir somente caso a fronteira esteja claramente violada e a mudanca seja pequena.
## Estrategia de implementacao
Buscar termos PBS no runtime, bytecode e specs VM; classificar ocorrencias validas de docs historicas vs erros de contrato.
## Testes necessarios
- Teste de magic/header PBX.
- Teste arquitetural impedindo imports PBS no runtime/PVM.
- Teste de carregamento/verificacao de programa sem dependencia de linguagem.
## Criterios de aceitacao
- PVM nao depende de conceitos PBS.
- Formato executavel e tratado como PBX.
- Qualquer correcao runtime necessaria fica separada de refactors Studio/compiler.
## Riscos
- Confundir nomenclatura documental antiga com acoplamento real.
- Expandir escopo para VM quando o problema pertence ao compiler.
## Decisoes que devem ser registradas
- Lista de conceitos permitidos na PVM.
- Politica de nomenclatura PBX/PBS.
- Onde ficam testes de neutralidade runtime.
@@ -1,77 +0,0 @@
---
id: AGD-0066
ticket: multi-frontend-synthetic-test-frontend
title: Frontend sintetico de teste para provar neutralidade do pipeline
status: open
created: 2026-07-15
resolved:
decision:
tags: [compiler, compiler-general, frontend, tests, backend, multi-frontend]
---
# Agenda - Criar um frontend sintetico de teste
## Objetivo
Domain owner: `compiler/general`.
Discutir um frontend exclusivo de testes que prove que o pipeline comum nao depende implicitamente do PBS.
## Contexto atual
O criterio arquitetural final exige que um frontend sintetico implemente contratos equivalentes a `FrontendProvider`, `FrontendSpec` e `FrontendCompiler`, produza IR comum minima e passe pelo backend ate PBX/verifier.
## Escopo
- Escolher entre frontend totalmente sintetico ou extensao ficticia.
- Definir fixture de IR minima com `frame` vazio.
- Garantir isolamento em testes.
## Fora de escopo
- Expor frontend sintetico no Studio.
- Criar segunda linguagem real.
- Criar parser completo ou grammar dummy complexa.
## Arquivos e componentes a inspecionar
- `prometeu-compiler/prometeu-frontend-registry/...`
- `prometeu-compiler/prometeu-build-pipeline/...`
- testes do build pipeline e backend
- `prometeu-studio/src/main/java/p/studio/projects/...` apenas se a selecao por extensao for exercitada
## Alteracoes propostas
Opcao A: provider sintetico que ignora arquivos e retorna IR minima diretamente.
Opcao B: extensao `.dummy` reconhecida em fixture, com conteudo ignorado ou trivial.
Recomendacao inicial: preferir Opcao A para provar neutralidade do pipeline sem criar outra superficie de linguagem.
## Estrategia de implementacao
Esperar provider/IR/lifecycle estarem suficientemente definidos, entao adicionar fixture de teste que registra provider sintetico e executa pipeline comum sem PBS.
## Testes necessarios
- Provider registrado e resolvido por `languageId`.
- Extensao/source handling testado se a opcao B for escolhida.
- IR comum produzida, lifecycle montado, IRVM gerado, PBX emitido e verificado.
## Criterios de aceitacao
- Teste falha se pipeline comum instanciar PBS implicitamente.
- Synthetic frontend existe apenas em test fixtures.
- PBS nao e afetado.
## Riscos
- Fixture sintetica exercitar caminho feliz pequeno demais e nao proteger acoplamentos reais.
- Virar uma segunda linguagem informal.
## Decisoes que devem ser registradas
- Forma do frontend sintetico.
- Escopo minimo da IR fixture.
- Onde o provider de teste pode ser registrado.
@@ -1,79 +0,0 @@
---
id: AGD-0067
ticket: multi-frontend-architectural-tests
title: Testes arquiteturais para fronteiras multi-frontend
status: open
created: 2026-07-15
resolved:
decision:
tags: [compiler, compiler-general, studio, frontend, architecture, tests, multi-frontend]
---
# Agenda - Criar testes arquiteturais
## Objetivo
Domain owner: `compiler/general`, com impacto em `studio` e `vm-arch`.
Definir testes que protejam fronteiras: backend comum sem PBS, IR comum sem AST PBS, Studio comum sem instanciacao PBS fora do composition root e runtime neutro.
## Contexto atual
O repo ja tem testes Java para backend, bytecode e IRVM. ArchUnit pode ser util, mas o alinhamento proibe adicionar biblioteca arquitetural quando testes simples bastarem.
## Escopo
- Escolher ferramenta minima.
- Definir regras por pacote.
- Adicionar testes que sejam baratos e claros.
## Fora de escopo
- Cobrir toda arquitetura do monorepo.
- Adicionar ArchUnit sem justificativa concreta.
- Bloquear referencias PBS em testes PBS ou no frontend PBS.
## Arquivos e componentes a inspecionar
- `build.gradle.kts` e version catalog se houver.
- `prometeu-compiler/prometeu-build-pipeline/src/test/java/...`
- `prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/...`
- `prometeu-studio/src/test/java/...`
- pacotes runtime/PVM quando presentes
## Alteracoes propostas
Opcao A: testes Java/reflection simples para imports, nomes de tipos e packages publicos.
Opcao B: ArchUnit caso a quantidade de regras e modulos justifique.
Recomendacao inicial: comecar com testes simples; reavaliar ArchUnit se as regras virarem frageis.
## Estrategia de implementacao
Definir allowlist de packages PBS, composition root e testes PBS. Escrever verificacoes independentes por dominio para falhas legiveis.
## Testes necessarios
- Backend/common nao importa `frontend.pbs`, `parser.pbs` ou `semantic.pbs`.
- IR comum nao expoe tipos PBS.
- Studio comum nao instancia servicos PBS fora da allowlist.
- Runtime nao usa nomenclatura ou semantica PBS.
## Criterios de aceitacao
- Regras rodam no build local.
- Falhas apontam arquivo/pacote responsavel.
- Excecoes autorizadas estao documentadas.
## Riscos
- Teste textual produzir falso positivo por docs ou fixtures.
- Criar barreira rigida antes de definir provider e lifecycle.
## Decisoes que devem ser registradas
- Ferramenta escolhida.
- Allowlist de packages.
- Ordem de introducao das regras.
@@ -82,7 +82,8 @@ The following inputs are already fixed elsewhere and must not be contradicted he
- Stable source span metadata is required at the token level and must remain useful to later diagnostics. - Stable source span metadata is required at the token level and must remain useful to later diagnostics.
- Traps are fatal runtime outcomes rather than a recoverable userland diagnostic flow. - Traps are fatal runtime outcomes rather than a recoverable userland diagnostic flow.
- Qualitative cost facts such as retention-bearing operations and host-boundary crossings are normative, but quantitative performance metrics are not. - Qualitative cost facts such as retention-bearing operations and host-boundary crossings are normative, but quantitative performance metrics are not.
- Topic `19` requires deterministic diagnostics for globals, lifecycle markers, init admission, and published-wrapper structural failures. - PBS requires deterministic diagnostics for source-form globals, lifecycle markers, and init admission.
- Published-wrapper, boot-guard, synthetic-origin, and invalid-lifecycle-declaration failures are compiler-general. See `docs/specs/compiler/19. Verification and Safety Checks Specification.md` section 11 and `docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md`.
## 6. Required Diagnostic Phases ## 6. Required Diagnostic Phases
@@ -97,6 +98,8 @@ PBS-facing tooling must distinguish at least the following external diagnostic p
`linking` is a first-class phase in the external diagnostics contract and must not be collapsed away into a generic resolution bucket. `linking` is a first-class phase in the external diagnostics contract and must not be collapsed away into a generic resolution bucket.
The `host-binding/capability admission` phase covers the source shape of `[Host]` and `[Capability]`. Canonical host-binding identity and capability consistency over `IRReservedMetadata` are platform-owned and are not moved by this specification.
This document does not require one finer-grained public phase split for verifier internals, artifact offsets, or transport-specific backend stages beyond what is stated here. This document does not require one finer-grained public phase split for verifier internals, artifact offsets, or transport-specific backend stages beyond what is stated here.
## 7. Required Diagnostic Identity, Payload, and Attribution ## 7. Required Diagnostic Identity, Payload, and Attribution
@@ -180,7 +183,7 @@ At minimum, the PBS diagnostics baseline must cover:
5. malformed, unauthorized, or capability-rejected host usage required by `6.2. Host ABI Binding and Loader Resolution Specification.md` and `7. Cartridge Manifest and Runtime Capabilities Specification.md`, 5. malformed, unauthorized, or capability-rejected host usage required by `6.2. Host ABI Binding and Loader Resolution Specification.md` and `7. Cartridge Manifest and Runtime Capabilities Specification.md`,
6. source-attributable backend-originated failures that remain user-actionable under normative lowering or load-facing rules. 6. source-attributable backend-originated failures that remain user-actionable under normative lowering or load-facing rules.
7. dependency-scoped fail-fast admission at frontend boundary: when one module is rejected, modules that import it (directly or transitively) must not be emitted, while diagnostics collection for independent modules must continue. 7. dependency-scoped fail-fast admission at frontend boundary: when one module is rejected, modules that import it (directly or transitively) must not be emitted, while diagnostics collection for independent modules must continue.
8. lifecycle and globals diagnostics required by topic `19`, including: 8. lifecycle-marker and source-form global diagnostics, including:
- `global initializer uses unsupported form`, - `global initializer uses unsupported form`,
- `global dependency cycle detected`, - `global dependency cycle detected`,
- `global import must resolve through a global barrel entry`, - `global import must resolve through a global barrel entry`,
@@ -194,16 +197,13 @@ At minimum, the PBS diagnostics baseline must cover:
- `project init must be colocated with frame`, - `project init must be colocated with frame`,
- `Init attribute target invalid`, - `Init attribute target invalid`,
- `InitAllowed is valid only on SDK host methods`, - `InitAllowed is valid only on SDK host methods`,
- `host call not allowed during init`, - `host call not allowed during init`.
- `synthetic wrapper entrypoint missing`, 9. compiler-general lifecycle-assembly and IRVM-precondition failures, which this PBS catalog MUST NOT claim as PBS required coverage; see `docs/specs/compiler/19. Verification and Safety Checks Specification.md` section 11 and `docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md`.
- `published entrypoint is not function index 0`, 10. symbolic asset-reference diagnostics required by backend-owned `Addressable` resolution, including:
- `hidden boot guard is missing`,
- `synthetic callable origin missing`.
9. symbolic asset-reference diagnostics required by backend-owned `Addressable` resolution, including:
- unresolved terminal asset reference, - unresolved terminal asset reference,
- namespace-versus-terminal asset misuse, - namespace-versus-terminal asset misuse,
- structurally invalid symbolic asset path admitted by source syntax but rejected by semantic surface rules. - structurally invalid symbolic asset path admitted by source syntax but rejected by semantic surface rules.
10. ignored-value diagnostics for expression statements, including: 11. ignored-value diagnostics for expression statements, including:
- a stable warning when a materialized value is produced and then ignored, - a stable warning when a materialized value is produced and then ignored,
- and no warning for unit-like expression statements. - and no warning for unit-like expression statements.
@@ -1,13 +1,13 @@
# PBS Lowering IRBackend Specification # PBS Lowering IRBackend Specification
Status: Draft v1 (Frontend Scope + Backend Handoff Addendum) Status: Draft v1 (PBS Frontend Scope + Common Handoff Emission)
Applies to: first lowering boundary from bound PBS frontend model into `IRBackend`/`IRBackendFile`, plus executable-backend handoff obligations at this boundary Applies to: first lowering boundary from bound PBS frontend model into the common `IRBackend`/`IRBackendFile` handoff
## 1. Purpose ## 1. Purpose
This document defines the normative frontend lowering contract from PBS source semantics to `IRBackend`. This document defines the normative frontend lowering contract from PBS source semantics to the common `IRBackend` handoff.
Its purpose is to keep the first lowering deterministic and shared across implementations while PBS and backend design evolve. Its purpose is to keep PBS lowering deterministic while preserving the common frontend-to-backend contract owned by compiler-general backend specs.
## 2. Scope ## 2. Scope
@@ -18,7 +18,7 @@ This document defines:
- semantic obligations preserved in `IRBackend`, - semantic obligations preserved in `IRBackend`,
- deterministic rejection behavior for unsupported frontend-lowering forms, - deterministic rejection behavior for unsupported frontend-lowering forms,
- diagnostics attribution obligations for lowering failures in frontend scope, - diagnostics attribution obligations for lowering failures in frontend scope,
- executable-backend handoff obligations at the `IRBackend` boundary, - PBS obligations for emitting the common executable `IRBackend` handoff,
- and backend-owned symbolic lowering obligations for asset-facing references. - and backend-owned symbolic lowering obligations for asset-facing references.
This document does not define: This document does not define:
@@ -26,7 +26,8 @@ This document does not define:
- VM lowering (`IRVM`), - VM lowering (`IRVM`),
- bytecode/PBX mapping, - bytecode/PBX mapping,
- runtime execution behavior, - runtime execution behavior,
- verifier/loader internals. - verifier/loader internals,
- or common backend ownership of the `IRBackend -> IRVM` contract.
Those concerns belong to shared acceptance specs under `docs/specs/compiler`. Those concerns belong to shared acceptance specs under `docs/specs/compiler`.
@@ -75,9 +76,9 @@ When the active source slice depends on a backend-owned symbolic surface such as
- the frontend must not query domain services directly to discover operational assets; - the frontend must not query domain services directly to discover operational assets;
- and lowering must preserve enough identity for the backend to complete final operational resolution. - and lowering must preserve enough identity for the backend to complete final operational resolution.
## 6. IRBackend Preserved Obligations ## 6. PBS IRBackend Emission Obligations
For each admitted source unit and callable in the current lowering slice, `IRBackend` must preserve at minimum: For each admitted PBS source unit and callable in the current lowering slice, PBS lowering must emit `IRBackend` that preserves at minimum:
1. callable identity (name/category as applicable), 1. callable identity (name/category as applicable),
2. callable arity, 2. callable arity,
@@ -85,14 +86,18 @@ For each admitted source unit and callable in the current lowering slice, `IRBac
4. source attribution anchor (`file + span`) for diagnostics and traceability, 4. source attribution anchor (`file + span`) for diagnostics and traceability,
5. source-observable parse intent for statement/expression structure (including precedence/associativity outcome already fixed by AST shape). 5. source-observable parse intent for statement/expression structure (including precedence/associativity outcome already fixed by AST shape).
6. deterministic `requiredCapabilities` derived from admitted host-binding metadata for packer/runtime-manifest assistance. 6. deterministic `requiredCapabilities` derived from admitted host-binding metadata for packer/runtime-manifest assistance.
7. compiler-selected published-wrapper entrypoint identity for backend handoff, 7. a typed `IRLifecycleDeclaration` for executable programs, with file-init fragment, optional project-init, and required frame-root references,
8. explicit global and synthetic lifecycle structure required by executable lowering. 8. explicit user globals and frontend-lowered file-init fragments required by later common lifecycle assembly,
9. backend-owned symbolic identities that must survive to later executable lowering, including symbolic asset references when admitted by the source slice. 9. backend-owned symbolic identities that must survive to later executable lowering, including symbolic asset references when admitted by the source slice.
PBS lowering MUST NOT emit module init, project-init wrapper, published frame wrapper, physical entrypoint, or boot guard. Those artifacts are produced exclusively by common lifecycle assembly.
Lowering must not collapse source categories in a way that erases required declaration/callable identity needed by downstream diagnostics or conformance assertions. Lowering must not collapse source categories in a way that erases required declaration/callable identity needed by downstream diagnostics or conformance assertions.
The normative contract is obligation-based, not tied to one mandatory in-memory class graph. The normative contract is obligation-based, not tied to one mandatory in-memory class graph.
`IRBackend` itself is the common frontend-to-backend executable handoff. This PBS spec owns only the PBS-specific admission and translation path into that handoff. Common backend rules for consuming `IRBackend` are owned by `docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md`.
## 7. Deterministic Rejection Policy ## 7. Deterministic Rejection Policy
If a source form is outside current frontend-lowering support: If a source form is outside current frontend-lowering support:
@@ -111,7 +116,7 @@ For multi-module builds, lowering admission must apply dependency-scoped fail-fa
## 8. Conformance Boundary ## 8. Conformance Boundary
`IRBackend` is the first lowering boundary (frontend responsibility). PBS emission into `IRBackend` is the first PBS lowering boundary (frontend responsibility).
Conformance-valid claims at this boundary require Gate U evidence from `docs/specs/compiler/13. Conformance Test Specification.md`. Conformance-valid claims at this boundary require Gate U evidence from `docs/specs/compiler/13. Conformance Test Specification.md`.
@@ -148,9 +153,9 @@ This document is healthy when:
3. deterministic rejection policy is explicit and test-backed, 3. deterministic rejection policy is explicit and test-backed,
4. and scope boundaries with general/backend acceptance specs are explicit. 4. and scope boundaries with general/backend acceptance specs are explicit.
## 12. Executable Backend Handoff Addendum (v1) ## 12. PBS Executable Handoff Emission Obligations (v1)
For executable backends, the `IRBackend` output from this frontend boundary must satisfy the additional handoff obligations below. For executable backends, PBS lowering must emit `IRBackend` satisfying the additional handoff obligations below before common backend lowering starts.
### 12.1 Callable obligations ### 12.1 Callable obligations
@@ -170,7 +175,7 @@ Each executable callsite in `IRBackend` must be classified into exactly one cate
2. `CALL_HOST`, 2. `CALL_HOST`,
3. `CALL_INTRINSIC`. 3. `CALL_INTRINSIC`.
Backend lowering must not infer this category by textual heuristics. PBS lowering must not leave this category for backend inference by textual heuristics.
### 12.3 Host-backed metadata obligations ### 12.3 Host-backed metadata obligations
@@ -187,11 +192,11 @@ When a host-backed callsite also depends on backend-owned symbolic asset lowerin
- the frontend boundary MUST preserve which callsite argument is asset-facing; - the frontend boundary MUST preserve which callsite argument is asset-facing;
- for PBS v1 this asset-facing designation is carried by reserved host metadata `[AssetLowering(param = N)]`; - for PBS v1 this asset-facing designation is carried by reserved host metadata `[AssetLowering(param = N)]`;
- the preserved symbolic operand MUST remain attributable to a backend-provided `Addressable` identity; - the preserved symbolic operand MUST remain attributable to a backend-provided `Addressable` identity;
- backend stages MUST be able to rewrite that symbolic operand into runtime-facing `asset_id` before the final low-level host path is emitted. - common backend stages MUST be able to rewrite that symbolic operand into runtime-facing `asset_id` before the final low-level host path is emitted.
When an expression statement leaves a materialized runtime value on the stack: When an expression statement leaves a materialized runtime value on the stack:
- `IRBackend` lowering MUST emit explicit discard behavior rather than relying on implicit backend stack cleanup; - PBS lowering into `IRBackend` MUST emit explicit discard behavior rather than relying on implicit backend stack cleanup;
- for single-slot materialized values this discard is represented by `POP`; - for single-slot materialized values this discard is represented by `POP`;
- and the discard path MUST preserve stack-accounting validity for subsequent backend lowering stages. - and the discard path MUST preserve stack-accounting validity for subsequent backend lowering stages.
@@ -218,20 +223,18 @@ It does not replace:
2. `docs/specs/compiler/21. IRVM Optimization Pipeline Specification.md`, 2. `docs/specs/compiler/21. IRVM Optimization Pipeline Specification.md`,
3. or `docs/specs/compiler/15. Bytecode and PBX Mapping Specification.md`. 3. or `docs/specs/compiler/15. Bytecode and PBX Mapping Specification.md`.
### 12.7 Executable Lifecycle and Published Wrapper Obligation ### 12.7 Executable Lifecycle Declaration Obligation
For executable PBS frontends, backend handoff must preserve the compiler-selected published wrapper rather than a frontend-declared nominal entrypoint. For executable PBS frontends, PBS lowering MUST emit a typed `IRLifecycleDeclaration` rather than assembling the published lifecycle.
At `IRBackend` emission time: At frontend `IRBackend` emission time:
1. the lowered graph must contain explicit lifecycle structure for: 1. PBS MUST retain marker admission for `[Init]`, `[Frame]`, and `InitAllowed`,
- user-authored globals, 2. PBS MUST emit typed references for:
- file init fragments, - file-init fragments that include global materialization and non-project `[Init]`,
- module init, - the optional project-init callable, which is the `[Init]` colocated with `[Frame]`,
- project init when present, - and the required frame-root callable marked with `[Frame]`,
- and the published frame wrapper, 3. the colocated project init MUST be excluded from file-init fragments,
2. the published frame wrapper must be the effective entrypoint identity handed to backend stages, 4. module order in the declaration MUST propagate the explicit dependency order already derived from resolved project/module data, without sorting by `FileId`, textual module name, or synthetic callable name,
3. the userland callable marked with `[Frame]` must remain distinguishable as the logical frame root, 5. PBS MUST NOT emit module init, project-init wrapper, published frame wrapper, physical entrypoint, or boot guard,
4. the wrapper must own final `FRAME_RET`, 6. and common lifecycle assembly remains the owner of derived artifacts, including the published wrapper that becomes the physical entrypoint and owns the final frame return.
5. backend stages must not reintroduce manifest-owned or `FrontendSpec`-owned nominal entrypoint authority,
6. and hidden compiler-owned lifecycle state such as the boot guard must remain structurally distinguishable from user globals.
@@ -250,6 +250,8 @@ Rules:
- A file may declare at most one `[Init]`. - A file may declare at most one `[Init]`.
- The `[Init]` colocated with `[Frame]` is the project init. - The `[Init]` colocated with `[Frame]` is the project init.
- Project init must be colocated with `[Frame]`. - Project init must be colocated with `[Frame]`.
- PBS static semantics and lowering admit those markers and translate them into a typed `IRLifecycleDeclaration`.
- PBS MUST NOT materialize module init, project-init wrapper, published frame wrapper, physical entrypoint, or boot guard; those artifacts belong to common lifecycle assembly.
- `InitAllowed` is valid only on SDK host methods and is invalid on userland `fn`, `global`, `service`, `const`, `struct`, `contract`, and callback surfaces. - `InitAllowed` is valid only on SDK host methods and is invalid on userland `fn`, `global`, `service`, `const`, `struct`, `contract`, and callback surfaces.
- A host method signature in a reserved stdlib/interface module MUST carry exactly one `Host` attribute. - A host method signature in a reserved stdlib/interface module MUST carry exactly one `Host` attribute.
- A host method signature in a reserved stdlib/interface module MUST carry exactly one `Capability` attribute. - A host method signature in a reserved stdlib/interface module MUST carry exactly one `Capability` attribute.
@@ -15,6 +15,10 @@ This document defines the current contract between:
Its purpose is to let compiler and runtime work in parallel without diverging on the most critical boundary: Its purpose is to let compiler and runtime work in parallel without diverging on the most critical boundary:
how host-backed SDK calls become load-time-resolved numeric syscalls. how host-backed SDK calls become load-time-resolved numeric syscalls.
PBS `declare host` / `[Host]` shells are compile-time delivery. The
loader-facing catalog is runtime-owned. This document MUST NOT publish syscall
IDs or `SyscallMeta`.
This document is intentionally narrower than a full PBX or VM specification. This document is intentionally narrower than a full PBX or VM specification.
It focuses on loader behavior and the minimum artifact contract the loader must consume. It focuses on loader behavior and the minimum artifact contract the loader must consume.
@@ -44,16 +48,20 @@ This document does not define:
This document follows two prior decisions: This document follows two prior decisions:
1. Canonical host identity is defined by the hardware ABI as `(module, name, version)`. 1. Canonical host identity is defined by the runtime host registry as `(module, name, version)`.
2. User code does not declare host bindings directly; SDK/toolchain-controlled modules expose reserved `declare host` surfaces and the compiler lowers those usages into PBX host-binding metadata. 2. User code does not declare host bindings directly; SDK/toolchain-controlled modules expose reserved `declare host` surfaces and the compiler lowers those usages into PBX host-binding metadata.
PBS shells MUST repeat identities already published by the runtime registry
(`../runtime/docs/specs/runtime/16-host-abi-and-syscalls.md` and `SyscallMeta`).
They MUST NOT invent `(module, name, version)`.
This document therefore treats: This document therefore treats:
- `declare host Gfx { fn draw_pixel(...); }` - `declare host LowGfx { [Host(module = "gfx2d", name = "clear", version = 1)] fn clear(...); }`
as compile-time surface only, and treats: as compile-time surface only, and treats:
- `("gfx", "draw_pixel", 1)` - `("gfx2d", "clear", 1)`
as the normative runtime-facing identity. as the normative runtime-facing identity.
@@ -63,7 +71,7 @@ The host-binding pipeline is:
1. User code imports SDK surfaces such as `Gfx` from `@sdk:gfx` and `Composer` from `@sdk:composer`. 1. User code imports SDK surfaces such as `Gfx` from `@sdk:gfx` and `Composer` from `@sdk:composer`.
2. The compiler resolves those surfaces against the selected stdlib line. 2. The compiler resolves those surfaces against the selected stdlib line.
3. The compiler maps each host-backed SDK member to a canonical identity `(module, name, version)`. 3. The compiler maps each host-backed SDK member to a canonical identity `(module, name, version)` that already exists in the runtime host registry.
4. The compiler emits those required canonical identities into the PBX `SYSC` table. 4. The compiler emits those required canonical identities into the PBX `SYSC` table.
5. The compiler emits pre-load host call sites as `HOSTCALL <sysc_index>`. 5. The compiler emits pre-load host call sites as `HOSTCALL <sysc_index>`.
6. At cartridge load time, the loader resolves `SYSC` entries against the host syscall registry. 6. At cartridge load time, the loader resolves `SYSC` entries against the host syscall registry.
@@ -84,7 +92,7 @@ Every host binding is identified by the triple:
Rules: Rules:
- `module` is the canonical host subsystem namespace, such as `gfx` or `audio`. - `module` is the canonical host subsystem namespace, such as `gfx2d` or `asset`.
- `name` is the canonical host operation name within that module. - `name` is the canonical host operation name within that module.
- `version` is the canonical ABI version of that host operation. - `version` is the canonical ABI version of that host operation.
- This identity is stable across source languages and SDK naming styles. - This identity is stable across source languages and SDK naming styles.
@@ -310,7 +318,10 @@ Rules:
- the loader resolves only against this canonical registry, - the loader resolves only against this canonical registry,
- unknown identities are load errors, - unknown identities are load errors,
- successful resolution yields numeric syscall identifiers and associated metadata, - successful resolution yields numeric syscall identifiers and associated metadata,
- the resolved metadata is authoritative for capability gating and later runtime verification. - the resolved metadata is authoritative for capability gating and later runtime verification,
- PBS `declare host` / `[Host]` shells MUST repeat identities from this registry,
- PBS shells MUST NOT invent `(module, name, version)`,
- this specification MUST NOT publish the syscall catalog; runtime spec 16 and `SyscallMeta` do.
For the current asset runtime surface, the canonical registry entries include: For the current asset runtime surface, the canonical registry entries include:
@@ -16,7 +16,11 @@ Its purpose is to make the stdlib:
This document complements the normative language-level model in: This document complements the normative language-level model in:
- [5. Manifest, Stdlib, and SDK Resolution Specification.md](/Users/niltonconstantino/personal/workspace.personal/intrepid/prometeu/studio/docs/specs/pbs/5.%20Manifest,%20Stdlib,%20and%20SDK%20Resolution%20Specification.md) - [5. Manifest, Stdlib, and SDK Resolution Specification.md](5.%20Manifest%2C%20Stdlib%2C%20and%20SDK%20Resolution%20Specification.md)
This document is PBS packaging. It MUST NOT define console ABI. Intrinsic
`final_id` values and host `SyscallMeta` remain runtime-owned. Physical stdlib
path MUST NOT imply VM-owned versus host-backed ownership.
## 2. Scope ## 2. Scope
@@ -53,52 +57,66 @@ The recommended Studio layout is:
```text ```text
prometeu-compiler/frontends/prometeu-frontend-pbs/ prometeu-compiler/frontends/prometeu-frontend-pbs/
src/main/resources/ src/main/resources/
stdlib/ <target>/
1/ stdlib/
sdk/ 1/
composer/ core/
main.pbs color/
mod.barrel main.pbs
gfx/ mod.barrel
main.pbs sdk/
mod.barrel asset/
asset/ main.pbs
main.pbs mod.barrel
mod.barrel composer/
audio/ main.pbs
main.pbs mod.barrel
mod.barrel gfx/
core/ main.pbs
math/ mod.barrel
main.pbs input/
mod.barrel main.pbs
mod.barrel
log/
main.pbs
mod.barrel
``` ```
Interpretation: Interpretation:
- `stdlib/1` selects stdlib major line `1`, - `<target>` is the `AppMode` export name (`game` for the current line-1 environment),
- `game/stdlib/1` selects stdlib major line `1` for that target,
- `sdk` and `core` are reserved project spaces, - `sdk` and `core` are reserved project spaces,
- `composer`, `gfx`, `audio`, `math` are module paths within those reserved spaces, - current line `1` modules are `color`, `asset`, `composer`, `gfx`, `input`, and `log`,
- `main.pbs` and `mod.barrel` form the interface module contents. - `main.pbs` and `mod.barrel` form the interface module contents.
Current line `1` MUST NOT be documented as shipping `audio` or `@core:math`.
Those names are not packaged in the current environment. `@sdk:input` is a
VM-owned builtin shell; its path does not make it host-backed.
## 5. Logical Mapping ## 5. Logical Mapping
The compiler must treat the physical layout as a logical stdlib environment. The compiler must treat the physical layout as a logical stdlib environment.
Required mapping: Required mapping:
- `stdlib/<N>/sdk/gfx` -> `@sdk:gfx` - `<target>/stdlib/<N>/<space>/<module>` -> `@<space>:<module>`
- `stdlib/<N>/sdk/composer` -> `@sdk:composer`
- `stdlib/<N>/sdk/asset` -> `@sdk:asset` Current line `1` (`game`) mapping:
- `stdlib/<N>/sdk/audio` -> `@sdk:audio`
- `stdlib/<N>/core/math` -> `@core:math` - `game/stdlib/1/core/color` -> `@core:color`
- `stdlib/<N>/core/math/vector` -> `@core:math/vector` - `game/stdlib/1/sdk/asset` -> `@sdk:asset`
- `game/stdlib/1/sdk/composer` -> `@sdk:composer`
- `game/stdlib/1/sdk/gfx` -> `@sdk:gfx`
- `game/stdlib/1/sdk/input` -> `@sdk:input`
- `game/stdlib/1/sdk/log` -> `@sdk:log`
Rules: Rules:
- physical storage is an implementation detail, - physical storage is an implementation detail,
- logical module identity is authoritative, - logical module identity is authoritative,
- callers of the resolver should work with logical addresses such as `@sdk:gfx` and `@sdk:composer`, not resource paths. - callers of the resolver should work with logical addresses such as `@sdk:gfx` and `@core:color`, not resource paths,
- physical path MUST NOT imply VM-owned versus host-backed ownership.
## 6. Module File Convention ## 6. Module File Convention
@@ -150,7 +168,8 @@ Minimum operations:
- `resolve(@sdk:gfx)` - `resolve(@sdk:gfx)`
- `resolve(@sdk:composer)` - `resolve(@sdk:composer)`
- `resolve(@core:math/vector)` - `resolve(@sdk:input)`
- `resolve(@core:color)`
### 7.3 `StdlibModuleSource` ### 7.3 `StdlibModuleSource`
@@ -102,17 +102,21 @@ Executable PBS programs have a logical bootstrap sequence before ordinary frame
Normative order: Normative order:
1. materialize globals for each file according to dependency order, 1. materialize globals for each file according to dependency order,
2. execute that file's `[Init]`, if present, 2. execute that file's non-project `[Init]`, if present,
3. compose those steps into one synthetic module init per module, 3. compose those steps into one synthetic module init per module,
4. execute project init, if present, 4. execute project init exactly once, if present, after all module initializers,
5. then invoke the userland callable marked with `[Frame]`. 5. then invoke the userland callable marked with `[Frame]`.
The `[Init]` colocated with `[Frame]` is project init. It MUST NOT also run as a file-init fragment.
Lifecycle bootstrap is one-shot: Lifecycle bootstrap is one-shot:
- no automatic retry occurs after boot failure, - no automatic retry occurs after boot failure,
- failure during module init aborts boot, - failure during module init aborts boot,
- failure during project init aborts boot. - failure during project init aborts boot.
Common lifecycle assembly materializes this order from the typed declaration. PBS remains the language source of marker meaning; it is not the owner of the published wrapper.
## 6.2 Logical frame root and physical wrapper ## 6.2 Logical frame root and physical wrapper
PBS distinguishes the logical frame root from the physical published entrypoint: PBS distinguishes the logical frame root from the physical published entrypoint:
@@ -1,4 +1,4 @@
# PBS Bytecode and PBX Mapping Specification # Bytecode and PBX Mapping Specification
Status: Draft v1 (Backend Baseline) Status: Draft v1 (Backend Baseline)
Applies to: mapping from lowered/optimized backend programs into PBX sections, bytecode-facing artifacts, and source-to-artifact invariants required by loader/verifier/runtime Applies to: mapping from lowered/optimized backend programs into PBX sections, bytecode-facing artifacts, and source-to-artifact invariants required by loader/verifier/runtime
@@ -9,6 +9,10 @@ This document defines the normative mapping between backend-lowered semantics an
Its purpose is to keep artifact emission deterministic and compatible with runtime loader/verifier contracts. Its purpose is to keep artifact emission deterministic and compatible with runtime loader/verifier contracts.
PBX is the only executable boundary between the compiler and runtime. `IRVM`
is a compiler-internal representation consumed by bytecode emission; it MUST
NOT be exposed to or consumed by the runtime loader, verifier, or PVM.
## 2. Scope ## 2. Scope
This document defines: This document defines:
@@ -7,6 +7,9 @@ Applies to: normative stdlib-facing API surface, reserved stdlib project spaces,
This document will define the normative user-facing standard-library surface for PBS. This document will define the normative user-facing standard-library surface for PBS.
This document is PBS delivery. It does not own console ABI. Intrinsic
`final_id` values and host syscall metadata are runtime-owned.
## 2. Scope ## 2. Scope
This document is intended to define: This document is intended to define:
@@ -28,15 +31,22 @@ This document does not define:
Normative precedence: Normative precedence:
1. `5. Manifest, Stdlib, and SDK Resolution Specification.md` 1. Runtime intrinsic catalog (`../runtime/docs/vm-arch/INTRINSICS.csv`; Studio mirror `docs/vm-arch/INTRINSICS.csv`)
2. `8. Stdlib Environment Packaging and Loading Specification.md` 2. Runtime host ABI (`../runtime/docs/specs/runtime/16-host-abi-and-syscalls.md` and `SyscallMeta`)
3. `6. VM-owned vs Host-backed.md` 3. `5. Manifest, Stdlib, and SDK Resolution Specification.md`
4. `6.1. Intrinsics and Builtin Types Specification.md` 4. `8. Stdlib Environment Packaging and Loading Specification.md`
5. `6.2. Host ABI Binding and Loader Resolution Specification.md` 5. `6. VM-owned vs Host-backed.md`
6. This document 6. `6.1. Intrinsics and Builtin Types Specification.md`
7. `6.2. Host ABI Binding and Loader Resolution Specification.md`
8. This document
If a rule here conflicts with higher-precedence specs, it is invalid. If a rule here conflicts with higher-precedence specs, it is invalid.
This document MUST NOT define numeric syscall identifiers, intrinsic `final_id`
values, or `SyscallMeta`. PBS `[Host]` and `[IntrinsicCall]` attributes MUST
repeat identities already published by those runtime catalogs. They MUST NOT
invent console ABI.
## 4. Normative Inputs ## 4. Normative Inputs
This document depends on, at minimum: This document depends on, at minimum:
@@ -57,6 +67,9 @@ The following inputs are already fixed elsewhere and must not be contradicted he
- User code must import stdlib modules explicitly. - User code must import stdlib modules explicitly.
- Canonical host identity comes from reserved host-binding metadata, not from source owner spelling. - Canonical host identity comes from reserved host-binding metadata, not from source owner spelling.
- VM-owned builtin type, builtin constant, and intrinsic surfaces may be exposed through reserved stdlib shells without transferring semantic ownership away from the VM. - VM-owned builtin type, builtin constant, and intrinsic surfaces may be exposed through reserved stdlib shells without transferring semantic ownership away from the VM.
- Console ABI authority is runtime-owned. PBS stdlib is delivery.
- Reserved project-space path (`@sdk:*` / `@core:*`) MUST NOT imply VM-owned versus host-backed ownership.
- Current stdlib line `1` ships a VM-owned builtin input shell at `@sdk:input`. That exception does not make `@sdk:*` the VM-owned space.
## 6. Initial Section Targets ## 6. Initial Section Targets
@@ -78,7 +91,10 @@ The following items remain to be closed in future agenda discussion.
- Whether `@core:*` is specified as language-adjacent utility surface or as ordinary stdlib contract. - Whether `@core:*` is specified as language-adjacent utility surface or as ordinary stdlib contract.
- How stdlib API evolution is documented and conformance-tested. - How stdlib API evolution is documented and conformance-tested.
- Whether some interface modules remain toolchain-private and outside user-facing stdlib surface. - Whether some interface modules remain toolchain-private and outside user-facing stdlib surface.
- Whether builtin shells may appear in `@sdk:*` as well as `@core:*`, or whether `@sdk:*` should remain host-facing only by policy.
Settled by DEC-0048 and not reopened here:
- Builtin shells MAY appear in `@sdk:*` as well as `@core:*`. Path MUST NOT imply ownership. Current line `1` exception: `@sdk:input`.
## 8. Non-Goals ## 8. Non-Goals
@@ -127,6 +143,12 @@ Rules:
- but ownership remains governed by the VM-owned vs host-backed classification, - but ownership remains governed by the VM-owned vs host-backed classification,
- and placing a builtin shell in stdlib does not make it host-backed. - and placing a builtin shell in stdlib does not make it host-backed.
Current line `1` exception:
- `@sdk:input` exposes VM-owned builtin input types through `[BuiltinType]` and `[IntrinsicCall]`.
- that module is not host-backed.
- the `@sdk:*` preference for host-backed APIs still holds for new host modules.
## 11. Builtin Shell Surfaces ## 11. Builtin Shell Surfaces
Reserved stdlib modules may expose builtin declarations as compile-time-only Reserved stdlib modules may expose builtin declarations as compile-time-only
@@ -205,6 +227,10 @@ Their canonical runtime-facing identities still come from builtin metadata such
as `BuiltinType(name="vec2", version=1)` and as `BuiltinType(name="vec2", version=1)` and
`BuiltinConst(target="vec2", name="zero", version=1)`. `BuiltinConst(target="vec2", name="zero", version=1)`.
Current stdlib line `1` ships `Color` at `@core:color`. The `@core:math` import
above is an identity illustration, not a claim that `@core:math` is packaged in
line `1`.
## 14. Deterministic Stdlib Surface Failures ## 14. Deterministic Stdlib Surface Failures
At minimum, a conforming implementation must reject: At minimum, a conforming implementation must reject:
@@ -214,3 +240,15 @@ At minimum, a conforming implementation must reject:
3. a user-facing stdlib module that exports executable PBS bodies for builtin semantics, 3. a user-facing stdlib module that exports executable PBS bodies for builtin semantics,
4. a stdlib line that exposes conflicting canonical builtin identities through the same resolved environment, 4. a stdlib line that exposes conflicting canonical builtin identities through the same resolved environment,
5. a stdlib line that exposes conflicting canonical host identities through the same resolved environment. 5. a stdlib line that exposes conflicting canonical host identities through the same resolved environment.
## 15. Console ABI Non-Ownership
This specification MUST NOT:
1. define numeric syscall identifiers,
2. define intrinsic `final_id` values,
3. publish `SyscallMeta`,
4. or treat PBS `[Host]` / `[IntrinsicCall]` attributes as the ABI catalog.
PBS shells MUST repeat identities already published by the runtime catalogs
named in section 3.
@@ -1,18 +1,21 @@
# PBS Verification and Safety Checks Specification # Compiler Verification and Safety Checks Specification
Status: Draft v1 (Quality-Gate Baseline) Status: Draft v1 (Quality-Gate Baseline)
Applies to: test-backed safety gates for backend compiler stages and integration regression safety checks against runtime Applies to: test-backed safety gates for common compiler stages, validation ownership across executable frontends, and integration regression safety checks against runtime
## 1. Purpose ## 1. Purpose
This document defines the minimum safety/verification quality gates that must be enforced for executable backend pipelines. This document defines the minimum safety/verification quality gates that must be enforced for executable compiler pipelines, and the ownership rule that separates language validation from platform validation.
Its purpose is to keep safety measurable and deterministic across: Its purpose is to keep safety measurable and deterministic across:
- lowering, - lowering,
- optimization, - optimization,
- emission, - emission,
- and runtime integration boundaries. - runtime integration boundaries,
- and the classification of diagnostics that every executable frontend must obey.
PBS is the current executable frontend. It is an example, not the owner of this specification.
## 2. Scope ## 2. Scope
@@ -20,37 +23,41 @@ This document defines:
- mandatory compiler-stage safety checks for executable pipeline stages, - mandatory compiler-stage safety checks for executable pipeline stages,
- conditional integration safety regression checks against runtime line, - conditional integration safety regression checks against runtime line,
- and evidence requirements for safety-related support claims. - evidence requirements for safety-related support claims,
- and validation-ownership rules that apply to all executable frontends.
This document does not define: This document does not define:
- full runtime verifier algorithm internals, - full runtime verifier algorithm internals,
- formal proof of all runtime safety properties, - formal proof of all runtime safety properties,
- or one mandatory verifier/optimizer architecture. - one mandatory verifier/optimizer architecture,
- PBS syntax or static-semantics catalogs,
- or a generic validator-core package.
## 3. Authority and Precedence ## 3. Authority and Precedence
Normative precedence: Normative precedence:
1. `docs/pbs/specs/2. Governance and Versioning.md` 1. Runtime authority (`docs/specs/hardware/topics/chapter-2.md`, `chapter-3.md`, `chapter-9.md`, `chapter-12.md`, `chapter-16.md`)
2. `docs/pbs/specs/12. Diagnostics Specification.md` 2. Bytecode authority (`docs/specs/bytecode/ISA_CORE.md`)
3. `20. IRBackend to IRVM Lowering Specification.md` 3. `20. IRBackend to IRVM Lowering Specification.md`
4. `21. IRVM Optimization Pipeline Specification.md` 4. `21. IRVM Optimization Pipeline Specification.md`
5. `15. Bytecode and PBX Mapping Specification.md` 5. `15. Bytecode and PBX Mapping Specification.md`
6. `13. Conformance Test Specification.md` 6. `13. Conformance Test Specification.md`
7. This document 7. This document
8. Frontend diagnostics specifications, including `docs/specs/compiler-languages/pbs/12. Diagnostics Specification.md`, for language-owned coverage only
If a rule here conflicts with higher-precedence authorities, it is invalid. If a rule here conflicts with a higher-precedence authority, it is invalid. Frontend diagnostics documents MUST NOT redefine compiler-general safety gates or platform validation ownership.
## 4. Normative Inputs ## 4. Normative Inputs
This document depends on: This document depends on:
- `docs/pbs/specs/12. Diagnostics Specification.md`
- `13. Conformance Test Specification.md` - `13. Conformance Test Specification.md`
- `15. Bytecode and PBX Mapping Specification.md` - `15. Bytecode and PBX Mapping Specification.md`
- `20. IRBackend to IRVM Lowering Specification.md` - `20. IRBackend to IRVM Lowering Specification.md`
- `21. IRVM Optimization Pipeline Specification.md` - `21. IRVM Optimization Pipeline Specification.md`
- `docs/specs/compiler-languages/pbs/12. Diagnostics Specification.md` as the current frontend diagnostics catalog, not as the owner of this specification
## 5. Safety Gate Model ## 5. Safety Gate Model
@@ -133,3 +140,74 @@ This document is healthy when:
2. executable backends have explicit S-I status (`pass`/`fail`/`deferred`), 2. executable backends have explicit S-I status (`pass`/`fail`/`deferred`),
3. integration safety regressions are preserved in tests, 3. integration safety regressions are preserved in tests,
4. and safety-related support claims remain evidence-backed. 4. and safety-related support claims remain evidence-backed.
## 11. Validation Ownership
A validation MUST live at the lowest layer that understands the failure without knowing the source language.
- A check is language-owned if it needs AST, tokens, a language marker, a barrel, or another source-language rule.
- A check is platform-owned if it can be performed on `IRBackend`, `IRLifecycleDeclaration`, IRVM, PBX, host/capability tables, or ids.
Adding a validation MUST record:
1. the input artifact the check reads;
2. whether that artifact is language source/AST/marker or a common contract;
3. the matrix owner;
4. the code family (`E_PARSE_*` / `E_SEM_*` / `E_LINK_*` / `E_HOST_*` versus `COMMON_*` / `LOWER_IRVM_*` / `MARSHAL_*`);
5. whether the span comes from a common-contract origin or from language tokens/AST.
If item 2 is both, the implementation MUST emit two diagnostics with distinct identities, not one hybrid.
### 11.1 Diagnostic identity and span
Platform diagnostics MUST use `COMMON_*`, `LOWER_IRVM_*`, or `MARSHAL_*` codes and the phase of the pipeline stage that reports them.
PBS MUST keep its current `E_PARSE_*`, `E_SEM_*`, `E_LINK_*`, and `E_HOST_*` codes.
This specification MUST NOT rewrite diagnostic messages or renumber existing codes.
Common code MUST copy origin/span when the declaration, instruction, or metadata carries one. A missing origin MUST be a structural error. Implementations MUST NOT invent a span.
The same fact MAY exist on both sides. PBS explains the language rule; the common layer rejects an invalid handoff even when the frontend has no PBS markers. The two errors MUST keep distinct identities. Example: `E_SEM_MISSING_PROJECT_FRAME` and a missing frame root on an executable `IRLifecycleDeclaration`.
### 11.2 Initial ownership matrix
| Family | Owner | Status | Notes |
| --- | --- | --- | --- |
| Parse / syntax (`ParseErrors`) | `compiler/pbs` | language | remains |
| Type, flow, declaration, const, and source-form global semantics | `compiler/pbs` | language | remains |
| Markers `[Init]`, `[Frame]`, `InitAllowed`, signature, colocation | `compiler/pbs` | language | already split by lifecycle assembly |
| `host call not allowed during init` | `compiler/pbs` | language | marker/source rule |
| PBS linking (`PbsLinkErrors`, barrel, import, visibility) | `compiler/pbs` | language | do not extract |
| Source shape of `[Host]` / `[Capability]` | `compiler/pbs` | language | host-admission split |
| Canonical host-binding identity and capability over `IRReservedMetadata` | `compiler/general` | platform | classified; validator remains in the PBS package until a later plan |
| Lifecycle assembler | `compiler/general` | platform | already implemented |
| IRVM preconditions for wrapper, boot guard, origin | `compiler/general` | platform | already implemented |
| `IRVMValidator`, lowering, marshal/bytecode | `compiler/general` | platform | already implemented |
| `Addressable` / asset path | `compiler/general` | platform | classified; no extra migration in this specification |
| Gates S-U/S-I | `compiler/general` | platform | this document |
### 11.3 Host admission, assets, and linking
Host admission is split:
- language owns the source shape of `[Host]` and `[Capability]`;
- platform owns canonical binding identity `(module, name, version)`, unknown capability, undeclared capability, and inconsistent binding once those facts exist on `IRReservedMetadata`.
`PbsHostAdmissionValidator` MAY remain in the PBS package until a later plan. `E_HOST_*` MUST NOT be treated as eternal PBS semantics.
`Addressable` / asset-path resolution is platform-owned. This specification classifies it and MUST NOT move additional asset code.
PBS linking, barrel files, and `PbsLinkErrors` remain language-owned. `ResolveDeps` does not authorize extracting them.
### 11.4 What this section does not authorize
This specification MUST NOT be read as authorizing:
- a generic validator-core package;
- moving `PbsHostAdmissionValidator` into a common package;
- moving asset-resolution production code;
- extracting PBS linking;
- or reopening lifecycle-assembly ownership.
Platform validators MUST NOT depend on types from the PBS frontend module (`prometeu-frontend-pbs`). The package `p.studio.compiler.pbs` is not the complete boundary; facades shipped by that module remain PBS-owned. Platform validators MUST NOT discover roles from `__pbs.` prefixes.
@@ -1,7 +1,7 @@
# PBS IRBackend to IRVM Lowering Specification # IRBackend to IRVM Lowering Specification
Status: Draft v1 (Backend Baseline) Status: Draft v1 (Backend Baseline)
Applies to: executable-backend lowering from `IRBackend` handoff into `IRVM` Applies to: executable-backend lowering from the common `IRBackend` handoff into `IRVM`
## 1. Purpose ## 1. Purpose
@@ -9,11 +9,20 @@ This document defines the normative lowering contract from executable `IRBackend
Its purpose is to make backend lowering deterministic, reviewable, and compatible with runtime ISA/verification authority. Its purpose is to make backend lowering deterministic, reviewable, and compatible with runtime ISA/verification authority.
`IRBackend` is the common frontend-to-backend executable handoff. It is emitted by frontends and consumed by common backend stages. Backend lowering MUST NOT require PBS AST nodes, PBS tokens, PBS parser structures, PBS semantic objects, PBS editorial objects, or equivalent language-owned objects from future frontends.
`IRVM` is an internal compiler representation. It MUST be consumed by common
compiler optimization and PBX emission stages, and it MUST NOT cross the
compiler/runtime boundary or become an input, dependency, public type, or
operational concept of the runtime loader, verifier, or PVM. PBX is the only
executable artifact boundary between compiler and runtime.
## 2. Scope ## 2. Scope
This document defines: This document defines:
- required backend preconditions before `IRBackend -> IRVM` starts, - required backend preconditions before `IRBackend -> IRVM` starts,
- allowed language-neutral `IRBackend` contract concepts at the backend boundary,
- `IRVM` structural obligations needed before optimization/emission, - `IRVM` structural obligations needed before optimization/emission,
- deterministic function-id assignment and control-flow lowering obligations, - deterministic function-id assignment and control-flow lowering obligations,
- callsite lowering obligations across function, host-backed, and VM-owned intrinsic paths, - callsite lowering obligations across function, host-backed, and VM-owned intrinsic paths,
@@ -25,7 +34,8 @@ This document does not define:
- binary PBX layout details, - binary PBX layout details,
- loader patching internals, - loader patching internals,
- runtime execution internals, - runtime execution internals,
- or one mandatory optimizer implementation. - one mandatory optimizer implementation,
- or frontend-specific lowering rules before `IRBackend` emission.
## 3. Authority and Precedence ## 3. Authority and Precedence
@@ -33,8 +43,8 @@ Normative precedence:
1. Runtime authority (`docs/specs/hardware/topics/chapter-2.md`, `chapter-3.md`, `chapter-9.md`, `chapter-12.md`, `chapter-16.md`) 1. Runtime authority (`docs/specs/hardware/topics/chapter-2.md`, `chapter-3.md`, `chapter-9.md`, `chapter-12.md`, `chapter-16.md`)
2. Bytecode authority (`docs/specs/bytecode/ISA_CORE.md`) 2. Bytecode authority (`docs/specs/bytecode/ISA_CORE.md`)
3. `docs/specs/compiler-languages/pbs/13. Lowering IRBackend Specification.md` 3. This document
4. This document 4. Frontend-specific lowering specifications, including `docs/specs/compiler-languages/pbs/13. Lowering IRBackend Specification.md`
If a rule here conflicts with higher-precedence authorities, it is invalid. If a rule here conflicts with higher-precedence authorities, it is invalid.
@@ -42,22 +52,106 @@ If a rule here conflicts with higher-precedence authorities, it is invalid.
This document depends on: This document depends on:
- `docs/specs/compiler-languages/pbs/13. Lowering IRBackend Specification.md`
- `docs/specs/compiler-languages/pbs/6.1. Intrinsics and Builtin Types Specification.md` - `docs/specs/compiler-languages/pbs/6.1. Intrinsics and Builtin Types Specification.md`
- `docs/specs/compiler-languages/pbs/6.2. Host ABI Binding and Loader Resolution Specification.md` - `docs/specs/compiler-languages/pbs/6.2. Host ABI Binding and Loader Resolution Specification.md`
- frontend-specific lowering specifications that emit the common `IRBackend` handoff
- `15. Bytecode and PBX Mapping Specification.md` - `15. Bytecode and PBX Mapping Specification.md`
- `21. IRVM Optimization Pipeline Specification.md` - `21. IRVM Optimization Pipeline Specification.md`
## 4.1 Common IRBackend Contract
At this boundary, `IRBackend` may contain only language-neutral compiler concepts required by executable backend lowering:
1. source identity and spans,
2. modules and module identifiers,
3. callable identities, signatures, names, arity, and type-shape surfaces,
4. executable functions,
5. instruction kinds and instruction metadata,
6. globals and global origins,
7. synthetic executable functions and synthetic origins,
8. host-call metadata,
9. intrinsic metadata,
10. reserved metadata required for backend lowering,
11. required runtime or platform capabilities,
12. and an optional typed `IRLifecycleDeclaration` used as lifecycle provenance after common assembly.
The common backend contract MUST express these concepts as backend obligations, not as PBS syntax or PBS semantic rules. When a concept currently originates from PBS, the backend contract still owns only the language-neutral obligation carried by `IRBackend`.
### 4.3 IRLifecycleDeclaration
`IRLifecycleDeclaration` is the typed, immutable, serializable-by-design lifecycle provenance carried by `IRBackend`.
An executable handoff MUST contain exactly one declaration before common assembly. A deliberately non-executable handoff MAY omit it; absence MUST NOT synthesize a default `main` or published wrapper.
The declaration MUST represent, using ordered collections and typed ids:
1. modules in explicit dependency order,
2. each module's ordered file-init fragment references,
3. an optional project-init callable reference,
4. and exactly one frame-root callable reference.
References MUST use `ModuleId`, `FileId`, `CallableId`, a typed role, and source attribution. The public shape MUST NOT expose maps, sets, callbacks, compiler services, or frontend-owned types.
`AssembleLifecyclePipelineStage` MUST run after `FrontendPhasePipelineStage` and before `LowerToIRVMPipelineStage`. `LifecycleAssemblerService` is the only owner of derived lifecycle artifacts: module init, project-init wrapper, published frame wrapper, physical entrypoint, and hidden boot guard. Those artifacts MUST use deterministic neutral internal identities. Common code MUST NOT discover roles from `__pbs.*` prefixes or depend on types from the PBS frontend module (`prometeu-frontend-pbs`). The package `p.studio.compiler.pbs` is not the complete boundary.
The declaration MUST remain available on the assembled `IRBackend` as typed provenance. Downstream inspection MUST use roles, ids, and origins rather than synthetic names.
Project init MUST be absent from file-init fragments and MUST execute exactly once, after all module initializers and before the frame root. Bootstrap failure MUST abort without retry. The boot guard MUST prevent a second bootstrap after successful completion. The published wrapper owns the final frame return.
The common backend contract MUST NOT expose or require:
1. `PbsExpression`, `PbsStatement`, `PbsToken`, or equivalent PBS-owned syntax objects,
2. PBS parser cursors, parse contexts, parse nodes, or token kinds,
3. PBS semantic validator internals,
4. PBS editorial or language-service objects,
5. or any type from the PBS frontend module (`prometeu-frontend-pbs`) or an equivalent language frontend module as part of the public backend handoff.
## 4.2 Serializable-by-Design Contract Shape
The public `IRBackend` handoff MUST remain serializable by design. This requirement does not select a wire format, schema language, RPC mechanism, process boundary, plugin runtime, or external frontend transport. It only constrains the public data shape so those choices remain possible later without redesigning the handoff.
Public `IRBackend` contract types MUST be modelable as an acyclic, deterministic data graph made of:
1. primitive values and strings,
2. enums,
3. immutable value objects,
4. ordered lists,
5. nullable or optional scalar fields only where absence is part of the contract,
6. explicit identifier values for cross-references,
7. and source attribution values such as file ids and spans.
The public handoff MUST NOT expose, require, or rely on:
1. callbacks, lambdas, service objects, registries, visitors, or live compiler services,
2. frontend AST, parser, token, semantic, or editorial objects,
3. mutable global state as part of interpretation,
4. object identity equality as a semantic key,
5. unordered collections where iteration order affects output,
6. cyclic references between public handoff objects,
7. lazy values whose result depends on current process state,
8. or a selected wire format.
Cross-object references MUST use explicit ids or stable symbolic keys. Existing table-scoped identifiers such as `FileId`, `ModuleId`, `CallableId`, and `IntrinsicId` are valid handoff values when their table scope is explicit and deterministic. New typed ids SHOULD be introduced only when a concrete public handoff field would otherwise depend on textual identity, object identity, or a direct object reference.
Ordered collections MUST preserve deterministic order. Any map-like data that becomes part of the handoff MUST either be represented as an ordered list of entries or define deterministic key ordering before it reaches the public contract.
Initial enforcement for this contract SHOULD be audit and guardrail based: specs, reflection tests over public handoff surfaces, deterministic ordering tests, and targeted fixes for concrete leaks. A serializer or schema implementation is not required for conformance to this subsection.
## 5. Backend Entry Preconditions ## 5. Backend Entry Preconditions
Lowering from `IRBackend` to `IRVM` may start only when: Lowering from `IRBackend` to `IRVM` may start only when:
1. frontend admission to `IRBackend` is complete for the active slice, 1. frontend admission to `IRBackend` is complete for the active slice,
2. required callsite categories (`CALL_FUNC`/`CALL_HOST`/`CALL_INTRINSIC`) are available, 2. common lifecycle assembly has already materialized derived artifacts for an executable handoff,
3. required canonical host/intrinsic metadata is available for admitted callsites, 3. required callsite categories (`CALL_FUNC`/`CALL_HOST`/`CALL_INTRINSIC`) are available,
4. dependency-scoped fail-fast exclusions have already been applied at the `IRBackend` boundary, 4. required canonical host/intrinsic metadata is available for admitted callsites,
5. compiler-selected published-wrapper entrypoint identity is present and unambiguous, 5. dependency-scoped fail-fast exclusions have already been applied at the `IRBackend` boundary,
6. and target `vm_profile` is selected deterministically. 6. compiler-selected published-wrapper entrypoint identity is present and unambiguous,
7. and target `vm_profile` is selected deterministically.
Declaration validation, role uniqueness, explicit order, and rejection of frontend-preassembled derived artifacts belong to `LifecycleAssemblerService`. `IRBackend -> IRVM` MUST keep only backend preconditions on the assembled graph, such as published-wrapper identity, synthetic origin presence, and hidden boot-guard presence. It MUST NOT reconstruct lifecycle order from callable names.
Those common structural diagnostics are compiler-general. Classification, code families, and dual language/platform reporting are owned by `docs/specs/compiler/19. Verification and Safety Checks Specification.md` section 11. They MUST NOT be catalogued as PBS-facing required coverage.
## 6. IRVM Model Obligations ## 6. IRVM Model Obligations
@@ -98,12 +192,15 @@ Function indexing must be deterministic:
4. manifest-owned or name-only entrypoint fallback is forbidden, 4. manifest-owned or name-only entrypoint fallback is forbidden,
5. and identical admitted input graphs must produce identical function-id assignments. 5. and identical admitted input graphs must produce identical function-id assignments.
For PBS executable lowering: For executable lowering:
- the userland callable marked with `[Frame]` remains the logical frame root, - the declared frame-root callable remains the logical frame root,
- the wrapper path must contain final `FRAME_RET`, - the assembled published wrapper is the physical entrypoint,
- the wrapper path must contain the final frame return,
- and lowering must preserve that distinction through `IRVM`. - and lowering must preserve that distinction through `IRVM`.
PBS `[Init]`/`[Frame]` markers are a frontend source of the declaration. The backend-owned obligation is the neutral requirement that the compiler-selected published wrapper be the physical entrypoint and that lifecycle provenance remain explicit in `IRBackend` through typed roles and ids. Neutral synthetic names are internal and are not a public ABI.
## 9. Callsite Lowering Obligations ## 9. Callsite Lowering Obligations
### 9.1 Function calls ### 9.1 Function calls
@@ -150,7 +247,7 @@ Before bytecode emission, backend must run structural pre-verification on lowere
7. and structural validity of host/intrinsic call forms. 7. and structural validity of host/intrinsic call forms.
8. and structural validity of backend-owned symbolic-to-operational rewrites such as `Addressable -> asset_id`. 8. and structural validity of backend-owned symbolic-to-operational rewrites such as `Addressable -> asset_id`.
For PBS host-backed asset calls in v1, this validation includes the rewrite selected by preserved host metadata such as `[AssetLowering(param = N)]`. For host-backed asset calls in v1, this validation includes backend-owned symbolic-to-operational rewrites selected by preserved host metadata. PBS currently emits this designation from metadata such as `[AssetLowering(param = N)]`, but final operational resolution is a common backend obligation.
This pre-verification does not replace runtime verifier authority. This pre-verification does not replace runtime verifier authority.
@@ -184,4 +281,6 @@ This document is healthy when:
1. `IRBackend -> IRVM` obligations are explicit and testable, 1. `IRBackend -> IRVM` obligations are explicit and testable,
2. deterministic function/call/control-flow lowering rules are explicit, 2. deterministic function/call/control-flow lowering rules are explicit,
3. mandatory pre-verification boundary is explicit, 3. mandatory pre-verification boundary is explicit,
4. and scope boundaries with optimization/emission specs are explicit. 4. common backend obligations are not described as owned by PBS,
5. frontend-specific lowering specs only own emission into `IRBackend`,
6. and scope boundaries with optimization/emission specs are explicit.
@@ -1,4 +1,4 @@
# PBS IRVM Optimization Pipeline Specification # IRVM Optimization Pipeline Specification
Status: Draft v1 (Pipeline Baseline) Status: Draft v1 (Pipeline Baseline)
Applies to: placement and invariants of the `OptimizeIRVM` stage between lowering and bytecode emission Applies to: placement and invariants of the `OptimizeIRVM` stage between lowering and bytecode emission
@@ -9,6 +9,10 @@ This document defines the normative placement and safety invariants of the `Opti
Its purpose is to allow optimization in the backend pipeline without transferring semantic optimization responsibility to runtime. Its purpose is to allow optimization in the backend pipeline without transferring semantic optimization responsibility to runtime.
`IRVM` is internal to the compiler. Optimization output MUST flow to PBX
emission and MUST NOT be exposed as a runtime input or protocol. PBX remains the
only executable boundary consumed by the runtime loader, verifier, and PVM.
## 2. Scope ## 2. Scope
This document defines: This document defines:
@@ -3,7 +3,7 @@
Status: Draft v1 (Traceability Baseline) Status: Draft v1 (Traceability Baseline)
Applies to: compiler/backend conformance traceability for canonical stage order and entrypoint-specific contracts Applies to: compiler/backend conformance traceability for canonical stage order and entrypoint-specific contracts
Last Updated: 2026-03-30 Last Updated: 2026-09-19
## 1. Purpose ## 1. Purpose
@@ -13,7 +13,7 @@ This matrix maps each normative backend MUST from:
2. `docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md` 2. `docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md`
3. `docs/specs/compiler/21. IRVM Optimization Pipeline Specification.md` 3. `docs/specs/compiler/21. IRVM Optimization Pipeline Specification.md`
4. `docs/specs/compiler/23. Compiler Pipeline Entry Points Specification.md` 4. `docs/specs/compiler/23. Compiler Pipeline Entry Points Specification.md`
5. `docs/specs/compiler-languages/pbs/13. Lowering IRBackend Specification.md` (Section 12 addendum only) 5. `docs/specs/compiler-languages/pbs/13. Lowering IRBackend Specification.md` (PBS lowering obligations only)
to concrete positive/negative test evidence and current status. to concrete positive/negative test evidence and current status.
@@ -40,6 +40,22 @@ to concrete positive/negative test evidence and current status.
| G19-5.2.6 | Gate S-I MUST reject missing capability at load-time. | N/A | `BackendGateIIntegrationTest#gateI_rejectMissingCapability` | pass | | | G19-5.2.6 | Gate S-I MUST reject missing capability at load-time. | N/A | `BackendGateIIntegrationTest#gateI_rejectMissingCapability` | pass | |
| G19-5.2.7 | Gate S-I MUST cover valid VM-owned intrinsic path. | `BackendGateIIntegrationTest#gateI_validIntrinsicPath` | N/A | pass | | | G19-5.2.7 | Gate S-I MUST cover valid VM-owned intrinsic path. | `BackendGateIIntegrationTest#gateI_validIntrinsicPath` | N/A | pass | |
| G19-5.2.8 | Gate S-I MUST cover repeatability across runtime line. | `RuntimeBackedCompatibilityAdapterTest#checkMustPassInStrictModeWhenRuntimeCommandIsValid`; `RuntimeBackedCompatibilityAdapterTest#checkMustBeRepeatableAcrossDeclaredRuntimeLinesInStrictMode` | `RuntimeBackedCompatibilityAdapterTest#checkMustFailInStrictModeWhenRuntimeCommandIsUnavailable` | pass | Multi-line repeatability is asserted with strict runtime-backed checks over distinct declared runtime lines. | | G19-5.2.8 | Gate S-I MUST cover repeatability across runtime line. | `RuntimeBackedCompatibilityAdapterTest#checkMustPassInStrictModeWhenRuntimeCommandIsValid`; `RuntimeBackedCompatibilityAdapterTest#checkMustBeRepeatableAcrossDeclaredRuntimeLinesInStrictMode` | `RuntimeBackedCompatibilityAdapterTest#checkMustFailInStrictModeWhenRuntimeCommandIsUnavailable` | pass | Multi-line repeatability is asserted with strict runtime-backed checks over distinct declared runtime lines. |
| G19-11.1 | A validation MUST live at the lowest layer that understands the failure without knowing the source language. | `ValidationOwnershipSpecTest#spec19MustBeCompilerGeneralAndPublishValidationOwnership` | N/A | pass | Spec 19 section 11 states the classification rule. |
| G19-11.2 | Spec 19 MUST publish the validation ownership matrix. | `ValidationOwnershipSpecTest#spec19MustBeCompilerGeneralAndPublishValidationOwnership` | N/A | pass | Matrix families include parse/syntax, PBS linking, and lifecycle assembler. |
| G19-11.3 | Platform diagnostics MUST use `COMMON_*` / `LOWER_IRVM_*` / `MARSHAL_*` and MUST copy origin/span when present. | `ValidationOwnershipSpecTest#spec19MustBeCompilerGeneralAndPublishValidationOwnership`; `LifecycleAssemblerServiceTest#assembleMustRejectMissingFrameRootWithoutRepair` | N/A | pass | Code families and span policy are normative in spec 19 section 11.1. |
| G19-11.4 | The same fact MAY exist as a language diagnostic and a platform diagnostic with distinct identities. | `ValidationOwnershipSpecTest#spec19MustBeCompilerGeneralAndPublishValidationOwnership` | N/A | pass | Dual reporting is required when a check reads both source and common contract. |
| G19-11.5 | Host admission MUST split source attribute shape from canonical `IRReservedMetadata` identity without moving the PBS validator in this plan. | `ValidationOwnershipSpecTest#spec19MustBeCompilerGeneralAndPublishValidationOwnership` | N/A | pass | Classified as platform; validator remains in the PBS package. |
| G19-11.6 | Platform validators MUST NOT depend on PBS frontend module types or match `__pbs.` prefixes. | `PbsModuleBoundaryArchTest#productionOutsideAllowlistMustNotDependOnPbsModuleTypes`; `CommonBackendPbsPrefixScanTest#commonLifecycleAndBackendMustNotDiscoverRolesFromPbsNamePrefixes` | N/A | pass | ArchUnit covers PBS module origin, including facades outside `p.studio.compiler.pbs`; source scan still rejects `__pbs.` in backend, lifecycle, and common pipeline stages. |
| PBS12-11 | PBS diagnostics MUST NOT claim common structural lifecycle/IRVM failures as PBS required coverage. | `ValidationOwnershipSpecTest#pbsDiagnosticsMustNotClaimCommonStructuralFailures` | N/A | pass | PBS spec 12 points those failures at spec 19 section 11 and spec 20. |
| G20-4.1.1 | `IRBackend` MUST be the common frontend-to-backend executable handoff. | `LowerToIRVMServiceTest#lowerMustAcceptManuallyConstructedCommonIRBackend` | N/A | pass | Direct backend lowering from manually constructed common IRBackend proves PBS parser/frontend services are not required. |
| G20-4.1.2 | Common backend code MUST NOT depend on types from the PBS frontend module. | `PbsModuleBoundaryArchTest#productionOutsideAllowlistMustNotDependOnPbsModuleTypes`; `PbsModuleBoundaryArchTest#irBackendModelsMustNotDependOnPbsModuleTypes` | N/A | pass | ArchUnit rejects PBS-module origin types in common production code, including facades outside `p.studio.compiler.pbs`. |
| G20-4.1.3 | Public `IRBackend` contract MUST NOT expose PBS AST, token, parser, semantic, or editorial types. | `IRBackendExecutableContractTest#publicIRBackendContractMustNotExposePbsTypes` | N/A | pass | Reflection guard covers public contract fields, constructors, methods, and record components. |
| G20-4.2.1 | Public `IRBackend` contract types MUST remain modelable as an acyclic, deterministic data graph. | `IRBackendExecutableContractTest#publicIRBackendContractMustExposeOnlySerializableShapes`; `IRBackendExecutableContractTest#aggregatorMustEmitDeterministicOrderedPublicContractShape` | N/A | pass | Covers public shape guardrails, generic type arguments, ordered aggregate emission, table remapping, and capability de-duplication order. |
| G20-4.2.2 | Public `IRBackend` contract types MUST NOT expose callbacks, services, mutable/unordered collection contracts, frontend-owned objects, process-dependent lazy values, cyclic public references, or wire-format commitments. | `IRBackendExecutableContractTest#publicIRBackendContractMustExposeOnlySerializableShapes` | N/A | pass | Reflection guard covers public contract fields, constructors, methods, record components, and generic type arguments. |
| G20-4.2.3 | Public `IRBackend` cross-object references MUST use explicit ids or stable symbolic keys. | `IRBackendExecutableContractTest#publicIRBackendContractAuditMustClassifyAllowedSupportTypes`; `IRBackendExecutableContractTest#publicIRBackendContractMustUseExplicitIdsOrStableKeysForKnownReferences` | N/A | pass | Current audit found no concrete public serialization leak requiring model correction. Existing `FileId`, `ModuleId`, `CallableId`, and `IntrinsicId` remain explicit table-scoped identifiers. |
| G20-4.3.1 | Executable `IRBackend` MUST carry a typed, ordered, id-based `IRLifecycleDeclaration` as provenance. | `IRBackendExecutableContractTest#aggregatorMustRemapTypedLifecycleReferencesAndPreserveDeclaredModuleOrder`; `LifecycleAssemblerServiceTest#assembleMustMaterializeNeutralLifecycleArtifactsInDeclaredOrder` | `IRBackendExecutableContractTest#aggregatorMustOmitLifecycleDeclarationWhenNoFileContributesOne` | pass | Declaration uses `ReadOnlyList`, typed ids, roles, and source attribution; aggregator remaps ids with explicit module order. |
| G20-4.3.2 | Missing lifecycle declaration MUST mean a deliberately non-executable handoff and MUST NOT synthesize entrypoints. | `LifecycleAssemblerServiceTest#assembleMustNoOpWhenLifecycleDeclarationIsAbsent`; `AssembleLifecyclePipelineStageTest#runMustNoOpForDeliberatelyNonExecutableHandoff` | N/A | pass | Assembler and stage leave the backend unchanged when the declaration is absent. |
| G20-4.3.3 | Common lifecycle assembly MUST be the exclusive owner of derived artifacts and MUST use neutral identities. | `LifecycleAssemblerServiceTest#assembleMustMaterializeNeutralLifecycleArtifactsInDeclaredOrder`; `CommonBackendPbsPrefixScanTest#commonLifecycleAndBackendMustNotDiscoverRolesFromPbsNamePrefixes`; `PbsModuleBoundaryArchTest#productionOutsideAllowlistMustNotDependOnPbsModuleTypes` | `LifecycleAssemblerServiceTest#assembleMustRejectPreMaterializedDerivedArtifacts` | pass | Derived wrappers and boot guard are common-owned; ArchUnit rejects PBS-module types and the source scan rejects `__pbs.` prefix matching. |
| G20-6.2 | `IRVM_EXT` MUST declare structural metadata (`pops/pushes/is_branch/is_terminator`). | `IRVMValidatorTest#validateMustApplyStructuralMetadataForCustomInternalExtension`; `IRVMValidatorTest#validateMustRejectCustomInternalExtensionWhenStructuralMetadataUnderflowsStack`; `IRVMOp` record contract (`pops/pushes/branch/terminator/internal`) | N/A | pass | Dedicated extension fixtures now assert structural metadata is consumed by validation behavior. | | G20-6.2 | `IRVM_EXT` MUST declare structural metadata (`pops/pushes/is_branch/is_terminator`). | `IRVMValidatorTest#validateMustApplyStructuralMetadataForCustomInternalExtension`; `IRVMValidatorTest#validateMustRejectCustomInternalExtensionWhenStructuralMetadataUnderflowsStack`; `IRVMOp` record contract (`pops/pushes/branch/terminator/internal`) | N/A | pass | Dedicated extension fixtures now assert structural metadata is consumed by validation behavior. |
| G20-6.3 | `IRVM_EXT` MUST be eliminable before bytecode emission. | `OptimizeIRVMServiceTest#optimizeDefaultPassesMustEliminateUnreachableInternalExtensionBeforeEmission` | `EmitBytecodePipelineStageTest#runMustFailWhenInternalOpcodesRemain`; `EmitBytecodePipelineStageTest#runMustFailWhenInternalOpcodesRemainEvenWithNonEmptyEmissionPlan`; `IRVMValidatorTest#validateMustRejectInternalOpcodeWhenConfigured` | pass | Optimizer elimination path and emit-stage hard rejection path are both covered. | | G20-6.3 | `IRVM_EXT` MUST be eliminable before bytecode emission. | `OptimizeIRVMServiceTest#optimizeDefaultPassesMustEliminateUnreachableInternalExtensionBeforeEmission` | `EmitBytecodePipelineStageTest#runMustFailWhenInternalOpcodesRemain`; `EmitBytecodePipelineStageTest#runMustFailWhenInternalOpcodesRemainEvenWithNonEmptyEmissionPlan`; `IRVMValidatorTest#validateMustRejectInternalOpcodeWhenConfigured` | pass | Optimizer elimination path and emit-stage hard rejection path are both covered. |
| G20-6.4 | IRVM MUST preserve per-function slot and identity headers. | `IRVMProgramTest#constructorMustRejectModuleAndEmissionPlanMismatch` | `IRVMProgramTest#constructorMustRejectModuleAndEmissionPlanMismatch` | pass | Header mismatch is rejected deterministically. | | G20-6.4 | IRVM MUST preserve per-function slot and identity headers. | `IRVMProgramTest#constructorMustRejectModuleAndEmissionPlanMismatch` | `IRVMProgramTest#constructorMustRejectModuleAndEmissionPlanMismatch` | pass | Header mismatch is rejected deterministically. |
@@ -67,14 +83,19 @@ to concrete positive/negative test evidence and current status.
| G21-9.1 | Validation MUST include optimized-vs-non-optimized equivalence fixtures. | `OptimizeIRVMEquivalenceHarnessTest#optimizeOnOffMustPreserveObservableTraceForLoweredHostIntrinsicFixture`; `OptimizeIRVMEquivalenceHarnessTest#optimizeOnOffMustPreserveObservableTraceForConditionalJoinFixture`; `OptimizeIRVMEquivalenceHarnessTest#optimizeOnOffMustPreserveObservableTraceForSimpleLoopFixture`; `OptimizeIRVMEquivalenceHarnessTest#optimizeOnOffMustPreserveObservableTraceForLinearCallFixture` | N/A | pass | Dedicated opt on/off harness with reusable interpreter and deterministic trace assertions is in place. | | G21-9.1 | Validation MUST include optimized-vs-non-optimized equivalence fixtures. | `OptimizeIRVMEquivalenceHarnessTest#optimizeOnOffMustPreserveObservableTraceForLoweredHostIntrinsicFixture`; `OptimizeIRVMEquivalenceHarnessTest#optimizeOnOffMustPreserveObservableTraceForConditionalJoinFixture`; `OptimizeIRVMEquivalenceHarnessTest#optimizeOnOffMustPreserveObservableTraceForSimpleLoopFixture`; `OptimizeIRVMEquivalenceHarnessTest#optimizeOnOffMustPreserveObservableTraceForLinearCallFixture` | N/A | pass | Dedicated opt on/off harness with reusable interpreter and deterministic trace assertions is in place. |
| G21-9.2 | Validation MUST preserve known negative loader/verifier behavior. | `BackendSafetyGateSUTest#emitStageMustExposeMarshalingLinkageFailureDeterministically`; `BackendGateIIntegrationTest` rejection suite | N/A | pass | | | G21-9.2 | Validation MUST preserve known negative loader/verifier behavior. | `BackendSafetyGateSUTest#emitStageMustExposeMarshalingLinkageFailureDeterministically`; `BackendGateIIntegrationTest` rejection suite | N/A | pass | |
| G21-9.3 | Validation MUST preserve deterministic artifact-level invariants. | `BackendSafetyGateSUTest#fullPipelineMustProduceDeterministicBytecodeForSameInput`; `BytecodeEmitterTest#emitMustRemainDeterministicAfterInterning` | N/A | pass | | | G21-9.3 | Validation MUST preserve deterministic artifact-level invariants. | `BackendSafetyGateSUTest#fullPipelineMustProduceDeterministicBytecodeForSameInput`; `BytecodeEmitterTest#emitMustRemainDeterministicAfterInterning` | N/A | pass | |
| G23-5.1 | Canonical compiler pipeline MUST preserve the shared stage order through `WriteBytecodeArtifact`. | `MainProjectPipelineIntegrationTest#analyzeShouldNotWriteProgramBytecode`; `MainProjectPipelineIntegrationTest#compileShouldProduceInMemoryBytecodeWithoutWritingProgramBytecode`; `MainProjectPipelineIntegrationTest#buildShouldWriteProgramBytecode` | N/A | partial | Entrypoint execution now covers the full analyze -> compile -> build path, but a dedicated order-only assertion for every terminal boundary is still missing. | | G23-5.1 | Canonical compiler pipeline MUST preserve the shared stage order through `WriteBytecodeArtifact`. | `BuilderPipelineServiceOrderTest#canonicalOrderMustContainOptimizeBetweenLowerAndEmit`; `MainProjectPipelineIntegrationTest#analyzeShouldNotWriteProgramBytecode`; `MainProjectPipelineIntegrationTest#compileShouldProduceInMemoryBytecodeWithoutWritingProgramBytecode`; `MainProjectPipelineIntegrationTest#buildShouldWriteProgramBytecode` | N/A | pass | Dedicated order assertion now covers analyses, compile, and build stage lists, including `AssembleLifecyclePipelineStage`. |
| G23-6.1 | `analyze` MUST terminate after `FrontendPhase` and MUST NOT execute backend artifact stages. | `MainProjectPipelineIntegrationTest#analyzeShouldNotWriteProgramBytecode` | N/A | pass | The integration fixture asserts the analysis snapshot contract and proves `program.pbx` is not written on the analysis path. | | G23-5.2 | `AssembleLifecyclePipelineStage` MUST run immediately after `FrontendPhasePipelineStage` and before IRVM lowering. | `BuilderPipelineServiceOrderTest#canonicalOrderMustContainOptimizeBetweenLowerAndEmit`; `BuilderPipelineServiceOrderTest#analyzeMustTerminateAfterLifecycleAssemblyWithoutBackendArtifacts` | N/A | pass | Analyses terminate at lifecycle assembly; compile stages begin at `LowerToIRVMPipelineStage`. |
| G23-6.1 | `analyze` MUST terminate after `AssembleLifecycle` and MUST NOT execute backend artifact stages. | `BuilderPipelineServiceOrderTest#analyzeMustTerminateAfterLifecycleAssemblyWithoutBackendArtifacts`; `MainProjectPipelineIntegrationTest#analyzeShouldNotWriteProgramBytecode` | N/A | pass | Analyze returns an assembled executable `IRBackend` with no IRVM, bytecode, or file output. |
| G23-6.2 | `compile` MUST terminate after `VerifyBytecode` and MUST return a validated in-memory executable result without disk write. | `MainProjectPipelineIntegrationTest#compileShouldProduceInMemoryBytecodeWithoutWritingProgramBytecode`; `BuilderPipelinePublicSurfaceTest#compileResultMustExposeValidatedInMemoryArtifacts` | N/A | pass | Coverage asserts validated in-memory bytecode artifacts and the no-write boundary for `compile`. | | G23-6.2 | `compile` MUST terminate after `VerifyBytecode` and MUST return a validated in-memory executable result without disk write. | `MainProjectPipelineIntegrationTest#compileShouldProduceInMemoryBytecodeWithoutWritingProgramBytecode`; `BuilderPipelinePublicSurfaceTest#compileResultMustExposeValidatedInMemoryArtifacts` | N/A | pass | Coverage asserts validated in-memory bytecode artifacts and the no-write boundary for `compile`. |
| G23-6.3 | `build` MUST extend `compile` only with terminal artifact persistence. | `MainProjectPipelineIntegrationTest#buildShouldWriteProgramBytecode`; `BuilderPipelinePublicSurfaceTest#buildResultMustExposeArtifactPathAndCompilePayload` | N/A | pass | Coverage asserts that `build` retains the compile payload and writes the filesystem artifact path expected by callers. | | G23-6.3 | `build` MUST extend `compile` only with terminal artifact persistence. | `MainProjectPipelineIntegrationTest#buildShouldWriteProgramBytecode`; `BuilderPipelinePublicSurfaceTest#buildResultMustExposeArtifactPathAndCompilePayload` | N/A | pass | Coverage asserts that `build` retains the compile payload and writes the filesystem artifact path expected by callers. |
| G23-7.1 | `AnalysisSnapshot` MUST expose the minimum shared analysis contract. | `MainProjectPipelineIntegrationTest#analyzeShouldNotWriteProgramBytecode`; `BuilderPipelinePublicSurfaceTest#analysisSnapshotMustExposeMinimumSharedContract` | N/A | pass | Both executable and structural contract checks now cover the shared minimum analysis payload. | | G23-7.1 | `AnalysisSnapshot` MUST expose the minimum shared analysis contract. | `MainProjectPipelineIntegrationTest#analyzeShouldNotWriteProgramBytecode`; `BuilderPipelinePublicSurfaceTest#analysisSnapshotMustExposeMinimumSharedContract` | N/A | pass | Both executable and structural contract checks now cover the shared minimum analysis payload. |
| G23-8.1 | Caller-specific configs/contexts MUST NOT redefine canonical stage semantics. | N/A | N/A | missing | Requires explicit multi-entrypoint composition tests once non-filesystem contexts are implemented. | | G23-8.1 | Caller-specific configs/contexts MUST NOT redefine canonical stage semantics. | N/A | N/A | missing | Requires explicit multi-entrypoint composition tests once non-filesystem contexts are implemented. |
| G23-8.3 | A compile-only `FrontendProvider` registered by `languageId` MUST traverse `compile()` to verified bytecode without PBS, `.pbs` sources, or PBS stdlib. | `SyntheticFrontendPipelineTest#compileMustEmitVerifiedBytecodeWithoutPbs` | `FrontendRegistryServiceTest#unregisterMustRefuseToRemoveDefaultPbs` | pass | Synthetic `synth` provider is test-only; common pipeline must not require PBS types, PBS sources, or PBS stdlib. |
| G23-9.1 | Legacy public `run` MUST be removed as the normative entrypoint and filesystem-default behavior MUST be expressed through `build`. | `BuilderPipelinePublicSurfaceTest#publicServiceSurfaceMustExposeExplicitEntrypointsAndNoPublicRun`; `MainProjectPipelineIntegrationTest#buildShouldWriteProgramBytecode` | N/A | partial | Public service coverage now proves `run` is no longer public and `build` is the filesystem artifact path, but the CLI composition path is not yet exercised by a dedicated automated test. | | G23-9.1 | Legacy public `run` MUST be removed as the normative entrypoint and filesystem-default behavior MUST be expressed through `build`. | `BuilderPipelinePublicSurfaceTest#publicServiceSurfaceMustExposeExplicitEntrypointsAndNoPublicRun`; `MainProjectPipelineIntegrationTest#buildShouldWriteProgramBytecode` | N/A | partial | Public service coverage now proves `run` is no longer public and `build` is the filesystem artifact path, but the CLI composition path is not yet exercised by a dedicated automated test. |
| PBS13-12.0 | Executable backend handoff MUST satisfy addendum obligations. | `IRBackendExecutableContractTest` suite; `PBSFrontendPhaseServiceTest#shouldSynthesizePositiveTopic19FixtureAcrossFileInitProjectInitAndFrame` | `LowerToIRVMServiceTest#lowerMustRejectWhenSyntheticWrapperEntrypointIsMissing`; `LowerToIRVMServiceTest#lowerMustRejectWhenHiddenBootGuardIsMissing`; `LowerToIRVMServiceTest#lowerMustRejectWhenSyntheticCallableOriginIsMissing` | pass | Row group `PBS13-12.x` details each obligation; topic 19 closure now includes lifecycle wrapper/guard/origin evidence. | | PBS13-12.0 | PBS executable lowering MUST emit `IRBackend` satisfying frontend handoff obligations before common backend lowering. | `IRBackendExecutableContractTest` suite; `PBSFrontendPhaseServiceTest#shouldSynthesizePositiveTopic19FixtureAcrossFileInitProjectInitAndFrame` | `LowerToIRVMServiceTest#lowerMustRejectWhenSyntheticWrapperEntrypointIsMissing`; `LowerToIRVMServiceTest#lowerMustRejectWhenHiddenBootGuardIsMissing`; `LowerToIRVMServiceTest#lowerMustRejectWhenSyntheticCallableOriginIsMissing` | pass | Row group `PBS13-12.x` verifies PBS emission into the common handoff; common backend ownership is covered by G20 rows. |
| PBS13-12.7 | PBS executable lowering MUST emit a typed lifecycle declaration and MUST NOT assemble derived wrappers. | `PBSFrontendPhaseServiceTest#shouldSynthesizePositiveTopic19FixtureAcrossFileInitProjectInitAndFrame`; `PbsFrontendCompilerTest#shouldExposeGlobalsAndTypedLifecycleDeclarationInBackendFile` | N/A | pass | Frontend tests assert declaration roles and the absence of module init, published wrapper, and boot guard. |
| PBS13-12.8 | Project init MUST be excluded from file-init fragments and MUST execute exactly once after module initializers. | `PbsFrontendCompilerTest#shouldExposeGlobalsAndTypedLifecycleDeclarationInBackendFile`; `LifecycleAssemblerServiceTest#assembleMustInvokeProjectInitExactlyOnceAndExcludeItFromFileInit` | N/A | pass | Colocated `[Init]` is declared as project init and invoked once by the assembled wrapper. |
| PBS13-12.9 | Lifecycle module order MUST propagate resolved dependency order without name or `FileId` inference. | `PBSFrontendPhaseServiceTest#shouldPublishDependencyOrderedLifecycleModulesInsteadOfNameOrFileIdOrder`; `IRBackendExecutableContractTest#aggregatorMustRemapTypedLifecycleReferencesAndPreserveDeclaredModuleOrder` | N/A | pass | Adversarial module names and file registration order do not change declared dependency order. |
| PBS13-12.1.1 | Callable identity MUST be preserved at handoff. | `IRBackendExecutableContractTest#aggregatorMustPreserveExecutableFunctionOrderDeterministically` | N/A | pass | | | PBS13-12.1.1 | Callable identity MUST be preserved at handoff. | `IRBackendExecutableContractTest#aggregatorMustPreserveExecutableFunctionOrderDeterministically` | N/A | pass | |
| PBS13-12.1.2 | Observable callable signature MUST be preserved at handoff. | `IRBackendExecutableContractTest#functionContractMustRejectInvalidSlotAndSpanBounds` | N/A | pass | | | PBS13-12.1.2 | Observable callable signature MUST be preserved at handoff. | `IRBackendExecutableContractTest#functionContractMustRejectInvalidSlotAndSpanBounds` | N/A | pass | |
| PBS13-12.1.3 | Callable category MUST be preserved at handoff. | `PbsFrontendCompilerTest#shouldLowerExecutableFunctionsWithCallsiteCategories` | N/A | pass | | | PBS13-12.1.3 | Callable category MUST be preserved at handoff. | `PbsFrontendCompilerTest#shouldLowerExecutableFunctionsWithCallsiteCategories` | N/A | pass | |
@@ -103,7 +124,7 @@ to concrete positive/negative test evidence and current status.
1. Any backend PR that changes conformance-relevant behavior in FE/BE pipeline MUST update this matrix. 1. Any backend PR that changes conformance-relevant behavior in FE/BE pipeline MUST update this matrix.
2. If requirement coverage changes, update: mapped tests, status, and `Last Updated` date. 2. If requirement coverage changes, update: mapped tests, status, and `Last Updated` date.
3. New normative MUSTs in specs `19/20/21` or PBS `13` addendum MUST add a new matrix row before merge. 3. New normative MUSTs in specs `19/20/21` or PBS `13` lowering obligations MUST add a new matrix row before merge.
4. Conformance-relevant FE/BE code paths for hard-gate are: 4. Conformance-relevant FE/BE code paths for hard-gate are:
- `prometeu-compiler/prometeu-build-pipeline/` - `prometeu-compiler/prometeu-build-pipeline/`
- `prometeu-compiler/frontends/prometeu-frontend-pbs/` - `prometeu-compiler/frontends/prometeu-frontend-pbs/`
@@ -65,12 +65,13 @@ The canonical stage order is:
1. `ResolveDepsPipelineStage` 1. `ResolveDepsPipelineStage`
2. `LoadSourcesPipelineStage` 2. `LoadSourcesPipelineStage`
3. `FrontendPhasePipelineStage` 3. `FrontendPhasePipelineStage`
4. `LowerToIRVMPipelineStage` 4. `AssembleLifecyclePipelineStage`
5. `OptimizeIRVMPipelineStage` 5. `LowerToIRVMPipelineStage`
6. `EmitBytecodePipelineStage` 6. `OptimizeIRVMPipelineStage`
7. `LinkBytecodePipelineStage` 7. `EmitBytecodePipelineStage`
8. `VerifyBytecodePipelineStage` 8. `LinkBytecodePipelineStage`
9. `WriteBytecodeArtifactPipelineStage` 9. `VerifyBytecodePipelineStage`
10. `WriteBytecodeArtifactPipelineStage`
Public entrypoints MAY terminate early according to this document, but they MUST NOT: Public entrypoints MAY terminate early according to this document, but they MUST NOT:
@@ -82,21 +83,23 @@ Public entrypoints MAY terminate early according to this document, but they MUST
### 6.1 `analyze` ### 6.1 `analyze`
`analyze` MUST terminate at `FrontendPhasePipelineStage`. `analyze` MUST terminate at `AssembleLifecyclePipelineStage`.
`analyze` is defined as: `analyze` is defined as:
1. `ResolveDeps` 1. `ResolveDeps`
2. `LoadSources` 2. `LoadSources`
3. `FrontendPhase` 3. `FrontendPhase`
4. `AssembleLifecycle`
`analyze` MUST: `analyze` MUST:
1. resolve workspace/dependency inputs needed by the frontend, 1. resolve workspace/dependency inputs needed by the frontend,
2. load source surfaces admitted by the selected compiler configuration, 2. load source surfaces admitted by the selected compiler configuration,
3. run frontend semantic analysis, 3. run frontend semantic analysis and emit a declarative `IRBackend`,
4. return an `AnalysisSnapshot` or equivalent result contract, 4. assemble the common lifecycle from `IRLifecycleDeclaration` when present,
5. and remain free of backend artifact side effects. 5. return an `AnalysisSnapshot` or equivalent result contract whose `IRBackend` is fully assembled when the handoff is executable,
6. and remain free of backend artifact side effects.
`analyze` MUST NOT: `analyze` MUST NOT:
@@ -281,6 +284,10 @@ Provider registration MUST be explicit in v1. The registry contract MUST NOT use
PBS is the only initial real provider for this contract. PBS MAY be registered by an application composition root, but PBS MUST NOT become an exclusive semantic owner of the shared compiler pipeline. PBS is the only initial real provider for this contract. PBS MAY be registered by an application composition root, but PBS MUST NOT become an exclusive semantic owner of the shared compiler pipeline.
A compile-only `FrontendProvider` registered by `languageId` MUST be a valid participant of `analyze`, `compile`, and `build`. The shared pipeline MUST NOT require PBS frontend types, `.pbs` or `.barrel` sources, or PBS stdlib in order to emit verified bytecode. Test-only frontends MAY exist solely as fixtures. They MUST NOT be product languages, MUST NOT be registered by default bootstrap or Studio composition, and MUST NOT be discovered by plugin scanning, classpath scanning, or external JAR loading.
The frontend registry MUST expose explicit `register` and `unregister` operations. `unregister` MUST refuse to remove the default PBS provider. Lookup of an unknown `languageId` MUST fail explicitly. `unregister` of an unknown `languageId` MUST be a no-op.
## 9. Public Surface Rule ## 9. Public Surface Rule
The shared compiler public surface MUST expose explicit entrypoints equivalent in meaning to: The shared compiler public surface MUST expose explicit entrypoints equivalent in meaning to:
+2 -1
View File
@@ -9,7 +9,7 @@ Scope boundary:
- PROMETEU itself is a fantasy handheld / fantasy console with a broader machine model, firmware model, cartridge model, and virtual hardware surface. - PROMETEU itself is a fantasy handheld / fantasy console with a broader machine model, firmware model, cartridge model, and virtual hardware surface.
- This document does not define the whole PROMETEU machine. - This document does not define the whole PROMETEU machine.
- This document defines the VM/runtime subsystem that executes bytecode inside that machine. - This document defines the VM/runtime subsystem that executes bytecode inside that machine.
- For broader machine-level framing, see [`../specs/README.md`](../specs/README.md). - For broader machine-level framing, see [`../specs/README.md`](../specs/runtime/README.md).
Document roles: Document roles:
@@ -149,6 +149,7 @@ The verifier statically checks bytecode for structural safety and stack‑shape
- `SyscallMeta` defines expected arity and return slot counts. The loader resolves `HOSTCALL` against this metadata and rejects raw `SYSCALL` in PBX pre-load artifacts; the verifier checks final IDs/arity/return‑slot counts against the same metadata. - `SyscallMeta` defines expected arity and return slot counts. The loader resolves `HOSTCALL` against this metadata and rejects raw `SYSCALL` in PBX pre-load artifacts; the verifier checks final IDs/arity/return‑slot counts against the same metadata.
- Arguments and returns - Arguments and returns
- Arguments are taken from the operand stack in the order defined by the ABI. Returns use multi‑slot results via a host‑side return buffer (`HostReturn`) which the VM copies back onto the stack, or zero slots for “void”. A mismatch in result counts is a fault/panic per current hardening logic. - Arguments are taken from the operand stack in the order defined by the ABI. Returns use multi‑slot results via a host‑side return buffer (`HostReturn`) which the VM copies back onto the stack, or zero slots for “void”. A mismatch in result counts is a fault/panic per current hardening logic.
- Example: the canonical asset runtime load surface is `asset.load(asset_id, slot) -> (status, handle)`. The caller does not supply `asset_name` or `asset_type`; bank kind is derived from `asset_table` using `asset_id`.
- Capabilities - Capabilities
- Cartridge capability flags are applied before load-time host resolution. Missing required capability aborts load; invoking a syscall without the required capability also traps defensively at runtime. - Cartridge capability flags are applied before load-time host resolution. Missing required capability aborts load; invoking a syscall without the required capability also traps defensively at runtime.
+11
View File
@@ -78,6 +78,17 @@ Authority rule:
- `INTRINSIC u32` — final numeric VM-owned intrinsic call. - `INTRINSIC u32` — final numeric VM-owned intrinsic call.
- `FRAME_SYNC` — yield until the next frame boundary (e.g., vblank); explicit safepoint. - `FRAME_SYNC` — yield until the next frame boundary (e.g., vblank); explicit safepoint.
Host service arity is not encoded in the opcode itself. It is defined by resolved syscall metadata.
Example:
- `asset.load` currently resolves with `arg_slots = 2` and `ret_slots = 2`.
- The canonical stack contract is `asset_id, slot -> status, handle`.
- Callers do not provide an explicit asset kind; the runtime derives it from `asset_table`.
- `composer.bind_scene` resolves with `arg_slots = 1` and `ret_slots = 1`.
- The canonical stack contract is `bank_id -> status`.
- `composer.emit_sprite` resolves with `arg_slots = 9` and `ret_slots = 1`.
#### Canonical Intrinsic Registry Artifact #### Canonical Intrinsic Registry Artifact
- Final intrinsic IDs and intrinsic stack metadata are published in [`INTRINSICS.csv`](INTRINSICS.csv). - Final intrinsic IDs and intrinsic stack metadata are published in [`INTRINSICS.csv`](INTRINSICS.csv).
+32
View File
@@ -0,0 +1,32 @@
# VM Architecture Mirror Policy
The Prometeu runtime repository is the normative authority for PBX binary
layout, Core ISA, loader behavior, verification, and PVM execution semantics.
The files in this directory are convenience mirrors for Studio-side compiler
and integration work; they are not an independent architectural authority.
Canonical runtime sources:
- `../runtime/docs/vm-arch/ARCHITECTURE.md`
- `../runtime/docs/vm-arch/ISA_CORE.md`
- `../runtime/docs/vm-arch/INTRINSICS.csv`
When these mirrors are retained, an integration change that updates a canonical
runtime source MUST update the corresponding Studio mirror in the same logical
change. Verify synchronization from the Studio repository root with:
```bash
diff -u docs/vm-arch/ARCHITECTURE.md ../runtime/docs/vm-arch/ARCHITECTURE.md
diff -u docs/vm-arch/ISA_CORE.md ../runtime/docs/vm-arch/ISA_CORE.md
diff -u docs/vm-arch/INTRINSICS.csv ../runtime/docs/vm-arch/INTRINSICS.csv
```
All three commands MUST exit successfully with no output before a change claims
that the mirrors are synchronized. If the runtime repository is not available
in the same checkout, synchronization evidence must be produced against the
canonical runtime revision before merging.
Compiler-owned transformation contracts remain under `docs/specs/compiler`.
Those specifications define `IRBackend -> IRVM -> PBX` emission, but they MUST
conform to the runtime-owned PBX and ISA contracts and MUST NOT redefine runtime
execution semantics.
+2
View File
@@ -5,6 +5,7 @@ jackson = "2.18.2"
jacoco = "0.8.12" jacoco = "0.8.12"
lombok = "1.18.32" lombok = "1.18.32"
junit-jupiter = "5.12.1" junit-jupiter = "5.12.1"
archunit = "1.4.2"
slf4j = "2.0.7" slf4j = "2.0.7"
lsp4j = "1.0.0" lsp4j = "1.0.0"
@@ -19,6 +20,7 @@ apache-commons-collections = { group = "org.apache.commons", name = "commons-col
jacoco-core = { group = "org.jacoco", name = "org.jacoco.core", version.ref = "jacoco" } jacoco-core = { group = "org.jacoco", name = "org.jacoco.core", version.ref = "jacoco" }
lombok = { group = "org.projectlombok", name = "lombok", version.ref = "lombok" } lombok = { group = "org.projectlombok", name = "lombok", version.ref = "lombok" }
junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junit-jupiter" } junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junit-jupiter" }
archunit-junit5 = { group = "com.tngtech.archunit", name = "archunit-junit5", version.ref = "archunit" }
slf4j-api = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" } slf4j-api = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" }
slf4j-simple = { group = "org.slf4j", name = "slf4j-simple", version.ref = "slf4j" } slf4j-simple = { group = "org.slf4j", name = "slf4j-simple", version.ref = "slf4j" }
lsp4j = { group = "org.eclipse.lsp4j", name = "org.eclipse.lsp4j", version.ref = "lsp4j" } lsp4j = { group = "org.eclipse.lsp4j", name = "org.eclipse.lsp4j", version.ref = "lsp4j" }
-1
View File
@@ -7,7 +7,6 @@ dependencies {
implementation(project(":prometeu-infra")) implementation(project(":prometeu-infra"))
implementation(project(":prometeu-lsp:prometeu-lsp-api")) implementation(project(":prometeu-lsp:prometeu-lsp-api"))
implementation(project(":prometeu-lsp:prometeu-lsp-v1")) implementation(project(":prometeu-lsp:prometeu-lsp-v1"))
implementation(project(":prometeu-compiler:frontends:prometeu-frontend-pbs"))
implementation(project(":prometeu-compiler:prometeu-frontend-registry")) implementation(project(":prometeu-compiler:prometeu-frontend-registry"))
implementation(project(":prometeu-packer:prometeu-packer-api")) implementation(project(":prometeu-packer:prometeu-packer-api"))
implementation(project(":prometeu-packer:prometeu-packer-v1")) implementation(project(":prometeu-packer:prometeu-packer-v1"))
@@ -0,0 +1,23 @@
plugins {
id("gradle.java-library-conventions")
}
dependencies {
testImplementation(libs.archunit.junit5)
testImplementation(project(":prometeu-compiler:frontends:prometeu-frontend-pbs"))
testImplementation(project(":prometeu-compiler:prometeu-frontend-registry"))
testImplementation(project(":prometeu-compiler:prometeu-compiler-core"))
testImplementation(project(":prometeu-compiler:prometeu-frontend-api"))
testImplementation(project(":prometeu-compiler:prometeu-build-pipeline"))
testImplementation(project(":prometeu-compiler:prometeu-deps"))
testImplementation(project(":prometeu-infra"))
testImplementation(project(":prometeu-lsp:prometeu-lsp-api"))
testImplementation(project(":prometeu-lsp:prometeu-lsp-v1"))
testImplementation(project(":prometeu-studio"))
testImplementation(project(":prometeu-app"))
}
tasks.named<JacocoReport>("jacocoTestReport") {
enabled = false
}
@@ -0,0 +1,63 @@
package p.studio.architecture;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
class CommonBackendPbsPrefixScanTest {
private static final String COMPILER_SOURCE_ROOT =
"prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler";
private static final List<String> GUARDED_RELATIVE_ROOTS = List.of(
"backend",
"lifecycle",
"workspaces/stages");
private static final String FORBIDDEN_PBS_PREFIX = "__pbs.";
@Test
void commonLifecycleAndBackendMustNotDiscoverRolesFromPbsNamePrefixes() throws IOException {
final var violations = new ArrayList<String>();
final var repoRoot = locateRepoRoot();
final var compilerRoot = repoRoot.resolve(COMPILER_SOURCE_ROOT);
for (final var relativeRoot : GUARDED_RELATIVE_ROOTS) {
final var root = compilerRoot.resolve(relativeRoot);
if (!Files.exists(root)) {
fail("guarded source root is missing: " + root);
}
try (final var paths = Files.walk(root)) {
paths.filter(path -> path.toString().endsWith(".java")).forEach(path -> {
try {
if (Files.readString(path).contains(FORBIDDEN_PBS_PREFIX)) {
violations.add(repoRoot.relativize(path).toString());
}
} catch (IOException e) {
throw new IllegalStateException("failed to read source file: " + path, e);
}
});
}
}
assertTrue(
violations.isEmpty(),
"common lifecycle/backend code must not inspect __pbs. prefixes: " + violations);
}
private static Path locateRepoRoot() {
var cursor = Path.of(System.getProperty("user.dir")).toAbsolutePath().normalize();
while (cursor != null) {
final var hasDocs = Files.isDirectory(cursor.resolve("docs/specs/compiler"));
final var hasCompiler = Files.isDirectory(cursor.resolve("prometeu-compiler"));
if (hasDocs && hasCompiler) {
return cursor;
}
cursor = cursor.getParent();
}
fail("could not locate repository root from working directory");
throw new IllegalStateException("unreachable");
}
}
@@ -0,0 +1,22 @@
package p.studio.architecture;
import com.tngtech.archunit.base.DescribedPredicate;
import com.tngtech.archunit.core.domain.JavaClass;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
final class DescribedPredicates {
private DescribedPredicates() {
}
static DescribedPredicate<JavaClass> notBelongingTo(final Class<?>... allowed) {
final Set<String> allowedNames = Arrays.stream(allowed)
.map(Class::getName)
.collect(Collectors.toUnmodifiableSet());
return DescribedPredicate.describe(
"do not belong to " + allowedNames,
javaClass -> !allowedNames.contains(javaClass.getName()));
}
}
@@ -0,0 +1,85 @@
package p.studio.architecture;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
class PbsGradleDependencyAllowlistTest {
private static final Pattern PBS_PROJECT_DEP = Pattern.compile(
"(\\w+)\\(\\s*project\\(\\s*\"" + Pattern.quote(PbsModuleOrigins.PBS_GRADLE_PATH) + "\"\\s*\\)");
private static final Map<String, Set<String>> ALLOWED_CONFIGURATIONS = Map.of(
":prometeu-compiler:prometeu-frontend-registry", Set.of("implementation", "api"),
":prometeu-architecture-tests", Set.of("testImplementation"));
@Test
void onlyAllowlistedProjectsMayDependOnThePbsFrontendModule() throws IOException {
final var repoRoot = locateRepoRoot();
final var violations = new ArrayList<String>();
try (final var paths = Files.walk(repoRoot)) {
paths.filter(path -> path.getFileName().toString().equals("build.gradle.kts"))
.filter(path -> !path.toString().contains("/buildSrc/"))
.filter(path -> !path.toString().contains("/build/"))
.forEach(path -> collectViolations(repoRoot, path, violations));
}
assertTrue(violations.isEmpty(), "PBS Gradle project dependency allowlist violated: " + violations);
}
private static void collectViolations(
final Path repoRoot,
final Path buildFile,
final ArrayList<String> violations) {
final var projectPath = toProjectPath(repoRoot, buildFile);
if (PbsModuleOrigins.PBS_GRADLE_PATH.equals(projectPath)) {
return;
}
final String content;
try {
content = Files.readString(buildFile);
} catch (IOException e) {
throw new IllegalStateException("failed to read " + buildFile, e);
}
final var matcher = PBS_PROJECT_DEP.matcher(content);
while (matcher.find()) {
final var configuration = matcher.group(1);
final var allowed = ALLOWED_CONFIGURATIONS.getOrDefault(projectPath, Set.of());
if (!allowed.contains(configuration)) {
violations.add(projectPath + " " + configuration + " " + PbsModuleOrigins.PBS_GRADLE_PATH);
}
}
}
private static String toProjectPath(final Path repoRoot, final Path buildFile) {
final var relative = repoRoot.relativize(buildFile.getParent()).toString().replace('\\', '/');
if (relative.isEmpty() || ".".equals(relative)) {
return ":";
}
return ":" + relative.replace('/', ':');
}
private static Path locateRepoRoot() {
var cursor = Path.of(System.getProperty("user.dir")).toAbsolutePath().normalize();
while (cursor != null) {
final var hasDocs = Files.isDirectory(cursor.resolve("docs/specs/compiler"));
final var hasCompiler = Files.isDirectory(cursor.resolve("prometeu-compiler"));
if (hasDocs && hasCompiler) {
return cursor;
}
cursor = cursor.getParent();
}
fail("could not locate repository root from working directory");
throw new IllegalStateException("unreachable");
}
}
@@ -0,0 +1,43 @@
package p.studio.architecture;
import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import p.studio.compiler.PBSDefinitions;
import p.studio.compiler.PBSFrontendProvider;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
import static p.studio.architecture.PbsModuleOrigins.fromFrontendApiModule;
import static p.studio.architecture.PbsModuleOrigins.fromPbsModule;
import static p.studio.architecture.PbsModuleOrigins.fromRegistryModule;
@AnalyzeClasses(packages = "p.studio", importOptions = ImportOption.DoNotIncludeTests.class)
class PbsModuleBoundaryArchTest {
@ArchTest
static final ArchRule productionOutsideAllowlistMustNotDependOnPbsModuleTypes = noClasses()
.that(fromPbsModule().negate())
.and(fromRegistryModule().negate())
.should()
.dependOnClassesThat(fromPbsModule())
.because("DEC-0050: only prometeu-frontend-pbs and prometeu-frontend-registry may depend on PBS module types");
@ArchTest
static final ArchRule registryMustOnlyDependOnPbsProviderFacade = noClasses()
.that(fromRegistryModule())
.should()
.dependOnClassesThat(
fromPbsModule()
.and(DescribedPredicates.notBelongingTo(PBSFrontendProvider.class, PBSDefinitions.class)))
.because("DEC-0050: registry may depend only on PBSFrontendProvider and PBSDefinitions");
@ArchTest
static final ArchRule irBackendModelsMustNotDependOnPbsModuleTypes = noClasses()
.that(fromFrontendApiModule())
.and()
.resideInAPackage("p.studio.compiler.models..")
.should()
.dependOnClassesThat(fromPbsModule())
.because("DEC-0050: public IRBackend contract types must not depend on PBS module types");
}
@@ -0,0 +1,36 @@
package p.studio.architecture;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.core.importer.ImportOption;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
class PbsModuleClasspathTest {
@Test
void importerMustSeePbsAndRegistryModuleOrigins() {
final var classes = new ClassFileImporter()
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
.importPackages("p.studio");
final var pbsSample = classes.stream()
.filter(PbsModuleOrigins::isPbsModule)
.findFirst();
final var registrySample = classes.stream()
.filter(PbsModuleOrigins::isRegistryModule)
.findFirst();
if (pbsSample.isEmpty() || registrySample.isEmpty()) {
final var uris = classes.stream()
.limit(20)
.map(javaClass -> javaClass.getName() + " -> " + PbsModuleOrigins.sourceUri(javaClass))
.toList();
fail("PBS/registry module origins were not visible to ArchUnit. sample URIs: " + uris);
}
assertTrue(pbsSample.isPresent());
assertTrue(registrySample.isPresent());
}
}
@@ -0,0 +1,60 @@
package p.studio.architecture;
import com.tngtech.archunit.base.DescribedPredicate;
import com.tngtech.archunit.core.domain.JavaClass;
final class PbsModuleOrigins {
static final String PBS_GRADLE_PATH = ":prometeu-compiler:frontends:prometeu-frontend-pbs";
private PbsModuleOrigins() {
}
static boolean isPbsModule(final JavaClass javaClass) {
return uriContains(javaClass, "/prometeu-frontend-pbs/")
|| uriContains(javaClass, "prometeu-frontend-pbs.jar");
}
static boolean isRegistryModule(final JavaClass javaClass) {
return uriContains(javaClass, "/prometeu-frontend-registry/")
|| uriContains(javaClass, "prometeu-frontend-registry.jar");
}
static boolean isFrontendApiModule(final JavaClass javaClass) {
return uriContains(javaClass, "/prometeu-frontend-api/")
|| uriContains(javaClass, "prometeu-frontend-api.jar");
}
static DescribedPredicate<JavaClass> fromPbsModule() {
return DescribedPredicate.describe(
"originate from the PBS frontend module",
PbsModuleOrigins::isPbsModule);
}
static DescribedPredicate<JavaClass> fromRegistryModule() {
return DescribedPredicate.describe(
"originate from the frontend registry module",
PbsModuleOrigins::isRegistryModule);
}
static DescribedPredicate<JavaClass> fromFrontendApiModule() {
return DescribedPredicate.describe(
"originate from the frontend-api module",
PbsModuleOrigins::isFrontendApiModule);
}
static String sourceUri(final JavaClass javaClass) {
return javaClass.getSource()
.map(source -> normalize(source.getUri().toString()))
.orElse("<no source>");
}
private static boolean uriContains(final JavaClass javaClass, final String fragment) {
return javaClass.getSource()
.map(source -> normalize(source.getUri().toString()).contains(fragment))
.orElse(false);
}
private static String normalize(final String uri) {
return uri.replace('\\', '/');
}
}
@@ -8,6 +8,9 @@ import p.studio.compiler.models.IRFunction;
import p.studio.compiler.models.IRGlobal; import p.studio.compiler.models.IRGlobal;
import p.studio.compiler.models.IRGlobalOrigin; import p.studio.compiler.models.IRGlobalOrigin;
import p.studio.compiler.models.IRGlobalVisibility; import p.studio.compiler.models.IRGlobalVisibility;
import p.studio.compiler.models.IRLifecycleCallableReference;
import p.studio.compiler.models.IRLifecycleCallableRole;
import p.studio.compiler.models.IRLifecycleFileDeclaration;
import p.studio.compiler.models.IRReservedMetadata; import p.studio.compiler.models.IRReservedMetadata;
import p.studio.compiler.models.IRSyntheticCallableKind; import p.studio.compiler.models.IRSyntheticCallableKind;
import p.studio.compiler.models.IRSyntheticFunction; import p.studio.compiler.models.IRSyntheticFunction;
@@ -215,6 +218,12 @@ public final class PbsFrontendCompiler {
if (fileInitExecutable != null) { if (fileInitExecutable != null) {
executableFunctions.add(fileInitExecutable); executableFunctions.add(fileInitExecutable);
} }
final var lifecycleDeclaration = lowerLifecycleDeclaration(
fileId,
effectiveModuleId,
lifecycleArtifacts,
fileInitExecutable,
executableFunctions);
return new IRBackendFile( return new IRBackendFile(
fileId, fileId,
functions, functions,
@@ -224,7 +233,8 @@ public final class PbsFrontendCompiler {
reservedMetadata, reservedMetadata,
effectiveModulePool, effectiveModulePool,
ReadOnlyList.wrap(callableSignatures), ReadOnlyList.wrap(callableSignatures),
executableLowering.intrinsicPool()); executableLowering.intrinsicPool(),
lifecycleDeclaration);
} }
public String callableShapeSurfaceOf(final PbsAst.FunctionDecl functionDecl) { public String callableShapeSurfaceOf(final PbsAst.FunctionDecl functionDecl) {
@@ -306,33 +316,19 @@ public final class PbsFrontendCompiler {
final var frameDecl = lifecycleArtifacts.frameDecl(); final var frameDecl = lifecycleArtifacts.frameDecl();
final var firstGlobalDecl = lifecycleArtifacts.firstGlobalDecl(); final var firstGlobalDecl = lifecycleArtifacts.firstGlobalDecl();
final var fileInitAnchorSpan = initDecl != null ? initDecl.span() : firstGlobalDecl == null ? null : firstGlobalDecl.span(); final var ordinaryFileInit = frameDecl == null ? initDecl : null;
final var fileInitAnchorName = initDecl != null ? initDecl.name() : firstGlobalDecl == null ? "" : firstGlobalDecl.name(); final var fileInitAnchorSpan = ordinaryFileInit != null
? ordinaryFileInit.span()
: firstGlobalDecl == null ? null : firstGlobalDecl.span();
final var fileInitAnchorName = ordinaryFileInit != null
? ordinaryFileInit.name()
: firstGlobalDecl == null ? "" : firstGlobalDecl.name();
if (fileInitAnchorSpan != null) { if (fileInitAnchorSpan != null) {
syntheticFunctions.add(new IRSyntheticFunction( syntheticFunctions.add(new IRSyntheticFunction(
moduleId, moduleId,
fileInitCallableName(fileId), fileInitCallableName(fileId),
IRSyntheticCallableKind.FILE_INIT_FRAGMENT, IRSyntheticCallableKind.FILE_INIT_FRAGMENT,
new IRSyntheticOrigin(fileId, fileInitAnchorName, fileInitAnchorSpan))); new IRSyntheticOrigin(fileId, fileInitAnchorName, fileInitAnchorSpan)));
syntheticFunctions.add(new IRSyntheticFunction(
moduleId,
moduleInitCallableName(moduleId),
IRSyntheticCallableKind.MODULE_INIT,
new IRSyntheticOrigin(fileId, fileInitAnchorName, fileInitAnchorSpan)));
}
if (initDecl != null && frameDecl != null) {
syntheticFunctions.add(new IRSyntheticFunction(
moduleId,
projectInitCallableName(moduleId),
IRSyntheticCallableKind.PROJECT_INIT,
new IRSyntheticOrigin(fileId, initDecl.name(), initDecl.span())));
}
if (frameDecl != null) {
syntheticFunctions.add(new IRSyntheticFunction(
moduleId,
frameWrapperCallableName(moduleId),
IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER,
new IRSyntheticOrigin(fileId, frameDecl.name(), frameDecl.span())));
} }
return ReadOnlyList.wrap(syntheticFunctions); return ReadOnlyList.wrap(syntheticFunctions);
} }
@@ -343,8 +339,10 @@ public final class PbsFrontendCompiler {
final PbsLifecycleArtifacts lifecycleArtifacts, final PbsLifecycleArtifacts lifecycleArtifacts,
final ArrayList<IRBackendExecutableFunction> executableFunctions, final ArrayList<IRBackendExecutableFunction> executableFunctions,
final ArrayList<CallableSignatureRef> callableSignatures) { final ArrayList<CallableSignatureRef> callableSignatures) {
if (lifecycleArtifacts.firstGlobalDecl() == null final var ordinaryFileInit = lifecycleArtifacts.frameDecl() == null
&& lifecycleArtifacts.initDecl() == null) { ? lifecycleArtifacts.initDecl()
: null;
if (lifecycleArtifacts.firstGlobalDecl() == null && ordinaryFileInit == null) {
return null; return null;
} }
final var syntheticCallableName = fileInitCallableName(fileId); final var syntheticCallableName = fileInitCallableName(fileId);
@@ -352,8 +350,8 @@ public final class PbsFrontendCompiler {
callableSignatures.add(new CallableSignatureRef(moduleId, syntheticCallableName, 0, "() -> unit")); callableSignatures.add(new CallableSignatureRef(moduleId, syntheticCallableName, 0, "() -> unit"));
final var instructions = new ArrayList<IRBackendExecutableFunction.Instruction>(); final var instructions = new ArrayList<IRBackendExecutableFunction.Instruction>();
final var moduleInitSource = lifecycleArtifacts.initDecl(); final var moduleInitSource = ordinaryFileInit;
if (moduleInitSource != null && moduleInitSource != lifecycleArtifacts.frameDecl()) { if (moduleInitSource != null) {
final var initExecutable = resolveLifecycleExecutable(executableFunctions, moduleId, moduleInitSource.name()); final var initExecutable = resolveLifecycleExecutable(executableFunctions, moduleId, moduleInitSource.name());
if (initExecutable != null) { if (initExecutable != null) {
instructions.add(new IRBackendExecutableFunction.Instruction( instructions.add(new IRBackendExecutableFunction.Instruction(
@@ -390,6 +388,58 @@ public final class PbsFrontendCompiler {
span); span);
} }
private IRLifecycleFileDeclaration lowerLifecycleDeclaration(
final FileId fileId,
final ModuleId moduleId,
final PbsLifecycleArtifacts lifecycleArtifacts,
final IRBackendExecutableFunction fileInitExecutable,
final ArrayList<IRBackendExecutableFunction> executableFunctions) {
final var fileInitReference = fileInitExecutable == null
? null
: new IRLifecycleCallableReference(
moduleId,
fileId,
fileInitExecutable.callableId(),
IRLifecycleCallableRole.FILE_INIT_FRAGMENT,
fileInitExecutable.span());
final var projectInitSource = lifecycleArtifacts.frameDecl() == null
? null
: lifecycleArtifacts.initDecl();
final var projectInitExecutable = projectInitSource == null
? null
: resolveLifecycleExecutable(executableFunctions, moduleId, projectInitSource.name());
final var projectInitReference = projectInitExecutable == null
? null
: new IRLifecycleCallableReference(
moduleId,
fileId,
projectInitExecutable.callableId(),
IRLifecycleCallableRole.PROJECT_INIT,
projectInitSource.span());
final var frameSource = lifecycleArtifacts.frameDecl();
final var frameExecutable = frameSource == null
? null
: resolveLifecycleExecutable(executableFunctions, moduleId, frameSource.name());
final var frameReference = frameExecutable == null
? null
: new IRLifecycleCallableReference(
moduleId,
fileId,
frameExecutable.callableId(),
IRLifecycleCallableRole.FRAME_ROOT,
frameSource.span());
final var declaration = new IRLifecycleFileDeclaration(
moduleId,
fileId,
fileInitReference,
projectInitReference,
frameReference);
return declaration.isEmpty() ? null : declaration;
}
private IRBackendExecutableFunction resolveLifecycleExecutable( private IRBackendExecutableFunction resolveLifecycleExecutable(
final ArrayList<IRBackendExecutableFunction> executableFunctions, final ArrayList<IRBackendExecutableFunction> executableFunctions,
final ModuleId moduleId, final ModuleId moduleId,
@@ -443,27 +493,6 @@ public final class PbsFrontendCompiler {
return "__pbs.file_init$f" + fileId.getId(); return "__pbs.file_init$f" + fileId.getId();
} }
public static String moduleInitCallableName(final ModuleId moduleId) {
return "__pbs.module_init$m" + normalizedModuleIndex(moduleId);
}
public static String projectInitCallableName(final ModuleId moduleId) {
return "__pbs.project_init$m" + normalizedModuleIndex(moduleId);
}
public static String frameWrapperCallableName(final ModuleId moduleId) {
return "__pbs.frame_wrapper$m" + normalizedModuleIndex(moduleId);
}
public static String bootGuardGlobalName(final ModuleId moduleId) {
return "__pbs.boot_guard$m" + normalizedModuleIndex(moduleId);
}
private static int normalizedModuleIndex(final ModuleId moduleId) {
final var normalized = moduleId == null ? ModuleId.none() : moduleId;
return normalized.isNone() ? -1 : normalized.getIndex();
}
private int safeToInt(final long value) { private int safeToInt(final long value) {
if (value > Integer.MAX_VALUE) { if (value > Integer.MAX_VALUE) {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
@@ -5,24 +5,15 @@ import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.messages.FESurfaceContext; import p.studio.compiler.messages.FESurfaceContext;
import p.studio.compiler.messages.FrontendPhaseContext; import p.studio.compiler.messages.FrontendPhaseContext;
import p.studio.compiler.models.IRBackend; import p.studio.compiler.models.IRBackend;
import p.studio.compiler.models.IRBackendExecutableFunction;
import p.studio.compiler.models.IRGlobal;
import p.studio.compiler.models.IRGlobalOrigin;
import p.studio.compiler.models.IRGlobalVisibility;
import p.studio.compiler.models.IRHiddenGlobalKind;
import p.studio.compiler.models.IRSyntheticCallableKind;
import p.studio.compiler.pbs.PbsFrontendCompiler; import p.studio.compiler.pbs.PbsFrontendCompiler;
import p.studio.compiler.pbs.PbsReservedMetadataExtractor; import p.studio.compiler.pbs.PbsReservedMetadataExtractor;
import p.studio.compiler.pbs.semantics.PbsFlowSemanticsValidator; import p.studio.compiler.pbs.semantics.PbsFlowSemanticsValidator;
import p.studio.compiler.pbs.stdlib.InterfaceModuleLoader; import p.studio.compiler.pbs.stdlib.InterfaceModuleLoader;
import p.studio.compiler.pbs.stdlib.ResourceStdlibEnvironmentResolver; import p.studio.compiler.pbs.stdlib.ResourceStdlibEnvironmentResolver;
import p.studio.compiler.pbs.stdlib.StdlibEnvironmentResolver; import p.studio.compiler.pbs.stdlib.StdlibEnvironmentResolver;
import p.studio.compiler.source.Span;
import p.studio.compiler.source.diagnostics.DiagnosticSink; import p.studio.compiler.source.diagnostics.DiagnosticSink;
import p.studio.compiler.source.identifiers.CallableId;
import p.studio.compiler.source.identifiers.FileId; import p.studio.compiler.source.identifiers.FileId;
import p.studio.compiler.source.identifiers.ModuleId; import p.studio.compiler.source.identifiers.ModuleId;
import p.studio.compiler.source.tables.CallableSignatureRef;
import p.studio.utilities.logs.LogAggregator; import p.studio.utilities.logs.LogAggregator;
import p.studio.utilities.structures.ReadOnlyList; import p.studio.utilities.structures.ReadOnlyList;
@@ -168,7 +159,7 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
private IRBackend mergeCompiledSources( private IRBackend mergeCompiledSources(
final ArrayList<CompiledSourceFile> compiledSourceFiles, final ArrayList<CompiledSourceFile> compiledSourceFiles,
final Set<ModuleId> failedModuleIds, final Set<ModuleId> failedModuleIds,
final Map<ModuleId, Set<ModuleId>> moduleDependencyGraph) { final Map<ModuleId, ReadOnlyList<ModuleId>> moduleDependencyGraph) {
final var irBackendAggregator = IRBackend.aggregator(); final var irBackendAggregator = IRBackend.aggregator();
final var blockedModuleIds = blockedModulesByDependency(failedModuleIds, moduleDependencyGraph); final var blockedModuleIds = blockedModulesByDependency(failedModuleIds, moduleDependencyGraph);
@@ -178,438 +169,70 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
} }
irBackendAggregator.merge(compiledSource.irBackendFile()); irBackendAggregator.merge(compiledSource.irBackendFile());
} }
return synthesizePublishedLifecycle(irBackendAggregator.emit()); irBackendAggregator.lifecycleModuleOrder(lifecycleModuleOrder(
compiledSourceFiles,
blockedModuleIds,
moduleDependencyGraph));
return irBackendAggregator.emit();
} }
private IRBackend synthesizePublishedLifecycle(final IRBackend baseBackend) { private ReadOnlyList<ModuleId> lifecycleModuleOrder(
final var callableSignatures = new ArrayList<>(baseBackend.getCallableSignatures().asList()); final ArrayList<CompiledSourceFile> compiledSourceFiles,
final var executableFunctions = new ArrayList<>(baseBackend.getExecutableFunctions().asList()); final Set<ModuleId> blockedModuleIds,
final var globals = new ArrayList<>(baseBackend.getGlobals().asList()); final Map<ModuleId, ReadOnlyList<ModuleId>> dependenciesByModule) {
final var fileInitFunctionsByModule = new LinkedHashMap<ModuleId, List<IRBackendExecutableFunction>>(); final var availableModules = new LinkedHashSet<ModuleId>();
final var projectInitAnchorsByModule = new LinkedHashMap<ModuleId, String>(); for (final var compiledSource : compiledSourceFiles) {
final var wrapperNamesByModule = new LinkedHashMap<ModuleId, String>(); if (!blockedModuleIds.contains(compiledSource.moduleId())) {
final var frameAnchorsByModule = new LinkedHashMap<ModuleId, String>(); availableModules.add(compiledSource.moduleId());
for (final var executable : executableFunctions) {
if (!executable.callableName().startsWith("__pbs.file_init$")) {
continue;
}
fileInitFunctionsByModule
.computeIfAbsent(normalizeModuleId(executable.moduleId()), ignored -> new ArrayList<>())
.add(executable);
}
for (final var syntheticFunction : baseBackend.getSyntheticFunctions()) {
final var moduleId = normalizeModuleId(syntheticFunction.moduleId());
switch (syntheticFunction.kind()) {
case PROJECT_INIT -> projectInitAnchorsByModule.put(moduleId, syntheticFunction.origin().anchorCallableName());
case PUBLISHED_FRAME_WRAPPER -> {
wrapperNamesByModule.put(moduleId, syntheticFunction.callableName());
frameAnchorsByModule.put(moduleId, syntheticFunction.origin().anchorCallableName());
}
default -> {
}
} }
} }
final ModuleId entryPointModuleId; final var ordered = new ArrayList<ModuleId>(availableModules.size());
final String entryPointCallableName; final var visiting = new HashSet<ModuleId>();
if (wrapperNamesByModule.size() == 1) { final var visited = new HashSet<ModuleId>();
entryPointModuleId = wrapperNamesByModule.keySet().iterator().next(); for (final var moduleId : availableModules) {
entryPointCallableName = wrapperNamesByModule.get(entryPointModuleId); appendDependenciesFirst(
} else {
entryPointModuleId = baseBackend.getEntryPointModuleId();
entryPointCallableName = baseBackend.getEntryPointCallableName();
}
final var sortedModuleIds = new ArrayList<ModuleId>();
sortedModuleIds.addAll(fileInitFunctionsByModule.keySet());
for (final var moduleId : wrapperNamesByModule.keySet()) {
if (!sortedModuleIds.contains(moduleId)) {
sortedModuleIds.add(moduleId);
}
}
sortedModuleIds.sort(Comparator.comparing(moduleId -> moduleSortKey(baseBackend, moduleId)));
final var moduleInitCallableIds = new LinkedHashMap<ModuleId, CallableId>();
for (final var moduleId : sortedModuleIds) {
final var moduleInitName = PbsFrontendCompiler.moduleInitCallableName(moduleId);
final var fileInitFunctions = new ArrayList<>(fileInitFunctionsByModule.getOrDefault(moduleId, List.of()));
if (fileInitFunctions.isEmpty()) {
continue;
}
fileInitFunctions.sort(Comparator.comparingInt(fn -> fn.fileId().getId()));
final var callableId = new CallableId(callableSignatures.size());
callableSignatures.add(new CallableSignatureRef(moduleId, moduleInitName, 0, "() -> unit"));
moduleInitCallableIds.put(moduleId, callableId);
final var instructions = new ArrayList<IRBackendExecutableFunction.Instruction>();
var anchorSpan = fileInitFunctions.getFirst().span();
var anchorFileId = fileInitFunctions.getFirst().fileId();
for (final var fileInitFunction : fileInitFunctions) {
instructions.add(callInstruction(fileInitFunction, fileInitFunction.span()));
anchorSpan = fileInitFunction.span();
anchorFileId = fileInitFunction.fileId();
}
instructions.add(retInstruction(anchorSpan));
executableFunctions.add(new IRBackendExecutableFunction(
anchorFileId,
moduleId, moduleId,
moduleInitName, availableModules,
callableId, dependenciesByModule,
safeToInt(anchorSpan.getStart()), visiting,
safeToInt(anchorSpan.getEnd()), visited,
0, ordered);
0,
0,
1,
ReadOnlyList.wrap(instructions),
anchorSpan));
} }
return ReadOnlyList.wrap(ordered);
CallableId projectInitCallableId = null;
if (!entryPointModuleId.isNone()) {
final var projectInitAnchor = projectInitAnchorsByModule.get(entryPointModuleId);
final var projectInitTarget = resolveExecutable(executableFunctions, entryPointModuleId, projectInitAnchor);
if (projectInitTarget != null) {
final var projectInitName = PbsFrontendCompiler.projectInitCallableName(entryPointModuleId);
projectInitCallableId = new CallableId(callableSignatures.size());
callableSignatures.add(new CallableSignatureRef(entryPointModuleId, projectInitName, 0, "() -> unit"));
executableFunctions.add(new IRBackendExecutableFunction(
projectInitTarget.fileId(),
entryPointModuleId,
projectInitName,
projectInitCallableId,
projectInitTarget.sourceStart(),
projectInitTarget.sourceEnd(),
0,
0,
0,
1,
ReadOnlyList.from(
callInstruction(projectInitTarget, projectInitTarget.span()),
retInstruction(projectInitTarget.span())),
projectInitTarget.span()));
}
}
final var frameExecutable = resolveExecutable(
executableFunctions,
entryPointModuleId,
frameAnchorsByModule.get(entryPointModuleId));
if (frameExecutable != null
&& entryPointCallableName != null
&& !entryPointCallableName.isBlank()
&& !entryPointModuleId.isNone()) {
final var existingBootGuard = globals.stream()
.filter(global -> moduleIdsMatch(entryPointModuleId, global.moduleId()))
.filter(global -> global.hiddenKind() == IRHiddenGlobalKind.BOOT_GUARD)
.findFirst()
.orElse(null);
final var bootGuardSlot = existingBootGuard != null
? existingBootGuard.slot()
: nextGlobalSlot(globals, entryPointModuleId);
final var wrapperCallableId = new CallableId(callableSignatures.size());
callableSignatures.add(new CallableSignatureRef(entryPointModuleId, entryPointCallableName, 0, "() -> unit"));
final var instructions = new ArrayList<IRBackendExecutableFunction.Instruction>();
instructions.add(getGlobalInstruction(bootGuardSlot, frameExecutable.span()));
instructions.add(pushBoolInstruction(true, frameExecutable.span()));
instructions.add(eqInstruction(frameExecutable.span()));
instructions.add(jumpIfTrueInstruction("bootstrap_done", frameExecutable.span()));
for (final var moduleId : sortedModuleIds) {
final var moduleInitCallableId = moduleInitCallableIds.get(moduleId);
if (moduleInitCallableId == null) {
continue;
}
instructions.add(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
moduleId,
PbsFrontendCompiler.moduleInitCallableName(moduleId),
moduleInitCallableId,
null,
null,
0,
0,
frameExecutable.span()));
}
if (projectInitCallableId != null) {
instructions.add(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
entryPointModuleId,
PbsFrontendCompiler.projectInitCallableName(entryPointModuleId),
projectInitCallableId,
null,
null,
0,
0,
frameExecutable.span()));
}
instructions.add(pushBoolInstruction(true, frameExecutable.span()));
instructions.add(setGlobalInstruction(bootGuardSlot, frameExecutable.span()));
instructions.add(labelInstruction("bootstrap_done", frameExecutable.span()));
instructions.add(callInstruction(frameExecutable, frameExecutable.span()));
instructions.add(retInstruction(frameExecutable.span()));
executableFunctions.add(new IRBackendExecutableFunction(
frameExecutable.fileId(),
entryPointModuleId,
entryPointCallableName,
wrapperCallableId,
frameExecutable.sourceStart(),
frameExecutable.sourceEnd(),
0,
0,
0,
2,
ReadOnlyList.wrap(instructions),
frameExecutable.span()));
if (existingBootGuard == null) {
globals.add(new IRGlobal(
frameExecutable.fileId(),
entryPointModuleId,
PbsFrontendCompiler.bootGuardGlobalName(entryPointModuleId),
"bool",
bootGuardSlot,
IRGlobalVisibility.MODULE,
true,
IRHiddenGlobalKind.BOOT_GUARD,
new IRGlobalOrigin(
frameExecutable.fileId(),
entryPointModuleId,
frameAnchorsByModule.getOrDefault(entryPointModuleId, frameExecutable.callableName()),
frameExecutable.span(),
"BOOT_GUARD"),
frameExecutable.span()));
}
}
final var normalizedGlobals = normalizeGlobalSlots(globals);
return IRBackend.builder()
.entryPointCallableName(entryPointCallableName)
.entryPointModuleId(entryPointModuleId)
.functions(baseBackend.getFunctions())
.syntheticFunctions(baseBackend.getSyntheticFunctions())
.globals(ReadOnlyList.wrap(normalizedGlobals))
.executableFunctions(ReadOnlyList.wrap(executableFunctions))
.modulePool(baseBackend.getModulePool())
.callableSignatures(ReadOnlyList.wrap(callableSignatures))
.intrinsicPool(baseBackend.getIntrinsicPool())
.reservedMetadata(baseBackend.getReservedMetadata())
.build();
} }
private int nextGlobalSlot( private void appendDependenciesFirst(
final ArrayList<IRGlobal> globals,
final ModuleId moduleId) {
var nextSlot = 0;
for (final var global : globals) {
if (!moduleIdsMatch(moduleId, global.moduleId())) {
continue;
}
nextSlot = Math.max(nextSlot, global.slot() + 1);
}
return nextSlot;
}
private ArrayList<IRGlobal> normalizeGlobalSlots(final ArrayList<IRGlobal> globals) {
final var nextSlotByModule = new LinkedHashMap<ModuleId, Integer>();
final var normalized = new ArrayList<IRGlobal>(globals.size());
for (final var global : globals) {
final var moduleId = normalizeModuleId(global.moduleId());
final var slot = nextSlotByModule.getOrDefault(moduleId, 0);
nextSlotByModule.put(moduleId, slot + 1);
normalized.add(new IRGlobal(
global.fileId(),
moduleId,
global.name(),
global.declaredTypeSurface(),
slot,
global.visibility(),
global.isHidden(),
global.hiddenKind(),
global.origin(),
global.span()));
}
return normalized;
}
private IRBackendExecutableFunction resolveExecutable(
final ArrayList<IRBackendExecutableFunction> executableFunctions,
final ModuleId moduleId, final ModuleId moduleId,
final String callableName) { final Set<ModuleId> availableModules,
if (callableName == null || callableName.isBlank()) { final Map<ModuleId, ReadOnlyList<ModuleId>> dependenciesByModule,
return null; final Set<ModuleId> visiting,
final Set<ModuleId> visited,
final ArrayList<ModuleId> ordered) {
if (visited.contains(moduleId) || !availableModules.contains(moduleId)) {
return;
} }
for (final var executable : executableFunctions) { if (!visiting.add(moduleId)) {
if (!callableName.equals(executable.callableName())) { return;
continue;
}
if (!moduleIdsMatch(moduleId, executable.moduleId())) {
continue;
}
return executable;
} }
return null; for (final var dependency : dependenciesByModule.getOrDefault(moduleId, ReadOnlyList.empty())) {
} appendDependenciesFirst(
dependency,
private IRBackendExecutableFunction.Instruction callInstruction( availableModules,
final IRBackendExecutableFunction callee, dependenciesByModule,
final Span span) { visiting,
return new IRBackendExecutableFunction.Instruction( visited,
IRBackendExecutableFunction.InstructionKind.CALL_FUNC, ordered);
callee.moduleId(),
callee.callableName(),
callee.callableId(),
null,
null,
callee.paramSlots(),
callee.returnSlots(),
span);
}
private IRBackendExecutableFunction.Instruction retInstruction(final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.RET,
"",
null,
null,
span);
}
private IRBackendExecutableFunction.Instruction getGlobalInstruction(
final int slot,
final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.GET_GLOBAL,
"",
null,
null,
null,
slot,
null,
span);
}
private IRBackendExecutableFunction.Instruction setGlobalInstruction(
final int slot,
final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.SET_GLOBAL,
"",
null,
null,
null,
slot,
null,
span);
}
private IRBackendExecutableFunction.Instruction pushBoolInstruction(
final boolean value,
final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.PUSH_BOOL,
"",
null,
null,
null,
value ? "true" : "false",
null,
null,
null,
span);
}
private IRBackendExecutableFunction.Instruction eqInstruction(final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.EQ,
"",
null,
null,
null,
span);
}
private IRBackendExecutableFunction.Instruction labelInstruction(
final String label,
final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.LABEL,
"",
null,
null,
null,
label,
null,
null,
null,
span);
}
private IRBackendExecutableFunction.Instruction jumpIfTrueInstruction(
final String targetLabel,
final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.JMP_IF_TRUE,
"",
null,
null,
null,
null,
targetLabel,
null,
null,
span);
}
private ModuleId normalizeModuleId(final ModuleId moduleId) {
return moduleId == null ? ModuleId.none() : moduleId;
}
private boolean moduleIdsMatch(
final ModuleId left,
final ModuleId right) {
final var normalizedLeft = normalizeModuleId(left);
final var normalizedRight = normalizeModuleId(right);
if (normalizedLeft.isNone() && normalizedRight.isNone()) {
return true;
} }
return !normalizedLeft.isNone() visiting.remove(moduleId);
&& !normalizedRight.isNone() if (visited.add(moduleId)) {
&& normalizedLeft.getIndex() == normalizedRight.getIndex(); ordered.add(moduleId);
}
private String moduleSortKey(
final IRBackend backend,
final ModuleId moduleId) {
if (moduleId != null && !moduleId.isNone()) {
final var index = moduleId.getIndex();
if (index >= 0 && index < backend.getModulePool().size()) {
final var moduleReference = backend.getModulePool().get(index);
final var joiner = new StringJoiner("/", moduleReference.project() + ":", "");
for (final var segment : moduleReference.pathSegments()) {
joiner.add(segment);
}
return joiner.toString();
}
} }
return "";
}
private int safeToInt(final long value) {
if (value > Integer.MAX_VALUE) {
return Integer.MAX_VALUE;
}
if (value < Integer.MIN_VALUE) {
return Integer.MIN_VALUE;
}
return (int) value;
} }
private Set<ModuleId> blockedModulesByDependency( private Set<ModuleId> blockedModulesByDependency(
final Set<ModuleId> failedModuleIds, final Set<ModuleId> failedModuleIds,
final Map<ModuleId, Set<ModuleId>> dependenciesByModule) { final Map<ModuleId, ReadOnlyList<ModuleId>> dependenciesByModule) {
final Map<ModuleId, Set<ModuleId>> dependentsByModule = new HashMap<>(); final Map<ModuleId, Set<ModuleId>> dependentsByModule = new HashMap<>();
for (final var entry : dependenciesByModule.entrySet()) { for (final var entry : dependenciesByModule.entrySet()) {
final var importer = entry.getKey(); final var importer = entry.getKey();
@@ -7,13 +7,14 @@ import p.studio.compiler.source.tables.ModuleTable;
import p.studio.utilities.structures.ReadOnlyList; import p.studio.utilities.structures.ReadOnlyList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
record PbsModuleAssembly( record PbsModuleAssembly(
ReadOnlyList<PbsParsedSourceFile> parsedSourceFiles, ReadOnlyList<PbsParsedSourceFile> parsedSourceFiles,
Map<ModuleId, Set<ModuleId>> moduleDependencyGraph, Map<ModuleId, ReadOnlyList<ModuleId>> moduleDependencyGraph,
ReadOnlyList<ModuleReference> canonicalModulePool, ReadOnlyList<ModuleReference> canonicalModulePool,
Set<ModuleId> failedModuleIds, Set<ModuleId> failedModuleIds,
ModuleTable moduleTable, ModuleTable moduleTable,
@@ -26,11 +27,11 @@ record PbsModuleAssembly(
if (moduleDependencyGraph == null || moduleDependencyGraph.isEmpty()) { if (moduleDependencyGraph == null || moduleDependencyGraph.isEmpty()) {
moduleDependencyGraph = Map.of(); moduleDependencyGraph = Map.of();
} else { } else {
final var copiedGraph = new HashMap<ModuleId, Set<ModuleId>>(); final var copiedGraph = new LinkedHashMap<ModuleId, ReadOnlyList<ModuleId>>();
for (final var entry : moduleDependencyGraph.entrySet()) { for (final var entry : moduleDependencyGraph.entrySet()) {
copiedGraph.put(entry.getKey(), Set.copyOf(entry.getValue() == null ? Set.of() : entry.getValue())); copiedGraph.put(entry.getKey(), entry.getValue() == null ? ReadOnlyList.empty() : entry.getValue());
} }
moduleDependencyGraph = Map.copyOf(copiedGraph); moduleDependencyGraph = java.util.Collections.unmodifiableMap(copiedGraph);
} }
if (moduleTable == null) { if (moduleTable == null) {
@@ -353,20 +353,24 @@ final class PbsModuleAssemblyService {
} }
} }
private Map<ModuleId, Set<ModuleId>> buildModuleDependencyGraph( private Map<ModuleId, ReadOnlyList<ModuleId>> buildModuleDependencyGraph(
final ArrayList<PbsParsedSourceFile> parsedSourceFiles, final ArrayList<PbsParsedSourceFile> parsedSourceFiles,
final ModuleTable moduleTable) { final ModuleTable moduleTable) {
final Map<ModuleId, Set<ModuleId>> dependenciesByModule = new HashMap<>(); final Map<ModuleId, LinkedHashSet<ModuleId>> dependenciesByModule = new LinkedHashMap<>();
for (final var parsedSource : parsedSourceFiles) { for (final var parsedSource : parsedSourceFiles) {
final var moduleDependencies = dependenciesByModule.computeIfAbsent( final var moduleDependencies = dependenciesByModule.computeIfAbsent(
parsedSource.moduleId(), parsedSource.moduleId(),
ignored -> new HashSet<>()); ignored -> new LinkedHashSet<>());
for (final var importDecl : parsedSource.ast().imports()) { for (final var importDecl : parsedSource.ast().imports()) {
final var moduleRef = importDecl.moduleRef(); final var moduleRef = importDecl.moduleRef();
moduleDependencies.add(moduleId(moduleTable, moduleRef.project(), moduleRef.pathSegments())); moduleDependencies.add(moduleId(moduleTable, moduleRef.project(), moduleRef.pathSegments()));
} }
} }
return dependenciesByModule; final Map<ModuleId, ReadOnlyList<ModuleId>> ordered = new LinkedHashMap<>();
for (final var entry : dependenciesByModule.entrySet()) {
ordered.put(entry.getKey(), ReadOnlyList.wrap(new ArrayList<>(entry.getValue())));
}
return java.util.Collections.unmodifiableMap(ordered);
} }
private ModuleId moduleId( private ModuleId moduleId(
@@ -8,6 +8,7 @@ import p.studio.compiler.models.IRBackendExecutableFunction;
import p.studio.compiler.models.IRBackendFile; import p.studio.compiler.models.IRBackendFile;
import p.studio.compiler.models.IRHiddenGlobalKind; import p.studio.compiler.models.IRHiddenGlobalKind;
import p.studio.compiler.models.IRGlobalVisibility; import p.studio.compiler.models.IRGlobalVisibility;
import p.studio.compiler.models.IRLifecycleCallableRole;
import p.studio.compiler.models.IRSyntheticCallableKind; import p.studio.compiler.models.IRSyntheticCallableKind;
import p.studio.compiler.models.SourceKind; import p.studio.compiler.models.SourceKind;
import p.studio.compiler.pbs.lexer.LexErrors; import p.studio.compiler.pbs.lexer.LexErrors;
@@ -106,7 +107,7 @@ class PbsFrontendCompilerTest {
} }
@Test @Test
void shouldExposeGlobalsAndSyntheticLifecycleArtifactsInBackendFile() { void shouldExposeGlobalsAndTypedLifecycleDeclarationInBackendFile() {
final var source = """ final var source = """
declare global SCORE: int = 0; declare global SCORE: int = 0;
@@ -129,12 +130,20 @@ class PbsFrontendCompilerTest {
assertFalse(fileBackend.globals().getFirst().isHidden()); assertFalse(fileBackend.globals().getFirst().isHidden());
assertEquals(IRHiddenGlobalKind.NONE, fileBackend.globals().getFirst().hiddenKind()); assertEquals(IRHiddenGlobalKind.NONE, fileBackend.globals().getFirst().hiddenKind());
assertEquals("SCORE", fileBackend.globals().getFirst().origin().derivedFromUserSymbol()); assertEquals("SCORE", fileBackend.globals().getFirst().origin().derivedFromUserSymbol());
assertEquals(4, fileBackend.syntheticFunctions().size()); assertEquals(1, fileBackend.syntheticFunctions().size());
assertTrue(fileBackend.syntheticFunctions().stream().anyMatch(fn -> fn.kind() == IRSyntheticCallableKind.FILE_INIT_FRAGMENT)); assertTrue(fileBackend.syntheticFunctions().stream().anyMatch(fn -> fn.kind() == IRSyntheticCallableKind.FILE_INIT_FRAGMENT));
assertTrue(fileBackend.syntheticFunctions().stream().anyMatch(fn -> fn.kind() == IRSyntheticCallableKind.MODULE_INIT));
assertTrue(fileBackend.syntheticFunctions().stream().anyMatch(fn -> fn.kind() == IRSyntheticCallableKind.PROJECT_INIT));
assertTrue(fileBackend.syntheticFunctions().stream().anyMatch(fn -> fn.kind() == IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER));
assertTrue(fileBackend.syntheticFunctions().stream().allMatch(fn -> !fn.origin().anchorCallableName().isBlank())); assertTrue(fileBackend.syntheticFunctions().stream().allMatch(fn -> !fn.origin().anchorCallableName().isBlank()));
assertEquals(IRLifecycleCallableRole.FILE_INIT_FRAGMENT,
fileBackend.lifecycleDeclaration().fileInitFragment().role());
assertEquals(IRLifecycleCallableRole.PROJECT_INIT,
fileBackend.lifecycleDeclaration().projectInit().role());
assertEquals(IRLifecycleCallableRole.FRAME_ROOT,
fileBackend.lifecycleDeclaration().frameRoot().role());
final var fileInit = fileBackend.executableFunctions().stream()
.filter(fn -> fn.callableId().equals(fileBackend.lifecycleDeclaration().fileInitFragment().callableId()))
.findFirst()
.orElseThrow();
assertTrue(fileInit.instructions().stream().noneMatch(instruction -> "boot".equals(instruction.calleeCallableName())));
} }
@Test @Test
@@ -386,8 +386,10 @@ class PBSFrontendPhaseServiceTest {
assertTrue(diagnostics.isEmpty()); assertTrue(diagnostics.isEmpty());
assertEquals(2, irBackend.getFunctions().size()); assertEquals(2, irBackend.getFunctions().size());
assertTrue(irBackend.getExecutableFunctions().stream().anyMatch(function -> "frame".equals(function.callableName()))); assertTrue(irBackend.getExecutableFunctions().stream().anyMatch(function -> "frame".equals(function.callableName())));
assertTrue(irBackend.getExecutableFunctions().stream().anyMatch(function -> assertNotNull(irBackend.getLifecycleDeclaration());
function.callableName().startsWith("__pbs.frame_wrapper$m"))); assertEquals(IRLifecycleCallableRole.FRAME_ROOT, irBackend.getLifecycleDeclaration().frameRoot().role());
assertTrue(irBackend.getSyntheticFunctions().stream().noneMatch(function ->
function.kind() == IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER));
} }
@Test @Test
@@ -483,36 +485,19 @@ class PBSFrontendPhaseServiceTest {
BuildingIssueSink.empty()); BuildingIssueSink.empty());
assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString()); assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
assertTrue(irBackend.getEntryPointCallableName().startsWith("__pbs.frame_wrapper$m")); assertNotNull(irBackend.getLifecycleDeclaration());
assertEquals(IRLifecycleCallableRole.PROJECT_INIT, irBackend.getLifecycleDeclaration().projectInit().role());
assertEquals(IRLifecycleCallableRole.FRAME_ROOT, irBackend.getLifecycleDeclaration().frameRoot().role());
final var scoreGlobal = irBackend.getGlobals().stream() final var scoreGlobal = irBackend.getGlobals().stream()
.filter(global -> "SCORE".equals(global.name())) .filter(global -> "SCORE".equals(global.name()))
.findFirst() .findFirst()
.orElseThrow(); .orElseThrow();
assertEquals(IRGlobalVisibility.PUBLIC, scoreGlobal.visibility()); assertEquals(IRGlobalVisibility.PUBLIC, scoreGlobal.visibility());
final var bootGuard = irBackend.getGlobals().stream() assertTrue(irBackend.getGlobals().stream().noneMatch(global -> global.hiddenKind() == IRHiddenGlobalKind.BOOT_GUARD));
.filter(global -> global.hiddenKind() == IRHiddenGlobalKind.BOOT_GUARD) assertTrue(irBackend.getSyntheticFunctions().stream().noneMatch(function ->
.findFirst() function.kind() == IRSyntheticCallableKind.MODULE_INIT
.orElseThrow(); || function.kind() == IRSyntheticCallableKind.PROJECT_INIT
assertTrue(bootGuard.isHidden()); || function.kind() == IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER));
assertEquals(IRGlobalVisibility.MODULE, bootGuard.visibility());
assertTrue(bootGuard.name().startsWith("__pbs.boot_guard$m"));
assertEquals(1, bootGuard.slot());
final var wrapper = irBackend.getExecutableFunctions().stream()
.filter(function -> irBackend.getEntryPointCallableName().equals(function.callableName()))
.findFirst()
.orElseThrow();
assertEquals(11, wrapper.instructions().size());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.GET_GLOBAL, wrapper.instructions().get(0).kind());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.PUSH_BOOL, wrapper.instructions().get(1).kind());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.EQ, wrapper.instructions().get(2).kind());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.JMP_IF_TRUE, wrapper.instructions().get(3).kind());
assertTrue(wrapper.instructions().get(4).calleeCallableName().startsWith("__pbs.module_init$m"));
assertTrue(wrapper.instructions().get(5).calleeCallableName().startsWith("__pbs.project_init$m"));
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.PUSH_BOOL, wrapper.instructions().get(6).kind());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.SET_GLOBAL, wrapper.instructions().get(7).kind());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.LABEL, wrapper.instructions().get(8).kind());
assertEquals("frame", wrapper.instructions().get(9).calleeCallableName());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.RET, wrapper.instructions().get(10).kind());
} }
@Test @Test
@@ -572,16 +557,100 @@ class PBSFrontendPhaseServiceTest {
BuildingIssueSink.empty()); BuildingIssueSink.empty());
assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString()); assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
assertTrue(irBackend.getEntryPointCallableName().startsWith("__pbs.frame_wrapper$m")); assertNotNull(irBackend.getLifecycleDeclaration());
assertTrue(irBackend.getExecutableFunctions().stream().anyMatch(function -> assertTrue(irBackend.getExecutableFunctions().stream().anyMatch(function ->
function.callableName().startsWith("__pbs.file_init$f"))); function.callableName().startsWith("__pbs.file_init$f")));
assertTrue(irBackend.getExecutableFunctions().stream().anyMatch(function -> assertEquals(1, irBackend.getLifecycleDeclaration().modules().getFirst().fileInitFragments().size());
function.callableName().startsWith("__pbs.module_init$m"))); assertEquals(IRLifecycleCallableRole.PROJECT_INIT, irBackend.getLifecycleDeclaration().projectInit().role());
assertTrue(irBackend.getExecutableFunctions().stream().anyMatch(function -> assertEquals(IRLifecycleCallableRole.FRAME_ROOT, irBackend.getLifecycleDeclaration().frameRoot().role());
function.callableName().startsWith("__pbs.project_init$m")));
assertTrue(irBackend.getGlobals().stream().anyMatch(global -> assertTrue(irBackend.getGlobals().stream().anyMatch(global ->
"SCORE".equals(global.name()) && global.visibility() == IRGlobalVisibility.PUBLIC)); "SCORE".equals(global.name()) && global.visibility() == IRGlobalVisibility.PUBLIC));
assertTrue(irBackend.getGlobals().stream().anyMatch(global -> global.hiddenKind() == IRHiddenGlobalKind.BOOT_GUARD)); assertTrue(irBackend.getGlobals().stream().noneMatch(global -> global.hiddenKind() == IRHiddenGlobalKind.BOOT_GUARD));
}
@Test
void shouldPublishDependencyOrderedLifecycleModulesInsteadOfNameOrFileIdOrder() throws IOException {
final var projectRoot = tempDir.resolve("project-lifecycle-dep-order");
final var sourceRoot = projectRoot.resolve("src");
final var zzzPath = sourceRoot.resolve("zzz");
final var aaaPath = sourceRoot.resolve("aaa");
Files.createDirectories(zzzPath);
Files.createDirectories(aaaPath);
final var zzzSource = zzzPath.resolve("source.pbs");
final var zzzBarrel = zzzPath.resolve("mod.barrel");
Files.writeString(zzzSource, """
declare global WARM: int = 1;
[Init]
fn warmup() -> void { return; }
""");
Files.writeString(zzzBarrel, """
pub fn warmup() -> void;
pub global WARM;
""");
final var aaaSource = aaaPath.resolve("source.pbs");
final var aaaBarrel = aaaPath.resolve("mod.barrel");
Files.writeString(aaaSource, """
import { warmup } from @app:zzz;
[Init]
fn boot() -> void {
warmup();
return;
}
[Frame]
fn frame() -> void { return; }
""");
Files.writeString(aaaBarrel, """
pub fn boot() -> void;
pub fn frame() -> void;
""");
final var projectTable = new ProjectTable();
final var fileTable = new FileTable(1);
final var projectId = projectTable.register(ProjectDescriptor.builder()
.rootPath(projectRoot)
.name("app")
.version("1.0.0")
.sourceRoots(ReadOnlyList.wrap(List.of(sourceRoot)))
.build());
registerFile(projectId, projectRoot, aaaSource, fileTable);
registerFile(projectId, projectRoot, aaaBarrel, fileTable);
registerFile(projectId, projectRoot, zzzSource, fileTable);
registerFile(projectId, projectRoot, zzzBarrel, fileTable);
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
ctx,
diagnostics,
LogAggregator.empty(),
BuildingIssueSink.empty());
assertEquals(0, diagnostics.errorCount(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
final var declaration = irBackend.getLifecycleDeclaration();
assertNotNull(declaration);
assertEquals(2, declaration.modules().size());
final var firstModule = irBackend.getModulePool().get(declaration.modules().get(0).moduleId().getIndex());
final var secondModule = irBackend.getModulePool().get(declaration.modules().get(1).moduleId().getIndex());
assertEquals("zzz", firstModule.pathSegments().getFirst());
assertEquals("aaa", secondModule.pathSegments().getFirst());
assertFalse(declaration.modules().get(0).fileInitFragments().isEmpty());
assertEquals(IRLifecycleCallableRole.PROJECT_INIT, declaration.projectInit().role());
assertEquals(IRLifecycleCallableRole.FRAME_ROOT, declaration.frameRoot().role());
assertTrue(irBackend.getSyntheticFunctions().stream().noneMatch(function ->
function.kind() == IRSyntheticCallableKind.MODULE_INIT
|| function.kind() == IRSyntheticCallableKind.PROJECT_INIT
|| function.kind() == IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER));
} }
@Test @Test
@@ -40,7 +40,7 @@ public class LowerToIRVMService {
"IRBackend has no executable functions"); "IRBackend has no executable functions");
} }
validatePbsLifecycleStructure(backend); validateCommonLifecycleStructure(backend);
final var ordered = orderFunctions(backend); final var ordered = orderFunctions(backend);
final var funcIdByCallableId = new HashMap<CallableId, Integer>(); final var funcIdByCallableId = new HashMap<CallableId, Integer>();
for (var i = 0; i < ordered.size(); i++) { for (var i = 0; i < ordered.size(); i++) {
@@ -499,7 +499,9 @@ public class LowerToIRVMService {
return ReadOnlyList.wrap(ordered); return ReadOnlyList.wrap(ordered);
} }
private void validatePbsLifecycleStructure(final IRBackend backend) { private void validateCommonLifecycleStructure(final IRBackend backend) {
// Backend precondition on an already-assembled handoff. Declaration
// validation and materialization belong to LifecycleAssemblerService.
if (backend.getSyntheticFunctions().isEmpty()) { if (backend.getSyntheticFunctions().isEmpty()) {
return; return;
} }
@@ -0,0 +1,532 @@
package p.studio.compiler.lifecycle;
import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.models.*;
import p.studio.compiler.source.Span;
import p.studio.compiler.source.identifiers.CallableId;
import p.studio.compiler.source.identifiers.ModuleId;
import p.studio.compiler.source.tables.CallableSignatureRef;
import p.studio.utilities.structures.ReadOnlyList;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Set;
public final class LifecycleAssemblerService {
public static final String PHASE = "lifecycle-assembly";
public static final String INVALID_DECLARATION = "COMMON_LIFECYCLE_INVALID_DECLARATION";
public IRBackend assemble(
final IRBackend backend,
final BuildingIssueSink issues) {
if (backend == null) {
report(issues, null, "IRBackend is required for lifecycle assembly");
return null;
}
final var declaration = backend.getLifecycleDeclaration();
if (declaration == null) {
return backend;
}
if (!validate(backend, declaration, issues)) {
return backend;
}
final var callableSignatures = new ArrayList<>(backend.getCallableSignatures().asList());
final var executableFunctions = new ArrayList<>(backend.getExecutableFunctions().asList());
final var syntheticFunctions = new ArrayList<>(backend.getSyntheticFunctions().asList());
final var globals = new ArrayList<>(backend.getGlobals().asList());
final var moduleInitCallableIds = new LinkedHashMap<ModuleId, CallableId>();
for (final var module : declaration.modules()) {
if (module.fileInitFragments().isEmpty()) {
continue;
}
final var moduleId = module.moduleId();
final var moduleInitName = moduleInitCallableName(moduleId);
final var moduleInitCallableId = new CallableId(callableSignatures.size());
callableSignatures.add(new CallableSignatureRef(moduleId, moduleInitName, 0, "() -> unit"));
moduleInitCallableIds.put(moduleId, moduleInitCallableId);
final var instructions = new ArrayList<IRBackendExecutableFunction.Instruction>();
IRBackendExecutableFunction anchor = null;
for (final var fragment : module.fileInitFragments()) {
final var executable = resolveExecutable(backend, fragment);
instructions.add(callInstruction(executable, fragment.origin()));
anchor = executable;
}
instructions.add(retInstruction(anchor.span()));
executableFunctions.add(new IRBackendExecutableFunction(
anchor.fileId(),
moduleId,
moduleInitName,
moduleInitCallableId,
anchor.sourceStart(),
anchor.sourceEnd(),
0,
0,
0,
1,
ReadOnlyList.wrap(instructions),
anchor.span()));
syntheticFunctions.add(new IRSyntheticFunction(
moduleId,
moduleInitName,
IRSyntheticCallableKind.MODULE_INIT,
new IRSyntheticOrigin(anchor.fileId(), anchor.callableName(), anchor.span())));
}
final var frameExecutable = resolveExecutable(backend, declaration.frameRoot());
final var entryPointModuleId = frameExecutable.moduleId();
CallableId projectInitCallableId = null;
if (declaration.projectInit() != null) {
final var projectInitTarget = resolveExecutable(backend, declaration.projectInit());
final var projectInitName = projectInitCallableName(entryPointModuleId);
projectInitCallableId = new CallableId(callableSignatures.size());
callableSignatures.add(new CallableSignatureRef(
entryPointModuleId,
projectInitName,
0,
"() -> unit"));
executableFunctions.add(new IRBackendExecutableFunction(
projectInitTarget.fileId(),
entryPointModuleId,
projectInitName,
projectInitCallableId,
projectInitTarget.sourceStart(),
projectInitTarget.sourceEnd(),
0,
0,
0,
1,
ReadOnlyList.from(
callInstruction(projectInitTarget, projectInitTarget.span()),
retInstruction(projectInitTarget.span())),
projectInitTarget.span()));
syntheticFunctions.add(new IRSyntheticFunction(
entryPointModuleId,
projectInitName,
IRSyntheticCallableKind.PROJECT_INIT,
new IRSyntheticOrigin(
projectInitTarget.fileId(),
projectInitTarget.callableName(),
projectInitTarget.span())));
}
final var entryPointCallableName = frameWrapperCallableName(entryPointModuleId);
final var bootGuardSlot = nextGlobalSlot(globals, entryPointModuleId);
final var wrapperCallableId = new CallableId(callableSignatures.size());
callableSignatures.add(new CallableSignatureRef(
entryPointModuleId,
entryPointCallableName,
0,
"() -> unit"));
final var wrapperInstructions = new ArrayList<IRBackendExecutableFunction.Instruction>();
wrapperInstructions.add(getGlobalInstruction(bootGuardSlot, frameExecutable.span()));
wrapperInstructions.add(pushBoolInstruction(true, frameExecutable.span()));
wrapperInstructions.add(eqInstruction(frameExecutable.span()));
wrapperInstructions.add(jumpIfTrueInstruction("bootstrap_done", frameExecutable.span()));
for (final var module : declaration.modules()) {
final var moduleInitCallableId = moduleInitCallableIds.get(module.moduleId());
if (moduleInitCallableId == null) {
continue;
}
wrapperInstructions.add(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
module.moduleId(),
moduleInitCallableName(module.moduleId()),
moduleInitCallableId,
null,
null,
0,
0,
frameExecutable.span()));
}
if (projectInitCallableId != null) {
wrapperInstructions.add(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
entryPointModuleId,
projectInitCallableName(entryPointModuleId),
projectInitCallableId,
null,
null,
0,
0,
frameExecutable.span()));
}
wrapperInstructions.add(pushBoolInstruction(true, frameExecutable.span()));
wrapperInstructions.add(setGlobalInstruction(bootGuardSlot, frameExecutable.span()));
wrapperInstructions.add(labelInstruction("bootstrap_done", frameExecutable.span()));
wrapperInstructions.add(callInstruction(frameExecutable, frameExecutable.span()));
wrapperInstructions.add(retInstruction(frameExecutable.span()));
executableFunctions.add(new IRBackendExecutableFunction(
frameExecutable.fileId(),
entryPointModuleId,
entryPointCallableName,
wrapperCallableId,
frameExecutable.sourceStart(),
frameExecutable.sourceEnd(),
0,
0,
0,
2,
ReadOnlyList.wrap(wrapperInstructions),
frameExecutable.span()));
syntheticFunctions.add(new IRSyntheticFunction(
entryPointModuleId,
entryPointCallableName,
IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER,
new IRSyntheticOrigin(
frameExecutable.fileId(),
frameExecutable.callableName(),
frameExecutable.span())));
globals.add(new IRGlobal(
frameExecutable.fileId(),
entryPointModuleId,
bootGuardGlobalName(entryPointModuleId),
"bool",
bootGuardSlot,
IRGlobalVisibility.MODULE,
true,
IRHiddenGlobalKind.BOOT_GUARD,
new IRGlobalOrigin(
frameExecutable.fileId(),
entryPointModuleId,
frameExecutable.callableName(),
frameExecutable.span(),
"BOOT_GUARD"),
frameExecutable.span()));
return IRBackend.builder()
.entryPointCallableName(entryPointCallableName)
.entryPointModuleId(entryPointModuleId)
.functions(backend.getFunctions())
.syntheticFunctions(ReadOnlyList.wrap(syntheticFunctions))
.globals(ReadOnlyList.wrap(normalizeGlobalSlots(globals)))
.executableFunctions(ReadOnlyList.wrap(executableFunctions))
.modulePool(backend.getModulePool())
.callableSignatures(ReadOnlyList.wrap(callableSignatures))
.intrinsicPool(backend.getIntrinsicPool())
.reservedMetadata(backend.getReservedMetadata())
.lifecycleDeclaration(declaration)
.build();
}
private boolean validate(
final IRBackend backend,
final IRLifecycleDeclaration declaration,
final BuildingIssueSink issues) {
var valid = true;
for (final var synthetic : backend.getSyntheticFunctions()) {
if (synthetic.kind() != IRSyntheticCallableKind.FILE_INIT_FRAGMENT) {
report(issues, synthetic.origin().span(),
"frontend handoff contains pre-materialized lifecycle artifact: " + synthetic.kind());
valid = false;
}
}
for (final var global : backend.getGlobals()) {
if (global.hiddenKind() == IRHiddenGlobalKind.BOOT_GUARD) {
report(issues, global.span(), "frontend handoff contains pre-materialized boot guard");
valid = false;
}
}
final Set<Integer> moduleIds = new HashSet<>();
final Set<Integer> lifecycleCallableIds = new HashSet<>();
for (final var module : declaration.modules()) {
final var moduleIndex = module.moduleId().isNone() ? -1 : module.moduleId().getIndex();
if (!moduleIds.add(moduleIndex)) {
report(issues, null, "duplicate lifecycle module: " + moduleIndex);
valid = false;
}
for (final var fragment : module.fileInitFragments()) {
valid &= validateReference(
backend,
fragment,
IRLifecycleCallableRole.FILE_INIT_FRAGMENT,
module.moduleId(),
lifecycleCallableIds,
issues);
}
}
if (declaration.projectInit() != null) {
valid &= validateReference(
backend,
declaration.projectInit(),
IRLifecycleCallableRole.PROJECT_INIT,
declaration.projectInit().moduleId(),
lifecycleCallableIds,
issues);
}
if (declaration.frameRoot() == null) {
report(issues, null, "executable lifecycle declaration is missing frame root");
valid = false;
} else {
valid &= validateReference(
backend,
declaration.frameRoot(),
IRLifecycleCallableRole.FRAME_ROOT,
declaration.frameRoot().moduleId(),
lifecycleCallableIds,
issues);
}
return valid;
}
private boolean validateReference(
final IRBackend backend,
final IRLifecycleCallableReference reference,
final IRLifecycleCallableRole expectedRole,
final ModuleId expectedModuleId,
final Set<Integer> lifecycleCallableIds,
final BuildingIssueSink issues) {
if (reference == null) {
report(issues, null, "missing lifecycle reference for role " + expectedRole);
return false;
}
var valid = true;
if (reference.role() != expectedRole) {
report(issues, reference.origin(), "incompatible lifecycle role: expected "
+ expectedRole + " but found " + reference.role());
valid = false;
}
if (!sameModuleId(reference.moduleId(), expectedModuleId)) {
report(issues, reference.origin(), "lifecycle reference module does not match declaration module");
valid = false;
}
if (reference.origin() == null || reference.origin().isNone()) {
report(issues, reference.origin(), "lifecycle reference origin is missing for role " + expectedRole);
valid = false;
}
final var callableIndex = reference.callableId().getIndex();
if (!lifecycleCallableIds.add(callableIndex)) {
report(issues, reference.origin(), "callable is assigned to multiple lifecycle roles: " + callableIndex);
valid = false;
}
if (callableIndex < 0 || callableIndex >= backend.getCallableSignatures().size()) {
report(issues, reference.origin(), "unresolved lifecycle callable id: " + callableIndex);
return false;
}
final var signature = backend.getCallableSignatures().get(callableIndex);
if (!sameModuleId(signature.moduleId(), reference.moduleId())) {
report(issues, reference.origin(), "lifecycle callable signature module mismatch: " + callableIndex);
valid = false;
}
if (resolveExecutable(backend, reference) == null) {
report(issues, reference.origin(), "lifecycle callable has no executable body: " + callableIndex);
valid = false;
}
return valid;
}
private IRBackendExecutableFunction resolveExecutable(
final IRBackend backend,
final IRLifecycleCallableReference reference) {
if (reference == null) {
return null;
}
for (final var executable : backend.getExecutableFunctions()) {
if (executable.callableId().getIndex() == reference.callableId().getIndex()
&& sameModuleId(executable.moduleId(), reference.moduleId())) {
return executable;
}
}
return null;
}
private void report(
final BuildingIssueSink issues,
final Span span,
final String message) {
final var effectiveSpan = span == null ? Span.none() : span;
issues.report(builder -> builder
.error(true)
.phase(PHASE)
.code(INVALID_DECLARATION)
.fileId(effectiveSpan.getFileId().isNone() ? null : effectiveSpan.getFileId().getId())
.start(safeToInt(effectiveSpan.getStart()))
.end(safeToInt(effectiveSpan.getEnd()))
.message(message));
}
private int nextGlobalSlot(
final ArrayList<IRGlobal> globals,
final ModuleId moduleId) {
var nextSlot = 0;
for (final var global : globals) {
if (sameModuleId(moduleId, global.moduleId())) {
nextSlot = Math.max(nextSlot, global.slot() + 1);
}
}
return nextSlot;
}
private ArrayList<IRGlobal> normalizeGlobalSlots(final ArrayList<IRGlobal> globals) {
final var nextSlotByModule = new LinkedHashMap<ModuleId, Integer>();
final var normalized = new ArrayList<IRGlobal>(globals.size());
for (final var global : globals) {
final var moduleId = normalizeModuleId(global.moduleId());
final var slot = nextSlotByModule.getOrDefault(moduleId, 0);
nextSlotByModule.put(moduleId, slot + 1);
normalized.add(new IRGlobal(
global.fileId(),
moduleId,
global.name(),
global.declaredTypeSurface(),
slot,
global.visibility(),
global.isHidden(),
global.hiddenKind(),
global.origin(),
global.span()));
}
return normalized;
}
private IRBackendExecutableFunction.Instruction callInstruction(
final IRBackendExecutableFunction callee,
final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
callee.moduleId(),
callee.callableName(),
callee.callableId(),
null,
null,
callee.paramSlots(),
callee.returnSlots(),
span);
}
private IRBackendExecutableFunction.Instruction retInstruction(final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.RET,
"",
null,
null,
span);
}
private IRBackendExecutableFunction.Instruction getGlobalInstruction(final int slot, final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.GET_GLOBAL,
"",
null,
null,
null,
slot,
null,
span);
}
private IRBackendExecutableFunction.Instruction setGlobalInstruction(final int slot, final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.SET_GLOBAL,
"",
null,
null,
null,
slot,
null,
span);
}
private IRBackendExecutableFunction.Instruction pushBoolInstruction(final boolean value, final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.PUSH_BOOL,
"",
null,
null,
null,
value ? "true" : "false",
null,
null,
null,
span);
}
private IRBackendExecutableFunction.Instruction eqInstruction(final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.EQ,
"",
null,
null,
null,
span);
}
private IRBackendExecutableFunction.Instruction labelInstruction(final String label, final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.LABEL,
"",
null,
null,
null,
label,
null,
null,
null,
span);
}
private IRBackendExecutableFunction.Instruction jumpIfTrueInstruction(final String label, final Span span) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.JMP_IF_TRUE,
"",
null,
null,
null,
null,
label,
null,
null,
span);
}
private ModuleId normalizeModuleId(final ModuleId moduleId) {
return moduleId == null ? ModuleId.none() : moduleId;
}
private boolean sameModuleId(final ModuleId left, final ModuleId right) {
final var normalizedLeft = normalizeModuleId(left);
final var normalizedRight = normalizeModuleId(right);
if (normalizedLeft.isNone() || normalizedRight.isNone()) {
return normalizedLeft.isNone() && normalizedRight.isNone();
}
return normalizedLeft.getIndex() == normalizedRight.getIndex();
}
private String moduleInitCallableName(final ModuleId moduleId) {
return "__prometeu.lifecycle.module_init$m" + normalizedModuleIndex(moduleId);
}
private String projectInitCallableName(final ModuleId moduleId) {
return "__prometeu.lifecycle.project_init$m" + normalizedModuleIndex(moduleId);
}
private String frameWrapperCallableName(final ModuleId moduleId) {
return "__prometeu.lifecycle.frame_wrapper$m" + normalizedModuleIndex(moduleId);
}
private String bootGuardGlobalName(final ModuleId moduleId) {
return "__prometeu.lifecycle.boot_guard$m" + normalizedModuleIndex(moduleId);
}
private int normalizedModuleIndex(final ModuleId moduleId) {
final var normalized = normalizeModuleId(moduleId);
return normalized.isNone() ? -1 : normalized.getIndex();
}
private int safeToInt(final long value) {
if (value > Integer.MAX_VALUE) {
return Integer.MAX_VALUE;
}
if (value < Integer.MIN_VALUE) {
return Integer.MIN_VALUE;
}
return (int) value;
}
}
@@ -23,7 +23,8 @@ public class BuilderPipelineService {
final var analyses = List.<PipelineStage>of( final var analyses = List.<PipelineStage>of(
new ResolveDepsPipelineStage(), new ResolveDepsPipelineStage(),
new LoadSourcesPipelineStage(), new LoadSourcesPipelineStage(),
new FrontendPhasePipelineStage() new FrontendPhasePipelineStage(),
new AssembleLifecyclePipelineStage()
); );
final var compile = List.<PipelineStage>of( final var compile = List.<PipelineStage>of(
@@ -0,0 +1,32 @@
package p.studio.compiler.workspaces.stages;
import lombok.extern.slf4j.Slf4j;
import p.studio.compiler.lifecycle.LifecycleAssemblerService;
import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.models.BuilderPipelineContext;
import p.studio.compiler.workspaces.PipelineStage;
import p.studio.utilities.logs.LogAggregator;
@Slf4j
public final class AssembleLifecyclePipelineStage implements PipelineStage {
private final LifecycleAssemblerService assembler;
public AssembleLifecyclePipelineStage() {
this(new LifecycleAssemblerService());
}
AssembleLifecyclePipelineStage(final LifecycleAssemblerService assembler) {
this.assembler = assembler;
}
@Override
public BuildingIssueSink run(final BuilderPipelineContext ctx, final LogAggregator logs) {
final var issues = BuildingIssueSink.empty();
final var assembled = assembler.assemble(ctx.irBackend, issues);
if (!issues.hasErrors()) {
ctx.irBackend = assembled;
logs.using(log).debug("Common lifecycle assembly completed successfully!");
}
return issues;
}
}
@@ -67,31 +67,31 @@ class LowerToIRVMServiceTest {
@Test @Test
void lowerMustPublishSyntheticWrapperAtFunctionZeroAndKeepFinalRetInWrapperPath() { void lowerMustPublishSyntheticWrapperAtFunctionZeroAndKeepFinalRetInWrapperPath() {
final var backend = IRBackend.builder() final var backend = IRBackend.builder()
.entryPointCallableName("__pbs.frame_wrapper$m0") .entryPointCallableName("__prometeu.lifecycle.frame_wrapper$m0")
.entryPointModuleId(new ModuleId(0)) .entryPointModuleId(new ModuleId(0))
.globals(ReadOnlyList.from(hiddenBootGuard(0))) .globals(ReadOnlyList.from(hiddenBootGuard(0)))
.syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction( .syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction(
new ModuleId(0), new ModuleId(0),
"__pbs.frame_wrapper$m0", "__prometeu.lifecycle.frame_wrapper$m0",
IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER, IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER,
new IRSyntheticOrigin(new FileId(0), "frame", new Span(new FileId(0), 1, 10))))) new IRSyntheticOrigin(new FileId(0), "frame", new Span(new FileId(0), 1, 10)))))
.executableFunctions(ReadOnlyList.from( .executableFunctions(ReadOnlyList.from(
fn("__pbs.file_init$f1", "app", 30, ReadOnlyList.from(ret())), fn("__prometeu.lifecycle.file_init$f1", "app", 30, ReadOnlyList.from(ret())),
fn("__pbs.module_init$m0", "app", 31, ReadOnlyList.from( fn("__prometeu.lifecycle.module_init$m0", "app", 31, ReadOnlyList.from(
callFunc("app", "__pbs.file_init$f1", 30), callFunc("app", "__prometeu.lifecycle.file_init$f1", 30),
ret())), ret())),
fn("__pbs.project_init$m0", "app", 32, ReadOnlyList.from( fn("__prometeu.lifecycle.project_init$m0", "app", 32, ReadOnlyList.from(
callFunc("app", "boot", 10), callFunc("app", "boot", 10),
ret())), ret())),
fn("boot", "app", 10, ReadOnlyList.from(ret())), fn("boot", "app", 10, ReadOnlyList.from(ret())),
fn("frame", "app", 20, ReadOnlyList.from(ret())), fn("frame", "app", 20, ReadOnlyList.from(ret())),
fn("__pbs.frame_wrapper$m0", "app", 40, ReadOnlyList.from( fn("__prometeu.lifecycle.frame_wrapper$m0", "app", 40, ReadOnlyList.from(
getGlobal(0), getGlobal(0),
pushBool(true), pushBool(true),
eq(), eq(),
jmpIfTrue("bootstrap_done"), jmpIfTrue("bootstrap_done"),
callFunc("app", "__pbs.module_init$m0", 31), callFunc("app", "__prometeu.lifecycle.module_init$m0", 31),
callFunc("app", "__pbs.project_init$m0", 32), callFunc("app", "__prometeu.lifecycle.project_init$m0", 32),
pushBool(true), pushBool(true),
setGlobal(0), setGlobal(0),
label("bootstrap_done"), label("bootstrap_done"),
@@ -101,7 +101,7 @@ class LowerToIRVMServiceTest {
final var lowered = new LowerToIRVMService().lower(backend); final var lowered = new LowerToIRVMService().lower(backend);
assertEquals("__pbs.frame_wrapper$m0", lowered.module().functions().get(0).name()); assertEquals("__prometeu.lifecycle.frame_wrapper$m0", lowered.module().functions().get(0).name());
assertEquals(IRVMOp.GET_GLOBAL, lowered.module().functions().get(0).instructions().get(0).op()); assertEquals(IRVMOp.GET_GLOBAL, lowered.module().functions().get(0).instructions().get(0).op());
assertEquals(IRVMOp.PUSH_BOOL, lowered.module().functions().get(0).instructions().get(1).op()); assertEquals(IRVMOp.PUSH_BOOL, lowered.module().functions().get(0).instructions().get(1).op());
assertEquals(IRVMOp.EQ, lowered.module().functions().get(0).instructions().get(2).op()); assertEquals(IRVMOp.EQ, lowered.module().functions().get(0).instructions().get(2).op());
@@ -124,12 +124,12 @@ class LowerToIRVMServiceTest {
@Test @Test
void lowerMustRejectWhenSyntheticWrapperEntrypointIsMissing() { void lowerMustRejectWhenSyntheticWrapperEntrypointIsMissing() {
final var backend = IRBackend.builder() final var backend = IRBackend.builder()
.entryPointCallableName("__pbs.frame_wrapper$m0") .entryPointCallableName("__prometeu.lifecycle.frame_wrapper$m0")
.entryPointModuleId(new ModuleId(0)) .entryPointModuleId(new ModuleId(0))
.globals(ReadOnlyList.from(hiddenBootGuard(0))) .globals(ReadOnlyList.from(hiddenBootGuard(0)))
.syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction( .syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction(
new ModuleId(0), new ModuleId(0),
"__pbs.frame_wrapper$m0", "__prometeu.lifecycle.frame_wrapper$m0",
IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER, IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER,
new IRSyntheticOrigin(new FileId(0), "frame", new Span(new FileId(0), 1, 10))))) new IRSyntheticOrigin(new FileId(0), "frame", new Span(new FileId(0), 1, 10)))))
.executableFunctions(ReadOnlyList.from( .executableFunctions(ReadOnlyList.from(
@@ -148,11 +148,11 @@ class LowerToIRVMServiceTest {
.globals(ReadOnlyList.from(hiddenBootGuard(0))) .globals(ReadOnlyList.from(hiddenBootGuard(0)))
.syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction( .syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction(
new ModuleId(0), new ModuleId(0),
"__pbs.frame_wrapper$m0", "__prometeu.lifecycle.frame_wrapper$m0",
IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER, IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER,
new IRSyntheticOrigin(new FileId(0), "frame", new Span(new FileId(0), 1, 10))))) new IRSyntheticOrigin(new FileId(0), "frame", new Span(new FileId(0), 1, 10)))))
.executableFunctions(ReadOnlyList.from( .executableFunctions(ReadOnlyList.from(
fn("__pbs.frame_wrapper$m0", "app", 40, ReadOnlyList.from( fn("__prometeu.lifecycle.frame_wrapper$m0", "app", 40, ReadOnlyList.from(
callFunc("app", "frame", 20), callFunc("app", "frame", 20),
ret())), ret())),
fn("frame", "app", 20, ReadOnlyList.from(ret())))) fn("frame", "app", 20, ReadOnlyList.from(ret()))))
@@ -165,15 +165,15 @@ class LowerToIRVMServiceTest {
@Test @Test
void lowerMustRejectWhenHiddenBootGuardIsMissing() { void lowerMustRejectWhenHiddenBootGuardIsMissing() {
final var backend = IRBackend.builder() final var backend = IRBackend.builder()
.entryPointCallableName("__pbs.frame_wrapper$m0") .entryPointCallableName("__prometeu.lifecycle.frame_wrapper$m0")
.entryPointModuleId(new ModuleId(0)) .entryPointModuleId(new ModuleId(0))
.syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction( .syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction(
new ModuleId(0), new ModuleId(0),
"__pbs.frame_wrapper$m0", "__prometeu.lifecycle.frame_wrapper$m0",
IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER, IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER,
new IRSyntheticOrigin(new FileId(0), "frame", new Span(new FileId(0), 1, 10))))) new IRSyntheticOrigin(new FileId(0), "frame", new Span(new FileId(0), 1, 10)))))
.executableFunctions(ReadOnlyList.from( .executableFunctions(ReadOnlyList.from(
fn("__pbs.frame_wrapper$m0", "app", 40, ReadOnlyList.from( fn("__prometeu.lifecycle.frame_wrapper$m0", "app", 40, ReadOnlyList.from(
callFunc("app", "frame", 20), callFunc("app", "frame", 20),
ret())), ret())),
fn("frame", "app", 20, ReadOnlyList.from(ret())))) fn("frame", "app", 20, ReadOnlyList.from(ret()))))
@@ -186,16 +186,16 @@ class LowerToIRVMServiceTest {
@Test @Test
void lowerMustRejectWhenSyntheticCallableOriginIsMissing() { void lowerMustRejectWhenSyntheticCallableOriginIsMissing() {
final var backend = IRBackend.builder() final var backend = IRBackend.builder()
.entryPointCallableName("__pbs.frame_wrapper$m0") .entryPointCallableName("__prometeu.lifecycle.frame_wrapper$m0")
.entryPointModuleId(new ModuleId(0)) .entryPointModuleId(new ModuleId(0))
.globals(ReadOnlyList.from(userVisibleGlobal("__pbs.boot_guard$m0", 0))) .globals(ReadOnlyList.from(userVisibleGlobal("__prometeu.lifecycle.boot_guard$m0", 0)))
.syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction( .syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction(
new ModuleId(0), new ModuleId(0),
"__pbs.frame_wrapper$m0", "__prometeu.lifecycle.frame_wrapper$m0",
IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER, IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER,
new IRSyntheticOrigin(new FileId(0), "", Span.none())))) new IRSyntheticOrigin(new FileId(0), "", Span.none()))))
.executableFunctions(ReadOnlyList.from( .executableFunctions(ReadOnlyList.from(
fn("__pbs.frame_wrapper$m0", "app", 40, ReadOnlyList.from( fn("__prometeu.lifecycle.frame_wrapper$m0", "app", 40, ReadOnlyList.from(
callFunc("app", "frame", 20), callFunc("app", "frame", 20),
ret())), ret())),
fn("frame", "app", 20, ReadOnlyList.from(ret())))) fn("frame", "app", 20, ReadOnlyList.from(ret()))))
@@ -229,6 +229,35 @@ class LowerToIRVMServiceTest {
assertTrue(emissionOps.stream().allMatch(op -> op.span() != null)); assertTrue(emissionOps.stream().allMatch(op -> op.span() != null));
} }
@Test
void lowerMustAcceptManuallyConstructedCommonIRBackend() {
final var backend = IRBackend.builder()
.entryPointCallableName("tick")
.entryPointModuleId(new ModuleId(0))
.modulePool(ReadOnlyList.from(new ModuleReference("game", ReadOnlyList.from("runtime"))))
.executableFunctions(ReadOnlyList.from(
fnWithModule("tick", "game/runtime", 0, 10, ReadOnlyList.from(
callHost("timer", "poll", 1, 0, 0),
callIntrinsic("input.pad", 1, 0),
callFuncWithExpected("game/runtime", "helper", 20, 0, 0),
ret())),
fnWithModule("helper", "game/runtime", 0, 20, ReadOnlyList.from(
ret()))))
.intrinsicPool(ReadOnlyList.from(new IntrinsicReference("input.pad", 1)))
.build();
final var lowered = new LowerToIRVMService().lower(backend);
assertEquals(2, lowered.module().functions().size());
assertEquals("tick", lowered.module().functions().getFirst().name());
final var instructions = lowered.module().functions().getFirst().instructions();
assertEquals(IRVMOp.HOSTCALL, instructions.get(0).op());
assertEquals(IRVMOp.INTRINSIC, instructions.get(1).op());
assertEquals(IRVMOp.CALL, instructions.get(2).op());
assertEquals(1, instructions.get(2).immediate());
assertEquals(IRVMOp.RET, instructions.get(3).op());
}
@Test @Test
void lowerMustRejectUnterminatedFunction() { void lowerMustRejectUnterminatedFunction() {
final var backend = IRBackend.builder() final var backend = IRBackend.builder()
@@ -421,7 +450,7 @@ class LowerToIRVMServiceTest {
return new IRGlobal( return new IRGlobal(
fileId, fileId,
ownerModuleId, ownerModuleId,
"__pbs.boot_guard$m" + moduleId, "__prometeu.lifecycle.boot_guard$m" + moduleId,
"bool", "bool",
0, 0,
IRGlobalVisibility.MODULE, IRGlobalVisibility.MODULE,
@@ -0,0 +1,99 @@
package p.studio.compiler.integration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import p.studio.compiler.FrontendRegistryService;
import p.studio.compiler.messages.BuilderPipelineConfig;
import p.studio.compiler.models.BuilderPipelineContext;
import p.studio.compiler.models.IRBackendReader;
import p.studio.compiler.models.IRHiddenGlobalKind;
import p.studio.compiler.synth.SyntheticFrontendProvider;
import p.studio.compiler.workspaces.BuilderPipelineService;
import p.studio.utilities.logs.LogAggregator;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class SyntheticFrontendPipelineTest {
@TempDir
Path projectRoot;
@Test
void compileMustEmitVerifiedBytecodeWithoutPbs() throws IOException {
writeSyntheticProject();
final var provider = new SyntheticFrontendProvider();
FrontendRegistryService.register(provider);
try {
final var context = BuilderPipelineContext.fromConfig(
new BuilderPipelineConfig(false, projectRoot.toString()));
final var result = BuilderPipelineService.INSTANCE.compile(context, LogAggregator.empty());
assertTrue(provider.syntheticCompiler().invoked(), "synthetic compiler must be the effective frontend");
assertEquals(
SyntheticFrontendProvider.LANGUAGE_ID,
result.analysisSnapshot().frontendSpec().getLanguageId());
assertFalse("pbs".equals(result.analysisSnapshot().frontendSpec().getLanguageId()));
assertTrue(provider.languageService().isEmpty());
assertTrue(
result.diagnostics().stream().noneMatch(issue -> issue.isError()),
result.diagnostics().toString());
assertNotNull(result.bytecodeModule());
assertNotNull(result.bytecodeBytes());
assertTrue(result.bytecodeBytes().length > 0);
final var backend = result.analysisSnapshot().irBackend();
assertEquals("__prometeu.lifecycle.frame_wrapper$m0", backend.getEntryPointCallableName());
assertTrue(backend.getGlobals().stream().anyMatch(global ->
global.hiddenKind() == IRHiddenGlobalKind.BOOT_GUARD
&& "__prometeu.lifecycle.boot_guard$m0".equals(global.name())));
assertNoPbsNames(backend);
assertTrue(noPbsSources(projectRoot));
} finally {
FrontendRegistryService.unregister(SyntheticFrontendProvider.LANGUAGE_ID);
assertEquals(1, FrontendRegistryService.listProviders().size());
assertEquals(
"pbs",
FrontendRegistryService.listProviders().getFirst().specification().getLanguageId());
}
}
private void writeSyntheticProject() throws IOException {
Files.writeString(projectRoot.resolve("prometeu.json"), """
{
"name": "synth-fixture",
"version": "1.0.0",
"language": "synth",
"stdlib": "1",
"target": "Game",
"dependencies": []
}
""");
Files.createDirectory(projectRoot.resolve("src"));
}
private void assertNoPbsNames(final IRBackendReader backend) {
assertFalse(backend.getEntryPointCallableName().contains("__pbs."));
assertTrue(backend.getExecutableFunctions().stream()
.noneMatch(function -> function.callableName().contains("__pbs.")));
assertTrue(backend.getSyntheticFunctions().stream()
.noneMatch(function -> function.callableName().contains("__pbs.")));
assertTrue(backend.getGlobals().stream()
.noneMatch(global -> global.name().contains("__pbs.")));
}
private boolean noPbsSources(final Path root) throws IOException {
try (final var files = Files.walk(root)) {
return files
.filter(Files::isRegularFile)
.map(path -> path.getFileName().toString())
.noneMatch(name -> name.endsWith(".pbs") || name.endsWith(".barrel"));
}
}
}
@@ -0,0 +1,367 @@
package p.studio.compiler.lifecycle;
import org.junit.jupiter.api.Test;
import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.models.IRBackend;
import p.studio.compiler.models.IRBackendExecutableFunction;
import p.studio.compiler.models.IRGlobal;
import p.studio.compiler.models.IRGlobalOrigin;
import p.studio.compiler.models.IRGlobalVisibility;
import p.studio.compiler.models.IRHiddenGlobalKind;
import p.studio.compiler.models.IRLifecycleCallableReference;
import p.studio.compiler.models.IRLifecycleCallableRole;
import p.studio.compiler.models.IRLifecycleDeclaration;
import p.studio.compiler.models.IRLifecycleModuleDeclaration;
import p.studio.compiler.models.IRSyntheticCallableKind;
import p.studio.compiler.models.IRSyntheticFunction;
import p.studio.compiler.models.IRSyntheticOrigin;
import p.studio.compiler.source.Span;
import p.studio.compiler.source.identifiers.CallableId;
import p.studio.compiler.source.identifiers.FileId;
import p.studio.compiler.source.identifiers.ModuleId;
import p.studio.compiler.source.tables.CallableSignatureRef;
import p.studio.compiler.source.tables.ModuleReference;
import p.studio.utilities.structures.ReadOnlyList;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*;
class LifecycleAssemblerServiceTest {
@Test
void assembleMustMaterializeNeutralLifecycleArtifactsInDeclaredOrder() {
final var backend = declarativeBackend();
final var issues = BuildingIssueSink.empty();
final var assembled = new LifecycleAssemblerService().assemble(backend, issues);
assertFalse(issues.hasErrors(), issues.asCollection().toString());
assertSame(backend.getLifecycleDeclaration(), assembled.getLifecycleDeclaration());
assertEquals("__prometeu.lifecycle.frame_wrapper$m1", assembled.getEntryPointCallableName());
assertEquals(1, assembled.getEntryPointModuleId().getIndex());
assertTrue(assembled.getSyntheticFunctions().stream().anyMatch(fn ->
fn.kind() == IRSyntheticCallableKind.MODULE_INIT
&& "__prometeu.lifecycle.module_init$m0".equals(fn.callableName())));
assertTrue(assembled.getSyntheticFunctions().stream().anyMatch(fn ->
fn.kind() == IRSyntheticCallableKind.PROJECT_INIT
&& "__prometeu.lifecycle.project_init$m1".equals(fn.callableName())));
assertTrue(assembled.getSyntheticFunctions().stream().anyMatch(fn ->
fn.kind() == IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER
&& "__prometeu.lifecycle.frame_wrapper$m1".equals(fn.callableName())));
assertTrue(assembled.getGlobals().stream().anyMatch(global ->
global.hiddenKind() == IRHiddenGlobalKind.BOOT_GUARD
&& global.isHidden()
&& "__prometeu.lifecycle.boot_guard$m1".equals(global.name())));
assertTrue(assembled.getSyntheticFunctions().stream().noneMatch(fn ->
fn.callableName().contains("__pbs.")));
assertTrue(assembled.getGlobals().stream().noneMatch(global ->
global.name().contains("__pbs.")));
final var wrapper = executable(assembled, "__prometeu.lifecycle.frame_wrapper$m1");
final var calledNames = wrapper.instructions().stream()
.filter(instruction -> instruction.kind() == IRBackendExecutableFunction.InstructionKind.CALL_FUNC)
.map(IRBackendExecutableFunction.Instruction::calleeCallableName)
.toList();
assertEquals(
List.of(
"__prometeu.lifecycle.module_init$m0",
"__prometeu.lifecycle.module_init$m1",
"__prometeu.lifecycle.project_init$m1",
"frame"),
calledNames);
assertEquals(
1,
calledNames.stream().filter("__prometeu.lifecycle.project_init$m1"::equals).count());
assertEquals(IRBackendExecutableFunction.InstructionKind.RET, wrapper.instructions().getLast().kind());
final var moduleInit = executable(assembled, "__prometeu.lifecycle.module_init$m0");
assertEquals(
List.of("file_init_dep"),
moduleInit.instructions().stream()
.filter(instruction -> instruction.kind() == IRBackendExecutableFunction.InstructionKind.CALL_FUNC)
.map(IRBackendExecutableFunction.Instruction::calleeCallableName)
.toList());
final var hostModuleInit = executable(assembled, "__prometeu.lifecycle.module_init$m1");
assertEquals(
List.of("file_init_host"),
hostModuleInit.instructions().stream()
.filter(instruction -> instruction.kind() == IRBackendExecutableFunction.InstructionKind.CALL_FUNC)
.map(IRBackendExecutableFunction.Instruction::calleeCallableName)
.toList());
}
@Test
void assembleMustInvokeProjectInitExactlyOnceAndExcludeItFromFileInit() {
final var assembled = new LifecycleAssemblerService().assemble(declarativeBackend(), BuildingIssueSink.empty());
final var wrapperCalls = executable(assembled, assembled.getEntryPointCallableName()).instructions().stream()
.filter(instruction -> instruction.kind() == IRBackendExecutableFunction.InstructionKind.CALL_FUNC)
.map(IRBackendExecutableFunction.Instruction::calleeCallableName)
.toList();
final var fileInitCalls = executable(assembled, "file_init_host").instructions().stream()
.filter(instruction -> instruction.kind() == IRBackendExecutableFunction.InstructionKind.CALL_FUNC)
.map(IRBackendExecutableFunction.Instruction::calleeCallableName)
.toList();
assertEquals(1, wrapperCalls.stream().filter("__prometeu.lifecycle.project_init$m1"::equals).count());
assertTrue(wrapperCalls.contains("frame"));
assertTrue(fileInitCalls.stream().noneMatch("boot"::equals));
final var projectInitWrapper = executable(assembled, "__prometeu.lifecycle.project_init$m1");
assertEquals(
List.of("boot"),
projectInitWrapper.instructions().stream()
.filter(instruction -> instruction.kind() == IRBackendExecutableFunction.InstructionKind.CALL_FUNC)
.map(IRBackendExecutableFunction.Instruction::calleeCallableName)
.toList());
}
@Test
void assembleMustNoOpWhenLifecycleDeclarationIsAbsent() {
final var backend = IRBackend.builder()
.entryPointCallableName("main")
.entryPointModuleId(new ModuleId(0))
.executableFunctions(ReadOnlyList.from(fn("main", 0, 0, 0, span(1))))
.callableSignatures(ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "main", 0, "() -> unit")))
.build();
final var issues = BuildingIssueSink.empty();
final var assembled = new LifecycleAssemblerService().assemble(backend, issues);
assertFalse(issues.hasErrors());
assertSame(backend, assembled);
assertNull(assembled.getLifecycleDeclaration());
assertTrue(assembled.getSyntheticFunctions().isEmpty());
}
@Test
void assembleMustRejectMissingFrameRootWithoutRepair() {
final var backend = backendWithDeclaration(new IRLifecycleDeclaration(
ReadOnlyList.from(new IRLifecycleModuleDeclaration(new ModuleId(0), ReadOnlyList.empty())),
null,
null));
final var issues = BuildingIssueSink.empty();
final var assembled = new LifecycleAssemblerService().assemble(backend, issues);
assertTrue(issues.hasErrors());
assertSame(backend, assembled);
assertEquals(LifecycleAssemblerService.INVALID_DECLARATION, firstCode(issues));
assertTrue(firstMessage(issues).contains("frame root"));
}
@Test
void assembleMustRejectUnresolvedCallableIds() {
final var backend = backendWithDeclaration(new IRLifecycleDeclaration(
ReadOnlyList.empty(),
null,
reference(0, 1, 99, IRLifecycleCallableRole.FRAME_ROOT, span(3))));
final var issues = BuildingIssueSink.empty();
new LifecycleAssemblerService().assemble(backend, issues);
assertTrue(issues.hasErrors());
assertTrue(firstMessage(issues).contains("unresolved lifecycle callable id"));
}
@Test
void assembleMustRejectIncompatibleRoles() {
final var backend = backendWithDeclaration(new IRLifecycleDeclaration(
ReadOnlyList.empty(),
null,
reference(0, 1, 2, IRLifecycleCallableRole.PROJECT_INIT, span(3))));
final var issues = BuildingIssueSink.empty();
new LifecycleAssemblerService().assemble(backend, issues);
assertTrue(issues.hasErrors());
assertTrue(firstMessage(issues).contains("incompatible lifecycle role"));
}
@Test
void assembleMustRejectMissingOrigin() {
final var backend = backendWithDeclaration(new IRLifecycleDeclaration(
ReadOnlyList.empty(),
null,
reference(0, 1, 2, IRLifecycleCallableRole.FRAME_ROOT, Span.none())));
final var issues = BuildingIssueSink.empty();
new LifecycleAssemblerService().assemble(backend, issues);
assertTrue(issues.hasErrors());
assertTrue(firstMessage(issues).contains("origin is missing"));
}
@Test
void assembleMustRejectPreMaterializedDerivedArtifacts() {
final var backend = declarativeBackend(new IRSyntheticFunction(
new ModuleId(1),
"already_wrapped",
IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER,
new IRSyntheticOrigin(new FileId(2), "frame", span(2))));
final var issues = BuildingIssueSink.empty();
final var assembled = new LifecycleAssemblerService().assemble(backend, issues);
assertTrue(issues.hasErrors());
assertSame(backend, assembled);
assertTrue(firstMessage(issues).contains("pre-materialized lifecycle artifact"));
}
@Test
void assembleMustRejectDuplicateModuleContributions() {
final var module = new IRLifecycleModuleDeclaration(
new ModuleId(0),
ReadOnlyList.from(reference(0, 1, 0, IRLifecycleCallableRole.FILE_INIT_FRAGMENT, span(1))));
final var backend = backendWithDeclaration(new IRLifecycleDeclaration(
ReadOnlyList.from(module, module),
reference(1, 2, 3, IRLifecycleCallableRole.PROJECT_INIT, span(2)),
reference(1, 2, 2, IRLifecycleCallableRole.FRAME_ROOT, span(2))));
final var issues = BuildingIssueSink.empty();
new LifecycleAssemblerService().assemble(backend, issues);
assertTrue(issues.hasErrors());
assertTrue(firstMessage(issues).contains("duplicate lifecycle module"));
}
@Test
void assembleMustRejectNullBackend() {
final var issues = BuildingIssueSink.empty();
final var assembled = new LifecycleAssemblerService().assemble(null, issues);
assertNull(assembled);
assertTrue(issues.hasErrors());
assertEquals(LifecycleAssemblerService.PHASE, issues.asCollection().iterator().next().getPhase());
}
private static IRBackend declarativeBackend(final IRSyntheticFunction... extraSynthetics) {
return declarativeBackend(null, extraSynthetics);
}
private static IRBackend backendWithDeclaration(final IRLifecycleDeclaration declaration) {
return declarativeBackend(declaration);
}
private static IRBackend declarativeBackend(
final IRLifecycleDeclaration declarationOverride,
final IRSyntheticFunction... extraSynthetics) {
final var depSpan = span(1);
final var hostSpan = span(2);
final var synthetics = new ArrayList<IRSyntheticFunction>();
synthetics.add(new IRSyntheticFunction(
new ModuleId(0),
"file_init_dep",
IRSyntheticCallableKind.FILE_INIT_FRAGMENT,
new IRSyntheticOrigin(new FileId(1), "warmup", depSpan)));
synthetics.add(new IRSyntheticFunction(
new ModuleId(1),
"file_init_host",
IRSyntheticCallableKind.FILE_INIT_FRAGMENT,
new IRSyntheticOrigin(new FileId(2), "boot", hostSpan)));
synthetics.addAll(Arrays.asList(extraSynthetics));
final var declaration = declarationOverride != null
? declarationOverride
: new IRLifecycleDeclaration(
ReadOnlyList.from(
new IRLifecycleModuleDeclaration(
new ModuleId(0),
ReadOnlyList.from(reference(0, 1, 0, IRLifecycleCallableRole.FILE_INIT_FRAGMENT, depSpan))),
new IRLifecycleModuleDeclaration(
new ModuleId(1),
ReadOnlyList.from(reference(1, 2, 1, IRLifecycleCallableRole.FILE_INIT_FRAGMENT, hostSpan)))),
reference(1, 2, 3, IRLifecycleCallableRole.PROJECT_INIT, hostSpan),
reference(1, 2, 2, IRLifecycleCallableRole.FRAME_ROOT, hostSpan));
return IRBackend.builder()
.entryPointCallableName("frame")
.entryPointModuleId(new ModuleId(1))
.modulePool(ReadOnlyList.from(
new ModuleReference("app", ReadOnlyList.from("zzz")),
new ModuleReference("app", ReadOnlyList.from("aaa"))))
.callableSignatures(ReadOnlyList.from(
new CallableSignatureRef(new ModuleId(0), "file_init_dep", 0, "() -> unit"),
new CallableSignatureRef(new ModuleId(1), "file_init_host", 0, "() -> unit"),
new CallableSignatureRef(new ModuleId(1), "frame", 0, "() -> unit"),
new CallableSignatureRef(new ModuleId(1), "boot", 0, "() -> unit")))
.executableFunctions(ReadOnlyList.from(
fn("file_init_dep", 1, 0, 0, depSpan),
fn("file_init_host", 2, 1, 1, hostSpan),
fn("frame", 2, 1, 2, hostSpan),
fn("boot", 2, 1, 3, hostSpan)))
.syntheticFunctions(ReadOnlyList.wrap(synthetics))
.globals(ReadOnlyList.from(new IRGlobal(
new FileId(1),
new ModuleId(0),
"SCORE",
"int",
0,
IRGlobalVisibility.MODULE,
false,
IRHiddenGlobalKind.NONE,
new IRGlobalOrigin(new FileId(1), new ModuleId(0), "SCORE", depSpan, "SCORE"),
depSpan)))
.lifecycleDeclaration(declaration)
.build();
}
private static IRLifecycleCallableReference reference(
final int moduleId,
final int fileId,
final int callableId,
final IRLifecycleCallableRole role,
final Span origin) {
return new IRLifecycleCallableReference(
new ModuleId(moduleId),
new FileId(fileId),
new CallableId(callableId),
role,
origin);
}
private static IRBackendExecutableFunction fn(
final String name,
final int fileId,
final int moduleId,
final int callableId,
final Span span) {
return new IRBackendExecutableFunction(
new FileId(fileId),
new ModuleId(moduleId),
name,
new CallableId(callableId),
(int) span.getStart(),
(int) span.getEnd(),
0,
0,
0,
1,
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.RET,
"",
null,
null,
span)),
span);
}
private static IRBackendExecutableFunction executable(final IRBackend backend, final String name) {
return backend.getExecutableFunctions().stream()
.filter(function -> name.equals(function.callableName()))
.findFirst()
.orElseThrow(() -> new AssertionError("missing executable " + name));
}
private static Span span(final int fileId) {
return new Span(new FileId(fileId), 4, 16);
}
private static String firstCode(final BuildingIssueSink issues) {
return issues.asCollection().iterator().next().getCode();
}
private static String firstMessage(final BuildingIssueSink issues) {
return issues.asCollection().iterator().next().getMessage();
}
}
@@ -36,6 +36,22 @@ class BackendConformanceMatrixSpecTest {
"G19-5.2.6", "G19-5.2.6",
"G19-5.2.7", "G19-5.2.7",
"G19-5.2.8", "G19-5.2.8",
"G19-11.1",
"G19-11.2",
"G19-11.3",
"G19-11.4",
"G19-11.5",
"G19-11.6",
"PBS12-11",
"G20-4.1.1",
"G20-4.1.2",
"G20-4.1.3",
"G20-4.2.1",
"G20-4.2.2",
"G20-4.2.3",
"G20-4.3.1",
"G20-4.3.2",
"G20-4.3.3",
"G20-6.2", "G20-6.2",
"G20-6.3", "G20-6.3",
"G20-6.4", "G20-6.4",
@@ -75,7 +91,12 @@ class BackendConformanceMatrixSpecTest {
"PBS13-12.3.2", "PBS13-12.3.2",
"PBS13-12.4.1", "PBS13-12.4.1",
"PBS13-12.4.2", "PBS13-12.4.2",
"PBS13-12.5"); "PBS13-12.5",
"PBS13-12.7",
"PBS13-12.8",
"PBS13-12.9",
"G23-5.2",
"G23-8.3");
@Test @Test
void matrixMustExistAndContainRequiredRequirementRows() throws IOException { void matrixMustExistAndContainRequiredRequirementRows() throws IOException {
@@ -0,0 +1,109 @@
package p.studio.compiler.specs;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
class ConsoleAbiAuthoritySpecTest {
private static final String SPEC_18 =
"docs/specs/compiler/18. Standard Library Surface Specification.md";
private static final String PBS_SPEC_8 =
"docs/specs/compiler-languages/pbs/8. Stdlib Environment Packaging and Loading Specification.md";
private static final String PBS_SPEC_6_2 =
"docs/specs/compiler-languages/pbs/6.2. Host ABI Binding and Loader Resolution Specification.md";
@Test
void spec18MustTreatStdlibAsDeliveryAndMustNotOwnConsoleAbi() throws IOException {
final var content = Files.readString(locateRepoRoot().resolve(SPEC_18));
assertTrue(
content.contains("This document is PBS delivery. It does not own console ABI."),
"spec 18 must state that PBS stdlib is delivery, not console ABI");
assertTrue(
content.contains("This document MUST NOT define numeric syscall identifiers, intrinsic `final_id`"),
"spec 18 must forbid defining syscall IDs and intrinsic final IDs");
assertTrue(
content.contains("or `SyscallMeta`"),
"spec 18 must forbid publishing SyscallMeta");
assertTrue(
content.contains("## 15. Console ABI Non-Ownership"),
"spec 18 must contain Console ABI Non-Ownership");
assertTrue(
content.contains("Reserved project-space path (`@sdk:*` / `@core:*`) MUST NOT imply VM-owned versus host-backed ownership."),
"spec 18 must state that @sdk/@core paths do not imply ownership");
assertTrue(
content.contains("Current stdlib line `1` ships a VM-owned builtin input shell at `@sdk:input`."),
"spec 18 must record @sdk:input as the current builtin exception");
}
@Test
void spec8MustDocumentCurrentGameStdlibLayout() throws IOException {
final var content = Files.readString(locateRepoRoot().resolve(PBS_SPEC_8));
final var layoutFence = extractFirstTextFence(content);
assertTrue(content.contains("game/stdlib/1"), "spec 8 must document game/stdlib/1");
assertTrue(content.contains("game/stdlib/1/core/color"), "spec 8 must map @core:color");
assertTrue(content.contains("game/stdlib/1/sdk/input"), "spec 8 must map @sdk:input");
assertTrue(content.contains("game/stdlib/1/sdk/log"), "spec 8 must map @sdk:log");
assertTrue(
content.contains("Physical stdlib\npath MUST NOT imply VM-owned versus host-backed ownership."),
"spec 8 must state that packaging path does not imply ownership");
assertTrue(layoutFence.contains("core/\n color/"), "layout fence must include core/color");
assertTrue(layoutFence.contains("input/"), "layout fence must include sdk/input");
assertTrue(layoutFence.contains("log/"), "layout fence must include sdk/log");
assertFalse(layoutFence.contains("audio/"), "layout fence must not ship audio as a current module");
assertFalse(layoutFence.contains("math/"), "layout fence must not ship core/math as a current module");
}
@Test
void spec62MustRequirePbsHostShellsToRepeatRuntimeRegistry() throws IOException {
final var content = Files.readString(locateRepoRoot().resolve(PBS_SPEC_6_2));
assertTrue(
content.contains("PBS shells MUST repeat identities already published by the runtime registry"),
"spec 6.2 must require PBS shells to repeat the runtime registry");
assertTrue(
content.contains("They MUST NOT invent `(module, name, version)`."),
"spec 6.2 must forbid inventing canonical host identity");
assertTrue(
content.contains("This document MUST NOT publish syscall\nIDs or `SyscallMeta`."),
"spec 6.2 must not publish the syscall catalog");
assertTrue(
content.contains("(\"gfx2d\", \"clear\", 1)"),
"spec 6.2 authority example must use a current runtime identity");
}
private static String extractFirstTextFence(final String content) {
final var startToken = "```text";
final var start = content.indexOf(startToken);
if (start < 0) {
fail("spec 8 must contain a text layout fence");
}
final var fenceStart = start + startToken.length();
final var end = content.indexOf("```", fenceStart);
if (end < 0) {
fail("spec 8 layout fence is unclosed");
}
return content.substring(fenceStart, end);
}
private static Path locateRepoRoot() {
var cursor = Path.of(System.getProperty("user.dir")).toAbsolutePath().normalize();
while (cursor != null) {
final var hasDocs = Files.isDirectory(cursor.resolve("docs/specs/compiler"));
final var hasCompiler = Files.isDirectory(cursor.resolve("prometeu-compiler"));
if (hasDocs && hasCompiler) {
return cursor;
}
cursor = cursor.getParent();
}
fail("could not locate repository root from working directory");
throw new IllegalStateException("unreachable");
}
}
@@ -11,93 +11,11 @@ import p.studio.compiler.source.diagnostics.DiagnosticSink;
import p.studio.utilities.logs.LogAggregator; import p.studio.utilities.logs.LogAggregator;
import p.studio.utilities.structures.ReadOnlySet; import p.studio.utilities.structures.ReadOnlySet;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
class FrontendProviderBoundaryTest { class FrontendProviderBoundaryTest {
@Test
void commonModulesMustNotInstantiatePbsFrontendPhaseServiceDirectly() throws IOException {
final var repoRoot = findRepoRoot(Path.of("").toAbsolutePath().normalize());
final var commonSourceRoots = List.of(
repoRoot.resolve("prometeu-compiler/prometeu-build-pipeline/src/main/java"),
repoRoot.resolve("prometeu-compiler/prometeu-deps/src/main/java"),
repoRoot.resolve("prometeu-studio/src/main/java"),
repoRoot.resolve("prometeu-app/src/main/java"));
for (final var sourceRoot : commonSourceRoots) {
if (!Files.exists(sourceRoot)) {
continue;
}
try (final var files = Files.walk(sourceRoot)) {
final var violations = files
.filter(path -> path.toString().endsWith(".java"))
.filter(path -> contains(path, "new PBSFrontendPhaseService("))
.toList();
if (!violations.isEmpty()) {
fail("common modules must resolve frontend compiler behavior through FrontendProvider: " + violations);
}
}
}
}
@Test
void commonModulesMustNotInstantiatePbsEditorialSupportServiceDirectly() throws IOException {
final var repoRoot = findRepoRoot(Path.of("").toAbsolutePath().normalize());
final var sourceRoots = List.of(
repoRoot.resolve("prometeu-compiler/prometeu-build-pipeline/src/main/java"),
repoRoot.resolve("prometeu-compiler/prometeu-deps/src/main/java"),
repoRoot.resolve("prometeu-lsp/prometeu-lsp-v1/src/main/java"),
repoRoot.resolve("prometeu-studio/src/main/java"),
repoRoot.resolve("prometeu-app/src/main/java"));
for (final var sourceRoot : sourceRoots) {
if (!Files.exists(sourceRoot)) {
continue;
}
try (final var files = Files.walk(sourceRoot)) {
final var violations = files
.filter(path -> path.toString().endsWith(".java"))
.filter(path -> contains(path, "new PbsEditorialSupportService("))
.toList();
if (!violations.isEmpty()) {
fail("common modules must resolve PBS editor behavior through FrontendProvider.languageService(): " + violations);
}
}
}
}
@Test
void commonLspMustNotImportPbsImplementationPackages() throws IOException {
final var repoRoot = findRepoRoot(Path.of("").toAbsolutePath().normalize());
final var sourceRoot = repoRoot.resolve("prometeu-lsp/prometeu-lsp-v1/src/main/java");
final var prohibitedNeedles = List.of(
"p.studio.compiler.PBSFrontendLanguageService",
"p.studio.compiler.services.PBSFrontendPhaseService",
"p.studio.compiler.pbs",
"PbsAst",
"PbsEditorial");
try (final var files = Files.walk(sourceRoot)) {
final var violations = files
.filter(path -> path.toString().endsWith(".java"))
.filter(path -> prohibitedNeedles.stream().anyMatch(needle -> contains(path, needle)))
.toList();
if (!violations.isEmpty()) {
fail("common LSP code must consume generic frontend language-service contracts instead of PBS implementation packages: "
+ violations);
}
}
}
@Test @Test
void compileOnlyFrontendProviderMayOmitLanguageService() { void compileOnlyFrontendProviderMayOmitLanguageService() {
final FrontendProvider provider = new CompileOnlyFrontendProvider(); final FrontendProvider provider = new CompileOnlyFrontendProvider();
@@ -110,26 +28,6 @@ class FrontendProviderBoundaryTest {
BuildingIssueSink.empty())); BuildingIssueSink.empty()));
} }
private boolean contains(final Path path, final String needle) {
try {
return Files.readString(path).contains(needle);
} catch (IOException e) {
throw new IllegalStateException("failed to read " + path, e);
}
}
private Path findRepoRoot(final Path start) {
var current = start;
while (current != null) {
if (Files.exists(current.resolve("settings.gradle.kts"))) {
return current;
}
current = current.getParent();
}
fail("unable to locate repository root from " + start);
return start;
}
private static final class CompileOnlyFrontendProvider implements FrontendProvider { private static final class CompileOnlyFrontendProvider implements FrontendProvider {
private final FrontendSpec specification = FrontendSpec.builder() private final FrontendSpec specification = FrontendSpec.builder()
.languageId("compile-only") .languageId("compile-only")
@@ -0,0 +1,83 @@
package p.studio.compiler.specs;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
class ValidationOwnershipSpecTest {
private static final String SPEC_19 =
"docs/specs/compiler/19. Verification and Safety Checks Specification.md";
private static final String PBS_SPEC_12 =
"docs/specs/compiler-languages/pbs/12. Diagnostics Specification.md";
private static final List<String> PBS_FORBIDDEN_COMMON_COVERAGE = List.of(
"synthetic wrapper entrypoint missing",
"published entrypoint is not function index 0",
"hidden boot guard is missing",
"synthetic callable origin missing");
@Test
void spec19MustBeCompilerGeneralAndPublishValidationOwnership() throws IOException {
final var content = Files.readString(locateRepoRoot().resolve(SPEC_19));
assertFalse(
content.startsWith("# PBS Verification"),
"spec 19 must not be titled as PBS Verification");
assertTrue(
content.contains("# Compiler Verification and Safety Checks Specification"),
"spec 19 must use the compiler-general title");
assertTrue(content.contains("## 11. Validation Ownership"), "spec 19 must contain Validation Ownership");
assertTrue(
content.contains("lowest layer that understands the failure without knowing the source language"),
"spec 19 must state the classification MUST");
assertTrue(content.contains("Parse / syntax"), "spec 19 matrix must include parse/syntax");
assertTrue(content.contains("PBS linking"), "spec 19 matrix must include PBS linking");
assertTrue(content.contains("Lifecycle assembler"), "spec 19 matrix must include lifecycle assembler");
assertTrue(
content.contains("Canonical host-binding identity"),
"spec 19 matrix must include the host-admission split");
assertTrue(
content.contains("MUST NOT depend on types from the PBS frontend module"),
"spec 19 must forbid PBS frontend module types in platform validators");
assertTrue(
content.contains("`p.studio.compiler.pbs` is not the complete boundary"),
"spec 19 must not treat package p.studio.compiler.pbs as the complete PBS boundary");
}
@Test
void pbsDiagnosticsMustNotClaimCommonStructuralFailures() throws IOException {
final var content = Files.readString(locateRepoRoot().resolve(PBS_SPEC_12));
for (final var forbidden : PBS_FORBIDDEN_COMMON_COVERAGE) {
assertFalse(
content.contains(forbidden),
"PBS spec 12 must not list common structural coverage: " + forbidden);
}
assertTrue(
content.contains("docs/specs/compiler/19. Verification and Safety Checks Specification.md"),
"PBS spec 12 must point common structural failures at spec 19");
assertTrue(
content.contains("init function must have signature fn name() -> void"),
"PBS spec 12 must retain lifecycle-marker coverage");
}
private static Path locateRepoRoot() {
var cursor = Path.of(System.getProperty("user.dir")).toAbsolutePath().normalize();
while (cursor != null) {
final var hasDocs = Files.isDirectory(cursor.resolve("docs/specs/compiler"));
final var hasCompiler = Files.isDirectory(cursor.resolve("prometeu-compiler"));
if (hasDocs && hasCompiler) {
return cursor;
}
cursor = cursor.getParent();
}
fail("could not locate repository root from working directory");
throw new IllegalStateException("unreachable");
}
}
@@ -0,0 +1,81 @@
package p.studio.compiler.synth;
import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.messages.FrontendPhaseContext;
import p.studio.compiler.models.IRBackend;
import p.studio.compiler.models.IRBackendExecutableFunction;
import p.studio.compiler.models.IRLifecycleCallableReference;
import p.studio.compiler.models.IRLifecycleCallableRole;
import p.studio.compiler.models.IRLifecycleDeclaration;
import p.studio.compiler.models.IRLifecycleModuleDeclaration;
import p.studio.compiler.services.FrontendPhaseService;
import p.studio.compiler.source.Span;
import p.studio.compiler.source.diagnostics.DiagnosticSink;
import p.studio.compiler.source.identifiers.CallableId;
import p.studio.compiler.source.identifiers.FileId;
import p.studio.compiler.source.identifiers.ModuleId;
import p.studio.compiler.source.tables.CallableSignatureRef;
import p.studio.compiler.source.tables.ModuleReference;
import p.studio.utilities.logs.LogAggregator;
import p.studio.utilities.structures.ReadOnlyList;
import java.util.concurrent.atomic.AtomicBoolean;
public final class SyntheticFrontendPhaseService implements FrontendPhaseService {
private final AtomicBoolean invoked = new AtomicBoolean();
public boolean invoked() {
return invoked.get();
}
@Override
public IRBackend compile(
final FrontendPhaseContext request,
final DiagnosticSink diagnostics,
final LogAggregator logs,
final BuildingIssueSink issues) {
invoked.set(true);
final var moduleId = new ModuleId(0);
final var fileId = new FileId(0);
final var callableId = new CallableId(0);
final var span = new Span(fileId, 0, 1);
final var frame = new IRBackendExecutableFunction(
fileId,
moduleId,
"frame",
callableId,
0,
1,
0,
0,
0,
1,
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.RET,
"",
null,
null,
span)),
span);
final var frameRoot = new IRLifecycleCallableReference(
moduleId,
fileId,
callableId,
IRLifecycleCallableRole.FRAME_ROOT,
span);
return IRBackend.builder()
.entryPointCallableName("frame")
.entryPointModuleId(moduleId)
.modulePool(ReadOnlyList.from(new ModuleReference("synth", ReadOnlyList.from("main"))))
.callableSignatures(ReadOnlyList.from(
new CallableSignatureRef(moduleId, "frame", 0, "() -> unit")))
.executableFunctions(ReadOnlyList.from(frame))
.lifecycleDeclaration(new IRLifecycleDeclaration(
ReadOnlyList.from(new IRLifecycleModuleDeclaration(moduleId, ReadOnlyList.empty())),
null,
frameRoot))
.build();
}
}
@@ -0,0 +1,31 @@
package p.studio.compiler.synth;
import p.studio.compiler.models.FrontendSpec;
import p.studio.compiler.services.FrontendPhaseService;
import p.studio.compiler.services.FrontendProvider;
import p.studio.utilities.structures.ReadOnlySet;
public final class SyntheticFrontendProvider implements FrontendProvider {
public static final String LANGUAGE_ID = "synth";
private final FrontendSpec specification = FrontendSpec.builder()
.languageId(LANGUAGE_ID)
.allowedExtensions(ReadOnlySet.from("synth"))
.sourceRoots(ReadOnlySet.from("src"))
.build();
private final SyntheticFrontendPhaseService compiler = new SyntheticFrontendPhaseService();
@Override
public FrontendSpec specification() {
return specification;
}
@Override
public FrontendPhaseService compiler() {
return compiler;
}
public SyntheticFrontendPhaseService syntheticCompiler() {
return compiler;
}
}
@@ -0,0 +1,156 @@
package p.studio.compiler.workspaces;
import org.junit.jupiter.api.Test;
import p.studio.AppMode;
import p.studio.compiler.lifecycle.LifecycleAssemblerService;
import p.studio.compiler.messages.BuilderPipelineConfig;
import p.studio.compiler.models.BuilderPipelineContext;
import p.studio.compiler.models.IRBackend;
import p.studio.compiler.models.ResolvedWorkspace;
import p.studio.compiler.source.identifiers.ProjectId;
import p.studio.compiler.models.IRBackendExecutableFunction;
import p.studio.compiler.models.IRLifecycleCallableReference;
import p.studio.compiler.models.IRLifecycleCallableRole;
import p.studio.compiler.models.IRLifecycleDeclaration;
import p.studio.compiler.models.IRLifecycleModuleDeclaration;
import p.studio.compiler.models.IRSyntheticCallableKind;
import p.studio.compiler.source.Span;
import p.studio.compiler.source.identifiers.CallableId;
import p.studio.compiler.source.identifiers.FileId;
import p.studio.compiler.source.identifiers.ModuleId;
import p.studio.compiler.source.tables.CallableSignatureRef;
import p.studio.compiler.source.tables.ModuleReference;
import p.studio.compiler.workspaces.stages.AssembleLifecyclePipelineStage;
import p.studio.compiler.workspaces.stages.EmitBytecodePipelineStage;
import p.studio.compiler.workspaces.stages.FrontendPhasePipelineStage;
import p.studio.compiler.workspaces.stages.LinkBytecodePipelineStage;
import p.studio.compiler.workspaces.stages.LoadSourcesPipelineStage;
import p.studio.compiler.workspaces.stages.LowerToIRVMPipelineStage;
import p.studio.compiler.workspaces.stages.OptimizeIRVMPipelineStage;
import p.studio.compiler.workspaces.stages.ResolveDepsPipelineStage;
import p.studio.compiler.workspaces.stages.VerifyBytecodePipelineStage;
import p.studio.compiler.workspaces.stages.WriteBytecodeArtifactPipelineStage;
import p.studio.utilities.logs.LogAggregator;
import p.studio.utilities.structures.ReadOnlyList;
import java.lang.reflect.Field;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class BuilderPipelineServiceOrderTest {
@Test
void canonicalOrderMustContainOptimizeBetweenLowerAndEmit() {
final var analyses = stageNames("analyses");
final var compile = stageNames("compile");
final var build = stageNames("build");
assertEquals(
List.of(
ResolveDepsPipelineStage.class.getSimpleName(),
LoadSourcesPipelineStage.class.getSimpleName(),
FrontendPhasePipelineStage.class.getSimpleName(),
AssembleLifecyclePipelineStage.class.getSimpleName()),
analyses);
assertEquals(
List.of(
LowerToIRVMPipelineStage.class.getSimpleName(),
OptimizeIRVMPipelineStage.class.getSimpleName(),
EmitBytecodePipelineStage.class.getSimpleName(),
LinkBytecodePipelineStage.class.getSimpleName(),
VerifyBytecodePipelineStage.class.getSimpleName()),
compile);
assertEquals(List.of(WriteBytecodeArtifactPipelineStage.class.getSimpleName()), build);
assertEquals(
FrontendPhasePipelineStage.class.getSimpleName(),
analyses.get(analyses.size() - 2));
assertEquals(
AssembleLifecyclePipelineStage.class.getSimpleName(),
analyses.getLast());
}
@Test
void analyzeMustTerminateAfterLifecycleAssemblyWithoutBackendArtifacts() {
final var ctx = BuilderPipelineContext.fromConfig(new BuilderPipelineConfig(false, "."));
ctx.irBackend = validDeclaration();
ctx.resolvedWorkspace = new ResolvedWorkspace(
new ProjectId(0),
null,
1,
AppMode.Game,
null,
null);
final var pipeline = new BuilderPipelineService(
List.of(new AssembleLifecyclePipelineStage()),
List.of(new LowerToIRVMPipelineStage()),
List.of());
final var snapshot = pipeline.analyze(ctx, LogAggregator.empty());
assertNotNull(snapshot.irBackend());
assertTrue(snapshot.irBackend().getSyntheticFunctions().stream().anyMatch(fn ->
fn.kind() == IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER));
assertEquals(
"__prometeu.lifecycle.frame_wrapper$m0",
snapshot.irBackend().getEntryPointCallableName());
assertSame(ctx.irBackend.getLifecycleDeclaration(), snapshot.irBackend().getLifecycleDeclaration());
assertNull(ctx.irvm);
assertNull(ctx.optimizedIrvm);
assertNull(ctx.bytecodeModule);
assertNull(ctx.bytecodeBytes);
assertNull(ctx.bytecodeArtifactPath);
assertTrue(snapshot.diagnostics().stream().noneMatch(issue ->
LifecycleAssemblerService.INVALID_DECLARATION.equals(issue.getCode())));
}
@SuppressWarnings("unchecked")
private static List<String> stageNames(final String fieldName) {
try {
final Field field = BuilderPipelineService.class.getDeclaredField(fieldName);
field.setAccessible(true);
final var stages = (List<PipelineStage>) field.get(BuilderPipelineService.INSTANCE);
return stages.stream().map(stage -> stage.getClass().getSimpleName()).toList();
} catch (ReflectiveOperationException e) {
throw new AssertionError("failed to inspect pipeline field " + fieldName, e);
}
}
private static IRBackend validDeclaration() {
final var span = new Span(new FileId(1), 1, 8);
return IRBackend.builder()
.entryPointCallableName("frame")
.entryPointModuleId(new ModuleId(0))
.modulePool(ReadOnlyList.from(new ModuleReference("app", ReadOnlyList.from("main"))))
.callableSignatures(ReadOnlyList.from(
new CallableSignatureRef(new ModuleId(0), "frame", 0, "() -> unit")))
.executableFunctions(ReadOnlyList.from(new IRBackendExecutableFunction(
new FileId(1),
new ModuleId(0),
"frame",
new CallableId(0),
1,
8,
0,
0,
0,
1,
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.RET,
"",
null,
null,
span)),
span)))
.lifecycleDeclaration(new IRLifecycleDeclaration(
ReadOnlyList.from(new IRLifecycleModuleDeclaration(new ModuleId(0), ReadOnlyList.empty())),
null,
new IRLifecycleCallableReference(
new ModuleId(0),
new FileId(1),
new CallableId(0),
IRLifecycleCallableRole.FRAME_ROOT,
span)))
.build();
}
}
@@ -0,0 +1,131 @@
package p.studio.compiler.workspaces.stages;
import org.junit.jupiter.api.Test;
import p.studio.compiler.lifecycle.LifecycleAssemblerService;
import p.studio.compiler.messages.BuilderPipelineConfig;
import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.models.BuilderPipelineContext;
import p.studio.compiler.models.IRBackend;
import p.studio.compiler.models.IRBackendExecutableFunction;
import p.studio.compiler.models.IRLifecycleCallableReference;
import p.studio.compiler.models.IRLifecycleCallableRole;
import p.studio.compiler.models.IRLifecycleDeclaration;
import p.studio.compiler.models.IRLifecycleModuleDeclaration;
import p.studio.compiler.models.IRSyntheticCallableKind;
import p.studio.compiler.source.Span;
import p.studio.compiler.source.identifiers.CallableId;
import p.studio.compiler.source.identifiers.FileId;
import p.studio.compiler.source.identifiers.ModuleId;
import p.studio.compiler.source.tables.CallableSignatureRef;
import p.studio.compiler.source.tables.ModuleReference;
import p.studio.utilities.logs.LogAggregator;
import p.studio.utilities.structures.ReadOnlyList;
import static org.junit.jupiter.api.Assertions.*;
class AssembleLifecyclePipelineStageTest {
@Test
void runMustAssignAssembledBackendOnSuccess() {
final var ctx = BuilderPipelineContext.fromConfig(new BuilderPipelineConfig(false, "."));
ctx.irBackend = validDeclaration();
final var original = ctx.irBackend;
final var issues = new AssembleLifecyclePipelineStage().run(ctx, LogAggregator.empty());
assertFalse(issues.hasErrors(), issues.asCollection().toString());
assertNotSame(original, ctx.irBackend);
assertTrue(ctx.irBackend.getSyntheticFunctions().stream().anyMatch(fn ->
fn.kind() == IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER));
assertEquals(
original.getLifecycleDeclaration(),
ctx.irBackend.getLifecycleDeclaration());
assertNull(ctx.irvm);
assertNull(ctx.bytecodeModule);
assertNull(ctx.bytecodeBytes);
}
@Test
void runMustKeepOriginalBackendAndReportStructuralErrors() {
final var ctx = BuilderPipelineContext.fromConfig(new BuilderPipelineConfig(false, "."));
ctx.irBackend = IRBackend.builder()
.entryPointCallableName("frame")
.entryPointModuleId(new ModuleId(0))
.executableFunctions(ReadOnlyList.from(fn("frame", 0, 0)))
.callableSignatures(ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "frame", 0, "() -> unit")))
.lifecycleDeclaration(new IRLifecycleDeclaration(ReadOnlyList.empty(), null, null))
.build();
final var original = ctx.irBackend;
final var issues = new AssembleLifecyclePipelineStage().run(ctx, LogAggregator.empty());
assertTrue(issues.hasErrors());
assertSame(original, ctx.irBackend);
assertEquals(LifecycleAssemblerService.INVALID_DECLARATION, issues.asCollection().iterator().next().getCode());
assertEquals(LifecycleAssemblerService.PHASE, issues.asCollection().iterator().next().getPhase());
assertNull(ctx.irvm);
}
@Test
void runMustNoOpForDeliberatelyNonExecutableHandoff() {
final var ctx = BuilderPipelineContext.fromConfig(new BuilderPipelineConfig(false, "."));
ctx.irBackend = IRBackend.builder()
.entryPointCallableName("main")
.entryPointModuleId(new ModuleId(0))
.executableFunctions(ReadOnlyList.from(fn("main", 0, 0)))
.build();
final var original = ctx.irBackend;
final var issues = new AssembleLifecyclePipelineStage().run(ctx, LogAggregator.empty());
assertFalse(issues.hasErrors());
assertSame(original, ctx.irBackend);
assertTrue(ctx.irBackend.getSyntheticFunctions().isEmpty());
}
private static IRBackend validDeclaration() {
final var span = new Span(new FileId(1), 1, 8);
return IRBackend.builder()
.entryPointCallableName("frame")
.entryPointModuleId(new ModuleId(0))
.modulePool(ReadOnlyList.from(new ModuleReference("app", ReadOnlyList.from("main"))))
.callableSignatures(ReadOnlyList.from(
new CallableSignatureRef(new ModuleId(0), "frame", 0, "() -> unit")))
.executableFunctions(ReadOnlyList.from(fn("frame", 0, 0)))
.lifecycleDeclaration(new IRLifecycleDeclaration(
ReadOnlyList.from(new IRLifecycleModuleDeclaration(new ModuleId(0), ReadOnlyList.empty())),
null,
new IRLifecycleCallableReference(
new ModuleId(0),
new FileId(1),
new CallableId(0),
IRLifecycleCallableRole.FRAME_ROOT,
span)))
.build();
}
private static IRBackendExecutableFunction fn(
final String name,
final int moduleId,
final int callableId) {
final var span = new Span(new FileId(1), 1, 8);
return new IRBackendExecutableFunction(
new FileId(1),
new ModuleId(moduleId),
name,
new CallableId(callableId),
1,
8,
0,
0,
0,
1,
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.RET,
"",
null,
null,
span)),
span);
}
}
@@ -34,6 +34,7 @@ public class IRBackend implements IRBackendReader {
private final ReadOnlyList<IntrinsicReference> intrinsicPool = ReadOnlyList.empty(); private final ReadOnlyList<IntrinsicReference> intrinsicPool = ReadOnlyList.empty();
@Builder.Default @Builder.Default
private final IRReservedMetadata reservedMetadata = IRReservedMetadata.empty(); private final IRReservedMetadata reservedMetadata = IRReservedMetadata.empty();
private final IRLifecycleDeclaration lifecycleDeclaration;
public static IRBackendAggregator aggregator() { public static IRBackendAggregator aggregator() {
return new IRBackendAggregator(); return new IRBackendAggregator();
@@ -53,6 +54,8 @@ public class IRBackend implements IRBackendReader {
private final ArrayList<IRReservedMetadata.BuiltinTypeSurface> builtinTypeSurfaces = new ArrayList<>(); private final ArrayList<IRReservedMetadata.BuiltinTypeSurface> builtinTypeSurfaces = new ArrayList<>();
private final ArrayList<IRReservedMetadata.BuiltinConstSurface> builtinConstSurfaces = new ArrayList<>(); private final ArrayList<IRReservedMetadata.BuiltinConstSurface> builtinConstSurfaces = new ArrayList<>();
private final LinkedHashSet<String> requiredCapabilities = new LinkedHashSet<>(); private final LinkedHashSet<String> requiredCapabilities = new LinkedHashSet<>();
private final ArrayList<IRLifecycleFileDeclaration> lifecycleFiles = new ArrayList<>();
private ReadOnlyList<ModuleId> lifecycleModuleOrder = ReadOnlyList.empty();
public void merge(final IRBackendFile backendFile) { public void merge(final IRBackendFile backendFile) {
if (backendFile == null) { if (backendFile == null) {
@@ -90,6 +93,12 @@ public class IRBackend implements IRBackendReader {
for (final var function : backendFile.executableFunctions()) { for (final var function : backendFile.executableFunctions()) {
executableFunctions.add(remapExecutableFunction(function, moduleRemap, callableRemap, intrinsicRemap)); executableFunctions.add(remapExecutableFunction(function, moduleRemap, callableRemap, intrinsicRemap));
} }
if (backendFile.lifecycleDeclaration() != null && !backendFile.lifecycleDeclaration().isEmpty()) {
lifecycleFiles.add(remapLifecycleFileDeclaration(
backendFile.lifecycleDeclaration(),
moduleRemap,
callableRemap));
}
final var metadata = backendFile.reservedMetadata(); final var metadata = backendFile.reservedMetadata();
hostMethodBindings.addAll(metadata.hostMethodBindings().asList()); hostMethodBindings.addAll(metadata.hostMethodBindings().asList());
builtinTypeSurfaces.addAll(metadata.builtinTypeSurfaces().asList()); builtinTypeSurfaces.addAll(metadata.builtinTypeSurfaces().asList());
@@ -111,6 +120,11 @@ public class IRBackend implements IRBackendReader {
return this; return this;
} }
public IRBackendAggregator lifecycleModuleOrder(final ReadOnlyList<ModuleId> moduleOrder) {
lifecycleModuleOrder = moduleOrder == null ? ReadOnlyList.empty() : moduleOrder;
return this;
}
private ModuleId[] reindexModules(final ReadOnlyList<ModuleReference> localModulePool) { private ModuleId[] reindexModules(final ReadOnlyList<ModuleReference> localModulePool) {
if (localModulePool == null || localModulePool.isEmpty()) { if (localModulePool == null || localModulePool.isEmpty()) {
return new ModuleId[0]; return new ModuleId[0];
@@ -203,6 +217,37 @@ public class IRBackend implements IRBackendReader {
function.span()); function.span());
} }
private IRLifecycleFileDeclaration remapLifecycleFileDeclaration(
final IRLifecycleFileDeclaration declaration,
final ModuleId[] moduleRemap,
final CallableId[] callableRemap) {
final var remappedModuleId = remapModuleId(
declaration.moduleId(),
moduleRemap,
"lifecycle file");
return new IRLifecycleFileDeclaration(
remappedModuleId,
declaration.fileId(),
remapLifecycleCallable(declaration.fileInitFragment(), moduleRemap, callableRemap),
remapLifecycleCallable(declaration.projectInit(), moduleRemap, callableRemap),
remapLifecycleCallable(declaration.frameRoot(), moduleRemap, callableRemap));
}
private IRLifecycleCallableReference remapLifecycleCallable(
final IRLifecycleCallableReference reference,
final ModuleId[] moduleRemap,
final CallableId[] callableRemap) {
if (reference == null) {
return null;
}
return new IRLifecycleCallableReference(
remapModuleId(reference.moduleId(), moduleRemap, "lifecycle callable"),
reference.fileId(),
remapCallableId(reference.callableId(), callableRemap, "lifecycle callable"),
reference.role(),
reference.origin());
}
private ModuleId remapModuleId( private ModuleId remapModuleId(
final ModuleId localModuleId, final ModuleId localModuleId,
final ModuleId[] moduleRemap, final ModuleId[] moduleRemap,
@@ -273,6 +318,52 @@ public class IRBackend implements IRBackendReader {
return ReadOnlyList.wrap(pool); return ReadOnlyList.wrap(pool);
} }
private IRLifecycleDeclaration emitLifecycleDeclaration() {
if (lifecycleFiles.isEmpty()) {
return null;
}
if (lifecycleModuleOrder.isEmpty()) {
throw new IllegalStateException("lifecycle module order is required for executable handoff");
}
final var modules = new ArrayList<IRLifecycleModuleDeclaration>();
IRLifecycleCallableReference projectInit = null;
IRLifecycleCallableReference frameRoot = null;
for (final var moduleId : lifecycleModuleOrder) {
final var fragments = new ArrayList<IRLifecycleCallableReference>();
var hasLifecycleContribution = false;
for (final var lifecycleFile : lifecycleFiles) {
if (!sameModuleId(moduleId, lifecycleFile.moduleId())) {
continue;
}
hasLifecycleContribution = true;
if (lifecycleFile.fileInitFragment() != null) {
fragments.add(lifecycleFile.fileInitFragment());
}
if (projectInit == null && lifecycleFile.projectInit() != null) {
projectInit = lifecycleFile.projectInit();
}
if (frameRoot == null && lifecycleFile.frameRoot() != null) {
frameRoot = lifecycleFile.frameRoot();
}
}
if (hasLifecycleContribution) {
modules.add(new IRLifecycleModuleDeclaration(moduleId, ReadOnlyList.wrap(fragments)));
}
}
return new IRLifecycleDeclaration(ReadOnlyList.wrap(modules), projectInit, frameRoot);
}
private boolean sameModuleId(final ModuleId left, final ModuleId right) {
if (left == null || right == null) {
return left == right;
}
if (left.isNone() || right.isNone()) {
return left.isNone() && right.isNone();
}
return left.getIndex() == right.getIndex();
}
public IRBackend emit() { public IRBackend emit() {
return IRBackend return IRBackend
.builder() .builder()
@@ -290,6 +381,7 @@ public class IRBackend implements IRBackendReader {
ReadOnlyList.wrap(builtinTypeSurfaces), ReadOnlyList.wrap(builtinTypeSurfaces),
ReadOnlyList.wrap(builtinConstSurfaces), ReadOnlyList.wrap(builtinConstSurfaces),
ReadOnlyList.wrap(requiredCapabilities.stream().toList()))) ReadOnlyList.wrap(requiredCapabilities.stream().toList())))
.lifecycleDeclaration(emitLifecycleDeclaration())
.build(); .build();
} }
@@ -321,6 +413,7 @@ public class IRBackend implements IRBackendReader {
.append(", builtinTypes=").append(reservedMetadata.builtinTypeSurfaces().size()) .append(", builtinTypes=").append(reservedMetadata.builtinTypeSurfaces().size())
.append(", builtinConsts=").append(reservedMetadata.builtinConstSurfaces().size()) .append(", builtinConsts=").append(reservedMetadata.builtinConstSurfaces().size())
.append(", requiredCapabilities=").append(reservedMetadata.requiredCapabilities().size()) .append(", requiredCapabilities=").append(reservedMetadata.requiredCapabilities().size())
.append(", lifecycle=").append(lifecycleDeclaration == null ? "none" : "declared")
.append('}'); .append('}');
if (functions.isEmpty()) { if (functions.isEmpty()) {
@@ -17,7 +17,8 @@ public record IRBackendFile(
IRReservedMetadata reservedMetadata, IRReservedMetadata reservedMetadata,
ReadOnlyList<ModuleReference> modulePool, ReadOnlyList<ModuleReference> modulePool,
ReadOnlyList<CallableSignatureRef> callableSignatures, ReadOnlyList<CallableSignatureRef> callableSignatures,
ReadOnlyList<IntrinsicReference> intrinsicPool) { ReadOnlyList<IntrinsicReference> intrinsicPool,
IRLifecycleFileDeclaration lifecycleDeclaration) {
public IRBackendFile { public IRBackendFile {
fileId = Objects.requireNonNull(fileId, "fileId"); fileId = Objects.requireNonNull(fileId, "fileId");
functions = functions == null ? ReadOnlyList.empty() : functions; functions = functions == null ? ReadOnlyList.empty() : functions;
@@ -30,6 +31,29 @@ public record IRBackendFile(
intrinsicPool = intrinsicPool == null ? ReadOnlyList.empty() : intrinsicPool; intrinsicPool = intrinsicPool == null ? ReadOnlyList.empty() : intrinsicPool;
} }
public IRBackendFile(
final FileId fileId,
final ReadOnlyList<IRFunction> functions,
final ReadOnlyList<IRSyntheticFunction> syntheticFunctions,
final ReadOnlyList<IRGlobal> globals,
final ReadOnlyList<IRBackendExecutableFunction> executableFunctions,
final IRReservedMetadata reservedMetadata,
final ReadOnlyList<ModuleReference> modulePool,
final ReadOnlyList<CallableSignatureRef> callableSignatures,
final ReadOnlyList<IntrinsicReference> intrinsicPool) {
this(
fileId,
functions,
syntheticFunctions,
globals,
executableFunctions,
reservedMetadata,
modulePool,
callableSignatures,
intrinsicPool,
null);
}
public IRBackendFile( public IRBackendFile(
final FileId fileId, final FileId fileId,
final ReadOnlyList<IRFunction> functions) { final ReadOnlyList<IRFunction> functions) {
@@ -42,7 +66,8 @@ public record IRBackendFile(
IRReservedMetadata.empty(), IRReservedMetadata.empty(),
ReadOnlyList.empty(), ReadOnlyList.empty(),
ReadOnlyList.empty(), ReadOnlyList.empty(),
ReadOnlyList.empty()); ReadOnlyList.empty(),
null);
} }
public static IRBackendFile empty(final FileId fileId) { public static IRBackendFile empty(final FileId fileId) {
@@ -55,7 +80,8 @@ public record IRBackendFile(
IRReservedMetadata.empty(), IRReservedMetadata.empty(),
ReadOnlyList.empty(), ReadOnlyList.empty(),
ReadOnlyList.empty(), ReadOnlyList.empty(),
ReadOnlyList.empty()); ReadOnlyList.empty(),
null);
} }
public IRBackendFile( public IRBackendFile(
@@ -71,7 +97,8 @@ public record IRBackendFile(
reservedMetadata, reservedMetadata,
ReadOnlyList.empty(), ReadOnlyList.empty(),
ReadOnlyList.empty(), ReadOnlyList.empty(),
ReadOnlyList.empty()); ReadOnlyList.empty(),
null);
} }
public IRBackendFile( public IRBackendFile(
@@ -90,7 +117,8 @@ public record IRBackendFile(
reservedMetadata, reservedMetadata,
ReadOnlyList.empty(), ReadOnlyList.empty(),
callableSignatures, callableSignatures,
intrinsicPool); intrinsicPool,
null);
} }
public IRBackendFile( public IRBackendFile(
@@ -110,6 +138,7 @@ public record IRBackendFile(
reservedMetadata, reservedMetadata,
modulePool, modulePool,
callableSignatures, callableSignatures,
intrinsicPool); intrinsicPool,
null);
} }
} }
@@ -17,4 +17,5 @@ public interface IRBackendReader {
ReadOnlyList<CallableSignatureRef> getCallableSignatures(); ReadOnlyList<CallableSignatureRef> getCallableSignatures();
ReadOnlyList<IntrinsicReference> getIntrinsicPool(); ReadOnlyList<IntrinsicReference> getIntrinsicPool();
IRReservedMetadata getReservedMetadata(); IRReservedMetadata getReservedMetadata();
IRLifecycleDeclaration getLifecycleDeclaration();
} }
@@ -0,0 +1,23 @@
package p.studio.compiler.models;
import p.studio.compiler.source.Span;
import p.studio.compiler.source.identifiers.CallableId;
import p.studio.compiler.source.identifiers.FileId;
import p.studio.compiler.source.identifiers.ModuleId;
import java.util.Objects;
public record IRLifecycleCallableReference(
ModuleId moduleId,
FileId fileId,
CallableId callableId,
IRLifecycleCallableRole role,
Span origin) {
public IRLifecycleCallableReference {
moduleId = Objects.requireNonNull(moduleId, "moduleId");
fileId = Objects.requireNonNull(fileId, "fileId");
callableId = Objects.requireNonNull(callableId, "callableId");
role = Objects.requireNonNull(role, "role");
origin = origin == null ? Span.none() : origin;
}
}
@@ -0,0 +1,7 @@
package p.studio.compiler.models;
public enum IRLifecycleCallableRole {
FILE_INIT_FRAGMENT,
PROJECT_INIT,
FRAME_ROOT
}
@@ -0,0 +1,12 @@
package p.studio.compiler.models;
import p.studio.utilities.structures.ReadOnlyList;
public record IRLifecycleDeclaration(
ReadOnlyList<IRLifecycleModuleDeclaration> modules,
IRLifecycleCallableReference projectInit,
IRLifecycleCallableReference frameRoot) {
public IRLifecycleDeclaration {
modules = modules == null ? ReadOnlyList.empty() : modules;
}
}
@@ -0,0 +1,22 @@
package p.studio.compiler.models;
import p.studio.compiler.source.identifiers.FileId;
import p.studio.compiler.source.identifiers.ModuleId;
import java.util.Objects;
public record IRLifecycleFileDeclaration(
ModuleId moduleId,
FileId fileId,
IRLifecycleCallableReference fileInitFragment,
IRLifecycleCallableReference projectInit,
IRLifecycleCallableReference frameRoot) {
public IRLifecycleFileDeclaration {
moduleId = Objects.requireNonNull(moduleId, "moduleId");
fileId = Objects.requireNonNull(fileId, "fileId");
}
public boolean isEmpty() {
return fileInitFragment == null && projectInit == null && frameRoot == null;
}
}
@@ -0,0 +1,15 @@
package p.studio.compiler.models;
import p.studio.compiler.source.identifiers.ModuleId;
import p.studio.utilities.structures.ReadOnlyList;
import java.util.Objects;
public record IRLifecycleModuleDeclaration(
ModuleId moduleId,
ReadOnlyList<IRLifecycleCallableReference> fileInitFragments) {
public IRLifecycleModuleDeclaration {
moduleId = Objects.requireNonNull(moduleId, "moduleId");
fileInitFragments = fileInitFragments == null ? ReadOnlyList.empty() : fileInitFragments;
}
}
@@ -11,9 +11,241 @@ import p.studio.compiler.source.tables.IntrinsicReference;
import p.studio.compiler.source.tables.ModuleReference; import p.studio.compiler.source.tables.ModuleReference;
import p.studio.utilities.structures.ReadOnlyList; import p.studio.utilities.structures.ReadOnlyList;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.function.Function;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class IRBackendExecutableContractTest { class IRBackendExecutableContractTest {
private static final String FORBIDDEN_PBS_PACKAGE = "p.studio.compiler.pbs";
private static final Set<Class<?>> AUDITED_SUPPORT_TYPES = Set.of(
FileId.class,
ModuleId.class,
CallableId.class,
IntrinsicId.class,
Span.class,
ModuleReference.class,
CallableSignatureRef.class,
IntrinsicReference.class,
ReadOnlyList.class,
String.class,
Integer.class,
Long.class,
Boolean.class);
private static final List<Class<?>> PUBLIC_CONTRACT_TYPES = List.of(
IRBackend.class,
IRBackend.IRBackendAggregator.class,
IRBackendReader.class,
IRBackendFile.class,
IRBackendExecutableFunction.class,
IRBackendExecutableFunction.Instruction.class,
IRBackendExecutableFunction.InstructionKind.class,
IRBackendExecutableFunction.HostCallMetadata.class,
IRBackendExecutableFunction.IntrinsicCallMetadata.class,
IRFunction.class,
IRSyntheticFunction.class,
IRSyntheticCallableKind.class,
IRSyntheticOrigin.class,
IRGlobal.class,
IRGlobalOrigin.class,
IRGlobalVisibility.class,
IRHiddenGlobalKind.class,
IRLifecycleDeclaration.class,
IRLifecycleModuleDeclaration.class,
IRLifecycleFileDeclaration.class,
IRLifecycleCallableReference.class,
IRLifecycleCallableRole.class,
IRReservedMetadata.class,
IRReservedMetadata.HostMethodBinding.class,
IRReservedMetadata.BuiltinTypeSurface.class,
IRReservedMetadata.BuiltinFieldSurface.class,
IRReservedMetadata.IntrinsicSurface.class,
IRReservedMetadata.BuiltinConstSurface.class);
@Test
void publicIRBackendContractAuditMustCoverAllModelTypes() {
final var expectedTopLevelModelTypes = Set.of(
IRBackend.class,
IRBackendReader.class,
IRBackendFile.class,
IRBackendExecutableFunction.class,
IRFunction.class,
IRGlobal.class,
IRGlobalOrigin.class,
IRGlobalVisibility.class,
IRHiddenGlobalKind.class,
IRReservedMetadata.class,
IRSyntheticCallableKind.class,
IRSyntheticFunction.class,
IRSyntheticOrigin.class,
IRLifecycleDeclaration.class,
IRLifecycleModuleDeclaration.class,
IRLifecycleFileDeclaration.class,
IRLifecycleCallableReference.class,
IRLifecycleCallableRole.class);
assertTrue(
PUBLIC_CONTRACT_TYPES.containsAll(expectedTopLevelModelTypes),
"public IRBackend contract audit must cover every top-level handoff model type");
assertTrue(
PUBLIC_CONTRACT_TYPES.contains(IRBackendExecutableFunction.Instruction.class)
&& PUBLIC_CONTRACT_TYPES.contains(IRBackendExecutableFunction.HostCallMetadata.class)
&& PUBLIC_CONTRACT_TYPES.contains(IRBackendExecutableFunction.IntrinsicCallMetadata.class)
&& PUBLIC_CONTRACT_TYPES.contains(IRReservedMetadata.HostMethodBinding.class)
&& PUBLIC_CONTRACT_TYPES.contains(IRReservedMetadata.BuiltinTypeSurface.class)
&& PUBLIC_CONTRACT_TYPES.contains(IRReservedMetadata.BuiltinFieldSurface.class)
&& PUBLIC_CONTRACT_TYPES.contains(IRReservedMetadata.IntrinsicSurface.class)
&& PUBLIC_CONTRACT_TYPES.contains(IRReservedMetadata.BuiltinConstSurface.class),
"public IRBackend contract audit must cover nested handoff value types");
}
@Test
void publicIRBackendContractAuditMustClassifyAllowedSupportTypes() {
assertTrue(
AUDITED_SUPPORT_TYPES.containsAll(Set.of(
FileId.class,
ModuleId.class,
CallableId.class,
IntrinsicId.class)),
"table-scoped ids are audited as explicit handoff identifiers");
assertTrue(
AUDITED_SUPPORT_TYPES.contains(Span.class),
"Span is audited as source attribution data");
assertTrue(
AUDITED_SUPPORT_TYPES.containsAll(Set.of(
ModuleReference.class,
CallableSignatureRef.class,
IntrinsicReference.class)),
"source table references are audited as ordered table values");
assertTrue(
AUDITED_SUPPORT_TYPES.contains(ReadOnlyList.class),
"ReadOnlyList is audited as the ordered collection contract");
}
@Test
void publicIRBackendContractMustUseExplicitIdsOrStableKeysForKnownReferences() {
assertEquals(ModuleId.class, recordComponentType(IRBackendExecutableFunction.class, "moduleId"));
assertEquals(CallableId.class, recordComponentType(IRBackendExecutableFunction.class, "callableId"));
assertEquals(ModuleId.class, recordComponentType(IRBackendExecutableFunction.Instruction.class, "calleeModuleId"));
assertEquals(CallableId.class, recordComponentType(IRBackendExecutableFunction.Instruction.class, "calleeCallableId"));
assertEquals(IntrinsicId.class, recordComponentType(IRBackendExecutableFunction.IntrinsicCallMetadata.class, "intrinsicId"));
assertEquals(FileId.class, recordComponentType(IRBackendFile.class, "fileId"));
assertEquals(FileId.class, recordComponentType(IRFunction.class, "fileId"));
assertEquals(FileId.class, recordComponentType(IRGlobal.class, "fileId"));
assertEquals(ModuleId.class, recordComponentType(IRGlobal.class, "moduleId"));
assertEquals(FileId.class, recordComponentType(IRGlobalOrigin.class, "derivedFromFile"));
assertEquals(ModuleId.class, recordComponentType(IRGlobalOrigin.class, "derivedFromModule"));
assertEquals(FileId.class, recordComponentType(IRSyntheticOrigin.class, "fileId"));
assertEquals(ModuleId.class, recordComponentType(IRSyntheticFunction.class, "moduleId"));
assertEquals(ModuleId.class, recordComponentType(IRLifecycleModuleDeclaration.class, "moduleId"));
assertEquals(ModuleId.class, recordComponentType(IRLifecycleFileDeclaration.class, "moduleId"));
assertEquals(FileId.class, recordComponentType(IRLifecycleFileDeclaration.class, "fileId"));
assertEquals(ModuleId.class, recordComponentType(IRLifecycleCallableReference.class, "moduleId"));
assertEquals(FileId.class, recordComponentType(IRLifecycleCallableReference.class, "fileId"));
assertEquals(CallableId.class, recordComponentType(IRLifecycleCallableReference.class, "callableId"));
assertEquals(Span.class, recordComponentType(IRLifecycleCallableReference.class, "origin"));
assertEquals(String.class, recordComponentType(ModuleReference.class, "project"));
assertEquals(String.class, recordComponentType(CallableSignatureRef.class, "callableName"));
assertEquals(String.class, recordComponentType(IntrinsicReference.class, "canonicalName"));
}
@Test
void publicIRBackendContractMustNotExposePbsTypes() {
final var violations = new ArrayList<String>();
for (final var contractType : PUBLIC_CONTRACT_TYPES) {
inspectType(contractType.getName(), contractType, violations);
for (final var field : contractType.getFields()) {
inspectType(contractType.getName() + "#" + field.getName(), field.getGenericType(), violations);
}
for (final var constructor : contractType.getConstructors()) {
for (final var parameterType : constructor.getGenericParameterTypes()) {
inspectType(contractType.getName() + "#<init>", parameterType, violations);
}
}
for (final var method : contractType.getMethods()) {
if (method.getDeclaringClass().equals(Object.class)
|| !Modifier.isPublic(method.getModifiers())) {
continue;
}
inspectType(contractType.getName() + "#" + method.getName(), method.getGenericReturnType(), violations);
for (final var parameterType : method.getGenericParameterTypes()) {
inspectType(contractType.getName() + "#" + method.getName(), parameterType, violations);
}
}
if (contractType.isRecord()) {
for (final var component : contractType.getRecordComponents()) {
inspectType(contractType.getName() + "#" + component.getName(), component.getGenericType(), violations);
}
}
}
assertTrue(
violations.isEmpty(),
"public IRBackend contract must not expose PBS frontend types: " + violations);
}
@Test
void publicIRBackendContractMustExposeOnlySerializableShapes() {
final var violations = new ArrayList<String>();
for (final var contractType : PUBLIC_CONTRACT_TYPES) {
inspectSerializableContractType(contractType.getName(), contractType, violations);
for (final var field : contractType.getFields()) {
inspectSerializableContractType(
contractType.getName() + "#" + field.getName(),
field.getGenericType(),
violations);
}
for (final var constructor : contractType.getConstructors()) {
for (final var parameterType : constructor.getGenericParameterTypes()) {
inspectSerializableContractType(
contractType.getName() + "#<init>",
parameterType,
violations);
}
}
for (final var method : contractType.getMethods()) {
if (method.getDeclaringClass().equals(Object.class)
|| !Modifier.isPublic(method.getModifiers())) {
continue;
}
inspectSerializableContractType(
contractType.getName() + "#" + method.getName(),
method.getGenericReturnType(),
violations);
for (final var parameterType : method.getGenericParameterTypes()) {
inspectSerializableContractType(
contractType.getName() + "#" + method.getName(),
parameterType,
violations);
}
}
if (contractType.isRecord()) {
for (final var component : contractType.getRecordComponents()) {
inspectSerializableContractType(
contractType.getName() + "#" + component.getName(),
component.getGenericType(),
violations);
}
}
}
assertTrue(
violations.isEmpty(),
"public IRBackend contract must expose only serializable-by-design shapes: " + violations);
}
@Test @Test
void callInstructionMustRequireCategorySpecificMetadata() { void callInstructionMustRequireCategorySpecificMetadata() {
@@ -366,4 +598,436 @@ class IRBackendExecutableContractTest {
assertEquals(0, backend.getCallableSignatures().get(0).moduleId().getIndex()); assertEquals(0, backend.getCallableSignatures().get(0).moduleId().getIndex());
assertEquals(1, backend.getCallableSignatures().get(1).moduleId().getIndex()); assertEquals(1, backend.getCallableSignatures().get(1).moduleId().getIndex());
} }
@Test
void aggregatorMustEmitDeterministicOrderedPublicContractShape() {
final var first = emitDeterministicAggregateFixture();
final var second = emitDeterministicAggregateFixture();
assertEquals(
List.of("alpha", "beta"),
first.getFunctions().asList().stream().map(IRFunction::name).toList());
assertEquals(
List.of("frameWrapper", "initWrapper"),
first.getSyntheticFunctions().asList().stream().map(IRSyntheticFunction::callableName).toList());
assertEquals(
List.of("state", "timer"),
first.getGlobals().asList().stream().map(IRGlobal::name).toList());
assertEquals(
List.of("frame", "init"),
first.getExecutableFunctions().asList().stream().map(IRBackendExecutableFunction::callableName).toList());
assertEquals(
List.of("app:alpha", "app:beta"),
first.getModulePool().asList().stream()
.map(module -> module.project() + ":" + String.join(".", module.pathSegments().asList()))
.toList());
assertEquals(
List.of("frame", "helper", "init"),
first.getCallableSignatures().asList().stream().map(CallableSignatureRef::callableName).toList());
assertEquals(
List.of("core.draw", "core.color.pack"),
first.getIntrinsicPool().asList().stream().map(IntrinsicReference::canonicalName).toList());
assertEquals(
List.of("draw", "play"),
first.getReservedMetadata().hostMethodBindings().asList().stream()
.map(IRReservedMetadata.HostMethodBinding::abiMethod)
.toList());
assertEquals(
List.of("Sprite", "Sound"),
first.getReservedMetadata().builtinTypeSurfaces().asList().stream()
.map(IRReservedMetadata.BuiltinTypeSurface::sourceTypeName)
.toList());
assertEquals(
List.of("WHITE", "BLACK"),
first.getReservedMetadata().builtinConstSurfaces().asList().stream()
.map(IRReservedMetadata.BuiltinConstSurface::sourceConstName)
.toList());
assertEquals(
List.of("gfx.draw", "audio.play", "input.read"),
first.getReservedMetadata().requiredCapabilities().asList());
assertEquals(first.toString(), second.toString());
assertEquals(
first.getReservedMetadata().requiredCapabilities().asList(),
second.getReservedMetadata().requiredCapabilities().asList());
assertEquals(
first.getExecutableFunctions().get(0).moduleId(),
second.getExecutableFunctions().get(0).moduleId());
assertEquals(
first.getExecutableFunctions().get(1).callableId(),
second.getExecutableFunctions().get(1).callableId());
}
@Test
void aggregatorMustRemapTypedLifecycleReferencesAndPreserveDeclaredModuleOrder() {
final var fileASpan = new Span(new FileId(10), 1, 8);
final var fileBSpan = new Span(new FileId(20), 2, 9);
final var fileA = new IRBackendFile(
new FileId(10),
ReadOnlyList.empty(),
ReadOnlyList.from(new IRSyntheticFunction(
new ModuleId(0),
"file_init_zzz",
IRSyntheticCallableKind.FILE_INIT_FRAGMENT,
new IRSyntheticOrigin(new FileId(10), "warmup", fileASpan))),
ReadOnlyList.empty(),
ReadOnlyList.from(executable("file_init_zzz", 10, 0, 0, fileASpan)),
IRReservedMetadata.empty(),
ReadOnlyList.from(new ModuleReference("app", ReadOnlyList.from("zzz"))),
ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "file_init_zzz", 0, "() -> unit")),
ReadOnlyList.empty(),
new IRLifecycleFileDeclaration(
new ModuleId(0),
new FileId(10),
new IRLifecycleCallableReference(
new ModuleId(0),
new FileId(10),
new CallableId(0),
IRLifecycleCallableRole.FILE_INIT_FRAGMENT,
fileASpan),
null,
null));
final var fileB = new IRBackendFile(
new FileId(20),
ReadOnlyList.empty(),
ReadOnlyList.empty(),
ReadOnlyList.empty(),
ReadOnlyList.from(
executable("boot", 20, 0, 0, fileBSpan),
executable("frame", 20, 0, 1, fileBSpan)),
IRReservedMetadata.empty(),
ReadOnlyList.from(new ModuleReference("app", ReadOnlyList.from("aaa"))),
ReadOnlyList.from(
new CallableSignatureRef(new ModuleId(0), "boot", 0, "() -> unit"),
new CallableSignatureRef(new ModuleId(0), "frame", 0, "() -> unit")),
ReadOnlyList.empty(),
new IRLifecycleFileDeclaration(
new ModuleId(0),
new FileId(20),
null,
new IRLifecycleCallableReference(
new ModuleId(0),
new FileId(20),
new CallableId(0),
IRLifecycleCallableRole.PROJECT_INIT,
fileBSpan),
new IRLifecycleCallableReference(
new ModuleId(0),
new FileId(20),
new CallableId(1),
IRLifecycleCallableRole.FRAME_ROOT,
fileBSpan)));
final var aggregator = IRBackend.aggregator();
aggregator.merge(fileA);
aggregator.merge(fileB);
aggregator.lifecycleModuleOrder(ReadOnlyList.from(new ModuleId(1), new ModuleId(0)));
final var backend = aggregator.emit();
final var declaration = backend.getLifecycleDeclaration();
assertNotNull(declaration);
assertEquals(2, declaration.modules().size());
assertEquals(1, declaration.modules().get(0).moduleId().getIndex());
assertEquals(0, declaration.modules().get(1).moduleId().getIndex());
assertEquals("aaa", backend.getModulePool().get(1).pathSegments().getFirst());
assertEquals("zzz", backend.getModulePool().get(0).pathSegments().getFirst());
assertEquals(IRLifecycleCallableRole.FILE_INIT_FRAGMENT, declaration.modules().get(1).fileInitFragments().getFirst().role());
assertEquals(0, declaration.modules().get(1).fileInitFragments().getFirst().callableId().getIndex());
assertEquals(1, declaration.projectInit().callableId().getIndex());
assertEquals(2, declaration.frameRoot().callableId().getIndex());
assertEquals(20, declaration.frameRoot().fileId().getId());
assertEquals(2, declaration.frameRoot().origin().getStart());
assertEquals("boot", backend.getExecutableFunctions().get(1).callableName());
assertEquals("frame", backend.getExecutableFunctions().get(2).callableName());
}
@Test
void aggregatorMustOmitLifecycleDeclarationWhenNoFileContributesOne() {
final var aggregator = IRBackend.aggregator();
aggregator.merge(new IRBackendFile(
new FileId(1),
ReadOnlyList.empty(),
ReadOnlyList.from(new IRBackendExecutableFunction(
new FileId(1),
"entry",
new CallableId(0),
0,
10,
0,
0,
0,
1,
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.RET,
"",
null,
null,
Span.none())),
Span.none())),
IRReservedMetadata.empty(),
ReadOnlyList.from(new CallableSignatureRef("entry", 0, "() -> unit")),
ReadOnlyList.empty()));
final var backend = aggregator.emit();
assertNull(backend.getLifecycleDeclaration());
}
private static IRBackendExecutableFunction executable(
final String name,
final int fileId,
final int moduleId,
final int callableId,
final Span span) {
return new IRBackendExecutableFunction(
new FileId(fileId),
new ModuleId(moduleId),
name,
new CallableId(callableId),
(int) span.getStart(),
(int) span.getEnd(),
0,
0,
0,
1,
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.RET,
"",
null,
null,
span)),
span);
}
private static IRBackend emitDeterministicAggregateFixture() {
final var aggregator = IRBackend.aggregator();
aggregator.merge(new IRBackendFile(
new FileId(10),
ReadOnlyList.from(new IRFunction(new FileId(10), "alpha", 0, false, new Span(new FileId(10), 0, 5))),
ReadOnlyList.from(new IRSyntheticFunction(
new ModuleId(0),
"frameWrapper",
IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER,
new IRSyntheticOrigin(new FileId(10), "frame", new Span(new FileId(10), 0, 5)))),
ReadOnlyList.from(new IRGlobal(
new FileId(10),
new ModuleId(0),
"state",
"int",
new Span(new FileId(10), 1, 2))),
ReadOnlyList.from(new IRBackendExecutableFunction(
new FileId(10),
new ModuleId(0),
"frame",
new CallableId(0),
0,
10,
0,
0,
0,
1,
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC,
new ModuleId(0),
"",
null,
null,
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.draw", 1, new IntrinsicId(0)),
Span.none())),
Span.none())),
new IRReservedMetadata(
ReadOnlyList.from(new IRReservedMetadata.HostMethodBinding(
"Graphics",
"draw",
"gfx",
"draw",
1,
0,
null,
true,
"gfx.draw",
Span.none())),
ReadOnlyList.from(new IRReservedMetadata.BuiltinTypeSurface(
"Sprite",
"core.Sprite",
1,
ReadOnlyList.from(new IRReservedMetadata.BuiltinFieldSurface(
"x",
"int",
0,
Span.none())),
ReadOnlyList.empty(),
Span.none())),
ReadOnlyList.from(new IRReservedMetadata.BuiltinConstSurface(
"WHITE",
"color",
"core.color.white",
1,
Span.none())),
ReadOnlyList.from("gfx.draw", "audio.play")),
ReadOnlyList.from(new ModuleReference("app", ReadOnlyList.from("alpha"))),
ReadOnlyList.from(
new CallableSignatureRef(new ModuleId(0), "frame", 0, "() -> unit"),
new CallableSignatureRef(new ModuleId(0), "helper", 0, "() -> unit")),
ReadOnlyList.from(new IntrinsicReference("core.draw", 1))));
aggregator.merge(new IRBackendFile(
new FileId(20),
ReadOnlyList.from(new IRFunction(new FileId(20), "beta", 1, true, new Span(new FileId(20), 0, 7))),
ReadOnlyList.from(new IRSyntheticFunction(
new ModuleId(0),
"initWrapper",
IRSyntheticCallableKind.PROJECT_INIT,
new IRSyntheticOrigin(new FileId(20), "init", new Span(new FileId(20), 0, 7)))),
ReadOnlyList.from(new IRGlobal(
new FileId(20),
new ModuleId(0),
"timer",
"int",
new Span(new FileId(20), 1, 3))),
ReadOnlyList.from(new IRBackendExecutableFunction(
new FileId(20),
new ModuleId(0),
"init",
new CallableId(0),
0,
8,
0,
0,
0,
1,
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC,
new ModuleId(0),
"",
null,
null,
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, new IntrinsicId(0)),
Span.none())),
Span.none())),
new IRReservedMetadata(
ReadOnlyList.from(new IRReservedMetadata.HostMethodBinding(
"Audio",
"play",
"audio",
"play",
1,
0,
null,
true,
"audio.play",
Span.none())),
ReadOnlyList.from(new IRReservedMetadata.BuiltinTypeSurface(
"Sound",
"core.Sound",
1,
ReadOnlyList.empty(),
ReadOnlyList.from(new IRReservedMetadata.IntrinsicSurface(
"volume",
"core.sound.volume",
1,
1,
1,
Span.none())),
Span.none())),
ReadOnlyList.from(new IRReservedMetadata.BuiltinConstSurface(
"BLACK",
"color",
"core.color.black",
1,
Span.none())),
ReadOnlyList.from("gfx.draw", "input.read")),
ReadOnlyList.from(new ModuleReference("app", ReadOnlyList.from("beta"))),
ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "init", 0, "() -> unit")),
ReadOnlyList.from(new IntrinsicReference("core.color.pack", 1))));
return aggregator.emit();
}
private static void inspectType(
final String owner,
final Type type,
final ArrayList<String> violations) {
if (type == null) {
return;
}
final var typeName = type.getTypeName();
if (typeName.contains(FORBIDDEN_PBS_PACKAGE)) {
violations.add(owner + " -> " + typeName);
}
}
private static void inspectSerializableContractType(
final String owner,
final Type type,
final ArrayList<String> violations) {
if (type == null) {
return;
}
if (type instanceof ParameterizedType parameterizedType) {
inspectSerializableContractType(owner, parameterizedType.getRawType(), violations);
for (final var argument : parameterizedType.getActualTypeArguments()) {
inspectSerializableContractType(owner, argument, violations);
}
return;
}
if (!(type instanceof Class<?> clazz)) {
return;
}
if (clazz.isPrimitive()
|| clazz.isEnum()
|| AUDITED_SUPPORT_TYPES.contains(clazz)
|| PUBLIC_CONTRACT_TYPES.contains(clazz)) {
return;
}
if (isForbiddenFrontendOwnedType(clazz)) {
violations.add(owner + " exposes frontend-owned type " + clazz.getName());
}
if (isForbiddenCallbackShape(clazz)) {
violations.add(owner + " exposes callback shape " + clazz.getName());
}
if (isForbiddenMutableOrUnorderedCollection(clazz)) {
violations.add(owner + " exposes mutable or unordered collection " + clazz.getName());
}
if (isForbiddenServiceShape(clazz)) {
violations.add(owner + " exposes service-like shape " + clazz.getName());
}
}
private static boolean isForbiddenFrontendOwnedType(final Class<?> clazz) {
final var packageName = clazz.getPackageName();
return packageName.startsWith("p.studio.compiler.pbs")
|| packageName.contains(".parser")
|| packageName.contains(".semantic")
|| packageName.contains(".editor");
}
private static boolean isForbiddenCallbackShape(final Class<?> clazz) {
return clazz.equals(Runnable.class)
|| Callable.class.isAssignableFrom(clazz)
|| Function.class.isAssignableFrom(clazz)
|| clazz.getPackageName().startsWith("java.util.function");
}
private static boolean isForbiddenMutableOrUnorderedCollection(final Class<?> clazz) {
return !clazz.equals(ReadOnlyList.class)
&& (Collection.class.isAssignableFrom(clazz) || Map.class.isAssignableFrom(clazz));
}
private static boolean isForbiddenServiceShape(final Class<?> clazz) {
final var simpleName = clazz.getSimpleName();
return simpleName.endsWith("Service")
|| simpleName.endsWith("Registry")
|| simpleName.endsWith("Visitor")
|| simpleName.endsWith("Provider");
}
private static Class<?> recordComponentType(
final Class<?> recordType,
final String componentName) {
for (final var component : recordType.getRecordComponents()) {
if (component.getName().equals(componentName)) {
return component.getType();
}
}
fail("missing record component " + recordType.getName() + "#" + componentName);
throw new IllegalStateException("unreachable");
}
} }
@@ -62,7 +62,7 @@ public class FrontendRegistryService {
.toList(); .toList();
} }
static void register(final FrontendProvider provider) { public static void register(final FrontendProvider provider) {
final var languageId = provider.specification().getLanguageId(); final var languageId = provider.specification().getLanguageId();
if (FRONTEND_PROVIDERS.containsKey(languageId)) { if (FRONTEND_PROVIDERS.containsKey(languageId)) {
throw new IllegalArgumentException("Duplicate frontend languageId: " + languageId); throw new IllegalArgumentException("Duplicate frontend languageId: " + languageId);
@@ -71,6 +71,16 @@ public class FrontendRegistryService {
FRONTEND_PROVIDERS.put(languageId, provider); FRONTEND_PROVIDERS.put(languageId, provider);
} }
public static void unregister(final String languageId) {
if (languageId == null || languageId.isBlank()) {
return;
}
if (PBSDefinitions.PBS.getLanguageId().equals(languageId)) {
throw new IllegalArgumentException("Cannot unregister the default PBS frontend: " + languageId);
}
FRONTEND_PROVIDERS.remove(languageId);
}
private static void registerIfAbsent(final FrontendProvider provider) { private static void registerIfAbsent(final FrontendProvider provider) {
FRONTEND_PROVIDERS.putIfAbsent(provider.specification().getLanguageId(), provider); FRONTEND_PROVIDERS.putIfAbsent(provider.specification().getLanguageId(), provider);
} }
@@ -1,6 +1,15 @@
package p.studio.compiler; package p.studio.compiler;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.messages.FrontendPhaseContext;
import p.studio.compiler.models.FrontendSpec;
import p.studio.compiler.models.IRBackend;
import p.studio.compiler.services.FrontendPhaseService;
import p.studio.compiler.services.FrontendProvider;
import p.studio.compiler.source.diagnostics.DiagnosticSink;
import p.studio.utilities.logs.LogAggregator;
import p.studio.utilities.structures.ReadOnlySet;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
@@ -41,4 +50,89 @@ class FrontendRegistryServiceTest {
assertEquals(1, providers.size()); assertEquals(1, providers.size());
assertEquals(PBSDefinitions.PBS.getLanguageId(), providers.getFirst().specification().getLanguageId()); assertEquals(PBSDefinitions.PBS.getLanguageId(), providers.getFirst().specification().getLanguageId());
} }
@Test
void registerShouldResolveAndUnregisterTemporaryProvider() {
final var provider = new TemporaryFrontendProvider("registry-temp");
FrontendRegistryService.register(provider);
try {
assertSame(provider, FrontendRegistryService.require("registry-temp"));
assertEquals(2, FrontendRegistryService.listProviders().size());
} finally {
FrontendRegistryService.unregister("registry-temp");
}
assertEquals(1, FrontendRegistryService.listProviders().size());
assertEquals(PBSDefinitions.PBS.getLanguageId(),
FrontendRegistryService.listProviders().getFirst().specification().getLanguageId());
}
@Test
void registerShouldRejectDuplicateLanguageId() {
final var provider = new TemporaryFrontendProvider("registry-dup");
FrontendRegistryService.register(provider);
try {
final var thrown = assertThrows(
IllegalArgumentException.class,
() -> FrontendRegistryService.register(new TemporaryFrontendProvider("registry-dup")));
assertTrue(thrown.getMessage().contains("registry-dup"));
} finally {
FrontendRegistryService.unregister("registry-dup");
}
}
@Test
void unregisterMustRefuseToRemoveDefaultPbs() {
final var thrown = assertThrows(
IllegalArgumentException.class,
() -> FrontendRegistryService.unregister(PBSDefinitions.PBS.getLanguageId()));
assertTrue(thrown.getMessage().contains(PBSDefinitions.PBS.getLanguageId()));
assertEquals(1, FrontendRegistryService.listProviders().size());
assertSame(
PBSDefinitions.PBS,
FrontendRegistryService.require(PBSDefinitions.PBS.getLanguageId()).specification());
}
@Test
void unregisterUnknownLanguageIdMustBeNoOp() {
FrontendRegistryService.unregister(null);
FrontendRegistryService.unregister(" ");
FrontendRegistryService.unregister("unknown-language");
assertEquals(1, FrontendRegistryService.listProviders().size());
assertEquals(PBSDefinitions.PBS.getLanguageId(),
FrontendRegistryService.listProviders().getFirst().specification().getLanguageId());
}
private static final class TemporaryFrontendProvider implements FrontendProvider {
private final FrontendSpec specification;
private TemporaryFrontendProvider(final String languageId) {
this.specification = FrontendSpec.builder()
.languageId(languageId)
.allowedExtensions(ReadOnlySet.from("tmp"))
.sourceRoots(ReadOnlySet.from("src"))
.build();
}
@Override
public FrontendSpec specification() {
return specification;
}
@Override
public FrontendPhaseService compiler() {
return new FrontendPhaseService() {
@Override
public IRBackend compile(
final FrontendPhaseContext request,
final DiagnosticSink diagnostics,
final LogAggregator logs,
final BuildingIssueSink issues) {
return IRBackend.builder().build();
}
};
}
}
} }
@@ -7,7 +7,6 @@ dependencies {
implementation(project(":prometeu-compiler:prometeu-compiler-core")) implementation(project(":prometeu-compiler:prometeu-compiler-core"))
implementation(project(":prometeu-compiler:prometeu-frontend-api")) implementation(project(":prometeu-compiler:prometeu-frontend-api"))
implementation(project(":prometeu-compiler:prometeu-build-pipeline")) implementation(project(":prometeu-compiler:prometeu-build-pipeline"))
implementation(project(":prometeu-compiler:frontends:prometeu-frontend-pbs"))
implementation(project(":prometeu-compiler:prometeu-frontend-registry")) implementation(project(":prometeu-compiler:prometeu-frontend-registry"))
implementation(project(":prometeu-compiler:prometeu-deps")) implementation(project(":prometeu-compiler:prometeu-deps"))
implementation(libs.lsp4j) implementation(libs.lsp4j)
-1
View File
@@ -14,7 +14,6 @@ dependencies {
implementation(libs.javafx.controls) implementation(libs.javafx.controls)
implementation(libs.javafx.fxml) implementation(libs.javafx.fxml)
implementation(libs.richtextfx) implementation(libs.richtextfx)
testImplementation(project(":prometeu-compiler:frontends:prometeu-frontend-pbs"))
testImplementation(project(":prometeu-packer:prometeu-packer-v1")) testImplementation(project(":prometeu-packer:prometeu-packer-v1"))
} }
+2
View File
@@ -22,3 +22,5 @@ include("prometeu-compiler:prometeu-frontend-registry")
include("prometeu-studio") include("prometeu-studio")
include("prometeu-app") include("prometeu-app")
include("prometeu-architecture-tests")