Skip to content

Send/Sync enforcement substance (§14.16) #473

Closed

Description

@ehartford

Summary

Give Send, Sync, and ScopedSend real semantic force instead of mostly vacuous marker handling. Today Send and ScopedSend are interned as language traits, but Sync is not, and there are few or no owned non-Send witnesses until Rc/Arc land. The compiler needs a substantive trait model so tasks, channels, locks, generators, and future shared ownership enforce the §14.16 tables.

Spec

§14.16 defines Send as safe to move across threads, Sync as safe to share via &T across threads, and ScopedSend as safe to move to a bounded lexical thread. §14.20 and §14.22 apply those rules to generators and tasks. The table requires examples such as Rc[T] being non-Send/non-Sync and Arc[T] being Send/Sync only when T: Send + Sync.

Current state

Sema.init_intrinsic_symbols registers Send and ScopedSend as language-level traits but not Sync (src/Sema.w:1531, src/Sema.w:1535). Copy/Drop get real semantic logic; Send/Sync mostly reduce to existing ephemerality checks. Channels reject ephemeral sends and have a placeholder channel send requires Send value diagnostic (src/SemaCheck.w:11236), but without owned non-Send types that check has little substance.

Generic trait selection exists (src/SemaCheck.w:8922), but #391's generic-instance erasure limits correct per-instantiation reasoning. Future Rc/Arc (#470) and Box (#475) provide the needed non-Send and conditional-Send witnesses.

Implementation plan

  1. Intern Sync as a language trait beside Send and ScopedSend in src/Sema.w.
  2. Add semantic helpers type_is_send, type_is_sync, and type_is_scoped_send that handle primitives, references, raw pointers, tasks, generators, arrays/tuples, structs, enums, and generic instances.
  3. Make traits structural by default only where the spec allows it. A struct is Send if all stored fields are Send; Sync if all shared fields are Sync; references depend on referenced type and lifetime/ephemeral rules.
  4. Add explicit negative and conditional impl behavior for future Rc[T], Arc[T], Box[T], Task[T], ScopedTask[T], channels, locks, and generators. Do not use name-only heuristics.
  5. Wire the helpers into channel send (Bug: channel send does not consume; non-integer element types mistyped (§14.15) #419), Task sendability (Enforce Task sendability conditions (§14.7, §14.22) #480), OS-thread spawn, scoped thread spawn, generator sendability, and lock sharing.
  6. Improve diagnostics to name the reason: type Rc[T] is not Send, field foo is not Sync, or Task captures non-Send value.
  7. Sequence concrete non-Send witnesses behind Implement Rc[T] and Arc[T] (+ Shared[T] alias) (§8.2, §8.4, §14.16) #470 so tests can prove rejection with real owned types instead of artificial compiler-only fixtures.

Test plan

After #470, add tests:

  • err_send_rc_to_channel.w;
  • err_spawn_os_captures_rc.w;
  • err_sync_shared_rc_ref.w;
  • positive Arc[i32] send/sync;
  • negative Arc[Rc[i32]] if nested bounds fail;
  • scoped-send positive for stack-bounded thread scope where allowed.

Add sema unit/spec tests for structural Send/Sync of tuples, arrays, and structs.

Acceptance criteria

  • Send, Sync, and ScopedSend are all interned semantic language traits.
  • Compiler decisions use typed helpers, not only ephemerality or string checks.
  • Channel/task/thread/generator boundaries enforce the correct trait.
  • Diagnostics identify the non-Send/non-Sync source.
  • with build && with build :fixpoint && with build :test pass.

Dependencies

Depends on #391 and #470 for full useful coverage. Blocks #419 and #480 enforcement substance.

Traceability

From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 14.16.1.10, 14.16.1.13, 14.16.1.2, 14.16.1.9, 14.20.1.10, 14.22.1.20, 14.22.1.4.

Activity

  1. ehartford commented on Jun 15, 2026

    @ehartford
    ContributorAuthor

    Implemented in 42a540d4.

    What changed:

    • Interned Sync alongside Send and ScopedSend as language-level traits.
    • Added structural Send / Sync / ScopedSend predicates for primitives, references, structs, enums, generic instantiations, Box, Rc, Arc, Task, channels, and std containers.
    • Made Rc[T] non-Send/non-Sync, Arc[T] conditional on T: Send + Sync, and Box[T] delegate to T.
    • Enforced Send/ScopedSend at channel send/element boundaries and OS-thread/scoped-thread capture boundaries.
    • Tracked non-Send task provenance from async calls/captures so channel sends cannot smuggle non-Send work.
    • Added positive structural tests and negative diagnostics for Rc channel elements, Rc sends, non-Send tasks, thread.spawn_os, and scoped thread workers.
    • Removed the Send/Sync enforcement substance (§14.16) #473 traceability links from docs/requirements.md.

    Verification passed on pushed main: build, fixpoint, full :test, and explicit :test-green using the project seed/release compiler path.

    Note: the separate @TypeOf(generator_call()) alias crash discovered while attempting direct generator-state coverage remains open as #589.

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