Skip to content

[HC-010] Hard cutover public C frontend API to explicit ownership and error contracts #8141

@doublemover

Description

@doublemover

Hard cutover policy: the public frontend C API owns every contract explicitly. No borrowed result pointers, no undocumented lifetime, no silent null-argument behavior, no old ABI surface kept as a wrapper.

Source facts already established:

  • native/objc3c/src/libobjc3c_frontend/api.h exposes result path pointers as const char *.
  • frontend_anchor.cpp populates result paths from context-owned string storage.
  • Null context, options, and result arguments return usage errors without a complete caller-owned diagnostic result.
  • Public comments contain roadmap and lane text rather than a tight ABI contract.

Required public API tree:

  • native/objc3c/src/libobjc3c_frontend/public/
    • objc3c_frontend.h: umbrella public include.
    • objc3c_frontend_version.h: ABI version and feature version.
    • objc3c_frontend_context.h: opaque context create and destroy.
    • objc3c_frontend_options.h: canonical compile options.
    • objc3c_frontend_result.h: owned compile result.
    • objc3c_frontend_diagnostic.h: diagnostic list API.
    • objc3c_frontend_string.h: owned string API.
    • objc3c_frontend_artifact.h: artifact path API.
    • objc3c_frontend_error.h: structured error API.
  • native/objc3c/src/libobjc3c_frontend/internal/
    • context_impl.h/.cpp
    • options_bridge.h/.cpp
    • result_builder.h/.cpp
    • diagnostic_bridge.h/.cpp
    • string_arena.h/.cpp

Required API rules:

  • Every returned string is an owned objc3c_frontend_string_t released by one public function.
  • Every compile result is an owned objc3c_frontend_result_t released by one public function.
  • Every diagnostic list is owned by its result.
  • Null input returns a complete owned error result through dedicated constructors.
  • Multiple contexts compile concurrently with separate state.
  • One context serializes its own compile calls.
  • ABI version mismatch returns a structured error.
  • All old enum values and mode fields are deleted.

Required work:

  • Replace raw const char * result fields with owned API accessors.
  • Replace public lane and roadmap comments with concise ABI contract comments.
  • Add API tests for ownership, null arguments, concurrent contexts, result destruction, diagnostic retrieval, and ABI version mismatch.
  • Update the CLI runner to consume the new API only.
  • Delete old public header aliases and old result structs.

Maximum effort shared hoist pass:

  • Hoist string ownership to objc3c_frontend_string.*.
  • Hoist diagnostic conversion to internal/diagnostic_bridge.*.
  • Hoist artifact path conversion to public/objc3c_frontend_artifact.* and internal/result_builder.*.
  • Hoist context state construction to internal/context_impl.*.

Acceptance criteria:

  • Public headers contain ABI contracts only.
  • No public result struct exposes raw context-owned pointers.
  • rg "const char \*.*path|compatibility_mode|lane|roadmap|reserved future" native/objc3c/src/libobjc3c_frontend returns no public ABI surface.
  • C API tests run under normal user privileges and pass.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions