CEP-0008: Copy, Clone, and Ownership Capabilities¶
Draft
Draft proposal for explicit copy and clone capabilities. V1 has structural implicit copy eligibility and explicit move, but no public Copyable or Cloneable contract.
Summary¶
Catalyst should eventually expose copy and clone capabilities as first-class constraints or contracts so generic APIs can state their ownership requirements directly.
V1 already knows whether a type permits implicit copying, and @resource forbids copying while requiring visible disposal. What V1 lacks is a public way to name copyability or duplicating ownership in generic API signatures.
Example¶
Possible future shape:
fn duplicate(comptime T: Cloneable, value: *const T) T {
return value.clone()
}
fn remember_key(comptime T: Copyable, key: T) T {
return key
}
V1 can diagnose implicit copy eligibility, but code cannot name Cloneable or Copyable as public constraint types.
Motivation¶
Today, unconstrained generic code may attempt to copy T; instantiation fails when the concrete type forbids copying. That is implementable, but the API contract is implicit and diagnostics can point only at the failed operation.
Explicit capabilities would let APIs say:
- this function requires implicit copyability;
- this function can duplicate ownership by calling
clone; - this resource type is non-copy but explicitly cloneable;
- this generic container's copyability depends on its element type.
Proposed Direction¶
Future design should cover:
- explicit
Copyableconstraints or contracts; - explicit
Cloneablecontracts for duplicating ownership; - interaction between
@resource,Disposable,Cloneable, and copy prohibition; - derived or structural copy eligibility for aggregates;
- whether public copyability names are semantic contracts, structural constraints, reflection predicates, or compiler-owned constraint types;
- diagnostics that distinguish "cannot copy" from "can move" and "can clone explicitly".
Cloneable should not be treated as implicit copying. A clone operation is an explicit function call and may allocate, fail, or require authority depending on the chosen contract design.
V1 Compatibility¶
V1 keeps structural copy eligibility, declaration metadata that may forbid copying, and explicit move. Resource-like values do not opt back into implicit copyability.