@native-sdk/cli 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/bin/native.js +2 -1
- package/build/app.zig +320 -60
- package/build/corewire.zig +53 -0
- package/build/test_shards.zig +49 -0
- package/build/ts_run.mjs +3 -3
- package/build.zig +1818 -87
- package/package.json +19 -14
- package/packages/core/compile-surface/core.ts +134 -72
- package/packages/core/package-lock.json +75 -357
- package/packages/core/package.json +25 -4
- package/packages/core/scripts/compiler_command.mjs +17 -12
- package/packages/core/scripts/compiler_typecheck.mjs +1 -0
- package/packages/core/scripts/gen_declarations.mjs +3 -2
- package/packages/core/scripts/gen_service_surface.mjs +22 -10
- package/packages/core/scripts/install_scriptc.mjs +182 -0
- package/packages/core/scripts/invoke_scriptc.mjs +18 -0
- package/packages/core/scripts/merge_static_archives.mjs +6 -1
- package/packages/core/scripts/npm_static_spike.mjs +2 -2
- package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
- package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
- package/packages/core/scripts/run_library_compiler.mjs +51 -0
- package/packages/core/scripts/run_native_tests.mjs +22 -0
- package/packages/core/scripts/scriptc-toolchain.json +101 -0
- package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
- package/packages/core/scripts/stage_external_core.mjs +57 -1
- package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
- package/packages/core/sdk/bytes.d.ts +2 -0
- package/packages/core/sdk/bytes.ts +86 -0
- package/packages/core/sdk/core.d.ts +308 -4
- package/packages/core/sdk/core.ts +320 -84
- package/packages/core/sdk/events.d.ts +247 -0
- package/packages/core/sdk/events.ts +230 -2
- package/packages/core/sdk/internal/image_identity.d.ts +7 -0
- package/packages/core/sdk/internal/image_identity.ts +71 -0
- package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
- package/packages/core/sdk/internal/markdown_policy.ts +878 -0
- package/packages/core/sdk/text.d.ts +27 -0
- package/packages/core/sdk/text.ts +206 -15
- package/packages/core/sdk/theme.d.ts +251 -0
- package/packages/core/sdk/theme.ts +267 -0
- package/packages/core/src/authorization.ts +137 -0
- package/packages/core/src/automation_commands.ts +201 -0
- package/packages/core/src/automation_interactions.ts +92 -0
- package/packages/core/src/bridge_descriptors.ts +104 -0
- package/packages/core/src/builtin_coordination.ts +172 -0
- package/packages/core/src/canvas_frame_coordination.ts +81 -0
- package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
- package/packages/core/src/canvas_scene_observation.ts +145 -0
- package/packages/core/src/chart_content.ts +161 -0
- package/packages/core/src/chart_plans.ts +432 -0
- package/packages/core/src/checker.ts +166 -19
- package/packages/core/src/code_content.ts +580 -0
- package/packages/core/src/command_coordination.ts +140 -0
- package/packages/core/src/component_composition.ts +94 -0
- package/packages/core/src/component_construction.ts +149 -0
- package/packages/core/src/contract.ts +25 -7
- package/packages/core/src/control_appearance.ts +232 -0
- package/packages/core/src/control_commands.ts +115 -0
- package/packages/core/src/control_content.ts +105 -0
- package/packages/core/src/control_geometry.ts +107 -0
- package/packages/core/src/control_payloads.ts +119 -0
- package/packages/core/src/control_primitives.ts +134 -0
- package/packages/core/src/devhost.ts +82 -7
- package/packages/core/src/devhost_journal.mjs +30 -7
- package/packages/core/src/effect_plans.ts +71 -0
- package/packages/core/src/flow_measurement.ts +121 -0
- package/packages/core/src/font_registry.ts +37 -0
- package/packages/core/src/glyph_atlas.ts +86 -0
- package/packages/core/src/gpu_packet_preparation.ts +130 -0
- package/packages/core/src/gpu_planning.ts +123 -0
- package/packages/core/src/gpu_presentation.ts +55 -0
- package/packages/core/src/host_flow.ts +89 -0
- package/packages/core/src/host_input_regions.ts +165 -0
- package/packages/core/src/image_registry.ts +66 -0
- package/packages/core/src/indicator_plans.ts +132 -0
- package/packages/core/src/infer.ts +150 -8
- package/packages/core/src/input_composition.ts +116 -0
- package/packages/core/src/intrinsic_measure.ts +100 -0
- package/packages/core/src/layout_coordination.ts +207 -0
- package/packages/core/src/leaf_plans.ts +134 -0
- package/packages/core/src/markup_development.ts +160 -0
- package/packages/core/src/measurement_coordination.ts +185 -0
- package/packages/core/src/modules.ts +1 -1
- package/packages/core/src/motion_sampling.ts +100 -0
- package/packages/core/src/paragraph_layout.ts +192 -0
- package/packages/core/src/portable_sources.json +74 -0
- package/packages/core/src/portable_sources.ts +17 -0
- package/packages/core/src/registered_font.ts +93 -0
- package/packages/core/src/render_animation_lifecycle.ts +128 -0
- package/packages/core/src/render_coordination.ts +170 -0
- package/packages/core/src/render_resources.ts +234 -0
- package/packages/core/src/runtime_policy.ts +3930 -0
- package/packages/core/src/scalar_text.ts +84 -0
- package/packages/core/src/service_contract.ts +2 -1
- package/packages/core/src/session_codecs.ts +309 -0
- package/packages/core/src/shell_admission.ts +126 -0
- package/packages/core/src/shell_coordination.ts +93 -0
- package/packages/core/src/sqlite_cli.ts +11 -0
- package/packages/core/src/status_validation.ts +232 -0
- package/packages/core/src/stream_policy.ts +63 -0
- package/packages/core/src/surface_recipes.ts +136 -0
- package/packages/core/src/system_admission.ts +60 -0
- package/packages/core/src/terminal_paint.ts +436 -0
- package/packages/core/src/text_document_width.ts +81 -0
- package/packages/core/src/text_measurement_cache.ts +69 -0
- package/packages/core/src/text_query_layout.ts +179 -0
- package/packages/core/src/text_run_layout.ts +410 -0
- package/packages/core/src/text_span_queries.ts +355 -0
- package/packages/core/src/typed_ast.ts +18 -1
- package/packages/core/src/types.ts +7 -5
- package/packages/core/src/vector_effects.ts +98 -0
- package/packages/core/src/vector_raster.ts +243 -0
- package/packages/core/src/view_components.ts +2415 -0
- package/packages/core/src/view_coordination.ts +198 -0
- package/packages/core/src/view_frontend.ts +980 -0
- package/packages/core/src/widget_audits.ts +202 -0
- package/packages/core/src/widget_changes.ts +258 -0
- package/packages/core/src/widget_metrics.ts +139 -0
- package/packages/core/src/widget_motion.ts +171 -0
- package/packages/core/src/widget_paint.ts +272 -0
- package/packages/core/src/widget_paint_walk.ts +203 -0
- package/packages/core/src/widget_presentation.ts +141 -0
- package/packages/core/src/widget_routing.ts +262 -0
- package/packages/core/src/window_lifecycle.ts +92 -0
- package/packages/core/testing/index.ts +430 -0
- package/schemas/app.schema.json +13 -0
- package/skill-data/core/SKILL.md +2 -2
- package/skill-data/core/references/web-engines-packaging-debugging.md +2 -1
- package/skill-data/native-ui/SKILL.md +76 -17
- package/skill-data/ts-core/SKILL.md +113 -9
- package/skill-data/ts-services/SKILL.md +1 -1
- package/skill-data/ts-services/references/service-surface.md +264 -144
- package/src/app_runner/root.zig +25 -12
- package/src/app_runner/ts_compiled_view.zig +1631 -0
- package/src/app_runner/ts_core_main.zig +143 -10
- package/src/app_runner/ts_core_mobile.zig +24 -12
- package/src/automation/server.zig +1 -3
- package/src/automation/snapshot.zig +9 -637
- package/src/automation/snapshot_reference.zig +656 -0
- package/src/automation/snapshot_serialization.zig +566 -0
- package/src/platform/linux/gtk_host.c +36 -24
- package/src/platform/linux/gtk_pixels.h +118 -0
- package/src/platform/linux/gtk_pixels_test.c +241 -0
- package/src/platform/linux/root.zig +2 -0
- package/src/platform/macos/appkit_host.m +188 -30
- package/src/platform/macos/pointer_motion_test.m +96 -0
- package/src/platform/macos/scroll_driver_test.m +105 -0
- package/src/platform/macos/spectrum_bins.h +34 -0
- package/src/platform/macos/spectrum_bins_test.c +56 -0
- package/src/platform/macos/text_keyboard_test.m +80 -0
- package/src/platform/macos/widget_focus_test.m +66 -0
- package/src/platform/null_platform.zig +26 -2
- package/src/platform/null_platform_tests.zig +13 -0
- package/src/platform/root.zig +1 -0
- package/src/platform/types.zig +13 -0
- package/src/platform/windows/root.zig +2 -0
- package/src/platform/windows/webview2_host.cpp +7 -2
- package/src/primitives/app_manifest/comptime_scene.zig +1 -1
- package/src/primitives/app_manifest/root.zig +2 -0
- package/src/primitives/app_manifest/tests.zig +4 -1
- package/src/primitives/app_manifest/validation.zig +2 -0
- package/src/primitives/canvas/a11y_audit.zig +3 -1
- package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
- package/src/primitives/canvas/chart_content_policy.zig +75 -0
- package/src/primitives/canvas/chart_plan_policy.zig +196 -0
- package/src/primitives/canvas/code_content_policy.zig +162 -0
- package/src/primitives/canvas/commands.zig +29 -1
- package/src/primitives/canvas/component_composition.zig +125 -0
- package/src/primitives/canvas/component_composition_policy.zig +44 -0
- package/src/primitives/canvas/component_construction_policy.zig +187 -0
- package/src/primitives/canvas/container_layout_policy.zig +87 -0
- package/src/primitives/canvas/control_appearance_policy.zig +142 -0
- package/src/primitives/canvas/control_command_policy.zig +75 -0
- package/src/primitives/canvas/control_content_policy.zig +90 -0
- package/src/primitives/canvas/control_geometry_policy.zig +165 -0
- package/src/primitives/canvas/control_payload_policy.zig +48 -0
- package/src/primitives/canvas/control_primitive_policy.zig +129 -0
- package/src/primitives/canvas/effect_plan_policy.zig +96 -0
- package/src/primitives/canvas/events.zig +1027 -1
- package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
- package/src/primitives/canvas/frame.zig +92 -23
- package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
- package/src/primitives/canvas/gpu.zig +10 -0
- package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
- package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
- package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
- package/src/primitives/canvas/grid_layout_policy.zig +51 -0
- package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
- package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
- package/src/primitives/canvas/intrinsic_measure_policy.zig +128 -0
- package/src/primitives/canvas/layout_audit.zig +5 -2
- package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
- package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
- package/src/primitives/canvas/markdown.zig +13 -3
- package/src/primitives/canvas/markdown_content_policy.zig +227 -0
- package/src/primitives/canvas/markdown_image_binding.zig +81 -0
- package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
- package/src/primitives/canvas/numeric_capabilities.zig +14 -0
- package/src/primitives/canvas/reference.zig +12 -6
- package/src/primitives/canvas/registered_font_policy.zig +152 -0
- package/src/primitives/canvas/render.zig +48 -0
- package/src/primitives/canvas/render_cache_policy.zig +184 -0
- package/src/primitives/canvas/render_coordination_policy.zig +163 -0
- package/src/primitives/canvas/render_damage_policy.zig +160 -0
- package/src/primitives/canvas/render_effects.zig +14 -0
- package/src/primitives/canvas/render_generic_resources.zig +14 -0
- package/src/primitives/canvas/render_images.zig +14 -0
- package/src/primitives/canvas/render_layers.zig +14 -0
- package/src/primitives/canvas/render_override_policy.zig +119 -0
- package/src/primitives/canvas/render_paths.zig +14 -0
- package/src/primitives/canvas/render_plan_policy.zig +199 -0
- package/src/primitives/canvas/render_resource_policy.zig +476 -0
- package/src/primitives/canvas/root.zig +100 -0
- package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
- package/src/primitives/canvas/serialization.zig +8 -1
- package/src/primitives/canvas/surface_layout_policy.zig +36 -0
- package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
- package/src/primitives/canvas/terminal_grid.zig +10 -696
- package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
- package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
- package/src/primitives/canvas/text.zig +1 -0
- package/src/primitives/canvas/text_atlas.zig +113 -0
- package/src/primitives/canvas/text_cache_policy.zig +94 -0
- package/src/primitives/canvas/text_document_policy.zig +120 -0
- package/src/primitives/canvas/text_layout.zig +51 -2
- package/src/primitives/canvas/text_layout_cache.zig +29 -0
- package/src/primitives/canvas/text_layout_hash.zig +1 -0
- package/src/primitives/canvas/text_layout_types.zig +3 -0
- package/src/primitives/canvas/text_measure_cache.zig +46 -0
- package/src/primitives/canvas/text_measurement_policy.zig +124 -0
- package/src/primitives/canvas/text_metrics.zig +23 -0
- package/src/primitives/canvas/text_query_policy.zig +156 -0
- package/src/primitives/canvas/text_run_policy.zig +252 -0
- package/src/primitives/canvas/text_scalar_policy.zig +156 -0
- package/src/primitives/canvas/text_span_query_policy.zig +232 -0
- package/src/primitives/canvas/text_spans.zig +280 -8
- package/src/primitives/canvas/text_tests.zig +10 -0
- package/src/primitives/canvas/tokens.zig +38 -0
- package/src/primitives/canvas/ui.zig +250 -83
- package/src/primitives/canvas/ui_markup.zig +139 -33
- package/src/primitives/canvas/ui_markup_compiled.zig +319 -59
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
- package/src/primitives/canvas/ui_markup_contract.zig +146 -14
- package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
- package/src/primitives/canvas/ui_markup_tests.zig +116 -0
- package/src/primitives/canvas/ui_markup_view.zig +258 -32
- package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
- package/src/primitives/canvas/ui_schema.zig +13 -1
- package/src/primitives/canvas/ui_schema_tests.zig +11 -7
- package/src/primitives/canvas/ui_tests.zig +1 -0
- package/src/primitives/canvas/vector.zig +36 -2
- package/src/primitives/canvas/vector_effect_policy.zig +236 -0
- package/src/primitives/canvas/vector_raster_policy.zig +190 -0
- package/src/primitives/canvas/virtual_extent_policy.zig +292 -0
- package/src/primitives/canvas/virtual_extents.zig +99 -3
- package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
- package/src/primitives/canvas/widget_audit_policy.zig +293 -0
- package/src/primitives/canvas/widget_change_policy.zig +298 -0
- package/src/primitives/canvas/widget_invalidation.zig +113 -2
- package/src/primitives/canvas/widget_layout.zig +673 -128
- package/src/primitives/canvas/widget_layout_tests.zig +4 -0
- package/src/primitives/canvas/widget_metric_policy.zig +126 -0
- package/src/primitives/canvas/widget_metrics.zig +45 -6
- package/src/primitives/canvas/widget_paint_policy.zig +166 -0
- package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
- package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
- package/src/primitives/canvas/widget_render.zig +744 -74
- package/src/primitives/canvas/widget_render_controls.zig +1217 -133
- package/src/primitives/canvas/widget_render_scroll.zig +11 -3
- package/src/primitives/canvas/widget_render_style.zig +94 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
- package/src/primitives/canvas/widget_routing.zig +75 -0
- package/src/primitives/canvas/widget_routing_policy.zig +135 -0
- package/src/primitives/canvas/widget_runtime.zig +20 -1
- package/src/primitives/canvas/widget_semantics.zig +25 -0
- package/src/primitives/canvas/widget_text_input.zig +86 -23
- package/src/primitives/canvas/widget_text_select.zig +1 -0
- package/src/primitives/canvas/widget_tree.zig +8 -1
- package/src/primitives/canvas/widgets.zig +42 -12
- package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
- package/src/root.zig +21 -0
- package/src/runtime/accessibility_policy.zig +122 -0
- package/src/runtime/api.zig +28 -0
- package/src/runtime/app_dispatch_policy.zig +68 -0
- package/src/runtime/authorization_policy.zig +150 -0
- package/src/runtime/automation_command_policy.zig +241 -0
- package/src/runtime/automation_interaction_policy.zig +107 -0
- package/src/runtime/automation_snapshot.zig +52 -22
- package/src/runtime/automation_snapshot_reference.zig +290 -0
- package/src/runtime/automation_widget_dispatch.zig +267 -355
- package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
- package/src/runtime/blob_policy.zig +58 -0
- package/src/runtime/blob_reference.zig +64 -0
- package/src/runtime/bridge_descriptor_policy.zig +206 -0
- package/src/runtime/builtin_bridge.zig +180 -44
- package/src/runtime/builtin_coordination_policy.zig +121 -0
- package/src/runtime/callback_policy_test_reference.zig +97 -0
- package/src/runtime/canvas_drag_policy.zig +94 -0
- package/src/runtime/canvas_fonts.zig +38 -10
- package/src/runtime/canvas_frame.zig +590 -134
- package/src/runtime/canvas_frame_helpers.zig +1 -0
- package/src/runtime/canvas_hover_policy.zig +131 -0
- package/src/runtime/canvas_images.zig +59 -30
- package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
- package/src/runtime/canvas_limits.zig +1 -1
- package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
- package/src/runtime/canvas_scene_observation_policy.zig +181 -0
- package/src/runtime/canvas_widget_context_menu.zig +4 -4
- package/src/runtime/canvas_widget_display.zig +110 -9
- package/src/runtime/canvas_widget_events.zig +718 -328
- package/src/runtime/canvas_widget_runtime.zig +437 -81
- package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
- package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
- package/src/runtime/canvas_widget_state.zig +93 -56
- package/src/runtime/channel_sources.zig +80 -0
- package/src/runtime/command_policy.zig +161 -0
- package/src/runtime/component_policy.zig +83 -0
- package/src/runtime/core.zig +156 -6
- package/src/runtime/desktop_files.zig +189 -0
- package/src/runtime/effects.zig +466 -29
- package/src/runtime/effects_tests.zig +28 -0
- package/src/runtime/file_policy_test_reference.zig +113 -0
- package/src/runtime/flow.zig +418 -341
- package/src/runtime/flow_reference.zig +1426 -0
- package/src/runtime/font_registry_policy.zig +72 -0
- package/src/runtime/frame_profile.zig +24 -33
- package/src/runtime/gpu_surface_events.zig +97 -35
- package/src/runtime/host_event_pump.zig +303 -0
- package/src/runtime/host_event_pump_reference.zig +268 -0
- package/src/runtime/host_flow_policy.zig +155 -0
- package/src/runtime/host_input_regions_policy.zig +156 -0
- package/src/runtime/image_registry_policy.zig +94 -0
- package/src/runtime/input_composition_policy.zig +138 -0
- package/src/runtime/journal_policy.zig +66 -0
- package/src/runtime/journal_reference.zig +53 -0
- package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
- package/src/runtime/markup_development_policy.zig +91 -0
- package/src/runtime/media_surface.zig +40 -1
- package/src/runtime/motion_sampling_policy.zig +159 -0
- package/src/runtime/recording_policy.zig +42 -0
- package/src/runtime/render_animation_policy.zig +206 -0
- package/src/runtime/replay_policy.zig +66 -0
- package/src/runtime/replay_policy_reference.zig +326 -0
- package/src/runtime/replay_progress_policy.zig +64 -0
- package/src/runtime/replay_progress_reference.zig +34 -0
- package/src/runtime/request_policy_test_reference.zig +188 -0
- package/src/runtime/root.zig +13 -0
- package/src/runtime/session_blobs.zig +157 -58
- package/src/runtime/session_blobs_reference.zig +692 -0
- package/src/runtime/session_codec.zig +361 -0
- package/src/runtime/session_codec_reference.zig +1027 -0
- package/src/runtime/session_journal.zig +246 -983
- package/src/runtime/session_record.zig +224 -45
- package/src/runtime/session_replay.zig +157 -415
- package/src/runtime/session_tests.zig +552 -0
- package/src/runtime/shell_admission_policy.zig +225 -0
- package/src/runtime/shell_coordination_policy.zig +138 -0
- package/src/runtime/shell_layout.zig +126 -1
- package/src/runtime/snapshot_policy.zig +60 -0
- package/src/runtime/snapshot_reference.zig +64 -0
- package/src/runtime/state.zig +16 -0
- package/src/runtime/status_validation.zig +190 -0
- package/src/runtime/system_admission_policy.zig +140 -0
- package/src/runtime/system_services.zig +46 -36
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_canvas_hooks.zig +261 -0
- package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
- package/src/runtime/ts_canvas_icons.zig +234 -0
- package/src/runtime/ts_core_host.zig +2325 -411
- package/src/runtime/ts_core_host_tests.zig +1982 -0
- package/src/runtime/ts_test_host.zig +699 -0
- package/src/runtime/ts_ui_app.zig +1087 -45
- package/src/runtime/ui_app.zig +1117 -629
- package/src/runtime/ui_app_provenance.zig +147 -5
- package/src/runtime/ui_app_provenance_reference.zig +370 -0
- package/src/runtime/ui_app_tests.zig +619 -9
- package/src/runtime/ui_app_window_tests.zig +89 -0
- package/src/runtime/view.zig +25 -0
- package/src/runtime/view_canvas.zig +30 -6
- package/src/runtime/view_coordination_policy.zig +147 -0
- package/src/runtime/view_widget_control.zig +51 -14
- package/src/runtime/view_widget_scroll.zig +16 -5
- package/src/runtime/view_widget_text.zig +153 -68
- package/src/runtime/view_widget_tree.zig +460 -56
- package/src/runtime/webview_view_bridge_tests.zig +2 -0
- package/src/runtime/widget_motion_policy.zig +238 -0
- package/src/runtime/window_command_bridge_tests.zig +63 -0
- package/src/runtime/window_lifecycle_policy.zig +127 -0
- package/src/runtime/window_storage.zig +74 -8
- package/src/runtime/window_view_runtime.zig +148 -33
- package/src/runtime/window_views.zig +163 -10
- package/src/tooling/codesign.zig +125 -74
- package/src/tooling/components/identity_tests.zig +62 -36
- package/src/tooling/components/stepper.native +24 -0
- package/src/tooling/components/stepper.zig +0 -19
- package/src/tooling/components/timeline-item.native +22 -0
- package/src/tooling/components/timeline.native +5 -3
- package/src/tooling/components/timeline_item.zig +0 -32
- package/src/tooling/eject_components.zig +76 -8
- package/src/tooling/ios.zig +66 -12
- package/src/tooling/manifest.zig +35 -0
- package/src/tooling/package.zig +85 -1
- package/src/tooling/raw_manifest.zig +6 -0
- package/src/tooling/templates.zig +15 -3
- package/src/tooling/ts_core.zig +13 -3
- package/src/tooling/verbs.zig +22 -0
- package/tools/corewire/build_profile.mjs +54 -0
- package/tools/corewire/contract_intake.ts +303 -0
- package/tools/corewire/contract_intake.zig +82 -0
- package/tools/corewire/core.test.ts +166 -0
- package/tools/corewire/core_abi.zig +51 -0
- package/tools/corewire/core_cases.ts +233 -0
- package/tools/corewire/core_contract.ts +407 -0
- package/tools/corewire/core_emission.ts +136 -0
- package/tools/corewire/core_emission.zig +69 -0
- package/tools/corewire/core_goldens.json +3110 -0
- package/tools/corewire/core_policy.ts +14 -0
- package/tools/corewire/core_policy.zig +48 -0
- package/tools/corewire/core_projection.ts +360 -0
- package/tools/corewire/core_vocabulary.ts +6 -0
- package/tools/corewire/emit.zig +19 -1590
- package/tools/corewire/emit_facade.ts +714 -0
- package/tools/corewire/emit_facade.zig +10 -3752
- package/tools/corewire/emit_mirror.ts +290 -0
- package/tools/corewire/emit_profile.ts +50 -0
- package/tools/corewire/emit_service.ts +331 -0
- package/tools/corewire/emit_service.zig +23 -842
- package/tools/corewire/entry.test.ts +95 -0
- package/tools/corewire/entry_coordination.ts +127 -0
- package/tools/corewire/entry_coordination.zig +190 -0
- package/tools/corewire/facade_templates.ts +85 -0
- package/tools/corewire/filesystem.test.ts +166 -0
- package/tools/corewire/filesystem_coordination.ts +213 -0
- package/tools/corewire/filesystem_coordination.zig +245 -0
- package/tools/corewire/intake.test.ts +35 -0
- package/tools/corewire/intake_cases.ts +55 -0
- package/tools/corewire/intake_goldens.json +12237 -0
- package/tools/corewire/invocation.test.ts +24 -0
- package/tools/corewire/invocation.ts +175 -0
- package/tools/corewire/invocation.zig +136 -0
- package/tools/corewire/invocation_cases.ts +60 -0
- package/tools/corewire/invocation_fixture.ts +33 -0
- package/tools/corewire/invocation_goldens.json +1143 -0
- package/tools/corewire/invocation_tests.zig +111 -0
- package/tools/corewire/invocation_usage.ts +2 -0
- package/tools/corewire/lossless_projection.ts +96 -0
- package/tools/corewire/main.zig +7 -680
- package/tools/corewire/main_reference.zig +415 -0
- package/tools/corewire/mirror_templates.ts +55 -0
- package/tools/corewire/profile.test.ts +248 -0
- package/tools/corewire/profile.zig +56 -0
- package/tools/corewire/profile_emission.ts +202 -0
- package/tools/corewire/profile_library.json +29 -0
- package/tools/corewire/profile_tests.zig +136 -0
- package/tools/corewire/service.test.ts +75 -0
- package/tools/corewire/service_cases.ts +61 -0
- package/tools/corewire/service_contract.zig +40 -146
- package/tools/corewire/service_goldens.json +650 -0
- package/tools/corewire/service_projection.zig +52 -0
- package/tools/corewire/service_templates.ts +14 -0
- package/tools/corewire/shim_rt.zig +9 -0
- package/tools/corewire/sidecar.zig +267 -1438
- package/tools/corewire/emit_profile.zig +0 -521
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
//! payload-descriptor kind, a number class) is refused whole-file:
|
|
24
24
|
//! half-understanding a message arm is how wrong dispatch ships.
|
|
25
25
|
//!
|
|
26
|
-
//!
|
|
27
|
-
//!
|
|
26
|
+
//! Native owns JSON syntax and exact integer decoding. Schema admission is compiled from
|
|
27
|
+
//! TypeScript and tested with the same host archive the generator uses.
|
|
28
28
|
|
|
29
29
|
const std = @import("std");
|
|
30
30
|
|
|
@@ -34,7 +34,7 @@ pub const supported_format: i64 = 1;
|
|
|
34
34
|
/// The command-wire vocabulary generation the SDK's bridge speaks
|
|
35
35
|
/// (rt.zig `cmd_format_version`). A sidecar declaring a different
|
|
36
36
|
/// generation is refused at generate time.
|
|
37
|
-
pub const supported_wire_version: i64 =
|
|
37
|
+
pub const supported_wire_version: i64 = 10;
|
|
38
38
|
|
|
39
39
|
/// The C-ABI generation of the core entry points this generator binds
|
|
40
40
|
/// (core_abi.zig `abi_version`).
|
|
@@ -59,6 +59,32 @@ pub const TypeRef = union(enum) {
|
|
|
59
59
|
value: []const u8,
|
|
60
60
|
enum_ref: []const u8,
|
|
61
61
|
union_ref: []const u8,
|
|
62
|
+
|
|
63
|
+
pub fn jsonStringify(self: TypeRef, json: *std.json.Stringify) !void {
|
|
64
|
+
try json.beginObject();
|
|
65
|
+
try json.objectField("kind");
|
|
66
|
+
try json.write(switch (self) {
|
|
67
|
+
.enum_ref => "enum",
|
|
68
|
+
.union_ref => "union",
|
|
69
|
+
else => @tagName(self),
|
|
70
|
+
});
|
|
71
|
+
switch (self) {
|
|
72
|
+
.optional => |inner| {
|
|
73
|
+
try json.objectField("inner");
|
|
74
|
+
try json.write(inner.*);
|
|
75
|
+
},
|
|
76
|
+
.slice => |elem| {
|
|
77
|
+
try json.objectField("elem");
|
|
78
|
+
try json.write(elem.*);
|
|
79
|
+
},
|
|
80
|
+
.node, .value, .enum_ref, .union_ref => |name| {
|
|
81
|
+
try json.objectField("name");
|
|
82
|
+
try json.write(name);
|
|
83
|
+
},
|
|
84
|
+
else => {},
|
|
85
|
+
}
|
|
86
|
+
try json.endObject();
|
|
87
|
+
}
|
|
62
88
|
};
|
|
63
89
|
|
|
64
90
|
pub const Field = struct {
|
|
@@ -125,6 +151,36 @@ pub const Payload = union(enum) {
|
|
|
125
151
|
union_ref: []const u8,
|
|
126
152
|
enum_ref: []const u8,
|
|
127
153
|
scalar: TypeRef,
|
|
154
|
+
|
|
155
|
+
pub fn jsonStringify(self: Payload, json: *std.json.Stringify) !void {
|
|
156
|
+
try json.beginObject();
|
|
157
|
+
try json.objectField("kind");
|
|
158
|
+
try json.write(@tagName(self));
|
|
159
|
+
switch (self) {
|
|
160
|
+
.number => |class| {
|
|
161
|
+
try json.objectField("class");
|
|
162
|
+
try json.write(@tagName(class));
|
|
163
|
+
},
|
|
164
|
+
.number_bytes => |desc| {
|
|
165
|
+
try json.objectField("number_field");
|
|
166
|
+
try json.write(desc.number_field);
|
|
167
|
+
try json.objectField("number_class");
|
|
168
|
+
try json.write(@tagName(desc.number_class));
|
|
169
|
+
try json.objectField("bytes_field");
|
|
170
|
+
try json.write(desc.bytes_field);
|
|
171
|
+
},
|
|
172
|
+
.record, .union_ref, .enum_ref => |name| {
|
|
173
|
+
try json.objectField("name");
|
|
174
|
+
try json.write(name);
|
|
175
|
+
},
|
|
176
|
+
.scalar => |ref| {
|
|
177
|
+
try json.objectField("type");
|
|
178
|
+
try json.write(ref);
|
|
179
|
+
},
|
|
180
|
+
else => {},
|
|
181
|
+
}
|
|
182
|
+
try json.endObject();
|
|
183
|
+
}
|
|
128
184
|
};
|
|
129
185
|
|
|
130
186
|
pub const MsgArm = struct {
|
|
@@ -155,6 +211,7 @@ pub const EnvMsg = struct {
|
|
|
155
211
|
|
|
156
212
|
pub const Channels = struct {
|
|
157
213
|
command_msg: bool,
|
|
214
|
+
command_bytes: bool = false,
|
|
158
215
|
frame_msg: bool,
|
|
159
216
|
key_msg: bool,
|
|
160
217
|
pinch_msg: bool,
|
|
@@ -224,7 +281,7 @@ pub const Sidecar = struct {
|
|
|
224
281
|
/// init, collect, result reset), then the program's entry-point map
|
|
225
282
|
/// (core_abi.zig binds the matching extern signatures). The five
|
|
226
283
|
/// conditional channel-entry suffixes follow, present exactly when the
|
|
227
|
-
/// matching channel is wired.
|
|
284
|
+
/// matching channel is wired, then the optional compiled view extensions.
|
|
228
285
|
pub const unconditional_exports = [_][]const u8{
|
|
229
286
|
"abi_version",
|
|
230
287
|
"build_id",
|
|
@@ -253,9 +310,36 @@ pub const unconditional_exports = [_][]const u8{
|
|
|
253
310
|
pub const conditional_exports = [_][]const u8{
|
|
254
311
|
"command_msg",
|
|
255
312
|
"frame_msg",
|
|
313
|
+
"frame_msg_ns",
|
|
256
314
|
"key_msg",
|
|
257
315
|
"pinch_msg",
|
|
258
316
|
"drop_msg",
|
|
317
|
+
// Native SDK's opt-in compiled-view extension, after function channels.
|
|
318
|
+
"native_view",
|
|
319
|
+
"native_window_view",
|
|
320
|
+
"native_media_view",
|
|
321
|
+
"native_media_window_view",
|
|
322
|
+
"native_radio_policy",
|
|
323
|
+
"native_tabs_policy",
|
|
324
|
+
"native_tree_policy",
|
|
325
|
+
"native_list_policy",
|
|
326
|
+
"native_menu_policy",
|
|
327
|
+
"native_toggle_policy",
|
|
328
|
+
"native_accordion_policy",
|
|
329
|
+
"native_slider_policy",
|
|
330
|
+
"native_split_policy",
|
|
331
|
+
"native_scroll_policy",
|
|
332
|
+
"native_resizable_policy",
|
|
333
|
+
"native_text_policy",
|
|
334
|
+
"native_timer_policy",
|
|
335
|
+
"native_db_policy",
|
|
336
|
+
"native_effect_policy",
|
|
337
|
+
"native_stream_policy",
|
|
338
|
+
"native_window_policy",
|
|
339
|
+
"native_theme_policy",
|
|
340
|
+
"native_status_policy",
|
|
341
|
+
"native_virtual_requests",
|
|
342
|
+
"native_virtual_view",
|
|
259
343
|
};
|
|
260
344
|
|
|
261
345
|
// ------------------------------------------------------------ reading
|
|
@@ -325,666 +409,52 @@ pub const Diagnostics = struct {
|
|
|
325
409
|
/// diagnostics carry every teaching; the caller prints them and stops.
|
|
326
410
|
/// All returned memory lives in the caller's arena.
|
|
327
411
|
pub fn read(arena: std.mem.Allocator, source: []const u8, diags: *Diagnostics) error{ Refused, OutOfMemory }!Sidecar {
|
|
328
|
-
|
|
412
|
+
_ = std.json.parseFromSliceLeaky(std.json.Value, arena, source, .{}) catch |err| switch (err) {
|
|
329
413
|
// Memory pressure is not malformed input; keep the contract's
|
|
330
414
|
// error meanings honest.
|
|
331
415
|
error.OutOfMemory => return error.OutOfMemory,
|
|
332
416
|
else => return diags.fail("", "the sidecar is not valid JSON — it should be the core.contract.json a core-mode compile writes beside the compiled object", .{}),
|
|
333
417
|
};
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
418
|
+
const result = try @import("contract_intake.zig").evaluate(arena, source, "core");
|
|
419
|
+
for (result.diagnostics) |diagnostic| switch (diagnostic.severity) {
|
|
420
|
+
.@"error" => diags.flag(diagnostic.path, "{s}", .{diagnostic.message}),
|
|
421
|
+
.warning => diags.warn(diagnostic.path, "{s}", .{diagnostic.message}),
|
|
422
|
+
};
|
|
337
423
|
if (diags.hasErrors()) return error.Refused;
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
// ------------------------------------------------- JSON -> schema map
|
|
342
|
-
|
|
343
|
-
const Mapper = struct {
|
|
344
|
-
arena: std.mem.Allocator,
|
|
345
|
-
diags: *Diagnostics,
|
|
346
|
-
|
|
347
|
-
fn path(self: *Mapper, comptime fmt: []const u8, args: anytype) []const u8 {
|
|
348
|
-
return std.fmt.allocPrint(self.arena, fmt, args) catch "";
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
fn object(self: *Mapper, value: std.json.Value, at: []const u8) error{ Refused, OutOfMemory }!std.json.ObjectMap {
|
|
352
|
-
return switch (value) {
|
|
353
|
-
.object => |o| o,
|
|
354
|
-
else => self.diags.fail(at, "expected an object, found {s}", .{jsonKindName(value)}),
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
fn array(self: *Mapper, value: std.json.Value, at: []const u8) error{ Refused, OutOfMemory }!std.json.Array {
|
|
359
|
-
return switch (value) {
|
|
360
|
-
.array => |a| a,
|
|
361
|
-
else => self.diags.fail(at, "expected an array, found {s}", .{jsonKindName(value)}),
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
fn string(self: *Mapper, value: std.json.Value, at: []const u8) error{ Refused, OutOfMemory }![]const u8 {
|
|
366
|
-
return switch (value) {
|
|
367
|
-
.string => |s| s,
|
|
368
|
-
else => self.diags.fail(at, "expected a string, found {s}", .{jsonKindName(value)}),
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/// The ABI prefix rides straight into exported symbol spellings
|
|
373
|
-
/// (`@extern` names, linker entries), so it must be a symbol-safe
|
|
374
|
-
/// spelling: ASCII letters, digits, and underscores, not starting
|
|
375
|
-
/// with a digit. Anything else (an embedded NUL, unicode, spaces)
|
|
376
|
-
/// cannot be represented faithfully as an object-file symbol name.
|
|
377
|
-
fn symbolPrefix(self: *Mapper, value: std.json.Value, at: []const u8) error{ Refused, OutOfMemory }![]const u8 {
|
|
378
|
-
const text = try self.nonEmptyString(value, at);
|
|
379
|
-
for (text, 0..) |byte, index| {
|
|
380
|
-
const ok = byte == '_' or std.ascii.isAlphabetic(byte) or (index > 0 and std.ascii.isDigit(byte));
|
|
381
|
-
if (!ok) {
|
|
382
|
-
return self.diags.fail(at, "byte 0x{x:0>2} at offset {d} cannot appear in a linker symbol name — the prefix is spelled verbatim into every exported symbol; use ASCII letters, digits, and underscores, not starting with a digit", .{ byte, index });
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
return text;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
fn nonEmptyString(self: *Mapper, value: std.json.Value, at: []const u8) error{ Refused, OutOfMemory }![]const u8 {
|
|
389
|
-
const text = try self.string(value, at);
|
|
390
|
-
if (text.len == 0) return self.diags.fail(at, "expected a non-empty string", .{});
|
|
391
|
-
return text;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
fn boolean(self: *Mapper, value: std.json.Value, at: []const u8) error{ Refused, OutOfMemory }!bool {
|
|
395
|
-
return switch (value) {
|
|
396
|
-
.bool => |flag| flag,
|
|
397
|
-
else => self.diags.fail(at, "expected true or false, found {s}", .{jsonKindName(value)}),
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
fn integer(self: *Mapper, value: std.json.Value, at: []const u8) error{ Refused, OutOfMemory }!i64 {
|
|
402
|
-
return switch (value) {
|
|
403
|
-
.integer => |int| int,
|
|
404
|
-
else => self.diags.fail(at, "expected an integer, found {s}", .{jsonKindName(value)}),
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/// 64-bit hashes ride as strings of exactly 16 lowercase hex digits
|
|
409
|
-
/// (JSON interchange cannot carry a u64 exactly) — V2.
|
|
410
|
-
fn hash64(self: *Mapper, value: std.json.Value, at: []const u8) error{ Refused, OutOfMemory }!u64 {
|
|
411
|
-
const text = switch (value) {
|
|
412
|
-
.string => |s| s,
|
|
413
|
-
.integer, .float => return self.diags.fail(at, "64-bit hashes are encoded as strings of exactly 16 lowercase hex digits, never JSON numbers (JSON cannot carry a u64 exactly)", .{}),
|
|
414
|
-
else => return self.diags.fail(at, "expected a 16-lowercase-hex-digit string, found {s}", .{jsonKindName(value)}),
|
|
415
|
-
};
|
|
416
|
-
if (text.len != 16) {
|
|
417
|
-
return self.diags.fail(at, "expected exactly 16 lowercase hex digits, found {d} characters (\"{s}\")", .{ text.len, text });
|
|
418
|
-
}
|
|
419
|
-
for (text) |char| {
|
|
420
|
-
const ok = (char >= '0' and char <= '9') or (char >= 'a' and char <= 'f');
|
|
421
|
-
if (!ok) return self.diags.fail(at, "expected lowercase hex digits only, found '{c}' in \"{s}\"", .{ char, text });
|
|
422
|
-
}
|
|
423
|
-
return std.fmt.parseInt(u64, text, 16) catch unreachable;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
/// An OPTIONAL nonempty-string member: null when absent (additive
|
|
427
|
-
/// facts older emitters do not write), refused when present but not
|
|
428
|
-
/// a nonempty string.
|
|
429
|
-
fn optionalString(self: *Mapper, map: std.json.ObjectMap, name: []const u8, at: []const u8) error{ Refused, OutOfMemory }!?[]const u8 {
|
|
430
|
-
const value = map.get(name) orelse return null;
|
|
431
|
-
return try self.nonEmptyString(value, self.path("{s}.{s}", .{ at, name }));
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/// An additive boolean member with its compatibility default.
|
|
435
|
-
fn optionalBoolean(self: *Mapper, map: std.json.ObjectMap, name: []const u8, at: []const u8, default: bool) error{ Refused, OutOfMemory }!bool {
|
|
436
|
-
const value = map.get(name) orelse return default;
|
|
437
|
-
return try self.boolean(value, self.path("{s}.{s}", .{ at, name }));
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
fn stringList(self: *Mapper, value: std.json.Value, at: []const u8) error{ Refused, OutOfMemory }![]const []const u8 {
|
|
441
|
-
const items = try self.array(value, at);
|
|
442
|
-
const out = try self.arena.alloc([]const u8, items.items.len);
|
|
443
|
-
for (items.items, 0..) |item, index| {
|
|
444
|
-
out[index] = try self.nonEmptyString(item, self.path("{s}[{d}]", .{ at, index }));
|
|
445
|
-
}
|
|
446
|
-
return out;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
/// Fetch a required member; warn about (and skip) unknown members —
|
|
450
|
-
/// the additive forward-compat rule.
|
|
451
|
-
const Members = struct {
|
|
452
|
-
mapper: *Mapper,
|
|
453
|
-
map: std.json.ObjectMap,
|
|
454
|
-
at: []const u8,
|
|
455
|
-
known: []const []const u8,
|
|
456
|
-
|
|
457
|
-
fn get(self: *const Members, name: []const u8) error{ Refused, OutOfMemory }!std.json.Value {
|
|
458
|
-
return self.map.get(name) orelse self.mapper.diags.fail(
|
|
459
|
-
self.mapper.path("{s}{s}{s}", .{ self.at, if (self.at.len > 0) "." else "", name }),
|
|
460
|
-
"required field missing",
|
|
461
|
-
.{},
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
fn warnUnknown(self: *const Members) void {
|
|
466
|
-
var it = self.map.iterator();
|
|
467
|
-
outer: while (it.next()) |entry| {
|
|
468
|
-
for (self.known) |name| {
|
|
469
|
-
if (std.mem.eql(u8, entry.key_ptr.*, name)) continue :outer;
|
|
470
|
-
}
|
|
471
|
-
self.mapper.diags.warn(
|
|
472
|
-
self.mapper.path("{s}{s}{s}", .{ self.at, if (self.at.len > 0) "." else "", entry.key_ptr.* }),
|
|
473
|
-
"unknown field ignored (an emitter newer than this reader may emit additive facts)",
|
|
474
|
-
.{},
|
|
475
|
-
);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
424
|
+
var normalized = std.json.parseFromSliceLeaky(std.json.Value, arena, result.normalized, .{}) catch |err| switch (err) {
|
|
425
|
+
error.OutOfMemory => return error.OutOfMemory,
|
|
426
|
+
else => @panic("corewire: malformed normalized core contract"),
|
|
478
427
|
};
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
"init_returns_bare", "update_returns_bare", "has_subscriptions", "has_migrate", "channels",
|
|
490
|
-
"abi", "integer_slots", "deterministic", "async_free",
|
|
491
|
-
});
|
|
492
|
-
top.warnUnknown();
|
|
493
|
-
|
|
494
|
-
// The format fence comes first: nothing else in an unknown
|
|
495
|
-
// generation may be half-read.
|
|
496
|
-
const format = try self.integer(try top.get("format"), "format");
|
|
497
|
-
if (format != supported_format) {
|
|
498
|
-
return self.diags.fail("format", "this reader implements sidecar format {d}, found {d} — upgrade the SDK tooling or pin the compiler release that matches it", .{ supported_format, format });
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
const abi = try self.mapAbi(try top.get("abi"));
|
|
502
|
-
const channels = try self.mapChannels(try top.get("channels"), abiHasExport(abi, "drop_msg"));
|
|
503
|
-
return .{
|
|
504
|
-
.format = format,
|
|
505
|
-
.wire_version = try self.integer(try top.get("wire_version"), "wire_version"),
|
|
506
|
-
.abi_version = try self.integer(try top.get("abi_version"), "abi_version"),
|
|
507
|
-
.compiler_version = try self.nonEmptyString(try top.get("compiler_version"), "compiler_version"),
|
|
508
|
-
.entry = try self.nonEmptyString(try top.get("entry"), "entry"),
|
|
509
|
-
.source_hash = try self.hash64(try top.get("source_hash"), "source_hash"),
|
|
510
|
-
.build_id = try self.hash64(try top.get("build_id"), "build_id"),
|
|
511
|
-
.model_fingerprint = try self.hash64(try top.get("model_fingerprint"), "model_fingerprint"),
|
|
512
|
-
.types = try self.mapTypes(try top.get("types")),
|
|
513
|
-
.model = try self.nonEmptyString(try top.get("model"), "model"),
|
|
514
|
-
.model_helpers = try self.mapHelpers(try top.get("model_helpers")),
|
|
515
|
-
.model_unbound = try self.stringList(try top.get("model_unbound"), "model_unbound"),
|
|
516
|
-
.msg = try self.mapMsg(try top.get("msg")),
|
|
517
|
-
.init_returns_cmd = try self.boolean(try top.get("init_returns_cmd"), "init_returns_cmd"),
|
|
518
|
-
.update_returns_cmd = try self.boolean(try top.get("update_returns_cmd"), "update_returns_cmd"),
|
|
519
|
-
.init_returns_bare = try self.optionalBoolean(top.map, "init_returns_bare", "", false),
|
|
520
|
-
.update_returns_bare = try self.optionalBoolean(top.map, "update_returns_bare", "", false),
|
|
521
|
-
.has_subscriptions = try self.boolean(try top.get("has_subscriptions"), "has_subscriptions"),
|
|
522
|
-
.has_migrate = try self.boolean(try top.get("has_migrate"), "has_migrate"),
|
|
523
|
-
.channels = channels,
|
|
524
|
-
.abi = abi,
|
|
525
|
-
.integer_slots = try self.mapIntegerSlots(try top.get("integer_slots")),
|
|
526
|
-
.deterministic = try self.boolean(try top.get("deterministic"), "deterministic"),
|
|
527
|
-
.async_free = try self.boolean(try top.get("async_free"), "async_free"),
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
fn mapTypes(self: *Mapper, value: std.json.Value) error{ Refused, OutOfMemory }!Types {
|
|
532
|
-
const table = try self.members(value, "types", &.{ "structs", "enums", "unions" });
|
|
533
|
-
table.warnUnknown();
|
|
534
|
-
return .{
|
|
535
|
-
.structs = try self.mapStructs(try table.get("structs")),
|
|
536
|
-
.enums = try self.mapEnums(try table.get("enums")),
|
|
537
|
-
.unions = try self.mapUnions(try table.get("unions")),
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
fn mapStructs(self: *Mapper, value: std.json.Value) error{ Refused, OutOfMemory }![]const Struct {
|
|
542
|
-
const items = try self.array(value, "types.structs");
|
|
543
|
-
const out = try self.arena.alloc(Struct, items.items.len);
|
|
544
|
-
for (items.items, 0..) |item, index| {
|
|
545
|
-
const at = self.path("types.structs[{d}]", .{index});
|
|
546
|
-
// "synthesized" is an additive marker some emitters place on
|
|
547
|
-
// records they named themselves. The current projection uses
|
|
548
|
-
// `origin` as the authoritative authored-vs-synthesized fact and
|
|
549
|
-
// retains the name-pattern fallback for old null-origin sidecars,
|
|
550
|
-
// so this older marker remains accepted and unused.
|
|
551
|
-
const entry = try self.members(item, at, &.{ "name", "origin", "exported", "synthesized", "fields" });
|
|
552
|
-
entry.warnUnknown();
|
|
553
|
-
const fields_value = try self.array(try entry.get("fields"), self.path("{s}.fields", .{at}));
|
|
554
|
-
const fields = try self.arena.alloc(Field, fields_value.items.len);
|
|
555
|
-
for (fields_value.items, 0..) |field_value, field_index| {
|
|
556
|
-
const field_at = self.path("{s}.fields[{d}]", .{ at, field_index });
|
|
557
|
-
const field = try self.members(field_value, field_at, &.{ "name", "type" });
|
|
558
|
-
field.warnUnknown();
|
|
559
|
-
fields[field_index] = .{
|
|
560
|
-
.name = try self.nonEmptyString(try field.get("name"), self.path("{s}.name", .{field_at})),
|
|
561
|
-
.type = try self.mapTypeRef(try field.get("type"), self.path("{s}.type", .{field_at})),
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
out[index] = .{
|
|
565
|
-
.name = try self.nonEmptyString(try entry.get("name"), self.path("{s}.name", .{at})),
|
|
566
|
-
.origin = try self.optionalString(entry.map, "origin", at),
|
|
567
|
-
.exported = try self.optionalBoolean(entry.map, "exported", at, true),
|
|
568
|
-
.fields = fields,
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
return out;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
fn mapEnums(self: *Mapper, value: std.json.Value) error{ Refused, OutOfMemory }![]const Enum {
|
|
575
|
-
const items = try self.array(value, "types.enums");
|
|
576
|
-
const out = try self.arena.alloc(Enum, items.items.len);
|
|
577
|
-
for (items.items, 0..) |item, index| {
|
|
578
|
-
const at = self.path("types.enums[{d}]", .{index});
|
|
579
|
-
const entry = try self.members(item, at, &.{ "name", "origin", "exported", "members" });
|
|
580
|
-
entry.warnUnknown();
|
|
581
|
-
out[index] = .{
|
|
582
|
-
.name = try self.nonEmptyString(try entry.get("name"), self.path("{s}.name", .{at})),
|
|
583
|
-
.origin = try self.optionalString(entry.map, "origin", at),
|
|
584
|
-
.exported = try self.optionalBoolean(entry.map, "exported", at, true),
|
|
585
|
-
.members = try self.stringList(try entry.get("members"), self.path("{s}.members", .{at})),
|
|
586
|
-
};
|
|
587
|
-
}
|
|
588
|
-
return out;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
fn mapUnions(self: *Mapper, value: std.json.Value) error{ Refused, OutOfMemory }![]const Union {
|
|
592
|
-
const items = try self.array(value, "types.unions");
|
|
593
|
-
const out = try self.arena.alloc(Union, items.items.len);
|
|
594
|
-
for (items.items, 0..) |item, index| {
|
|
595
|
-
const at = self.path("types.unions[{d}]", .{index});
|
|
596
|
-
const entry = try self.members(item, at, &.{ "name", "origin", "exported", "arms" });
|
|
597
|
-
entry.warnUnknown();
|
|
598
|
-
const arms_value = try self.array(try entry.get("arms"), self.path("{s}.arms", .{at}));
|
|
599
|
-
const arms = try self.arena.alloc(UnionArm, arms_value.items.len);
|
|
600
|
-
for (arms_value.items, 0..) |arm_value, arm_index| {
|
|
601
|
-
const arm_at = self.path("{s}.arms[{d}]", .{ at, arm_index });
|
|
602
|
-
const arm = try self.members(arm_value, arm_at, &.{ "name", "member", "payload" });
|
|
603
|
-
arm.warnUnknown();
|
|
604
|
-
arms[arm_index] = .{
|
|
605
|
-
.name = try self.nonEmptyString(try arm.get("name"), self.path("{s}.name", .{arm_at})),
|
|
606
|
-
.member = try self.optionalString(arm.map, "member", arm_at),
|
|
607
|
-
.payload = try self.mapTypeRef(try arm.get("payload"), self.path("{s}.payload", .{arm_at})),
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
out[index] = .{
|
|
611
|
-
.name = try self.nonEmptyString(try entry.get("name"), self.path("{s}.name", .{at})),
|
|
612
|
-
.origin = try self.optionalString(entry.map, "origin", at),
|
|
613
|
-
.exported = try self.optionalBoolean(entry.map, "exported", at, true),
|
|
614
|
-
.arms = arms,
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
return out;
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
fn mapTypeRef(self: *Mapper, value: std.json.Value, at: []const u8) error{ Refused, OutOfMemory }!TypeRef {
|
|
621
|
-
return self.mapTypeRefDepth(value, at, 0);
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
/// Structural nesting rides the recursion, so it is bounded: no
|
|
625
|
-
/// real contract wraps a slot 256 levels deep, and past the bound a
|
|
626
|
-
/// document is refused instead of exhausting the stack.
|
|
627
|
-
const max_typeref_nesting = 256;
|
|
628
|
-
|
|
629
|
-
fn mapTypeRefDepth(self: *Mapper, value: std.json.Value, at: []const u8, depth: usize) error{ Refused, OutOfMemory }!TypeRef {
|
|
630
|
-
if (depth > max_typeref_nesting) {
|
|
631
|
-
return self.diags.fail(at, "TypeRef nesting exceeds {d} levels — no real contract wraps a slot this deep; flatten the state in the core source", .{max_typeref_nesting});
|
|
632
|
-
}
|
|
633
|
-
const map = try self.object(value, at);
|
|
634
|
-
const kind_value = map.get("kind") orelse return self.diags.fail(self.path("{s}.kind", .{at}), "required field missing (every TypeRef carries a kind discriminator)", .{});
|
|
635
|
-
const kind = try self.string(kind_value, self.path("{s}.kind", .{at}));
|
|
636
|
-
|
|
637
|
-
if (std.mem.eql(u8, kind, "bool")) {
|
|
638
|
-
(try self.members(value, at, &.{"kind"})).warnUnknown();
|
|
639
|
-
return .bool;
|
|
640
|
-
}
|
|
641
|
-
if (std.mem.eql(u8, kind, "f64")) {
|
|
642
|
-
(try self.members(value, at, &.{"kind"})).warnUnknown();
|
|
643
|
-
return .f64;
|
|
644
|
-
}
|
|
645
|
-
if (std.mem.eql(u8, kind, "i64")) {
|
|
646
|
-
(try self.members(value, at, &.{"kind"})).warnUnknown();
|
|
647
|
-
return .i64;
|
|
648
|
-
}
|
|
649
|
-
if (std.mem.eql(u8, kind, "bytes")) {
|
|
650
|
-
(try self.members(value, at, &.{"kind"})).warnUnknown();
|
|
651
|
-
return .bytes;
|
|
652
|
-
}
|
|
653
|
-
if (std.mem.eql(u8, kind, "void")) {
|
|
654
|
-
(try self.members(value, at, &.{"kind"})).warnUnknown();
|
|
655
|
-
return .void;
|
|
656
|
-
}
|
|
657
|
-
if (std.mem.eql(u8, kind, "optional")) {
|
|
658
|
-
const entry = try self.members(value, at, &.{ "kind", "inner" });
|
|
659
|
-
entry.warnUnknown();
|
|
660
|
-
const inner = try self.arena.create(TypeRef);
|
|
661
|
-
inner.* = try self.mapTypeRefDepth(try entry.get("inner"), self.path("{s}.inner", .{at}), depth + 1);
|
|
662
|
-
return .{ .optional = inner };
|
|
663
|
-
}
|
|
664
|
-
if (std.mem.eql(u8, kind, "slice")) {
|
|
665
|
-
const entry = try self.members(value, at, &.{ "kind", "elem" });
|
|
666
|
-
entry.warnUnknown();
|
|
667
|
-
const elem = try self.arena.create(TypeRef);
|
|
668
|
-
elem.* = try self.mapTypeRefDepth(try entry.get("elem"), self.path("{s}.elem", .{at}), depth + 1);
|
|
669
|
-
return .{ .slice = elem };
|
|
670
|
-
}
|
|
671
|
-
if (std.mem.eql(u8, kind, "node") or std.mem.eql(u8, kind, "value") or
|
|
672
|
-
std.mem.eql(u8, kind, "enum") or std.mem.eql(u8, kind, "union"))
|
|
673
|
-
{
|
|
674
|
-
const entry = try self.members(value, at, &.{ "kind", "name" });
|
|
675
|
-
entry.warnUnknown();
|
|
676
|
-
const name = try self.nonEmptyString(try entry.get("name"), self.path("{s}.name", .{at}));
|
|
677
|
-
if (std.mem.eql(u8, kind, "node")) return .{ .node = name };
|
|
678
|
-
if (std.mem.eql(u8, kind, "value")) return .{ .value = name };
|
|
679
|
-
if (std.mem.eql(u8, kind, "enum")) return .{ .enum_ref = name };
|
|
680
|
-
return .{ .union_ref = name };
|
|
681
|
-
}
|
|
682
|
-
return self.diags.fail(self.path("{s}.kind", .{at}), "unknown TypeRef kind \"{s}\" — this reader is too old for this sidecar; upgrade the SDK tooling or pin the compiler release it was built for", .{kind});
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
fn mapNumberClass(self: *Mapper, value: std.json.Value, at: []const u8) error{ Refused, OutOfMemory }!NumberClass {
|
|
686
|
-
const text = try self.string(value, at);
|
|
687
|
-
if (std.mem.eql(u8, text, "f64")) return .f64;
|
|
688
|
-
if (std.mem.eql(u8, text, "i64")) return .i64;
|
|
689
|
-
return self.diags.fail(at, "unknown number class \"{s}\" — the v1 classes are \"f64\" and \"i64\"; this reader is too old for anything else", .{text});
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
/// The integer_slots class vocabulary is its own closed set:
|
|
693
|
-
/// payload descriptors spell "f64"/"i64" (V7), attestations spell
|
|
694
|
-
/// "i64"/"u64" — the unsigned class exists only as a per-slot
|
|
695
|
-
/// verdict, never as a TypeRef or descriptor spelling.
|
|
696
|
-
fn mapIntegerClass(self: *Mapper, value: std.json.Value, at: []const u8) error{ Refused, OutOfMemory }!IntegerClass {
|
|
697
|
-
const text = try self.string(value, at);
|
|
698
|
-
if (std.mem.eql(u8, text, "i64")) return .i64;
|
|
699
|
-
if (std.mem.eql(u8, text, "u64")) return .u64;
|
|
700
|
-
if (std.mem.eql(u8, text, "f64")) {
|
|
701
|
-
return self.diags.fail(at, "integer_slots records the compiler's integer-class verdicts; class \"f64\" has no place here (f64 is the default class and is never attested)", .{});
|
|
702
|
-
}
|
|
703
|
-
return self.diags.fail(at, "unknown integer class \"{s}\" — the format-1 classes are \"i64\" and \"u64\"; this reader is too old for anything else", .{text});
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
fn mapHelpers(self: *Mapper, value: std.json.Value) error{ Refused, OutOfMemory }![]const Helper {
|
|
707
|
-
const items = try self.array(value, "model_helpers");
|
|
708
|
-
const out = try self.arena.alloc(Helper, items.items.len);
|
|
709
|
-
for (items.items, 0..) |item, index| {
|
|
710
|
-
const at = self.path("model_helpers[{d}]", .{index});
|
|
711
|
-
const entry = try self.members(item, at, &.{ "name", "params", "returns", "arena" });
|
|
712
|
-
entry.warnUnknown();
|
|
713
|
-
const params_value = try self.array(try entry.get("params"), self.path("{s}.params", .{at}));
|
|
714
|
-
const params = try self.arena.alloc(TypeRef, params_value.items.len);
|
|
715
|
-
for (params_value.items, 0..) |param, param_index| {
|
|
716
|
-
params[param_index] = try self.mapTypeRef(param, self.path("{s}.params[{d}]", .{ at, param_index }));
|
|
717
|
-
}
|
|
718
|
-
out[index] = .{
|
|
719
|
-
.name = try self.nonEmptyString(try entry.get("name"), self.path("{s}.name", .{at})),
|
|
720
|
-
.params = params,
|
|
721
|
-
.returns = try self.mapTypeRef(try entry.get("returns"), self.path("{s}.returns", .{at})),
|
|
722
|
-
.arena = try self.boolean(try entry.get("arena"), self.path("{s}.arena", .{at})),
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
return out;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
fn mapMsg(self: *Mapper, value: std.json.Value) error{ Refused, OutOfMemory }!Msg {
|
|
729
|
-
const entry = try self.members(value, "msg", &.{ "name", "arms", "unbound" });
|
|
730
|
-
entry.warnUnknown();
|
|
731
|
-
const arms_value = try self.array(try entry.get("arms"), "msg.arms");
|
|
732
|
-
const arms = try self.arena.alloc(MsgArm, arms_value.items.len);
|
|
733
|
-
for (arms_value.items, 0..) |arm_value, index| {
|
|
734
|
-
const at = self.path("msg.arms[{d}]", .{index});
|
|
735
|
-
const arm = try self.members(arm_value, at, &.{ "name", "member", "payload" });
|
|
736
|
-
arm.warnUnknown();
|
|
737
|
-
arms[index] = .{
|
|
738
|
-
.name = try self.nonEmptyString(try arm.get("name"), self.path("{s}.name", .{at})),
|
|
739
|
-
.member = try self.optionalString(arm.map, "member", at),
|
|
740
|
-
.payload = try self.mapPayload(try arm.get("payload"), self.path("{s}.payload", .{at})),
|
|
741
|
-
};
|
|
742
|
-
}
|
|
743
|
-
return .{
|
|
744
|
-
.name = try self.nonEmptyString(try entry.get("name"), "msg.name"),
|
|
745
|
-
.arms = arms,
|
|
746
|
-
.unbound = try self.stringList(try entry.get("unbound"), "msg.unbound"),
|
|
747
|
-
};
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
fn mapPayload(self: *Mapper, value: std.json.Value, at: []const u8) error{ Refused, OutOfMemory }!Payload {
|
|
751
|
-
const map = try self.object(value, at);
|
|
752
|
-
const kind_value = map.get("kind") orelse return self.diags.fail(self.path("{s}.kind", .{at}), "required field missing (every payload descriptor carries a kind discriminator)", .{});
|
|
753
|
-
const kind = try self.string(kind_value, self.path("{s}.kind", .{at}));
|
|
754
|
-
|
|
755
|
-
if (std.mem.eql(u8, kind, "void")) {
|
|
756
|
-
(try self.members(value, at, &.{"kind"})).warnUnknown();
|
|
757
|
-
return .void;
|
|
758
|
-
}
|
|
759
|
-
if (std.mem.eql(u8, kind, "bytes")) {
|
|
760
|
-
(try self.members(value, at, &.{"kind"})).warnUnknown();
|
|
761
|
-
return .bytes;
|
|
762
|
-
}
|
|
763
|
-
if (std.mem.eql(u8, kind, "number")) {
|
|
764
|
-
const entry = try self.members(value, at, &.{ "kind", "class" });
|
|
765
|
-
entry.warnUnknown();
|
|
766
|
-
return .{ .number = try self.mapNumberClass(try entry.get("class"), self.path("{s}.class", .{at})) };
|
|
767
|
-
}
|
|
768
|
-
if (std.mem.eql(u8, kind, "number_bytes")) {
|
|
769
|
-
const entry = try self.members(value, at, &.{ "kind", "number_field", "number_class", "bytes_field" });
|
|
770
|
-
entry.warnUnknown();
|
|
771
|
-
return .{ .number_bytes = .{
|
|
772
|
-
.number_field = try self.nonEmptyString(try entry.get("number_field"), self.path("{s}.number_field", .{at})),
|
|
773
|
-
.number_class = try self.mapNumberClass(try entry.get("number_class"), self.path("{s}.number_class", .{at})),
|
|
774
|
-
.bytes_field = try self.nonEmptyString(try entry.get("bytes_field"), self.path("{s}.bytes_field", .{at})),
|
|
775
|
-
} };
|
|
776
|
-
}
|
|
777
|
-
if (std.mem.eql(u8, kind, "record") or std.mem.eql(u8, kind, "union") or std.mem.eql(u8, kind, "enum")) {
|
|
778
|
-
const entry = try self.members(value, at, &.{ "kind", "name" });
|
|
779
|
-
entry.warnUnknown();
|
|
780
|
-
const name = try self.nonEmptyString(try entry.get("name"), self.path("{s}.name", .{at}));
|
|
781
|
-
if (std.mem.eql(u8, kind, "record")) return .{ .record = name };
|
|
782
|
-
if (std.mem.eql(u8, kind, "union")) return .{ .union_ref = name };
|
|
783
|
-
return .{ .enum_ref = name };
|
|
784
|
-
}
|
|
785
|
-
if (std.mem.eql(u8, kind, "scalar")) {
|
|
786
|
-
const entry = try self.members(value, at, &.{ "kind", "type" });
|
|
787
|
-
entry.warnUnknown();
|
|
788
|
-
return .{ .scalar = try self.mapTypeRef(try entry.get("type"), self.path("{s}.type", .{at})) };
|
|
789
|
-
}
|
|
790
|
-
return self.diags.fail(self.path("{s}.kind", .{at}), "unknown payload descriptor kind \"{s}\" — this reader is too old for this sidecar; upgrade the SDK tooling or pin the compiler release it was built for (half-understanding a message arm is how wrong dispatch ships)", .{kind});
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
fn mapChannels(self: *Mapper, value: std.json.Value, drop_default: bool) error{ Refused, OutOfMemory }!Channels {
|
|
794
|
-
const entry = try self.members(value, "channels", &.{
|
|
795
|
-
"command_msg", "frame_msg", "key_msg", "pinch_msg", "drop_msg", "appearance_msg", "chrome_msg", "env_msgs",
|
|
796
|
-
});
|
|
797
|
-
entry.warnUnknown();
|
|
798
|
-
const env_value = try self.array(try entry.get("env_msgs"), "channels.env_msgs");
|
|
799
|
-
const env_msgs = try self.arena.alloc(EnvMsg, env_value.items.len);
|
|
800
|
-
for (env_value.items, 0..) |item, index| {
|
|
801
|
-
const at = self.path("channels.env_msgs[{d}]", .{index});
|
|
802
|
-
const env_entry = try self.members(item, at, &.{ "env", "msg" });
|
|
803
|
-
env_entry.warnUnknown();
|
|
804
|
-
env_msgs[index] = .{
|
|
805
|
-
.env = try self.nonEmptyString(try env_entry.get("env"), self.path("{s}.env", .{at})),
|
|
806
|
-
.msg = try self.nonEmptyString(try env_entry.get("msg"), self.path("{s}.msg", .{at})),
|
|
807
|
-
};
|
|
808
|
-
}
|
|
809
|
-
return .{
|
|
810
|
-
.command_msg = try self.boolean(try entry.get("command_msg"), "channels.command_msg"),
|
|
811
|
-
.frame_msg = try self.boolean(try entry.get("frame_msg"), "channels.frame_msg"),
|
|
812
|
-
.key_msg = try self.boolean(try entry.get("key_msg"), "channels.key_msg"),
|
|
813
|
-
.pinch_msg = try self.boolean(try entry.get("pinch_msg"), "channels.pinch_msg"),
|
|
814
|
-
// Additive over the pinned compiler's format-1 emitter: older
|
|
815
|
-
// compilers preserve the profile-declared ABI export but do not
|
|
816
|
-
// know this channel fact yet, so the export list is its honest
|
|
817
|
-
// compatibility default. New frontend sidecars state it directly.
|
|
818
|
-
.drop_msg = try self.optionalBoolean(entry.map, "drop_msg", "channels", drop_default),
|
|
819
|
-
.appearance_msg = try self.armNameOrNull(try entry.get("appearance_msg"), "channels.appearance_msg"),
|
|
820
|
-
.chrome_msg = try self.armNameOrNull(try entry.get("chrome_msg"), "channels.chrome_msg"),
|
|
821
|
-
.env_msgs = env_msgs,
|
|
822
|
-
};
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
fn armNameOrNull(self: *Mapper, value: std.json.Value, at: []const u8) error{ Refused, OutOfMemory }!?[]const u8 {
|
|
826
|
-
return switch (value) {
|
|
827
|
-
.null => null,
|
|
828
|
-
.string => try self.nonEmptyString(value, at),
|
|
829
|
-
else => self.diags.fail(at, "expected null or a message arm name string, found {s}", .{jsonKindName(value)}),
|
|
830
|
-
};
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
fn mapAbi(self: *Mapper, value: std.json.Value) error{ Refused, OutOfMemory }!Abi {
|
|
834
|
-
const entry = try self.members(value, "abi", &.{ "prefix", "exports", "snapshot_format" });
|
|
835
|
-
entry.warnUnknown();
|
|
836
|
-
return .{
|
|
837
|
-
.prefix = try self.symbolPrefix(try entry.get("prefix"), "abi.prefix"),
|
|
838
|
-
.exports = try self.stringList(try entry.get("exports"), "abi.exports"),
|
|
839
|
-
.snapshot_format = try self.integer(try entry.get("snapshot_format"), "abi.snapshot_format"),
|
|
840
|
-
};
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
fn mapIntegerSlots(self: *Mapper, value: std.json.Value) error{ Refused, OutOfMemory }![]const IntegerSlot {
|
|
844
|
-
const items = try self.array(value, "integer_slots");
|
|
845
|
-
const out = try self.arena.alloc(IntegerSlot, items.items.len);
|
|
846
|
-
for (items.items, 0..) |item, index| {
|
|
847
|
-
const at = self.path("integer_slots[{d}]", .{index});
|
|
848
|
-
const entry = try self.members(item, at, &.{ "slot", "class" });
|
|
849
|
-
entry.warnUnknown();
|
|
850
|
-
out[index] = .{
|
|
851
|
-
.slot = try self.nonEmptyString(try entry.get("slot"), self.path("{s}.slot", .{at})),
|
|
852
|
-
.class = try self.mapIntegerClass(try entry.get("class"), self.path("{s}.class", .{at})),
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
return out;
|
|
856
|
-
}
|
|
857
|
-
};
|
|
858
|
-
|
|
859
|
-
fn jsonKindName(value: std.json.Value) []const u8 {
|
|
860
|
-
return switch (value) {
|
|
861
|
-
.null => "null",
|
|
862
|
-
.bool => "a boolean",
|
|
863
|
-
.integer => "a number",
|
|
864
|
-
.float => "a number",
|
|
865
|
-
.number_string => "a number",
|
|
866
|
-
.string => "a string",
|
|
867
|
-
.array => "an array",
|
|
868
|
-
.object => "an object",
|
|
428
|
+
// Hashes cross the compiled boundary as validated hexadecimal strings.
|
|
429
|
+
// Decode them exactly into native u64, never through a floating number.
|
|
430
|
+
for ([_][]const u8{ "source_hash", "build_id", "model_fingerprint" }) |name| {
|
|
431
|
+
const value = normalized.object.getPtr(name).?;
|
|
432
|
+
const hash = std.fmt.parseInt(u64, value.string, 16) catch @panic("corewire: invalid normalized hash");
|
|
433
|
+
value.* = .{ .number_string = std.fmt.allocPrint(arena, "{d}", .{hash}) catch return error.OutOfMemory };
|
|
434
|
+
}
|
|
435
|
+
const sidecar = std.json.parseFromValueLeaky(Sidecar, arena, normalized, .{ .allocate = .alloc_always }) catch |err| switch (err) {
|
|
436
|
+
error.OutOfMemory => return error.OutOfMemory,
|
|
437
|
+
else => @panic("corewire: malformed normalized core shape"),
|
|
869
438
|
};
|
|
439
|
+
try validate(arena, sidecar, diags);
|
|
440
|
+
if (diags.hasErrors()) return error.Refused;
|
|
441
|
+
return sidecar;
|
|
870
442
|
}
|
|
871
443
|
|
|
872
444
|
// --------------------------------------------------------- validation
|
|
873
445
|
//
|
|
874
|
-
//
|
|
875
|
-
//
|
|
876
|
-
//
|
|
877
|
-
//
|
|
878
|
-
//
|
|
879
|
-
//
|
|
880
|
-
//
|
|
881
|
-
//
|
|
882
|
-
//
|
|
883
|
-
// V6 tag density and arm bound — validateMsg (density is
|
|
884
|
-
// structural: tags are positions; the reader checks the bound).
|
|
885
|
-
// Source declaration order itself is only checkable against the
|
|
886
|
-
// source, i.e. by the emitter.
|
|
887
|
-
// V7 descriptor consistency — the mapper (classes) and
|
|
888
|
-
// validateMsg (field names,
|
|
889
|
-
// scalar shape).
|
|
890
|
-
// V8 unbound lists resolve — validateUnbound.
|
|
891
|
-
// V9 channel wiring — validateChannels.
|
|
892
|
-
// V10 integer-slot bijection — validateIntegerSlots: the
|
|
893
|
-
// one-to-one check both ways, plus structural resolution of every
|
|
894
|
-
// leftover entry's path (unresolvable, wrong spelling, or the
|
|
895
|
-
// grammar's slice-element gap each carry their own teaching).
|
|
896
|
-
// V11 export attestation — validateAbi checks the list
|
|
897
|
-
// against the profile's canonical vocabulary and order; the
|
|
898
|
-
// "exactly what the object exports" half needs the object and is
|
|
899
|
-
// enforced at link/boot time by the generated shim.
|
|
900
|
-
// V12 identity coherence — a boot-time check: the
|
|
901
|
-
// generated shim compares the sidecar's build_id against the
|
|
902
|
-
// object's identity getter before the first dispatch.
|
|
903
|
-
// V13 deterministic emission — an emitter-side property;
|
|
904
|
-
// the generator itself re-emits byte-identically from equal
|
|
905
|
-
// input (pinned by a test).
|
|
906
|
-
// V14 attestation honesty — an emitter-side property a
|
|
907
|
-
// reader cannot re-derive (the proof lives in the compiler; the
|
|
908
|
-
// sidecar records verdicts).
|
|
446
|
+
// Compiled intake enforces required fields, format, hashes, and the closed
|
|
447
|
+
// TypeRef/payload vocabularies (V1, V2, structural V7). core_contract.ts owns
|
|
448
|
+
// versions, names, reachability, cycles/depth, message bounds/descriptors,
|
|
449
|
+
// void positions, unbound lists, channel wiring, integer-slot bijection and
|
|
450
|
+
// canonical ABI export order (V3-V11). The owned result boundary preserves
|
|
451
|
+
// diagnostic order and exact native i64 version spellings.
|
|
452
|
+
// Identity and exported-symbol coherence are proved by the generated shim
|
|
453
|
+
// at link/boot (V11-V12). Complete output conformance proves deterministic
|
|
454
|
+
// emission (V13); compiler attestations retain their original ownership (V14).
|
|
909
455
|
|
|
910
456
|
fn validate(arena: std.mem.Allocator, sidecar: Sidecar, diags: *Diagnostics) error{OutOfMemory}!void {
|
|
911
|
-
|
|
912
|
-
try validateNames(arena, sidecar, diags);
|
|
913
|
-
// Reference checks assume the namespace is coherent; a broken
|
|
914
|
-
// namespace already carries its own teachings.
|
|
915
|
-
if (diags.hasErrors()) return;
|
|
916
|
-
try validateReferences(arena, sidecar, diags);
|
|
917
|
-
if (diags.hasErrors()) return;
|
|
918
|
-
try validateAcyclic(arena, sidecar, diags);
|
|
919
|
-
validateMsg(sidecar, diags);
|
|
920
|
-
validateVoidPositions(sidecar, diags);
|
|
921
|
-
validateUnbound(sidecar, diags);
|
|
922
|
-
validateChannels(sidecar, diags);
|
|
923
|
-
validateAbi(sidecar, diags);
|
|
924
|
-
try validateIntegerSlots(arena, sidecar, diags);
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
fn validateVersions(sidecar: Sidecar, diags: *Diagnostics) void {
|
|
928
|
-
if (sidecar.wire_version != supported_wire_version) {
|
|
929
|
-
diags.flag("wire_version", "this SDK's command-wire vocabulary is generation {d}, the sidecar declares {d} — the compiled core's effect builders speak a different wire; upgrade the SDK or pin the compiler release that matches it", .{ supported_wire_version, sidecar.wire_version });
|
|
930
|
-
}
|
|
931
|
-
if (sidecar.abi_version != supported_abi_version) {
|
|
932
|
-
diags.flag("abi_version", "this generator binds core ABI version {d}, the sidecar declares {d} — upgrade the SDK or pin the compiler release that matches it", .{ supported_abi_version, sidecar.abi_version });
|
|
933
|
-
}
|
|
934
|
-
if (sidecar.abi.snapshot_format != supported_snapshot_format) {
|
|
935
|
-
diags.flag("abi.snapshot_format", "this generator decodes snapshot format {d}, the sidecar declares {d} — upgrade the SDK or pin the compiler release that matches it", .{ supported_snapshot_format, sidecar.abi.snapshot_format });
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
const NameSet = std.StringArrayHashMapUnmanaged(void);
|
|
940
|
-
|
|
941
|
-
fn noteName(arena: std.mem.Allocator, set: *NameSet, name: []const u8, at: []const u8, what: []const u8, diags: *Diagnostics) error{OutOfMemory}!void {
|
|
942
|
-
const entry = try set.getOrPut(arena, name);
|
|
943
|
-
if (entry.found_existing) {
|
|
944
|
-
diags.flag(at, "duplicate {s} \"{s}\" — V3 requires unique names here", .{ what, name });
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
fn validateNames(arena: std.mem.Allocator, sidecar: Sidecar, diags: *Diagnostics) error{OutOfMemory}!void {
|
|
949
|
-
// One namespace across structs + enums + unions.
|
|
950
|
-
var table_names: NameSet = .empty;
|
|
951
|
-
for (sidecar.types.structs, 0..) |entry, index| {
|
|
952
|
-
try noteName(arena, &table_names, entry.name, pathOf(arena, "types.structs[{d}].name", .{index}), "type-table name", diags);
|
|
953
|
-
var field_names: NameSet = .empty;
|
|
954
|
-
for (entry.fields, 0..) |field, field_index| {
|
|
955
|
-
try noteName(arena, &field_names, field.name, pathOf(arena, "types.structs[{d}].fields[{d}].name", .{ index, field_index }), "field name", diags);
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
for (sidecar.types.enums, 0..) |entry, index| {
|
|
959
|
-
try noteName(arena, &table_names, entry.name, pathOf(arena, "types.enums[{d}].name", .{index}), "type-table name", diags);
|
|
960
|
-
var member_names: NameSet = .empty;
|
|
961
|
-
for (entry.members, 0..) |member, member_index| {
|
|
962
|
-
try noteName(arena, &member_names, member, pathOf(arena, "types.enums[{d}].members[{d}]", .{ index, member_index }), "enum member", diags);
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
for (sidecar.types.unions, 0..) |entry, index| {
|
|
966
|
-
try noteName(arena, &table_names, entry.name, pathOf(arena, "types.unions[{d}].name", .{index}), "type-table name", diags);
|
|
967
|
-
var arm_names: NameSet = .empty;
|
|
968
|
-
for (entry.arms, 0..) |arm, arm_index| {
|
|
969
|
-
try noteName(arena, &arm_names, arm.name, pathOf(arena, "types.unions[{d}].arms[{d}].name", .{ index, arm_index }), "union arm", diags);
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
var msg_arm_names: NameSet = .empty;
|
|
973
|
-
for (sidecar.msg.arms, 0..) |arm, index| {
|
|
974
|
-
try noteName(arena, &msg_arm_names, arm.name, pathOf(arena, "msg.arms[{d}].name", .{index}), "message arm", diags);
|
|
975
|
-
}
|
|
976
|
-
var helper_names: NameSet = .empty;
|
|
977
|
-
for (sidecar.model_helpers, 0..) |helper, index| {
|
|
978
|
-
try noteName(arena, &helper_names, helper.name, pathOf(arena, "model_helpers[{d}].name", .{index}), "helper name", diags);
|
|
979
|
-
}
|
|
980
|
-
var env_names: NameSet = .empty;
|
|
981
|
-
for (sidecar.channels.env_msgs, 0..) |entry, index| {
|
|
982
|
-
try noteName(arena, &env_names, entry.env, pathOf(arena, "channels.env_msgs[{d}].env", .{index}), "environment variable name", diags);
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
fn pathOf(arena: std.mem.Allocator, comptime fmt: []const u8, args: anytype) []const u8 {
|
|
987
|
-
return std.fmt.allocPrint(arena, fmt, args) catch "";
|
|
457
|
+
_ = try @import("core_policy.zig").apply(arena, sidecar, "core", diags);
|
|
988
458
|
}
|
|
989
459
|
|
|
990
460
|
pub const TableKind = enum { @"struct", @"enum", @"union" };
|
|
@@ -1017,390 +487,6 @@ pub fn findUnion(types: Types, name: []const u8) ?*const Union {
|
|
|
1017
487
|
return null;
|
|
1018
488
|
}
|
|
1019
489
|
|
|
1020
|
-
const Reach = struct {
|
|
1021
|
-
arena: std.mem.Allocator,
|
|
1022
|
-
types: Types,
|
|
1023
|
-
diags: *Diagnostics,
|
|
1024
|
-
seen: NameSet = .empty,
|
|
1025
|
-
/// The active visit's worklist, when a walk is in progress; a
|
|
1026
|
-
/// checkRef outside a walk visits directly.
|
|
1027
|
-
pending: ?*std.ArrayListUnmanaged([]const u8) = null,
|
|
1028
|
-
|
|
1029
|
-
fn enqueue(self: *Reach, name: []const u8) error{OutOfMemory}!void {
|
|
1030
|
-
if (self.pending) |worklist| {
|
|
1031
|
-
try worklist.append(self.arena, name);
|
|
1032
|
-
return;
|
|
1033
|
-
}
|
|
1034
|
-
try self.visit(name);
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
fn checkRef(self: *Reach, ref: TypeRef, at: []const u8) error{OutOfMemory}!void {
|
|
1038
|
-
switch (ref) {
|
|
1039
|
-
.bool, .f64, .i64, .bytes, .void => {},
|
|
1040
|
-
.optional => |inner| try self.checkRef(inner.*, at),
|
|
1041
|
-
.slice => |elem| try self.checkRef(elem.*, at),
|
|
1042
|
-
.node, .value => |name| {
|
|
1043
|
-
if (findStruct(self.types, name) == null) {
|
|
1044
|
-
self.wrongKind(name, .@"struct", at);
|
|
1045
|
-
return;
|
|
1046
|
-
}
|
|
1047
|
-
try self.enqueue(name);
|
|
1048
|
-
},
|
|
1049
|
-
.enum_ref => |name| {
|
|
1050
|
-
if (findEnum(self.types, name) == null) {
|
|
1051
|
-
self.wrongKind(name, .@"enum", at);
|
|
1052
|
-
return;
|
|
1053
|
-
}
|
|
1054
|
-
try self.enqueue(name);
|
|
1055
|
-
},
|
|
1056
|
-
.union_ref => |name| {
|
|
1057
|
-
if (findUnion(self.types, name) == null) {
|
|
1058
|
-
self.wrongKind(name, .@"union", at);
|
|
1059
|
-
return;
|
|
1060
|
-
}
|
|
1061
|
-
try self.enqueue(name);
|
|
1062
|
-
},
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
fn wrongKind(self: *Reach, name: []const u8, wanted: TableKind, at: []const u8) void {
|
|
1067
|
-
if (lookupKind(self.types, name)) |found| {
|
|
1068
|
-
self.diags.flag(at, "\"{s}\" names {s} {s} in the type table, but this reference requires {s} {s} — V4", .{
|
|
1069
|
-
name, articleOf(found), @tagName(found), articleOf(wanted), @tagName(wanted),
|
|
1070
|
-
});
|
|
1071
|
-
} else {
|
|
1072
|
-
self.diags.flag(at, "\"{s}\" names no entry in the type table (no struct, enum, or union declares it) — V4", .{name});
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
/// Iterative: named-type chains can be as long as the document
|
|
1077
|
-
/// allows, so the walk carries its own worklist instead of the
|
|
1078
|
-
/// process stack (structural nesting within one reference stays
|
|
1079
|
-
/// recursive under the reader's 256-level bound).
|
|
1080
|
-
fn visit(self: *Reach, root: []const u8) error{OutOfMemory}!void {
|
|
1081
|
-
var worklist: std.ArrayListUnmanaged([]const u8) = .empty;
|
|
1082
|
-
try worklist.append(self.arena, root);
|
|
1083
|
-
while (worklist.pop()) |name| {
|
|
1084
|
-
const entry = try self.seen.getOrPut(self.arena, name);
|
|
1085
|
-
if (entry.found_existing) continue;
|
|
1086
|
-
self.pending = &worklist;
|
|
1087
|
-
defer self.pending = null;
|
|
1088
|
-
if (findStruct(self.types, name)) |record| {
|
|
1089
|
-
for (record.fields, 0..) |field, index| {
|
|
1090
|
-
try self.checkRef(field.type, pathOf(self.arena, "types.structs.{s}.fields[{d}].type", .{ name, index }));
|
|
1091
|
-
}
|
|
1092
|
-
continue;
|
|
1093
|
-
}
|
|
1094
|
-
if (findUnion(self.types, name)) |tagged| {
|
|
1095
|
-
for (tagged.arms, 0..) |arm, index| {
|
|
1096
|
-
try self.checkRef(arm.payload, pathOf(self.arena, "types.unions.{s}.arms[{d}].payload", .{ name, index }));
|
|
1097
|
-
}
|
|
1098
|
-
continue;
|
|
1099
|
-
}
|
|
1100
|
-
// Enums carry no references.
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
};
|
|
1104
|
-
|
|
1105
|
-
fn articleOf(kind: TableKind) []const u8 {
|
|
1106
|
-
return switch (kind) {
|
|
1107
|
-
.@"enum" => "an",
|
|
1108
|
-
.@"struct", .@"union" => "a",
|
|
1109
|
-
};
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
fn validateReferences(arena: std.mem.Allocator, sidecar: Sidecar, diags: *Diagnostics) error{OutOfMemory}!void {
|
|
1113
|
-
var reach = Reach{ .arena = arena, .types = sidecar.types, .diags = diags };
|
|
1114
|
-
|
|
1115
|
-
// The roots: model, msg arms, helper signatures, channels (channel
|
|
1116
|
-
// arm names resolve against msg arms in validateChannels; they add
|
|
1117
|
-
// no type references of their own).
|
|
1118
|
-
if (findStruct(sidecar.types, sidecar.model) == null) {
|
|
1119
|
-
if (lookupKind(sidecar.types, sidecar.model)) |found| {
|
|
1120
|
-
diags.flag("model", "\"{s}\" names {s} {s} in the type table, but the model root must be a struct — V4", .{ sidecar.model, articleOf(found), @tagName(found) });
|
|
1121
|
-
} else {
|
|
1122
|
-
diags.flag("model", "\"{s}\" names no struct in the type table — V4", .{sidecar.model});
|
|
1123
|
-
}
|
|
1124
|
-
} else {
|
|
1125
|
-
try reach.visit(sidecar.model);
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
for (sidecar.msg.arms, 0..) |arm, index| {
|
|
1129
|
-
switch (arm.payload) {
|
|
1130
|
-
.void, .bytes, .number, .number_bytes => {},
|
|
1131
|
-
.record => |name| {
|
|
1132
|
-
if (findStruct(sidecar.types, name) == null) {
|
|
1133
|
-
reach.wrongKind(name, .@"struct", pathOf(arena, "msg.arms[{d}].payload.name", .{index}));
|
|
1134
|
-
} else try reach.visit(name);
|
|
1135
|
-
},
|
|
1136
|
-
.union_ref => |name| {
|
|
1137
|
-
if (findUnion(sidecar.types, name) == null) {
|
|
1138
|
-
reach.wrongKind(name, .@"union", pathOf(arena, "msg.arms[{d}].payload.name", .{index}));
|
|
1139
|
-
} else try reach.visit(name);
|
|
1140
|
-
},
|
|
1141
|
-
.enum_ref => |name| {
|
|
1142
|
-
if (findEnum(sidecar.types, name) == null) {
|
|
1143
|
-
reach.wrongKind(name, .@"enum", pathOf(arena, "msg.arms[{d}].payload.name", .{index}));
|
|
1144
|
-
} else try reach.visit(name);
|
|
1145
|
-
},
|
|
1146
|
-
.scalar => |ref| try reach.checkRef(ref, pathOf(arena, "msg.arms[{d}].payload.type", .{index})),
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
for (sidecar.model_helpers, 0..) |helper, index| {
|
|
1151
|
-
try reach.checkRef(helper.returns, pathOf(arena, "model_helpers[{d}].returns", .{index}));
|
|
1152
|
-
for (helper.params, 0..) |param, param_index| {
|
|
1153
|
-
try reach.checkRef(param, pathOf(arena, "model_helpers[{d}].params[{d}]", .{ index, param_index }));
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
// The table lists exactly the reachable types — nothing else (V4's
|
|
1158
|
-
// unreachable-entry half).
|
|
1159
|
-
for (sidecar.types.structs, 0..) |entry, index| {
|
|
1160
|
-
if (!reach.seen.contains(entry.name)) {
|
|
1161
|
-
diags.flag(pathOf(arena, "types.structs[{d}]", .{index}), "\"{s}\" is unreachable from model, msg, model_helpers, and channels — the type table lists exactly the reachable types, nothing else (V4)", .{entry.name});
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
for (sidecar.types.enums, 0..) |entry, index| {
|
|
1165
|
-
if (!reach.seen.contains(entry.name)) {
|
|
1166
|
-
diags.flag(pathOf(arena, "types.enums[{d}]", .{index}), "\"{s}\" is unreachable from model, msg, model_helpers, and channels — the type table lists exactly the reachable types, nothing else (V4)", .{entry.name});
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
for (sidecar.types.unions, 0..) |entry, index| {
|
|
1170
|
-
if (!reach.seen.contains(entry.name)) {
|
|
1171
|
-
diags.flag(pathOf(arena, "types.unions[{d}]", .{index}), "\"{s}\" is unreachable from model, msg, model_helpers, and channels — the type table lists exactly the reachable types, nothing else (V4)", .{entry.name});
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
fn validateAcyclic(arena: std.mem.Allocator, sidecar: Sidecar, diags: *Diagnostics) error{OutOfMemory}!void {
|
|
1177
|
-
// Iterative colored depth-first walk with an explicit frame stack:
|
|
1178
|
-
// any back edge is a cycle, and named-type chains deeper than the
|
|
1179
|
-
// reader's bound refuse instead of exhausting every downstream
|
|
1180
|
-
// consumer's call stack (recursive state types are refused at
|
|
1181
|
-
// compile time by the emitter; a sidecar carrying one is malformed,
|
|
1182
|
-
// and nothing real chains hundreds of record types).
|
|
1183
|
-
const max_chain_depth = 256;
|
|
1184
|
-
const State = enum { unvisited, on_stack, done };
|
|
1185
|
-
var states: std.StringArrayHashMapUnmanaged(State) = .empty;
|
|
1186
|
-
var depths: std.StringArrayHashMapUnmanaged(usize) = .empty;
|
|
1187
|
-
|
|
1188
|
-
const Frame = struct {
|
|
1189
|
-
name: []const u8,
|
|
1190
|
-
shape: EntryShape,
|
|
1191
|
-
next_edge: usize,
|
|
1192
|
-
};
|
|
1193
|
-
|
|
1194
|
-
var roots: std.ArrayListUnmanaged([]const u8) = .empty;
|
|
1195
|
-
for (sidecar.types.structs) |entry| try roots.append(arena, entry.name);
|
|
1196
|
-
for (sidecar.types.unions) |entry| try roots.append(arena, entry.name);
|
|
1197
|
-
|
|
1198
|
-
var depth_refused = false;
|
|
1199
|
-
for (roots.items) |root| {
|
|
1200
|
-
if ((states.get(root) orelse .unvisited) != .unvisited) continue;
|
|
1201
|
-
var stack: std.ArrayListUnmanaged(Frame) = .empty;
|
|
1202
|
-
try states.put(arena, root, .on_stack);
|
|
1203
|
-
try stack.append(arena, .{ .name = root, .shape = try entryShape(arena, sidecar.types, root), .next_edge = 0 });
|
|
1204
|
-
while (stack.items.len > 0) {
|
|
1205
|
-
const top = &stack.items[stack.items.len - 1];
|
|
1206
|
-
if (top.next_edge < top.shape.edges.len) {
|
|
1207
|
-
const child = top.shape.edges[top.next_edge].name;
|
|
1208
|
-
top.next_edge += 1;
|
|
1209
|
-
switch (states.get(child) orelse .unvisited) {
|
|
1210
|
-
.on_stack => {
|
|
1211
|
-
var cycle: std.ArrayListUnmanaged(u8) = .empty;
|
|
1212
|
-
var started = false;
|
|
1213
|
-
for (stack.items) |frame| {
|
|
1214
|
-
if (!started and !std.mem.eql(u8, frame.name, child)) continue;
|
|
1215
|
-
started = true;
|
|
1216
|
-
try cycle.appendSlice(arena, frame.name);
|
|
1217
|
-
try cycle.appendSlice(arena, " -> ");
|
|
1218
|
-
}
|
|
1219
|
-
try cycle.appendSlice(arena, child);
|
|
1220
|
-
diags.flag("types", "the type reference graph has a cycle ({s}) — recursive state types are refused at compile time and can never be encoded (V5)", .{cycle.items});
|
|
1221
|
-
return;
|
|
1222
|
-
},
|
|
1223
|
-
.done => {},
|
|
1224
|
-
.unvisited => {
|
|
1225
|
-
try states.put(arena, child, .on_stack);
|
|
1226
|
-
try stack.append(arena, .{ .name = child, .shape = try entryShape(arena, sidecar.types, child), .next_edge = 0 });
|
|
1227
|
-
},
|
|
1228
|
-
}
|
|
1229
|
-
continue;
|
|
1230
|
-
}
|
|
1231
|
-
// Post-order: the deepest fully expanded value tree under
|
|
1232
|
-
// this entry. Structural wrapping and named chains multiply
|
|
1233
|
-
// when counted separately, so the bound is on their sum —
|
|
1234
|
-
// the depth every downstream walk (encoders, emitters,
|
|
1235
|
-
// sample builders) actually recurses to.
|
|
1236
|
-
var deepest: usize = top.shape.leaf_levels;
|
|
1237
|
-
for (top.shape.edges) |edge| {
|
|
1238
|
-
deepest = @max(deepest, edge.wrap + (depths.get(edge.name) orelse 0));
|
|
1239
|
-
}
|
|
1240
|
-
const depth = deepest + 1;
|
|
1241
|
-
try depths.put(arena, top.name, depth);
|
|
1242
|
-
try states.put(arena, top.name, .done);
|
|
1243
|
-
if (depth > max_chain_depth and !depth_refused) {
|
|
1244
|
-
depth_refused = true;
|
|
1245
|
-
diags.flag("types", "the value tree under \"{s}\" expands deeper than {d} levels (record chains and optional/slice wrapping both count) — no real contract nests state this deep, and every consumer bounds its walks; flatten the state in the core source", .{ top.name, max_chain_depth });
|
|
1246
|
-
}
|
|
1247
|
-
_ = stack.pop();
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
/// One named-type edge leaving a table entry: the referenced name and
|
|
1253
|
-
/// the structural levels (optional/slice) wrapped around the reference
|
|
1254
|
-
/// at its use site.
|
|
1255
|
-
const Edge = struct { name: []const u8, wrap: usize };
|
|
1256
|
-
|
|
1257
|
-
const EntryShape = struct {
|
|
1258
|
-
edges: []const Edge,
|
|
1259
|
-
/// The deepest purely structural member (no named reference): its
|
|
1260
|
-
/// wrapper count plus the leaf itself.
|
|
1261
|
-
leaf_levels: usize,
|
|
1262
|
-
};
|
|
1263
|
-
|
|
1264
|
-
/// The shape of one table entry's members for depth accounting
|
|
1265
|
-
/// (structural nesting within a reference is bounded by the reader, so
|
|
1266
|
-
/// the collection recursion is bounded too).
|
|
1267
|
-
fn entryShape(arena: std.mem.Allocator, types: Types, name: []const u8) error{OutOfMemory}!EntryShape {
|
|
1268
|
-
var edges: std.ArrayListUnmanaged(Edge) = .empty;
|
|
1269
|
-
var leaf_levels: usize = 0;
|
|
1270
|
-
if (findStruct(types, name)) |record| {
|
|
1271
|
-
for (record.fields) |field| try measureRef(arena, &edges, &leaf_levels, field.type, 0);
|
|
1272
|
-
} else if (findUnion(types, name)) |tagged| {
|
|
1273
|
-
for (tagged.arms) |arm| try measureRef(arena, &edges, &leaf_levels, arm.payload, 0);
|
|
1274
|
-
}
|
|
1275
|
-
return .{ .edges = edges.items, .leaf_levels = leaf_levels };
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
fn measureRef(arena: std.mem.Allocator, edges: *std.ArrayListUnmanaged(Edge), leaf_levels: *usize, ref: TypeRef, wrap: usize) error{OutOfMemory}!void {
|
|
1279
|
-
switch (ref) {
|
|
1280
|
-
.bool, .f64, .i64, .bytes, .void, .enum_ref => leaf_levels.* = @max(leaf_levels.*, wrap + 1),
|
|
1281
|
-
.optional => |inner| try measureRef(arena, edges, leaf_levels, inner.*, wrap + 1),
|
|
1282
|
-
.slice => |elem| try measureRef(arena, edges, leaf_levels, elem.*, wrap + 1),
|
|
1283
|
-
.node, .value, .union_ref => |edge| try edges.append(arena, .{ .name = edge, .wrap = wrap }),
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
fn validateMsg(sidecar: Sidecar, diags: *Diagnostics) void {
|
|
1288
|
-
// Tags are positional and dense by construction — there is no
|
|
1289
|
-
// explicit tag field to get wrong. The reader checks the u8 bound,
|
|
1290
|
-
// and the floor: a valueless union or enum has no declarable mirror
|
|
1291
|
-
// form (`union(enum) {}` is not a type) and nothing could ever
|
|
1292
|
-
// dispatch or encode it.
|
|
1293
|
-
if (sidecar.msg.arms.len == 0) {
|
|
1294
|
-
diags.flag("msg.arms", "the message union declares no arms — a core with no messages cannot dispatch; declare at least one arm", .{});
|
|
1295
|
-
}
|
|
1296
|
-
if (sidecar.msg.arms.len > 256) {
|
|
1297
|
-
diags.flag("msg.arms", "{d} arms exceed the 256-arm bound (wire tags ride a u8) — V6", .{sidecar.msg.arms.len});
|
|
1298
|
-
}
|
|
1299
|
-
// The same u8 bound governs every tabled union (the canonical value
|
|
1300
|
-
// encoding carries a one-byte arm index), and the mirror's enums
|
|
1301
|
-
// ride enum(u8) with member index = wire value.
|
|
1302
|
-
for (sidecar.types.unions, 0..) |entry, index| {
|
|
1303
|
-
if (entry.arms.len == 0) {
|
|
1304
|
-
diags.flag(pathOfStatic(diags, "types.unions[{d}]", .{index}), "union \"{s}\" declares no arms — a valueless union has no mirror form; declare at least one arm", .{entry.name});
|
|
1305
|
-
}
|
|
1306
|
-
if (entry.arms.len > 256) {
|
|
1307
|
-
diags.flag(pathOfStatic(diags, "types.unions[{d}]", .{index}), "union \"{s}\" has {d} arms; encoded union values carry a one-byte declaration-order arm index (256 arms at most)", .{ entry.name, entry.arms.len });
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
for (sidecar.types.enums, 0..) |entry, index| {
|
|
1311
|
-
if (entry.members.len == 0) {
|
|
1312
|
-
diags.flag(pathOfStatic(diags, "types.enums[{d}]", .{index}), "enum \"{s}\" declares no members — a valueless enum has no mirror form; declare at least one member", .{entry.name});
|
|
1313
|
-
}
|
|
1314
|
-
if (entry.members.len > 256) {
|
|
1315
|
-
diags.flag(pathOfStatic(diags, "types.enums[{d}]", .{index}), "enum \"{s}\" has {d} members; the mirror's enums ride a u8 tag with member index = wire value (256 members at most)", .{ entry.name, entry.members.len });
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
for (sidecar.msg.arms, 0..) |arm, index| {
|
|
1319
|
-
switch (arm.payload) {
|
|
1320
|
-
.number_bytes => |desc| {
|
|
1321
|
-
if (std.mem.eql(u8, desc.number_field, desc.bytes_field)) {
|
|
1322
|
-
diags.flag(pathOfStatic(diags, "msg.arms[{d}].payload", .{index}), "number_field and bytes_field are both \"{s}\" — the two field names must be distinct (V7)", .{desc.number_field});
|
|
1323
|
-
}
|
|
1324
|
-
},
|
|
1325
|
-
.scalar => |ref| switch (ref) {
|
|
1326
|
-
.void => diags.flag(pathOfStatic(diags, "msg.arms[{d}].payload.type", .{index}), "a scalar descriptor cannot carry void — bare arms use the void descriptor kind (V7)", .{}),
|
|
1327
|
-
.node, .value => diags.flag(pathOfStatic(diags, "msg.arms[{d}].payload.type", .{index}), "a scalar descriptor cannot carry a record — record payloads use the record descriptor kind (V7)", .{}),
|
|
1328
|
-
else => {},
|
|
1329
|
-
},
|
|
1330
|
-
else => {},
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
fn pathOfStatic(diags: *Diagnostics, comptime fmt: []const u8, args: anytype) []const u8 {
|
|
1336
|
-
return std.fmt.allocPrint(diags.arena, fmt, args) catch "";
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
/// The void TypeRef means "no value" and exists for bare union arms
|
|
1340
|
-
/// only (the schema's stated scope); anywhere else the mirror would
|
|
1341
|
-
/// declare a valueless slot the snapshot encoding cannot carry.
|
|
1342
|
-
fn validateVoidPositions(sidecar: Sidecar, diags: *Diagnostics) void {
|
|
1343
|
-
for (sidecar.types.structs, 0..) |entry, index| {
|
|
1344
|
-
for (entry.fields, 0..) |field, field_index| {
|
|
1345
|
-
flagVoid(field.type, pathOfStatic(diags, "types.structs[{d}].fields[{d}].type", .{ index, field_index }), diags);
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
for (sidecar.types.unions, 0..) |entry, index| {
|
|
1349
|
-
for (entry.arms, 0..) |arm, arm_index| {
|
|
1350
|
-
// A bare void arm is the one sanctioned use; void NESTED
|
|
1351
|
-
// inside an arm's payload is not.
|
|
1352
|
-
if (arm.payload == .void) continue;
|
|
1353
|
-
flagVoid(arm.payload, pathOfStatic(diags, "types.unions[{d}].arms[{d}].payload", .{ index, arm_index }), diags);
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
for (sidecar.model_helpers, 0..) |helper, index| {
|
|
1357
|
-
flagVoid(helper.returns, pathOfStatic(diags, "model_helpers[{d}].returns", .{index}), diags);
|
|
1358
|
-
for (helper.params, 0..) |param, param_index| {
|
|
1359
|
-
flagVoid(param, pathOfStatic(diags, "model_helpers[{d}].params[{d}]", .{ index, param_index }), diags);
|
|
1360
|
-
}
|
|
1361
|
-
}
|
|
1362
|
-
for (sidecar.msg.arms, 0..) |arm, index| {
|
|
1363
|
-
switch (arm.payload) {
|
|
1364
|
-
.scalar => |ref| flagVoid(ref, pathOfStatic(diags, "msg.arms[{d}].payload.type", .{index}), diags),
|
|
1365
|
-
else => {},
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
fn flagVoid(ref: TypeRef, at: []const u8, diags: *Diagnostics) void {
|
|
1371
|
-
switch (ref) {
|
|
1372
|
-
.void => diags.flag(at, "the void TypeRef carries no value and is legal only as a bare union arm payload — this slot needs a value type", .{}),
|
|
1373
|
-
.optional => |inner| flagVoid(inner.*, at, diags),
|
|
1374
|
-
.slice => |elem| flagVoid(elem.*, at, diags),
|
|
1375
|
-
else => {},
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
fn validateUnbound(sidecar: Sidecar, diags: *Diagnostics) void {
|
|
1380
|
-
const model = findStruct(sidecar.types, sidecar.model) orelse return;
|
|
1381
|
-
// The opt-out vocabulary spans everything a view could bind on the
|
|
1382
|
-
// model: its fields AND its exported helpers (helpers surface as
|
|
1383
|
-
// bindable model methods, so an author can declare one
|
|
1384
|
-
// intentionally unbound). The schema's V8 wording says "field";
|
|
1385
|
-
// the reader accepts the helper case the dead-state lint actually
|
|
1386
|
-
// covers — see SCHEMA-GAPS.md.
|
|
1387
|
-
outer: for (sidecar.model_unbound, 0..) |name, index| {
|
|
1388
|
-
for (model.fields) |field| {
|
|
1389
|
-
if (std.mem.eql(u8, field.name, name)) continue :outer;
|
|
1390
|
-
}
|
|
1391
|
-
for (sidecar.model_helpers) |helper| {
|
|
1392
|
-
if (std.mem.eql(u8, helper.name, name)) continue :outer;
|
|
1393
|
-
}
|
|
1394
|
-
diags.flag(pathOfStatic(diags, "model_unbound[{d}]", .{index}), "\"{s}\" is neither a field of the model struct \"{s}\" nor an exported helper (V8)", .{ name, sidecar.model });
|
|
1395
|
-
}
|
|
1396
|
-
outer: for (sidecar.msg.unbound, 0..) |name, index| {
|
|
1397
|
-
for (sidecar.msg.arms) |arm| {
|
|
1398
|
-
if (std.mem.eql(u8, arm.name, name)) continue :outer;
|
|
1399
|
-
}
|
|
1400
|
-
diags.flag(pathOfStatic(diags, "msg.unbound[{d}]", .{index}), "\"{s}\" is not an arm of the message union (V8)", .{name});
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
490
|
pub fn findArm(msg: Msg, name: []const u8) ?*const MsgArm {
|
|
1405
491
|
for (msg.arms) |*arm| {
|
|
1406
492
|
if (std.mem.eql(u8, arm.name, name)) return arm;
|
|
@@ -1408,419 +494,20 @@ pub fn findArm(msg: Msg, name: []const u8) ?*const MsgArm {
|
|
|
1408
494
|
return null;
|
|
1409
495
|
}
|
|
1410
496
|
|
|
1411
|
-
fn
|
|
1412
|
-
return abiHasExport(sidecar.abi, suffix);
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
fn abiHasExport(abi: Abi, suffix: []const u8) bool {
|
|
497
|
+
pub fn abiHasExport(abi: Abi, suffix: []const u8) bool {
|
|
1416
498
|
for (abi.exports) |entry| {
|
|
1417
499
|
if (std.mem.eql(u8, entry, suffix)) return true;
|
|
1418
500
|
}
|
|
1419
501
|
return false;
|
|
1420
502
|
}
|
|
1421
503
|
|
|
1422
|
-
fn validateChannels(sidecar: Sidecar, diags: *Diagnostics) void {
|
|
1423
|
-
const record_channels = [_]struct { name: []const u8, arm: ?[]const u8 }{
|
|
1424
|
-
.{ .name = "appearance_msg", .arm = sidecar.channels.appearance_msg },
|
|
1425
|
-
.{ .name = "chrome_msg", .arm = sidecar.channels.chrome_msg },
|
|
1426
|
-
};
|
|
1427
|
-
for (record_channels) |channel| {
|
|
1428
|
-
const arm_name = channel.arm orelse continue;
|
|
1429
|
-
const at = pathOfStatic(diags, "channels.{s}", .{channel.name});
|
|
1430
|
-
const arm = findArm(sidecar.msg, arm_name) orelse {
|
|
1431
|
-
diags.flag(at, "\"{s}\" names no arm of the message union (V9)", .{arm_name});
|
|
1432
|
-
continue;
|
|
1433
|
-
};
|
|
1434
|
-
switch (arm.payload) {
|
|
1435
|
-
.record, .union_ref, .enum_ref, .scalar => {},
|
|
1436
|
-
else => diags.flag(at, "arm \"{s}\" has a {s} payload descriptor, but this channel requires the named-type family (record/union/enum/scalar) — the host constructs the arm's payload itself, so it must learn the shape from the type table (V9)", .{ arm_name, @tagName(arm.payload) }),
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
outer: for (sidecar.channels.env_msgs, 0..) |entry, index| {
|
|
1441
|
-
const at = pathOfStatic(diags, "channels.env_msgs[{d}].msg", .{index});
|
|
1442
|
-
const arm = findArm(sidecar.msg, entry.msg) orelse {
|
|
1443
|
-
diags.flag(at, "\"{s}\" names no arm of the message union (V9)", .{entry.msg});
|
|
1444
|
-
continue :outer;
|
|
1445
|
-
};
|
|
1446
|
-
if (arm.payload != .bytes) {
|
|
1447
|
-
diags.flag(at, "arm \"{s}\" has a {s} payload descriptor, but environment channels deliver the variable's value as bytes, so the target arm's descriptor must be bytes (V9)", .{ entry.msg, @tagName(arm.payload) });
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
|
-
const function_channels = [_]struct { name: []const u8, wired: bool }{
|
|
1452
|
-
.{ .name = "command_msg", .wired = sidecar.channels.command_msg },
|
|
1453
|
-
.{ .name = "frame_msg", .wired = sidecar.channels.frame_msg },
|
|
1454
|
-
.{ .name = "key_msg", .wired = sidecar.channels.key_msg },
|
|
1455
|
-
.{ .name = "pinch_msg", .wired = sidecar.channels.pinch_msg },
|
|
1456
|
-
.{ .name = "drop_msg", .wired = sidecar.channels.drop_msg },
|
|
1457
|
-
};
|
|
1458
|
-
for (function_channels) |channel| {
|
|
1459
|
-
const listed = exportListed(sidecar, channel.name);
|
|
1460
|
-
if (channel.wired and !listed) {
|
|
1461
|
-
diags.flag(pathOfStatic(diags, "channels.{s}", .{channel.name}), "the channel is declared wired but \"{s}\" is missing from abi.exports — presence is biconditional (V9)", .{channel.name});
|
|
1462
|
-
}
|
|
1463
|
-
if (!channel.wired and listed) {
|
|
1464
|
-
diags.flag("abi.exports", "\"{s}\" is listed but channels.{s} is false — presence is biconditional (V9)", .{ channel.name, channel.name });
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
|
|
1469
|
-
fn validateAbi(sidecar: Sidecar, diags: *Diagnostics) void {
|
|
1470
|
-
// The list must be exactly: every unconditional suffix, then the
|
|
1471
|
-
// wired conditional suffixes, in the normative canonical order —
|
|
1472
|
-
// identity getters, mode-provided entries (set_panic_sink, init,
|
|
1473
|
-
// collect, frame_reset), then the entry-point map. The "and the
|
|
1474
|
-
// object exports nothing else" half needs the object and runs at
|
|
1475
|
-
// link time.
|
|
1476
|
-
var cursor: usize = 0;
|
|
1477
|
-
for (unconditional_exports) |suffix| {
|
|
1478
|
-
if (cursor < sidecar.abi.exports.len and std.mem.eql(u8, sidecar.abi.exports[cursor], suffix)) {
|
|
1479
|
-
cursor += 1;
|
|
1480
|
-
} else {
|
|
1481
|
-
diags.flag(pathOfStatic(diags, "abi.exports[{d}]", .{cursor}), "expected the unconditional export \"{s}\" here — abi.exports lists every unconditional suffix, then the wired channel entries, in the canonical order: identity getters (abi_version, build_id), the mode-provided entries (set_panic_sink, init, collect, frame_reset), then the entry-point map (V11)", .{suffix});
|
|
1482
|
-
return;
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
for (conditional_exports) |suffix| {
|
|
1486
|
-
if (cursor < sidecar.abi.exports.len and std.mem.eql(u8, sidecar.abi.exports[cursor], suffix)) {
|
|
1487
|
-
cursor += 1;
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
if (cursor < sidecar.abi.exports.len) {
|
|
1491
|
-
diags.flag(pathOfStatic(diags, "abi.exports[{d}]", .{cursor}), "\"{s}\" is not an export suffix of ABI version {d} (or is out of canonical order) — V11", .{ sidecar.abi.exports[cursor], supported_abi_version });
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
|
|
1495
|
-
pub const SlotPath = struct {
|
|
1496
|
-
path: []const u8,
|
|
1497
|
-
/// Whether any joined component itself contains a dot (the grammar
|
|
1498
|
-
/// cannot address such a slot unambiguously).
|
|
1499
|
-
components_dotted: bool,
|
|
1500
|
-
};
|
|
1501
|
-
|
|
1502
|
-
fn dotted(names: []const []const u8) bool {
|
|
1503
|
-
for (names) |name| {
|
|
1504
|
-
if (std.mem.indexOfScalar(u8, name, '.') != null) return true;
|
|
1505
|
-
}
|
|
1506
|
-
return false;
|
|
1507
|
-
}
|
|
1508
|
-
|
|
1509
|
-
/// The slot spellings V10's bijection is checked against: every i64
|
|
1510
|
-
/// spelling in the sidecar, at its schema-defined slot path.
|
|
1511
|
-
pub fn collectIntegerSlotPaths(arena: std.mem.Allocator, sidecar: Sidecar) error{OutOfMemory}![]const SlotPath {
|
|
1512
|
-
var paths: std.ArrayListUnmanaged(SlotPath) = .empty;
|
|
1513
|
-
for (sidecar.types.structs) |entry| {
|
|
1514
|
-
for (entry.fields) |field| {
|
|
1515
|
-
if (spellsInteger(field.type)) {
|
|
1516
|
-
try paths.append(arena, .{ .path = try std.fmt.allocPrint(arena, "{s}.{s}", .{ entry.name, field.name }), .components_dotted = dotted(&.{ entry.name, field.name }) });
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
|
-
for (sidecar.types.unions) |entry| {
|
|
1521
|
-
for (entry.arms) |arm| {
|
|
1522
|
-
if (spellsInteger(arm.payload)) {
|
|
1523
|
-
try paths.append(arena, .{ .path = try std.fmt.allocPrint(arena, "{s}.{s}", .{ entry.name, arm.name }), .components_dotted = dotted(&.{ entry.name, arm.name }) });
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
// The message-side path forms spell the union's AUTHORED name —
|
|
1528
|
-
// an app whose union is named Action spells its slots
|
|
1529
|
-
// `Action.<arm>`, never a literal `Msg` token.
|
|
1530
|
-
for (sidecar.msg.arms) |arm| {
|
|
1531
|
-
switch (arm.payload) {
|
|
1532
|
-
.number => |class| if (class == .i64) {
|
|
1533
|
-
try paths.append(arena, .{ .path = try std.fmt.allocPrint(arena, "{s}.{s}", .{ sidecar.msg.name, arm.name }), .components_dotted = dotted(&.{ sidecar.msg.name, arm.name }) });
|
|
1534
|
-
},
|
|
1535
|
-
.number_bytes => |desc| if (desc.number_class == .i64) {
|
|
1536
|
-
try paths.append(arena, .{ .path = try std.fmt.allocPrint(arena, "{s}.{s}.{s}", .{ sidecar.msg.name, arm.name, desc.number_field }), .components_dotted = dotted(&.{ sidecar.msg.name, arm.name, desc.number_field }) });
|
|
1537
|
-
},
|
|
1538
|
-
.scalar => |ref| if (spellsInteger(ref)) {
|
|
1539
|
-
try paths.append(arena, .{ .path = try std.fmt.allocPrint(arena, "{s}.{s}", .{ sidecar.msg.name, arm.name }), .components_dotted = dotted(&.{ sidecar.msg.name, arm.name }) });
|
|
1540
|
-
},
|
|
1541
|
-
else => {},
|
|
1542
|
-
}
|
|
1543
|
-
}
|
|
1544
|
-
for (sidecar.model_helpers) |helper| {
|
|
1545
|
-
if (spellsInteger(helper.returns)) {
|
|
1546
|
-
try paths.append(arena, .{ .path = try std.fmt.allocPrint(arena, "helpers.{s}.return", .{helper.name}), .components_dotted = dotted(&.{helper.name}) });
|
|
1547
|
-
}
|
|
1548
|
-
for (helper.params, 0..) |param, index| {
|
|
1549
|
-
if (spellsInteger(param)) {
|
|
1550
|
-
try paths.append(arena, .{ .path = try std.fmt.allocPrint(arena, "helpers.{s}.params[{d}]", .{ helper.name, index }), .components_dotted = dotted(&.{helper.name}) });
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
return paths.items;
|
|
1555
|
-
}
|
|
1556
|
-
|
|
1557
|
-
/// Whether a TypeRef spells i64 at its own slot (through optionals; a
|
|
1558
|
-
/// slice element is its own slot grammar problem and the schema defines
|
|
1559
|
-
/// no path for it, so a slice of i64 cannot be attested — the emitter
|
|
1560
|
-
/// spells such elements f64 until the schema grows a path form).
|
|
1561
|
-
fn spellsInteger(ref: TypeRef) bool {
|
|
1562
|
-
return switch (ref) {
|
|
1563
|
-
.i64 => true,
|
|
1564
|
-
.optional => |inner| spellsInteger(inner.*),
|
|
1565
|
-
else => false,
|
|
1566
|
-
};
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
/// What an `integer_slots` entry's path names once resolved against the
|
|
1570
|
-
/// sidecar's own tables under the format-1 slot-path grammar.
|
|
1571
|
-
pub const SlotTarget = union(enum) {
|
|
1572
|
-
/// A slot the sidecar spells i64 — an attestable target.
|
|
1573
|
-
integer,
|
|
1574
|
-
/// A real slot, spelled or classed as described — not attestable.
|
|
1575
|
-
not_integer: []const u8,
|
|
1576
|
-
/// A sequence whose elements spell an integer: the format-1 grammar
|
|
1577
|
-
/// has no slice-element form, so no path can attest it.
|
|
1578
|
-
slice_element,
|
|
1579
|
-
/// No grammar form reaches a slot of this spelling.
|
|
1580
|
-
unresolved,
|
|
1581
|
-
};
|
|
1582
|
-
|
|
1583
|
-
fn refSpelling(ref: TypeRef) []const u8 {
|
|
1584
|
-
return switch (ref) {
|
|
1585
|
-
.bool => "bool",
|
|
1586
|
-
.f64 => "f64",
|
|
1587
|
-
.i64 => "i64",
|
|
1588
|
-
.bytes => "bytes",
|
|
1589
|
-
.void => "void",
|
|
1590
|
-
.optional => |inner| refSpelling(inner.*),
|
|
1591
|
-
.slice => "a slice",
|
|
1592
|
-
.node, .value => "a record",
|
|
1593
|
-
.enum_ref => "an enum",
|
|
1594
|
-
.union_ref => "a union",
|
|
1595
|
-
};
|
|
1596
|
-
}
|
|
1597
|
-
|
|
1598
|
-
fn wrapsInteger(ref: TypeRef) bool {
|
|
1599
|
-
return switch (ref) {
|
|
1600
|
-
.i64 => true,
|
|
1601
|
-
.optional => |inner| wrapsInteger(inner.*),
|
|
1602
|
-
.slice => |elem| wrapsInteger(elem.*),
|
|
1603
|
-
else => false,
|
|
1604
|
-
};
|
|
1605
|
-
}
|
|
1606
|
-
|
|
1607
|
-
/// Classify the TypeRef a resolved path lands on: i64 through optionals
|
|
1608
|
-
/// is the attestable shape; an integer buried under a slice is the
|
|
1609
|
-
/// grammar's known gap; everything else is a real slot of another
|
|
1610
|
-
/// spelling.
|
|
1611
|
-
fn classifyRef(ref: TypeRef) SlotTarget {
|
|
1612
|
-
return switch (ref) {
|
|
1613
|
-
.i64 => .integer,
|
|
1614
|
-
.optional => |inner| classifyRef(inner.*),
|
|
1615
|
-
.slice => |elem| if (wrapsInteger(elem.*)) .slice_element else .{ .not_integer = "a slice" },
|
|
1616
|
-
else => .{ .not_integer = refSpelling(ref) },
|
|
1617
|
-
};
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
|
-
fn classifyNumberClass(class: NumberClass) SlotTarget {
|
|
1621
|
-
return switch (class) {
|
|
1622
|
-
.i64 => .integer,
|
|
1623
|
-
.f64 => .{ .not_integer = "f64" },
|
|
1624
|
-
};
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
/// Resolve one slot path against the sidecar's tables. The grammar's
|
|
1628
|
-
/// forms, each segment the author's spelling: `<TypeName>.<field>` (a
|
|
1629
|
-
/// struct field, or a non-msg union arm's payload),
|
|
1630
|
-
/// `<msgName>.<arm>` (a scalar-number arm), `<msgName>.<arm>.<field>`
|
|
1631
|
-
/// (a number_bytes arm's number field), `helpers.<name>.return`, and
|
|
1632
|
-
/// `helpers.<name>.params[<index>]`.
|
|
1633
|
-
pub fn resolveSlotPath(sidecar: Sidecar, path: []const u8) SlotTarget {
|
|
1634
|
-
var segments: [4][]const u8 = undefined;
|
|
1635
|
-
var count: usize = 0;
|
|
1636
|
-
var it = std.mem.splitScalar(u8, path, '.');
|
|
1637
|
-
while (it.next()) |segment| {
|
|
1638
|
-
if (segment.len == 0) return .unresolved;
|
|
1639
|
-
if (count == segments.len) return .unresolved;
|
|
1640
|
-
segments[count] = segment;
|
|
1641
|
-
count += 1;
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
if (count == 3 and std.mem.eql(u8, segments[0], "helpers")) {
|
|
1645
|
-
for (sidecar.model_helpers) |helper| {
|
|
1646
|
-
if (!std.mem.eql(u8, helper.name, segments[1])) continue;
|
|
1647
|
-
if (std.mem.eql(u8, segments[2], "return")) return classifyRef(helper.returns);
|
|
1648
|
-
if (std.mem.startsWith(u8, segments[2], "params[") and std.mem.endsWith(u8, segments[2], "]")) {
|
|
1649
|
-
const digits = segments[2]["params[".len .. segments[2].len - 1];
|
|
1650
|
-
const index = std.fmt.parseInt(usize, digits, 10) catch return .unresolved;
|
|
1651
|
-
if (index >= helper.params.len) return .unresolved;
|
|
1652
|
-
return classifyRef(helper.params[index]);
|
|
1653
|
-
}
|
|
1654
|
-
return .unresolved;
|
|
1655
|
-
}
|
|
1656
|
-
return .unresolved;
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
if (std.mem.eql(u8, segments[0], sidecar.msg.name)) {
|
|
1660
|
-
if (count == 2) {
|
|
1661
|
-
if (findArm(sidecar.msg, segments[1])) |arm| {
|
|
1662
|
-
return switch (arm.payload) {
|
|
1663
|
-
.number => |class| classifyNumberClass(class),
|
|
1664
|
-
.scalar => |ref| classifyRef(ref),
|
|
1665
|
-
.void => .{ .not_integer = "void" },
|
|
1666
|
-
.bytes => .{ .not_integer = "bytes" },
|
|
1667
|
-
.number_bytes => .{ .not_integer = "a number_bytes record (its number field is the slot)" },
|
|
1668
|
-
.record => .{ .not_integer = "a record" },
|
|
1669
|
-
.union_ref => .{ .not_integer = "a union" },
|
|
1670
|
-
.enum_ref => .{ .not_integer = "an enum" },
|
|
1671
|
-
};
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
if (count == 3) {
|
|
1675
|
-
if (findArm(sidecar.msg, segments[1])) |arm| {
|
|
1676
|
-
switch (arm.payload) {
|
|
1677
|
-
.number_bytes => |desc| {
|
|
1678
|
-
if (std.mem.eql(u8, segments[2], desc.number_field)) return classifyNumberClass(desc.number_class);
|
|
1679
|
-
if (std.mem.eql(u8, segments[2], desc.bytes_field)) return .{ .not_integer = "bytes" };
|
|
1680
|
-
},
|
|
1681
|
-
else => {},
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
return .unresolved;
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
|
-
if (count == 2) {
|
|
1689
|
-
if (findStruct(sidecar.types, segments[0])) |record| {
|
|
1690
|
-
for (record.fields) |field| {
|
|
1691
|
-
if (std.mem.eql(u8, field.name, segments[1])) return classifyRef(field.type);
|
|
1692
|
-
}
|
|
1693
|
-
return .unresolved;
|
|
1694
|
-
}
|
|
1695
|
-
if (findUnion(sidecar.types, segments[0])) |tagged| {
|
|
1696
|
-
for (tagged.arms) |arm| {
|
|
1697
|
-
if (std.mem.eql(u8, arm.name, segments[1])) return classifyRef(arm.payload);
|
|
1698
|
-
}
|
|
1699
|
-
return .unresolved;
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
return .unresolved;
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1705
|
-
fn validateIntegerSlots(arena: std.mem.Allocator, sidecar: Sidecar, diags: *Diagnostics) error{OutOfMemory}!void {
|
|
1706
|
-
const expected = try collectIntegerSlotPaths(arena, sidecar);
|
|
1707
|
-
|
|
1708
|
-
// The path grammar joins components with dots, so a component
|
|
1709
|
-
// carrying its own dot would make two different slots spell one
|
|
1710
|
-
// path — the bijection would silently thin. Refuse the ambiguity at
|
|
1711
|
-
// its source.
|
|
1712
|
-
for (expected) |path| {
|
|
1713
|
-
if (path.components_dotted) {
|
|
1714
|
-
diags.flag("integer_slots", "the i64 slot at \"{s}\" involves a name containing '.', which the slot path grammar cannot address unambiguously — rename it in the core source (V10)", .{path.path});
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
// Two DISTINCT slots spelling one path is the same ambiguity from
|
|
1718
|
-
// another direction (a message union named `helpers` whose
|
|
1719
|
-
// number_bytes field spells a helper's return slot, a table type
|
|
1720
|
-
// sharing the message union's name): the bijection would consume
|
|
1721
|
-
// entries interchangeably and one attestation would silently govern
|
|
1722
|
-
// both slots.
|
|
1723
|
-
for (expected, 0..) |path, index| {
|
|
1724
|
-
for (expected[0..index]) |earlier| {
|
|
1725
|
-
if (std.mem.eql(u8, earlier.path, path.path)) {
|
|
1726
|
-
diags.flag("integer_slots", "two distinct i64 slots spell the one path \"{s}\" — the slot-path grammar cannot address them separately, so their attestations cannot be told apart; rename one of the colliding surfaces in the core source (V10)", .{path.path});
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
}
|
|
1730
|
-
if (diags.hasErrors()) return;
|
|
1731
|
-
|
|
1732
|
-
// One-to-one both ways: every expected slot consumes exactly one
|
|
1733
|
-
// entry, and no entry is left over or spent twice.
|
|
1734
|
-
const consumed = try arena.alloc(bool, sidecar.integer_slots.len);
|
|
1735
|
-
@memset(consumed, false);
|
|
1736
|
-
outer: for (expected) |path| {
|
|
1737
|
-
for (sidecar.integer_slots, 0..) |slot, index| {
|
|
1738
|
-
if (!consumed[index] and std.mem.eql(u8, slot.slot, path.path)) {
|
|
1739
|
-
consumed[index] = true;
|
|
1740
|
-
continue :outer;
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
diags.flag("integer_slots", "the sidecar spells \"{s}\" i64 but attests no integer_slots entry for it — every i64 spelling has exactly one entry (V10)", .{path.path});
|
|
1744
|
-
}
|
|
1745
|
-
for (sidecar.integer_slots, 0..) |slot, index| {
|
|
1746
|
-
if (consumed[index]) continue;
|
|
1747
|
-
var duplicate = false;
|
|
1748
|
-
for (sidecar.integer_slots[0..index]) |earlier| {
|
|
1749
|
-
if (std.mem.eql(u8, earlier.slot, slot.slot)) duplicate = true;
|
|
1750
|
-
}
|
|
1751
|
-
const at = pathOfStatic(diags, "integer_slots[{d}].slot", .{index});
|
|
1752
|
-
if (duplicate) {
|
|
1753
|
-
diags.flag(at, "duplicate entry for \"{s}\" — every i64 slot has exactly one entry (V10)", .{slot.slot});
|
|
1754
|
-
continue;
|
|
1755
|
-
}
|
|
1756
|
-
// The entry consumed nothing: resolve its path structurally so
|
|
1757
|
-
// the teaching names what actually went wrong instead of one
|
|
1758
|
-
// generic mismatch.
|
|
1759
|
-
switch (resolveSlotPath(sidecar, slot.slot)) {
|
|
1760
|
-
.integer => diags.flag(at, "\"{s}\" resolves to no slot the sidecar spells i64 — every entry must name a real i64 slot (V10)", .{slot.slot}),
|
|
1761
|
-
.not_integer => |spelling| diags.flag(at, "\"{s}\" resolves to a slot the sidecar spells {s}, not i64 — an attested integer class must sit on an i64 spelling (V10)", .{ slot.slot, spelling }),
|
|
1762
|
-
.slice_element => diags.flag(at, "\"{s}\" addresses a sequence — the format-1 slot-path grammar has no slice-element form, so slice elements are never integer-attested; the emitter spells them f64 and readers exempt them from the bijection (V10)", .{slot.slot}),
|
|
1763
|
-
.unresolved => diags.flag(at, "\"{s}\" resolves against none of the sidecar's own tables — slot paths name a record field or union arm (<Type>.<name>), a message payload (\"{s}.<arm>\" or \"{s}.<arm>.<numberField>\"), or a helper signature slot (helpers.<name>.return, helpers.<name>.params[<index>]) (V10)", .{ slot.slot, sidecar.msg.name, sidecar.msg.name }),
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
|
|
1768
504
|
/// Restate a validated sidecar after applying record-slot f64 demotions.
|
|
1769
505
|
/// Mutating the dynamic document instead of serializing the typed reader
|
|
1770
506
|
/// preserves unknown additive fields for newer producers. The caller first
|
|
1771
507
|
/// validates each path against the typed contract, so a miss here is internal
|
|
1772
508
|
/// projection drift rather than user input.
|
|
1773
509
|
pub fn projectF64SlotsJson(arena: std.mem.Allocator, source: []const u8, f64_slots: []const []const u8) ![]const u8 {
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
var root = try std.json.parseFromSliceLeaky(std.json.Value, arena, source, .{});
|
|
1777
|
-
const types = root.object.getPtr("types").?;
|
|
1778
|
-
const structs = types.object.getPtr("structs").?;
|
|
1779
|
-
for (f64_slots) |slot_path| {
|
|
1780
|
-
const dot = std.mem.indexOfScalar(u8, slot_path, '.') orelse return error.ProjectionDrift;
|
|
1781
|
-
const container = slot_path[0..dot];
|
|
1782
|
-
const field_name = slot_path[dot + 1 ..];
|
|
1783
|
-
var changed = false;
|
|
1784
|
-
for (structs.array.items) |*entry| {
|
|
1785
|
-
if (!std.mem.eql(u8, entry.object.get("name").?.string, container)) continue;
|
|
1786
|
-
const fields = entry.object.getPtr("fields").?;
|
|
1787
|
-
for (fields.array.items) |*field| {
|
|
1788
|
-
if (!std.mem.eql(u8, field.object.get("name").?.string, field_name)) continue;
|
|
1789
|
-
const ref = field.object.getPtr("type").?;
|
|
1790
|
-
const kind = ref.object.getPtr("kind").?;
|
|
1791
|
-
if (std.mem.eql(u8, kind.string, "optional")) {
|
|
1792
|
-
const inner = ref.object.getPtr("inner").?;
|
|
1793
|
-
inner.object.getPtr("kind").?.* = .{ .string = "f64" };
|
|
1794
|
-
} else {
|
|
1795
|
-
kind.* = .{ .string = "f64" };
|
|
1796
|
-
}
|
|
1797
|
-
changed = true;
|
|
1798
|
-
break;
|
|
1799
|
-
}
|
|
1800
|
-
break;
|
|
1801
|
-
}
|
|
1802
|
-
if (!changed) return error.ProjectionDrift;
|
|
1803
|
-
}
|
|
1804
|
-
|
|
1805
|
-
const attestations = root.object.getPtr("integer_slots").?;
|
|
1806
|
-
var index: usize = 0;
|
|
1807
|
-
while (index < attestations.array.items.len) {
|
|
1808
|
-
const slot = attestations.array.items[index].object.get("slot").?.string;
|
|
1809
|
-
const demoted = for (f64_slots) |candidate| {
|
|
1810
|
-
if (std.mem.eql(u8, slot, candidate)) break true;
|
|
1811
|
-
} else false;
|
|
1812
|
-
if (demoted) {
|
|
1813
|
-
_ = attestations.array.orderedRemove(index);
|
|
1814
|
-
} else {
|
|
1815
|
-
index += 1;
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
|
|
1819
|
-
var out: std.Io.Writer.Allocating = .init(arena);
|
|
1820
|
-
var json: std.json.Stringify = .{ .writer = &out.writer, .options = .{ .whitespace = .indent_2 } };
|
|
1821
|
-
try json.write(root);
|
|
1822
|
-
try out.writer.writeByte('\n');
|
|
1823
|
-
return out.written();
|
|
510
|
+
return @import("invocation.zig").effective(arena, source, f64_slots);
|
|
1824
511
|
}
|
|
1825
512
|
|
|
1826
513
|
// --------------------------------------------------------------- tests
|
|
@@ -1832,7 +519,7 @@ const testing = std.testing;
|
|
|
1832
519
|
pub const minimal_valid_json =
|
|
1833
520
|
\\{
|
|
1834
521
|
\\ "format": 1,
|
|
1835
|
-
\\ "wire_version":
|
|
522
|
+
\\ "wire_version": 10,
|
|
1836
523
|
\\ "abi_version": 2,
|
|
1837
524
|
\\ "compiler_version": "0.0.1",
|
|
1838
525
|
\\ "entry": "src/core.ts",
|
|
@@ -1891,6 +578,40 @@ pub const minimal_valid_json =
|
|
|
1891
578
|
\\}
|
|
1892
579
|
;
|
|
1893
580
|
|
|
581
|
+
test "compiled policy diagnostics and plan names remain owned across collect and init" {
|
|
582
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
583
|
+
defer arena_state.deinit();
|
|
584
|
+
const arena = arena_state.allocator();
|
|
585
|
+
var diags = Diagnostics{ .arena = arena };
|
|
586
|
+
var parsed = try read(arena, minimal_valid_json, &diags);
|
|
587
|
+
const policy = @import("core_policy.zig");
|
|
588
|
+
parsed.types.structs = &.{
|
|
589
|
+
.{ .name = "Model", .fields = &.{} },
|
|
590
|
+
.{ .name = "Msg_insert", .fields = &.{
|
|
591
|
+
.{ .name = "label", .type = .bytes },
|
|
592
|
+
.{ .name = "active", .type = .bool },
|
|
593
|
+
} },
|
|
594
|
+
};
|
|
595
|
+
parsed.msg.arms = &.{.{ .name = "insert", .payload = .{ .record = "Msg_insert" } }};
|
|
596
|
+
const plan = try policy.evaluate(arena, parsed, "plan");
|
|
597
|
+
try testing.expectEqualStrings("Msg_insert", plan.inlined[0]);
|
|
598
|
+
try testing.expectEqualStrings("Msg_insert", plan.flattened[0]);
|
|
599
|
+
try testing.expectEqualStrings("Model", plan.node_stored[0]);
|
|
600
|
+
parsed.wire_version = std.math.maxInt(i64);
|
|
601
|
+
const refused = try policy.evaluate(arena, parsed, "core");
|
|
602
|
+
const before = try std.json.Stringify.valueAlloc(arena, refused, .{});
|
|
603
|
+
try testing.expect(std.mem.indexOf(u8, before, "9223372036854775807") != null);
|
|
604
|
+
for (0..12) |i| {
|
|
605
|
+
parsed.wire_version = @intCast(i + 20);
|
|
606
|
+
_ = try policy.evaluate(arena, parsed, if (i % 2 == 0) "core" else "facade");
|
|
607
|
+
}
|
|
608
|
+
const after = try std.json.Stringify.valueAlloc(arena, refused, .{});
|
|
609
|
+
try testing.expectEqualStrings(before, after);
|
|
610
|
+
try testing.expectEqualStrings("Msg_insert", plan.inlined[0]);
|
|
611
|
+
try testing.expectEqualStrings("Msg_insert", plan.flattened[0]);
|
|
612
|
+
try testing.expectEqualStrings("Model", plan.node_stored[0]);
|
|
613
|
+
}
|
|
614
|
+
|
|
1894
615
|
test "drop_msg infers from the ABI export for older format-1 emitters" {
|
|
1895
616
|
var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1896
617
|
defer arena_state.deinit();
|
|
@@ -2399,6 +1120,114 @@ test "V11: an unknown export suffix refuses" {
|
|
|
2399
1120
|
try expectRefusal(source, "abi.exports[22]", "not an export suffix of ABI version 2");
|
|
2400
1121
|
}
|
|
2401
1122
|
|
|
1123
|
+
test "V11: the optional native view extension is unique and follows channels" {
|
|
1124
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1125
|
+
defer arena_state.deinit();
|
|
1126
|
+
const arena = arena_state.allocator();
|
|
1127
|
+
const source = try replaced(arena, minimal_valid_json, "\"helper_call\"]", "\"helper_call\", \"native_view\"]");
|
|
1128
|
+
const valid = try readValid(arena, source);
|
|
1129
|
+
try testing.expect(abiHasExport(valid.abi, "native_view"));
|
|
1130
|
+
const windows = try replaced(arena, source, "\"native_view\"]", "\"native_view\", \"native_window_view\"]");
|
|
1131
|
+
const window_valid = try readValid(arena, windows);
|
|
1132
|
+
try testing.expect(abiHasExport(window_valid.abi, "native_window_view"));
|
|
1133
|
+
const policy = try replaced(arena, windows, "\"native_window_view\"]", "\"native_window_view\", \"native_radio_policy\"]");
|
|
1134
|
+
const policy_valid = try readValid(arena, policy);
|
|
1135
|
+
try testing.expect(abiHasExport(policy_valid.abi, "native_radio_policy"));
|
|
1136
|
+
const tabs = try replaced(arena, policy, "\"native_radio_policy\"]", "\"native_radio_policy\", \"native_tabs_policy\"]");
|
|
1137
|
+
const tabs_valid = try readValid(arena, tabs);
|
|
1138
|
+
try testing.expect(abiHasExport(tabs_valid.abi, "native_tabs_policy"));
|
|
1139
|
+
const tree = try replaced(arena, tabs, "\"native_tabs_policy\"]", "\"native_tabs_policy\", \"native_tree_policy\"]");
|
|
1140
|
+
const tree_valid = try readValid(arena, tree);
|
|
1141
|
+
try testing.expect(abiHasExport(tree_valid.abi, "native_tree_policy"));
|
|
1142
|
+
const list = try replaced(arena, tree, "\"native_tree_policy\"]", "\"native_tree_policy\", \"native_list_policy\"]");
|
|
1143
|
+
const list_valid = try readValid(arena, list);
|
|
1144
|
+
try testing.expect(abiHasExport(list_valid.abi, "native_list_policy"));
|
|
1145
|
+
const menu = try replaced(arena, list, "\"native_list_policy\"]", "\"native_list_policy\", \"native_menu_policy\"]");
|
|
1146
|
+
const menu_valid = try readValid(arena, menu);
|
|
1147
|
+
try testing.expect(abiHasExport(menu_valid.abi, "native_menu_policy"));
|
|
1148
|
+
const toggle = try replaced(arena, menu, "\"native_menu_policy\"]", "\"native_menu_policy\", \"native_toggle_policy\"]");
|
|
1149
|
+
const toggle_valid = try readValid(arena, toggle);
|
|
1150
|
+
try testing.expect(abiHasExport(toggle_valid.abi, "native_toggle_policy"));
|
|
1151
|
+
const accordion = try replaced(arena, toggle, "\"native_toggle_policy\"]", "\"native_toggle_policy\", \"native_accordion_policy\"]");
|
|
1152
|
+
const accordion_valid = try readValid(arena, accordion);
|
|
1153
|
+
try testing.expect(abiHasExport(accordion_valid.abi, "native_accordion_policy"));
|
|
1154
|
+
const slider = try replaced(arena, accordion, "\"native_accordion_policy\"]", "\"native_accordion_policy\", \"native_slider_policy\"]");
|
|
1155
|
+
const slider_valid = try readValid(arena, slider);
|
|
1156
|
+
try testing.expect(abiHasExport(slider_valid.abi, "native_slider_policy"));
|
|
1157
|
+
const split = try replaced(arena, slider, "\"native_slider_policy\"]", "\"native_slider_policy\", \"native_split_policy\"]");
|
|
1158
|
+
const split_valid = try readValid(arena, split);
|
|
1159
|
+
try testing.expect(abiHasExport(split_valid.abi, "native_split_policy"));
|
|
1160
|
+
const scroll = try replaced(arena, split, "\"native_split_policy\"]", "\"native_split_policy\", \"native_scroll_policy\"]");
|
|
1161
|
+
const scroll_valid = try readValid(arena, scroll);
|
|
1162
|
+
try testing.expect(abiHasExport(scroll_valid.abi, "native_scroll_policy"));
|
|
1163
|
+
const resizable = try replaced(arena, scroll, "\"native_scroll_policy\"]", "\"native_scroll_policy\", \"native_resizable_policy\"]");
|
|
1164
|
+
const resizable_valid = try readValid(arena, resizable);
|
|
1165
|
+
try testing.expect(abiHasExport(resizable_valid.abi, "native_resizable_policy"));
|
|
1166
|
+
const text = try replaced(arena, resizable, "\"native_resizable_policy\"]", "\"native_resizable_policy\", \"native_text_policy\"]");
|
|
1167
|
+
const text_valid = try readValid(arena, text);
|
|
1168
|
+
try testing.expect(abiHasExport(text_valid.abi, "native_text_policy"));
|
|
1169
|
+
const timer = try replaced(arena, text, "\"native_text_policy\"]", "\"native_text_policy\", \"native_timer_policy\"]");
|
|
1170
|
+
const timer_valid = try readValid(arena, timer);
|
|
1171
|
+
try testing.expect(abiHasExport(timer_valid.abi, "native_timer_policy"));
|
|
1172
|
+
const db = try replaced(arena, timer, "\"native_timer_policy\"]", "\"native_timer_policy\", \"native_db_policy\"]");
|
|
1173
|
+
const db_valid = try readValid(arena, db);
|
|
1174
|
+
try testing.expect(abiHasExport(db_valid.abi, "native_db_policy"));
|
|
1175
|
+
const effect = try replaced(arena, db, "\"native_db_policy\"]", "\"native_db_policy\", \"native_effect_policy\"]");
|
|
1176
|
+
const effect_valid = try readValid(arena, effect);
|
|
1177
|
+
try testing.expect(abiHasExport(effect_valid.abi, "native_effect_policy"));
|
|
1178
|
+
const effect_duplicate = try replaced(arena, effect, "\"native_effect_policy\"]", "\"native_effect_policy\", \"native_effect_policy\"]");
|
|
1179
|
+
try expectRefusal(effect_duplicate, "abi.exports[39]", "out of canonical order");
|
|
1180
|
+
const window = try replaced(arena, db, "\"native_db_policy\"]", "\"native_db_policy\", \"native_window_policy\"]");
|
|
1181
|
+
const window_policy_valid = try readValid(arena, window);
|
|
1182
|
+
try testing.expect(abiHasExport(window_policy_valid.abi, "native_window_policy"));
|
|
1183
|
+
const window_policy_duplicate = try replaced(arena, window, "\"native_window_policy\"]", "\"native_window_policy\", \"native_window_policy\"]");
|
|
1184
|
+
try expectRefusal(window_policy_duplicate, "abi.exports[39]", "out of canonical order");
|
|
1185
|
+
const theme = try replaced(arena, db, "\"native_db_policy\"]", "\"native_db_policy\", \"native_theme_policy\"]");
|
|
1186
|
+
const theme_valid = try readValid(arena, theme);
|
|
1187
|
+
try testing.expect(abiHasExport(theme_valid.abi, "native_theme_policy"));
|
|
1188
|
+
const theme_duplicate = try replaced(arena, theme, "\"native_theme_policy\"]", "\"native_theme_policy\", \"native_theme_policy\"]");
|
|
1189
|
+
try expectRefusal(theme_duplicate, "abi.exports[39]", "out of canonical order");
|
|
1190
|
+
const status = try replaced(arena, db, "\"native_db_policy\"]", "\"native_db_policy\", \"native_status_policy\"]");
|
|
1191
|
+
const status_valid = try readValid(arena, status);
|
|
1192
|
+
try testing.expect(abiHasExport(status_valid.abi, "native_status_policy"));
|
|
1193
|
+
const status_duplicate = try replaced(arena, status, "\"native_status_policy\"]", "\"native_status_policy\", \"native_status_policy\"]");
|
|
1194
|
+
try expectRefusal(status_duplicate, "abi.exports[39]", "out of canonical order");
|
|
1195
|
+
const db_duplicate = try replaced(arena, db, "\"native_db_policy\"]", "\"native_db_policy\", \"native_db_policy\"]");
|
|
1196
|
+
try expectRefusal(db_duplicate, "abi.exports[38]", "out of canonical order");
|
|
1197
|
+
const timer_duplicate = try replaced(arena, timer, "\"native_timer_policy\"]", "\"native_timer_policy\", \"native_timer_policy\"]");
|
|
1198
|
+
try expectRefusal(timer_duplicate, "abi.exports[37]", "out of canonical order");
|
|
1199
|
+
const text_duplicate = try replaced(arena, text, "\"native_text_policy\"]", "\"native_text_policy\", \"native_text_policy\"]");
|
|
1200
|
+
try expectRefusal(text_duplicate, "abi.exports[36]", "out of canonical order");
|
|
1201
|
+
const resizable_duplicate = try replaced(arena, resizable, "\"native_resizable_policy\"]", "\"native_resizable_policy\", \"native_resizable_policy\"]");
|
|
1202
|
+
try expectRefusal(resizable_duplicate, "abi.exports[35]", "out of canonical order");
|
|
1203
|
+
const scroll_duplicate = try replaced(arena, scroll, "\"native_scroll_policy\"]", "\"native_scroll_policy\", \"native_scroll_policy\"]");
|
|
1204
|
+
try expectRefusal(scroll_duplicate, "abi.exports[34]", "out of canonical order");
|
|
1205
|
+
const split_duplicate = try replaced(arena, split, "\"native_split_policy\"]", "\"native_split_policy\", \"native_split_policy\"]");
|
|
1206
|
+
try expectRefusal(split_duplicate, "abi.exports[33]", "out of canonical order");
|
|
1207
|
+
const slider_duplicate = try replaced(arena, slider, "\"native_slider_policy\"]", "\"native_slider_policy\", \"native_slider_policy\"]");
|
|
1208
|
+
try expectRefusal(slider_duplicate, "abi.exports[32]", "out of canonical order");
|
|
1209
|
+
const accordion_duplicate = try replaced(arena, accordion, "\"native_accordion_policy\"]", "\"native_accordion_policy\", \"native_accordion_policy\"]");
|
|
1210
|
+
try expectRefusal(accordion_duplicate, "abi.exports[31]", "out of canonical order");
|
|
1211
|
+
const toggle_duplicate = try replaced(arena, toggle, "\"native_toggle_policy\"]", "\"native_toggle_policy\", \"native_toggle_policy\"]");
|
|
1212
|
+
try expectRefusal(toggle_duplicate, "abi.exports[30]", "out of canonical order");
|
|
1213
|
+
const menu_duplicate = try replaced(arena, menu, "\"native_menu_policy\"]", "\"native_menu_policy\", \"native_menu_policy\"]");
|
|
1214
|
+
try expectRefusal(menu_duplicate, "abi.exports[29]", "out of canonical order");
|
|
1215
|
+
const list_duplicate = try replaced(arena, list, "\"native_list_policy\"]", "\"native_list_policy\", \"native_list_policy\"]");
|
|
1216
|
+
try expectRefusal(list_duplicate, "abi.exports[28]", "out of canonical order");
|
|
1217
|
+
const tree_duplicate = try replaced(arena, tree, "\"native_tree_policy\"]", "\"native_tree_policy\", \"native_tree_policy\"]");
|
|
1218
|
+
try expectRefusal(tree_duplicate, "abi.exports[27]", "out of canonical order");
|
|
1219
|
+
const tabs_duplicate = try replaced(arena, tabs, "\"native_tabs_policy\"]", "\"native_tabs_policy\", \"native_tabs_policy\"]");
|
|
1220
|
+
try expectRefusal(tabs_duplicate, "abi.exports[26]", "out of canonical order");
|
|
1221
|
+
const policy_duplicate = try replaced(arena, policy, "\"native_radio_policy\"]", "\"native_radio_policy\", \"native_radio_policy\"]");
|
|
1222
|
+
try expectRefusal(policy_duplicate, "abi.exports[25]", "out of canonical order");
|
|
1223
|
+
const window_duplicate = try replaced(arena, windows, "\"native_window_view\"]", "\"native_window_view\", \"native_window_view\"]");
|
|
1224
|
+
try expectRefusal(window_duplicate, "abi.exports[24]", "out of canonical order");
|
|
1225
|
+
const duplicate = try replaced(arena, source, "\"native_view\"]", "\"native_view\", \"native_view\"]");
|
|
1226
|
+
try expectRefusal(duplicate, "abi.exports[23]", "out of canonical order");
|
|
1227
|
+
const reordered = try replaced(arena, source, "\"helper_call\", \"native_view\"", "\"native_view\", \"helper_call\"");
|
|
1228
|
+
try expectRefusal(reordered, "abi.exports[21]", "expected the unconditional export");
|
|
1229
|
+
}
|
|
1230
|
+
|
|
2402
1231
|
test "V11: a missing unconditional export refuses with the expected suffix" {
|
|
2403
1232
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
2404
1233
|
defer arena_state.deinit();
|
|
@@ -2428,8 +1257,8 @@ test "unknown payload descriptor kinds refuse as reader-too-old" {
|
|
|
2428
1257
|
test "wire and abi version mismatches refuse with both values named" {
|
|
2429
1258
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
2430
1259
|
defer arena_state.deinit();
|
|
2431
|
-
const source = try replaced(arena_state.allocator(), minimal_valid_json, "\"wire_version\":
|
|
2432
|
-
try expectRefusal(source, "wire_version", "generation
|
|
1260
|
+
const source = try replaced(arena_state.allocator(), minimal_valid_json, "\"wire_version\": 10", "\"wire_version\": 11");
|
|
1261
|
+
try expectRefusal(source, "wire_version", "generation 10, the sidecar declares 11");
|
|
2433
1262
|
}
|
|
2434
1263
|
|
|
2435
1264
|
test "unknown fields warn and are ignored" {
|