Skip to content

Tests: c import surface coverage (§16) #487

Closed

Description

@ehartford

Summary

Add missing tests for c_import surface stability: enum translation, allow-list cache keys, and collision mangling. These are implemented or partially implemented behaviors that need regression coverage.

Spec

§16.2 says generated c_import surfaces contain only real bindings and reports inexpressible gaps honestly (docs/with-specification.md:8131, docs/with-specification.md:8171). Constant/enum-like C declarations should become With constants/types where representable, and duplicate names from transitive includes are mangled with numeric suffixes (name_2, name_3) (docs/with-specification.md:8201). The importer allow-list for acknowledged untranslated symbols must affect cache identity so changing it cannot reuse stale generated bindings; this requirement is tracked in docs/requirements.md under 16.2.1.18.

Current state

Frontend.c_import_cache_key_frontend includes link libraries and allow_untranslated names in the cache key (src/compiler/Frontend.w:352). Omitted unallowed symbols produce directional diagnostics with an allow_untranslated suggestion (src/compiler/Frontend.w:471). CImport.w contains enum constant emission and collision mangling logic around enum constants (src/CImport.w:1753) and records emitted names to avoid collisions throughout import generation. The issue is missing test coverage for these surface contracts.

Implementation plan

  1. Add a header fixture with an enum and assert the generated/imported With surface exposes constants/variants with the expected names and values.
  2. Add a duplicate-name fixture through transitive includes or repeated declarations and assert numeric suffixing (foo, foo_2) is deterministic.
  3. Add a cache-key test for allow_untranslated: import the same header once without an allow-list and once with one; assert the cache key/generated path differs or the second import does not reuse the first result.
  4. Add a negative test that referencing an omitted symbol without allow-list produces the directional diagnostic already emitted by Frontend.w.
  5. Keep the tests local and deterministic; do not depend on system headers.

Test plan

Add test/behavior/behav_c_import_enum_surface.h and .w. Add test/behavior/behav_c_import_collision_mangling.h plus any included headers needed to force duplicate names. Add a compile/check test for allow_untranslated cache key behavior, possibly by setting WITH_CIMPORT_CACHE_EPOCH or inspecting generated cache metadata if the harness supports it.

Acceptance criteria

  • C enum translation is covered.
  • Duplicate imported names receive deterministic numeric suffixes under test.
  • allow_untranslated participates in c_import cache identity under test.
  • Directional omitted-symbol diagnostics remain covered.
  • with build && with build :fixpoint && with build :test pass.

Dependencies

Related to #417 for omission manifest diagnostics and #418 for strict/selective import behavior.

Traceability

From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 16.1.1.10, 16.2.1.18, 16.2.1.26.

Activity

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    Closing the pinnable surface: C enum→constants (behav_c_import_enum_surface) + allow_untranslated (behav_c_import_allow_untranslated) covered (3628d82). Two sub-parts are NOT expressible as runnable .w fixtures and need harness mechanisms: cross-c_import collision mangling (_2 suffix, only observable via the internal dedup table) and cache-key participation (needs cache-metadata inspection). Flagged as harness gaps, not behavior gaps. §16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions