From bbd00ed9afcf8c9adf0bdf5a2754079a06a5f84f Mon Sep 17 00:00:00 2001 From: Thorsten Fuchs <76904008+ThorFuchs@users.noreply.github.com> Date: Thu, 15 Oct 2026 20:45:49 +0200 Subject: [PATCH 1/7] feat: prototype scope-bound admitted JSON roots --- Documentation/Architecture/Concurrency.md | 8 + .../Architecture/ExtractionManifest.json | 6 + Documentation/Architecture/ResourceLimits.md | 14 +- Documentation/CI/README.md | 33 +-- Documentation/Qualification/README.md | 6 +- .../Qualification/TestDiscovery.json | 11 +- Scripts/ci.py | 26 ++- Scripts/qualify_composition.py | 49 ++++- Scripts/test_composition_compiler_harness.py | 38 ++++ .../JSON/Documentation.docc/Composition.md | 51 ++++- .../JSON/Limits/JSONCompositionScope.swift | 93 +++++++- .../CompositionRootTests.swift | 199 ++++++++++++++++++ .../Compiler/ClosureBorrow.swift.txt | 5 + .../Compiler/ContainerEscape.swift.txt | 5 + .../ExplicitBorrowParameters.swift.txt | 5 + .../Compiler/LocalFunctionBorrow.swift.txt | 7 + .../Compiler/MethodBorrow.swift.txt | 5 + .../Compiler/MethodEscape.swift.txt | 4 + .../Compiler/RootClosureBorrow.swift.txt | 10 + .../Compiler/RootContainerEscape.swift.txt | 10 + .../Negative/RootConstruct.swift.txt | 2 + .../Negative/RootCopy.swift.txt | 3 + .../Negative/RootEscape.swift.txt | 4 + .../Negative/RootRefund.swift.txt | 2 + .../Negative/RootReturn.swift.txt | 4 + .../Negative/RootSend.swift.txt | 3 + .../Negative/RootSubstitute.swift.txt | 9 + Tools/CompositionQualification/Package.swift | 2 + Tools/CompositionQualification/README.md | 28 ++- .../Sources/CompositionConsumer/main.swift | 37 +++- .../Sources/CompositionRootScale/main.swift | 33 +++ 31 files changed, 657 insertions(+), 55 deletions(-) create mode 100644 Scripts/test_composition_compiler_harness.py create mode 100644 Tests/JSONIntegrationTests/CompositionRootTests.swift create mode 100644 Tools/CompositionQualification/Compiler/ClosureBorrow.swift.txt create mode 100644 Tools/CompositionQualification/Compiler/ContainerEscape.swift.txt create mode 100644 Tools/CompositionQualification/Compiler/ExplicitBorrowParameters.swift.txt create mode 100644 Tools/CompositionQualification/Compiler/LocalFunctionBorrow.swift.txt create mode 100644 Tools/CompositionQualification/Compiler/MethodBorrow.swift.txt create mode 100644 Tools/CompositionQualification/Compiler/MethodEscape.swift.txt create mode 100644 Tools/CompositionQualification/Compiler/RootClosureBorrow.swift.txt create mode 100644 Tools/CompositionQualification/Compiler/RootContainerEscape.swift.txt create mode 100644 Tools/CompositionQualification/Negative/RootConstruct.swift.txt create mode 100644 Tools/CompositionQualification/Negative/RootCopy.swift.txt create mode 100644 Tools/CompositionQualification/Negative/RootEscape.swift.txt create mode 100644 Tools/CompositionQualification/Negative/RootRefund.swift.txt create mode 100644 Tools/CompositionQualification/Negative/RootReturn.swift.txt create mode 100644 Tools/CompositionQualification/Negative/RootSend.swift.txt create mode 100644 Tools/CompositionQualification/Negative/RootSubstitute.swift.txt create mode 100644 Tools/CompositionQualification/Sources/CompositionRootScale/main.swift diff --git a/Documentation/Architecture/Concurrency.md b/Documentation/Architecture/Concurrency.md index 0cc525d..33f5465 100644 --- a/Documentation/Architecture/Concurrency.md +++ b/Documentation/Architecture/Concurrency.md @@ -21,6 +21,14 @@ unchecked box. Operation reports are Sendable only when their result qualifies. Library work has no default MainActor isolation or CPU-offloading convenience. Synchronous calls use the caller executor. +Experimental composition root handles are borrowed, noncopyable and non-Sendable. +Their immutable graph is admitted once by the owning invocation; a private owner +reference prevents another invocation from using that admission. Root callbacks +hold no inout meter borrow across caller code. Handle lifetime never refunds +logical ownership. Scope and handle captures remain subject to compiler ownership +checks; the composition qualification records known Swift 6.4 call-site compiler +aborts separately from expected semantic rejections. + Cancellation checks occur at operation entry, before growth/suspension, on await return and at most 1024 owned charged units apart. Native tests must exercise inner numeric, codec and regex loops, not only wrapper cancellation. A clock diff --git a/Documentation/Architecture/ExtractionManifest.json b/Documentation/Architecture/ExtractionManifest.json index 14aa49e..d5ec001 100644 --- a/Documentation/Architecture/ExtractionManifest.json +++ b/Documentation/Architecture/ExtractionManifest.json @@ -274,6 +274,12 @@ "1.5.1 restores 126 original Apache-2.0 test functions and qualification tools from Swift-JSON 1.2.1 (e8b687f822c577311156b13bf1d15c2d5620b84e), with file hashes and stable function identities in Qualification/Release1.5.1/Restoration.json. The diagnostic omission and Git-free provenance repairs are restored original code; current seven-product harness reconciliation and deterministic CLI identity are original contributions. No new upstream adaptation or dependency.", "Composition reference-load fixtures, serial descriptor staging, public-only adapter, capacity/terminal tests and strict CI receipt checks are original Apache-2.0 code. Generated JSON graphs introduce no upstream protocol fixtures, engine or dependency. Core public APIs, finite profiles and accounting weights are unchanged." ], + "composition_admitted_root_original_contributions": { + "license": "Apache-2.0", + "adapted_third_party_code": false, + "basis": "Independent ownership and repeated-admission review of 720da596; private review evidence excluded from source distribution.", + "scope": "Borrowed immutable admitted-root handles, private invocation identity, conservative selected-output reservations, boundary and scale consumers, compiler-callsite regressions and explicit compiler-abort classification. No root dependency or unsafe annotation added." + }, "jsonhtml_export_original_contributions": { "license": "Apache-2.0", "adapted_third_party_code": false, diff --git a/Documentation/Architecture/ResourceLimits.md b/Documentation/Architecture/ResourceLimits.md index 30cefad..fa518d7 100644 --- a/Documentation/Architecture/ResourceLimits.md +++ b/Documentation/Architecture/ResourceLimits.md @@ -132,9 +132,19 @@ accepted capacities and consumed work. JSONSchema adds offline URI operations through package access without a dependency from JSON to JSONSchema. URI identity and adapter reservations use core, never compiledPlanBytes or compileWorkUnits. -The initial ownership policy is conservative: no public refunds or owner tokens. +The ownership policy is conservative: no public refunds or transferable owner tokens. External reservations and native result ownership survive until scope completion; -re-admitted roots and selected result graphs are reserved again even for aliases. +arbitrary JSON inputs and selected result graphs are reserved again even for aliases. +`withAdmittedRoot` admits an immutable root once and borrows a noncopyable, +non-Sendable handle. `withParsedDocument` borrows a handle to the root already +admitted by source-backed parsing. The handle adds one 16-byte logical frame slot; +its graph and slot remain reserved until composition exit. It has no public +constructor, value accessor, mutation or refund. The resolving scope checks exact +private owner identity before navigation; a wrong-owner operation latches failure +in the receiving invocation. Pointer work and each selected output graph still +charge normally. An empty Pointer selecting the entire root reserves that graph +again. This removes repeated input admission for handle-based lookups without +relaxing arbitrary-JSON admission, output ownership or restriction history. The full Data-to-array reservation precedes allocation and remains charged alongside the root, source bytes, spans, resources and final result. Native scratch uses its existing release rules. The logical peak is a maximum of this single diff --git a/Documentation/CI/README.md b/Documentation/CI/README.md index 01c1973..dc246ef 100644 --- a/Documentation/CI/README.md +++ b/Documentation/CI/README.md @@ -39,9 +39,9 @@ include that consumer alongside their existing gates; all 49 core cap outcomes a retain their original source context; actual source-bound receipts establish passes. This main-based forward-port retains seven products and restores the entire -1.2.1 regression inventory. The experimental composition increment adds 12 functions; current native root discovery is 558 functions and -325 parameter invocations; Linux is 542/325. Full ASan uses the same roots; -TSan checks 42 native or 41 Linux functions. QA requires the original 145-function +1.2.1 regression inventory. The experimental composition increment adds 20 functions; current native root discovery is 566 functions and +325 parameter invocations; Linux is 550/325. Full ASan uses the same roots; +TSan checks 43 native or 42 Linux functions. QA requires the original 145-function maintenance subset. Exact per-module counts are in [the discovery contract](../Qualification/TestDiscovery.json); parameter-function identities remain independently checked from Swift Testing events. All 49 public @@ -173,16 +173,23 @@ observations remain separate from automated SDK/API and portable execution. ## Experimental composition lane -`python3 Scripts/ci.py --lane composition` executes 12 composition functions in -Debug and Release, a distinct-package JSON/JSONSchema consumer in both modes, -five external reference-load functions in Debug/Release/ASan, eight separately classified scale cells, -and 11 compiler-negative ownership fixtures. It supplements the full native, -safety and docs lanes. On a CLT installation that does not discover TestingMacros, +`python3 Scripts/ci.py --lane composition` executes 20 composition functions in +Debug, Release and ASan, two concurrent-invocation functions with TSan, strict +memory-safety compilation of JSON, and a distinct-package JSON/JSONSchema consumer +in both modes (four positive and six negative outcomes). A Release public consumer +performs 1,000 resolutions over 50,000-value trusted and parsed roots under balanced +limits. Eighteen compiler negatives require semantic diagnostics with no object or +compiler abort. Eight real call-site probes include three explicit-borrow positives +and five forms that expose current compiler aborts. Eight Python cases verify +that signals, fatal diagnostics and missing imports cannot pass as rejections. +All commands, nonzero exits, source hashes and outcomes remain in receipts. + +The lane runs every check before reporting compiler robustness. Reproduced known +aborts set overall status `blocked` and exit 2 while `behavior_status` and the +ownership rejection results remain explicit. A crash is never a semantic pass. +This lane uses actual Linux preflight when invoked on Linux; no Linux success is +inferred from macOS execution. It supplements full native, safety and docs lanes. +On a CLT installation that does not discover TestingMacros, set `SWIFT_JSON_TESTING_PLUGIN_PATH` to the installed testing plugin directory; CI records the explicit `-plugin-path` arguments and preserves the original failure. No language, SDK, platform, discovery or sanitizer baseline changes. - -The focused composition lane also runs on the Linux architecture jobs and Native / native. -Its separate-package discovery is additive; all root and 49-cap expectations remain intact. -The qualification harness now has 15 regression functions, retaining its original 14. -See [composition qualification](../Architecture/CompositionQualification.md) for finite capacity outcomes. diff --git a/Documentation/Qualification/README.md b/Documentation/Qualification/README.md index e6c1394..7985538 100644 --- a/Documentation/Qualification/README.md +++ b/Documentation/Qualification/README.md @@ -2,9 +2,9 @@ The 1.5.1 repair candidate restores all 126 functions from the separate 1.2.1 maintenance line without removing the later HTML, bridge, provider or CLI suites. -The experimental composition increment adds 12 functions. Expected full discovery is 558 native / 542 Linux functions, with 325 parameter -invocations. The restored QA subset is 145 functions; shared-state safety is 42 -native / 41 Linux. [TestDiscovery.json](TestDiscovery.json) supplies exact module +The experimental composition increment adds 20 functions. Expected full discovery is 566 native / 550 Linux functions, with 325 parameter +invocations. The restored QA subset is 145 functions; shared-state safety is 43 +native / 42 Linux. [TestDiscovery.json](TestDiscovery.json) supplies exact module cardinalities, while the event reader checks identities and each parameter count. All 49 public cap outcomes and independent policies below remain required. Read [the repair/return record](Release1.5.1/README.md) for actual commands and diff --git a/Documentation/Qualification/TestDiscovery.json b/Documentation/Qualification/TestDiscovery.json index a173776..68a1b0b 100644 --- a/Documentation/Qualification/TestDiscovery.json +++ b/Documentation/Qualification/TestDiscovery.json @@ -6,7 +6,7 @@ "JSONRegexRuntimeTests": 16, "JSONStreamingTests": 30, "JSONPatchTests": 16, - "JSONIntegrationTests": 32, + "JSONIntegrationTests": 40, "JSONHTMLTests": 97, "JSONBridgesTests": 10, "JSONCLITests": 88, @@ -27,7 +27,7 @@ "JSONSchemaTests": 3, "JSONRegexRuntimeTests": 1, "JSONStreamingTests": 16, - "JSONIntegrationTests": 11, + "JSONIntegrationTests": 12, "JSONHTMLTests": 5, "JSONBridgesTests": 1, "JSONCLITests": 1, @@ -64,7 +64,7 @@ "JSONRegexRuntimeTests": 16, "JSONStreamingTests": 30, "JSONPatchTests": 16, - "JSONIntegrationTests": 32, + "JSONIntegrationTests": 40, "JSONHTMLTests": 81, "JSONBridgesTests": 10, "JSONCLITests": 88, @@ -87,7 +87,7 @@ "JSONSchemaTests": 3, "JSONRegexRuntimeTests": 1, "JSONStreamingTests": 16, - "JSONIntegrationTests": 11, + "JSONIntegrationTests": 12, "JSONHTMLTests": 4, "JSONBridgesTests": 1, "JSONCLITests": 1, @@ -96,5 +96,6 @@ "export_functions": { "JSONSchemaTests": 1, "JSONHTMLTests": 39 - } + }, + "composition_functions": 20 } diff --git a/Scripts/ci.py b/Scripts/ci.py index d99640a..1eaf046 100644 --- a/Scripts/ci.py +++ b/Scripts/ci.py @@ -9,7 +9,7 @@ ROOT = pathlib.Path(__file__).resolve().parents[1] SHARED_TESTS = 'independentCodecFacadesAndExactValuesCanBeSharedAcrossTasks|concurrentSchemaEvaluationsHaveExclusiveDynamicRegexAndAnnotationState|sharedRegexProgramHasExclusiveConcurrentSearchState|immutableIndexedObjectCanBeSharedAcrossTasks|qaSharedPayloadAndRootHaveIndependentConcurrentReadScopes|sha256InputCapacityAndConcurrentInvocationsRemainIndependent|sharedFormattedHTMLRendererHasIndependentConcurrentInvocations|sharedAnnotatedDocumentRendererHasIndependentConcurrentInvocations|sharedExportPreparationsHaveIndependentConcurrentState|applePDFSimultaneousJobsHaveIndependentStateAndCancellation|sharedFilterPlanHasIndependentConcurrentInvocations|structuredSharedRendererPlansHaveInvocationOwnedState|sharedProviderBridgeHasIndependentConcurrentInvocations|e2SharedBridgeInputsHaveInvocationOwnedState|e2SharedCompiledPlanFacadeHasIndependentInvocationState' -SHARED_TESTS += '|compositionIndependentScopesCanBeSharedAcrossTasks' +SHARED_TESTS += '|compositionIndependentScopesCanBeSharedAcrossTasks|compositionRootIndependentScopesCanBeSharedAcrossTasks' SHARED_TESTS += '|qaStreaming|qaE2E(SharedPlan|RootImport|NDJSONImport|AwaitedSink|ExactWorkflow)' SHARED_TESTS += '|navigationSharedImmutableRootIndependentInvocations' R0_TESTS = 'readerProbe|indexProbes|duplicateRecognitionPrecedesValueAndClosingSyntax' @@ -22,14 +22,17 @@ def commands(lane, output): output = output.relative_to(ROOT) if lane == 'composition': result = [ + ['python3', '-B', 'Scripts/public_check.py'], + ['python3', '-B', 'Scripts/generate_cli_identity.py', '--check'], + ['python3', '-B', 'Scripts/test_composition_compiler_harness.py'], ['swift', 'test', '--filter', 'composition|composed|caughtOperationalFailureCannotComplete'], ['swift', 'test', '-c', 'release', '--filter', 'composition|composed|caughtOperationalFailureCannotComplete'], + ['swift', 'test', '-c', 'release', '--sanitize', 'address', '--scratch-path', '.build/composition-address', '--filter', 'composition|composed|caughtOperationalFailureCannotComplete'], + ['swift', 'test', '-c', 'release', '--sanitize', 'thread', '--scratch-path', '.build/composition-thread', '--filter', 'composition.*IndependentScopesCanBeSharedAcrossTasks'], + ['swift', 'build', '--target', 'JSON', '--scratch-path', '.build/composition-strict', '-Xswiftc', '-strict-memory-safety', '-Xswiftc', '-warnings-as-errors'], ['swift', 'run', '--package-path', 'Tools/CompositionQualification', 'CompositionConsumer'], ['swift', 'run', '-c', 'release', '--package-path', 'Tools/CompositionQualification', 'CompositionConsumer'], - ['swift', 'test', '--package-path', 'Tools/CompositionQualification'], - ['swift', 'test', '-c', 'release', '--package-path', 'Tools/CompositionQualification'], - ['swift', 'test', '-c', 'release', '--sanitize', 'address', '--scratch-path', '.build/composition-address', '--package-path', 'Tools/CompositionQualification'], - ['python3', '-B', 'Scripts/qualify_composition_scale.py', '--output', str(output / 'scale')], + ['swift', 'run', '-c', 'release', '--package-path', 'Tools/CompositionQualification', 'CompositionRootScale'], ['python3', '-B', 'Scripts/qualify_composition.py', '--output', str(output / 'compiler-negative')], ] return [c + ['--disable-xctest'] if sys.platform == 'linux' and c[:2] == ['swift', 'test'] else c for c in result] @@ -168,7 +171,7 @@ def check_result(command, code, log, events=None): passed = code == 0 if events is not None: counts = events['bundle_counts'] if command[:2] == ['swift', 'test']: - expected = [DISCOVERY['composition_external_functions']] if 'Tools/CompositionQualification' in command else [12] if 'composition|composed|caughtOperationalFailureCannotComplete' in command else [88] if 'cli|sharedFilterPlan' in command else sorted(DISCOVERY['export_functions'].values()) if 'export|Export|apple' in command else [14] if 'Tools/WasmAudit' in command else sorted(DISCOVERY['qa_functions'].values()) if 'qa' in command else [7] if R0_TESTS in command else [3] if 'Tools/MCPReadiness' in command or 'Tools/MobileQualification' in command else [1] if 'Tools/Qualification' in command else sorted(SHARED_COUNTS.values()) if 'thread' in command else sorted(ROOT_COUNTS.values()) + expected = [DISCOVERY['composition_functions']] if 'composition|composed|caughtOperationalFailureCannotComplete' in command else [2] if 'composition.*IndependentScopesCanBeSharedAcrossTasks' in command else [88] if 'cli|sharedFilterPlan' in command else sorted(DISCOVERY['export_functions'].values()) if 'export|Export|apple' in command else [14] if 'Tools/WasmAudit' in command else sorted(DISCOVERY['qa_functions'].values()) if 'qa' in command else [7] if R0_TESTS in command else [3] if 'Tools/MCPReadiness' in command or 'Tools/MobileQualification' in command else [1] if 'Tools/Qualification' in command else sorted(SHARED_COUNTS.values()) if 'thread' in command else sorted(ROOT_COUNTS.values()) if 'navigation' in command: expected = [DISCOVERY['root_functions']['JSONNavigationTests']] if events is not None: @@ -178,7 +181,7 @@ def check_result(command, code, log, events=None): passed = passed and events['module_function_counts'] == {'CompositionScaleTests': DISCOVERY['composition_external_functions']} and events['parameter_case_invocations'] == 0 if 'qa' in command and events is not None: passed = passed and events['module_function_counts'] == DISCOVERY['qa_functions'] and check_restored(events) - if 'thread' in command and events is not None: + if 'thread' in command and 'composition.*IndependentScopesCanBeSharedAcrossTasks' not in command and events is not None: passed = passed and events['module_function_counts'] == SHARED_COUNTS if '--filter' not in command and not any(x.startswith('Tools/') for x in command): if events is not None: @@ -217,7 +220,14 @@ def check_result(command, code, log, events=None): if command == ['swift', 'package', 'show-dependencies', '--format', 'json'] and passed: passed = json.loads(log)['dependencies'] == [] if command[:2] == ['swift', 'run'] and 'CompositionConsumer' in command: - passed = passed and bool(re.search(r'^COMPOSITION_CONSUMER passed positive=2 negative=4 work=[1-9][0-9]* peak=[1-9][0-9]* version=1$', log, re.MULTILINE)) + passed = passed and bool(re.search(r'^COMPOSITION_CONSUMER passed positive=4 negative=6 work=[1-9][0-9]* peak=[1-9][0-9]* version=1$', log, re.MULTILINE)) + if command[:2] == ['swift', 'run'] and 'CompositionRootScale' in command: + cases = re.findall(r'^ADMITTED_ROOT_SCALE path=(trusted|parsed) items=50000 bytes=250001 refs=1000 nodes=51001 work=([1-9][0-9]*) retained=([1-9][0-9]*) peak=([1-9][0-9]*)$', log, re.MULTILINE) + passed = passed and len(cases) == 2 and {c[0] for c in cases} == {'trusted', 'parsed'} and all(int(c[1]) < 1_000_000 and int(c[2]) < 6_000_000 for c in cases) + if 'Scripts/test_composition_compiler_harness.py' in command: + passed = passed and 'COMPOSITION_COMPILER_HARNESS passed cases=10' in log.splitlines() + if command[:2] == ['swift', 'test'] and 'Tools/CompositionQualification' in command and events is not None: + passed = passed and events['module_function_counts'] == {'CompositionScaleTests': DISCOVERY['composition_external_functions']} and events['parameter_case_invocations'] == 0 if command[:2] == ['swift', 'run'] and 'ProviderConsumer' in command: passed = passed and 'PROVIDER_CONSUMER passed cases=14' in log.splitlines() if command[:2] == ['swift', 'run'] and 'Tools/MobileQualification' in command: diff --git a/Scripts/qualify_composition.py b/Scripts/qualify_composition.py index b88f0de..7fe98fb 100644 --- a/Scripts/qualify_composition.py +++ b/Scripts/qualify_composition.py @@ -1,9 +1,19 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: Apache-2.0 """Compiler-negative public composition ownership checks (object emission required).""" -import argparse, json, pathlib, subprocess, tempfile +import argparse, hashlib, json, pathlib, subprocess, tempfile ROOT = pathlib.Path(__file__).resolve().parents[1] +def compiler_outcome(code, log, object_exists, diagnostic=None): + """An abort never establishes an expected ownership rejection.""" + if 'no such module' in log: + return 'failed' + if code < 0 or any(s in log for s in ('Stack dump:', 'fatal error encountered during compilation', 'Found ownership error?!')): + return 'compiler_abort' if not object_exists else 'failed' + if diagnostic is None: + return 'compiled' if code == 0 and object_exists else 'failed' + return 'rejected' if code > 0 and not object_exists and diagnostic in log else 'failed' + def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--output', required=True) @@ -17,21 +27,46 @@ def main(): 'Copy': 'Copyable', 'Send': 'Sendable', 'Escape': 'borrowed', 'Refund': "no member 'release'", 'Construct': "inaccessible", 'Return': 'Copyable', 'Substitute': 'immutable', 'CrossScope': "no member 'release'", 'SubstituteRetention': 'immutable', 'SubstituteCaughtWork': 'immutable', - 'SubstituteCaughtRetention': 'immutable' + 'SubstituteCaughtRetention': 'immutable', + 'RootCopy': 'Copyable', 'RootSend': 'Sendable', 'RootEscape': 'borrowed', + 'RootConstruct': 'inaccessible', 'RootReturn': 'Copyable', + 'RootSubstitute': 'immutable', 'RootRefund': "no member 'release'" } records = [] + callsites = [] with tempfile.TemporaryDirectory(prefix='swift-json-composition-') as directory: - for name, diagnostic in expected.items(): + def compile_case(name, folder, diagnostic): source = pathlib.Path(directory) / (name + '.swift') - source.write_bytes((ROOT / 'Tools/CompositionQualification/Negative' / (name + '.swift.txt')).read_bytes()) + source.write_bytes((ROOT / 'Tools/CompositionQualification' / folder / (name + '.swift.txt')).read_bytes()) command = ['swiftc', '-c', '-swift-version', '6', '-I', str(modules), str(source), '-o', str(source.with_suffix('.o'))] run = subprocess.run(command, cwd=ROOT, capture_output=True, text=True, timeout=120) log = run.stdout + run.stderr (output / (name + '.log')).write_text(log) - records.append(dict(name=name, command=command, exit_code=run.returncode, - expected_diagnostic=diagnostic, status='passed' if run.returncode != 0 and diagnostic in log and 'no such module' not in log else 'failed')) + return dict(name=name, command=command, exit_code=run.returncode, + source_sha256=hashlib.sha256(source.read_bytes()).hexdigest(), + expected_diagnostic=diagnostic, + outcome=compiler_outcome(run.returncode, log, source.with_suffix('.o').exists(), diagnostic)) + for name, diagnostic in expected.items(): + record = compile_case(name, 'Negative', diagnostic) + record['status'] = 'passed' if record['outcome'] == 'rejected' else 'failed' + records.append(record) + for name, diagnostic in [('ClosureBorrow', None), ('RootClosureBorrow', None), ('ExplicitBorrowParameters', None), + ('MethodEscape', 'borrowed'), ('ContainerEscape', 'borrowed'), + ('MethodBorrow', None), ('RootContainerEscape', 'borrowed'), ('LocalFunctionBorrow', None)]: + record = compile_case(name, 'Compiler', diagnostic) + # Preserve these known call-site compiler bugs separately. A newer + # compiler may diagnose the escapes or compile the nonescaping use. + known_abort = name in {'MethodEscape', 'ContainerEscape', 'MethodBorrow', 'RootContainerEscape', 'LocalFunctionBorrow'} + record['status'] = ('blocked' if known_abort and record['outcome'] == 'compiler_abort' else + 'passed' if record['outcome'] == ('compiled' if diagnostic is None else 'rejected') else 'failed') + callsites.append(record) receipt = dict(status='passed' if all(r['status']=='passed' for r in records) else 'failed', - compiler_negative_cases=len(records), records=records) + compiler_negative_cases=len(records), records=records, + callsite_cases=len(callsites), callsites=callsites, + compiler_abort_cases=sum(r['outcome']=='compiler_abort' for r in callsites)) + if any(r['status']=='failed' for r in callsites): receipt['status'] = 'failed' + receipt['compiler_robustness_status'] = ('blocked' if receipt['compiler_abort_cases'] else + 'failed' if any(r['status']=='failed' for r in callsites) else 'passed') (output / 'receipt.json').write_text(json.dumps(receipt, indent=2)+'\n') print(json.dumps(receipt, indent=2)) return 0 if receipt['status']=='passed' else 1 diff --git a/Scripts/test_composition_compiler_harness.py b/Scripts/test_composition_compiler_harness.py new file mode 100644 index 0000000..4d87cca --- /dev/null +++ b/Scripts/test_composition_compiler_harness.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Verify compiler crash classification independently of the Swift fixtures.""" +import unittest +from qualify_composition import compiler_outcome + +class CompilerHarnessTests(unittest.TestCase): + def test_expected_rejection(self): + self.assertEqual(compiler_outcome(1, "error: borrowed", False, 'borrowed'), 'rejected') + + def test_missing_module_never_rejects(self): + self.assertEqual(compiler_outcome(1, "no such module JSON; borrowed", False, 'borrowed'), 'failed') + + def test_signal_is_not_rejection(self): + self.assertEqual(compiler_outcome(-6, "borrowed", False, 'borrowed'), 'compiler_abort') + + def test_fatal_diagnostic_is_not_rejection(self): + self.assertEqual(compiler_outcome(1, "borrowed; fatal error encountered during compilation", False, 'borrowed'), 'compiler_abort') + + def test_stack_dump_is_not_rejection(self): + self.assertEqual(compiler_outcome(1, "borrowed; Stack dump:", False, 'borrowed'), 'compiler_abort') + + def test_negative_cannot_emit_object(self): + self.assertEqual(compiler_outcome(1, "error: borrowed", True, 'borrowed'), 'failed') + + def test_positive_requires_emission(self): + self.assertEqual(compiler_outcome(0, '', True), 'compiled') + self.assertEqual(compiler_outcome(0, '', False), 'failed') + + def test_unrelated_error_is_not_rejection(self): + self.assertEqual(compiler_outcome(1, "error: invalid syntax", False, 'borrowed'), 'failed') + +if __name__ == '__main__': + suite = unittest.defaultTestLoader.loadTestsFromTestCase(CompilerHarnessTests) + result = unittest.TextTestRunner().run(suite) + passed = result.wasSuccessful() and result.testsRun == 8 and not result.skipped + if passed: print('COMPOSITION_COMPILER_HARNESS passed cases=8') + raise SystemExit(0 if passed else 1) diff --git a/Sources/JSON/Documentation.docc/Composition.md b/Sources/JSON/Documentation.docc/Composition.md index 6de53b5..bc0b7ff 100644 --- a/Sources/JSON/Documentation.docc/Composition.md +++ b/Sources/JSON/Documentation.docc/Composition.md @@ -10,21 +10,23 @@ import JSON import JSONSchema let report = try JSON.withComposition { scope in - let document = try scope.parseDocument(Data(#"{"count":9007199254740993}"#.utf8)) - try scope.reserveExternalLogicalBytes(64) // Adapter-declared output frame weight. - try scope.chargeExternalWork(1) // Before the adapter's corresponding work. - let pointer = try scope.pointer(tokens: ["count"]) - _ = try scope.uri("https://example.invalid/schema.json") - return try scope.resolve(pointer, in: document.root) + try scope.withParsedDocument(Data(#"{"count":9007199254740993}"#.utf8)) { document, root in + try scope.reserveExternalLogicalBytes(64) // Adapter-declared output frame weight. + try scope.chargeExternalWork(1) // Before the adapter's corresponding work. + let pointer = try scope.pointer(tokens: ["count"]) + _ = try scope.uri("https://example.invalid/schema.json") + _ = document.sourceMap + return try scope.resolve(pointer, in: root) + } } ``` The scope is borrowed, noncopyable, synchronous and not Sendable. Its methods mutate invocation-owned private state. The closure cannot replace or swap the borrowed facade. It has no public -initializer, continuation, refund or ownership token. Every reservation lasts -until completion. Re-admitting a value reserves its graph again; resolving -reserves its input graph and selected graph again. This intentionally overcounts +initializer, continuation or refund. Every reservation lasts +until completion. Re-admitting a value reserves its graph again; resolving an +arbitrary JSON input reserves its input graph and selected graph again. This intentionally overcounts aliases and dead temporaries rather than assuming copy-on-write releases memory. Reserve each external result, queue, diagnostic and copied slot before growth; choose and audit its logical weights in the adapter. A zero reservation makes no @@ -56,3 +58,34 @@ unforgeable receipt, and it cannot establish that an arbitrary callback charged all its work. An adopting adapter must own its final accounting boundary and audit all external work and reservations. Independent reports cannot retroactively certify one enforced invocation. + +For repeated lookups, `withAdmittedRoot` admits a trusted immutable graph once. +`withParsedDocument` supplies the source-backed document and a handle to its +already-admitted root, without a second root traversal. Both borrow a noncopyable, +non-Sendable `JSONCompositionRoot` in a synchronous nonescaping callback. The handle +has no public constructor, value accessor, mutation or refund. It keeps the exact +immutable snapshot even if the caller later replaces its original JSON value. + +Only the creating composition can resolve against a handle. A wrong-owner attempt +fails before navigation and permanently fails the receiving invocation. The owner +identity is a private reference retained by the handle, so identity cannot be +recycled while a handle exists. Native health and cumulative limits still apply. +No mutable meter borrow spans callback execution. + +Root ownership and one 16-byte logical handle slot remain charged after the root +callback ends, until composition completion. Each selected output graph is still +admitted and reserved separately, including an empty Pointer selecting the whole +root. Pointer admission and navigation remain metered. For R small selections over +an N-node root, admission becomes O(N) plus navigation and selected-output work; +large selected graphs still cost their full size. Calling `withAdmittedRoot` again +reserves another graph even for aliases. This API never caches arbitrary JSON +identity or presumes a copy-on-write refund. + +The pinned Swift 6.4 compiler aborts for some implicit captures at actual callback +call sites: returned bound methods, returned closure containers, a bound method +passed to a nonescaping helper and local functions implicitly capturing a scope. +Use explicit borrowing parameters for named helpers and explicit nonescaping closures, for example +`try perform { try scope.checkpoint() }`, instead of a bound method reference. +Qualification records aborts separately from semantic ownership rejections; an +abort emits no object and never counts as a successful rejection. Compiler +robustness remains a reported blocker while those aborts reproduce. diff --git a/Sources/JSON/Limits/JSONCompositionScope.swift b/Sources/JSON/Limits/JSONCompositionScope.swift index 3ebf9b3..f821bab 100644 --- a/Sources/JSON/Limits/JSONCompositionScope.swift +++ b/Sources/JSON/Limits/JSONCompositionScope.swift @@ -1,13 +1,29 @@ // SPDX-License-Identifier: Apache-2.0 import Foundation -private final class JSONCompositionState { +fileprivate final class JSONCompositionState { var context: JSONOperationContext init(limits: JSONLimits) throws { context = try JSONOperationContext(limits: limits, domain: .core, trackAcceptedCapacities: true) } } +/// A borrowed immutable root admitted by one composition invocation. +/// +/// Obtain this handle through ``JSONCompositionScope/withAdmittedRoot(_:_:)`` or +/// ``JSONCompositionScope/withParsedDocument(_:_:)``. It has no public initializer, +/// value accessor or refund. Only its owning scope may resolve against it. The +/// borrowed noncopyable handle cannot be returned, substituted or sent to a task. +public struct JSONCompositionRoot: ~Copyable { + fileprivate let owner: JSONCompositionState + fileprivate let value: JSON + + fileprivate init(owner: JSONCompositionState, value: JSON) { + self.owner = owner + self.value = value + } +} + /// One synchronous, noncopyable composition of native and explicitly instrumented work. /// /// Create a scope with ``JSON/withComposition(limits:_:)``. Native results and @@ -64,6 +80,60 @@ public struct JSONCompositionScope: ~Copyable { } } + /// Admits an immutable graph once and borrows an invocation-bound lookup handle. + /// + /// The root graph and one 16-byte logical handle slot remain reserved until + /// composition completion. Repeated lookups admit their Pointer and selected + /// result, without traversing or reserving this root again. Each new call to + /// this method admits a complete graph, including aliases of an earlier root. + /// - Parameters: + /// - value: Trusted caller value; its prior construction is caller work. + /// - body: Synchronous work borrowing the immutable admitted root. + /// - Returns: The callback result; the handle cannot be returned. + /// - Throws: Native terminal failure, cancellation or callback error. + public func withAdmittedRoot(_ value: JSON, + _ body: (borrowing JSONCompositionRoot) throws -> Result) throws -> Result { + try withMeter { try JSONAdmission.value(value, meter: &$0, owned: true) } + return try borrowingRoot(value, body) + } + + /// Parses a source-backed document and borrows its already-admitted root. + /// + /// Parsing, source bytes, mapping and the root share this invocation's ledger. + /// The handle adds one logical slot and shares the parsed immutable graph; + /// it does not perform a second admission of the parsed root. The document + /// may be returned. Its existing reservation lasts until composition exit. + /// - Parameters: + /// - data: Caller-owned strict UTF-8 input. + /// - body: Synchronous work receiving the document and borrowing its root handle. + /// - Returns: The callback result, which may include the document or selected values. + /// - Throws: Native terminal failure, cancellation or callback error. + public func withParsedDocument(_ data: Data, + _ body: (JSONDocument, borrowing JSONCompositionRoot) throws -> Result) throws -> Result { + let document = try parseDocument(data) + return try borrowingRoot(document.root) { root in try body(document, root) } + } + + private func borrowingRoot(_ value: JSON, + _ body: (borrowing JSONCompositionRoot) throws -> Result) throws -> Result { + try withMeter { meter in + try meter.work() + try meter.retain(JSONLogicalWeights.frame) + } + let root = JSONCompositionRoot(owner: state, value: value) + let original = state.context.meter.continuation + // No inout meter access spans caller code: nested native calls use the + // same invocation, and a caught owned failure still prevents this return. + do { + let result = try body(root) + try original.check(state.context.meter) + return result + } catch { + try original.check(state.context.meter) + throw error + } + } + /// Constructs an exact Pointer using this invocation's remaining budget. /// - Parameter tokens: Caller-owned decoded tokens. /// - Returns: The admitted Pointer. @@ -117,6 +187,27 @@ public struct JSONCompositionScope: ~Copyable { } } + /// Resolves against this invocation's admitted immutable root. + /// + /// Owner identity is checked before navigation. Pointer admission and native + /// navigation consume cumulative work; the selected result graph is reserved + /// anew, even for aliases or an empty Pointer selecting the entire root. + /// - Parameters: + /// - pointer: Caller or scope-created exact Pointer. + /// - root: Borrowed handle produced by this scope's root callback. + /// - Returns: The selected exact value with a conservative output reservation. + /// - Throws: Wrong-owner configuration failure, native failure or cancellation. + public func resolve(_ pointer: JSONPointer, in root: borrowing JSONCompositionRoot) throws -> JSON { + try withMeter(domain: .pointer) { meter in + try meter.work() + guard root.owner === state else { throw JSONFailure(.configuration, code: .invalidOperation) } + let admitted = try JSONPointer.decodedTokens(pointer.tokens, meter: &meter) + let result = try admitted.resolve(in: root.value, meter: &meter) + try JSONAdmission.value(result, meter: &meter, owned: true) + return result + } + } + /// Charges instrumented adapter work once to aggregate core work. /// - Parameter units: Declared primitive work admitted before performing it. /// - Throws: Quota/overflow failure or cancellation, permanently terminal. diff --git a/Tests/JSONIntegrationTests/CompositionRootTests.swift b/Tests/JSONIntegrationTests/CompositionRootTests.swift new file mode 100644 index 0000000..a3f3b06 --- /dev/null +++ b/Tests/JSONIntegrationTests/CompositionRootTests.swift @@ -0,0 +1,199 @@ +// SPDX-License-Identifier: Apache-2.0 +import Foundation +import JSON +import Testing + +private func rootLookups(_ value: JSON, count: Int, limits: JSONLimits = .balanced) throws -> JSONOperationReport { + try JSON.withComposition(limits: limits) { scope in + let pointer = try scope.pointer(tokens: ["0"]) + return try scope.withAdmittedRoot(value) { root in + for _ in 0..= threshold { withUnsafeCurrentTask { $0?.cancel() } } + } + } +} + +@Test func compositionRootAdmissionIsOnceAndPlainOverloadRemainsConservative() throws { + let value = JSON.array(Array(repeating: .null, count: 50_000)) + let zero = try rootLookups(value, count: 0) + let one = try rootLookups(value, count: 1) + let two = try rootLookups(value, count: 2) + let many = try rootLookups(value, count: 1_000) + #expect(many.result == 1_000) + #expect(zero.statistics[.nodes] == 50_001) + #expect(many.statistics[.nodes] == 51_001) + #expect(many.statistics[.workUnits] == zero.statistics[.workUnits] + 1_000 * (one.statistics[.workUnits] - zero.statistics[.workUnits])) + #expect(two.statistics[.retainedBytes] - one.statistics[.retainedBytes] == one.statistics[.retainedBytes] - zero.statistics[.retainedBytes]) + #expect(many.statistics[.retainedBytes] < 3_000_000) + // The arbitrary-JSON overload still cannot presume prior admission. + do { + _ = try JSON.withComposition { scope in + let admitted = try scope.admitTrusted(value) + let pointer = try scope.pointer(tokens: ["0"]) + for _ in 0..<19 { _ = try scope.resolve(pointer, in: admitted) } + } + Issue.record("plain root unexpectedly bypassed repeated admission") + } catch let failure as JSONFailure { + #expect(failure.resource?.metric == .nodes) + #expect(failure.resource?.attemptedUsage == 1_000_001) + } +} + +@Test func compositionRootParsedDocumentSharesAdmissionAndExactSnapshot() throws { + let data = Data(#"{"é":9007199254740993,"e\u0301":0.01}"#.utf8) + let ordinary = try JSON.withComposition { try $0.parseDocument(data) } + let parsed = try JSON.withComposition { scope in + try scope.withParsedDocument(data) { document, root in + let number = try scope.resolve(scope.pointer(tokens: ["é"]), in: root) + let fraction = try scope.resolve(scope.pointer(tokens: ["e\u{301}"]), in: root) + #expect(number.numberValue?.originalLexeme == "9007199254740993") + #expect(fraction.numberValue?.originalLexeme == "0.01") + return document + } + } + #expect(parsed.result.sourceBytes == data) + #expect(parsed.result.sourceMap?.entries.count == ordinary.result.sourceMap?.entries.count) + #expect(parsed.statistics[.nodes] == ordinary.statistics[.nodes] + 2) + var callerValue = JSON.array([.boolean(true)]) + _ = try JSON.withComposition { scope in + try scope.withAdmittedRoot(callerValue) { root in + callerValue = .null + let selected = try scope.resolve(scope.pointer(tokens: ["0"]), in: root) + #expect(selected == true) + } + } + #expect(callerValue == .null) +} + +@Test func compositionRootThresholdsAndTerminalFailures() throws { + let value = JSON.array(Array(repeating: .null, count: 32)) + let probe = try rootLookups(value, count: 8) + var limits = JSONLimits.balanced + limits[.workUnits] = probe.statistics[.workUnits] + limits[.retainedBytes] = probe.statistics.peakLogicalRetainedBytes + #expect(try rootLookups(value, count: 8, limits: limits).statistics == probe.statistics) + for metric in [JSONResourceMetric.workUnits, .retainedBytes] { + var below = limits + below[metric] -= 1 + #expect(throws: JSONFailure.self) { try rootLookups(value, count: 8, limits: below) } + } + #expect(throws: JSONFailure.self) { + try JSON.withComposition { scope in + try scope.withAdmittedRoot(value) { root in + do { _ = try scope.resolve(scope.pointer(tokens: ["99"]), in: root) } catch { } + return 0 + } + } + } +} + +@Test func compositionRootOwnerIdentityAndNestedRoots() throws { + let report = try JSON.withComposition { outer in + let pointer = try outer.pointer(tokens: ["0"]) + return try outer.withAdmittedRoot(.array([true])) { root in + do { + _ = try JSON.withComposition { inner in + do { _ = try inner.resolve(pointer, in: root) } catch let failure as JSONFailure { + #expect(failure.category == .configuration) + #expect(failure.code == .invalidOperation) + } + return 0 + } + Issue.record("caught wrong-owner failure finalized") + } catch let failure as JSONFailure { #expect(failure.code == .invalidOperation) } + try outer.withAdmittedRoot(.array([false])) { other in + let innerValue = try outer.resolve(pointer, in: other) + let outerValue = try outer.resolve(pointer, in: root) + #expect(innerValue == false) + #expect(outerValue == true) + } + return try outer.resolve(pointer, in: root) + } + } + #expect(report.result == true) + #expect(report.statistics[.nodes] == 7) // Two roots and three selected scalars. +} + +@Test func compositionRootOutputReservationsAndDeadHandlesStayCharged() throws { + let value = JSON.array([.null, .null]) + let admitted = try JSON.withComposition { scope in try scope.withAdmittedRoot(value) { _ in 0 } } + let selected = try JSON.withComposition { scope in + let pointer = try scope.pointer(tokens: []) + return try scope.withAdmittedRoot(value) { root in try scope.resolve(pointer, in: root) } + } + let graphBytes = try JSON.withComposition { try $0.admitTrusted(value) }.statistics[.retainedBytes] + #expect(selected.statistics[.retainedBytes] == admitted.statistics[.retainedBytes] + graphBytes) + #expect(selected.statistics[.nodes] == 6) + var below = JSONLimits.balanced + below[.retainedBytes] = admitted.statistics[.retainedBytes] + #expect(throws: JSONFailure.self) { + try JSON.withComposition(limits: below) { scope in + _ = try scope.withAdmittedRoot(value) { _ in 0 } + // Ending the handle callback cannot refund the reserved graph/slot. + try scope.reserveExternalLogicalBytes(1) + } + } + let aliases = try JSON.withComposition { scope in + _ = try scope.withAdmittedRoot(value) { _ in 0 } + return try scope.withAdmittedRoot(value) { _ in 0 } + } + #expect(aliases.statistics[.retainedBytes] == admitted.statistics[.retainedBytes] * 2) +} + +@Test func compositionRootRestrictionsRememberAdmission() throws { + for metric in [JSONResourceMetric.nodes, .retainedBytes, .maxDepth] { + #expect(throws: JSONFailure.self) { + try JSON.withComposition { scope in + _ = try scope.withAdmittedRoot(.array([.null])) { _ in 0 } + var smaller = JSONLimits.balanced + smaller[metric] = 0 + do { try scope.restrict(to: smaller) } catch { } + return 0 + } + } + } + enum CallerFailure: Error { case expected } + #expect(throws: CallerFailure.self) { + try JSON.withComposition { scope in + try scope.withAdmittedRoot(.null) { _ in throw CallerFailure.expected } + } + } +} + +@Test func compositionRootCancellationIsTerminal() async throws { + for duringSelection in [false, true] { + let task = Task.detached { + _ = try JSON.withComposition { scope in + let value = JSON.array(Array(repeating: .null, count: 4_096)) + if !duringSelection { try observeRootCancellation(scope) } + do { + try scope.withAdmittedRoot(value) { root in + if duringSelection { try observeRootCancellation(scope) } + do { _ = try scope.resolve(scope.pointer(tokens: []), in: root) } catch is CancellationError { } + } + } catch is CancellationError { } + return 0 + } + } + do { try await task.value; Issue.record("cancelled admitted root finalized") } + catch is CancellationError { } + } +} + +@Test func compositionRootIndependentScopesCanBeSharedAcrossTasks() async throws { + let value = JSON.array(Array(repeating: .null, count: 256)) + let expected = try rootLookups(value, count: 64).statistics + try await withThrowingTaskGroup(of: JSONOperationStatistics.self) { group in + for _ in 0..<16 { group.addTask { try rootLookups(value, count: 64).statistics } } + for try await statistics in group { #expect(statistics == expected) } + } +} diff --git a/Tools/CompositionQualification/Compiler/ClosureBorrow.swift.txt b/Tools/CompositionQualification/Compiler/ClosureBorrow.swift.txt new file mode 100644 index 0000000..e76a011 --- /dev/null +++ b/Tools/CompositionQualification/Compiler/ClosureBorrow.swift.txt @@ -0,0 +1,5 @@ +import JSON +func callNow(_ operation: () throws -> Void) throws { try operation() } +func borrowedClosure() throws { + _ = try JSON.withComposition { scope in try callNow { try scope.checkpoint() } } +} diff --git a/Tools/CompositionQualification/Compiler/ContainerEscape.swift.txt b/Tools/CompositionQualification/Compiler/ContainerEscape.swift.txt new file mode 100644 index 0000000..a1d427f --- /dev/null +++ b/Tools/CompositionQualification/Compiler/ContainerEscape.swift.txt @@ -0,0 +1,5 @@ +import JSON +struct Box { let action: () throws -> Void } +func escapedContainer() throws -> Box { + try JSON.withComposition { scope in Box(action: { try scope.checkpoint() }) }.result +} diff --git a/Tools/CompositionQualification/Compiler/ExplicitBorrowParameters.swift.txt b/Tools/CompositionQualification/Compiler/ExplicitBorrowParameters.swift.txt new file mode 100644 index 0000000..7b55e46 --- /dev/null +++ b/Tools/CompositionQualification/Compiler/ExplicitBorrowParameters.swift.txt @@ -0,0 +1,5 @@ +import JSON +func invoke(_ scope: borrowing JSONCompositionScope) throws { try scope.checkpoint() } +func borrowedParameter() throws { + _ = try JSON.withComposition { scope in try invoke(scope) } +} diff --git a/Tools/CompositionQualification/Compiler/LocalFunctionBorrow.swift.txt b/Tools/CompositionQualification/Compiler/LocalFunctionBorrow.swift.txt new file mode 100644 index 0000000..342ee86 --- /dev/null +++ b/Tools/CompositionQualification/Compiler/LocalFunctionBorrow.swift.txt @@ -0,0 +1,7 @@ +import JSON +func borrowedLocalFunction() throws { + _ = try JSON.withComposition { scope in + func invoke() throws { try scope.checkpoint() } + try invoke() + } +} diff --git a/Tools/CompositionQualification/Compiler/MethodBorrow.swift.txt b/Tools/CompositionQualification/Compiler/MethodBorrow.swift.txt new file mode 100644 index 0000000..7770a8b --- /dev/null +++ b/Tools/CompositionQualification/Compiler/MethodBorrow.swift.txt @@ -0,0 +1,5 @@ +import JSON +func callNow(_ operation: () throws -> Void) throws { try operation() } +func borrowedMethod() throws { + _ = try JSON.withComposition { scope in try callNow(scope.checkpoint) } +} diff --git a/Tools/CompositionQualification/Compiler/MethodEscape.swift.txt b/Tools/CompositionQualification/Compiler/MethodEscape.swift.txt new file mode 100644 index 0000000..65b6aab --- /dev/null +++ b/Tools/CompositionQualification/Compiler/MethodEscape.swift.txt @@ -0,0 +1,4 @@ +import JSON +func escapedMethod() throws -> () throws -> Void { + try JSON.withComposition { scope in scope.checkpoint }.result +} diff --git a/Tools/CompositionQualification/Compiler/RootClosureBorrow.swift.txt b/Tools/CompositionQualification/Compiler/RootClosureBorrow.swift.txt new file mode 100644 index 0000000..572586c --- /dev/null +++ b/Tools/CompositionQualification/Compiler/RootClosureBorrow.swift.txt @@ -0,0 +1,10 @@ +import JSON +func callNow(_ operation: () throws -> JSON) throws -> JSON { try operation() } +func borrowedRoot() throws -> JSON { + try JSON.withComposition { scope in + let pointer = try scope.pointer(tokens: []) + return try scope.withAdmittedRoot(.null) { root in + try callNow { try scope.resolve(pointer, in: root) } + } + }.result +} diff --git a/Tools/CompositionQualification/Compiler/RootContainerEscape.swift.txt b/Tools/CompositionQualification/Compiler/RootContainerEscape.swift.txt new file mode 100644 index 0000000..4d9ec30 --- /dev/null +++ b/Tools/CompositionQualification/Compiler/RootContainerEscape.swift.txt @@ -0,0 +1,10 @@ +import JSON +struct Box { let action: () throws -> JSON } +func escapedRoot() throws -> Box { + try JSON.withComposition { scope in + let pointer = try scope.pointer(tokens: []) + return try scope.withAdmittedRoot(.null) { root in + Box(action: { try scope.resolve(pointer, in: root) }) + } + }.result +} diff --git a/Tools/CompositionQualification/Negative/RootConstruct.swift.txt b/Tools/CompositionQualification/Negative/RootConstruct.swift.txt new file mode 100644 index 0000000..76c1ed1 --- /dev/null +++ b/Tools/CompositionQualification/Negative/RootConstruct.swift.txt @@ -0,0 +1,2 @@ +import JSON +let root = JSONCompositionRoot() diff --git a/Tools/CompositionQualification/Negative/RootCopy.swift.txt b/Tools/CompositionQualification/Negative/RootCopy.swift.txt new file mode 100644 index 0000000..6eeddeb --- /dev/null +++ b/Tools/CompositionQualification/Negative/RootCopy.swift.txt @@ -0,0 +1,3 @@ +import JSON +func copy(_ value: T) {} +func rejected(_ root: borrowing JSONCompositionRoot) { copy(root) } diff --git a/Tools/CompositionQualification/Negative/RootEscape.swift.txt b/Tools/CompositionQualification/Negative/RootEscape.swift.txt new file mode 100644 index 0000000..1f159b9 --- /dev/null +++ b/Tools/CompositionQualification/Negative/RootEscape.swift.txt @@ -0,0 +1,4 @@ +import JSON +func rejected(_ root: borrowing JSONCompositionRoot, scope: borrowing JSONCompositionScope, pointer: JSONPointer) -> () throws -> JSON { + { try scope.resolve(pointer, in: root) } +} diff --git a/Tools/CompositionQualification/Negative/RootRefund.swift.txt b/Tools/CompositionQualification/Negative/RootRefund.swift.txt new file mode 100644 index 0000000..0efe0e3 --- /dev/null +++ b/Tools/CompositionQualification/Negative/RootRefund.swift.txt @@ -0,0 +1,2 @@ +import JSON +func rejected(_ root: borrowing JSONCompositionRoot) throws { try root.release(1) } diff --git a/Tools/CompositionQualification/Negative/RootReturn.swift.txt b/Tools/CompositionQualification/Negative/RootReturn.swift.txt new file mode 100644 index 0000000..1d6584d --- /dev/null +++ b/Tools/CompositionQualification/Negative/RootReturn.swift.txt @@ -0,0 +1,4 @@ +import JSON +func rejected(_ scope: borrowing JSONCompositionScope) throws -> JSONCompositionRoot { + try scope.withAdmittedRoot(.null) { root in return consume root } +} diff --git a/Tools/CompositionQualification/Negative/RootSend.swift.txt b/Tools/CompositionQualification/Negative/RootSend.swift.txt new file mode 100644 index 0000000..dd8bd92 --- /dev/null +++ b/Tools/CompositionQualification/Negative/RootSend.swift.txt @@ -0,0 +1,3 @@ +import JSON +func share(_ value: borrowing T) {} +func rejected(_ root: borrowing JSONCompositionRoot) { share(root) } diff --git a/Tools/CompositionQualification/Negative/RootSubstitute.swift.txt b/Tools/CompositionQualification/Negative/RootSubstitute.swift.txt new file mode 100644 index 0000000..7b4439f --- /dev/null +++ b/Tools/CompositionQualification/Negative/RootSubstitute.swift.txt @@ -0,0 +1,9 @@ +import JSON +let _ = try JSON.withComposition { scope in + try scope.withAdmittedRoot(.null) { outer in + try scope.withAdmittedRoot(.null) { inner in + swap(&outer, &inner) + swap(&outer, &inner) + } + } +} diff --git a/Tools/CompositionQualification/Package.swift b/Tools/CompositionQualification/Package.swift index 47d1933..3ed9717 100644 --- a/Tools/CompositionQualification/Package.swift +++ b/Tools/CompositionQualification/Package.swift @@ -15,6 +15,8 @@ let package = Package( ]), .executableTarget(name: "CompositionConsumer", dependencies: [ .product(name: "JSON", package: "Swift-JSON"), .product(name: "JSONSchema", package: "Swift-JSON") + ]), .executableTarget(name: "CompositionRootScale", dependencies: [ + .product(name: "JSON", package: "Swift-JSON") ]), .executableTarget(name: "CompositionRegression", dependencies: [ .product(name: "JSON", package: "Swift-JSON"), .product(name: "JSONSchema", package: "Swift-JSON") diff --git a/Tools/CompositionQualification/README.md b/Tools/CompositionQualification/README.md index f61927e..a03a520 100644 --- a/Tools/CompositionQualification/README.md +++ b/Tools/CompositionQualification/README.md @@ -9,15 +9,31 @@ Run the complete focused gate from the repository root: python3 Scripts/ci.py --lane composition ``` -The gate executes 12 Swift Testing functions in Debug and Release, this consumer -in both configurations (two positive and four negative outcomes each), and 11 -compiler-negative cases. Negative cases use object emission, which catches +The gate executes 20 Swift Testing functions in Debug, Release and ASan, two +concurrent-invocation functions with TSan, strict memory-safety JSON compilation, +and this consumer in both configurations (four positive and six negative outcomes +each). `CompositionRootScale` resolves 1,000 references over 50,000-value trusted +and source-backed roots with balanced limits. The root is admitted once; selected +outputs remain charged individually. The arbitrary-JSON overload retains its +conservative repeated-root admission behavior. + +Eighteen compiler-negative cases use object emission, which catches ownership diagnostics deferred beyond typechecking. Missing imports never count -as successful rejection. Copy, Sendable sharing, escape, direct construction, +as successful rejection. Compiler signals, fatal diagnostics and emitted objects +also cannot satisfy a negative case. Copy, Sendable sharing, escape, direct construction, return, scope swap/use/restore for exact work, retention and caught failures, double refund and cross-scope refund are rejected. -The policy exposes no ownership token or refund, so those operations are invalid -public programs rather than runtime token failures. +The policy exposes no transferable owner token or refund. Borrowed root handles +have no public constructor, value accessor or mutation; their private owner +identity rejects use by another scope before navigation. + +Eight additional actual-callsite probes include three explicit-borrow positives and +five forms exposing Swift 6.4 compiler aborts. Their outcomes are separate from +the 18 semantic rejections. Eight Python harness cases check the distinction. +The lane completes its checks, then exits 2 with overall `blocked` if known compiler +aborts reproduce. Successful behavior and ownership results are recorded alongside +the compiler robustness blocker. Use explicit nonescaping closures in supported +code; do not turn a compiler crash into a rejection pass. ```sh swift run -c release --package-path Tools/CompositionQualification CompositionRegression diff --git a/Tools/CompositionQualification/Sources/CompositionConsumer/main.swift b/Tools/CompositionQualification/Sources/CompositionConsumer/main.swift index 30ad7db..f5e1ec8 100644 --- a/Tools/CompositionQualification/Sources/CompositionConsumer/main.swift +++ b/Tools/CompositionQualification/Sources/CompositionConsumer/main.swift @@ -54,4 +54,39 @@ zero[.workUnits] = 0 } fatalError("caught native failure finalized") } catch let failure as JSONFailure { precondition(failure.category == .resource); negativeCount += 1 } -print("COMPOSITION_CONSUMER passed positive=2 negative=\(negativeCount) work=\(probe.statistics[.workUnits]) peak=\(probe.statistics.peakLogicalRetainedBytes) version=\(probe.statistics.accountingVersion)") +let rooted = try JSON.withComposition { scope in + try scope.withParsedDocument(data) { document, root in + let pointer = try scope.pointer(tokens: ["n"]) + for _ in 0..<100 { + let selected = try scope.resolve(pointer, in: root) + precondition(selected.numberValue?.originalLexeme == "9007199254740993") + } + return document + } +} +precondition(rooted.result.sourceBytes == data) +let trusted = try JSON.withComposition { scope in + try scope.withAdmittedRoot(.array([true])) { root in + try scope.resolve(scope.pointer(tokens: ["0"]), in: root) + } +} +precondition(trusted.result == true) +for wrongOwner in [false, true] { + do { + _ = try JSON.withComposition { scope in + try scope.withAdmittedRoot(.array([true])) { root in + let pointer = try scope.pointer(tokens: [wrongOwner ? "0" : "9"]) + if wrongOwner { + return try JSON.withComposition { other in + do { _ = try other.resolve(pointer, in: root) } catch { } + return 0 + }.result + } + do { _ = try scope.resolve(pointer, in: root) } catch { } + return 0 + } + } + fatalError("invalid admitted-root operation finalized") + } catch is JSONFailure { negativeCount += 1 } +} +print("COMPOSITION_CONSUMER passed positive=4 negative=\(negativeCount) work=\(probe.statistics[.workUnits]) peak=\(probe.statistics.peakLogicalRetainedBytes) version=\(probe.statistics.accountingVersion)") diff --git a/Tools/CompositionQualification/Sources/CompositionRootScale/main.swift b/Tools/CompositionQualification/Sources/CompositionRootScale/main.swift new file mode 100644 index 0000000..eb0e808 --- /dev/null +++ b/Tools/CompositionQualification/Sources/CompositionRootScale/main.swift @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: Apache-2.0 +import Foundation +import JSON + +// Public consumer of the exact scale case from the independent review. Input +// construction belongs to the caller; all owned admission and lookups share scope. +let value = JSON.array(Array(repeating: .null, count: 50_000)) +let data = Data(("[" + Array(repeating: "null", count: 50_000).joined(separator: ",") + "]").utf8) +func lookups(_ scope: borrowing JSONCompositionScope, _ root: borrowing JSONCompositionRoot, + _ pointer: JSONPointer) throws -> Int { + for _ in 0..<1_000 { + let selected = try scope.resolve(pointer, in: root) + precondition(selected == .null) + } + return 1_000 +} +for parsed in [false, true] { + let report = try JSON.withComposition { scope in + let pointer = try scope.pointer(tokens: ["0"]) + if parsed { + return try scope.withParsedDocument(data) { document, root in + precondition(document.sourceBytes == data) + return try lookups(scope, root, pointer) + } + } + return try scope.withAdmittedRoot(value) { root in try lookups(scope, root, pointer) } + } + precondition(report.result == 1_000) + precondition(report.statistics[.nodes] == 51_001) + precondition(report.statistics[.workUnits] < 1_000_000) + precondition(report.statistics[.retainedBytes] < 6_000_000) + print("ADMITTED_ROOT_SCALE path=\(parsed ? "parsed" : "trusted") items=50000 bytes=\(data.count) refs=1000 nodes=\(report.statistics[.nodes]) work=\(report.statistics[.workUnits]) retained=\(report.statistics[.retainedBytes]) peak=\(report.statistics.peakLogicalRetainedBytes)") +} From 4ef59a5d30c4886aceda216c4a9f2fc46d2cdfb1 Mon Sep 17 00:00:00 2001 From: Thorsten Fuchs <76904008+ThorFuchs@users.noreply.github.com> Date: Thu, 15 Oct 2026 22:24:34 +0200 Subject: [PATCH 2/7] test: harden composition ownership compiler qualification --- Documentation/CI/README.md | 4 +-- Scripts/ci.py | 14 ++++++++++ Scripts/qualify_composition.py | 18 ++++++++----- Scripts/test_composition_compiler_harness.py | 26 +++++++++++++++---- .../JSON/Documentation.docc/Composition.md | 3 ++- .../Compiler/RootOnlyEscape.swift.txt | 8 ++++++ Tools/CompositionQualification/README.md | 7 ++--- 7 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 Tools/CompositionQualification/Compiler/RootOnlyEscape.swift.txt diff --git a/Documentation/CI/README.md b/Documentation/CI/README.md index dc246ef..f49389a 100644 --- a/Documentation/CI/README.md +++ b/Documentation/CI/README.md @@ -179,8 +179,8 @@ memory-safety compilation of JSON, and a distinct-package JSON/JSONSchema consum in both modes (four positive and six negative outcomes). A Release public consumer performs 1,000 resolutions over 50,000-value trusted and parsed roots under balanced limits. Eighteen compiler negatives require semantic diagnostics with no object or -compiler abort. Eight real call-site probes include three explicit-borrow positives -and five forms that expose current compiler aborts. Eight Python cases verify +compiler abort. Nine real call-site probes include three explicit-borrow positives +and six forms that expose current compiler aborts. Ten Python cases verify that signals, fatal diagnostics and missing imports cannot pass as rejections. All commands, nonzero exits, source hashes and outcomes remain in receipts. diff --git a/Scripts/ci.py b/Scripts/ci.py index 1eaf046..91ecdfa 100644 --- a/Scripts/ci.py +++ b/Scripts/ci.py @@ -311,6 +311,20 @@ def save(): save() else: receipt['status'] = 'passed' + if receipt['status'] == 'passed' and args.lane == 'composition': + try: + compiler_path = output / 'compiler-negative/receipt.json' + compiler = json.loads(compiler_path.read_text()) + if compiler['status'] != 'passed' or compiler['compiler_negative_cases'] != 18 or compiler['callsite_cases'] != 9: + raise ValueError('Missing composition compiler outcomes') + receipt['compiler_qualification'] = {'path': 'compiler-negative/receipt.json', + 'sha256': hashlib.sha256(compiler_path.read_bytes()).hexdigest(), + 'ownership_status': compiler['status'], 'robustness_status': compiler['compiler_robustness_status'], + 'compiler_abort_cases': compiler['compiler_abort_cases']} + receipt['behavior_status'] = 'passed' + if compiler['compiler_robustness_status'] == 'blocked': receipt['status'] = 'blocked' + except (OSError, KeyError, ValueError, TypeError) as error: + receipt['status'] = 'failed'; receipt['evidence_error'] = str(error) if receipt['status'] == 'passed' and args.lane in ('native', 'linux'): try: receipt['materialized_outcomes'] = materialized_outcomes(output) diff --git a/Scripts/qualify_composition.py b/Scripts/qualify_composition.py index 7fe98fb..1dfc2c6 100644 --- a/Scripts/qualify_composition.py +++ b/Scripts/qualify_composition.py @@ -1,10 +1,10 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: Apache-2.0 """Compiler-negative public composition ownership checks (object emission required).""" -import argparse, hashlib, json, pathlib, subprocess, tempfile +import argparse, hashlib, json, pathlib, re, subprocess, tempfile ROOT = pathlib.Path(__file__).resolve().parents[1] -def compiler_outcome(code, log, object_exists, diagnostic=None): +def compiler_outcome(code, log, object_exists, diagnostic=None, source_name=None): """An abort never establishes an expected ownership rejection.""" if 'no such module' in log: return 'failed' @@ -12,7 +12,11 @@ def compiler_outcome(code, log, object_exists, diagnostic=None): return 'compiler_abort' if not object_exists else 'failed' if diagnostic is None: return 'compiled' if code == 0 and object_exists else 'failed' - return 'rejected' if code > 0 and not object_exists and diagnostic in log else 'failed' + if code <= 0 or object_exists or source_name is None: + return 'failed' + source_error = re.compile( + r'^(?:.*[/\\])?' + re.escape(source_name) + r':\d+:\d+:\s+error:\s*(.*)$', re.MULTILINE) + return 'rejected' if any(diagnostic in message for message in source_error.findall(log)) else 'failed' def main(): parser = argparse.ArgumentParser(description=__doc__) @@ -45,18 +49,20 @@ def compile_case(name, folder, diagnostic): return dict(name=name, command=command, exit_code=run.returncode, source_sha256=hashlib.sha256(source.read_bytes()).hexdigest(), expected_diagnostic=diagnostic, - outcome=compiler_outcome(run.returncode, log, source.with_suffix('.o').exists(), diagnostic)) + outcome=compiler_outcome(run.returncode, log, source.with_suffix('.o').exists(), + diagnostic, source.name if diagnostic is not None else None)) for name, diagnostic in expected.items(): record = compile_case(name, 'Negative', diagnostic) record['status'] = 'passed' if record['outcome'] == 'rejected' else 'failed' records.append(record) for name, diagnostic in [('ClosureBorrow', None), ('RootClosureBorrow', None), ('ExplicitBorrowParameters', None), ('MethodEscape', 'borrowed'), ('ContainerEscape', 'borrowed'), - ('MethodBorrow', None), ('RootContainerEscape', 'borrowed'), ('LocalFunctionBorrow', None)]: + ('MethodBorrow', None), ('RootContainerEscape', 'borrowed'), ('LocalFunctionBorrow', None), + ('RootOnlyEscape', 'borrowed')]: record = compile_case(name, 'Compiler', diagnostic) # Preserve these known call-site compiler bugs separately. A newer # compiler may diagnose the escapes or compile the nonescaping use. - known_abort = name in {'MethodEscape', 'ContainerEscape', 'MethodBorrow', 'RootContainerEscape', 'LocalFunctionBorrow'} + known_abort = name in {'MethodEscape', 'ContainerEscape', 'MethodBorrow', 'RootContainerEscape', 'LocalFunctionBorrow', 'RootOnlyEscape'} record['status'] = ('blocked' if known_abort and record['outcome'] == 'compiler_abort' else 'passed' if record['outcome'] == ('compiled' if diagnostic is None else 'rejected') else 'failed') callsites.append(record) diff --git a/Scripts/test_composition_compiler_harness.py b/Scripts/test_composition_compiler_harness.py index 4d87cca..324190b 100644 --- a/Scripts/test_composition_compiler_harness.py +++ b/Scripts/test_composition_compiler_harness.py @@ -6,10 +6,25 @@ class CompilerHarnessTests(unittest.TestCase): def test_expected_rejection(self): - self.assertEqual(compiler_outcome(1, "error: borrowed", False, 'borrowed'), 'rejected') + log = "/tmp/swift-json/Escape.swift:2:17: error: 'scope' cannot be captured by an escaping closure since it is a borrowed parameter" + self.assertEqual(compiler_outcome(1, log, False, 'borrowed', 'Escape.swift'), 'rejected') + + def test_module_cache_keyword_is_not_an_ownership_rejection(self): + log = """:0: error: unable to open output file 'SwiftShims.pcm': 'Operation not permitted' +Swift.swiftinterface:5:8: error: could not build Objective-C module 'SwiftShims' +Swift.swiftinterface:3:1: note: compiler flags include -enable-experimental-feature BitwiseCopyable +""" + self.assertEqual(compiler_outcome(1, log, False, 'Copyable', 'RootCopy.swift'), 'failed') + + def test_expected_keyword_in_source_note_is_not_an_error(self): + log = """/tmp/RootCopy.swift:3:8: note: expected Copyable ownership rule +Swift.swiftinterface:3:1: note: BitwiseCopyable +""" + self.assertEqual(compiler_outcome(1, log, False, 'Copyable', 'RootCopy.swift'), 'failed') def test_missing_module_never_rejects(self): - self.assertEqual(compiler_outcome(1, "no such module JSON; borrowed", False, 'borrowed'), 'failed') + log = "/tmp/Escape.swift:2:17: error: no such module JSON; scope is borrowed" + self.assertEqual(compiler_outcome(1, log, False, 'borrowed', 'Escape.swift'), 'failed') def test_signal_is_not_rejection(self): self.assertEqual(compiler_outcome(-6, "borrowed", False, 'borrowed'), 'compiler_abort') @@ -28,11 +43,12 @@ def test_positive_requires_emission(self): self.assertEqual(compiler_outcome(0, '', False), 'failed') def test_unrelated_error_is_not_rejection(self): - self.assertEqual(compiler_outcome(1, "error: invalid syntax", False, 'borrowed'), 'failed') + log = "/tmp/Escape.swift:2:17: error: invalid syntax" + self.assertEqual(compiler_outcome(1, log, False, 'borrowed', 'Escape.swift'), 'failed') if __name__ == '__main__': suite = unittest.defaultTestLoader.loadTestsFromTestCase(CompilerHarnessTests) result = unittest.TextTestRunner().run(suite) - passed = result.wasSuccessful() and result.testsRun == 8 and not result.skipped - if passed: print('COMPOSITION_COMPILER_HARNESS passed cases=8') + passed = result.wasSuccessful() and result.testsRun == 10 and not result.skipped + if passed: print('COMPOSITION_COMPILER_HARNESS passed cases=10') raise SystemExit(0 if passed else 1) diff --git a/Sources/JSON/Documentation.docc/Composition.md b/Sources/JSON/Documentation.docc/Composition.md index bc0b7ff..e4b8332 100644 --- a/Sources/JSON/Documentation.docc/Composition.md +++ b/Sources/JSON/Documentation.docc/Composition.md @@ -83,7 +83,8 @@ identity or presumes a copy-on-write refund. The pinned Swift 6.4 compiler aborts for some implicit captures at actual callback call sites: returned bound methods, returned closure containers, a bound method -passed to a nonescaping helper and local functions implicitly capturing a scope. +passed to a nonescaping helper, local functions implicitly capturing a scope and +an escaping closure that captures only the borrowed root handle. Use explicit borrowing parameters for named helpers and explicit nonescaping closures, for example `try perform { try scope.checkpoint() }`, instead of a bound method reference. Qualification records aborts separately from semantic ownership rejections; an diff --git a/Tools/CompositionQualification/Compiler/RootOnlyEscape.swift.txt b/Tools/CompositionQualification/Compiler/RootOnlyEscape.swift.txt new file mode 100644 index 0000000..fd76db1 --- /dev/null +++ b/Tools/CompositionQualification/Compiler/RootOnlyEscape.swift.txt @@ -0,0 +1,8 @@ +import JSON +func inspect(_ root: borrowing JSONCompositionRoot) { } +struct Box { let action: () -> Void } +func escapedRoot() throws -> Box { + try JSON.withComposition { scope in + try scope.withAdmittedRoot(.null) { root in Box(action: { inspect(root) }) } + }.result +} diff --git a/Tools/CompositionQualification/README.md b/Tools/CompositionQualification/README.md index a03a520..c23cce0 100644 --- a/Tools/CompositionQualification/README.md +++ b/Tools/CompositionQualification/README.md @@ -27,9 +27,10 @@ The policy exposes no transferable owner token or refund. Borrowed root handles have no public constructor, value accessor or mutation; their private owner identity rejects use by another scope before navigation. -Eight additional actual-callsite probes include three explicit-borrow positives and -five forms exposing Swift 6.4 compiler aborts. Their outcomes are separate from -the 18 semantic rejections. Eight Python harness cases check the distinction. +Nine additional actual-callsite probes include three explicit-borrow positives and +six forms exposing Swift 6.4 compiler aborts, including a root-only escaping capture. +Their outcomes are separate from the 18 semantic rejections. Ten Python harness +cases check the distinction and reject setup-log keyword false positives. The lane completes its checks, then exits 2 with overall `blocked` if known compiler aborts reproduce. Successful behavior and ownership results are recorded alongside the compiler robustness blocker. Use explicit nonescaping closures in supported From 1f50b6409ce16e8d702b4467b08db45fc2c1f849 Mon Sep 17 00:00:00 2001 From: Thorsten Fuchs Date: Fri, 16 Oct 2026 00:57:51 +0200 Subject: [PATCH 3/7] docs: prepare Swift-JSON 1.6.0 release candidate --- CHANGELOG.md | 35 ++++++++---- .../Architecture/CompositionQualification.md | 53 ++++++++++++++----- Documentation/CI/README.md | 28 ++++++---- Documentation/CLI.md | 7 ++- .../Qualification/Release1.6.0/README.md | 35 ++++++++++++ README.md | 43 +++++++-------- Scripts/ci.py | 6 ++- Sources/JSONCLIEngine/CLIReleaseVersion.swift | 4 +- Tools/CompositionQualification/README.md | 6 +-- 9 files changed, 151 insertions(+), 66 deletions(-) create mode 100644 Documentation/Qualification/Release1.6.0/README.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 12b9cd6..9e3c103 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,30 @@ # Changelog -## Unreleased — next feature train +## 1.6.0 — 2026-10-16 +- Add bounded synchronous JSON composition with one cumulative work/retention + ledger, borrowed scope lifetime, cross-scope rejection and a scope-bound admitted + root. Trusted and source-parsed roots are admitted once; each selected output + remains charged. Preserve exact values, source snapshots, cancellation and + terminal owned failures. - Add structured JSONHTML layouts with finite string, color, declared raster, inline and atomic MathML previews; preserve exact source, complete export/print and shared - CLI policy. Native, browser and WASI evidence is recorded with remaining assistive - and host qualification boundaries. -- Forward-port the following 1.5.1 maintenance repairs. Development CLI metadata - is `1.6.0-dev` with a deterministic source digest; this is not a released version. - -### 1.5.1 maintenance repairs + CLI policy. Native, browser and WASI evidence retains its assistive and host + qualification boundaries. +- Carry forward the 1.5.1 diagnostic, regression-suite, CLI-identity and Git-free + archive repairs. The CLI reports `1.6.0` and a deterministic source digest. +- Composition qualification covers 20 core functions in Debug/Release/ASan, two + concurrent-scope functions under TSan, 18 semantic ownership rejections, nine + call-site probes and 1,000 selections from 50,000-value trusted and parsed roots. +- **Known compiler limitation:** six of the nine call-site forms abort Swift 6.4 + during compilation; the ownership harness records these as blocked, never as + successful rejections. The direct reference adapter still refuses the + `balanced-128-128` capacity target. The large-root consumer is synthetic and does + not qualify a complete Swift-OpenAPI importer, arbitrary callback instructions, + process RSS or broad application capacity. See the [composition qualification + record](Documentation/Qualification/Release1.6.0/README.md). + +## 1.5.1 — 2026-10-15 - Restore best-effort schema diagnostic omission without latching terminal failure; strict diagnostic, work, retention, annotation and cancellation errors still throw. @@ -19,7 +34,7 @@ - Replace stale CLI development metadata with an explicit version and reproducible source digest; preserve empty dependencies, all seven products and 49 core caps. - Reconcile README, support/platform guidance, release history and DocC navigation. - Structured HTML previews remain outside the separate 1.5.1 patch candidate. + Structured HTML previews shipped in 1.6.0. ## 1.5.0 — 2026-10-15 @@ -30,7 +45,7 @@ - Qualify native and ARM64/x86_64 Linux behavior/safety, source reproduction, public consumers and six DocC catalogues. Full CLI/WASI and Apple model helpers remain unqualified/unavailable. Frozen CLI metadata reports 1.4.0-dev/unknown, - explicitly disclosed in the release notes and repaired in the next candidate. + explicitly disclosed in the release notes and repaired in 1.5.1. ## 1.4.0 tag — 2026-10-15 @@ -85,7 +100,7 @@ Published from the separate 1.2 maintenance branch. Add 126 behavior/conformance functions, public integration and missing/corrupt-resource acceptance, complete coverage export and explicit performance disposition. Repair best-effort schema diagnostics and Git-free qualification identity. These two repairs and the added -suites were absent from 1.3.0 through 1.5.0; the 1.5.1 candidate restores them. +suites were absent from 1.3.0 through 1.5.0; the 1.5.1 release restores them. Historical qualification and performance receipts retain their original scope. ## 1.2.0 — 2026-10-13 diff --git a/Documentation/Architecture/CompositionQualification.md b/Documentation/Architecture/CompositionQualification.md index 47f77bc..a9271ff 100644 --- a/Documentation/Architecture/CompositionQualification.md +++ b/Documentation/Architecture/CompositionQualification.md @@ -50,6 +50,32 @@ characterization check verifies those outcomes; it does not turn the three incomplete imports into successes or establish arbitrary production capacity. The direct adapter's failed capacity target remains explicit. +## Admitted-root lookup path + +`withAdmittedRoot` admits one trusted immutable graph and lends a private, +noncopyable, non-Sendable handle for the synchronous callback. `withParsedDocument` +parses and admits its root on the same ledger without traversing that parsed root +again. The handle retains the exact snapshot and a private reference to its owner; +only that composition can resolve through it. Cross-scope use fails before +navigation. Root admission and the logical handle slot remain charged through +composition completion. + +Each Pointer and selected output still consumes work and retention. Selecting the +entire root with an empty Pointer therefore reserves the selected graph again. +The arbitrary-JSON overload retains conservative repeated admission. For a root +with N nodes and R small selections, the admitted-handle path changes root +admission from O(R × N) to O(N), plus Pointer navigation and each selected-output +graph. A 50,000-value trusted root and the same source-parsed root are each +resolved 1,000 times in the separate public consumer under balanced limits; its +work and retention receipts qualify that synthetic workload only. + +The public compiler probes also record supported explicit-borrow call sites and +known Swift 6.4 compiler aborts. Those aborts remain compiler-robustness blockers; +they are not counted as successful ownership rejections. The synthetic scale +consumer does not qualify a full Swift-OpenAPI importer, broad application +capacity, process RSS or callback instruction limits. The original direct +adapter's 128/128 balanced quota refusal remains in the record. + The adapter declares 64 logical bytes for its frame, 16 per output slot and a conservative 68 per descriptor (20 index-text bytes and three 16-byte input token slots). Staging adds one admitted input token slot. Reservations and work charges @@ -59,13 +85,14 @@ owned operation. Functional elapsed times do not establish throughput guarantees ## Execution and evidence -Run python3 Scripts/ci.py --lane composition on the supported native or Linux -runner. The lane requires 12 core functions in each build mode, separate public -consumers, five external Swift Testing functions in Debug/Release/ASan, all eight -scale cells and 11 compiler rejection cases. Exact module/cardinality checks -reject missing tests and misclassified resource failures. The reconciled 597 native / 581 -Linux root functions, 325 parameter invocations, restored identities and 49 public -metric probes retain their existing contracts. +Run `python3 Scripts/ci.py --lane composition` on the supported native or Linux +runner. The lane requires 20 core functions in Debug/Release/ASan, two TSan +concurrency functions, a strict-memory-safety build, distinct public consumers, +both 50,000-value admitted-root scale cases, all eight reference-adapter scale +cells, 18 semantic compiler rejections and nine actual call-site probes. Exact +module/cardinality checks reject missing tests and misclassified resource +failures. The current root function counts and 49 public metric probes are +recorded by `Documentation/Qualification/TestDiscovery.json`. The tests replay exact and one-below work/retention thresholds, compare both strategies on identical input, preserve exact values and scalar keys, and catch @@ -73,12 +100,12 @@ late missing-target/cancellation failures before attempting normal completion. Finalization must still throw the original native failure. Each report retains its actual source, environment, command exits, counts and input hashes. -CI runs the focused lane alongside the existing Native / native and both Linux -architecture jobs. Their names and protection rules remain unchanged. Sanitizer -and full-root lanes continue independently. Linux uses the existing Swift -Testing-only runner policy; no baseline is suppressed. +The full Native / native and Linux architecture lanes discover and run the new +root functions. The standalone composition lane adds the separate compiler +harness and adapter/scale consumers. Sanitizer and full-root lanes continue +independently. Linux uses the existing Swift Testing-only runner policy; no +baseline is suppressed. Controlled idle-host performance remains a separate gate using the unchanged 10% review trigger. Shared or busy-host timing cannot close it. Representative -application scale beyond these synthetic cells needs separate evaluation; no -downstream dependency adoption, merge or release follows automatically. +application scale beyond these synthetic cells needs separate evaluation. diff --git a/Documentation/CI/README.md b/Documentation/CI/README.md index f49389a..c41bd8d 100644 --- a/Documentation/CI/README.md +++ b/Documentation/CI/README.md @@ -173,23 +173,33 @@ observations remain separate from automated SDK/API and portable execution. ## Experimental composition lane -`python3 Scripts/ci.py --lane composition` executes 20 composition functions in +`python3 Scripts/ci.py --lane composition` runs 20 core composition functions in Debug, Release and ASan, two concurrent-invocation functions with TSan, strict -memory-safety compilation of JSON, and a distinct-package JSON/JSONSchema consumer -in both modes (four positive and six negative outcomes). A Release public consumer -performs 1,000 resolutions over 50,000-value trusted and parsed roots under balanced -limits. Eighteen compiler negatives require semantic diagnostics with no object or -compiler abort. Nine real call-site probes include three explicit-borrow positives -and six forms that expose current compiler aborts. Ten Python cases verify -that signals, fatal diagnostics and missing imports cannot pass as rejections. -All commands, nonzero exits, source hashes and outcomes remain in receipts. +memory-safety compilation of JSON, and distinct-package consumers. The public +consumer has four positive and six negative outcomes in both configurations. The +external reference adapter retains its five Debug/Release/ASan tests and eight +scale cells, including three explicit finite-quota refusals. A separate Release +consumer performs 1,000 resolutions over 50,000-value trusted and parsed roots +under balanced limits, checking the admitted-root path and per-selection accounting. + +Eighteen compiler ownership negatives require source-local diagnostics and no +object emission. Nine actual call-site probes include three borrowing positives +and six forms that expose current Swift 6.4 compiler aborts, including a root-only +escaping capture. Ten Python cases verify that module-cache false positives, +signals, fatal diagnostics and missing imports cannot pass as rejections. All +commands, nonzero exits, source hashes and outcomes remain in receipts. The lane runs every check before reporting compiler robustness. Reproduced known aborts set overall status `blocked` and exit 2 while `behavior_status` and the ownership rejection results remain explicit. A crash is never a semantic pass. This lane uses actual Linux preflight when invoked on Linux; no Linux success is inferred from macOS execution. It supplements full native, safety and docs lanes. +The focused lane also runs in the native and both Linux architecture workflows. On a CLT installation that does not discover TestingMacros, set `SWIFT_JSON_TESTING_PLUGIN_PATH` to the installed testing plugin directory; CI records the explicit `-plugin-path` arguments and preserves the original failure. No language, SDK, platform, discovery or sanitizer baseline changes. + +The full native/Linux behavior lanes discover and run the new root functions. +The standalone composition lane adds the independent public compiler harness, +reference-heavy adapter matrix and the large repeated-root consumer. diff --git a/Documentation/CLI.md b/Documentation/CLI.md index aca7cc6..cc5a8a8 100644 --- a/Documentation/CLI.md +++ b/Documentation/CLI.md @@ -47,16 +47,15 @@ source, compiler and architecture; library WASI results are a separate boundary. ## Version and source identity The frozen 1.5.0 executable reports `1.4.0-dev` and revision `unknown`; its release -notes disclose that limitation. The separate 1.5.1 maintenance candidate corrects it. This main-based forward-port -retains unreleased structured previews, so its explicit version is `1.6.0-dev`. -Both candidates use the same source-identity interface: +notes disclose that limitation. Swift-JSON 1.6.0 reports its explicit release +version and deterministic source digest. Both releases use the same source-identity interface: ```sh swift run swift-json --version swift run swift-json --version --json ``` -Human output identifies the candidate version. JSON adds `revisionKind` with value +Human output identifies the package version. JSON adds `revisionKind` with value `source-sha256`; `revision` is `sha256:` plus a lowercase 64-digit digest. This digest hashes the ordered content manifest for `Package.swift` and every file in `Sources`, excluding only generated `CLIBuildIdentity.swift`. The manifest uses diff --git a/Documentation/Qualification/Release1.6.0/README.md b/Documentation/Qualification/Release1.6.0/README.md new file mode 100644 index 0000000..cffd351 --- /dev/null +++ b/Documentation/Qualification/Release1.6.0/README.md @@ -0,0 +1,35 @@ +# Swift-JSON 1.6.0 qualification scope + +This release adds bounded synchronous composition with a borrowed, noncopyable, +non-Sendable scope handle and a scope-bound admitted-root handle. Root ownership is +retained through the callback; exact owner identity rejects cross-scope use before +navigation. A trusted graph and a parsed document root share one admission on the +same cumulative ledger. Selecting a root or subtree still reserves the logical +output graph, and monotone reservations keep aliases charged until completion. + +The focused native lane exercises 20 core functions in Debug, Release and ASan, +two concurrent-scope functions under TSan, strict-memory-safety compilation, public +consumers and external adapter fixtures. Its synthetic scale consumer resolves +1,000 pointers from 50,000-value trusted and parsed roots. This measures that +admitted-root lookup avoids repeated root admission; it does not establish protocol +conformance, arbitrary callback instruction limits, process RSS or broad application +capacity. The separate reference adapter still refuses its direct +`balanced-128-128` capacity target. + +Compiler ownership qualification includes 18 semantic-negative cases and nine +actual call-site forms. On Swift 6.4, six call-site probes currently abort the +compiler, including the root-only escaping capture. The classifier preserves those +as compiler-robustness blockers and does not count them as ownership rejections; +three supported borrowing call sites compile. This release therefore does not claim +that arbitrary closure/capture forms are compiler-robust. The package test and +consumer lanes pass independently of that compiler-robustness blocker. + +The Swift-OpenAPI package may pin this release and use the public composition API, +but a complete importer remains a separate downstream qualification. Its source +preservation, dialect behavior, complete cumulative accounting, first-error +behavior, usable-capacity goals, and live composed retention peak require their own +implementation and evidence. The synthetic consumer here does not close those C2 +gaps. + +Logical retained bytes are owned accounting quantities, not process RSS. Work units +describe owned operations, not arbitrary caller instructions or wall-clock limits. diff --git a/README.md b/README.md index b14fc75..c0fa2bb 100644 --- a/README.md +++ b/README.md @@ -17,16 +17,11 @@ Maintained by [Thorsten Fuchs](https://github.com/ThorFuchs). Swift-JSON follows semantic versioning. Use a released version and retain `Package.resolved` for reproducible builds; `main` tracks ongoing development. -This feature branch also contains an [opt-in structural traversal product candidate](Documentation/Architecture/StructuralIntelligence/N1Promotion.md). -It preserves the seven released products and proposes JSONNavigation as the eighth. -Merge and release remain human-gated; the [compiled traversal guide](Sources/JSONNavigation/Documentation.docc/Traversal.md) -describes its many-node scope, exact locations, finite accounting and coverage. - -Published **1.5.0** provides six libraries and the CLI. This development branch -retains main’s unreleased structured HTML previews and forward-ports the 1.5.1 -maintenance repairs: best-effort schema diagnostics, the complete 1.2.1 regression -suites and Git-free qualification. Its CLI identifies itself as `1.6.0-dev`; this -is not a published version. See the [repair record](Documentation/Qualification/Release1.5.1/README.md). +Published **1.6.0** provides seven libraries and the CLI. It adds bounded synchronous +JSON composition with scope-bound admitted roots and opt-in structural traversal, +ships structured HTML previews, and includes the 1.5.1 maintenance repairs. The +compiler robustness and downstream importer limits remain explicit in the +[release qualification record](Documentation/Qualification/Release1.6.0/README.md). ## Why Swift-JSON? @@ -71,13 +66,13 @@ Choose the products your application needs: | Product | Use it for | | --- | --- | -| **JSON** | Exact values, strict parsing/writing, native Codable, Pointer, presence, checked construction, source documents and diagnostics | +| **JSON** | Exact values, strict parsing/writing, native Codable, Pointer, presence, checked construction, source documents, diagnostics and bounded composition | | **JSONSchema** | Draft 2020-12 compilation/evaluation, offline registries, bounded regex, annotations and raw declaration inspection | | **JSONStreaming** | Pull syntax events and values, strict NDJSON, root-array elements and awaited output chunks | -| **JSONHTML** | Exact HTML and immutable exports since 1.3.0; structured forms/cards and bounded previews on unreleased main | +| **JSONHTML** | Exact HTML and immutable exports since 1.3.0; structured forms/cards and bounded previews since 1.6.0 | | **swift-json** | Bounded command-line JSON workflows (available since 1.5.0) | | **JSONBridges** | Opt-in native integer, Double and Foundation Decimal conversions (available in the 1.4.0 tag and 1.5.0 release) | -| **JSONNavigation** | Unreleased candidate: exact many-node DFS, physical/virtual scopes, finite metadata and explicit coverage | +| **JSONNavigation** | Opt-in exact many-node DFS, physical/virtual scopes, finite metadata and explicit coverage (available since 1.6.0) | | **JSONPatch** | Staged RFC 6902 JSON Patch and RFC 7396 Merge Patch | `JSONSchema`, `JSONStreaming`, `JSONPatch`, `JSONHTML` and opt-in `JSONBridges` build on `JSON`. The package-private @@ -101,7 +96,7 @@ and Embedded Swift hosting require separate qualification. Add the package to your `Package.swift`: ```swift -.package(url: "https://github.com/ThorFuchs/Swift-JSON.git", from: "1.5.0") +.package(url: "https://github.com/ThorFuchs/Swift-JSON.git", from: "1.6.0") ``` Then add products to your target dependencies: @@ -393,7 +388,7 @@ hard RSS or throughput guarantees. Read the [resource contract](Documentation/Ar [machine-readable profiles](Documentation/Architecture/ResourceProfiles.json) and [49-cap ownership matrix](Documentation/Qualification/LimitsMatrix.json). -## Standalone HTML (structured previews on unreleased main) +## Standalone HTML (structured previews since 1.6.0) `JSONHTML` presents the exact value as ordered object forms, indexed array cards and small scalar flow lists. The direct renderer defaults to interactive structured @@ -436,8 +431,8 @@ Read the [structured preview guide](Sources/JSONHTML/Documentation.docc/Structur [formatted syntax guide](Sources/JSONHTML/Documentation.docc/FormattedRendering.md), [prepared export guide](Sources/JSONHTML/Documentation.docc/PreparedExport.md) and [API/policy freeze](Documentation/Architecture/Release1.3/StructuredPreviews/APIAndPolicy.md). -The consolidated design revision is not a package release number. These structured -previews are on unreleased main; published 1.5.0 retains the prior renderer contract. +The consolidated design revision is not a package release number. Structured +previews are part of the 1.6.0 renderer contract. ## Documentation and examples @@ -448,10 +443,10 @@ Browse the [public documentation site](https://thorfuchs.github.io/Swift-JSON/): [JSONPatch](https://thorfuchs.github.io/Swift-JSON/JSONPatch/documentation/jsonpatch/), [JSONHTML](https://thorfuchs.github.io/Swift-JSON/JSONHTML/documentation/jsonhtml/) and [JSONBridges](https://thorfuchs.github.io/Swift-JSON/JSONBridges/documentation/jsonbridges/). -The site tracks `main` and publishes only after all four native CI lanes pass. -It includes unreleased APIs. For the exact released 1.5.0 interface, use its -[tagged source documentation](https://github.com/ThorFuchs/Swift-JSON/tree/1.5.0/Sources) -or its [compiled DocC asset](https://github.com/ThorFuchs/Swift-JSON/releases/tag/1.5.0). +The site tracks `main` and publishes only after the native CI lanes pass. +For the exact released 1.6.0 interface, use its +[tagged source documentation](https://github.com/ThorFuchs/Swift-JSON/tree/1.6.0/Sources) +or its compiled DocC asset from the [1.6.0 release](https://github.com/ThorFuchs/Swift-JSON/releases/tag/1.6.0). The [documentation index](Documentation/README.md) links the behavior contracts. The six DocC catalogs provide public API references, focused guides, parameter descriptions and failure @@ -552,9 +547,9 @@ See the [CLI reference](Documentation/Architecture/Release1.4/CLIReference.md), [integration contract](Documentation/Architecture/Release1.4/Integration.md) and [acceptance ledger](Documentation/Architecture/Release1.4/Acceptance.json). The frozen 1.5.0 CLI reports `1.4.0-dev` and revision `unknown`, as disclosed in -its release notes. This 1.5.1 candidate reports its actual candidate version and a -deterministic source digest; see the [CLI guide](Documentation/CLI.md). -Versioned release assets identify the exact qualified platform and source scope. +its release notes. Swift-JSON 1.6.0 reports its release version and a deterministic +source digest; see the [CLI guide](Documentation/CLI.md). Versioned release assets +identify the exact qualified platform and source scope. ### Offline provider fragments (available since 1.5.0) diff --git a/Scripts/ci.py b/Scripts/ci.py index 91ecdfa..06488e6 100644 --- a/Scripts/ci.py +++ b/Scripts/ci.py @@ -32,6 +32,10 @@ def commands(lane, output): ['swift', 'build', '--target', 'JSON', '--scratch-path', '.build/composition-strict', '-Xswiftc', '-strict-memory-safety', '-Xswiftc', '-warnings-as-errors'], ['swift', 'run', '--package-path', 'Tools/CompositionQualification', 'CompositionConsumer'], ['swift', 'run', '-c', 'release', '--package-path', 'Tools/CompositionQualification', 'CompositionConsumer'], + ['swift', 'test', '--package-path', 'Tools/CompositionQualification'], + ['swift', 'test', '-c', 'release', '--package-path', 'Tools/CompositionQualification'], + ['swift', 'test', '-c', 'release', '--sanitize', 'address', '--scratch-path', '.build/composition-address', '--package-path', 'Tools/CompositionQualification'], + ['python3', '-B', 'Scripts/qualify_composition_scale.py', '--output', str(output / 'scale')], ['swift', 'run', '-c', 'release', '--package-path', 'Tools/CompositionQualification', 'CompositionRootScale'], ['python3', '-B', 'Scripts/qualify_composition.py', '--output', str(output / 'compiler-negative')], ] @@ -171,7 +175,7 @@ def check_result(command, code, log, events=None): passed = code == 0 if events is not None: counts = events['bundle_counts'] if command[:2] == ['swift', 'test']: - expected = [DISCOVERY['composition_functions']] if 'composition|composed|caughtOperationalFailureCannotComplete' in command else [2] if 'composition.*IndependentScopesCanBeSharedAcrossTasks' in command else [88] if 'cli|sharedFilterPlan' in command else sorted(DISCOVERY['export_functions'].values()) if 'export|Export|apple' in command else [14] if 'Tools/WasmAudit' in command else sorted(DISCOVERY['qa_functions'].values()) if 'qa' in command else [7] if R0_TESTS in command else [3] if 'Tools/MCPReadiness' in command or 'Tools/MobileQualification' in command else [1] if 'Tools/Qualification' in command else sorted(SHARED_COUNTS.values()) if 'thread' in command else sorted(ROOT_COUNTS.values()) + expected = [DISCOVERY['composition_external_functions']] if 'Tools/CompositionQualification' in command else [DISCOVERY['composition_functions']] if 'composition|composed|caughtOperationalFailureCannotComplete' in command else [2] if 'composition.*IndependentScopesCanBeSharedAcrossTasks' in command else [88] if 'cli|sharedFilterPlan' in command else sorted(DISCOVERY['export_functions'].values()) if 'export|Export|apple' in command else [14] if 'Tools/WasmAudit' in command else sorted(DISCOVERY['qa_functions'].values()) if 'qa' in command else [7] if R0_TESTS in command else [3] if 'Tools/MCPReadiness' in command or 'Tools/MobileQualification' in command else [1] if 'Tools/Qualification' in command else sorted(SHARED_COUNTS.values()) if 'thread' in command else sorted(ROOT_COUNTS.values()) if 'navigation' in command: expected = [DISCOVERY['root_functions']['JSONNavigationTests']] if events is not None: diff --git a/Sources/JSONCLIEngine/CLIReleaseVersion.swift b/Sources/JSONCLIEngine/CLIReleaseVersion.swift index c80f417..21ea108 100644 --- a/Sources/JSONCLIEngine/CLIReleaseVersion.swift +++ b/Sources/JSONCLIEngine/CLIReleaseVersion.swift @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 -// Version of this unreleased main-based candidate. Publication is a separate action. +// Version reported by the 1.6.0 release executable. package enum CLIReleaseVersion { - package static let value = "1.6.0-dev" + package static let value = "1.6.0" } diff --git a/Tools/CompositionQualification/README.md b/Tools/CompositionQualification/README.md index c23cce0..a3c9fd8 100644 --- a/Tools/CompositionQualification/README.md +++ b/Tools/CompositionQualification/README.md @@ -46,8 +46,8 @@ Data parsing, Pointer construction/append/resolve and schema-only compilation. Build the identical source against each revision, then measure while builds and safety runs are idle. Timing samples are observations, separate from native logical work/retention counters; a noisy shared machine cannot establish a -controlled regression gate. No release or downstream pin change follows from -successful qualification. +controlled regression gate. They do not substitute for functional or ownership +qualification. The Data-document and Pointer timing workloads have no native public report; their raw zero counter placeholders mean unmeasured/N/A. Only byte-parser and schema-only @@ -59,7 +59,7 @@ placeholders must never establish measured counter equivalence. The separate fixture target and five Swift Testing functions cover exact scalar/number semantics, shared exact work/retention boundaries, late failure/cancellation and serial descriptor staging. Run the composition CI lane to execute both configurations, ASan, eight materialized scale cells -and all 11 compiler rejection cases. Five cells complete and three deliberately reach finite quotas; +and all 18 source-anchored compiler ownership rejections. Five cells complete and three deliberately reach finite quotas; those refusals remain operational errors. The initial direct 128/128 balanced capacity assumption failed and is preserved. Staging the reference array on the same scope qualifies that bounded target without changing core APIs or limits. See ../../Documentation/Architecture/CompositionQualification.md. From 8492151ff5c65231adeec9f31fdd51496e7ccc60 Mon Sep 17 00:00:00 2001 From: Thorsten Fuchs Date: Fri, 16 Oct 2026 01:28:33 +0200 Subject: [PATCH 4/7] docs: finalize Swift-JSON 1.6.0 release scope --- CHANGELOG.md | 12 ++----- .../Architecture/CompositionQualification.md | 4 +-- Documentation/Architecture/Linux.md | 13 ++------ Documentation/CI/README.md | 31 +++++++++---------- Documentation/CLI.md | 2 +- README.md | 18 +++++------ RELEASING.md | 2 +- Sources/JSONCLIEngine/CLIBuildIdentity.swift | 2 +- .../JSONHTML/Documentation.docc/JSONHTML.md | 7 ++--- Tests/JSONCLITests/IntegrationTests.swift | 2 +- 10 files changed, 39 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e3c103..3e2bf4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and atomic MathML previews; preserve exact source, complete export/print and shared CLI policy. Native, browser and WASI evidence retains its assistive and host qualification boundaries. +- Ship the opt-in JSONNavigation library for exact many-node DFS over canonical + documents, with typed locations, physical and virtual scopes, finite metadata, + explicit coverage and the existing cumulative resource contract. - Carry forward the 1.5.1 diagnostic, regression-suite, CLI-identity and Git-free archive repairs. The CLI reports `1.6.0` and a deterministic source digest. - Composition qualification covers 20 core functions in Debug/Release/ASan, two @@ -185,12 +188,3 @@ remain unselected; projection and RFC 7464 framing remain deferred. timing sleeps; retain an invocation-local package-only checkpoint observer. - Qualify twenty frozen explicitly rooted downstream schema vectors and public cumulative budgets in a separate consumer; no protocol/runtime dependency added. - -## Unreleased Navigation candidate - -- Propose opt-in JSONNavigation as an eighth SwiftPM product, preserving its56 - exact traversal declarations and cumulative resource semantics. -- Qualify a real external Debug/Release SwiftPM consumer and preserve source-first - error precedence with two explicit regressions. -- N2 inspection remains unimplemented: its separate borrowed-context compiler - proof is blocked. No version/tag/release or automatic merge is implied. diff --git a/Documentation/Architecture/CompositionQualification.md b/Documentation/Architecture/CompositionQualification.md index a9271ff..3608f75 100644 --- a/Documentation/Architecture/CompositionQualification.md +++ b/Documentation/Architecture/CompositionQualification.md @@ -3,8 +3,8 @@ The synchronous borrowed composition API is described in [Compose native operations](../../Sources/JSON/Documentation.docc/Composition.md). Its public surface and default profiles are unchanged by this qualification work. -The root dependency graph remains empty and the package retains the existing products and adds opt-in JSONNavigation after its -separate public-product gate. +The root dependency graph remains empty and JSONNavigation is available as an +opt-in product alongside the composition API. The separate [qualification package](../../Tools/CompositionQualification) exercises source-backed parsing, exact Pointer targets, URI identity and explicitly charged diff --git a/Documentation/Architecture/Linux.md b/Documentation/Architecture/Linux.md index 7948ead..8615c5d 100644 --- a/Documentation/Architecture/Linux.md +++ b/Documentation/Architecture/Linux.md @@ -1,21 +1,14 @@ -# N1 candidate platform scope - -This additive candidate proposes JSONNavigation as an eighth product (seven -libraries plus CLI), with no external dependencies. Its public SwiftPM consumer -and39 Navigation functions join the unchanged Linux lanes. Both actual ARM64 and -x86_64 full/safety receipts are required for final qualification. The historical -platform text below describes the original seven-product implementation. - # Linux platform contract -The six libraries and swift-json executable are qualified for 64-bit +Release 1.6.0 includes opt-in JSONNavigation alongside the six established +libraries. The seven libraries and swift-json executable are qualified for 64-bit Linux with Swift tools/compiler 6.4+ and Swift language mode 6. Initial execution qualification targets Ubuntu 24.04 with glibc on ARM64 and x86_64. A platform preflight identifies the actual runtime; cross-compilation alone cannot qualify behavior or safety. Architecture-specific receipts must pass before claiming that architecture qualified. Apple minimums remain macOS/SDK 27 and iOS/SDK 27. -The root manifest keeps an empty dependency graph and seven products. +The root manifest keeps an empty dependency graph and eight products. Apple PDF and native transfer APIs retain their platform availability; portable HTML has no WebKit requirement. Linux does not need a SwiftPM deployment-platform entry. Foundation file/resource diff --git a/Documentation/CI/README.md b/Documentation/CI/README.md index c41bd8d..c6b43c5 100644 --- a/Documentation/CI/README.md +++ b/Documentation/CI/README.md @@ -1,18 +1,17 @@ # Native CI -## Reconciled Navigation and composition increment - -Current source retains composition from main and adds the opt-in Navigation -product. The discovery contract requires 597 native functions, 581 Linux functions -and 493 WASI functions, including all 39 Navigation and 12 composition functions. -Parameterized inventories remain 325 native/Linux and 288 WASI. Shared-state -sanitizer expectations are 43 native and 42 Linux. All 126 restored maintenance -identities and all 49 public capacity probes remain mandatory. Full ASan uses the -current root inventory. Native has 33 commands, Linux 29; the separate composition -lane retains its nine commands, five external functions, eight capacity cells and -11 negative compiler cases. Navigation's focused lane retains five commands. -Seven public library DocC catalogues include Navigation. These are acceptance -expectations; source-bound receipts establish actual execution outcomes. +## Current release source + +Current source includes the bounded composition API and the opt-in JSONNavigation +product. The discovery contract requires 605 native functions, 589 Linux functions +and 581 WASI functions, including 39 Navigation and 20 composition functions. +Parameterized inventories remain 325 native/Linux and 288 WASI. All 126 restored +maintenance identities and 49 public capacity probes remain mandatory. Full ASan +uses the current root inventory. Native has 33 commands, Linux 29; the focused +composition lane has 16 commands, five external adapter functions, eight capacity +cells and 18 semantic-negative compiler cases. Navigation's focused lane retains +five commands. Seven public library DocC catalogues include Navigation. These are +acceptance expectations; source-bound receipts establish actual execution outcomes. The following dated sections retain their original source context. @@ -65,7 +64,7 @@ are recorded; macOS/SDK 27 and Swift 6.4 remain minimums. Pushes to main, pull requests and manual dispatch run four lanes: - Native: public inventory, manifest/dependency graph, release build, debug and - release Swift Testing, six-library example, rooted JSON/JSONSchema consumer, + release Swift Testing, seven-library example, rooted JSON/JSONSchema consumer, public cap tests and pinned independent suites under an external timeout. - Safety: full Address Sanitizer tests, targeted shared-state Thread Sanitizer tests, and strict memory safety compilation with warnings as errors. @@ -74,7 +73,7 @@ Pushes to main, pull requests and manual dispatch run four lanes: after execution. The extracted receipt must have null Git identity and the same complete source manifest. - Documentation: public symbol graphs, complete authored API/parameter comments, - executed README examples, six native DocC catalogs with warnings as errors, + executed README examples, seven native DocC catalogs with warnings as errors, native static-hosting transforms and site route/asset checks. Actions are pinned by commit. Jobs have read-only repository permissions and @@ -171,7 +170,7 @@ remain required. The first failed inherited expectations are retained; no blanke nonzero/exit-zero replacement is used. Real receiving-app and physical-device UI observations remain separate from automated SDK/API and portable execution. -## Experimental composition lane +## Composition qualification lane `python3 Scripts/ci.py --lane composition` runs 20 core composition functions in Debug, Release and ASan, two concurrent-invocation functions with TSan, strict diff --git a/Documentation/CLI.md b/Documentation/CLI.md index cc5a8a8..8e26b06 100644 --- a/Documentation/CLI.md +++ b/Documentation/CLI.md @@ -1,6 +1,6 @@ # Command-line workflows -The `swift-json` executable ships with the six libraries from 1.5.0. It uses the +The `swift-json` executable ships with the seven libraries in 1.6.0. It uses the same exact decimal/scalar model, strict grammar, explicit offline schema resources and finite cumulative limits. It has no network provider, shell filter or universal jq compatibility claim. diff --git a/README.md b/README.md index c0fa2bb..c92f997 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ Choose the products your application needs: SwiftPM dependency graph is empty. Qualification and benchmark tools are separate packages. -Linux supports the six libraries and CLI with portable schema integrity +Linux supports the seven libraries and CLI with portable schema integrity without runtime dependencies. Its initial qualification scope is Swift 6.4+, 64-bit Ubuntu 24.04/glibc; see the [Linux contract](Documentation/Architecture/Linux.md) for execution gates and limits. Apple platform requirements remain unchanged. @@ -448,11 +448,11 @@ For the exact released 1.6.0 interface, use its [tagged source documentation](https://github.com/ThorFuchs/Swift-JSON/tree/1.6.0/Sources) or its compiled DocC asset from the [1.6.0 release](https://github.com/ThorFuchs/Swift-JSON/releases/tag/1.6.0). -The [documentation index](Documentation/README.md) links the behavior contracts. The six DocC catalogs +The [documentation index](Documentation/README.md) links the behavior contracts. The seven DocC catalogs provide public API references, focused guides, parameter descriptions and failure contracts, compiled from the native Swift public symbol graphs. -Build all seven candidate catalogs on a supported native host: +Build all seven release catalogs on a supported native host: ```sh python3 Scripts/ci.py --lane docs @@ -505,7 +505,7 @@ inputs retain their applicable [notices](NOTICE), [third-party notices](THIRD_PA ## Command-line tool (released in 1.5.0) -`swift-json` accompanies the six libraries. It provides strict formatting, validation, Pointer selection, staged +`swift-json` accompanies the seven libraries. It provides strict formatting, validation, Pointer selection, staged Patch and qualified HTML/text/Markdown rendering. See the [CLI plan](Documentation/Architecture/Release1.4/Plan.md) and [foundation contract](Documentation/Architecture/Release1.4/Foundation.md) for command semantics, cumulative budgets and qualification boundaries. The pull @@ -525,7 +525,7 @@ swift build -c release --product swift-json ### Run exact pull queries -The package has six libraries plus the executable, with no external root +The package has seven libraries plus the executable, with no external root dependencies. Build the selected source version with Swift6.4+ (`swift build -c release --product swift-json`), or use `swift run swift-json help`. Native qualification requires macOS/SDK27+. @@ -561,14 +561,14 @@ Incompatibility exits1; operational errors remain errors. Apple schema/model bri See the [provider contract](Documentation/Architecture/Release1.4/Providers.md) and [compiled public consumer](Tools/CLIQualification/Sources/ProviderConsumer/Main.swift). -## Exact structural navigation (unreleased candidate) +## Exact structural navigation (released in 1.6.0) `JSONNavigation` adds many-node DFS preorder over a captured canonical document, with insertion-order object members, increasing array indices and exact typed locations. Physical and virtual scopes, explicit overlap/stop/pruning policies, bounded metadata collection and coverage share one finite cumulative core budget. -Add the JSONNavigation product and import it explicitly. Existing one-node reads +Import the opt-in JSONNavigation product explicitly. Existing one-node reads remain in JSON. Full source admission precedes traversal option validation. See the [compiled traversal guide](Sources/JSONNavigation/Documentation.docc/Traversal.md) -and [real external SwiftPM consumer](Tools/NavigationQualification). This branch -prepares eight products; published 1.5.0 and its seven-product contract are unchanged. +and [real external SwiftPM consumer](Tools/NavigationQualification). Release 1.6.0 +contains seven libraries plus the executable. diff --git a/RELEASING.md b/RELEASING.md index 9da10da..8f7d95b 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -7,7 +7,7 @@ or releases. Published version tags are protected against updates and deletion. 1. Require passed native, safety, documentation and Git-free archive lanes for the exact candidate commit on macOS/SDK 27+ and Swift 6.4+ with language mode 6. Retain both ARM64 and x86_64 Linux behavior/safety receipts for portable changes. -2. Review seven public products (six libraries, including opt-in JSONBridges, plus swift-json), the empty root dependency graph, compiled external +2. Review eight public products (seven libraries, including opt-in JSONBridges and JSONNavigation, plus swift-json), the empty root dependency graph, compiled external consumers, populated pinned suites, policy exclusions, all 49 finite caps, schema/regex behavior and cancellation boundaries. 3. Review licenses, provenance, public file inventory and documentation links. diff --git a/Sources/JSONCLIEngine/CLIBuildIdentity.swift b/Sources/JSONCLIEngine/CLIBuildIdentity.swift index c1d9c13..432e422 100644 --- a/Sources/JSONCLIEngine/CLIBuildIdentity.swift +++ b/Sources/JSONCLIEngine/CLIBuildIdentity.swift @@ -2,6 +2,6 @@ // Generated by Scripts/generate_cli_identity.py; excludes this file. // SHA-256 of the ordered Package.swift + Sources content manifest, not a Git commit. package enum CLIBuildIdentity { - package static let revision = "sha256:bba3e1b374e88d3df8fe4fd5e58423bdfb8982a085754f2d5ad6813830da83db" + package static let revision = "sha256:b29fe25e05a355719dd1a8a0528618d6463ac48e0d0dd5426f7bec1ae6ac9fe6" package static let kind = "source-sha256" } diff --git a/Sources/JSONHTML/Documentation.docc/JSONHTML.md b/Sources/JSONHTML/Documentation.docc/JSONHTML.md index 5f3bb99..93461c8 100644 --- a/Sources/JSONHTML/Documentation.docc/JSONHTML.md +++ b/Sources/JSONHTML/Documentation.docc/JSONHTML.md @@ -2,8 +2,8 @@ Exact JSON as structured forms/cards or highlighted syntax in a standalone HTML document. -``JSONHTMLRenderer`` defaults to interactive structured inspection on unreleased -main. Object fields, indexed arrays, scalar previews and native disclosures retain +``JSONHTMLRenderer`` defaults to interactive structured inspection since 1.6.0. +Object fields, indexed arrays, scalar previews and native disclosures retain insertion order, decoded Unicode scalar identity and exact numeric lexemes. An explicit syntax layout uses the shared strict writer's token cursor. Generated markup is owned and allowlisted; arbitrary input is escaped, never trusted as HTML. @@ -12,8 +12,7 @@ Inspection prefixes are labelled, and full originals/source remain accessible without JavaScript. Finite color, declared raster, inline formatting and atomic mini-math previews preserve unsupported spans literally. Exact JSON/Pointer copy, downloads and complete printing use native prepared bytes. See . -These structured previews extend the renderer released in 1.3.0 and are not part -of the published 1.5.0 behavior. +These structured previews extend the renderer released in 1.3.0. Native JSON transfer and immutable prepared JSON/text/Markdown/static HTML, opt-in styled RTF and explicit main-actor PDF preparation are available since diff --git a/Tests/JSONCLITests/IntegrationTests.swift b/Tests/JSONCLITests/IntegrationTests.swift index 9fa5e03..c59d480 100644 --- a/Tests/JSONCLITests/IntegrationTests.swift +++ b/Tests/JSONCLITests/IntegrationTests.swift @@ -146,7 +146,7 @@ private func integrationDirectory() throws -> URL { @Test func cliVersionIsDeterministicAndNeedsNoRepositoryOrInput() throws { let metadata = try JSONParser().parse(CLIHelp.versionJSON) - #expect(try metadata.requiredMember("version") == .string("1.6.0-dev")) + #expect(try metadata.requiredMember("version") == .string("1.6.0")) #expect(try metadata.requiredMember("revisionKind") == .string("source-sha256")) let revision = try #require(try metadata.requiredMember("revision").stringValue) #expect(revision.hasPrefix("sha256:") && revision.utf8.count == 71) From b077841747211ae3ff9d343fa61f4a02a107a5d9 Mon Sep 17 00:00:00 2001 From: Thorsten Fuchs Date: Fri, 16 Oct 2026 01:42:35 +0200 Subject: [PATCH 5/7] ci: release TSan scratch before strict build --- Scripts/ci.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Scripts/ci.py b/Scripts/ci.py index 06488e6..7d7dcb1 100644 --- a/Scripts/ci.py +++ b/Scripts/ci.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: Apache-2.0 """Execute public native CI lanes with command, source and environment receipts.""" -import argparse, datetime, hashlib, json, os, pathlib, re, subprocess, sys +import argparse, datetime, hashlib, json, os, pathlib, re, shutil, subprocess, sys from archive_candidate import files from preflight import collect, collect_linux from testing_events import read_events, ROOT_PARAMETER_CASES @@ -313,6 +313,9 @@ def save(): receipt['status'] = 'blocked' if args.lane == 'browser' and code == 2 else 'failed' break save() + if args.lane == 'composition' and '--sanitize' in command and 'thread' in command: + # This dedicated TSan tree is no longer needed once its event receipt is saved. + shutil.rmtree(ROOT / '.build/composition-thread', ignore_errors=True) else: receipt['status'] = 'passed' if receipt['status'] == 'passed' and args.lane == 'composition': From 864e033f00df2ca3549f3a77f0ab553ab2030e98 Mon Sep 17 00:00:00 2001 From: Thorsten Fuchs Date: Fri, 16 Oct 2026 12:05:01 +0200 Subject: [PATCH 6/7] fix: declare composition borrows and isolate compiler capture failures --- CHANGELOG.md | 10 +-- .../Architecture/CompositionCompiler.md | 67 +++++++++++++++++++ .../Architecture/CompositionQualification.md | 6 +- .../Architecture/ExtractionManifest.json | 2 +- Documentation/CI/README.md | 22 +++--- .../Qualification/Release1.6.0/README.md | 17 +++-- Scripts/ci.py | 9 ++- Scripts/qualify_composition.py | 43 ++++++++---- Scripts/test_composition_compiler_harness.py | 26 ++++++- .../JSON/Documentation.docc/Composition.md | 28 +++++--- .../JSON/Limits/JSONCompositionScope.swift | 32 ++++----- Sources/JSONCLIEngine/CLIBuildIdentity.swift | 2 +- .../Document/JSONCompositionScope+URI.swift | 4 +- .../ExplicitContainerEscape.swift.txt | 5 ++ .../ExplicitLocalFunctionBorrow.swift.txt | 7 ++ .../ExplicitMethodClosureBorrow.swift.txt | 7 ++ .../ExplicitRootContainerEscape.swift.txt | 10 +++ .../Compiler/ExplicitRootOnlyEscape.swift.txt | 8 +++ .../ExplicitCapture.swift.txt | 10 +++ .../ExplicitLocalFunction.swift.txt | 12 ++++ .../ImplicitCapture.swift.txt | 10 +++ .../ImplicitLocalFunction.swift.txt | 12 ++++ .../CompilerReproductions/README.md | 18 +++++ Tools/CompositionQualification/README.md | 22 +++--- 24 files changed, 313 insertions(+), 76 deletions(-) create mode 100644 Documentation/Architecture/CompositionCompiler.md create mode 100644 Tools/CompositionQualification/Compiler/ExplicitContainerEscape.swift.txt create mode 100644 Tools/CompositionQualification/Compiler/ExplicitLocalFunctionBorrow.swift.txt create mode 100644 Tools/CompositionQualification/Compiler/ExplicitMethodClosureBorrow.swift.txt create mode 100644 Tools/CompositionQualification/Compiler/ExplicitRootContainerEscape.swift.txt create mode 100644 Tools/CompositionQualification/Compiler/ExplicitRootOnlyEscape.swift.txt create mode 100644 Tools/CompositionQualification/CompilerReproductions/ExplicitCapture.swift.txt create mode 100644 Tools/CompositionQualification/CompilerReproductions/ExplicitLocalFunction.swift.txt create mode 100644 Tools/CompositionQualification/CompilerReproductions/ImplicitCapture.swift.txt create mode 100644 Tools/CompositionQualification/CompilerReproductions/ImplicitLocalFunction.swift.txt create mode 100644 Tools/CompositionQualification/CompilerReproductions/README.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e2bf4e..a1a511f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,11 +17,13 @@ - Carry forward the 1.5.1 diagnostic, regression-suite, CLI-identity and Git-free archive repairs. The CLI reports `1.6.0` and a deterministic source digest. - Composition qualification covers 20 core functions in Debug/Release/ASan, two - concurrent-scope functions under TSan, 18 semantic ownership rejections, nine + concurrent-scope functions under TSan, 18 semantic ownership rejections, 14 call-site probes and 1,000 selections from 50,000-value trusted and parsed roots. -- **Known compiler limitation:** six of the nine call-site forms abort Swift 6.4 - during compilation; the ownership harness records these as blocked, never as - successful rejections. The direct reference adapter still refuses the +- **Known compiler limitation:** four inferred call-site forms still abort Swift + 6.4. Explicit borrowing methods prevent two bound-method aborts, but the + nonescaping bound-method positive remains unsupported. Five new explicit + callback-parameter probes verify a source workaround. The original failures + remain blocked, never counted as successful rejections. The direct reference adapter still refuses the `balanced-128-128` capacity target. The large-root consumer is synthetic and does not qualify a complete Swift-OpenAPI importer, arbitrary callback instructions, process RSS or broad application capacity. See the [composition qualification diff --git a/Documentation/Architecture/CompositionCompiler.md b/Documentation/Architecture/CompositionCompiler.md new file mode 100644 index 0000000..f77047b --- /dev/null +++ b/Documentation/Architecture/CompositionCompiler.md @@ -0,0 +1,67 @@ +# Composition compiler diagnosis + +Swift 6.4 aborts in `SILGenCleanup` when some implicitly named callback parameters +of noncopyable type are captured. The contextual function type says `borrowing`, +but the generated SIL attempts `copy_addr` on a value marked +`mark_unresolved_non_copyable_value [no_consume_or_assign]`. The ownership verifier +aborts before an ordinary ownership diagnostic can be emitted. JSON values, +resource accounting, Foundation and the private owner reference are not required +to reproduce this defect. + +The [standalone reductions](../../Tools/CompositionQualification/CompilerReproductions) +use an empty noncopyable `Handle`, a borrowing callback and either an escaping +capture or a synchronous local function. The inferred parameter forms abort; +spelling `(handle: borrowing Handle)` makes the escape produce a normal diagnostic +and makes the synchronous local function compile. The original inferred public +API fixtures remain in the qualification gate. + +## Library repair and supported spelling + +Every composition instance method now explicitly declares `borrowing`. This +preserves the existing ownership convention and prevents the two bound-method +probes from aborting. `MethodEscape` receives the expected borrowed-self diagnostic. +`MethodBorrow` also receives a borrowed-self diagnostic even though its callee is +nonescaping. Its original positive expectation is retained as an unsupported +compiler call site; a diagnostic does not turn that requirement into a pass. +Use a closure literal instead of a bound method value. + +Explicit callback parameter ownership avoids the other capture-lowering defect: + +```swift +try JSON.withComposition { (scope: borrowing JSONCompositionScope) in + try scope.withAdmittedRoot(value) { (root: borrowing JSONCompositionRoot) in + let pointer = try scope.pointer(tokens: ["name"]) + return try scope.resolve(pointer, in: root) + } +} +``` + +Five additional public probes exercise explicit ownership: three invalid escapes +must produce source-backed borrowed-parameter errors, while a local function and +a closure-literal method call must emit objects. They supplement the original +nine call sites and 18 semantic-negative programs. + +Swift emits a bound method's primary borrowed-self error at `:0`, with +the actual expression in a source note. Only the two bound-method fixtures opt +into that diagnostic shape. Classification requires the exact primary error and +the matching fixture's `closure capturing 'self' here` note. A setup error, a note +from another file, an object emitted for a negative program, or an abort cannot +satisfy the ownership rejection requirement. + +## Ownership boundary + +The public callback conventions remain borrowed. Scope and root types remain +noncopyable and non-Sendable; private owner identity, cumulative accounting, +selected-output reservations and terminal failures are unchanged. No compiler +feature flag or unsafe annotation is introduced. + +Trials with owning callbacks or copyable facades are excluded from the repair. +Owning callbacks allowed a local scope to be moved, swapped with a nested +invocation and restored. That would reopen the accounting substitution boundary. +Adding nonescapability to borrowed noncopyable callbacks alone did not eliminate +the compiler abort. These alternatives cannot replace the current guarantees. + +The remaining inferred captures still require an upstream compiler correction. +The gate stays blocked on those aborts and the unsupported bound-method positive; +the explicit spelling is a source workaround, not a claim that the compiler gate +has passed. diff --git a/Documentation/Architecture/CompositionQualification.md b/Documentation/Architecture/CompositionQualification.md index 3608f75..3598aec 100644 --- a/Documentation/Architecture/CompositionQualification.md +++ b/Documentation/Architecture/CompositionQualification.md @@ -71,7 +71,9 @@ work and retention receipts qualify that synthetic workload only. The public compiler probes also record supported explicit-borrow call sites and known Swift 6.4 compiler aborts. Those aborts remain compiler-robustness blockers; -they are not counted as successful ownership rejections. The synthetic scale +they are not counted as successful ownership rejections. Explicit borrowing +methods and callback-parameter counterparts isolate the remaining capture-lowering +defect; see the [compiler diagnosis](CompositionCompiler.md). The synthetic scale consumer does not qualify a full Swift-OpenAPI importer, broad application capacity, process RSS or callback instruction limits. The original direct adapter's 128/128 balanced quota refusal remains in the record. @@ -89,7 +91,7 @@ Run `python3 Scripts/ci.py --lane composition` on the supported native or Linux runner. The lane requires 20 core functions in Debug/Release/ASan, two TSan concurrency functions, a strict-memory-safety build, distinct public consumers, both 50,000-value admitted-root scale cases, all eight reference-adapter scale -cells, 18 semantic compiler rejections and nine actual call-site probes. Exact +cells, 18 semantic compiler rejections and 14 actual call-site probes. Exact module/cardinality checks reject missing tests and misclassified resource failures. The current root function counts and 49 public metric probes are recorded by `Documentation/Qualification/TestDiscovery.json`. diff --git a/Documentation/Architecture/ExtractionManifest.json b/Documentation/Architecture/ExtractionManifest.json index d5ec001..47a5840 100644 --- a/Documentation/Architecture/ExtractionManifest.json +++ b/Documentation/Architecture/ExtractionManifest.json @@ -278,7 +278,7 @@ "license": "Apache-2.0", "adapted_third_party_code": false, "basis": "Independent ownership and repeated-admission review of 720da596; private review evidence excluded from source distribution.", - "scope": "Borrowed immutable admitted-root handles, private invocation identity, conservative selected-output reservations, boundary and scale consumers, compiler-callsite regressions and explicit compiler-abort classification. No root dependency or unsafe annotation added." + "scope": "Borrowed immutable admitted-root handles, private invocation identity, conservative selected-output reservations, boundary and scale consumers, compiler-callsite regressions, explicit borrowing method declarations, standalone compiler reductions and source-anchored compiler-abort/unsupported-callsite classification. No root dependency or unsafe annotation added." }, "jsonhtml_export_original_contributions": { "license": "Apache-2.0", diff --git a/Documentation/CI/README.md b/Documentation/CI/README.md index c6b43c5..c1643e8 100644 --- a/Documentation/CI/README.md +++ b/Documentation/CI/README.md @@ -182,15 +182,19 @@ consumer performs 1,000 resolutions over 50,000-value trusted and parsed roots under balanced limits, checking the admitted-root path and per-selection accounting. Eighteen compiler ownership negatives require source-local diagnostics and no -object emission. Nine actual call-site probes include three borrowing positives -and six forms that expose current Swift 6.4 compiler aborts, including a root-only -escaping capture. Ten Python cases verify that module-cache false positives, -signals, fatal diagnostics and missing imports cannot pass as rejections. All -commands, nonzero exits, source hashes and outcomes remain in receipts. - -The lane runs every check before reporting compiler robustness. Reproduced known -aborts set overall status `blocked` and exit 2 while `behavior_status` and the -ownership rejection results remain explicit. A crash is never a semantic pass. +object emission. Fourteen actual call-site probes retain the original nine and +add five explicit-parameter counterparts. Four inferred captures still abort +Swift 6.4. Explicit borrowing methods produce ordinary borrowed-self diagnostics +for the two bound-method cases; the nonescaping bound-method positive remains +unsupported rather than counted as a pass. Fourteen Python cases reject setup-log +false positives and require an exact primary error/source-note pair for implicit +self diagnostics. Commands, nonzero exits, source hashes and outcomes remain in +receipts. See the [compiler diagnosis](../Architecture/CompositionCompiler.md). + +The lane runs every check before reporting compiler robustness. Known aborts and +unsupported positive call sites set overall status `blocked` and exit 2, while +`behavior_status` and ownership rejection results remain explicit. A crash or +rejected positive is never a semantic pass. This lane uses actual Linux preflight when invoked on Linux; no Linux success is inferred from macOS execution. It supplements full native, safety and docs lanes. The focused lane also runs in the native and both Linux architecture workflows. diff --git a/Documentation/Qualification/Release1.6.0/README.md b/Documentation/Qualification/Release1.6.0/README.md index cffd351..bd9b1b4 100644 --- a/Documentation/Qualification/Release1.6.0/README.md +++ b/Documentation/Qualification/Release1.6.0/README.md @@ -16,13 +16,16 @@ conformance, arbitrary callback instruction limits, process RSS or broad applica capacity. The separate reference adapter still refuses its direct `balanced-128-128` capacity target. -Compiler ownership qualification includes 18 semantic-negative cases and nine -actual call-site forms. On Swift 6.4, six call-site probes currently abort the -compiler, including the root-only escaping capture. The classifier preserves those -as compiler-robustness blockers and does not count them as ownership rejections; -three supported borrowing call sites compile. This release therefore does not claim -that arbitrary closure/capture forms are compiler-robust. The package test and -consumer lanes pass independently of that compiler-robustness blocker. +Compiler ownership qualification includes 18 semantic-negative cases and 14 +actual call-site forms. Explicit borrowing method declarations prevent two +Swift 6.4 aborts: the bound-method escape is correctly rejected, while the +nonescaping bound-method positive remains unsupported. Four original inferred +capture forms still abort, including the root-only escaping capture. Five added +explicit-parameter counterparts verify ordinary invalid-capture diagnostics and +supported local-function/closure-literal helpers. The original positive +requirements and all inferred crash cases remain in the gate. Compiler robustness +is still blocked; package tests and consumers pass independently. See the +[compiler diagnosis](../../Architecture/CompositionCompiler.md). The Swift-OpenAPI package may pin this release and use the public composition API, but a complete importer remains a separate downstream qualification. Its source diff --git a/Scripts/ci.py b/Scripts/ci.py index 7d7dcb1..9a0d9ad 100644 --- a/Scripts/ci.py +++ b/Scripts/ci.py @@ -229,7 +229,7 @@ def check_result(command, code, log, events=None): cases = re.findall(r'^ADMITTED_ROOT_SCALE path=(trusted|parsed) items=50000 bytes=250001 refs=1000 nodes=51001 work=([1-9][0-9]*) retained=([1-9][0-9]*) peak=([1-9][0-9]*)$', log, re.MULTILINE) passed = passed and len(cases) == 2 and {c[0] for c in cases} == {'trusted', 'parsed'} and all(int(c[1]) < 1_000_000 and int(c[2]) < 6_000_000 for c in cases) if 'Scripts/test_composition_compiler_harness.py' in command: - passed = passed and 'COMPOSITION_COMPILER_HARNESS passed cases=10' in log.splitlines() + passed = passed and 'COMPOSITION_COMPILER_HARNESS passed cases=14' in log.splitlines() if command[:2] == ['swift', 'test'] and 'Tools/CompositionQualification' in command and events is not None: passed = passed and events['module_function_counts'] == {'CompositionScaleTests': DISCOVERY['composition_external_functions']} and events['parameter_case_invocations'] == 0 if command[:2] == ['swift', 'run'] and 'ProviderConsumer' in command: @@ -322,12 +322,13 @@ def save(): try: compiler_path = output / 'compiler-negative/receipt.json' compiler = json.loads(compiler_path.read_text()) - if compiler['status'] != 'passed' or compiler['compiler_negative_cases'] != 18 or compiler['callsite_cases'] != 9: + if compiler['status'] != 'passed' or compiler['compiler_negative_cases'] != 18 or compiler['callsite_cases'] != 14: raise ValueError('Missing composition compiler outcomes') receipt['compiler_qualification'] = {'path': 'compiler-negative/receipt.json', 'sha256': hashlib.sha256(compiler_path.read_bytes()).hexdigest(), 'ownership_status': compiler['status'], 'robustness_status': compiler['compiler_robustness_status'], - 'compiler_abort_cases': compiler['compiler_abort_cases']} + 'compiler_abort_cases': compiler['compiler_abort_cases'], + 'unsupported_callsite_cases': compiler['unsupported_callsite_cases']} receipt['behavior_status'] = 'passed' if compiler['compiler_robustness_status'] == 'blocked': receipt['status'] = 'blocked' except (OSError, KeyError, ValueError, TypeError) as error: @@ -380,6 +381,8 @@ def save(): receipt['status'] = 'failed' receipt['finished_utc'] = datetime.datetime.now(datetime.timezone.utc).isoformat() save() + if args.lane == 'composition' and receipt['status'] == 'blocked': + return 2 return 0 if receipt['status'] == 'passed' else 1 if __name__ == '__main__': diff --git a/Scripts/qualify_composition.py b/Scripts/qualify_composition.py index 1dfc2c6..c769af3 100644 --- a/Scripts/qualify_composition.py +++ b/Scripts/qualify_composition.py @@ -4,19 +4,31 @@ import argparse, hashlib, json, pathlib, re, subprocess, tempfile ROOT = pathlib.Path(__file__).resolve().parents[1] -def compiler_outcome(code, log, object_exists, diagnostic=None, source_name=None): +def compiler_outcome(code, log, object_exists, diagnostic=None, source_name=None, borrowed_self_note=False): """An abort never establishes an expected ownership rejection.""" if 'no such module' in log: return 'failed' if code < 0 or any(s in log for s in ('Stack dump:', 'fatal error encountered during compilation', 'Found ownership error?!')): return 'compiler_abort' if not object_exists else 'failed' + if code == 0 and object_exists: + return 'compiled' if diagnostic is None: - return 'compiled' if code == 0 and object_exists else 'failed' + return 'failed' if code <= 0 or object_exists or source_name is None: return 'failed' source_error = re.compile( r'^(?:.*[/\\])?' + re.escape(source_name) + r':\d+:\d+:\s+error:\s*(.*)$', re.MULTILINE) - return 'rejected' if any(diagnostic in message for message in source_error.findall(log)) else 'failed' + if any(diagnostic in message for message in source_error.findall(log)): + return 'rejected' + # Swift 6.4 locates a bound method's implicit self error at , with + # its capture note at the actual source expression. Only these two probes + # opt into this exact primary-error/source-note pair. + source_note = re.compile(r'^(?:.*[/\\])?' + re.escape(source_name) + + r":\d+:\d+:\s+note:\s*closure capturing 'self' here\s*$", re.MULTILINE) + self_error = ":0: error: 'self' cannot be captured by an escaping closure since it is a borrowed parameter" + if borrowed_self_note and diagnostic == 'borrowed' and self_error in log.splitlines() and source_note.search(log): + return 'rejected' + return 'failed' def main(): parser = argparse.ArgumentParser(description=__doc__) @@ -39,7 +51,7 @@ def main(): records = [] callsites = [] with tempfile.TemporaryDirectory(prefix='swift-json-composition-') as directory: - def compile_case(name, folder, diagnostic): + def compile_case(name, folder, diagnostic, borrowed_self_note=False): source = pathlib.Path(directory) / (name + '.swift') source.write_bytes((ROOT / 'Tools/CompositionQualification' / folder / (name + '.swift.txt')).read_bytes()) command = ['swiftc', '-c', '-swift-version', '6', '-I', str(modules), str(source), '-o', str(source.with_suffix('.o'))] @@ -50,28 +62,35 @@ def compile_case(name, folder, diagnostic): source_sha256=hashlib.sha256(source.read_bytes()).hexdigest(), expected_diagnostic=diagnostic, outcome=compiler_outcome(run.returncode, log, source.with_suffix('.o').exists(), - diagnostic, source.name if diagnostic is not None else None)) + diagnostic, source.name if diagnostic is not None else None, borrowed_self_note)) for name, diagnostic in expected.items(): record = compile_case(name, 'Negative', diagnostic) record['status'] = 'passed' if record['outcome'] == 'rejected' else 'failed' records.append(record) for name, diagnostic in [('ClosureBorrow', None), ('RootClosureBorrow', None), ('ExplicitBorrowParameters', None), ('MethodEscape', 'borrowed'), ('ContainerEscape', 'borrowed'), - ('MethodBorrow', None), ('RootContainerEscape', 'borrowed'), ('LocalFunctionBorrow', None), - ('RootOnlyEscape', 'borrowed')]: - record = compile_case(name, 'Compiler', diagnostic) + ('MethodBorrow', 'borrowed'), ('RootContainerEscape', 'borrowed'), ('LocalFunctionBorrow', None), + ('RootOnlyEscape', 'borrowed'), ('ExplicitContainerEscape', 'borrowed'), + ('ExplicitRootContainerEscape', 'borrowed'), ('ExplicitRootOnlyEscape', 'borrowed'), + ('ExplicitLocalFunctionBorrow', None), ('ExplicitMethodClosureBorrow', None)]: + record = compile_case(name, 'Compiler', diagnostic, name in {'MethodBorrow', 'MethodEscape'}) # Preserve these known call-site compiler bugs separately. A newer # compiler may diagnose the escapes or compile the nonescaping use. known_abort = name in {'MethodEscape', 'ContainerEscape', 'MethodBorrow', 'RootContainerEscape', 'LocalFunctionBorrow', 'RootOnlyEscape'} - record['status'] = ('blocked' if known_abort and record['outcome'] == 'compiler_abort' else - 'passed' if record['outcome'] == ('compiled' if diagnostic is None else 'rejected') else 'failed') + # Preserve MethodBorrow's original positive requirement: a normal + # borrowed-self diagnostic is an unsupported call site, not a pass. + record['expected_outcome'] = 'compiled' if diagnostic is None or name == 'MethodBorrow' else 'rejected' + record['status'] = ('passed' if record['outcome'] == record['expected_outcome'] else + 'blocked' if known_abort and (record['outcome'] == 'compiler_abort' or + name == 'MethodBorrow' and record['outcome'] == 'rejected') else 'failed') callsites.append(record) receipt = dict(status='passed' if all(r['status']=='passed' for r in records) else 'failed', compiler_negative_cases=len(records), records=records, callsite_cases=len(callsites), callsites=callsites, - compiler_abort_cases=sum(r['outcome']=='compiler_abort' for r in callsites)) + compiler_abort_cases=sum(r['outcome']=='compiler_abort' for r in callsites), + unsupported_callsite_cases=sum(r['status']=='blocked' and r['outcome']!='compiler_abort' for r in callsites)) if any(r['status']=='failed' for r in callsites): receipt['status'] = 'failed' - receipt['compiler_robustness_status'] = ('blocked' if receipt['compiler_abort_cases'] else + receipt['compiler_robustness_status'] = ('blocked' if any(r['status']=='blocked' for r in callsites) else 'failed' if any(r['status']=='failed' for r in callsites) else 'passed') (output / 'receipt.json').write_text(json.dumps(receipt, indent=2)+'\n') print(json.dumps(receipt, indent=2)) diff --git a/Scripts/test_composition_compiler_harness.py b/Scripts/test_composition_compiler_harness.py index 324190b..97018db 100644 --- a/Scripts/test_composition_compiler_harness.py +++ b/Scripts/test_composition_compiler_harness.py @@ -42,6 +42,28 @@ def test_positive_requires_emission(self): self.assertEqual(compiler_outcome(0, '', True), 'compiled') self.assertEqual(compiler_outcome(0, '', False), 'failed') + def test_unexpected_negative_compilation_remains_observable(self): + self.assertEqual(compiler_outcome(0, '', True, 'borrowed', 'Escape.swift'), 'compiled') + + def test_bound_method_requires_exact_self_error_and_its_source_note(self): + log = """:0: error: 'self' cannot be captured by an escaping closure since it is a borrowed parameter +/tmp/MethodEscape.swift:3:47: note: closure capturing 'self' here +""" + self.assertEqual(compiler_outcome(1, log, False, 'borrowed', 'MethodEscape.swift', True), 'rejected') + self.assertEqual(compiler_outcome(1, log, False, 'borrowed', 'MethodEscape.swift'), 'failed') + + def test_bound_method_note_cannot_come_from_another_file(self): + log = """:0: error: 'self' cannot be captured by an escaping closure since it is a borrowed parameter +/tmp/Other.swift:3:47: note: closure capturing 'self' here +""" + self.assertEqual(compiler_outcome(1, log, False, 'borrowed', 'MethodEscape.swift', True), 'failed') + + def test_bound_method_note_does_not_validate_an_unrelated_error(self): + log = """:0: error: module setup failed; borrowed parameter +/tmp/MethodEscape.swift:3:47: note: closure capturing 'self' here +""" + self.assertEqual(compiler_outcome(1, log, False, 'borrowed', 'MethodEscape.swift', True), 'failed') + def test_unrelated_error_is_not_rejection(self): log = "/tmp/Escape.swift:2:17: error: invalid syntax" self.assertEqual(compiler_outcome(1, log, False, 'borrowed', 'Escape.swift'), 'failed') @@ -49,6 +71,6 @@ def test_unrelated_error_is_not_rejection(self): if __name__ == '__main__': suite = unittest.defaultTestLoader.loadTestsFromTestCase(CompilerHarnessTests) result = unittest.TextTestRunner().run(suite) - passed = result.wasSuccessful() and result.testsRun == 10 and not result.skipped - if passed: print('COMPOSITION_COMPILER_HARNESS passed cases=10') + passed = result.wasSuccessful() and result.testsRun == 14 and not result.skipped + if passed: print('COMPOSITION_COMPILER_HARNESS passed cases=14') raise SystemExit(0 if passed else 1) diff --git a/Sources/JSON/Documentation.docc/Composition.md b/Sources/JSON/Documentation.docc/Composition.md index e4b8332..91c128a 100644 --- a/Sources/JSON/Documentation.docc/Composition.md +++ b/Sources/JSON/Documentation.docc/Composition.md @@ -81,12 +81,22 @@ large selected graphs still cost their full size. Calling `withAdmittedRoot` aga reserves another graph even for aliases. This API never caches arbitrary JSON identity or presumes a copy-on-write refund. -The pinned Swift 6.4 compiler aborts for some implicit captures at actual callback -call sites: returned bound methods, returned closure containers, a bound method -passed to a nonescaping helper, local functions implicitly capturing a scope and -an escaping closure that captures only the borrowed root handle. -Use explicit borrowing parameters for named helpers and explicit nonescaping closures, for example -`try perform { try scope.checkpoint() }`, instead of a bound method reference. -Qualification records aborts separately from semantic ownership rejections; an -abort emits no object and never counts as a successful rejection. Compiler -robustness remains a reported blocker while those aborts reproduce. +The pinned Swift 6.4 compiler can abort when implicitly named borrowed callback +parameters are captured by local functions or escaping containers. Spell callback +parameter ownership explicitly when factoring synchronous work into helpers: + +```swift +try JSON.withComposition { (scope: borrowing JSONCompositionScope) in + try scope.withAdmittedRoot(value) { (root: borrowing JSONCompositionRoot) in + let pointer = try scope.pointer(tokens: ["name"]) + return try scope.resolve(pointer, in: root) + } +} +``` + +Use a closure literal, for example `try perform { try scope.checkpoint() }`, +instead of a bound method reference. Instance methods explicitly borrow `self`; +Swift 6.4 diagnoses bound method capture, including a reference passed to a +nonescaping helper. Qualification preserves the original inferred-capture crash +cases and unsupported positive as blockers. Explicit spelling is a verified source +workaround; it does not establish general compiler robustness. diff --git a/Sources/JSON/Limits/JSONCompositionScope.swift b/Sources/JSON/Limits/JSONCompositionScope.swift index f821bab..793c638 100644 --- a/Sources/JSON/Limits/JSONCompositionScope.swift +++ b/Sources/JSON/Limits/JSONCompositionScope.swift @@ -38,7 +38,7 @@ public struct JSONCompositionScope: ~Copyable { } /// Executes a native helper on the sole ledger; all owned errors are terminal. - package func withMeter(domain: JSONOperationDomain = .core, + package borrowing func withMeter(domain: JSONOperationDomain = .core, _ body: (inout JSONWorkMeter) throws -> T) throws -> T { do { try state.context.meter.operationDomain(domain) @@ -58,7 +58,7 @@ public struct JSONCompositionScope: ~Copyable { /// - Parameter data: Caller-owned UTF-8 input, never fetched or repaired. /// - Returns: The exact source-backed document. /// - Throws: Original native failure or cancellation; caught failures stay terminal. - public func parseDocument(_ data: Data) throws -> JSONDocument { + public borrowing func parseDocument(_ data: Data) throws -> JSONDocument { try withMeter(domain: .parsing) { meter in try meter.require(.inputBytes, UInt64(data.count)) try meter.retain(UInt64(data.count)) @@ -73,7 +73,7 @@ public struct JSONCompositionScope: ~Copyable { /// - Parameter value: Trusted caller value; its prior construction is caller work. /// - Returns: The admitted value. Each call reserves a complete logical graph. /// - Throws: Native admission failure or cancellation. - public func admitTrusted(_ value: JSON) throws -> JSON { + public borrowing func admitTrusted(_ value: JSON) throws -> JSON { try withMeter { meter in try JSONAdmission.value(value, meter: &meter, owned: true) return value @@ -91,7 +91,7 @@ public struct JSONCompositionScope: ~Copyable { /// - body: Synchronous work borrowing the immutable admitted root. /// - Returns: The callback result; the handle cannot be returned. /// - Throws: Native terminal failure, cancellation or callback error. - public func withAdmittedRoot(_ value: JSON, + public borrowing func withAdmittedRoot(_ value: JSON, _ body: (borrowing JSONCompositionRoot) throws -> Result) throws -> Result { try withMeter { try JSONAdmission.value(value, meter: &$0, owned: true) } return try borrowingRoot(value, body) @@ -108,13 +108,13 @@ public struct JSONCompositionScope: ~Copyable { /// - body: Synchronous work receiving the document and borrowing its root handle. /// - Returns: The callback result, which may include the document or selected values. /// - Throws: Native terminal failure, cancellation or callback error. - public func withParsedDocument(_ data: Data, + public borrowing func withParsedDocument(_ data: Data, _ body: (JSONDocument, borrowing JSONCompositionRoot) throws -> Result) throws -> Result { let document = try parseDocument(data) return try borrowingRoot(document.root) { root in try body(document, root) } } - private func borrowingRoot(_ value: JSON, + private borrowing func borrowingRoot(_ value: JSON, _ body: (borrowing JSONCompositionRoot) throws -> Result) throws -> Result { try withMeter { meter in try meter.work() @@ -138,7 +138,7 @@ public struct JSONCompositionScope: ~Copyable { /// - Parameter tokens: Caller-owned decoded tokens. /// - Returns: The admitted Pointer. /// - Throws: Original native Pointer/admission failure or cancellation. - public func pointer(tokens: [String]) throws -> JSONPointer { + public borrowing func pointer(tokens: [String]) throws -> JSONPointer { try withMeter(domain: .pointer) { try JSONPointer.fromStrings(tokens, meter: &$0) } } @@ -146,7 +146,7 @@ public struct JSONCompositionScope: ~Copyable { /// - Parameter text: Encoded Pointer text; empty selects the root. /// - Returns: The admitted Pointer. /// - Throws: Original native Pointer/admission failure or cancellation. - public func pointer(parsing text: String) throws -> JSONPointer { + public borrowing func pointer(parsing text: String) throws -> JSONPointer { try withMeter(domain: .pointer) { try JSONPointer.parse(text, meter: &$0) } } @@ -154,7 +154,7 @@ public struct JSONCompositionScope: ~Copyable { /// - Parameter fragment: Encoded fragment including its leading #. /// - Returns: The admitted Pointer. /// - Throws: Original native Pointer/admission failure or cancellation. - public func pointer(uriFragment fragment: String) throws -> JSONPointer { + public borrowing func pointer(uriFragment fragment: String) throws -> JSONPointer { try withMeter(domain: .pointer) { try JSONPointer.uriFragment(fragment, meter: &$0) } } @@ -164,7 +164,7 @@ public struct JSONCompositionScope: ~Copyable { /// - key: The decoded token, also usable as a strict array index spelling. /// - Returns: The admitted appended Pointer. /// - Throws: Original native Pointer/admission failure or cancellation. - public func appending(_ pointer: JSONPointer, key: String) throws -> JSONPointer { + public borrowing func appending(_ pointer: JSONPointer, key: String) throws -> JSONPointer { try withMeter(domain: .pointer) { try pointer.appending(key: key, meter: &$0) } } @@ -177,7 +177,7 @@ public struct JSONCompositionScope: ~Copyable { /// - value: A caller or scope-created root. /// - Returns: The selected exact value. /// - Throws: Original native Pointer/admission failure or cancellation. - public func resolve(_ pointer: JSONPointer, in value: JSON) throws -> JSON { + public borrowing func resolve(_ pointer: JSONPointer, in value: JSON) throws -> JSON { try withMeter(domain: .pointer) { meter in try JSONAdmission.value(value, meter: &meter, owned: true) let admitted = try JSONPointer.decodedTokens(pointer.tokens, meter: &meter) @@ -197,7 +197,7 @@ public struct JSONCompositionScope: ~Copyable { /// - root: Borrowed handle produced by this scope's root callback. /// - Returns: The selected exact value with a conservative output reservation. /// - Throws: Wrong-owner configuration failure, native failure or cancellation. - public func resolve(_ pointer: JSONPointer, in root: borrowing JSONCompositionRoot) throws -> JSON { + public borrowing func resolve(_ pointer: JSONPointer, in root: borrowing JSONCompositionRoot) throws -> JSON { try withMeter(domain: .pointer) { meter in try meter.work() guard root.owner === state else { throw JSONFailure(.configuration, code: .invalidOperation) } @@ -211,7 +211,7 @@ public struct JSONCompositionScope: ~Copyable { /// Charges instrumented adapter work once to aggregate core work. /// - Parameter units: Declared primitive work admitted before performing it. /// - Throws: Quota/overflow failure or cancellation, permanently terminal. - public func chargeExternalWork(_ units: UInt64) throws { + public borrowing func chargeExternalWork(_ units: UInt64) throws { try withMeter { try $0.work(units) } } @@ -224,7 +224,7 @@ public struct JSONCompositionScope: ~Copyable { /// - bytes: Logical weight per unit. /// - count: Number of units, multiplied with checked UInt64 arithmetic. /// - Throws: Quota/overflow failure or cancellation, permanently terminal. - public func reserveExternalLogicalBytes(_ bytes: UInt64, count: UInt64 = 1) throws { + public borrowing func reserveExternalLogicalBytes(_ bytes: UInt64, count: UInt64 = 1) throws { try withMeter { meter in let (total, overflow) = bytes.multipliedReportingOverflow(by: count) guard !overflow else { @@ -238,12 +238,12 @@ public struct JSONCompositionScope: ~Copyable { /// Checks cancellation and prior terminal failure before adapter work. /// - Throws: The original terminal failure or cancellation. - public func checkpoint() throws { try withMeter { try $0.checkpoint() } } + public borrowing func checkpoint() throws { try withMeter { try $0.checkpoint() } } /// Tightens finite limits without resetting work, live reservations or admissions. /// - Parameter limits: Requested ceilings, intersected with existing ceilings. /// - Throws: Invalid configuration, prior admission/work violation or cancellation. - public func restrict(to limits: JSONLimits) throws { + public borrowing func restrict(to limits: JSONLimits) throws { try withMeter { try $0.restrict(to: limits) } } diff --git a/Sources/JSONCLIEngine/CLIBuildIdentity.swift b/Sources/JSONCLIEngine/CLIBuildIdentity.swift index 432e422..5824099 100644 --- a/Sources/JSONCLIEngine/CLIBuildIdentity.swift +++ b/Sources/JSONCLIEngine/CLIBuildIdentity.swift @@ -2,6 +2,6 @@ // Generated by Scripts/generate_cli_identity.py; excludes this file. // SHA-256 of the ordered Package.swift + Sources content manifest, not a Git commit. package enum CLIBuildIdentity { - package static let revision = "sha256:b29fe25e05a355719dd1a8a0528618d6463ac48e0d0dd5426f7bec1ae6ac9fe6" + package static let revision = "sha256:9dd050bb32ebf6e70f58a6df0a6bb9c663b965aaf94e1c7f89e2e73478d11a70" package static let kind = "source-sha256" } diff --git a/Sources/JSONSchema/Document/JSONCompositionScope+URI.swift b/Sources/JSONSchema/Document/JSONCompositionScope+URI.swift index 60a44ae..b2386d1 100644 --- a/Sources/JSONSchema/Document/JSONCompositionScope+URI.swift +++ b/Sources/JSONSchema/Document/JSONCompositionScope+URI.swift @@ -11,7 +11,7 @@ extension JSONCompositionScope { /// - base: Explicit normalized base for a relative reference; never fetched. /// - Returns: Native normalized URI identity. /// - Throws: Native identifier/resource failure or cancellation, permanently terminal. - public func uri(_ text: String, relativeTo base: JSONSchemaURI? = nil) throws -> JSONSchemaURI { + public borrowing func uri(_ text: String, relativeTo base: JSONSchemaURI? = nil) throws -> JSONSchemaURI { try withMeter { meter in if let base { try JSONAdmission.text(base.string, meter: &meter, owned: true) } return try JSONSchemaURI.parse(text, relativeTo: base, meter: &meter) @@ -22,7 +22,7 @@ extension JSONCompositionScope { /// - Parameter uri: Caller or scope-created identity, re-admitted before use. /// - Returns: Normalized URI without its fragment. /// - Throws: Native identifier/resource failure or cancellation, permanently terminal. - public func removingFragment(_ uri: JSONSchemaURI) throws -> JSONSchemaURI { + public borrowing func removingFragment(_ uri: JSONSchemaURI) throws -> JSONSchemaURI { try withMeter { meter in let admitted = try JSONSchemaURI.parse(uri.string, relativeTo: nil, meter: &meter) // Avoid the ordinary unmetered fragment convenience (including its diff --git a/Tools/CompositionQualification/Compiler/ExplicitContainerEscape.swift.txt b/Tools/CompositionQualification/Compiler/ExplicitContainerEscape.swift.txt new file mode 100644 index 0000000..5e2e1c2 --- /dev/null +++ b/Tools/CompositionQualification/Compiler/ExplicitContainerEscape.swift.txt @@ -0,0 +1,5 @@ +import JSON +struct Box { let action: () throws -> Void } +func escapedContainer() throws -> Box { + try JSON.withComposition { (scope: borrowing JSONCompositionScope) in Box(action: { try scope.checkpoint() }) }.result +} diff --git a/Tools/CompositionQualification/Compiler/ExplicitLocalFunctionBorrow.swift.txt b/Tools/CompositionQualification/Compiler/ExplicitLocalFunctionBorrow.swift.txt new file mode 100644 index 0000000..839cb61 --- /dev/null +++ b/Tools/CompositionQualification/Compiler/ExplicitLocalFunctionBorrow.swift.txt @@ -0,0 +1,7 @@ +import JSON +func borrowedLocalFunction() throws { + _ = try JSON.withComposition { (scope: borrowing JSONCompositionScope) in + func invoke() throws { try scope.checkpoint() } + try invoke() + } +} diff --git a/Tools/CompositionQualification/Compiler/ExplicitMethodClosureBorrow.swift.txt b/Tools/CompositionQualification/Compiler/ExplicitMethodClosureBorrow.swift.txt new file mode 100644 index 0000000..c8691d5 --- /dev/null +++ b/Tools/CompositionQualification/Compiler/ExplicitMethodClosureBorrow.swift.txt @@ -0,0 +1,7 @@ +import JSON +func callNow(_ operation: () throws -> Void) throws { try operation() } +func borrowedMethodClosure() throws { + _ = try JSON.withComposition { (scope: borrowing JSONCompositionScope) in + try callNow { try scope.checkpoint() } + } +} diff --git a/Tools/CompositionQualification/Compiler/ExplicitRootContainerEscape.swift.txt b/Tools/CompositionQualification/Compiler/ExplicitRootContainerEscape.swift.txt new file mode 100644 index 0000000..5917990 --- /dev/null +++ b/Tools/CompositionQualification/Compiler/ExplicitRootContainerEscape.swift.txt @@ -0,0 +1,10 @@ +import JSON +struct Box { let action: () throws -> JSON } +func escapedRoot() throws -> Box { + try JSON.withComposition { (scope: borrowing JSONCompositionScope) in + let pointer = try scope.pointer(tokens: []) + return try scope.withAdmittedRoot(.null) { (root: borrowing JSONCompositionRoot) in + Box(action: { try scope.resolve(pointer, in: root) }) + } + }.result +} diff --git a/Tools/CompositionQualification/Compiler/ExplicitRootOnlyEscape.swift.txt b/Tools/CompositionQualification/Compiler/ExplicitRootOnlyEscape.swift.txt new file mode 100644 index 0000000..66cdd33 --- /dev/null +++ b/Tools/CompositionQualification/Compiler/ExplicitRootOnlyEscape.swift.txt @@ -0,0 +1,8 @@ +import JSON +func inspect(_ root: borrowing JSONCompositionRoot) { } +struct Box { let action: () -> Void } +func escapedRoot() throws -> Box { + try JSON.withComposition { (scope: borrowing JSONCompositionScope) in + try scope.withAdmittedRoot(.null) { (root: borrowing JSONCompositionRoot) in Box(action: { inspect(root) }) } + }.result +} diff --git a/Tools/CompositionQualification/CompilerReproductions/ExplicitCapture.swift.txt b/Tools/CompositionQualification/CompilerReproductions/ExplicitCapture.swift.txt new file mode 100644 index 0000000..a2be982 --- /dev/null +++ b/Tools/CompositionQualification/CompilerReproductions/ExplicitCapture.swift.txt @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: Apache-2.0 +struct Handle: ~Copyable { borrowing func check() {} } +func withHandle(_ body: (borrowing Handle) -> T) -> T { + let handle = Handle() + return body(handle) +} +struct Box { let action: () -> Void } +func escaped() -> Box { + withHandle { (handle: borrowing Handle) in Box(action: { handle.check() }) } +} diff --git a/Tools/CompositionQualification/CompilerReproductions/ExplicitLocalFunction.swift.txt b/Tools/CompositionQualification/CompilerReproductions/ExplicitLocalFunction.swift.txt new file mode 100644 index 0000000..fa27bd4 --- /dev/null +++ b/Tools/CompositionQualification/CompilerReproductions/ExplicitLocalFunction.swift.txt @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: Apache-2.0 +struct Handle: ~Copyable { borrowing func check() {} } +func withHandle(_ body: (borrowing Handle) -> T) -> T { + let handle = Handle() + return body(handle) +} +func synchronous() { + withHandle { (handle: borrowing Handle) in + func invoke() { handle.check() } + invoke() + } +} diff --git a/Tools/CompositionQualification/CompilerReproductions/ImplicitCapture.swift.txt b/Tools/CompositionQualification/CompilerReproductions/ImplicitCapture.swift.txt new file mode 100644 index 0000000..c40e878 --- /dev/null +++ b/Tools/CompositionQualification/CompilerReproductions/ImplicitCapture.swift.txt @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: Apache-2.0 +struct Handle: ~Copyable { borrowing func check() {} } +func withHandle(_ body: (borrowing Handle) -> T) -> T { + let handle = Handle() + return body(handle) +} +struct Box { let action: () -> Void } +func escaped() -> Box { + withHandle { handle in Box(action: { handle.check() }) } +} diff --git a/Tools/CompositionQualification/CompilerReproductions/ImplicitLocalFunction.swift.txt b/Tools/CompositionQualification/CompilerReproductions/ImplicitLocalFunction.swift.txt new file mode 100644 index 0000000..a9b8d93 --- /dev/null +++ b/Tools/CompositionQualification/CompilerReproductions/ImplicitLocalFunction.swift.txt @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: Apache-2.0 +struct Handle: ~Copyable { borrowing func check() {} } +func withHandle(_ body: (borrowing Handle) -> T) -> T { + let handle = Handle() + return body(handle) +} +func synchronous() { + withHandle { handle in + func invoke() { handle.check() } + invoke() + } +} diff --git a/Tools/CompositionQualification/CompilerReproductions/README.md b/Tools/CompositionQualification/CompilerReproductions/README.md new file mode 100644 index 0000000..63d81b7 --- /dev/null +++ b/Tools/CompositionQualification/CompilerReproductions/README.md @@ -0,0 +1,18 @@ +# Standalone Swift 6.4 capture reductions + +These original Apache-2.0 programs need no package or imports. Copy each `.swift.txt` +file to a temporary `.swift` file, then compile with `swiftc -swift-version 6 -c`. +Use object emission: typechecking alone does not run the failing SIL cleanup. +Keep compiler signals distinct from expected diagnostics. + +| Program | Swift 6.4 result | +| --- | --- | +| ImplicitCapture | Compiler abort in SILGenCleanup | +| ExplicitCapture | Ordinary borrowed-parameter diagnostic | +| ImplicitLocalFunction | Compiler abort in SILGenCleanup | +| ExplicitLocalFunction | Object emitted | + +Only the callback parameter spelling differs within each pair. The public API +gate retains its original inferred programs; these reductions explain the +[compiler diagnosis](../../../Documentation/Architecture/CompositionCompiler.md) +without the library implementation. diff --git a/Tools/CompositionQualification/README.md b/Tools/CompositionQualification/README.md index a3c9fd8..cd075bb 100644 --- a/Tools/CompositionQualification/README.md +++ b/Tools/CompositionQualification/README.md @@ -27,14 +27,20 @@ The policy exposes no transferable owner token or refund. Borrowed root handles have no public constructor, value accessor or mutation; their private owner identity rejects use by another scope before navigation. -Nine additional actual-callsite probes include three explicit-borrow positives and -six forms exposing Swift 6.4 compiler aborts, including a root-only escaping capture. -Their outcomes are separate from the 18 semantic rejections. Ten Python harness -cases check the distinction and reject setup-log keyword false positives. -The lane completes its checks, then exits 2 with overall `blocked` if known compiler -aborts reproduce. Successful behavior and ownership results are recorded alongside -the compiler robustness blocker. Use explicit nonescaping closures in supported -code; do not turn a compiler crash into a rejection pass. +Fourteen actual-callsite probes retain the original nine programs and add five +explicit-ownership counterparts. Explicit borrowing instance methods prevent the +two bound-method aborts: the escape is rejected, while the nonescaping bound-method +positive remains blocked as unsupported. Four original inferred-capture forms still +abort Swift 6.4. Explicit callback parameter spelling makes invalid captures receive +ordinary diagnostics and makes local-function and closure-literal helper uses compile. +See [the compiler diagnosis](../../Documentation/Architecture/CompositionCompiler.md). + +These outcomes remain separate from the 18 semantic rejections. Fourteen Python +harness cases reject setup-log keyword false positives and require an exact +borrowed-self error plus a source-local note for bound-method diagnostics. +The lane completes its checks, then exits 2 with overall `blocked` if known aborts +or unsupported positives remain. A workaround or an ordinary rejection does not +satisfy the original positive requirement. ```sh swift run -c release --package-path Tools/CompositionQualification CompositionRegression From 95267eea3d4ab3c3c1553d4afcf89806fde8788e Mon Sep 17 00:00:00 2001 From: Thorsten Fuchs Date: Fri, 16 Oct 2026 13:10:14 +0200 Subject: [PATCH 7/7] Add focused composition compiler qualification lane --- Documentation/Architecture/CompositionCompiler.md | 7 +++++++ Scripts/ci.py | 13 ++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Documentation/Architecture/CompositionCompiler.md b/Documentation/Architecture/CompositionCompiler.md index f77047b..763abc6 100644 --- a/Documentation/Architecture/CompositionCompiler.md +++ b/Documentation/Architecture/CompositionCompiler.md @@ -65,3 +65,10 @@ The remaining inferred captures still require an upstream compiler correction. The gate stays blocked on those aborts and the unsupported bound-method positive; the explicit spelling is a source workaround, not a claim that the compiler gate has passed. + +For toolchain comparisons, run `python3 Scripts/ci.py --lane composition-compiler`. +This builds the JSON module with the selected compiler, runs the classifier tests, +and checks all 18 semantic negatives and 14 call sites with their existing +expectations. It records runtime behavior as `not_run`; the full composition lane +remains the runtime, sanitizer, adapter and scale qualification gate. Compiler +aborts and rejected positive call sites keep either lane blocked with exit 2. diff --git a/Scripts/ci.py b/Scripts/ci.py index 9a0d9ad..5d9fcbe 100644 --- a/Scripts/ci.py +++ b/Scripts/ci.py @@ -20,6 +20,9 @@ def snapshot(): def commands(lane, output): # The qualification executable resolves output paths from its repository root. output = output.relative_to(ROOT) + if lane == 'composition-compiler': + composition = commands('composition', ROOT / output) + return composition[:3] + [['swift', 'build', '--target', 'JSON']] + [composition[-1]] if lane == 'composition': result = [ ['python3', '-B', 'Scripts/public_check.py'], @@ -254,7 +257,7 @@ def check_result(command, code, log, events=None): def main(): parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument('--lane', choices=['composition', 'native', 'safety', 'docs', 'r0', 'qa', 'linux', 'linux-safety', 'wasm', 'browser', 'export', 'cli', 'coverage', 'linux-coverage', 'linux-qa', 'wasm-qa', 'archive', 'navigation'], required=True) + parser.add_argument('--lane', choices=['composition', 'composition-compiler', 'native', 'safety', 'docs', 'r0', 'qa', 'linux', 'linux-safety', 'wasm', 'browser', 'export', 'cli', 'coverage', 'linux-coverage', 'linux-qa', 'wasm-qa', 'archive', 'navigation'], required=True) parser.add_argument('--output') args = parser.parse_args() output = ROOT / (args.output or '.build/ci/' + args.lane) @@ -263,7 +266,7 @@ def main(): repository = subprocess.run(['git', 'rev-parse', '--show-toplevel'], cwd=ROOT, capture_output=True, text=True) is_checkout = repository.returncode == 0 and pathlib.Path(repository.stdout.strip()).resolve() == ROOT.resolve() commit = subprocess.run(['git', 'rev-parse', 'HEAD'], cwd=ROOT, capture_output=True, text=True) if is_checkout else None - environment = collect_linux() if args.lane.startswith('linux') or (args.lane == 'composition' and sys.platform == 'linux') else collect() + environment = collect_linux() if args.lane.startswith('linux') or (args.lane in ('composition', 'composition-compiler') and sys.platform == 'linux') else collect() receipt = {'schema_version': 1, 'lane': args.lane, 'status': 'blocked', 'environment': environment, 'started_utc': datetime.datetime.now(datetime.timezone.utc).isoformat(), 'git_commit': commit.stdout.strip() if commit is not None and commit.returncode == 0 else None, 'github_run_id': os.environ.get('GITHUB_RUN_ID'), 'source_inputs': inputs, 'source_manifest_sha256': hashlib.sha256(json.dumps(inputs, sort_keys=True).encode()).hexdigest(), 'commands': []} def save(): (output / 'receipt.json').write_text(json.dumps(receipt, indent=2) + '\n') @@ -318,7 +321,7 @@ def save(): shutil.rmtree(ROOT / '.build/composition-thread', ignore_errors=True) else: receipt['status'] = 'passed' - if receipt['status'] == 'passed' and args.lane == 'composition': + if receipt['status'] == 'passed' and args.lane in ('composition', 'composition-compiler'): try: compiler_path = output / 'compiler-negative/receipt.json' compiler = json.loads(compiler_path.read_text()) @@ -329,7 +332,7 @@ def save(): 'ownership_status': compiler['status'], 'robustness_status': compiler['compiler_robustness_status'], 'compiler_abort_cases': compiler['compiler_abort_cases'], 'unsupported_callsite_cases': compiler['unsupported_callsite_cases']} - receipt['behavior_status'] = 'passed' + receipt['behavior_status'] = 'passed' if args.lane == 'composition' else 'not_run' if compiler['compiler_robustness_status'] == 'blocked': receipt['status'] = 'blocked' except (OSError, KeyError, ValueError, TypeError) as error: receipt['status'] = 'failed'; receipt['evidence_error'] = str(error) @@ -381,7 +384,7 @@ def save(): receipt['status'] = 'failed' receipt['finished_utc'] = datetime.datetime.now(datetime.timezone.utc).isoformat() save() - if args.lane == 'composition' and receipt['status'] == 'blocked': + if args.lane in ('composition', 'composition-compiler') and receipt['status'] == 'blocked': return 2 return 0 if receipt['status'] == 'passed' else 1