ttsc 0.33.1 → 0.34.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 +2 -0
- package/cmd/ttsc/api_compile.go +3 -2
- package/cmd/ttsc/api_transform.go +1 -1
- package/cmd/ttsc/build.go +5 -4
- package/cmd/ttsc-cache/account.go +16 -0
- package/cmd/ttsc-cache/account_test.go +91 -0
- package/cmd/ttsc-cache/main.go +1 -1
- package/cmd/ttsc-cache/protocol_test.go +2 -2
- package/cmd/ttsc-cache/publisher_seal_test.go +1 -1
- package/cmd/ttsc-cache/stock_go_failure_test.go +1 -1
- package/cmd/ttsc-cache/stock_go_test.go +2 -2
- package/cmd/ttsc-cache/store.go +5 -0
- package/cmd/ttsc-cache/tuple.go +6 -2
- package/cmd/ttsc-cache/tuple_test.go +1 -1
- package/cmd/ttscgraph/main.go +6 -1
- package/cmd/ttscgraph/run_help_version_and_bad_flags_exit_codes_test.go +6 -1
- package/cmd/ttscgraph/serve.go +22 -20
- package/cmd/ttscgraph/serve_shards.go +26 -15
- package/cmd/ttscgraph/serve_shards_abandoned_generation_converges_on_retry_test.go +2 -2
- package/cmd/ttscgraph/serve_shards_delete_removed_source_test.go +3 -3
- package/cmd/ttscgraph/serve_shards_prune_unreferenced_external_endpoints_test.go +1 -1
- package/cmd/ttscgraph/serve_shards_publish_created_source_test.go +3 -3
- package/cmd/ttscgraph/serve_shards_refresh_cross_file_implementation_test.go +2 -2
- package/cmd/ttscgraph/serve_shards_refresh_dependent_diagnostics_test.go +3 -3
- package/cmd/ttscgraph/serve_shards_rename_moves_source_identity_test.go +5 -5
- package/cmd/ttscgraph/serve_shards_reuse_unaffected_sources_test.go +8 -8
- package/cmd/ttscgraph/serve_source_encoding_test.go +2 -2
- package/driver/build_information_uses_selected_output_identity_test.go +5 -4
- package/driver/check_observations.go +1 -1
- package/driver/config_discovery.go +5 -1
- package/driver/declaration_shape.go +15 -21
- package/driver/diagnostics_preamble.go +2 -2
- package/driver/emit_containment.go +11 -14
- package/driver/emit_plugin.go +51 -43
- package/driver/emit_plugin_output.go +6 -5
- package/driver/emit_provenance.go +12 -15
- package/driver/graph.go +8 -8
- package/driver/host.go +15 -5
- package/driver/input_observation.go +22 -21
- package/driver/input_observation_test.go +11 -10
- package/driver/overlay.go +11 -11
- package/driver/program.go +102 -51
- package/driver/resolution_candidates.go +50 -32
- package/driver/resolution_candidates_test.go +18 -5
- package/driver/rewrite.go +11 -13
- package/driver/session.go +13 -7
- package/driver/target_ts70.go +85 -0
- package/driver/target_ts71.go +97 -0
- package/driver/transform_dependencies.go +1 -1
- package/driver/transform_source_map.go +21 -20
- package/go.mod +3 -3
- package/go.sum +4 -4
- package/internal/graph/alternative_member_declarations_resolve_uses_test.go +9 -9
- package/internal/graph/assigned_implementations_of_declaration_file_symbols_leave_no_edge_source_test.go +2 -2
- package/internal/graph/assigned_implementations_of_node_modules_symbols_leave_no_edge_source_test.go +2 -2
- package/internal/graph/build.go +17 -17
- package/internal/graph/build_files_reuses_committed_cross_file_endpoints_test.go +4 -4
- package/internal/graph/build_records_a_node_per_top_level_declaration_test.go +1 -1
- package/internal/graph/declaration_members.go +1 -1
- package/internal/graph/decorators_capture_name_and_literal_arguments_test.go +3 -3
- package/internal/graph/doc_tags.go +2 -2
- package/internal/graph/dump_paths.go +6 -5
- package/internal/graph/duplicate_variable_object_members_keep_first_declaration_test.go +1 -1
- package/internal/graph/edges.go +49 -38
- package/internal/graph/edges_cover_class_level_references_test.go +5 -5
- package/internal/graph/enum_initializer_calls_are_edges_test.go +2 -2
- package/internal/graph/enum_members_carry_their_names_on_the_enum_node_test.go +6 -6
- package/internal/graph/exports.go +6 -6
- package/internal/graph/file_diagnostics_match_tsgo_code_and_location_test.go +2 -2
- package/internal/graph/file_diagnostics_report_code_column_and_message_test.go +1 -1
- package/internal/graph/function_locals_do_not_collide_test.go +3 -3
- package/internal/graph/heritage_edges_cover_implements_and_interface_extends_test.go +5 -5
- package/internal/graph/heritage_edges_keep_extends_and_implements_to_same_base_test.go +2 -2
- package/internal/graph/heritage_edges_record_extends_versus_implements_origin_test.go +3 -3
- package/internal/graph/heritage_edges_traverse_barrels_and_stop_at_external_leaves_test.go +3 -3
- package/internal/graph/literals.go +3 -3
- package/internal/graph/literals_are_absent_when_the_type_admits_more_than_it_can_name_test.go +2 -2
- package/internal/graph/literals_cover_enum_members_the_graph_has_no_nodes_for_test.go +4 -4
- package/internal/graph/literals_do_not_depend_on_declaration_line_wrapping_test.go +2 -2
- package/internal/graph/literals_render_every_value_in_typescript_source_form_test.go +1 -1
- package/internal/graph/literals_resolve_through_alias_indirection_test.go +3 -3
- package/internal/graph/member_relation_edges_follow_checker_validity_test.go +7 -7
- package/internal/graph/member_relation_edges_preserve_checker_boundaries_test.go +19 -19
- package/internal/graph/member_relation_edges_reject_checker_invalid_pairs_test.go +11 -11
- package/internal/graph/namespace_dotted_form_qualifies_deeply_test.go +2 -2
- package/internal/graph/namespace_members_become_qualified_nodes_and_edges_test.go +7 -7
- package/internal/graph/namespace_private_declarations_keep_lexical_identity_test.go +5 -5
- package/internal/graph/nodes_are_marked_exported_through_the_export_table_test.go +2 -2
- package/internal/graph/object_literal_declarations_resolve_calls_test.go +9 -9
- package/internal/graph/object_literal_members_ride_on_the_snapshot_test.go +1 -1
- package/internal/graph/overload_implementation_replaces_signature_test.go +2 -2
- package/internal/graph/property_member_edges_remain_owner_visible_test.go +6 -6
- package/internal/graph/resolve.go +7 -7
- package/internal/graph/resolve_unwraps_barrel_reexport_to_real_declaration_test.go +6 -6
- package/internal/graph/source.go +1 -1
- package/internal/graph/type_ref_edges_cover_typeof_as_satisfies_test.go +7 -7
- package/internal/graph/type_ref_edges_resolve_named_types_across_files_test.go +2 -2
- package/internal/graph/value_access_edges_cover_properties_test.go +5 -5
- package/internal/graph/value_call_edges_attribute_function_assignments_to_members_test.go +3 -3
- package/internal/graph/value_call_edges_cover_jsx_components_test.go +2 -2
- package/internal/graph/value_call_edges_cover_methods_and_constructors_test.go +3 -3
- package/internal/graph/value_call_edges_cover_variable_bound_callables_test.go +2 -2
- package/internal/graph/value_call_edges_do_not_double_record_invoked_member_access_test.go +4 -4
- package/internal/graph/value_call_edges_record_construct_versus_call_origin_test.go +3 -3
- package/internal/graph/value_call_edges_resolve_across_files_and_dedupe_test.go +2 -2
- package/internal/graph/value_call_edges_skip_self_and_unresolved_test.go +4 -4
- package/internal/graph/value_reads_cover_expression_positions_test.go +6 -6
- package/lib/compiler/internal/buildNativeCompiler.d.ts +5 -2
- package/lib/compiler/internal/buildNativeCompiler.js +12 -4
- package/lib/compiler/internal/buildNativeCompiler.js.map +1 -1
- package/lib/flags/COMPILER_ENUM_WHITESPACE.js +1 -1
- package/lib/flags/COMPILER_ENUM_WHITESPACE.js.map +1 -1
- package/lib/flags/COMPILER_OPTIONS.js +1079 -149
- package/lib/flags/COMPILER_OPTIONS.js.map +1 -1
- package/lib/flags/COMPILER_OPTION_ASCII_FOLDS.js +1 -1
- package/lib/flags/COMPILER_OPTION_ASCII_FOLDS.js.map +1 -1
- package/lib/flags/COMPILER_OPTION_KINDS.js +1 -1
- package/lib/flags/COMPILER_OPTION_KINDS.js.map +1 -1
- package/lib/flags/CompilerOptionSpec.d.ts +9 -2
- package/lib/internal/pluginSource.d.ts +1 -0
- package/lib/internal/pluginSource.js +1 -0
- package/lib/internal/pluginSource.js.map +1 -1
- package/lib/launcher/internal/TypeScriptSyncApi.d.ts +140 -0
- package/lib/launcher/internal/TypeScriptSyncApi.js +99 -0
- package/lib/launcher/internal/TypeScriptSyncApi.js.map +1 -0
- package/lib/launcher/internal/buildSingleRootInMemory.d.ts +80 -0
- package/lib/launcher/internal/buildSingleRootInMemory.js +253 -0
- package/lib/launcher/internal/buildSingleRootInMemory.js.map +1 -0
- package/lib/launcher/internal/buildSingleRootProject.d.ts +22 -18
- package/lib/launcher/internal/buildSingleRootProject.js +27 -18
- package/lib/launcher/internal/buildSingleRootProject.js.map +1 -1
- package/lib/launcher/internal/compilerArgsAsConfigOptions.d.ts +39 -0
- package/lib/launcher/internal/compilerArgsAsConfigOptions.js +115 -0
- package/lib/launcher/internal/compilerArgsAsConfigOptions.js.map +1 -0
- package/lib/plugin/CapabilityPluginResolver.js +3 -0
- package/lib/plugin/CapabilityPluginResolver.js.map +1 -1
- package/lib/plugin/internal/load/loadProjectPlugins.js +6 -2
- package/lib/plugin/internal/load/loadProjectPlugins.js.map +1 -1
- package/lib/plugin/internal/source/CompilerTarget.d.ts +127 -0
- package/lib/plugin/internal/source/CompilerTarget.js +231 -0
- package/lib/plugin/internal/source/CompilerTarget.js.map +1 -0
- package/lib/plugin/internal/source/NativeSourcePackages.js +6 -5
- package/lib/plugin/internal/source/NativeSourcePackages.js.map +1 -1
- package/lib/plugin/internal/source/SourcePluginAdmission.d.ts +18 -1
- package/lib/plugin/internal/source/SourcePluginAdmission.js +24 -2
- package/lib/plugin/internal/source/SourcePluginAdmission.js.map +1 -1
- package/lib/plugin/internal/source/SourcePluginWorkspace.d.ts +6 -3
- package/lib/plugin/internal/source/SourcePluginWorkspace.js +31 -13
- package/lib/plugin/internal/source/SourcePluginWorkspace.js.map +1 -1
- package/lib/plugin/internal/source/buildSourcePlugin.js +3 -1
- package/lib/plugin/internal/source/buildSourcePlugin.js.map +1 -1
- package/lib/plugin/internal/source/hashPluginBuildEnvironment.d.ts +1 -1
- package/lib/plugin/internal/source/hashPluginBuildEnvironment.js +9 -1
- package/lib/plugin/internal/source/hashPluginBuildEnvironment.js.map +1 -1
- package/package.json +14 -9
- package/shim/ast/enums_gen.go +1 -0
- package/shim/ast/go.mod +2 -2
- package/shim/ast/go.sum +4 -4
- package/shim/ast/neutral.go +141 -0
- package/shim/astnav/go.mod +2 -2
- package/shim/astnav/go.sum +4 -4
- package/shim/bundled/go.mod +2 -2
- package/shim/bundled/go.sum +4 -4
- package/shim/checker/go.mod +2 -2
- package/shim/checker/go.sum +4 -4
- package/shim/compiler/go.mod +2 -2
- package/shim/compiler/go.sum +4 -4
- package/shim/compiler/neutral.go +213 -0
- package/shim/core/go.mod +2 -2
- package/shim/core/go.sum +4 -4
- package/shim/diagnosticwriter/go.mod +2 -2
- package/shim/diagnosticwriter/go.sum +4 -4
- package/shim/lsp/go.mod +2 -2
- package/shim/lsp/go.sum +4 -4
- package/shim/parser/go.mod +2 -2
- package/shim/parser/go.sum +4 -4
- package/shim/printer/go.mod +2 -2
- package/shim/printer/go.sum +4 -4
- package/shim/scanner/go.mod +2 -2
- package/shim/scanner/go.sum +4 -4
- package/shim/stringutil/go.mod +1 -1
- package/shim/stringutil/go.sum +2 -2
- package/shim/stringutil/shim.go +15 -0
- package/shim/transformers/go.mod +2 -2
- package/shim/transformers/go.sum +4 -4
- package/shim/tsoptions/go.mod +2 -2
- package/shim/tsoptions/go.sum +4 -4
- package/shim/tsoptions/neutral.go +56 -0
- package/shim/tspath/go.mod +1 -1
- package/shim/tspath/go.sum +2 -2
- package/shim/tspath/neutral.go +150 -0
- package/shim/tspath/typed_paths.go +266 -0
- package/shim/vfs/cachedvfs/go.mod +2 -2
- package/shim/vfs/cachedvfs/go.sum +4 -4
- package/shim/vfs/go.mod +2 -2
- package/shim/vfs/go.sum +4 -4
- package/shim/vfs/neutral.go +20 -0
- package/shim/vfs/osvfs/go.mod +2 -2
- package/shim/vfs/osvfs/go.sum +4 -4
- package/src/compiler/internal/buildNativeCompiler.ts +13 -4
- package/src/flags/COMPILER_ENUM_WHITESPACE.ts +1 -1
- package/src/flags/COMPILER_OPTIONS.ts +1080 -150
- package/src/flags/COMPILER_OPTION_ASCII_FOLDS.ts +1 -1
- package/src/flags/COMPILER_OPTION_KINDS.ts +1 -1
- package/src/flags/CompilerOptionSpec.ts +11 -2
- package/src/internal/pluginSource.ts +1 -0
- package/src/launcher/internal/TypeScriptSyncApi.ts +186 -0
- package/src/launcher/internal/buildSingleRootInMemory.ts +319 -0
- package/src/launcher/internal/buildSingleRootProject.ts +26 -18
- package/src/launcher/internal/compilerArgsAsConfigOptions.ts +112 -0
- package/src/plugin/CapabilityPluginResolver.ts +4 -1
- package/src/plugin/internal/load/loadProjectPlugins.ts +12 -2
- package/src/plugin/internal/source/CompilerTarget.ts +249 -0
- package/src/plugin/internal/source/NativeSourcePackages.ts +10 -4
- package/src/plugin/internal/source/SourcePluginAdmission.ts +28 -2
- package/src/plugin/internal/source/SourcePluginWorkspace.ts +45 -19
- package/src/plugin/internal/source/buildSourcePlugin.ts +3 -1
- package/src/plugin/internal/source/hashPluginBuildEnvironment.ts +9 -1
- package/targets/7.1/bridge/ast/enums_gen.go +174 -0
- package/targets/7.1/bridge/ast/extra-shim.json +4 -0
- package/targets/7.1/bridge/ast/go.mod +14 -0
- package/targets/7.1/bridge/ast/go.sum +20 -0
- package/targets/7.1/bridge/ast/lint.go +1412 -0
- package/targets/7.1/bridge/ast/neutral.go +141 -0
- package/targets/7.1/bridge/ast/parent.go +60 -0
- package/targets/7.1/bridge/ast/safe_text.go +108 -0
- package/targets/7.1/bridge/ast/shim.go +1656 -0
- package/targets/7.1/bridge/ast/surface.go +686 -0
- package/targets/7.1/bridge/ast/test/next_jsdoc_comment_location_reaches_variable_statement_test.go +51 -0
- package/targets/7.1/bridge/ast/test/node_text_joins_multi_hop_qualified_name_test.go +47 -0
- package/targets/7.1/bridge/ast/test/node_text_joins_one_hop_qualified_name_test.go +35 -0
- package/targets/7.1/bridge/ast/test/node_text_returns_empty_for_nil_test.go +31 -0
- package/targets/7.1/bridge/ast/test/node_text_returns_identifier_text_test.go +34 -0
- package/targets/7.1/bridge/ast/test/node_text_skips_empty_qualified_left_test.go +60 -0
- package/targets/7.1/bridge/astnav/go.mod +14 -0
- package/targets/7.1/bridge/astnav/go.sum +22 -0
- package/targets/7.1/bridge/astnav/shim.go +24 -0
- package/targets/7.1/bridge/bundled/extra-shim.json +1 -0
- package/targets/7.1/bridge/bundled/go.mod +10 -0
- package/targets/7.1/bridge/bundled/go.sum +10 -0
- package/targets/7.1/bridge/bundled/shim.go +24 -0
- package/targets/7.1/bridge/checker/enums_gen.go +150 -0
- package/targets/7.1/bridge/checker/extra-shim.json +37 -0
- package/targets/7.1/bridge/checker/go.mod +15 -0
- package/targets/7.1/bridge/checker/go.sum +24 -0
- package/targets/7.1/bridge/checker/node_builder_fields_gen.go +19 -0
- package/targets/7.1/bridge/checker/shim.go +1390 -0
- package/targets/7.1/bridge/compiler/contentmapper_process.go +70 -0
- package/targets/7.1/bridge/compiler/emit_sourcemap.go +296 -0
- package/targets/7.1/bridge/compiler/emitassemble.go +81 -0
- package/targets/7.1/bridge/compiler/emithook.go +44 -0
- package/targets/7.1/bridge/compiler/extra-shim.json +4 -0
- package/targets/7.1/bridge/compiler/go.mod +15 -0
- package/targets/7.1/bridge/compiler/go.sum +24 -0
- package/targets/7.1/bridge/compiler/incremental.go +185 -0
- package/targets/7.1/bridge/compiler/neutral.go +256 -0
- package/targets/7.1/bridge/compiler/resolution.go +571 -0
- package/targets/7.1/bridge/compiler/shim.go +70 -0
- package/targets/7.1/bridge/core/enums_gen.go +15 -0
- package/targets/7.1/bridge/core/extra-shim.json +4 -0
- package/targets/7.1/bridge/core/go.mod +7 -0
- package/targets/7.1/bridge/core/go.sum +8 -0
- package/targets/7.1/bridge/core/modulekind.go +19 -0
- package/targets/7.1/bridge/core/shim.go +272 -0
- package/targets/7.1/bridge/diagnosticwriter/go.mod +14 -0
- package/targets/7.1/bridge/diagnosticwriter/go.sum +20 -0
- package/targets/7.1/bridge/diagnosticwriter/lint.go +411 -0
- package/targets/7.1/bridge/diagnosticwriter/shim.go +56 -0
- package/targets/7.1/bridge/lsp/extra-shim.json +4 -0
- package/targets/7.1/bridge/lsp/go.mod +16 -0
- package/targets/7.1/bridge/lsp/go.sum +26 -0
- package/targets/7.1/bridge/lsp/shim.go +112 -0
- package/targets/7.1/bridge/parser/extra-shim.json +4 -0
- package/targets/7.1/bridge/parser/go.mod +14 -0
- package/targets/7.1/bridge/parser/go.sum +24 -0
- package/targets/7.1/bridge/parser/shim.go +61 -0
- package/targets/7.1/bridge/printer/emithost.go +69 -0
- package/targets/7.1/bridge/printer/go.mod +15 -0
- package/targets/7.1/bridge/printer/go.sum +24 -0
- package/targets/7.1/bridge/printer/shim.go +168 -0
- package/targets/7.1/bridge/printer/sourcemap.go +49 -0
- package/targets/7.1/bridge/scanner/extra-shim.json +4 -0
- package/targets/7.1/bridge/scanner/go.mod +14 -0
- package/targets/7.1/bridge/scanner/go.sum +20 -0
- package/targets/7.1/bridge/scanner/regexp.go +42 -0
- package/targets/7.1/bridge/scanner/shim.go +137 -0
- package/targets/7.1/bridge/stringutil/extra-shim.json +1 -0
- package/targets/7.1/bridge/stringutil/go.mod +5 -0
- package/targets/7.1/bridge/stringutil/go.sum +2 -0
- package/targets/7.1/bridge/stringutil/shim.go +131 -0
- package/targets/7.1/bridge/transformers/go.mod +15 -0
- package/targets/7.1/bridge/transformers/go.sum +24 -0
- package/targets/7.1/bridge/transformers/shim.go +24 -0
- package/targets/7.1/bridge/tsoptions/command_line_raw.go +44 -0
- package/targets/7.1/bridge/tsoptions/extra-shim.json +4 -0
- package/targets/7.1/bridge/tsoptions/go.mod +15 -0
- package/targets/7.1/bridge/tsoptions/go.sum +24 -0
- package/targets/7.1/bridge/tsoptions/neutral.go +47 -0
- package/targets/7.1/bridge/tsoptions/shim.go +193 -0
- package/targets/7.1/bridge/tspath/extra-shim.json +4 -0
- package/targets/7.1/bridge/tspath/go.mod +5 -0
- package/targets/7.1/bridge/tspath/go.sum +6 -0
- package/targets/7.1/bridge/tspath/neutral.go +142 -0
- package/targets/7.1/bridge/tspath/shim.go +382 -0
- package/targets/7.1/bridge/vfs/cachedvfs/extra-shim.json +4 -0
- package/targets/7.1/bridge/vfs/cachedvfs/go.mod +5 -0
- package/targets/7.1/bridge/vfs/cachedvfs/go.sum +10 -0
- package/targets/7.1/bridge/vfs/cachedvfs/shim.go +12 -0
- package/targets/7.1/bridge/vfs/decode.go +26 -0
- package/targets/7.1/bridge/vfs/decode_test.go +42 -0
- package/targets/7.1/bridge/vfs/extra-shim.json +4 -0
- package/targets/7.1/bridge/vfs/go.mod +10 -0
- package/targets/7.1/bridge/vfs/go.sum +10 -0
- package/targets/7.1/bridge/vfs/neutral.go +23 -0
- package/targets/7.1/bridge/vfs/osvfs/extra-shim.json +4 -0
- package/targets/7.1/bridge/vfs/osvfs/go.mod +10 -0
- package/targets/7.1/bridge/vfs/osvfs/go.sum +10 -0
- package/targets/7.1/bridge/vfs/osvfs/shim.go +14 -0
- package/targets/7.1/bridge/vfs/shim.go +27 -0
- package/targets/7.1/facade/ast/facade_gen.go +2691 -0
- package/targets/7.1/facade/ast/go.mod +20 -0
- package/targets/7.1/facade/ast/go.sum +20 -0
- package/targets/7.1/facade/astnav/facade_gen.go +15 -0
- package/targets/7.1/facade/astnav/go.mod +22 -0
- package/targets/7.1/facade/astnav/go.sum +22 -0
- package/targets/7.1/facade/bundled/facade_gen.go +32 -0
- package/targets/7.1/facade/bundled/go.mod +21 -0
- package/targets/7.1/facade/bundled/go.sum +10 -0
- package/targets/7.1/facade/checker/facade_gen.go +563 -0
- package/targets/7.1/facade/checker/go.mod +26 -0
- package/targets/7.1/facade/checker/go.sum +24 -0
- package/targets/7.1/facade/compiler/facade_gen.go +198 -0
- package/targets/7.1/facade/compiler/go.mod +41 -0
- package/targets/7.1/facade/compiler/go.sum +24 -0
- package/targets/7.1/facade/core/facade_gen.go +130 -0
- package/targets/7.1/facade/core/go.mod +12 -0
- package/targets/7.1/facade/core/go.sum +8 -0
- package/targets/7.1/facade/diagnosticwriter/facade_gen.go +36 -0
- package/targets/7.1/facade/diagnosticwriter/go.mod +22 -0
- package/targets/7.1/facade/diagnosticwriter/go.sum +20 -0
- package/targets/7.1/facade/lsp/facade_gen.go +31 -0
- package/targets/7.1/facade/lsp/go.mod +19 -0
- package/targets/7.1/facade/lsp/go.sum +26 -0
- package/targets/7.1/facade/parser/facade_gen.go +102 -0
- package/targets/7.1/facade/parser/go.mod +25 -0
- package/targets/7.1/facade/parser/go.sum +24 -0
- package/targets/7.1/facade/printer/facade_gen.go +74 -0
- package/targets/7.1/facade/printer/go.mod +26 -0
- package/targets/7.1/facade/printer/go.sum +24 -0
- package/targets/7.1/facade/scanner/facade_gen.go +191 -0
- package/targets/7.1/facade/scanner/go.mod +25 -0
- package/targets/7.1/facade/scanner/go.sum +20 -0
- package/targets/7.1/facade/stringutil/facade_gen.go +176 -0
- package/targets/7.1/facade/stringutil/go.mod +9 -0
- package/targets/7.1/facade/stringutil/go.sum +2 -0
- package/targets/7.1/facade/transformers/facade_gen.go +12 -0
- package/targets/7.1/facade/transformers/go.mod +18 -0
- package/targets/7.1/facade/transformers/go.sum +24 -0
- package/targets/7.1/facade/tsoptions/facade_gen.go +274 -0
- package/targets/7.1/facade/tsoptions/go.mod +32 -0
- package/targets/7.1/facade/tsoptions/go.sum +24 -0
- package/targets/7.1/facade/tspath/facade_gen.go +550 -0
- package/targets/7.1/facade/tspath/go.mod +9 -0
- package/targets/7.1/facade/tspath/go.sum +6 -0
- package/targets/7.1/facade/vfs/cachedvfs/facade_gen.go +17 -0
- package/targets/7.1/facade/vfs/cachedvfs/go.mod +18 -0
- package/targets/7.1/facade/vfs/cachedvfs/go.sum +10 -0
- package/targets/7.1/facade/vfs/facade_gen.go +47 -0
- package/targets/7.1/facade/vfs/go.mod +18 -0
- package/targets/7.1/facade/vfs/go.sum +10 -0
- package/targets/7.1/facade/vfs/osvfs/facade_gen.go +20 -0
- package/targets/7.1/facade/vfs/osvfs/go.mod +21 -0
- package/targets/7.1/facade/vfs/osvfs/go.sum +10 -0
- package/tools/gen_facade/committed_facades_match_their_bridges_test.go +57 -0
- package/tools/gen_facade/facade_manifest_points_into_the_bridge_root_test.go +75 -0
- package/tools/gen_facade/facade_spells_internal_types_through_bridge_aliases_test.go +75 -0
- package/tools/gen_facade/facade_types_are_their_bridge_types_test.go +99 -0
- package/tools/gen_facade/go.mod +10 -0
- package/tools/gen_facade/go.sum +8 -0
- package/tools/gen_facade/main.go +734 -0
- package/tools/gen_shims/go.mod +4 -4
- package/tools/gen_shims/go.sum +6 -6
- package/tools/gen_shims/main.go +124 -66
- package/tools/gen_shims/mirror_structs_terminate_on_unexported_cycles_test.go +101 -0
- package/tools/shim_audit/baseline-7.1.json +720 -0
- package/tools/shim_audit/baseline.json +5 -4
- package/tools/shim_audit/go.mod +4 -4
- package/tools/shim_audit/go.sum +6 -6
- package/tools/shim_audit/linkname_signatures.go +178 -0
- package/tools/shim_audit/linkname_signatures_match_their_targets_test.go +64 -0
- package/tools/shim_audit/linkname_targets_follow_the_audited_compiler_test.go +38 -0
- package/tools/shim_audit/main.go +29 -4
- package/tools/shim_audit/neutral_api.go +160 -0
- package/tools/shim_audit/neutral_api_must_match_across_targets_test.go +74 -0
- package/utility/host.go +5 -4
- package/utility/preamble_output.go +15 -15
- package/utility/serve.go +1 -1
package/tools/gen_shims/go.mod
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
module github.com/samchon/ttsc/packages/ttsc/tools/gen_shims
|
|
2
2
|
|
|
3
|
-
go 1.
|
|
3
|
+
go 1.27
|
|
4
4
|
|
|
5
5
|
require (
|
|
6
6
|
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433
|
|
7
7
|
golang.org/x/text v0.35.0
|
|
8
|
-
golang.org/x/tools v0.
|
|
8
|
+
golang.org/x/tools v0.52.0
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
require (
|
|
12
|
-
golang.org/x/mod v0.
|
|
13
|
-
golang.org/x/sync v0.
|
|
12
|
+
golang.org/x/mod v0.42.0 // indirect
|
|
13
|
+
golang.org/x/sync v0.24.0 // indirect
|
|
14
14
|
)
|
package/tools/gen_shims/go.sum
CHANGED
|
@@ -2,11 +2,11 @@ github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 h1:vymEbVw
|
|
|
2
2
|
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg=
|
|
3
3
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
|
4
4
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
|
5
|
-
golang.org/x/mod v0.
|
|
6
|
-
golang.org/x/mod v0.
|
|
7
|
-
golang.org/x/sync v0.
|
|
8
|
-
golang.org/x/sync v0.
|
|
5
|
+
golang.org/x/mod v0.42.0 h1:ICeL3t2L30ljSPHHxDnR4fqVcBt/zR2zJAb9juavmQg=
|
|
6
|
+
golang.org/x/mod v0.42.0/go.mod h1:u5fzIrRInkL8MaO1cbRkUHT64v303YIT5KEqpNr7jRs=
|
|
7
|
+
golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA=
|
|
8
|
+
golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
|
|
9
9
|
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
|
|
10
10
|
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
|
|
11
|
-
golang.org/x/tools v0.
|
|
12
|
-
golang.org/x/tools v0.
|
|
11
|
+
golang.org/x/tools v0.52.0 h1:ryxg4U63oaUYk7uOLTF37n43f4qgtGvqV4Ioit1BaEs=
|
|
12
|
+
golang.org/x/tools v0.52.0/go.mod h1:ItcP5UNaVGG+Yc4eIYmaFLNJ4soEopkx5Y2d4lcEurs=
|
package/tools/gen_shims/main.go
CHANGED
|
@@ -12,15 +12,23 @@
|
|
|
12
12
|
//
|
|
13
13
|
// cd packages/ttsc
|
|
14
14
|
// go run -modfile=tools/gen_shims/go.mod ./tools/gen_shims/main.go
|
|
15
|
+
// go run -modfile=tools/gen_shims/go.mod ./tools/gen_shims/main.go -check
|
|
15
16
|
//
|
|
16
|
-
//
|
|
17
|
+
// -shim and -internal select a compiler target: the shim root and the
|
|
18
|
+
// compiler's internal import prefix. The defaults are the TypeScript 7.0 target.
|
|
19
|
+
// -check writes nothing and fails when a committed file differs from the output.
|
|
20
|
+
//
|
|
21
|
+
// Each shim directory (`<shim root>/<name>`) may contain an
|
|
17
22
|
// `extra-shim.json` file (an absent file means no extras); the generator writes its output to
|
|
18
|
-
//
|
|
23
|
+
// `<shim root>/<name>/shim.go` or a configured private support file, formatted
|
|
24
|
+
// as gofmt with two-space indentation like the repository's Go sources.
|
|
19
25
|
package main
|
|
20
26
|
|
|
21
27
|
import (
|
|
22
28
|
"bytes"
|
|
29
|
+
"flag"
|
|
23
30
|
"fmt"
|
|
31
|
+
"go/format"
|
|
24
32
|
"go/types"
|
|
25
33
|
"log"
|
|
26
34
|
"maps"
|
|
@@ -36,7 +44,11 @@ import (
|
|
|
36
44
|
"golang.org/x/tools/go/packages"
|
|
37
45
|
)
|
|
38
46
|
|
|
39
|
-
|
|
47
|
+
// defaultInternalPrefix is the TypeScript 7.0 compiler's internal tree.
|
|
48
|
+
const defaultInternalPrefix = "github.com/microsoft/typescript-go/internal/"
|
|
49
|
+
|
|
50
|
+
// tsgoInternalPrefix is the internal tree of the target being generated.
|
|
51
|
+
var tsgoInternalPrefix = defaultInternalPrefix
|
|
40
52
|
|
|
41
53
|
// Packages for which we generate a shim. Mirrors tsgolint's list with
|
|
42
54
|
// project/lsp/lsproto removed for the current host boundary and the rest kept
|
|
@@ -99,14 +111,47 @@ func signatureHasUnexportedType(t types.Signature) bool {
|
|
|
99
111
|
return false
|
|
100
112
|
}
|
|
101
113
|
|
|
114
|
+
// generatedFile is one generator output and its destination.
|
|
115
|
+
type generatedFile struct {
|
|
116
|
+
path string
|
|
117
|
+
source []byte
|
|
118
|
+
}
|
|
119
|
+
|
|
102
120
|
func main() {
|
|
121
|
+
shimRoot := flag.String("shim", "./shim", "shim root of the compiler target")
|
|
122
|
+
internal := flag.String("internal", defaultInternalPrefix, "internal import prefix of the compiler target")
|
|
123
|
+
check := flag.Bool("check", false, "report stale generated files without writing them")
|
|
124
|
+
flag.Parse()
|
|
125
|
+
tsgoInternalPrefix = *internal
|
|
126
|
+
|
|
127
|
+
var stale []string
|
|
128
|
+
for _, output := range generate(*shimRoot) {
|
|
129
|
+
if *check {
|
|
130
|
+
if current, err := os.ReadFile(output.path); err != nil || !bytes.Equal(current, output.source) {
|
|
131
|
+
stale = append(stale, output.path)
|
|
132
|
+
}
|
|
133
|
+
continue
|
|
134
|
+
}
|
|
135
|
+
if err := os.WriteFile(output.path, output.source, 0o644); err != nil {
|
|
136
|
+
log.Fatalf("gen_shims: writing %v: %v", output.path, err)
|
|
137
|
+
}
|
|
138
|
+
fmt.Fprintf(os.Stdout, "gen_shims: wrote %s (%d bytes)\n", output.path, len(output.source))
|
|
139
|
+
}
|
|
140
|
+
if len(stale) > 0 {
|
|
141
|
+
log.Fatalf("gen_shims: stale generated files (run without -check):\n %s", strings.Join(stale, "\n "))
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// generate renders every shim of the target rooted at shimRoot without writing
|
|
146
|
+
// it, so -check and a regeneration share one output.
|
|
147
|
+
func generate(shimRoot string) []generatedFile {
|
|
103
148
|
fullNames := make([]string, len(packagesToShim))
|
|
104
149
|
for i, pkg := range packagesToShim {
|
|
105
150
|
fullNames[i] = tsgoInternalPrefix + pkg
|
|
106
151
|
}
|
|
107
152
|
|
|
108
153
|
loaded, err := packages.Load(&packages.Config{
|
|
109
|
-
Dir: "
|
|
154
|
+
Dir: path.Join(shimRoot, "ast"), // any shim module works as anchor; they all require the compiler
|
|
110
155
|
Mode: packages.LoadSyntax,
|
|
111
156
|
}, fullNames...)
|
|
112
157
|
if err != nil {
|
|
@@ -116,12 +161,13 @@ func main() {
|
|
|
116
161
|
log.Fatalf("gen_shims: packages.Load: %v", err)
|
|
117
162
|
}
|
|
118
163
|
|
|
164
|
+
var outputs []generatedFile
|
|
119
165
|
var shimHeaderBuilder strings.Builder
|
|
120
166
|
var shimBuilder strings.Builder
|
|
121
167
|
var tempBuffer bytes.Buffer
|
|
122
168
|
|
|
123
169
|
for _, pkg := range loaded {
|
|
124
|
-
shimDirPath := path.Join(
|
|
170
|
+
shimDirPath := path.Join(shimRoot, strings.TrimPrefix(pkg.PkgPath, tsgoInternalPrefix))
|
|
125
171
|
|
|
126
172
|
var extraShim ExtraShim
|
|
127
173
|
extraShimFilePath := path.Join(shimDirPath, "extra-shim.json")
|
|
@@ -148,6 +194,8 @@ func main() {
|
|
|
148
194
|
// true = referenced by name (needs a named import).
|
|
149
195
|
// false = only needed for its side-effects (blank import "_").
|
|
150
196
|
importedPackages := map[string]bool{}
|
|
197
|
+
// mirrored records the extra_ mirror structs this file already declares.
|
|
198
|
+
mirrored := map[string]bool{}
|
|
151
199
|
importPackage := func(path string, directly bool) {
|
|
152
200
|
if directly {
|
|
153
201
|
importedPackages[path] = true
|
|
@@ -331,10 +379,11 @@ func main() {
|
|
|
331
379
|
if path.Base(filename) != filename || !strings.HasSuffix(filename, "_gen.go") {
|
|
332
380
|
log.Fatalf("gen_shims: invalid generated field support filename %q", filename)
|
|
333
381
|
}
|
|
334
|
-
|
|
335
|
-
|
|
382
|
+
formatted, err := formatShim(output)
|
|
383
|
+
if err != nil {
|
|
384
|
+
log.Fatalf("gen_shims: field support %s: %v", name, err)
|
|
336
385
|
}
|
|
337
|
-
|
|
386
|
+
outputs = append(outputs, generatedFile{path: path.Join(shimDirPath, filename), source: formatted})
|
|
338
387
|
matchedExtraFields[name] = true
|
|
339
388
|
continue
|
|
340
389
|
}
|
|
@@ -342,60 +391,13 @@ func main() {
|
|
|
342
391
|
matchedExtraFields[name] = true
|
|
343
392
|
mirrorStructName := "extra_" + name
|
|
344
393
|
|
|
345
|
-
// emitExtraStruct emits a mirror struct (`extra_<Name>`) whose field
|
|
346
|
-
// layout matches the unexported original so that unsafe.Pointer casts
|
|
347
|
-
// in the generated accessor functions are safe. Unexported pointer
|
|
348
|
-
// fields whose element type is also unexported are recursively mirrored.
|
|
349
|
-
var emitExtraStruct func(name string, s *types.Struct)
|
|
350
|
-
emitExtraStruct = func(name string, s *types.Struct) {
|
|
351
|
-
shimBuilder.WriteString("type extra_")
|
|
352
|
-
shimBuilder.WriteString(name)
|
|
353
|
-
shimBuilder.WriteString(" struct {")
|
|
354
|
-
|
|
355
|
-
dependencies := []struct {
|
|
356
|
-
string
|
|
357
|
-
*types.Struct
|
|
358
|
-
}{}
|
|
359
|
-
for field := range s.Fields() {
|
|
360
|
-
shimBuilder.WriteString("\n ")
|
|
361
|
-
if !field.Embedded() {
|
|
362
|
-
shimBuilder.WriteString(field.Name())
|
|
363
|
-
shimBuilder.WriteByte(' ')
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
ptrType, ok := field.Type().(*types.Pointer)
|
|
367
|
-
if ok {
|
|
368
|
-
named, ok := ptrType.Elem().(*types.Named)
|
|
369
|
-
if ok && !named.Obj().Exported() {
|
|
370
|
-
strct, ok := named.Underlying().(*types.Struct)
|
|
371
|
-
if ok {
|
|
372
|
-
n := named.Obj().Name()
|
|
373
|
-
dependencies = append(dependencies, struct {
|
|
374
|
-
string
|
|
375
|
-
*types.Struct
|
|
376
|
-
}{n, strct})
|
|
377
|
-
shimBuilder.WriteString("extra_")
|
|
378
|
-
shimBuilder.WriteString(n)
|
|
379
|
-
continue
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
shimBuilder.WriteString(
|
|
385
|
-
strings.ReplaceAll(types.TypeString(field.Type(), qualifierOnlyPackageName), "checker.thisAssignmentDeclarationKind", "int32"),
|
|
386
|
-
)
|
|
387
|
-
}
|
|
388
|
-
shimBuilder.WriteString("\n}\n")
|
|
389
|
-
for _, dep := range dependencies {
|
|
390
|
-
emitExtraStruct(dep.string, dep.Struct)
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
394
|
strct, ok := named.Underlying().(*types.Struct)
|
|
395
395
|
if !ok {
|
|
396
396
|
log.Fatalf("gen_shims: expected %v to be struct", name)
|
|
397
397
|
}
|
|
398
|
-
|
|
398
|
+
writeMirrorStructs(&shimBuilder, name, strct, mirrored, func(t types.Type) string {
|
|
399
|
+
return strings.ReplaceAll(types.TypeString(t, qualifierOnlyPackageName), "checker.thisAssignmentDeclarationKind", "int32")
|
|
400
|
+
})
|
|
399
401
|
|
|
400
402
|
mappedFieldTypes := make(map[string]*types.Var, strct.NumFields())
|
|
401
403
|
for field := range strct.Fields() {
|
|
@@ -483,21 +485,77 @@ func main() {
|
|
|
483
485
|
if isHandMaintained(shimGoPath) {
|
|
484
486
|
fmt.Fprintf(os.Stderr, "gen_shims: skipping %s (hand-maintained marker present; remove '// gen_shims:hand-maintained' to regenerate)\n", shimGoPath)
|
|
485
487
|
} else {
|
|
486
|
-
|
|
488
|
+
formatted, err := formatShim([]byte(shimHeaderBuilder.String() + shimBuilder.String()))
|
|
487
489
|
if err != nil {
|
|
488
|
-
log.Fatalf("gen_shims:
|
|
490
|
+
log.Fatalf("gen_shims: %v: %v", shimGoPath, err)
|
|
489
491
|
}
|
|
490
|
-
|
|
491
|
-
file.WriteString(shimBuilder.String())
|
|
492
|
-
if err := file.Close(); err != nil {
|
|
493
|
-
log.Fatalf("gen_shims: closing %v: %v", shimGoPath, err)
|
|
494
|
-
}
|
|
495
|
-
fmt.Fprintf(os.Stdout, "gen_shims: wrote %s (%d bytes)\n", shimGoPath, len(shimBuilder.String()))
|
|
492
|
+
outputs = append(outputs, generatedFile{path: shimGoPath, source: formatted})
|
|
496
493
|
}
|
|
497
494
|
|
|
498
495
|
shimHeaderBuilder.Reset()
|
|
499
496
|
shimBuilder.Reset()
|
|
500
497
|
}
|
|
498
|
+
return outputs
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// writeMirrorStructs writes a mirror struct `extra_<name>` whose field layout
|
|
502
|
+
// matches the unexported original, so the generated accessors' unsafe.Pointer
|
|
503
|
+
// casts read the right offsets. An unexported pointer-to-struct field is
|
|
504
|
+
// mirrored in turn. seen holds the mirrors the file already declares: a cycle
|
|
505
|
+
// of unexported pointers then terminates, and a struct reached through two
|
|
506
|
+
// fields is declared once. typeString spells every other field type.
|
|
507
|
+
func writeMirrorStructs(out *strings.Builder, name string, s *types.Struct, seen map[string]bool, typeString func(types.Type) string) {
|
|
508
|
+
if seen[name] {
|
|
509
|
+
return
|
|
510
|
+
}
|
|
511
|
+
seen[name] = true
|
|
512
|
+
out.WriteString("type extra_")
|
|
513
|
+
out.WriteString(name)
|
|
514
|
+
out.WriteString(" struct {")
|
|
515
|
+
|
|
516
|
+
type dependency struct {
|
|
517
|
+
name string
|
|
518
|
+
layout *types.Struct
|
|
519
|
+
}
|
|
520
|
+
var dependencies []dependency
|
|
521
|
+
for field := range s.Fields() {
|
|
522
|
+
out.WriteString("\n ")
|
|
523
|
+
if !field.Embedded() {
|
|
524
|
+
out.WriteString(field.Name())
|
|
525
|
+
out.WriteByte(' ')
|
|
526
|
+
}
|
|
527
|
+
if pointer, ok := field.Type().(*types.Pointer); ok {
|
|
528
|
+
if named, ok := pointer.Elem().(*types.Named); ok && !named.Obj().Exported() {
|
|
529
|
+
if structure, ok := named.Underlying().(*types.Struct); ok {
|
|
530
|
+
dependencies = append(dependencies, dependency{named.Obj().Name(), structure})
|
|
531
|
+
out.WriteString("*extra_")
|
|
532
|
+
out.WriteString(named.Obj().Name())
|
|
533
|
+
continue
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
out.WriteString(typeString(field.Type()))
|
|
538
|
+
}
|
|
539
|
+
out.WriteString("\n}\n")
|
|
540
|
+
for _, dep := range dependencies {
|
|
541
|
+
writeMirrorStructs(out, dep.name, dep.layout, seen, typeString)
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// formatShim applies the repository's Go layout to generated source: gofmt,
|
|
546
|
+
// then two spaces for each leading tab. gofmt indents with tabs and aligns with
|
|
547
|
+
// spaces, so leading tabs are exactly the indentation.
|
|
548
|
+
func formatShim(source []byte) ([]byte, error) {
|
|
549
|
+
formatted, err := format.Source(source)
|
|
550
|
+
if err != nil {
|
|
551
|
+
return nil, err
|
|
552
|
+
}
|
|
553
|
+
lines := bytes.Split(formatted, []byte("\n"))
|
|
554
|
+
for i, line := range lines {
|
|
555
|
+
trimmed := bytes.TrimLeft(line, "\t")
|
|
556
|
+
lines[i] = append(bytes.Repeat([]byte(" "), len(line)-len(trimmed)), trimmed...)
|
|
557
|
+
}
|
|
558
|
+
return bytes.Join(lines, []byte("\n")), nil
|
|
501
559
|
}
|
|
502
560
|
|
|
503
561
|
// validateShimPackages admits a complete, error-free package population before
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"go/ast"
|
|
5
|
+
"go/parser"
|
|
6
|
+
"go/token"
|
|
7
|
+
"go/types"
|
|
8
|
+
"runtime"
|
|
9
|
+
"strings"
|
|
10
|
+
"testing"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
// Verifies mirror generation terminates on a cycle of unexported structs and
|
|
14
|
+
// declares every mirror once with the original layout.
|
|
15
|
+
//
|
|
16
|
+
// TypeScript 7.1's Checker reaches unexported structs that point back at each
|
|
17
|
+
// other, and the unguarded recursion overflowed the stack. The mirrors back
|
|
18
|
+
// unsafe field reads, so each must keep its original's size and offsets.
|
|
19
|
+
//
|
|
20
|
+
// 1. Type-check a Checker whose unexported node and edge structs form a cycle,
|
|
21
|
+
// reached through two fields, beside an exported pointer and a scalar.
|
|
22
|
+
// 2. Generate the mirrors and count each declaration.
|
|
23
|
+
// 3. Type-check the mirrors and compare their sizes and offsets with the originals.
|
|
24
|
+
//
|
|
25
|
+
// @evidence contracts/testing.md#behavioral-verification Calls the production writeMirrorStructs over go/types structs and type-checks its output; the declaration counts and layout comparison catch unbounded recursion, a duplicate mirror, a value-typed mirror field or a dropped field.
|
|
26
|
+
// @evidence contracts/testing.md#independent-expectations The authored fixture fixes which structs are unexported and cyclic, so the expected mirror set and single declarations follow from it; Go's gc size model independently supplies sizes and offsets.
|
|
27
|
+
// @evidence contracts/testing.md#distinguishing-cases A two-struct cycle, a struct reached through two fields, an exported pointer that must stay unmirrored, and a scalar field each require a different spelling.
|
|
28
|
+
// @evidence contracts/testing.md#execution-ownership This tools/gen_shims source unit parses and type-checks in memory in one Go process; it loads no module, writes no file and starts no process.
|
|
29
|
+
func TestMirrorStructsTerminateOnUnexportedCycles(t *testing.T) {
|
|
30
|
+
fset := token.NewFileSet()
|
|
31
|
+
upstreamFile, err := parser.ParseFile(fset, "upstream.go", `package checker
|
|
32
|
+
type Program struct{ files []string }
|
|
33
|
+
type node struct {
|
|
34
|
+
next *node
|
|
35
|
+
edges *edge
|
|
36
|
+
depth int
|
|
37
|
+
}
|
|
38
|
+
type edge struct {
|
|
39
|
+
from *node
|
|
40
|
+
to *node
|
|
41
|
+
}
|
|
42
|
+
type Checker struct {
|
|
43
|
+
program *Program
|
|
44
|
+
root *node
|
|
45
|
+
spare *node
|
|
46
|
+
count int
|
|
47
|
+
}
|
|
48
|
+
`, 0)
|
|
49
|
+
if err != nil {
|
|
50
|
+
t.Fatal(err)
|
|
51
|
+
}
|
|
52
|
+
upstream, err := (&types.Config{}).Check(tsgoInternalPrefix+"checker", fset, []*ast.File{upstreamFile}, nil)
|
|
53
|
+
if err != nil {
|
|
54
|
+
t.Fatal(err)
|
|
55
|
+
}
|
|
56
|
+
checker := upstream.Scope().Lookup("Checker").Type().Underlying().(*types.Struct)
|
|
57
|
+
|
|
58
|
+
var out strings.Builder
|
|
59
|
+
writeMirrorStructs(&out, "Checker", checker, map[string]bool{}, func(t types.Type) string {
|
|
60
|
+
return types.TypeString(t, func(*types.Package) string { return "" })
|
|
61
|
+
})
|
|
62
|
+
generated := out.String()
|
|
63
|
+
for _, mirror := range []string{"extra_Checker", "extra_node", "extra_edge"} {
|
|
64
|
+
if count := strings.Count(generated, "type "+mirror+" struct"); count != 1 {
|
|
65
|
+
t.Fatalf("%s declared %d times:\n%s", mirror, count, generated)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if strings.Contains(generated, "extra_Program") || !strings.Contains(generated, "program *Program") {
|
|
69
|
+
t.Fatalf("exported pointer field was mirrored instead of spelled:\n%s", generated)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// The exported Program stays spelled by name, so the mirror file declares
|
|
73
|
+
// the same layout under that name.
|
|
74
|
+
mirrorFile, err := parser.ParseFile(fset, "mirror.go", "package mirror\ntype Program struct{ files []string }\n"+generated, 0)
|
|
75
|
+
if err != nil {
|
|
76
|
+
t.Fatalf("%v:\n%s", err, generated)
|
|
77
|
+
}
|
|
78
|
+
mirrors, err := (&types.Config{}).Check("fixture/mirror", fset, []*ast.File{mirrorFile}, nil)
|
|
79
|
+
if err != nil {
|
|
80
|
+
t.Fatalf("%v:\n%s", err, generated)
|
|
81
|
+
}
|
|
82
|
+
sizes := types.SizesFor("gc", runtime.GOARCH)
|
|
83
|
+
for _, name := range []string{"Checker", "node", "edge"} {
|
|
84
|
+
original := upstream.Scope().Lookup(name).Type().Underlying().(*types.Struct)
|
|
85
|
+
mirror := mirrors.Scope().Lookup("extra_" + name).Type().Underlying().(*types.Struct)
|
|
86
|
+
if original.NumFields() != mirror.NumFields() || sizes.Sizeof(original) != sizes.Sizeof(mirror) {
|
|
87
|
+
t.Fatalf("extra_%s does not keep %s's layout", name, name)
|
|
88
|
+
}
|
|
89
|
+
originalFields := make([]*types.Var, original.NumFields())
|
|
90
|
+
mirrorFields := make([]*types.Var, mirror.NumFields())
|
|
91
|
+
for i := range originalFields {
|
|
92
|
+
originalFields[i], mirrorFields[i] = original.Field(i), mirror.Field(i)
|
|
93
|
+
}
|
|
94
|
+
originalOffsets, mirrorOffsets := sizes.Offsetsof(originalFields), sizes.Offsetsof(mirrorFields)
|
|
95
|
+
for i := range originalOffsets {
|
|
96
|
+
if originalOffsets[i] != mirrorOffsets[i] || original.Field(i).Name() != mirror.Field(i).Name() {
|
|
97
|
+
t.Fatalf("extra_%s field %d moved", name, i)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|