lang: Recognize the Copy marker on composites

96d22eeb80fd2313037c469738bcd6af9113a3201bf946359debba84ec17b4ea
Record `Copy` and `Linear` ownership markers on records and unions.
Check that a `Copy` composite holds only copy values and that no
declaration carries both markers. Track moves of non-copy bindings
and report uses after a move.

Records and unions stay copyable unless linear, so unmarked
declarations are still accepted. Mark the standard test types and
fixtures that are copyable with `Copy`.

Assisted-by: Claude:opus-5.5
Alexis Sellier committed ago 1 parent ee380f46
lib/std/lang/resolver.rad +182 -63
170 170
    labeled: bool,
171 171
    /// Cached layout.
172 172
    layout: Layout,
173 173
    /// Whether the declaration explicitly carries the `Linear` marker.
174 174
    declaredLinear: bool,
175 +
    /// Whether the declaration explicitly carries the `Copy` marker.
176 +
    declaredCopy: bool,
175 177
}
176 178
177 179
/// Union nominal type.
178 180
export record UnionType {
179 181
    variants: *[UnionVariant],
183 185
    valOffset: u32,
184 186
    /// If all variants have void payloads.
185 187
    isAllVoid: bool,
186 188
    /// Whether the declaration explicitly carries the `Linear` marker.
187 189
    declaredLinear: bool,
190 +
    /// Whether the declaration explicitly carries the `Copy` marker.
191 +
    declaredCopy: bool,
188 192
}
189 193
190 194
/// Metadata for user-defined types.
191 195
export union NominalType {
192 196
    /// Placeholder for a type that hasn't been fully resolved yet.
593 597
    FnThrowOverflow(CountMismatch),
594 598
    /// Trait declaration has too many methods.
595 599
    TraitMethodOverflow(CountMismatch),
596 600
    /// Instance declaration is missing a required supertrait instance.
597 601
    MissingSupertraitInstance(*[u8]),
602 +
    /// An affine binding was used after it moved.
603 +
    AffineUseAfterMove(*[u8]),
598 604
    /// Linear binding was consumed more than once.
599 605
    LinearUseAfterConsume(*[u8]),
600 606
    /// Linear binding remains available at an exit.
601 607
    LinearNotConsumed(*[u8]),
602 608
    /// A case-pattern `let-else` fallback must terminate control flow.
609 615
    LinearDiscard,
610 616
    /// Assignment would overwrite a live linear value.
611 617
    LinearOverwrite,
612 618
    /// `undefined` cannot initialize a linear type.
613 619
    LinearUndefined,
620 +
    /// A `Copy` declaration contains a non-copy field or variant.
621 +
    CopyContainsNonCopy,
622 +
    /// A declaration carries both `Copy` and `Linear`.
623 +
    ConflictingOwnershipMarkers,
614 624
    /// A reference appears in a storable or escaping position.
615 625
    InvalidRefPosition,
616 626
    /// A reference cannot be bound to a local.
617 627
    RefBinding,
618 628
    /// Call arguments contain overlapping incompatible loans.
2025 2035
        case Type::Nominal(_) => return false,
2026 2036
        else => return false,
2027 2037
    }
2028 2038
}
2029 2039
2030 -
/// Return whether a type is exact-linear.
2031 -
export fn isLinear(ty: Type) -> bool {
2040 +
/// Return whether `ty` may be duplicated implicitly.
2041 +
export fn isCopy(ty: Type) -> bool {
2032 2042
    match ty {
2033 -
        case Type::Pointer { class: types::PointerClass::Owned, .. },
2034 -
             Type::Slice { class: types::PointerClass::Owned, .. },
2035 -
             Type::TraitObject { class: types::PointerClass::Owned, .. } => return true,
2036 -
        case Type::Pointer { class: types::PointerClass::Ref, .. },
2037 -
             Type::Pointer { class: types::PointerClass::Unsafe, .. },
2038 -
             Type::Slice { class: types::PointerClass::Ref, .. },
2039 -
             Type::Slice { class: types::PointerClass::Unsafe, .. },
2040 -
             Type::TraitObject { class: types::PointerClass::Ref, .. },
2041 -
             Type::TraitObject { class: types::PointerClass::Unsafe, .. } => return false,
2043 +
        case Type::Array(array) => return isCopy(*array.item),
2044 +
        case Type::Optional(inner) => return isCopy(*inner),
2045 +
        // Records and unions are copyable unless linear. The `Copy` marker is
2046 +
        // recorded and validated but not yet required.
2047 +
        case Type::Nominal(NominalType::Record(_)) => return not isLinear(ty),
2048 +
        case Type::Nominal(NominalType::Union(_)) => return not isLinear(ty),
2049 +
        case Type::Nominal(NominalType::Placeholder(_)) => return false,
2050 +
        else => return true,
2051 +
    }
2052 +
}
2042 2053
2054 +
/// Return whether a type must be consumed exactly once.
2055 +
export fn isLinear(ty: Type) -> bool {
2056 +
    match ty {
2043 2057
        case Type::Array(array) => return isLinear(*array.item),
2044 2058
        case Type::Optional(inner) => return isLinear(*inner),
2045 2059
        case Type::Nominal(NominalType::Record(recInfo)) => {
2046 2060
            if recInfo.declaredLinear {
2047 2061
                return true;
2066 2080
        }
2067 2081
        else => return false,
2068 2082
    }
2069 2083
}
2070 2084
2085 +
/// Return whether a by-value use moves `ty`.
2086 +
fn isMoveOnly(ty: Type) -> bool {
2087 +
    return not isCopy(ty);
2088 +
}
2089 +
2071 2090
/// Return whether `ty` is a direct unsafe pointer-like value.
2072 2091
fn isUnsafePointerType(ty: Type) -> bool {
2073 2092
    match ty {
2074 2093
        case Type::Pointer { class: types::PointerClass::Unsafe, .. },
2075 2094
             Type::Slice { class: types::PointerClass::Unsafe, .. },
3406 3425
        if retTy <> Type::Void and bodyTy <> Type::Never {
3407 3426
            exitFn(self);
3408 3427
            if isUnsafe { set self.unsafeDepth -= 1; }
3409 3428
            throw emitError(self, body, ErrorKind::FnMissingReturn);
3410 3429
        }
3430 +
        try checkLinearFn(self, nil, decl.sig.params, body) catch e {
3431 +
            exitFn(self);
3432 +
            if isUnsafe { set self.unsafeDepth -= 1; }
3433 +
            throw e;
3434 +
        };
3411 3435
        exitFn(self);
3412 3436
        if isUnsafe {
3413 3437
            set self.unsafeDepth -= 1;
3414 3438
        }
3415 3439
    } else if not isExtern {
3425 3449
    let _ = try bindValueIdent(self, param.name, node, ty, false, 0, 0);
3426 3450
3427 3451
    return ty;
3428 3452
}
3429 3453
3430 -
/// Resolve the compiler-known `Linear` marker from a derive list.
3431 -
fn resolveLinearDerive(self: *mut Resolver, derives: *mut [*ast::Node]) -> bool
3454 +
/// Compiler-known ownership markers carried by a composite declaration.
3455 +
record OwnershipMarkers {
3456 +
    /// The declaration requires exact consumption.
3457 +
    linear: bool,
3458 +
    /// The declaration permits implicit copies.
3459 +
    copy: bool,
3460 +
}
3461 +
3462 +
/// Resolve compiler-known ownership markers from a derive list.
3463 +
fn resolveOwnershipMarkers(self: *mut Resolver, derives: *mut [*ast::Node]) -> OwnershipMarkers
3432 3464
    throws (ResolveError)
3433 3465
{
3434 -
    let mut linear = false;
3466 +
    let mut result = OwnershipMarkers { linear: false, copy: false };
3435 3467
    for derive in derives {
3436 3468
        let name = try nodeName(self, derive);
3437 3469
        if mem::eq(name, "Linear") {
3438 -
            if linear {
3470 +
            if result.linear {
3471 +
                throw emitError(self, derive, ErrorKind::DuplicateBinding(name));
3472 +
            }
3473 +
            if result.copy {
3474 +
                throw emitError(self, derive, ErrorKind::ConflictingOwnershipMarkers);
3475 +
            }
3476 +
            set result.linear = true;
3477 +
        } else if mem::eq(name, "Copy") {
3478 +
            if result.copy {
3439 3479
                throw emitError(self, derive, ErrorKind::DuplicateBinding(name));
3440 3480
            }
3441 -
            set linear = true;
3481 +
            if result.linear {
3482 +
                throw emitError(self, derive, ErrorKind::ConflictingOwnershipMarkers);
3483 +
            }
3484 +
            set result.copy = true;
3442 3485
        } else {
3443 3486
            // Resolve an ordinary trait derive.
3444 3487
            try infer(self, derive);
3445 3488
        }
3446 3489
    }
3447 -
    return linear;
3490 +
    return result;
3448 3491
}
3449 3492
3450 3493
/// Resolve record fields from a node list.
3451 3494
fn resolveRecordFields(self: *mut Resolver, node: *ast::Node, fields: *mut [*ast::Node], labeled: bool) -> RecordType
3452 3495
    throws (ResolveError)
3505 3548
    return RecordType {
3506 3549
        fields: &result[..],
3507 3550
        labeled,
3508 3551
        layout: recordLayout,
3509 3552
        declaredLinear: false,
3553 +
        declaredCopy: false,
3510 3554
    };
3511 3555
}
3512 3556
3513 3557
/// Resolve record field types for a named record declaration.
3514 3558
fn resolveRecordBody(self: *mut Resolver, node: *ast::Node, decl: ast::RecordDecl)
3523 3567
3524 3568
    // Skip if already resolved.
3525 3569
    if let case NominalType::Record(_) = *nominalTy {
3526 3570
        return;
3527 3571
    }
3528 -
    let declaredLinear = try resolveLinearDerive(self, decl.derives);
3572 +
    let markers = try resolveOwnershipMarkers(self, decl.derives);
3529 3573
    let mut recordType = try resolveRecordFields(self, node, decl.fields, decl.labeled);
3530 -
    set recordType.declaredLinear = declaredLinear;
3574 +
    if markers.copy {
3575 +
        for field in recordType.fields {
3576 +
            if not isCopy(field.fieldType) {
3577 +
                throw emitError(self, node, ErrorKind::CopyContainsNonCopy);
3578 +
            }
3579 +
        }
3580 +
    }
3581 +
    set recordType.declaredLinear = markers.linear;
3582 +
    set recordType.declaredCopy = markers.copy;
3531 3583
3532 3584
    set *nominalTy = NominalType::Record(recordType);
3533 3585
}
3534 3586
3535 3587
/// Bind a type name.
4011 4063
    if retTy <> Type::Void and bodyTy <> Type::Never {
4012 4064
        exitFn(self);
4013 4065
        if isUnsafe { set self.unsafeDepth -= 1; }
4014 4066
        throw emitError(self, body, ErrorKind::FnMissingReturn);
4015 4067
    }
4068 +
    try checkLinearFn(self, receiverName, sig.params, body) catch e {
4069 +
        exitFn(self);
4070 +
        if isUnsafe { set self.unsafeDepth -= 1; }
4071 +
        throw e;
4072 +
    };
4016 4073
    exitFn(self);
4017 4074
    if isUnsafe {
4018 4075
        set self.unsafeDepth -= 1;
4019 4076
    }
4020 4077
}
4203 4260
    let mut variants: *mut [UnionVariant] = &mut [];
4204 4261
4205 4262
    // Create a temporary nominal type to replace the placeholder.This prevents infinite recursion
4206 4263
    // when a variant references this union type (e.g. record payloads with `*[Self]`).
4207 4264
    // TODO: It would be best to have a resolving state eg. `Visiting` for this situation.
4208 -
    let declaredLinear = try resolveLinearDerive(self, decl.derives);
4265 +
    let markers = try resolveOwnershipMarkers(self, decl.derives);
4209 4266
    set *nominalTy = NominalType::Union(UnionType {
4210 4267
        variants: &[],
4211 4268
        layout: Layout { size: 0, alignment: 0 },
4212 4269
        valOffset: 0,
4213 4270
        isAllVoid: true,
4214 -
        declaredLinear,
4271 +
        declaredLinear: markers.linear,
4272 +
        declaredCopy: markers.copy,
4215 4273
    });
4216 4274
4217 4275
    assert decl.variants.len <= MAX_UNION_VARIANTS, "resolveUnionBody: maximum union variants exceeded";
4218 4276
    let mut iota: u32 = 0;
4219 4277
    for variantNode, i in decl.variants {
4237 4295
            name: variantName,
4238 4296
            valueType: variantType,
4239 4297
            symbol: variantSym,
4240 4298
        }, a);
4241 4299
    }
4300 +
    if markers.copy {
4301 +
        for variant in variants {
4302 +
            if not isCopy(variant.valueType) {
4303 +
                throw emitError(self, node, ErrorKind::CopyContainsNonCopy);
4304 +
            }
4305 +
        }
4306 +
    }
4242 4307
    let info = computeUnionLayout(&variants[..]);
4243 4308
4244 4309
    // Update the nominal type with the resolved variants.
4245 4310
    set *nominalTy = NominalType::Union(UnionType {
4246 4311
        variants: &variants[..],
4247 4312
        layout: info.layout,
4248 4313
        valOffset: info.valOffset,
4249 4314
        isAllVoid: info.isAllVoid,
4250 -
        declaredLinear,
4315 +
        declaredLinear: markers.linear,
4316 +
        declaredCopy: markers.copy,
4251 4317
    });
4252 4318
}
4253 4319
4254 4320
/// Check if a module should be analyzed based on its attributes and build configuration.
4255 4321
fn shouldAnalyzeModule(self: *Resolver, attrs: ?ast::Attributes) -> bool {
7131 7197
        case ast::TypeSig::Nominal(name) => {
7132 7198
            let ty = try resolveTypeName(self, name);
7133 7199
            return Type::Nominal(ty);
7134 7200
        }
7135 7201
        case ast::TypeSig::Record { fields, labeled } => {
7136 -
            let recordType = try resolveRecordFields(self, node, fields, labeled);
7202 +
            let mut recordType = try resolveRecordFields(self, node, fields, labeled);
7203 +
            set recordType.declaredCopy = true;
7204 +
            for field in recordType.fields {
7205 +
                if not isCopy(field.fieldType) {
7206 +
                    set recordType.declaredCopy = false;
7207 +
                }
7208 +
            }
7137 7209
            let nominalTy = allocNominalType(self, NominalType::Record(recordType));
7138 7210
            return Type::Nominal(nominalTy);
7139 7211
        }
7140 7212
        case ast::TypeSig::Fn(t) => {
7141 7213
            let a = alloc::arenaAllocator(&mut self.arena);
7380 7452
/// Return whether a tracked binding is still available.
7381 7453
fn linearBindingAvailable(env: *LinearEnv, index: u32) -> bool {
7382 7454
    return (env.available & ((1 as u64) << (index as u64))) <> 0;
7383 7455
}
7384 7456
7385 -
/// Add a local binding when its resolved type is linear.
7457 +
/// Add a local binding when its resolved type moves by value.
7386 7458
fn addLinearBinding(checker: *mut LinearChecker, env: *mut LinearEnv, node: *ast::Node)
7387 7459
    throws (ResolveError)
7388 7460
{
7389 7461
    let sym = symbolFor(checker.resolver, node) else return;
7390 7462
    let case SymbolData::Value { type: ty, .. } = sym.data else return;
7391 -
    if not isLinear(ty) {
7463 +
    if not isMoveOnly(ty) {
7392 7464
        return;
7393 7465
    }
7394 7466
    if env.len >= MAX_LINEAR_BINDINGS {
7395 7467
        throw emitError(checker.resolver, node, ErrorKind::Internal);
7396 7468
    }
7397 7469
    set env.symbols[env.len] = sym;
7398 7470
    set env.available |= (1 as u64) << (env.len as u64);
7399 7471
    set env.len += 1;
7400 7472
}
7401 7473
7402 -
/// Require all bindings introduced after `start` to have been consumed.
7474 +
/// Mark a tracked binding as uninitialized.
7475 +
fn markLinearBindingUnavailable(self: *mut Resolver, env: *mut LinearEnv, node: *ast::Node) {
7476 +
    let sym = symbolFor(self, node) else return;
7477 +
    let index = findLinearBinding(env, sym) else return;
7478 +
    set env.available &= ~((1 as u64) << (index as u64));
7479 +
}
7480 +
7481 +
/// Require exact-use bindings introduced after `start` to be consumed.
7403 7482
fn finishLinearScope(
7404 7483
    checker: *mut LinearChecker,
7405 7484
    env: *mut LinearEnv,
7406 7485
    start: u32,
7407 7486
) throws (ResolveError) {
7408 7487
    if not env.terminated {
7409 7488
        for i in start..env.len {
7410 7489
            if linearBindingAvailable(env, i) {
7411 7490
                let sym = env.symbols[i] else panic "finishLinearScope: missing symbol";
7412 -
                throw emitError(
7413 -
                    checker.resolver,
7414 -
                    sym.node,
7415 -
                    ErrorKind::LinearNotConsumed(sym.name),
7416 -
                );
7491 +
                let case SymbolData::Value { type: ty, .. } = sym.data
7492 +
                    else panic "finishLinearScope: expected value symbol";
7493 +
                if isLinear(ty) {
7494 +
                    throw emitError(
7495 +
                        checker.resolver,
7496 +
                        sym.node,
7497 +
                        ErrorKind::LinearNotConsumed(sym.name),
7498 +
                    );
7499 +
                }
7417 7500
            }
7418 7501
        }
7419 7502
    }
7420 7503
    set env.len = start;
7421 7504
}
7422 7505
7423 -
/// Consume a tracked identifier exactly once.
7506 +
/// Move or consume a tracked identifier once.
7424 7507
fn consumeLinearIdent(
7425 7508
    checker: *mut LinearChecker,
7426 7509
    env: *mut LinearEnv,
7427 7510
    node: *ast::Node,
7428 7511
) throws (ResolveError) {
7429 7512
    let sym = symbolFor(checker.resolver, node) else return;
7430 7513
    let index = findLinearBinding(env, sym) else return;
7431 7514
    if not linearBindingAvailable(env, index) {
7432 -
        throw emitError(
7433 -
            checker.resolver,
7434 -
            node,
7435 -
            ErrorKind::LinearUseAfterConsume(sym.name),
7436 -
        );
7515 +
        let case SymbolData::Value { type: ty, .. } = sym.data
7516 +
            else panic "consumeLinearIdent: expected value symbol";
7517 +
        let kind = ErrorKind::LinearUseAfterConsume(sym.name) if isLinear(ty)
7518 +
            else ErrorKind::AffineUseAfterMove(sym.name);
7519 +
        throw emitError(checker.resolver, node, kind);
7437 7520
    }
7438 7521
    set env.available &= ~((1 as u64) << (index as u64));
7439 7522
}
7440 7523
7441 -
/// Verify that two live branches agree on every outer binding.
7524 +
/// Merge ownership availability across two live branches.
7442 7525
fn joinLinearBranches(
7443 7526
    checker: *mut LinearChecker,
7444 7527
    env: *mut LinearEnv,
7445 7528
    left: LinearEnv,
7446 7529
    right: LinearEnv,
7458 7541
    if right.terminated {
7459 7542
        set *env = left;
7460 7543
        return;
7461 7544
    }
7462 7545
    assert left.len == right.len, "joinLinearBranches: scope mismatch";
7546 +
    let mut result = left;
7463 7547
    for i in 0..left.len {
7464 7548
        if linearBindingAvailable(&left, i) <> linearBindingAvailable(&right, i) {
7465 7549
            let sym = left.symbols[i] else panic "joinLinearBranches: missing symbol";
7466 -
            throw emitError(
7467 -
                checker.resolver,
7468 -
                node,
7469 -
                ErrorKind::LinearBranchMismatch(sym.name),
7470 -
            );
7550 +
            let case SymbolData::Value { type: ty, .. } = sym.data
7551 +
                else panic "joinLinearBranches: expected value symbol";
7552 +
            if isLinear(ty) {
7553 +
                throw emitError(
7554 +
                    checker.resolver,
7555 +
                    node,
7556 +
                    ErrorKind::LinearBranchMismatch(sym.name),
7557 +
                );
7558 +
            }
7559 +
            set result.available &= ~((1 as u64) << (i as u64));
7471 7560
        }
7472 7561
    }
7473 -
    set *env = left;
7562 +
    set *env = result;
7474 7563
}
7475 7564
7476 -
/// Require all current bindings to be consumed at a function exit.
7565 +
/// Require all available exact-use bindings to be consumed at a function exit.
7477 7566
fn finishLinearExit(
7478 7567
    checker: *mut LinearChecker,
7479 7568
    env: *mut LinearEnv,
7480 7569
) throws (ResolveError) {
7481 7570
    for i in 0..env.len {
7482 7571
        if linearBindingAvailable(env, i) {
7483 7572
            let sym = env.symbols[i] else panic "finishLinearExit: missing symbol";
7484 -
            throw emitError(
7485 -
                checker.resolver,
7486 -
                sym.node,
7487 -
                ErrorKind::LinearNotConsumed(sym.name),
7488 -
            );
7573 +
            let case SymbolData::Value { type: ty, .. } = sym.data
7574 +
                else panic "finishLinearExit: expected value symbol";
7575 +
            if isLinear(ty) {
7576 +
                throw emitError(
7577 +
                    checker.resolver,
7578 +
                    sym.node,
7579 +
                    ErrorKind::LinearNotConsumed(sym.name),
7580 +
                );
7581 +
            }
7489 7582
        }
7490 7583
    }
7491 7584
    set env.terminated = true;
7492 7585
}
7493 7586
7692 7785
            case ast::ProngArm::Binding(binding) => {
7693 7786
                try addLinearPatternBindings(checker, &mut branch, binding);
7694 7787
            }
7695 7788
            case ast::ProngArm::Else => {}
7696 7789
        }
7697 -
        if prong.guard <> nil and branch.len > bindingsStart {
7698 -
            throw emitError(checker.resolver, prongNode, ErrorKind::LinearDiscard);
7790 +
        if prong.guard <> nil {
7791 +
            for i in bindingsStart..branch.len {
7792 +
                let sym = branch.symbols[i] else panic "checkLinearMatch: missing symbol";
7793 +
                let case SymbolData::Value { type: ty, .. } = sym.data
7794 +
                    else panic "checkLinearMatch: expected value symbol";
7795 +
                if isLinear(ty) {
7796 +
                    throw emitError(checker.resolver, prongNode, ErrorKind::LinearDiscard);
7797 +
                }
7798 +
            }
7699 7799
        }
7700 7800
        if let guard = prong.guard {
7701 7801
            try checkLinearNode(checker, &mut branch, guard, LinearUse::Consume);
7702 7802
        }
7703 7803
        try checkLinearNode(checker, &mut branch, prong.body, LinearUse::Discard);
7720 7820
    env: *mut LinearEnv,
7721 7821
    node: *ast::Node,
7722 7822
    call: ast::Call,
7723 7823
) throws (ResolveError) {
7724 7824
    try checkLinearNode(checker, env, call.callee, LinearUse::Observe);
7725 -
    let calleeTy = typeFor(checker.resolver, call.callee) else {
7726 -
        throw emitError(checker.resolver, call.callee, ErrorKind::Internal);
7727 -
    };
7728 -
    let case Type::Fn(info) = calleeTy else {
7825 +
    let mut fnInfo: ?*FnType = nil;
7826 +
    match checker.resolver.nodeData.entries[node.id].extra {
7827 +
        case NodeExtra::TraitMethodCall { traitInfo, methodIndex } =>
7828 +
            set fnInfo = traitInfo.methods[methodIndex].fnType,
7829 +
        case NodeExtra::MethodCall { method } => set fnInfo = method.fnType,
7830 +
        else => {
7831 +
            if let calleeTy = typeFor(checker.resolver, call.callee) {
7832 +
                if let case Type::Fn(info) = calleeTy {
7833 +
                    set fnInfo = info;
7834 +
                }
7835 +
            }
7836 +
        }
7837 +
    }
7838 +
    let info = fnInfo else {
7729 7839
        for arg in call.args {
7730 7840
            try checkLinearNode(checker, env, arg, LinearUse::Consume);
7731 7841
        }
7732 7842
        return;
7733 7843
    };
7775 7885
    }
7776 7886
7777 7887
    for arg, i in call.args {
7778 7888
        let expected = *info.paramTypes[i];
7779 7889
        let root = linearRootSymbol(checker.resolver, arg);
7780 -
        let mut argExclusive = isLinear(expected);
7890 +
        let mut argExclusive = isMoveOnly(expected);
7781 7891
        if let case Type::Pointer { class: types::PointerClass::Ref, mutable, .. } = expected {
7782 7892
            set argExclusive = mutable;
7783 7893
        } else if let case Type::Slice { class: types::PointerClass::Ref, mutable, .. } = expected {
7784 7894
            set argExclusive = mutable;
7785 7895
        } else if let case Type::TraitObject {
7875 7985
            }
7876 7986
            try checkLinearNode(checker, env, expr, LinearUse::Consume);
7877 7987
        }
7878 7988
        case ast::NodeValue::Block(_) => try checkLinearBlock(checker, env, node),
7879 7989
        case ast::NodeValue::Let(binding) => {
7990 +
            let mut isUndefined = false;
7880 7991
            if let case ast::NodeValue::Undef = binding.value.value {
7992 +
                set isUndefined = true;
7993 +
            }
7994 +
            if isUndefined {
7881 7995
                if let bindingTy = typeFor(checker.resolver, binding.ident);
7882 7996
                    isLinear(bindingTy)
7883 7997
                {
7884 7998
                    throw emitError(
7885 7999
                        checker.resolver,
7888 8002
                    );
7889 8003
                }
7890 8004
            }
7891 8005
            try checkLinearNode(checker, env, binding.value, LinearUse::Consume);
7892 8006
            try addLinearBinding(checker, env, node);
8007 +
            if isUndefined {
8008 +
                markLinearBindingUnavailable(checker.resolver, env, node);
8009 +
            }
7893 8010
        }
7894 8011
        case ast::NodeValue::Assign(assign) => {
7895 8012
            let mut target: ?u32 = nil;
8013 +
            let mut targetLinear = false;
7896 8014
            if let leftTy = typeFor(checker.resolver, assign.left) {
7897 -
                if isLinear(leftTy) {
8015 +
                if isMoveOnly(leftTy) {
8016 +
                    set targetLinear = isLinear(leftTy);
7898 8017
                    if let case ast::NodeValue::Ident(_) = assign.left.value {
7899 8018
                        if let sym = symbolFor(checker.resolver, assign.left) {
7900 8019
                            set target = findLinearBinding(env, sym);
7901 8020
                        }
7902 8021
                    }
7910 8029
                }
7911 8030
            }
7912 8031
            try checkLinearNode(checker, env, assign.left, LinearUse::Place);
7913 8032
            try checkLinearNode(checker, env, assign.right, LinearUse::Consume);
7914 8033
            if let index = target {
7915 -
                if linearBindingAvailable(env, index) {
8034 +
                if targetLinear and linearBindingAvailable(env, index) {
7916 8035
                    throw emitError(
7917 8036
                        checker.resolver,
7918 8037
                        assign.left,
7919 8038
                        ErrorKind::LinearOverwrite,
7920 8039
                    );
7926 8045
        case ast::NodeValue::AddressOf(addr) => {
7927 8046
            try checkLinearNode(checker, env, addr.target, LinearUse::Borrow);
7928 8047
        }
7929 8048
        case ast::NodeValue::Deref(target) => {
7930 8049
            if let resultTy = typeFor(checker.resolver, node) {
7931 -
                if isLinear(resultTy) and usage == LinearUse::Consume {
8050 +
                if isMoveOnly(resultTy) and usage == LinearUse::Consume {
7932 8051
                    throw emitError(checker.resolver, node, ErrorKind::LinearPartialMove);
7933 8052
                }
7934 8053
            }
7935 8054
            try checkLinearNode(checker, env, target, LinearUse::Observe);
7936 8055
        }
7937 8056
        case ast::NodeValue::FieldAccess(access) => {
7938 8057
            if let resultTy = typeFor(checker.resolver, node) {
7939 -
                if isLinear(resultTy) and usage == LinearUse::Consume {
8058 +
                if isMoveOnly(resultTy) and usage == LinearUse::Consume {
7940 8059
                    throw emitError(checker.resolver, node, ErrorKind::LinearPartialMove);
7941 8060
                }
7942 8061
            }
7943 8062
            try checkLinearNode(checker, env, access.parent, LinearUse::Observe);
7944 8063
        }
7945 8064
        case ast::NodeValue::ScopeAccess(_) => {}
7946 8065
        case ast::NodeValue::Subscript { container, index } => {
7947 8066
            if let resultTy = typeFor(checker.resolver, node) {
7948 -
                if isLinear(resultTy) and usage == LinearUse::Consume {
8067 +
                if isMoveOnly(resultTy) and usage == LinearUse::Consume {
7949 8068
                    throw emitError(checker.resolver, node, ErrorKind::LinearPartialMove);
7950 8069
                }
7951 8070
            }
7952 8071
            try checkLinearNode(checker, env, container, LinearUse::Observe);
7953 8072
            try checkLinearNode(checker, env, index, LinearUse::Consume);
7964 8083
                try checkLinearNode(checker, env, item, LinearUse::Consume);
7965 8084
            }
7966 8085
        }
7967 8086
        case ast::NodeValue::ArrayRepeatLit(repeat) => {
7968 8087
            if let itemTy = typeFor(checker.resolver, repeat.item) {
7969 -
                if isLinear(itemTy) {
8088 +
                if not isCopy(itemTy) {
7970 8089
                    throw emitError(
7971 8090
                        checker.resolver,
7972 8091
                        repeat.item,
7973 8092
                        ErrorKind::LinearDiscard,
7974 8093
                    );
lib/std/lang/resolver/printer.rad +9 -0
494 494
        case super::ErrorKind::TraitMethodOverflow(m) =>
495 495
            printMismatch("too many trait methods", "maximum", m),
496 496
        case super::ErrorKind::MissingSupertraitInstance(name) => {
497 497
            printQuoted("missing instance for supertrait '", name);
498 498
        }
499 +
        case super::ErrorKind::AffineUseAfterMove(name) => {
500 +
            printQuoted("affine value used after move: '", name);
501 +
        }
499 502
        case super::ErrorKind::LinearUseAfterConsume(name) => {
500 503
            printQuoted("linear value used after consumption: '", name);
501 504
        }
502 505
        case super::ErrorKind::LinearNotConsumed(name) => {
503 506
            printQuoted("linear value is not consumed: '", name);
518 521
            io::print("assignment would overwrite a linear value");
519 522
        }
520 523
        case super::ErrorKind::LinearUndefined => {
521 524
            io::print("linear values cannot be undefined");
522 525
        }
526 +
        case super::ErrorKind::CopyContainsNonCopy => {
527 +
            io::print("`Copy` composite contains a non-copy value");
528 +
        }
529 +
        case super::ErrorKind::ConflictingOwnershipMarkers => {
530 +
            io::print("a composite cannot be both `Copy` and `Linear`");
531 +
        }
523 532
        case super::ErrorKind::InvalidRefPosition => {
524 533
            io::print("reference type is only allowed as a function parameter");
525 534
        }
526 535
        case super::ErrorKind::RefBinding => {
527 536
            io::print("references cannot be bound to locals");
lib/std/lang/resolver/tests.rad +41 -1
51 51
    "Second", "Opt", "x",
52 52
    "value", "idx"
53 53
];
54 54
55 55
/// Resolver result with AST, used by test helpers.
56 -
record TestResult {
56 +
record TestResult: Copy {
57 57
    diagnostics: super::Diagnostics,
58 58
    root: *ast::Node,
59 59
}
60 60
61 61
/// Create isolated storage for tests to avoid conflicts with global resolver storage.
279 279
        if let case super::ErrorKind::MissingSupertraitInstance(actualName) = *actual {
280 280
            return mem::eq(actualName, expectedName);
281 281
        }
282 282
        return false;
283 283
    }
284 +
    if let case super::ErrorKind::AffineUseAfterMove(expectedName) = expected {
285 +
        if let case super::ErrorKind::AffineUseAfterMove(actualName) = *actual {
286 +
            return mem::eq(actualName, expectedName);
287 +
        }
288 +
        return false;
289 +
    }
284 290
    if let case super::ErrorKind::LinearUseAfterConsume(expectedName) = expected {
285 291
        if let case super::ErrorKind::LinearUseAfterConsume(actualName) = *actual {
286 292
            return mem::eq(actualName, expectedName);
287 293
        }
288 294
        return false;
5238 5244
    let program = "record Value { number: i32 } trait Read { fn (&Read) get() -> i32; } instance Read for Value { fn (value: *Value) get() -> i32 { return value.number; } }";
5239 5245
    let result = try resolveProgramStr(&mut a, program);
5240 5246
    try expectErrorKind(&result, super::ErrorKind::TraitReceiverMismatch);
5241 5247
}
5242 5248
5249 +
/// Unmarked composite values may be discarded.
5250 +
@test fn testAffineCompositeMayBeDiscarded() throws (testing::TestError) {
5251 +
    let program = "record Value { number: u32 } fn run() { let value = Value { number: 1 }; }";
5252 +
    try expectAnalyzeOk(program);
5253 +
}
5254 +
5255 +
/// Affine values may move on only one branch when not used later.
5256 +
@test fn testAffineConditionalMoveMayBeDiscarded() throws (testing::TestError) {
5257 +
    let program = "record Value { number: u32 } fn take(value: Value) {} fn run(condition: bool) { let value = Value { number: 1 }; if condition { take(value); } }";
5258 +
    try expectAnalyzeOk(program);
5259 +
}
5260 +
5261 +
/// A `Copy` composite remains available after a by-value use.
5262 +
@test fn testCopyCompositeMayBeReused() throws (testing::TestError) {
5263 +
    let program = "record Value: Copy { number: u32 } fn take(value: Value) {} fn run() { let value = Value { number: 1 }; take(value); take(value); }";
5264 +
    try expectAnalyzeOk(program);
5265 +
}
5266 +
5267 +
/// A composite cannot carry conflicting ownership markers.
5268 +
@test fn testConflictingOwnershipMarkersRejected() throws (testing::TestError) {
5269 +
    let mut a = testResolver();
5270 +
    let program = "record Value: Copy + Linear { number: u32 }";
5271 +
    let result = try resolveProgramStr(&mut a, program);
5272 +
    try expectErrorKind(&result, super::ErrorKind::ConflictingOwnershipMarkers);
5273 +
}
5274 +
5275 +
/// Linear composites still require one consuming use.
5276 +
@test fn testLinearCompositeMustBeConsumed() throws (testing::TestError) {
5277 +
    let mut a = testResolver();
5278 +
    let program = "record Token: Linear { number: u32 } fn run() { let token = Token { number: 1 }; }";
5279 +
    let result = try resolveProgramStr(&mut a, program);
5280 +
    try expectErrorKind(&result, super::ErrorKind::LinearNotConsumed("token"));
5281 +
}
5282 +
5243 5283
/// The compiler-known marker cannot be derived more than once.
5244 5284
@test fn testDuplicateLinearMarkerRejected() throws (testing::TestError) {
5245 5285
    let mut a = testResolver();
5246 5286
    let program = "record Token: Linear + Linear { value: u32 }";
5247 5287
    let result = try resolveProgramStr(&mut a, program);
lib/std/testing.rad +3 -3
2 2
3 3
use std::mem;
4 4
use std::io;
5 5
6 6
/// Internal state for tracking test pass/fail counts.
7 -
record Ctx {
7 +
record Ctx: Copy {
8 8
    passed: u32,
9 9
    failed: u32,
10 10
}
11 11
12 12
/// Error thrown when a test assertion fails.
13 -
export union TestError {
13 +
export union TestError: Copy {
14 14
    Failed,
15 15
}
16 16
17 17
/// Descriptor for a single test case, holding its module path, name, and entry point.
18 -
export record TestInfo {
18 +
export record TestInfo: Copy {
19 19
    module: *[u8],
20 20
    name: *[u8],
21 21
    func: fn() throws (TestError),
22 22
}
23 23
lib/std/tests.rad +1 -1
6 6
use std::testing;
7 7
use std::sys::unix;
8 8
9 9
// Data types //////////////////////////////////////////////////////////////////
10 10
11 -
record Point {
11 +
record Point: Copy {
12 12
    x: i32,
13 13
    y: i32,
14 14
}
15 15
16 16
// fmt /////////////////////////////////////////////////////////////////////////
test/tests/abi.sizes.rad +5 -5
1 1
//! returns: 0
2 2
//! Test size-based ABI: small aggregates (<= 8 bytes) are passed/returned
3 3
//! by value in registers, while larger aggregates use hidden pointers.
4 4
5 -
record Byte {
5 +
record Byte: Copy {
6 6
    x: u8,
7 7
}
8 8
9 -
record Short {
9 +
record Short: Copy {
10 10
    x: u16,
11 11
}
12 12
13 -
record Word {
13 +
record Word: Copy {
14 14
    x: u32,
15 15
}
16 16
17 -
record Pair {
17 +
record Pair: Copy {
18 18
    a: u32,
19 19
    b: u32,
20 20
}
21 21
22 -
record Triple {
22 +
record Triple: Copy {
23 23
    x: u32,
24 24
    y: u32,
25 25
    z: u32,
26 26
}
27 27
test/tests/aggregate.return.rad +2 -2
1 1
//! returns: 0
2 2
//! Test that returning aggregate types via hidden return buffer does not
3 3
//! corrupt the caller's stack. Modifying a returned aggregate must not affect
4 4
//! other locals or previously returned values.
5 5
6 -
record Pair {
6 +
record Pair: Copy {
7 7
    a: u32,
8 8
    b: u32,
9 9
}
10 10
11 -
record Triple {
11 +
record Triple: Copy {
12 12
    x: u32,
13 13
    y: u32,
14 14
    z: u32,
15 15
}
16 16
test/tests/array.aggregate.stride.rad +1 -1
1 1
/// Tests for correct stride calculation with aggregate array elements.
2 2
/// This is important because aggregate types (records, arrays) are larger
3 3
/// than a single word and require correct stride (not just 4 bytes).
4 4
5 -
record Point { x: i32, y: i32 }
5 +
record Point: Copy { x: i32, y: i32 }
6 6
7 7
/// Array of records (8 bytes per element).
8 8
fn arrayOfRecords(arr: [Point; 3], idx: u32) -> i32 {
9 9
    return arr[idx].x;
10 10
}
test/tests/array.record.elements.rad +1 -1
1 1
//! returns: 50
2 2
//! Test arrays with record elements.
3 3
4 -
record Point {
4 +
record Point: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 9
fn calculateDistance(p1: Point, p2: Point) -> i32 {
test/tests/assign.mutable.rad +2 -2
1 1
//! returns: 0
2 2
//! Test suite for stack memory allocation and aliasing behavior.
3 3
//! Tests variable aliasing, mutations, and stack frame management.
4 4
5 -
record Person {
5 +
record Person: Copy {
6 6
    age: i32,
7 7
    score: i32,
8 8
}
9 9
10 -
record Container {
10 +
record Container: Copy {
11 11
    values: [i32; 3],
12 12
    count: i32,
13 13
}
14 14
15 15
/// Basic variable aliasing and mutation.
test/tests/bool.comparison.nested.gen.rad +2 -2
1 1
//! returns: 0
2 2
//! Test nested record equality.
3 3
4 -
record Point {
4 +
record Point: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 -
record Circle {
9 +
record Circle: Copy {
10 10
    center: Point,
11 11
    radius: u32,
12 12
}
13 13
14 14
fn testNestedEqual() -> bool {
test/tests/bool.comparison.record.gen.rad +2 -2
1 1
//! returns: 0
2 2
3 -
record Point {
3 +
record Point: Copy {
4 4
    x: i32,
5 5
    y: i32,
6 6
}
7 7
8 -
record Rect {
8 +
record Rect: Copy {
9 9
    width: u32,
10 10
    height: u32,
11 11
}
12 12
13 13
fn testPointEqual() -> bool {
test/tests/bool.comparison.record.rad +2 -2
1 1
//! returns: 1
2 2
3 3
// A packed record. 8 bytes.
4 -
record Packed {
4 +
record Packed: Copy {
5 5
    x: i32,
6 6
    y: i32
7 7
}
8 8
9 9
// A record with padding. 17 bytes.
10 -
record Padded {
10 +
record Padded: Copy {
11 11
    a: u8,
12 12
    b: u32,
13 13
    c: u16,
14 14
    d: u32,
15 15
    e: u8,
test/tests/bool.comparison.slice.record.gen.rad +2 -2
1 1
//! returns: 0
2 2
3 -
record Point {
3 +
record Point: Copy {
4 4
    x: i32,
5 5
    y: i32,
6 6
}
7 7
8 -
record Line {
8 +
record Line: Copy {
9 9
    points: *[Point],
10 10
}
11 11
12 12
fn pointsEqual(a: *[Point], b: *[Point]) -> bool {
13 13
    if a.len <> b.len {
test/tests/bool.comparison.slice.union.gen.rad +3 -3
1 1
//! returns: 0
2 2
3 -
record Point {
3 +
record Point: Copy {
4 4
    x: i32,
5 5
    y: i32,
6 6
}
7 7
8 -
record Size {
8 +
record Size: Copy {
9 9
    width: u32,
10 10
    height: u32,
11 11
}
12 12
13 -
union Shape {
13 +
union Shape: Copy {
14 14
    points(*[Point]),
15 15
    sizes(*[Size]),
16 16
}
17 17
18 18
fn pointsEqual(a: *[Point], b: *[Point]) -> bool {
test/tests/bool.comparison.union.ctor.rad +1 -1
1 1
//! returns: 0
2 2
//! Test comparing a void union variable against a constructor literal.
3 3
4 -
union Op {
4 +
union Op: Copy {
5 5
    Add,
6 6
    Sub,
7 7
    Mul,
8 8
}
9 9
test/tests/bool.comparison.union.gen.rad +1 -1
1 1
//! returns: 0
2 2
3 -
union Status {
3 +
union Status: Copy {
4 4
    pending,
5 5
    running(u32),
6 6
    completed(bool),
7 7
}
8 8
test/tests/bool.comparison.union.record.gen.rad +3 -3
1 1
//! returns: 0
2 2
3 -
record Point {
3 +
record Point: Copy {
4 4
    x: i32,
5 5
    y: i32,
6 6
}
7 7
8 -
record Size {
8 +
record Size: Copy {
9 9
    width: u32,
10 10
    height: u32,
11 11
}
12 12
13 -
union Shape {
13 +
union Shape: Copy {
14 14
    circle(u32),
15 15
    point(Point),
16 16
    rect(Size),
17 17
}
18 18
test/tests/bool.comparison.union.simple.gen.rad +1 -1
1 1
//! returns: 0
2 2
//! Test equality on simple enum without payloads.
3 -
union Color {
3 +
union Color: Copy {
4 4
    red,
5 5
    green,
6 6
    blue,
7 7
}
8 8
test/tests/builtin.alignof.rad +1 -1
1 1
/// A simple record with mixed field sizes for alignment testing.
2 -
record Mixed {
2 +
record Mixed: Copy {
3 3
    a: u8,
4 4
    b: u32,
5 5
}
6 6
7 7
/// Returns the alignment of a u8.
test/tests/builtin.size.align.rad +1 -1
1 1
//! returns: 0
2 -
record Foo {
2 +
record Foo: Copy {
3 3
    x: u8,
4 4
    y: u32,
5 5
}
6 6
7 7
@default fn main() -> u8 {
test/tests/builtin.sizeof.rad +1 -1
1 1
/// A simple record with mixed field sizes for alignment testing.
2 -
record Mixed {
2 +
record Mixed: Copy {
3 3
    a: u8,
4 4
    b: u32,
5 5
}
6 6
7 7
/// Returns the size of a u8.
test/tests/call.aggregate.arg.snapshot.rad +1 -1
1 1
//! returns: 0
2 2
//! Aggregate call arguments must capture their value when evaluated, before
3 3
//! later arguments run and mutate the source object.
4 4
5 -
record Pair {
5 +
record Pair: Copy {
6 6
    x: i32,
7 7
    y: i32,
8 8
}
9 9
10 10
fn mutate(pair: *mut Pair) -> i32 {
test/tests/compound.assign.field.rad +1 -1
1 1
//! returns: 0
2 2
/// Test compound assignment on record fields.
3 -
record Point {
3 +
record Point: Copy {
4 4
    x: i32,
5 5
    y: i32,
6 6
}
7 7
8 8
@default fn main() -> i32 {
test/tests/cond.expr.aggregate.rad +1 -1
1 1
//! returns: 0
2 2
//! Test conditional expression with aggregate types (tagged unions, optionals).
3 3
4 -
union Val {
4 +
union Val: Copy {
5 5
    Reg(u32),
6 6
    Imm(i64),
7 7
}
8 8
9 9
fn pickVal(flag: bool, reg: u32) -> Val {
test/tests/cond.expr.rad +1 -1
7 7
8 8
fn pick(cond: bool, a: i32, b: i32) -> i32 {
9 9
    return a if cond else b;
10 10
}
11 11
12 -
union Color { Red, Green, Blue }
12 +
union Color: Copy { Red, Green, Blue }
13 13
14 14
fn colorPick(isRed: bool) -> Color {
15 15
    return Color::Red if isRed else Color::Blue;
16 16
}
17 17
test/tests/cond.if.case.rad +1 -1
1 1
//! returns: 1
2 2
//! Test if-let-case with union variants.
3 3
4 -
union Response {
4 +
union Response: Copy {
5 5
    success(i32),
6 6
    failure,
7 7
    offline,
8 8
}
9 9
test/tests/cond.match.guard.rad +1 -1
1 1
//! returns: 0
2 2
3 -
union OptionNum {
3 +
union OptionNum: Copy {
4 4
    Some(i32),
5 5
    Other(i32),
6 6
    None,
7 7
}
8 8
test/tests/cond.match.guard.regalloc.rad +2 -2
5 5
//! `case Kind::Name(name) if name.len > 0` creates a block ordering where
6 6
//! the case body has a lower index than its predecessor (the guard block).
7 7
//! Without RPO-based register allocation, the name payload pointer can be
8 8
//! overwritten by the bounds check in the case body.
9 9
10 -
union Kind {
10 +
union Kind: Copy {
11 11
    Num(i32),
12 12
    Name(*[u8]),
13 13
    Pair { a: i32, b: i32 },
14 14
}
15 15
16 -
record Node {
16 +
record Node: Copy {
17 17
    id: u32,
18 18
    span1: u32,
19 19
    span2: u32,
20 20
    kind: Kind,
21 21
}
test/tests/const.array.record.ident.rad +1 -1
1 1
/// Test constant array containing references to other record constants.
2 2
/// This tests that identifiers referencing record constants work in constant arrays.
3 3
4 -
record Point {
4 +
record Point: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 9
constant P1: Point = Point { x: 1, y: 2 };
test/tests/const.array.repeat.record.rad +1 -1
1 1
/// Test constant array repeat with record elements.
2 -
record Point { x: i32, y: i32 }
2 +
record Point: Copy { x: i32, y: i32 }
3 3
4 4
constant POINTS: [Point; 3] = [Point { x: 1, y: 2 }; 3];
5 5
6 6
fn getSum() -> i32 {
7 7
    return POINTS[0].x + POINTS[1].y + POINTS[2].x;
test/tests/const.record.array.rad +1 -1
1 1
//! returns: 129
2 2
//! Test array of record constants.
3 3
4 -
record Point {
4 +
record Point: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 9
// A constant array of structs
test/tests/const.record.array.simple.rad +1 -1
1 1
//! returns: 0
2 2
// Test array of record constants.
3 3
4 -
record Point {
4 +
record Point: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 9
// Define an array of record constants
test/tests/const.record.ctor.rad +1 -1
1 1
//! returns: 0
2 2
//! Constant unlabeled record constructor.
3 -
record Pair(i32, i32);
3 +
record Pair: Copy(i32, i32);
4 4
5 5
constant P: Pair = Pair(40, 2);
6 6
7 7
@default fn main() -> i32 {
8 8
    assert P == Pair(40, 2);
test/tests/const.record.fn.rad +1 -1
1 1
//! returns: 7
2 2
//! Test record constants passed to functions.
3 3
4 -
record Point {
4 +
record Point: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 9
constant ORIGIN: Point = Point { x: 3, y: 4 };
test/tests/const.record.mutcopy.rad +1 -1
1 1
/// Test that accessing an aggregate constant produces a mutable copy
2 2
/// (via Reserve + Blit) so that code can safely assign through the pointer.
3 3
4 -
record Reg { n: u8 }
4 +
record Reg: Copy { n: u8 }
5 5
6 6
constant SCRATCH1: Reg = { n: 30 };
7 7
constant SCRATCH2: Reg = { n: 31 };
8 8
9 9
/// Returns a scratch register, avoiding the one already used by `rs`.
test/tests/const.record.nested.rad +2 -2
1 1
/// Test constant nested record lowering with padding.
2 -
record Inner {
2 +
record Inner: Copy {
3 3
    a: u8,
4 4
    b: i32,
5 5
}
6 6
7 -
record Outer {
7 +
record Outer: Copy {
8 8
    x: u8,
9 9
    inner: Inner,
10 10
    y: u8,
11 11
}
12 12
test/tests/const.record.packed.rad +1 -1
1 1
/// Test constant record with multiple sub-word fields.
2 -
record Packed {
2 +
record Packed: Copy {
3 3
    a: u8,
4 4
    b: u8,
5 5
    c: u8,
6 6
}
7 7
test/tests/const.record.padded.rad +1 -1
1 1
/// Test constant record with padding between fields.
2 -
record Padded {
2 +
record Padded: Copy {
3 3
    a: u8,
4 4
    b: i32,
5 5
    c: u8,
6 6
}
7 7
test/tests/const.record.rad +1 -1
1 1
//! returns: 0
2 2
// Test record constants.
3 3
4 -
record Point {
4 +
record Point: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 9
constant ORIGIN: Point = Point { x: 3, y: 4 };
test/tests/const.record.union.rad +2 -2
1 1
/// Test constant array of records containing union variant fields.
2 2
/// This is similar to scanner.rad's KEYWORDS constant.
3 -
union TokenKind {
3 +
union TokenKind: Copy {
4 4
    Fn,
5 5
    Let,
6 6
    If,
7 7
}
8 8
9 -
record Keyword {
9 +
record Keyword: Copy {
10 10
    name: *[u8],
11 11
    tok: TokenKind,
12 12
}
13 13
14 14
constant KEYWORDS: [Keyword; 3] = [
test/tests/const.union.payload.ctor.rad +1 -1
1 1
//! returns: 0
2 2
//! Constant union payload constructor call.
3 -
union Value {
3 +
union Value: Copy {
4 4
    Int(i32),
5 5
    Bool(bool),
6 6
    None,
7 7
}
8 8
test/tests/const.union.payload.fn.array.rad +3 -3
1 1
//! returns: 0
2 2
//! Constant array of records containing union variants with throwing function payloads.
3 3
4 -
union TestError {
4 +
union TestError: Copy {
5 5
    Fail,
6 6
}
7 7
8 8
fn add(a: i32, b: i32) -> i32 throws (TestError) {
9 9
    return a + b;
11 11
12 12
fn sub(a: i32, b: i32) -> i32 throws (TestError) {
13 13
    return a - b;
14 14
}
15 15
16 -
union Handler {
16 +
union Handler: Copy {
17 17
    Binary { op: fn(i32, i32) -> i32 throws (TestError) },
18 18
    None,
19 19
}
20 20
21 -
record Entry {
21 +
record Entry: Copy {
22 22
    handler: Handler,
23 23
}
24 24
25 25
constant ENTRIES: [Entry; 3] = [
26 26
    Entry { handler: Handler::None },
test/tests/const.union.payload.record.array.rad +2 -2
1 1
//! returns: 0
2 2
//! Constant array of records containing union variants with record payloads.
3 3
4 -
union InstrSpec {
4 +
union InstrSpec: Copy {
5 5
    Empty,
6 6
    Small { flag: bool },
7 7
    Imm { opcode: u32, funct3: u32, imm: i32 },
8 8
    Reg { opcode: u32, funct3: u32, funct7: u32 },
9 9
}
10 10
11 -
record Entry {
11 +
record Entry: Copy {
12 12
    name: *[u8],
13 13
    spec: InstrSpec,
14 14
}
15 15
16 16
constant ENTRIES: [Entry; 4] = [
test/tests/const.union.record.literal.rad +1 -1
1 1
//! returns: 0
2 2
//! Constant union record payload literal.
3 -
union Expr {
3 +
union Expr: Copy {
4 4
    Nil,
5 5
    Pair { first: i32, second: i32 },
6 6
}
7 7
8 8
constant E: Expr = Expr::Pair { first: 20, second: 22 };
test/tests/data.record.rad +2 -2
1 1
//! returns: 0
2 2
//! Test read-only data access for `record` types.
3 -
record Point {
3 +
record Point: Copy {
4 4
    x: i32,
5 5
    y: i32,
6 6
}
7 7
8 -
record Mixed {
8 +
record Mixed: Copy {
9 9
    a: u8,
10 10
    b: u16,
11 11
    c: u32,
12 12
    d: bool,
13 13
}
test/tests/data.union.rad +2 -2
1 1
//! returns: 0
2 2
//! Test read-only data access for `union` types.
3 -
union Color {
3 +
union Color: Copy {
4 4
    Red,
5 5
    Green,
6 6
    Blue,
7 7
}
8 8
9 -
union Value {
9 +
union Value: Copy {
10 10
    None,
11 11
    Small,
12 12
    Large,
13 13
}
14 14
test/tests/debug.tag.rad +1 -1
1 1
//! returns: 0
2 2
3 -
union Huge {
3 +
union Huge: Copy {
4 4
    Small(u32),
5 5
    Large {
6 6
        payload: [u32; 32],
7 7
        flag: u32,
8 8
    },
test/tests/edge.cases.2.rad +1 -1
1 1
//! returns: 0
2 2
//! Test scanner peek with optional return.
3 3
4 -
export record Scanner {
4 +
export record Scanner: Copy {
5 5
    source: *[u8],
6 6
}
7 7
8 8
fn peek(s: *Scanner) -> ?u8 {
9 9
    if 0 + 0 >= s.source.len {
test/tests/edge.cases.3.rad +1 -1
1 1
//! returns: 97
2 2
//! Test scanner current character access.
3 3
4 -
export record Scanner {
4 +
export record Scanner: Copy {
5 5
    source: *[u8],
6 6
    cursor: u32,
7 7
}
8 8
9 9
fn isEof(s: *Scanner) -> bool {
test/tests/edge.cases.4.rad +4 -4
1 1
//! returns: 0
2 2
3 -
union Signedness {
3 +
union Signedness: Copy {
4 4
    Signed,
5 5
    Unsigned,
6 6
}
7 7
8 -
union TypeSig {
8 +
union TypeSig: Copy {
9 9
    Integer {
10 10
        width: u8,
11 11
        sign: Signedness,
12 12
    },
13 13
}
14 14
15 -
union NodeValue {
15 +
union NodeValue: Copy {
16 16
    TypeSig(TypeSig),
17 17
}
18 18
19 -
record Node {
19 +
record Node: Copy {
20 20
    value: NodeValue,
21 21
}
22 22
23 23
fn node(nodes: *mut Node, count: *mut u32, value: NodeValue) -> *Node {
24 24
    let index = *count;
test/tests/edge.cases.5.rad +9 -9
1 1
//! returns: 0
2 2
3 -
union TestError {
3 +
union TestError: Copy {
4 4
    Fail,
5 5
}
6 6
7 -
record Derives {
7 +
record Derives: Copy {
8 8
    len: i32,
9 9
    list: [[u8; 8]; 2],
10 10
}
11 11
12 -
record StructField {
12 +
record StructField: Copy {
13 13
    typeSize: i32,
14 14
    isSigned: bool,
15 15
    value: ?i32,
16 16
}
17 17
18 -
record FieldNode {
18 +
record FieldNode: Copy {
19 19
    value: FieldValue,
20 20
}
21 21
22 -
record FieldList {
22 +
record FieldList: Copy {
23 23
    len: i32,
24 24
    list: [FieldNode; 2],
25 25
}
26 26
27 -
record StructDecl {
27 +
record StructDecl: Copy {
28 28
    derives: Derives,
29 29
    fields: FieldList,
30 30
}
31 31
32 -
record Node {
32 +
record Node: Copy {
33 33
    value: NodeValue,
34 34
}
35 35
36 -
union FieldValue {
36 +
union FieldValue: Copy {
37 37
    StructField(StructField),
38 38
    Other(i32),
39 39
}
40 40
41 -
union NodeValue {
41 +
union NodeValue: Copy {
42 42
    StructDecl(StructDecl),
43 43
    Other(i32),
44 44
}
45 45
46 46
fn expectIntType(a: i32, b: i32, c: bool, d: bool) throws (TestError) {}
test/tests/edge.cases.6.rad +2 -2
1 1
//! returns: 0
2 2
//! Standalone repro: writing a record into a static slice clobbers the slice header.
3 3
4 -
record Entry {
4 +
record Entry: Copy {
5 5
    a: u32,
6 6
    b: u32,
7 7
    c: u32,
8 8
    d: u32,
9 9
    e: u32,
22 22
    r: u32,
23 23
    s: u32,
24 24
    t: u32,
25 25
}
26 26
27 -
record Analyzer {
27 +
record Analyzer: Copy {
28 28
    pad0: u32,
29 29
    pad1: u32,
30 30
    entries: *mut [Entry],
31 31
    len: u32,
32 32
}
test/tests/edge.cases.7.addr.bug.rad +1 -1
1 1
//! returns: 42
2 2
3 -
record PtrHolder {
3 +
record PtrHolder: Copy {
4 4
    ptr: *mut i32,
5 5
}
6 6
7 7
static target: i32 = 10;
8 8
static holder: PtrHolder = undefined;
test/tests/edge.cases.8.bug.rad +2 -2
1 1
//! returns: 0
2 2
//! When a nested record field from a static variable is passed by value,
3 3
//! we only the base address and ignores the offset,
4 4
//! causing the function to receive the wrong data.
5 5
6 -
record Inner {
6 +
record Inner: Copy {
7 7
    value: i32,
8 8
}
9 9
10 -
record Outer {
10 +
record Outer: Copy {
11 11
    padding: i32,
12 12
    inner: Inner,
13 13
}
14 14
15 15
static global: Outer = undefined;
test/tests/edge.cases.rad +1 -1
1 1
//! returns: 0
2 2
3 -
export record Scanner {
3 +
export record Scanner: Copy {
4 4
    source: *[u8],
5 5
}
6 6
7 7
fn peek(s: *Scanner)  -> i32 {
8 8
    assert 0 + 0 <= s.source.len;
test/tests/error.basic.rad +1 -1
1 1
//! returns: 0
2 2
3 -
union MyError { A, B, C }
3 +
union MyError: Copy { A, B, C }
4 4
5 5
@default fn main() -> u32 {
6 6
    let err: MyError = MyError::B;
7 7
8 8
    if err == MyError::B {
test/tests/error.catch.rad +1 -1
1 1
//! returns: 0
2 2
3 -
union TestError { Fail }
3 +
union TestError: Copy { Fail }
4 4
static PTR_VALUE: i32 = 7;
5 5
6 6
@default fn main() -> u32 {
7 7
    // Catch block with early return
8 8
    let val1: u32 = catchWithReturn(true);
test/tests/error.catch.return.rad +1 -1
1 1
/// Error type for fallible functions.
2 -
union Error { Boom }
2 +
union Error: Copy { Boom }
3 3
4 4
/// Return a value or throw an error based on the flag.
5 5
fn fallible(flag: bool) -> i32 throws (Error) {
6 6
    if flag {
7 7
        throw Error::Boom();
test/tests/error.multi.basic.rad +2 -2
1 1
//! returns: 0
2 2
//! Test basic multi-error throw and catch.
3 3
4 -
union ErrA { A }
5 -
union ErrB { B }
4 +
union ErrA: Copy { A }
5 +
union ErrB: Copy { B }
6 6
7 7
fn failA() -> i32 throws (ErrA, ErrB) {
8 8
    throw ErrA::A();
9 9
}
10 10
test/tests/error.multi.catch.rad +2 -2
1 1
//! returns: 0
2 2
//! Test catch {} (no binding) with multi-error callee.
3 3
4 -
union ErrA { A }
5 -
union ErrB { B }
4 +
union ErrA: Copy { A }
5 +
union ErrB: Copy { B }
6 6
7 7
fn failA() -> i32 throws (ErrA, ErrB) {
8 8
    throw ErrA::A();
9 9
}
10 10
test/tests/error.multi.catch.typed.binding.rad +2 -2
1 1
//! returns: 0
2 2
//! Test typed multi-catch with payload extraction via bindings.
3 3
4 -
union ErrA { A(i32) }
5 -
union ErrB { B(i32) }
4 +
union ErrA: Copy { A(i32) }
5 +
union ErrB: Copy { B(i32) }
6 6
7 7
fn failA(v: i32) -> i32 throws (ErrA, ErrB) {
8 8
    throw ErrA::A(v);
9 9
}
10 10
test/tests/error.multi.catch.typed.catchall.rad +3 -3
1 1
//! returns: 0
2 2
//! Test typed catch with a catch-all fallback.
3 3
4 -
union ErrA { A(i32) }
5 -
union ErrB { B(i32) }
6 -
union ErrC { C }
4 +
union ErrA: Copy { A(i32) }
5 +
union ErrB: Copy { B(i32) }
6 +
union ErrC: Copy { C }
7 7
8 8
fn failA() -> i32 throws (ErrA, ErrB, ErrC) {
9 9
    throw ErrA::A(10);
10 10
}
11 11
test/tests/error.multi.catch.typed.rad +2 -2
1 1
//! returns: 0
2 2
//! Test typed multi-catch: catch e as ErrA {} catch e as ErrB {}.
3 3
4 -
union ErrA { A(i32) }
5 -
union ErrB { B(i32) }
4 +
union ErrA: Copy { A(i32) }
5 +
union ErrB: Copy { B(i32) }
6 6
7 7
fn failA() -> i32 throws (ErrA, ErrB) {
8 8
    throw ErrA::A(10);
9 9
}
10 10
test/tests/error.multi.propagate.multi.rad +2 -2
1 1
//! returns: 0
2 2
//! Test propagating a multi-throw callee via plain `try`.
3 3
4 -
union ErrA { A }
5 -
union ErrB { B }
4 +
union ErrA: Copy { A }
5 +
union ErrB: Copy { B }
6 6
7 7
fn inner(flag: i32) -> i32 throws (ErrA, ErrB) {
8 8
    if flag == 1 {
9 9
        throw ErrA::A();
10 10
    }
test/tests/error.multi.propagate.rad +2 -2
1 1
//! returns: 0
2 2
//! Test error propagation with multi-error and subset throw lists.
3 3
4 -
union ErrA { A }
5 -
union ErrB { B }
4 +
union ErrA: Copy { A }
5 +
union ErrB: Copy { B }
6 6
7 7
fn innerA() -> i32 throws (ErrA) {
8 8
    throw ErrA::A();
9 9
}
10 10
test/tests/error.multi.try.optional.rad +2 -2
1 1
//! returns: 0
2 2
//! Test try? with multi-error callee.
3 3
4 -
union ErrA { A }
5 -
union ErrB { B }
4 +
union ErrA: Copy { A }
5 +
union ErrB: Copy { B }
6 6
7 7
fn failA() -> i32 throws (ErrA, ErrB) {
8 8
    throw ErrA::A();
9 9
}
10 10
test/tests/error.try.bang.success.rad +1 -1
1 1
//! returns: 0
2 2
3 -
union PanicError { Boom }
3 +
union PanicError: Copy { Boom }
4 4
5 5
fn makeOk(value: u32) -> u32 throws (PanicError) {
6 6
    return value;
7 7
}
8 8
test/tests/error.try.catch.binding.rad +1 -1
1 1
//! returns: 0
2 2
3 -
union TestError { Boom, Bust }
3 +
union TestError: Copy { Boom, Bust }
4 4
5 5
@default fn main() -> u32 {
6 6
    // Test catching and using the error value.
7 7
    let mut caught: u32 = 0;
8 8
    try failWithBoom() catch e {
test/tests/error.try.optional.rad +2 -2
1 1
//! returns: 0
2 2
//! Test try? expressions converting errors to optionals.
3 3
4 -
union TestError { Boom, Bust }
4 +
union TestError: Copy { Boom, Bust }
5 5
6 6
fn returnsOk() -> u32 throws (TestError) {
7 7
    return 42;
8 8
}
9 9
10 10
fn returnsErr() -> u32 throws (TestError) {
11 11
    throw TestError::Boom;
12 12
}
13 13
14 -
record Point {
14 +
record Point: Copy {
15 15
    x: u32,
16 16
    y: u32,
17 17
}
18 18
19 19
fn returnsOkPoint() -> Point throws (TestError) {
test/tests/error.try.rad +2 -2
1 1
//! returns: 0
2 2
//! Test result-based error handling with try/throw.
3 3
4 -
union TestError { Boom, Bust }
4 +
union TestError: Copy { Boom, Bust }
5 5
6 -
record ResultSink {
6 +
record ResultSink: Copy {
7 7
    last: u32,
8 8
    count: u32,
9 9
}
10 10
11 11
fn returnsOk() -> u32 throws (TestError) {
test/tests/field.aggregate.rad +5 -5
1 1
/// Test field access where the field is an aggregate type.
2 2
/// Tests record, union, and slice fields.
3 3
4 -
record Inner { x: i32, y: i32 }
5 -
union MaybeInt { None, Some(i32) }
4 +
record Inner: Copy { x: i32, y: i32 }
5 +
union MaybeInt: Copy { None, Some(i32) }
6 6
7 -
record HasRecord { inner: Inner, z: i32 }
8 -
record HasUnion { maybe: MaybeInt, z: i32 }
9 -
record HasSlice { data: *[i32], z: i32 }
7 +
record HasRecord: Copy { inner: Inner, z: i32 }
8 +
record HasUnion: Copy { maybe: MaybeInt, z: i32 }
9 +
record HasSlice: Copy { data: *[i32], z: i32 }
10 10
11 11
/// Access a record field and read from it.
12 12
fn accessRecordField() -> i32 {
13 13
    let r = HasRecord { inner: Inner { x: 10, y: 20 }, z: 30 };
14 14
    return r.inner.y;
test/tests/fn.callback.nested.rad +2 -2
1 1
//! Test for callback with nested function call inside.
2 2
//! This exercises the register save/restore logic when a callback makes
3 3
//! a function call that uses caller-saved registers.
4 4
//! returns: 0
5 5
6 -
record Reg { n: u32 }
6 +
record Reg: Copy { n: u32 }
7 7
8 -
union Val {
8 +
union Val: Copy {
9 9
    Reg(Reg),
10 10
    Imm(i32),
11 11
}
12 12
13 13
fn maxRegNum(n: u32, current: u32) -> u32 {
test/tests/for.else.continue.rad +1 -1
1 1
//! returns: 0
2 2
//! Test `else continue` in a for loop with let-else.
3 3
4 -
record Field {
4 +
record Field: Copy {
5 5
    name: ?*[u8],
6 6
    value: i32,
7 7
}
8 8
9 9
fn findField(fields: *[Field], target: *[u8]) -> ?i32 {
test/tests/large.blit.store.rad +1 -1
11 11
//!
12 12
//! 2. Blit (memcpy) offset overflow: copying structs larger than ~2047 bytes
13 13
//!    caused the offset in the load/store loop to exceed the 12-bit immediate.
14 14
//!    Fixed by periodically advancing the base registers in the blit loop.
15 15
16 -
record Big {
16 +
record Big: Copy {
17 17
    a: [u8; 2200],
18 18
    tag: i32,
19 19
}
20 20
21 21
/// Store at offset 2200 (> MAX_IMM) into a record field.
test/tests/let.copy.semantics.rad +2 -2
1 1
/// Tests for copy semantics in let bindings.
2 2
/// Aggregates with storage (variables, field access, subscript, deref) need copying.
3 3
/// Temporaries (literals, call results) can be adopted directly.
4 4
5 -
record Point { x: i32, y: i32 }
6 -
record Outer { inner: Point, z: i32 }
5 +
record Point: Copy { x: i32, y: i32 }
6 +
record Outer: Copy { inner: Point, z: i32 }
7 7
8 8
/// Returns an aggregate - caller should NOT copy.
9 9
fn makePoint() -> Point {
10 10
    return Point { x: 1, y: 2 };
11 11
}
test/tests/let.guard.rad +1 -1
1 1
//! returns: 1
2 2
3 -
union Response {
3 +
union Response: Copy {
4 4
    success(i32),
5 5
    failure,
6 6
    other { message: *[u8] },
7 7
}
8 8
test/tests/literal.slice.record.rad +1 -1
1 1
/// Test slice literal with record elements.
2 -
record Point { x: i32, y: i32 }
2 +
record Point: Copy { x: i32, y: i32 }
3 3
4 4
fn localSliceOfRecords() -> i32 {
5 5
    let s: *[Point] = &[Point { x: 5, y: 6 }, Point { x: 7, y: 8 }];
6 6
    return s[0].x + s[1].y;
7 7
}
test/tests/load.u32.high.rad +1 -1
5 5
//! Regression test: `lw` sign-extends on RV64, producing a negative
6 6
//! 64-bit value for u32 values >= 0x80000000. The correct instruction
7 7
//! is `lwu` which zero-extends.
8 8
9 9
/// A u32 value with bit 31 set, stored in a struct to force a memory load.
10 -
record Pair {
10 +
record Pair: Copy {
11 11
    lo: u32,
12 12
    hi: u32,
13 13
}
14 14
15 15
/// Test that a u32 field with bit 31 set compares correctly.
test/tests/loc.addr.offset.bug.rad +2 -2
1 1
//! returns: 0
2 2
//! Test that LOC_ADDR values with non-zero offsets work correctly
3 3
//! for pass-by-ref types (structs).
4 4
5 -
record Inner {
5 +
record Inner: Copy {
6 6
    value: i32,
7 7
}
8 8
9 -
record Outer {
9 +
record Outer: Copy {
10 10
    pad: i32,      // offset 0, size 4
11 11
    inner: Inner,  // offset 4, size 4
12 12
}
13 13
14 14
static outer: Outer = undefined;
test/tests/loc.addr.opt.to.opt.rad +1 -1
1 1
//! returns: 0
2 2
//! Test assigning one optional to another when destination is LOC_ADDR
3 3
//! with offset.
4 4
5 -
record Container {
5 +
record Container: Copy {
6 6
    pad: i32,           // offset 0
7 7
    opt: ?i32,          // offset 4
8 8
}
9 9
10 10
static container: Container = undefined;
test/tests/loc.addr.optional.assign.rad +1 -1
1 1
//! returns: 0
2 2
//! Test assigning to an optional field stored at LOC_ADDR with offset.
3 3
4 -
record Container {
4 +
record Container: Copy {
5 5
    pad: i32,           // offset 0, size 4
6 6
    opt: ?i32,          // offset 4, size 8 (tag + value)
7 7
}
8 8
9 9
static container: Container = undefined;
test/tests/loc.addr.record.assign.rad +2 -2
1 1
//! returns: 0
2 2
//! Test assigning to a record field that is itself a record
3 3
//! when the parent is stored at LOC_ADDR (static).
4 4
5 -
record Inner {
5 +
record Inner: Copy {
6 6
    value: i32,
7 7
}
8 8
9 -
record Outer {
9 +
record Outer: Copy {
10 10
    pad: i32,      // offset 0, size 4
11 11
    inner: Inner,  // offset 4, size 4
12 12
}
13 13
14 14
static outer: Outer = undefined;
test/tests/loop.complex.flow.rad +1 -1
1 1
//! returns: 0
2 2
//! Test loop with complex control flow inside the body.
3 3
//! This mirrors patterns in the lowerer where loops contain
4 4
//! match statements, function calls, error handling, etc.
5 5
6 -
union Result {
6 +
union Result: Copy {
7 7
    Ok(i32),
8 8
    Err(i32),
9 9
}
10 10
11 11
fn maybeAdd(x: i32, y: i32) -> Result {
test/tests/loop.whilelet.union.rad +1 -1
1 1
/// Simple union for testing while-let with payload binding.
2 -
union Option { None, Some(u32) }
2 +
union Option: Copy { None, Some(u32) }
3 3
4 4
/// Sum values from a linked iteration using while-let case with binding.
5 5
fn sumWhileLet(x: Option) -> u32 {
6 6
    let mut opt = x;
7 7
    let mut sum: u32 = 0;
test/tests/lower.const.record.ident.rad +2 -2
1 -
record Reg(u8);
1 +
record Reg: Copy(u8);
2 2
3 3
constant A0: Reg = Reg(10);
4 4
constant A1: Reg = Reg(11);
5 5
6 -
record Entry {
6 +
record Entry: Copy {
7 7
    name: *[u8],
8 8
    reg: Reg,
9 9
}
10 10
11 11
constant ENTRIES: [Entry; 2] = [
test/tests/lower.private.union.const.rad +2 -2
1 -
union Kind {
1 +
union Kind: Copy {
2 2
    A,
3 3
    B,
4 4
}
5 5
6 -
record Entry {
6 +
record Entry: Copy {
7 7
    name: *[u8],
8 8
    kind: Kind,
9 9
}
10 10
11 11
constant ENTRIES: [Entry; 2] = [
test/tests/lower.record.scalar.record.const.rad +2 -2
1 -
record Reg(u8);
1 +
record Reg: Copy(u8);
2 2
3 -
record Entry {
3 +
record Entry: Copy {
4 4
    name: *[u8],
5 5
    reg: Reg,
6 6
}
7 7
8 8
constant ENTRIES: [Entry; 2] = [
test/tests/match.array.rad +1 -1
45 45
        }
46 46
    }
47 47
}
48 48
49 49
/// Array pattern nested inside union variant.
50 -
union Shape {
50 +
union Shape: Copy {
51 51
    Point { coords: [i32; 2] },
52 52
    Line { start: [i32; 2], end: [i32; 2] },
53 53
    None,
54 54
}
55 55
test/tests/match.char.rad +1 -1
11 11
        else => { return 0; }
12 12
    }
13 13
}
14 14
15 15
/// Character pattern nested inside a union variant field.
16 -
union Token {
16 +
union Token: Copy {
17 17
    Punct { ch: u8, pos: i32 },
18 18
    Eof,
19 19
}
20 20
21 21
fn tokenVal(t: Token) -> i32 {
test/tests/match.multi.seal.rad +1 -1
2 2
//! Regression test: intermediate arm blocks in multi-pattern matches must be
3 3
//! sealed so that SSA variables flow correctly through single-predecessor
4 4
//! optimization. Without sealing, block parameters are created but never
5 5
//! resolved, causing values to be read from wrong registers.
6 6
7 -
union Kind { A, B, C, D, E }
7 +
union Kind: Copy { A, B, C, D, E }
8 8
9 9
fn classify(k: Kind, y: i32) -> i32 {
10 10
    match k {
11 11
        case Kind::A, Kind::B, Kind::C => {
12 12
            return y + 10;
test/tests/match.multi.survive.rad +2 -2
7 7
//! the fall-through (else) path.
8 8
//!
9 9
//! This test catches the bug by requiring a value (`state`) to survive
10 10
//! through multiple match arms and into the `else` branch.
11 11
12 -
union Kind {
12 +
union Kind: Copy {
13 13
    Alpha,
14 14
    Beta,
15 15
    Gamma,
16 16
    Delta,
17 17
    Epsilon,
18 18
}
19 19
20 -
record State {
20 +
record State: Copy {
21 21
    value: i32,
22 22
    kind: Kind,
23 23
}
24 24
25 25
fn classify(s: State) -> i32 {
test/tests/match.mutref.push.rad +2 -2
1 1
//! returns: 0
2 2
//! Test pushing items through a mutable reference obtained via match.
3 3
4 -
record U32List {
4 +
record U32List: Copy {
5 5
    data: *mut [u32],
6 6
    len: u32,
7 7
}
8 8
9 -
union Sealed {
9 +
union Sealed: Copy {
10 10
    No { items: U32List },
11 11
    Yes,
12 12
}
13 13
14 14
fn pushItem(list: *mut U32List, value: u32) {
test/tests/match.mutref.union.rad +2 -2
1 1
//! returns: 0
2 2
//! Test matching on a mutable reference to a union field and mutating
3 3
//! the payload in place.
4 4
5 -
union State {
5 +
union State: Copy {
6 6
    A { count: u32 },
7 7
    B,
8 8
}
9 9
10 -
record Data {
10 +
record Data: Copy {
11 11
    state: State,
12 12
    value: u32,
13 13
}
14 14
15 15
fn process(d: *mut Data) -> u32 {
test/tests/match.nested.call.rad +3 -3
1 1
//! returns: 0
2 2
//! Test nested patterns with tuple-style (Call) union variants.
3 3
4 -
union Dir { North, South }
5 -
union Opt { Some(i32), None }
4 +
union Dir: Copy { North, South }
5 +
union Opt: Copy { Some(i32), None }
6 6
7 7
/// Tuple-style variant with integer literal nested pattern.
8 8
fn checkOpt(o: Opt) -> i32 {
9 9
    match o {
10 10
        case Opt::Some(42) => {
33 33
        else { return -1; };
34 34
    return x;
35 35
}
36 36
37 37
/// Nested union inside tuple-style variant.
38 -
union Wrapper { Wrap(Dir), Empty }
38 +
union Wrapper: Copy { Wrap(Dir), Empty }
39 39
40 40
fn extractDir(w: Wrapper) -> i32 {
41 41
    match w {
42 42
        case Wrapper::Wrap(Dir::North) => {
43 43
            return 10;
test/tests/match.nested.deep.rad +6 -6
1 1
//! returns: 0
2 2
//! Test deeply nested patterns: three levels of record nesting,
3 3
//! and nested unions inside records inside unions.
4 4
5 -
record Leaf {
5 +
record Leaf: Copy {
6 6
    val: i32,
7 7
}
8 8
9 -
record Branch {
9 +
record Branch: Copy {
10 10
    leaf: Leaf,
11 11
    extra: i32,
12 12
}
13 13
14 -
union Tree {
14 +
union Tree: Copy {
15 15
    Node { branch: Branch, tag: i32 },
16 16
    Empty,
17 17
}
18 18
19 19
/// Three levels deep: union -> record -> record -> record.
27 27
        }
28 28
    }
29 29
}
30 30
31 31
/// Nested union inside a record inside a union.
32 -
union Color { Red, Green, Blue }
32 +
union Color: Copy { Red, Green, Blue }
33 33
34 -
record Pixel {
34 +
record Pixel: Copy {
35 35
    color: Color,
36 36
    brightness: i32,
37 37
}
38 38
39 -
union Canvas {
39 +
union Canvas: Copy {
40 40
    Filled { pixel: Pixel },
41 41
    Blank,
42 42
}
43 43
44 44
fn getColor(cv: Canvas) -> i32 {
test/tests/match.nested.deref.rad +6 -6
1 1
//! returns: 0
2 2
//! Test nested patterns through pointer dereferences (auto-deref).
3 3
4 -
union Inner {
4 +
union Inner: Copy {
5 5
    A(i32),
6 6
    B,
7 7
}
8 8
9 -
union Outer {
9 +
union Outer: Copy {
10 10
    Some(*Inner),
11 11
    None,
12 12
}
13 13
14 14
/// Match nested union variant through pointer dereference in match/case.
40 40
        else { return -1; };
41 41
    return x;
42 42
}
43 43
44 44
/// Record with pointer field and nested pattern through deref.
45 -
record Container {
45 +
record Container: Copy {
46 46
    inner: *Inner,
47 47
    tag: i32,
48 48
}
49 49
50 -
union Boxed {
50 +
union Boxed: Copy {
51 51
    Some { c: Container },
52 52
    None,
53 53
}
54 54
55 55
/// Nested record with auto-deref on a pointer field.
87 87
    }
88 88
    return 0;
89 89
}
90 90
91 91
/// Auto-deref through pointer to record in a record field.
92 -
record Point {
92 +
record Point: Copy {
93 93
    x: i32,
94 94
    y: i32,
95 95
}
96 96
97 -
union Holder {
97 +
union Holder: Copy {
98 98
    Ptr { p: *Point, z: i32 },
99 99
    Empty,
100 100
}
101 101
102 102
fn derefRecordField(h: Holder) -> i32 {
test/tests/match.nested.guard.rad +4 -4
1 1
//! returns: 0
2 2
//! Test nested patterns combined with guards.
3 3
4 -
record Pair {
4 +
record Pair: Copy {
5 5
    a: i32,
6 6
    b: i32,
7 7
}
8 8
9 -
union Opt {
9 +
union Opt: Copy {
10 10
    Some { pair: Pair },
11 11
    None,
12 12
}
13 13
14 14
/// Nested pattern with guard on bound variable.
25 25
        }
26 26
    }
27 27
}
28 28
29 29
/// Nested union with guard.
30 -
union Tag { X, Y }
30 +
union Tag: Copy { X, Y }
31 31
32 -
union Box {
32 +
union Box: Copy {
33 33
    Item { tag: Tag, val: i32 },
34 34
    Empty,
35 35
}
36 36
37 37
fn guardedNested(bx: Box) -> i32 {
test/tests/match.nested.iflet.guard.rad +4 -4
1 1
//! returns: 0
2 2
//! Test nested patterns combined with guards in if-let-case.
3 3
4 -
record Pair {
4 +
record Pair: Copy {
5 5
    a: i32,
6 6
    b: i32,
7 7
}
8 8
9 -
union Opt {
9 +
union Opt: Copy {
10 10
    Some { pair: Pair },
11 11
    None,
12 12
}
13 13
14 14
/// Nested record pattern with guard on bound variable.
18 18
    }
19 19
    return -1;
20 20
}
21 21
22 22
/// Nested union variant with guard.
23 -
union Dir { North, South }
23 +
union Dir: Copy { North, South }
24 24
25 -
union Command {
25 +
union Command: Copy {
26 26
    Move { dir: Dir, speed: i32 },
27 27
    Stop,
28 28
}
29 29
30 30
fn fastNorth(c: Command) -> i32 {
test/tests/match.nested.iflet.rad +4 -4
1 1
//! returns: 0
2 2
//! Test nested patterns in if-let-case and let-else contexts.
3 3
4 -
record Inner {
4 +
record Inner: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 -
union Wrapper {
9 +
union Wrapper: Copy {
10 10
    Some { inner: Inner, z: i32 },
11 11
    None,
12 12
}
13 13
14 14
/// Nested if-let-case.
18 18
    }
19 19
    return -1;
20 20
}
21 21
22 22
/// Nested union variant in if-let-case.
23 -
union Kind { A, B }
23 +
union Kind: Copy { A, B }
24 24
25 -
union Tagged {
25 +
union Tagged: Copy {
26 26
    Item { kind: Kind, val: i32 },
27 27
    Empty,
28 28
}
29 29
30 30
fn ifLetNestedUnion(t: Tagged) -> i32 {
test/tests/match.nested.letelse.rad +2 -2
1 1
//! returns: 0
2 2
//! Test nested patterns in let-else statements.
3 3
4 -
record Inner {
4 +
record Inner: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 -
union Wrapper {
9 +
union Wrapper: Copy {
10 10
    Some { inner: Inner, z: i32 },
11 11
    None,
12 12
}
13 13
14 14
/// Nested record destructuring in let-else.
test/tests/match.nested.letelse.union.rad +5 -5
1 1
//! returns: 0
2 2
//! Test nested union variant patterns in let-else statements.
3 3
4 -
union Dir { North, South }
4 +
union Dir: Copy { North, South }
5 5
6 -
union Command {
6 +
union Command: Copy {
7 7
    Move { dir: Dir, speed: i32 },
8 8
    Stop,
9 9
}
10 10
11 11
/// Nested union variant in let-else.
14 14
        else { return -1; };
15 15
    return speed;
16 16
}
17 17
18 18
/// Nested union variant in let-else, deeper nesting.
19 -
record Inner {
19 +
record Inner: Copy {
20 20
    x: i32,
21 21
    y: i32,
22 22
}
23 23
24 -
union Wrapper {
24 +
union Wrapper: Copy {
25 25
    Some { inner: Inner, z: i32 },
26 26
    None,
27 27
}
28 28
29 -
union Box {
29 +
union Box: Copy {
30 30
    Filled { w: Wrapper, tag: i32 },
31 31
    Empty,
32 32
}
33 33
34 34
fn extractInner(b: Box) -> i32 {
test/tests/match.nested.literal.rad +2 -2
1 1
//! returns: 0
2 2
//! Test literal patterns (integers, booleans) nested inside union variant fields.
3 3
4 -
union Action {
4 +
union Action: Copy {
5 5
    Set { code: i32, value: i32 },
6 6
    Toggle { flag: bool },
7 7
    None,
8 8
}
9 9
53 53
    }
54 54
    return false;
55 55
}
56 56
57 57
/// Multiple literal fields in the same pattern.
58 -
union Pair {
58 +
union Pair: Copy {
59 59
    Both { a: i32, b: i32 },
60 60
    Empty,
61 61
}
62 62
63 63
fn matchBothLiterals(p: Pair) -> i32 {
test/tests/match.nested.multi.rad +3 -3
1 1
//! returns: 0
2 2
//! Test multiple nested refining fields in the same record pattern.
3 3
4 -
union Dir { North, South, East }
5 -
union Mode { Fast, Slow }
4 +
union Dir: Copy { North, South, East }
5 +
union Mode: Copy { Fast, Slow }
6 6
7 -
union Command {
7 +
union Command: Copy {
8 8
    Move { dir: Dir, mode: Mode, speed: i32 },
9 9
    Stop,
10 10
}
11 11
12 12
/// Two union-typed fields refined simultaneously.
test/tests/match.nested.pattern.rad +12 -12
1 1
//! returns: 0
2 2
//! Test nested patterns in match/case statements.
3 3
4 -
record Inner {
4 +
record Inner: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 -
union Outer {
9 +
union Outer: Copy {
10 10
    A { inner: Inner, z: i32 },
11 11
    B,
12 12
}
13 13
14 14
/// Match a union variant and destructure its nested record field.
42 42
        }
43 43
    }
44 44
}
45 45
46 46
/// Multi-level nesting: three records deep.
47 -
record Deep {
47 +
record Deep: Copy {
48 48
    val: i32,
49 49
}
50 50
51 -
record Mid {
51 +
record Mid: Copy {
52 52
    deep: Deep,
53 53
    extra: i32,
54 54
}
55 55
56 -
union Wrapper {
56 +
union Wrapper: Copy {
57 57
    W { mid: Mid, tag: i32 },
58 58
    Empty,
59 59
}
60 60
61 61
fn testDeepNesting(w: Wrapper) -> i32 {
68 68
        }
69 69
    }
70 70
}
71 71
72 72
/// Nested union inside a union variant.
73 -
union Direction {
73 +
union Direction: Copy {
74 74
    North,
75 75
    South,
76 76
}
77 77
78 -
union Command {
78 +
union Command: Copy {
79 79
    Move { dir: Direction, speed: i32 },
80 80
    Stop,
81 81
}
82 82
83 83
fn testNestedUnionLiteral(c: Command) -> i32 {
93 93
        }
94 94
    }
95 95
}
96 96
97 97
/// Mixed record and union nesting with multiple fields.
98 -
record Point {
98 +
record Point: Copy {
99 99
    x: i32,
100 100
    y: i32,
101 101
}
102 102
103 -
union Shape {
103 +
union Shape: Copy {
104 104
    Circle { center: Point, radius: i32 },
105 105
    Rect { origin: Point, size: Point },
106 106
    None,
107 107
}
108 108
119 119
        }
120 120
    }
121 121
}
122 122
123 123
/// Nested union variant pattern inside record field.
124 -
union Pair {
124 +
union Pair: Copy {
125 125
    Val { a: i32, b: i32 },
126 126
    Empty,
127 127
}
128 128
129 -
record Container {
129 +
record Container: Copy {
130 130
    pair: Pair,
131 131
    label: i32,
132 132
}
133 133
134 -
union Boxed {
134 +
union Boxed: Copy {
135 135
    Some { c: Container },
136 136
    None,
137 137
}
138 138
139 139
fn testNestedUnionInRecord(bx: Boxed) -> i32 {
test/tests/match.nested.record.rad +3 -3
1 1
//! returns: 0
2 2
//! Test nested record destructuring inside union variant patterns.
3 3
4 -
record Point {
4 +
record Point: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 -
record Rect {
9 +
record Rect: Copy {
10 10
    origin: Point,
11 11
    size: Point,
12 12
}
13 13
14 -
union Shape {
14 +
union Shape: Copy {
15 15
    Circle { center: Point, radius: i32 },
16 16
    Rectangle { rect: Rect },
17 17
    None,
18 18
}
19 19
test/tests/match.nested.union.rad +2 -2
1 1
//! returns: 0
2 2
//! Test nested union variant patterns inside record fields.
3 3
4 -
union Dir { North, South, East, West }
4 +
union Dir: Copy { North, South, East, West }
5 5
6 -
union Command {
6 +
union Command: Copy {
7 7
    Move { dir: Dir, speed: i32 },
8 8
    Turn { dir: Dir },
9 9
    Stop,
10 10
}
11 11
test/tests/match.nested.whilelet.rad +4 -4
1 1
//! returns: 0
2 2
//! Test nested patterns in while-let loops.
3 3
4 -
record Pair {
4 +
record Pair: Copy {
5 5
    a: i32,
6 6
    b: i32,
7 7
}
8 8
9 -
union Opt {
9 +
union Opt: Copy {
10 10
    Some { pair: Pair },
11 11
    None,
12 12
}
13 13
14 14
fn get(items: *[Opt], idx: u32) -> Opt {
38 38
        set i = i + 1;
39 39
    }
40 40
    return sum;
41 41
}
42 42
43 -
union Dir { North, South }
43 +
union Dir: Copy { North, South }
44 44
45 -
union Command {
45 +
union Command: Copy {
46 46
    Move { dir: Dir, speed: i32 },
47 47
    Stop,
48 48
}
49 49
50 50
fn getCmd(items: *[Command], idx: u32) -> Command {
test/tests/match.record.pattern.rad +1 -1
1 1
/// Match on union variant with record payload and bind fields.
2 -
union Expr {
2 +
union Expr: Copy {
3 3
    Null,
4 4
    Pair { first: i32, second: i32 },
5 5
}
6 6
7 7
/// Extract the first field from a Pair variant.
test/tests/match.string.rad +1 -1
18 18
        }
19 19
    }
20 20
}
21 21
22 22
/// String pattern nested inside a union variant field.
23 -
union Cmd {
23 +
union Cmd: Copy {
24 24
    Say { msg: *[u8], count: i32 },
25 25
    Quit,
26 26
}
27 27
28 28
fn dispatch(c: Cmd) -> i32 {
test/tests/match.value.copy.rad +3 -3
5 5
//!
6 6
//! The bug: when pattern-matching a union by value, the lowerer returns a
7 7
//! pointer into the original union's payload instead of copying it. If the
8 8
//! source is overwritten, the binding reads garbage.
9 9
10 -
record Pair {
10 +
record Pair: Copy {
11 11
    a: u32,
12 12
    b: u32,
13 13
}
14 14
15 -
union Data {
15 +
union Data: Copy {
16 16
    Some { pair: Pair },
17 17
    None,
18 18
}
19 19
20 -
record Box {
20 +
record Box: Copy {
21 21
    data: Data,
22 22
}
23 23
24 24
/// Test let-case on an aggregate union payload.
25 25
/// The Pair inside the union is an aggregate - its binding will be a pointer
test/tests/match.void.then.or.rad +2 -2
1 1
//! returns: 0
2 2
//! Regression test: match on void union followed by 'or' equality check
3 3
//! in the else branch.
4 4
5 -
union Op {
5 +
union Op: Copy {
6 6
    Add,
7 7
    Sub,
8 8
    Mul,
9 9
    Div,
10 10
    And,
12 12
    Xor,
13 13
    Eq,
14 14
    Ne,
15 15
}
16 16
17 -
record Expr {
17 +
record Expr: Copy {
18 18
    op: Op,
19 19
    left: i32,
20 20
    right: i32,
21 21
}
22 22
test/tests/memzero.result.bug.rad +1 -1
1 1
//! returns: 0
2 2
//! Test for result memzero overrun: success payload is tiny, error payload
3 3
//! is large, and a guard word sits immediately after the return slot.
4 4
5 -
union Err {
5 +
union Err: Copy {
6 6
    Big([u32; 3]), // 12-byte error payload, forces a large result container
7 7
}
8 8
9 9
fn fallible(ok: bool) throws (Err) {
10 10
    if ok {
test/tests/memzero.union.bug.rad +2 -2
1 1
//! returns: 0
2 2
//! Test enum with a large variant to force a payload capacity bigger than
3 3
//! the small variant we actually store.
4 -
union Payload {
4 +
union Payload: Copy {
5 5
    Big([u32; 3]), // 12-byte payload
6 6
    Small(u8),     // 1-byte payload
7 7
}
8 8
9 -
record Frame {
9 +
record Frame: Copy {
10 10
    guard1: u16,
11 11
    val: Payload,
12 12
    guard2: u32,
13 13
}
14 14
test/tests/method.basic.rad +1 -1
1 1
//! returns: 0
2 2
//! Basic standalone method test.
3 3
4 -
record Point {
4 +
record Point: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 9
fn (p: *Point) sum() -> i32 {
test/tests/method.chain.rad +1 -1
1 1
//! returns: 0
2 2
//! Method chaining via mutable pointer returns.
3 3
4 -
record Builder {
4 +
record Builder: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 9
fn (b: *mut Builder) setX(x: i32) -> *mut Builder {
test/tests/method.multiple.rad +1 -1
1 1
//! returns: 0
2 2
//! Multiple methods on the same type.
3 3
4 -
record Vec2 {
4 +
record Vec2: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 9
fn (v: *Vec2) magnitudeSq() -> i32 {
test/tests/method.ptr.rad +1 -1
1 1
//! returns: 0
2 2
//! Methods called via various pointer indirections.
3 3
4 -
record Counter {
4 +
record Counter: Copy {
5 5
    value: i32,
6 6
}
7 7
8 8
fn (c: *Counter) get() -> i32 {
9 9
    return c.value;
test/tests/method.pub.rad +1 -1
1 1
//! returns: 0
2 2
//! Public attribute on standalone methods.
3 3
4 -
record Foo {
4 +
record Foo: Copy {
5 5
    x: i32,
6 6
}
7 7
8 8
export fn (f: *Foo) getX() -> i32 {
9 9
    return f.x;
test/tests/method.return.rad +1 -1
1 1
//! returns: 0
2 2
//! Methods returning various types and records.
3 3
4 -
record Pair {
4 +
record Pair: Copy {
5 5
    a: i32,
6 6
    b: i32,
7 7
}
8 8
9 9
fn (p: *Pair) sum() -> i32 {
test/tests/method.throws.rad +2 -2
1 1
//! returns: 0
2 2
//! Methods that throw errors.
3 3
4 -
union ParseError {
4 +
union ParseError: Copy {
5 5
    Invalid,
6 6
}
7 7
8 -
record Parser {
8 +
record Parser: Copy {
9 9
    pos: i32,
10 10
    len: i32,
11 11
}
12 12
13 13
fn (p: *mut Parser) advance() throws (ParseError) {
test/tests/method.union.rad +1 -1
1 1
//! returns: 0
2 2
//! Standalone methods on union types.
3 3
4 -
union Shape {
4 +
union Shape: Copy {
5 5
    Circle(i32),
6 6
    Rect { w: i32, h: i32 },
7 7
}
8 8
9 9
fn (s: *Shape) isCircle() -> bool {
test/tests/method.with.trait.rad +1 -1
1 1
//! returns: 0
2 2
//! Standalone methods coexisting with trait instances on the same type.
3 3
4 -
record Widget {
4 +
record Widget: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 9
// Standalone method.
test/tests/multi.throw.basic.rad +2 -2
1 1
/// Multi-throw: function that can throw two different error types.
2 -
union ErrA { A }
3 -
union ErrB { B }
2 +
union ErrA: Copy { A }
3 +
union ErrB: Copy { B }
4 4
5 5
fn fallible(flag: i32) -> i32 throws (ErrA, ErrB) {
6 6
    if flag == 1 {
7 7
        throw ErrA::A();
8 8
    }
test/tests/multi.throw.catch.typed.rad +2 -2
1 1
/// Multi-error typed catch: switch dispatch on error tag.
2 -
union ErrA { A }
3 -
union ErrB { B }
2 +
union ErrA: Copy { A }
3 +
union ErrB: Copy { B }
4 4
5 5
fn fallible(flag: i32) -> i32 throws (ErrA, ErrB) {
6 6
    if flag == 1 {
7 7
        throw ErrA::A();
8 8
    }
test/tests/multi.throw.propagate.rad +2 -2
1 1
/// Multi-throw propagation: caller propagates errors from callee with subset throw list.
2 -
union ErrA { A }
3 -
union ErrB { B }
2 +
union ErrA: Copy { A }
3 +
union ErrB: Copy { B }
4 4
5 5
fn inner(flag: bool) -> i32 throws (ErrA) {
6 6
    if flag {
7 7
        throw ErrA::A();
8 8
    }
test/tests/mutref.call.result.rad +1 -1
1 1
//! returns: 0
2 2
//! Mutable borrow through a field access on a call result.
3 3
4 -
record Box {
4 +
record Box: Copy {
5 5
    x: i32,
6 6
}
7 7
8 8
fn idBox(b: *mut Box) -> *mut Box {
9 9
    return b;
test/tests/opt.record.eq.rad +2 -2
1 1
//! returns: 1
2 2
//! Test equality comparison of optional records.
3 3
4 -
record Inner {
4 +
record Inner: Copy {
5 5
    start: i32,
6 6
    end: i32,
7 7
}
8 8
9 -
record Outer {
9 +
record Outer: Copy {
10 10
    item: ?Inner,
11 11
}
12 12
13 13
@default fn main() -> bool {
14 14
    let outerA = Outer { item: Inner { start: 3, end: 9 } };
test/tests/opt.record.eq.rev.rad +1 -1
1 1
/// Tests equality between an optional record and a record (?T == T).
2 2
3 -
record Id { n: u32 }
3 +
record Id: Copy { n: u32 }
4 4
5 5
/// Wraps a record in an optional.
6 6
fn makeOpt(id: Id) -> ?Id {
7 7
    return id;
8 8
}
test/tests/opt.record.rad +2 -2
1 1
//! returns: 28
2 2
//! Test optional records with if-let.
3 3
4 -
record Vector {
4 +
record Vector: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
    z: i32,
8 8
}
9 9
10 -
record Wrapper {
10 +
record Wrapper: Copy {
11 11
    opt: ?i32,
12 12
}
13 13
14 14
fn takeOptional(x: ?i32) -> i32 {
15 15
    if let value = x {
test/tests/opt.return.nested.rad +1 -1
1 1
//! returns: 99
2 2
3 -
record Pair {
3 +
record Pair: Copy {
4 4
    x: u32,
5 5
    y: u32,
6 6
}
7 7
8 8
fn pick(flag: bool) -> ?Pair {
test/tests/opt.return.record.rad +1 -1
1 1
//! returns: 99
2 2
//! Test returning optional records from functions.
3 3
4 -
record Vector {
4 +
record Vector: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
    z: i32
8 8
}
9 9
test/tests/optional.aggregate.eq.rad +1 -1
1 1
// Test optional aggregate equality (non-pointer optionals)
2 2
3 -
record Pair {
3 +
record Pair: Copy {
4 4
    a: i32,
5 5
    b: i32,
6 6
}
7 7
8 8
fn optPairEq(a: ?Pair, b: ?Pair) -> bool {
test/tests/optional.record.value.match.rad +1 -1
1 1
//! returns: 0
2 2
//! Matching an optional record against a record value must compile and compare structurally.
3 3
4 -
record Pair {
4 +
record Pair: Copy {
5 5
    a: i32,
6 6
    b: i32,
7 7
}
8 8
9 9
fn classify(value: ?Pair) -> i32 {
test/tests/parser.call.record.argument.rad +1 -1
1 1
//! returns: 0
2 2
3 -
record Box { value: i32 }
3 +
record Box: Copy { value: i32 }
4 4
5 5
fn isOne(box: Box) -> bool {
6 6
    return box.value == 1;
7 7
}
8 8
test/tests/parser.condition.array.record.rad +1 -1
1 1
//! returns: 0
2 2
//! Bracketed array elements may contain record literals in a condition.
3 3
4 -
record Box { value: i32 }
4 +
record Box: Copy { value: i32 }
5 5
6 6
@default fn main() -> i32 {
7 7
    if [Box { value: 1 }][0].value == 1 {
8 8
        return 0;
9 9
    }
test/tests/parser.condition.subscript.record.rad +1 -1
1 1
//! returns: 0
2 2
//! Bracketed subscript expressions may contain record literals in a condition.
3 3
4 -
record Index { value: u32 }
4 +
record Index: Copy { value: u32 }
5 5
6 6
@default fn main() -> i32 {
7 7
    let values: [i32; 1] = [7];
8 8
    if values[Index { value: 0 }.value] == 7 {
9 9
        return 0;
test/tests/pointer.copy.edge.case.rad +4 -4
1 1
//! returns: 0
2 2
3 -
union NodeKind {
3 +
union NodeKind: Copy {
4 4
    Placeholder,
5 5
    Bool(bool),
6 6
}
7 7
8 -
record Span {
8 +
record Span: Copy {
9 9
    length: u32,
10 10
}
11 11
12 -
record Node {
12 +
record Node: Copy {
13 13
    span: Span,
14 14
    kind: NodeKind,
15 15
}
16 16
17 -
record Parser {
17 +
record Parser: Copy {
18 18
    nodes: [Node; 1],
19 19
    count: u32,
20 20
}
21 21
22 22
fn makeNode(p: *mut Parser, kind: NodeKind) -> *mut Node {
test/tests/pointer.slice.index.rad +1 -1
1 1
//! returns: 0
2 2
3 -
record Holder {
3 +
record Holder: Copy {
4 4
    ptr: *[i32],
5 5
    zero: u32,
6 6
}
7 7
8 8
// Test that pointer-to-slice indexing correctly dereferences the slice header.
test/tests/pointer.slice.store.rad +3 -3
1 1
//! returns: 0
2 2
//! Test storing through a pointer to a slice in static storage.
3 3
4 -
record Entry {
4 +
record Entry: Copy {
5 5
    a: u32,
6 6
    b: u32,
7 7
    c: u32,
8 8
    d: u32,
9 9
    e: u32,
10 10
}
11 11
12 -
record Table {
12 +
record Table: Copy {
13 13
    entries: *mut [Entry],
14 14
    len: u32,
15 15
}
16 16
17 -
record PtrBox {
17 +
record PtrBox: Copy {
18 18
    ptr: *mut *mut [Entry],
19 19
}
20 20
21 21
static STORAGE: [Entry; 2] = undefined;
22 22
static TABLE: Table = undefined;
test/tests/prog.cordic.rad +1 -1
20 20
21 21
/// Pi/2 in Q16.16.
22 22
constant HALF_PI: i32 = 102944;
23 23
24 24
/// Result record for cos and sin.
25 -
record CosSin {
25 +
record CosSin: Copy {
26 26
    cos: i32,
27 27
    sin: i32,
28 28
}
29 29
30 30
/// CORDIC rotation mode: compute cos(angle) and sin(angle).
test/tests/prog.dijkstra.rad +2 -2
4 4
//! and a min-heap priority queue. Reconstruct paths and verify distances.
5 5
6 6
constant MAX_NODES: u32 = 16;
7 7
constant INF: u32 = 0xFFFFFFFF;
8 8
9 -
record HeapEntry {
9 +
record HeapEntry: Copy {
10 10
    dist: u32,
11 11
    node: u32,
12 12
}
13 13
14 -
record Graph {
14 +
record Graph: Copy {
15 15
    adj: *mut [[u32; 16]],
16 16
    dist: *mut [u32],
17 17
    prev: *mut [i32],
18 18
    visited: *mut [bool],
19 19
    numNodes: u32,
test/tests/prog.eval.rad +4 -4
4 4
//! of tagged union nodes. Build expression trees, evaluate them recursively,
5 5
//! and verify results.
6 6
7 7
/// An expression node. Leaf nodes hold a number. Interior nodes hold an
8 8
/// operator and indices (into the nodes array) of their left and right children.
9 -
union Expr {
9 +
union Expr: Copy {
10 10
    Num(i32),
11 11
    Add(BinOp),
12 12
    Sub(BinOp),
13 13
    Mul(BinOp),
14 14
    Div(BinOp),
15 15
    Neg(u32),
16 16
}
17 17
18 18
/// Binary operator: indices of left and right child nodes.
19 -
record BinOp {
19 +
record BinOp: Copy {
20 20
    left: u32,
21 21
    right: u32,
22 22
}
23 23
24 24
/// A pool of expression nodes with a count of allocated nodes.
25 -
record Pool {
25 +
record Pool: Copy {
26 26
    nodes: [Expr; 64],
27 27
    count: u32,
28 28
}
29 29
30 30
/// Evaluation error.
31 -
union EvalError {
31 +
union EvalError: Copy {
32 32
    DivByZero
33 33
}
34 34
35 35
/// Allocate a new node, returning its index.
36 36
fn newNode(pool: *mut Pool, expr: Expr) -> u32 {
test/tests/prog.hanoi.rad +3 -3
6 6
constant NUM_DISKS: u32 = 6;
7 7
/// 2^6 - 1 = 63 moves.
8 8
constant MAX_MOVES: u32 = 63;
9 9
10 10
/// A single move: move a disk from one peg to another.
11 -
record Move {
11 +
record Move: Copy {
12 12
    disk: u32,
13 13
    from: u32,
14 14
    to: u32,
15 15
}
16 16
17 17
/// Log of all moves performed.
18 -
record MoveLog {
18 +
record MoveLog: Copy {
19 19
    moves: [Move; 63],
20 20
    count: u32,
21 21
}
22 22
23 23
/// Record a move.
65 65
    return 0;
66 66
}
67 67
68 68
/// Peg state: array of 3 pegs, each holding up to NUM_DISKS disks.
69 69
/// top[p] = number of disks currently on peg p.
70 -
record Pegs {
70 +
record Pegs: Copy {
71 71
    stacks: [[u32; 6]; 3],
72 72
    top: [u32; 3],
73 73
}
74 74
75 75
fn pegPush(pegs: *mut Pegs, peg: u32, disk: u32) -> bool {
test/tests/prog.huffman.rad +3 -3
6 6
constant MAX_SYMBOLS: u32 = 32;
7 7
constant MAX_NODES: u32 = 63;
8 8
constant MAX_BITS: u32 = 512;
9 9
10 10
/// A node in the Huffman tree.
11 -
union HNodeKind {
11 +
union HNodeKind: Copy {
12 12
    /// Leaf node with a symbol index.
13 13
    Leaf(u32),
14 14
    /// Interior node (no symbol).
15 15
    Interior,
16 16
}
17 17
18 -
record HNode {
18 +
record HNode: Copy {
19 19
    freq: u32,
20 20
    kind: HNodeKind,
21 21
    left: u32,
22 22
    right: u32,
23 23
}
24 24
25 25
constant NIL: u32 = 0xFFFFFFFF;
26 26
27 -
record HuffState {
27 +
record HuffState: Copy {
28 28
    nodes: *mut [HNode],
29 29
    nodeCount: u32,
30 30
    heap: *mut [u32],
31 31
    heapSize: u32,
32 32
    codeBits: *mut [u32],
test/tests/prog.linkedlist.rad +2 -2
2 2
//! Linked list via array pool.
3 3
//! Implement a singly-linked list using an array of node records
4 4
//! (pool allocator pattern). Operations: push, pop, find, reverse, length.
5 5
6 6
/// A node in the linked list.
7 -
record Node {
7 +
record Node: Copy {
8 8
    value: i32,
9 9
    next: ?u32,
10 10
}
11 11
12 12
/// A linked list backed by a pool of pre-allocated nodes.
13 -
record List {
13 +
record List: Copy {
14 14
    pool: [Node; 64],
15 15
    free: u32,
16 16
    head: ?u32,
17 17
}
18 18
test/tests/prog.lzw.rad +2 -2
6 6
constant MAX_DICT: u32 = 512;
7 7
constant INIT_DICT: u32 = 258;
8 8
constant CLEAR_CODE: u32 = 256;
9 9
constant EOI_CODE: u32 = 257;
10 10
11 -
record DictEntry {
11 +
record DictEntry: Copy {
12 12
    prefix: u32,
13 13
    suffix: u8,
14 14
}
15 15
16 -
record LzwState {
16 +
record LzwState: Copy {
17 17
    encDict: *mut [DictEntry],
18 18
    encDictSize: u32,
19 19
    decDict: *mut [DictEntry],
20 20
    decDictSize: u32,
21 21
    encoded: *mut [u32],
test/tests/prog.matmul.rad +1 -1
4 4
//! a known expected output. Classic benchmark kernel.
5 5
6 6
constant N: u32 = 4;
7 7
8 8
/// A 4x4 integer matrix (row-major).
9 -
record Mat4 {
9 +
record Mat4: Copy {
10 10
    rows: [[i32; 4]; 4],
11 11
}
12 12
13 13
/// Perform matrix multiplication: c = a * b.
14 14
fn matmul(c: *mut Mat4, a: *Mat4, b: *Mat4) {
test/tests/prog.mersenne.rad +1 -1
5 5
constant M: u32 = 397;
6 6
constant MATRIX_A: u32 = 0x9908B0DF;
7 7
constant UPPER_MASK: u32 = 0x80000000;
8 8
constant LOWER_MASK: u32 = 0x7FFFFFFF;
9 9
10 -
record MtState {
10 +
record MtState: Copy {
11 11
    mt: *mut [u32],
12 12
    mti: u32,
13 13
}
14 14
15 15
fn mtInit(s: *mut MtState, seed: u32) {
test/tests/prog.nqueens.rad +1 -1
3 3
//! Solve the N-Queens problem using backtracking. Count all valid placements
4 4
//! for boards of size 1 through 8 and verify against known solution counts.
5 5
6 6
constant MAX_N: u32 = 8;
7 7
8 -
record Board {
8 +
record Board: Copy {
9 9
    queens: *mut [i32],
10 10
    solutionCount: u32,
11 11
    boardSize: u32,
12 12
}
13 13
test/tests/prog.rbtree.rad +2 -2
6 6
constant NIL: u32 = 0;
7 7
8 8
constant RED: u32 = 0;
9 9
constant BLACK: u32 = 1;
10 10
11 -
record RBNode {
11 +
record RBNode: Copy {
12 12
    key: i32,
13 13
    color: u32,
14 14
    left: u32,
15 15
    right: u32,
16 16
    parent: u32,
17 17
}
18 18
19 -
record RBTree {
19 +
record RBTree: Copy {
20 20
    pool: *mut [RBNode],
21 21
    poolNext: u32,
22 22
    root: u32,
23 23
    inorder: *mut [i32],
24 24
    inorderCount: u32,
test/tests/prog.regex.rad +3 -3
10 10
11 11
constant TRANS_CHAR: u32 = 0;
12 12
constant TRANS_EPSILON: u32 = 1;
13 13
constant TRANS_DOT: u32 = 2;
14 14
15 -
record Trans {
15 +
record Trans: Copy {
16 16
    kind: u32,
17 17
    ch: u8,
18 18
    to: u32,
19 19
}
20 20
21 -
record Frag {
21 +
record Frag: Copy {
22 22
    start: u32,
23 23
    endState: u32,
24 24
}
25 25
26 -
record NfaState {
26 +
record NfaState: Copy {
27 27
    trans: *mut [Trans],
28 28
    transCount: u32,
29 29
    stateFirst: *mut [u32],
30 30
    transNext: *mut [u32],
31 31
    stateCount: u32,
test/tests/prog.sha256.rad +1 -1
2 2
//! SHA-256 (single block).
3 3
//! Implement the SHA-256 compression function for a single 512-bit block.
4 4
//! Verify against a known hash of a short message.
5 5
6 6
/// SHA-256 mutable state: hash values and message schedule.
7 -
record Sha256 {
7 +
record Sha256: Copy {
8 8
    h: [u32; 8],
9 9
    w: [u32; 64],
10 10
}
11 11
12 12
/// SHA-256 initial hash values (first 32 bits of fractional parts of square
test/tests/prog.symtab.rad +3 -3
9 9
constant MAX_SCOPES: u32 = 16;
10 10
constant HASH_SIZE: u32 = 64;
11 11
constant NIL: u32 = 0xFFFFFFFF;
12 12
13 13
/// A symbol entry in the table.
14 -
record Symbol {
14 +
record Symbol: Copy {
15 15
    /// Name of the symbol (hash for comparison).
16 16
    nameHash: u32,
17 17
    /// The value associated with this symbol.
18 18
    value: i32,
19 19
    /// Scope depth at which this symbol was defined.
23 23
    /// Previous symbol with the same name (for shadowing).
24 24
    shadow: u32,
25 25
}
26 26
27 27
/// A scope boundary marker.
28 -
record ScopeMarker {
28 +
record ScopeMarker: Copy {
29 29
    /// Number of symbols when scope was entered.
30 30
    symbolCount: u32,
31 31
}
32 32
33 33
/// The symbol table.
34 -
record SymTab {
34 +
record SymTab: Copy {
35 35
    symbols: *mut [Symbol],
36 36
    symbolCount: u32,
37 37
    scopes: *mut [ScopeMarker],
38 38
    scopeDepth: u32,
39 39
    buckets: *mut [u32],
test/tests/prog.tokenizer.rad +7 -7
4 4
//! then parses and evaluates them. Exercises: tagged unions with payloads,
5 5
//! match statements, optionals, if-let, while-let, for-in loops, records
6 6
//! with slice fields, and complex control flow.
7 7
8 8
/// Token types produced by the lexer.
9 -
union Token {
9 +
union Token: Copy {
10 10
    /// Integer literal with its value.
11 11
    Number(i32),
12 12
    /// +
13 13
    Plus,
14 14
    /// -
26 26
    /// Invalid character.
27 27
    Invalid(u8),
28 28
}
29 29
30 30
/// A lexer state over a byte slice.
31 -
record Lexer {
31 +
record Lexer: Copy {
32 32
    source: *[u8],
33 33
    pos: u32,
34 34
}
35 35
36 36
/// A list of tokens with a fixed-size backing store.
37 -
record TokenList {
37 +
record TokenList: Copy {
38 38
    tokens: *mut [Token],
39 39
    count: u32,
40 40
}
41 41
42 42
/// AST node for parsed expressions.
43 -
union Expr {
43 +
union Expr: Copy {
44 44
    Num(i32),
45 45
    BinOp(BinOpData),
46 46
    Neg(u32),
47 47
}
48 48
49 49
/// Binary operation data.
50 -
record BinOpData {
50 +
record BinOpData: Copy {
51 51
    op: u8,
52 52
    left: u32,
53 53
    right: u32,
54 54
}
55 55
56 56
/// Pool of AST nodes.
57 -
record ExprPool {
57 +
record ExprPool: Copy {
58 58
    nodes: *mut [Expr],
59 59
    count: u32,
60 60
}
61 61
62 62
/// Parser state.
63 -
record Parser {
63 +
record Parser: Copy {
64 64
    tokens: *[Token],
65 65
    tokenCount: u32,
66 66
    pos: u32,
67 67
    pool: *mut ExprPool,
68 68
}
test/tests/prog.vm.rad +4 -4
9 9
constant MAX_CODE: u32 = 256;
10 10
constant MAX_LOCALS: u32 = 16;
11 11
constant MAX_FRAMES: u32 = 8;
12 12
13 13
/// Bytecode instructions.
14 -
union Op {
14 +
union Op: Copy {
15 15
    /// Push an immediate value.
16 16
    Push(i32),
17 17
    /// Pop top two, push sum.
18 18
    Add,
19 19
    /// Pop top two, push difference (second - first).
49 49
    /// Halt execution, top of stack is result.
50 50
    Halt,
51 51
}
52 52
53 53
/// A call frame for function calls.
54 -
record Frame {
54 +
record Frame: Copy {
55 55
    returnAddr: u32,
56 56
    localBase: u32,
57 57
}
58 58
59 59
/// The VM state.
60 -
record VM {
60 +
record VM: Copy {
61 61
    code: *[Op],
62 62
    codeLen: u32,
63 63
    stack: *mut [i32],
64 64
    sp: u32,
65 65
    locals: *mut [i32],
67 67
    frameCount: u32,
68 68
    pc: u32,
69 69
}
70 70
71 71
/// VM error types.
72 -
union VmError {
72 +
union VmError: Copy {
73 73
    /// Stack underflow error.
74 74
    StackUnderflow,
75 75
    /// Stack overflow error.
76 76
    StackOverflow,
77 77
    /// Division by zero.
test/tests/ptr.addressof.field.rad +1 -1
1 -
record Point { x: i32, y: i32 }
1 +
record Point: Copy { x: i32, y: i32 }
2 2
3 3
/// Takes the address of a record field.
4 4
fn addressOfField(p: *Point) -> *i32 {
5 5
    return &p.y;
6 6
}
test/tests/ptr.addressof.local.rad +1 -1
1 -
record Point { x: i32, y: i32 }
1 +
record Point: Copy { x: i32, y: i32 }
2 2
3 3
/// Address of a record local (aggregate) - value is already a pointer.
4 4
fn addressOfRecordLocal() -> *Point {
5 5
    let p = Point { x: 1, y: 2 };
6 6
    return &p;
test/tests/ptr.deref.record.rad +1 -1
1 -
record Point { x: i32, y: i32 }
1 +
record Point: Copy { x: i32, y: i32 }
2 2
3 3
/// Dereferences a record pointer and accesses a field.
4 4
fn derefField(p: *Point) -> i32 {
5 5
    return (*p).x;
6 6
}
test/tests/ptr.eq.rad +1 -1
1 1
//! returns: 0
2 2
3 -
record Point {
3 +
record Point: Copy {
4 4
    x: i32,
5 5
    y: i32,
6 6
}
7 7
8 8
// Test that pointer equality uses address comparison, not value comparison.
test/tests/record.access.rad +1 -1
1 1
//! returns: 0
2 2
3 -
record Vector {
3 +
record Vector: Copy {
4 4
    x: i32,
5 5
    y: i32,
6 6
    z: i32,
7 7
    w: i32,
8 8
}
test/tests/record.alignment.rad +1 -1
1 1
//! returns: 0
2 2
//! Test record alignment computation.
3 3
4 -
record R {
4 +
record R: Copy {
5 5
    a: i32,
6 6
    b: i32,
7 7
}
8 8
9 9
@default fn main() -> i32 {
test/tests/record.array.elements.rad +2 -2
1 1
//! returns: 115
2 2
// Testing structs with array elements.
3 3
4 -
record Vector {
4 +
record Vector: Copy {
5 5
    data: [i32; 4],
6 6
}
7 7
8 -
record Matrix {
8 +
record Matrix: Copy {
9 9
    rows: [Vector; 3],
10 10
}
11 11
12 12
fn vectorSum(vec: Vector) -> i32 {
13 13
    let mut sum: i32 = 0;
test/tests/record.assign.blit.rad +1 -1
1 -
record Point { x: i32, y: i32 }
1 +
record Point: Copy { x: i32, y: i32 }
2 2
3 3
fn copy() {
4 4
    let p = Point { x: 1, y: 2 };
5 5
    let mut q = p;
6 6
    set q = p;
test/tests/record.copy.rad +1 -1
1 1
//! returns: 0
2 2
//! Test record value semantics through copying, mutation, and function calls.
3 -
record S {
3 +
record S: Copy {
4 4
    x: i16,
5 5
    y: i16,
6 6
    z: i16,
7 7
}
8 8
test/tests/record.ctor.tuple.rad +1 -1
1 -
record Pair(i32, i32);
1 +
record Pair: Copy(i32, i32);
2 2
3 3
fn make() -> Pair {
4 4
    return Pair(1, 2);
5 5
}
test/tests/record.empty.eq.rad +1 -1
1 1
// Test empty record equality
2 2
3 -
record Empty {}
3 +
record Empty: Copy {}
4 4
5 5
fn emptyEq(a: Empty, b: Empty) -> bool {
6 6
    return a == b;
7 7
}
8 8
test/tests/record.eq.rad +1 -1
1 1
// Holds two integer fields for equality comparisons.
2 -
record Pair {
2 +
record Pair: Copy {
3 3
    left: i32,
4 4
    right: i32,
5 5
}
6 6
7 7
// Returns true when the two records have identical fields.
test/tests/record.field.assign.rad +1 -1
1 1
//! returns: 0
2 2
3 -
record Vector { x: i32, y: i32 }
3 +
record Vector: Copy { x: i32, y: i32 }
4 4
5 5
@default fn main() -> i32 {
6 6
    let mut v: Vector = Vector { x: 3, y: 2 };
7 7
8 8
    set v.x = 40;
test/tests/record.literal.labeled.rad +1 -1
1 -
record Point { x: i32, y: i32 }
1 +
record Point: Copy { x: i32, y: i32 }
2 2
3 3
fn get() -> i32 {
4 4
    let p = Point { x: 1, y: 2 };
5 5
    return p.x;
6 6
}
test/tests/record.mixed.layout.rad +1 -1
1 -
record Mixed { a: i8, b: i32, c: i16 }
1 +
record Mixed: Copy { a: i8, b: i32, c: i16 }
2 2
3 3
fn get() -> i16 {
4 4
    let m = Mixed { a: 1, b: 2, c: 3 };
5 5
    return m.c;
6 6
}
test/tests/record.nested.calls.2.rad +1 -1
1 1
//! returns: 0
2 2
//! Test nested record function calls with scaling and addition.
3 3
4 -
record Point {
4 +
record Point: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 9
fn add(p1: Point, p2: Point) -> Point {
test/tests/record.nested.calls.3.rad +1 -1
1 1
//! returns: 0
2 2
//! Test record passing through multiple nested function calls.
3 3
4 -
record Point {
4 +
record Point: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 9
fn id(x: i32) -> i32 {
test/tests/record.nested.eq.rad +2 -2
1 1
// Test nested aggregate equality
2 2
3 -
record Inner {
3 +
record Inner: Copy {
4 4
    x: i32,
5 5
    y: i32,
6 6
}
7 7
8 -
record Outer {
8 +
record Outer: Copy {
9 9
    a: Inner,
10 10
    b: i32,
11 11
}
12 12
13 13
fn innerEq(a: Inner, b: Inner) -> bool {
test/tests/record.nested.lit.rad +2 -2
1 -
record Inner { a: i32, b: i32 }
2 -
record Outer { inner: Inner, c: i32 }
1 +
record Inner: Copy { a: i32, b: i32 }
2 +
record Outer: Copy { inner: Inner, c: i32 }
3 3
4 4
fn get() -> i32 {
5 5
    let o = Outer { inner: Inner { a: 1, b: 2 }, c: 3 };
6 6
    return o.inner.b;
7 7
}
test/tests/record.param.lit.rad +2 -2
1 1
//! returns: 0
2 2
// Test passing record literals directly into a function.
3 3
4 -
record Vector {
4 +
record Vector: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
    z: i32
8 8
}
9 9
10 -
record Point {
10 +
record Point: Copy {
11 11
    x: i32,
12 12
    y: i32,
13 13
}
14 14
15 15
fn compute(v: Vector, p: Point) -> i32 {
test/tests/record.ptr.access.rad +1 -1
1 1
//! returns: 0
2 2
3 -
record Point {
3 +
record Point: Copy {
4 4
    x: i32,
5 5
    y: i32,
6 6
}
7 7
8 8
@default fn main() -> i32 {
test/tests/record.ptr.mutate.rad +1 -1
1 1
//! returns: 42
2 2
3 -
record Point {
3 +
record Point: Copy {
4 4
    x: i32,
5 5
    y: i32,
6 6
}
7 7
8 8
fn mutate(p: *mut Point) {
test/tests/record.shorthand.rad +2 -2
1 1
//! returns: 1
2 2
//! Test shorthand field syntax in record literals and patterns.
3 3
4 -
record Point {
4 +
record Point: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 -
union Shape {
9 +
union Shape: Copy {
10 10
    circle(i32),
11 11
    rectangle { width: i32, height: i32 },
12 12
}
13 13
14 14
/// Test shorthand record literal construction.
test/tests/record.unlabeled.deref.rad +4 -4
1 1
//! returns: 0
2 2
// Test deref behavior for single-field unlabeled records.
3 3
4 -
record Wrap(i32);
5 -
record WrapBool(bool);
6 -
record WrapU8(u8);
7 -
record WrapU64(u64);
4 +
record Wrap: Copy(i32);
5 +
record WrapBool: Copy(bool);
6 +
record WrapU8: Copy(u8);
7 +
record WrapU64: Copy(u64);
8 8
9 9
fn getInner(w: Wrap) -> i32 {
10 10
    return *w;
11 11
}
12 12
test/tests/record.unlabeled.rad +2 -2
1 1
//! returns: 1
2 2
// TODO: Test destructuring.
3 3
4 -
record S(i32);
5 -
record R(bool, u8);
4 +
record S: Copy(i32);
5 +
record R: Copy(bool, u8);
6 6
7 7
fn passS(s: S) -> S {
8 8
    return s;
9 9
}
10 10
test/tests/reserve.loop.rad +1 -1
1 1
//! returns: 0
2 -
record Pair { a: i32, b: i32 }
2 +
record Pair: Copy { a: i32, b: i32 }
3 3
4 4
@default fn main() -> i32 {
5 5
    let mut total: i32 = 0;
6 6
    let mut i: i32 = 0;
7 7
    while i < 10000 {
test/tests/result.void.success.rad +1 -1
1 1
//! returns: 0
2 2
//! Test that no-result success returns work correctly.
3 3
4 -
union TestError {
4 +
union TestError: Copy {
5 5
    Failed,
6 6
}
7 7
8 8
fn voidSuccess() throws (TestError) {
9 9
    return;
test/tests/set.keyword.rad +1 -1
1 1
//! returns: 0
2 2
//! Test the `set` keyword for assignment statements.
3 3
4 -
record Point {
4 +
record Point: Copy {
5 5
    x: i32,
6 6
    y: i32,
7 7
}
8 8
9 9
@default fn main() -> i32 {
test/tests/slice.append.rad +2 -2
1 1
//! returns: 0
2 2
//! Test slice .append() method with inline allocator.
3 3
4 4
/// Simple bump allocator for testing.
5 -
record Arena {
5 +
record Arena: Copy {
6 6
    data: *mut [u8],
7 7
    offset: u32,
8 8
}
9 9
10 10
fn newArena(data: *mut [u8]) -> Arena {
22 22
23 23
    return base as *mut opaque;
24 24
}
25 25
26 26
/// Allocator record matching the compiler's expected layout.
27 -
record Allocator {
27 +
record Allocator: Copy {
28 28
    func: fn(*mut opaque, u32, u32) -> *mut opaque,
29 29
    ctx: *mut opaque,
30 30
}
31 31
32 32
fn arenaAllocFn(ctx: *mut opaque, size: u32, al: u32) -> *mut opaque {
test/tests/spill.blockarg.clobber.rad +1 -1
31 31
32 32
fn ssig1(x: u32) -> u32 {
33 33
    return rotr(x, 17) ^ rotr(x, 19) ^ (x >> 10);
34 34
}
35 35
36 -
record State {
36 +
record State: Copy {
37 37
    h: [u32; 8],
38 38
    w: [u32; 64],
39 39
}
40 40
41 41
fn prepareSchedule(s: *mut State, block: *[u32]) {
test/tests/spill.loop.rad +1 -1
1 1
//! returns: 0
2 2
//! Test register spilling in a loop with many live values.
3 3
//! Computes record layout from field tags, exercising alignment and offset
4 4
//! calculations that require multiple simultaneously live registers.
5 5
6 -
record Layout {
6 +
record Layout: Copy {
7 7
    size: u32,
8 8
    alignment: u32,
9 9
}
10 10
11 11
fn getLayout(tag: u8) -> Layout {
test/tests/static.record.array.rad +1 -1
1 1
//! returns: 0
2 2
//! Test mutating a static record containing an array.
3 3
4 -
record Record {
4 +
record Record: Copy {
5 5
    values: [i32; 4],
6 6
    bias: i32,
7 7
}
8 8
9 9
static TABLE: Record = Record {
test/tests/static.slice.index.assign.rad +2 -2
1 1
//! returns: 42
2 2
3 -
record Inner {
3 +
record Inner: Copy {
4 4
    value: i32,
5 5
}
6 6
7 -
record Container {
7 +
record Container: Copy {
8 8
    pad: i32,
9 9
    items: [Inner; 3],
10 10
}
11 11
12 12
static container: Container = undefined;
test/tests/static.slice.offset.rad +2 -2
1 1
//! returns: 0
2 2
//! Test slice indexing into a static table with offsets.
3 3
4 -
record Entry {
4 +
record Entry: Copy {
5 5
    a: i32,
6 6
    b: i32,
7 7
}
8 8
9 -
record Table {
9 +
record Table: Copy {
10 10
    scratch: *mut [Entry],
11 11
    entries: *mut [Entry],
12 12
    len: u32,
13 13
}
14 14
test/tests/static.zero.bss.rad +2 -2
1 1
//! returns: 0
2 2
//! rw-data-size: 0
3 3
4 4
/// Static pool used to verify that partially initialized zero data is BSS.
5 -
record Pool {
5 +
record Pool: Copy {
6 6
    /// Undefined slice table.
7 7
    table: [*[u8]; 32],
8 8
    /// Explicitly initialized count.
9 9
    count: u32,
10 10
}
11 11
12 12
/// Padded record used to verify that zero fields plus undefined padding are BSS.
13 -
record Padded {
13 +
record Padded: Copy {
14 14
    /// Leading byte.
15 15
    tag: u8,
16 16
    /// Field that forces padding after `tag`.
17 17
    value: u32,
18 18
}
test/tests/switch.blockargs.clobber.rad +1 -1
9 9
//! In the isel, `emitBlockArgs` for case 0 writes `1` (the merge arg) to the
10 10
//! merge block's parameter register.  If the register allocator assigned that
11 11
//! parameter register to the same physical register as the switch value, the
12 12
//! tag is clobbered before subsequent case comparisons run.
13 13
14 -
union Val {
14 +
union Val: Copy {
15 15
    none,
16 16
    empty,
17 17
    data(i32),
18 18
}
19 19
test/tests/trait.aggregate.ret.rad +3 -3
2 2
//! Test trait methods returning aggregate types.
3 3
//!
4 4
//! Exercises: trait methods that return structs (both small and larger
5 5
//! than pointer size) and optionals via v-table dispatch.
6 6
7 -
record Point {
7 +
record Point: Copy {
8 8
    x: i32,
9 9
    y: i32,
10 10
}
11 11
12 -
record Vec3 {
12 +
record Vec3: Copy {
13 13
    x: i32,
14 14
    y: i32,
15 15
    z: i32,
16 16
}
17 17
19 19
    fn (*Geometry) origin() -> Point;
20 20
    fn (*Geometry) center() -> Vec3;
21 21
    fn (*Geometry) maybe() -> ?i32;
22 22
}
23 23
24 -
record Circle {
24 +
record Circle: Copy {
25 25
    cx: i32,
26 26
    cy: i32,
27 27
    radius: i32,
28 28
}
29 29
test/tests/trait.array.optional.rad +2 -2
2 2
//! Test trait objects stored in arrays and used as optional values.
3 3
//!
4 4
//! Exercises: arrays of trait objects dispatched in loops,
5 5
//! and optional trait object values.
6 6
7 -
record Adder {
7 +
record Adder: Copy {
8 8
    n: i32,
9 9
}
10 10
11 -
record Multiplier {
11 +
record Multiplier: Copy {
12 12
    n: i32,
13 13
}
14 14
15 15
trait Transform {
16 16
    fn (*Transform) apply(x: i32) -> i32;
test/tests/trait.basic.rad +1 -1
1 1
//! returns: 0
2 2
//! Basic trait object dispatch test.
3 -
record Counter {
3 +
record Counter: Copy {
4 4
    value: i32,
5 5
}
6 6
7 7
trait Adder {
8 8
    fn (*mut Adder) add(n: i32) -> i32;
test/tests/trait.control.flow.rad +1 -1
3 3
//!
4 4
//! Exercises: trait method calls inside loops and conditionals,
5 5
//! verifying that vtable dispatch works correctly when interleaved
6 6
//! with branching and iteration.
7 7
8 -
record Counter {
8 +
record Counter: Copy {
9 9
    value: i32,
10 10
}
11 11
12 12
trait Stepper {
13 13
    fn (*mut Stepper) step() -> i32;
test/tests/trait.dispatch.rad +1 -1
1 -
record Acc {
1 +
record Acc: Copy {
2 2
    n: i32,
3 3
}
4 4
5 5
trait Ops {
6 6
    fn (*Ops) get() -> i32;
test/tests/trait.fn.param.rad +2 -2
2 2
//! Test passing trait objects as function parameters.
3 3
//!
4 4
//! Exercises: trait objects passed to non-method functions, including
5 5
//! both mutable and immutable trait object pointers as arguments.
6 6
7 -
record Circle {
7 +
record Circle: Copy {
8 8
    radius: i32,
9 9
}
10 10
11 -
record Square {
11 +
record Square: Copy {
12 12
    side: i32,
13 13
}
14 14
15 15
trait Shape {
16 16
    fn (*Shape) area() -> i32;
test/tests/trait.multiple.methods.rad +1 -1
3 3
//!
4 4
//! Exercises: a trait declaring multiple methods with void, bool, and
5 5
//! integer return types. Verifies vtable layout with more than one
6 6
//! entry and correct dispatch for each method.
7 7
8 -
record Accumulator {
8 +
record Accumulator: Copy {
9 9
    total: i32,
10 10
}
11 11
12 12
trait Collector {
13 13
    fn (*mut Collector) add(n: i32) -> i32;
test/tests/trait.multiple.traits.rad +1 -1
3 3
//!
4 4
//! Exercises: a single concrete type that provides instances for
5 5
//! two different traits. Each trait object dispatches independently
6 6
//! through its own vtable.
7 7
8 -
record Counter {
8 +
record Counter: Copy {
9 9
    value: i32,
10 10
}
11 11
12 12
trait Incrementable {
13 13
    fn (*mut Incrementable) inc() -> i32;
test/tests/trait.multiple.types.rad +2 -2
3 3
//!
4 4
//! Exercises: two different concrete types implementing the same trait,
5 5
//! coerced to the same trait object type. Also tests immutable `*Trait`
6 6
//! receivers. Verifies each type dispatches through its own vtable.
7 7
8 -
record Dog {
8 +
record Dog: Copy {
9 9
    age: i32,
10 10
}
11 11
12 -
record Cat {
12 +
record Cat: Copy {
13 13
    lives: i32,
14 14
}
15 15
16 16
trait Speaker {
17 17
    fn (*Speaker) speak() -> i32;
test/tests/trait.object.rad +1 -1
1 -
record Counter {
1 +
record Counter: Copy {
2 2
    value: i32,
3 3
}
4 4
5 5
trait Adder {
6 6
    fn (*mut Adder) add(n: i32) -> i32;
test/tests/trait.supertrait.forward.rad +1 -1
7 7
8 8
trait Parent {
9 9
    fn (*Parent) parent() -> i32;
10 10
}
11 11
12 -
record Value {
12 +
record Value: Copy {
13 13
    n: i32,
14 14
}
15 15
16 16
instance Parent for Value {
17 17
    fn (self: *Value) parent() -> i32 {
test/tests/trait.supertrait.rad +1 -1
18 18
19 19
trait ReadWriter: Reader + Writer {
20 20
    fn (*mut ReadWriter) flush() -> i32;
21 21
}
22 22
23 -
record Socket {
23 +
record Socket: Copy {
24 24
    rbuf: [u8; 32],
25 25
    rpos: i32,
26 26
    rlen: i32,
27 27
    wbuf: [u8; 32],
28 28
    wpos: i32,
test/tests/trait.throws.rad +2 -2
1 1
//! returns: 0
2 2
//! Test trait methods with throws clauses.
3 3
4 -
union ParseError {
4 +
union ParseError: Copy {
5 5
    InvalidInput,
6 6
    Overflow,
7 7
}
8 8
9 -
record StrictParser {
9 +
record StrictParser: Copy {
10 10
    limit: i32,
11 11
}
12 12
13 13
trait Parser {
14 14
    fn (*Parser) parse(n: i32) -> i32 throws (ParseError);
test/tests/trait.writer.rad +2 -2
10 10
    fn (*mut Writer) write(data: *[u8]) -> i32;
11 11
    fn (*Writer) total() -> i32;
12 12
}
13 13
14 14
/// Writes bytes into a fixed-size buffer.
15 -
record BufferWriter {
15 +
record BufferWriter: Copy {
16 16
    buf: [u8; 64],
17 17
    pos: i32,
18 18
}
19 19
20 20
instance Writer for BufferWriter {
35 35
        return w.pos;
36 36
    }
37 37
}
38 38
39 39
/// Counts bytes written through it, forwarding to an inner writer.
40 -
record CountingWriter {
40 +
record CountingWriter: Copy {
41 41
    inner: *mut opaque Writer,
42 42
    count: i32,
43 43
}
44 44
45 45
instance Writer for CountingWriter {
test/tests/try.basic.rad +1 -1
1 1
/// Error type for fallible functions.
2 -
union Error { Boom }
2 +
union Error: Copy { Boom }
3 3
4 4
/// Return a value or throw an error based on the flag.
5 5
fn fallible(flag: bool) -> i32 throws (Error) {
6 6
    if flag {
7 7
        throw Error::Boom();
test/tests/try.catch.rad +1 -1
1 1
/// Ensure `try` with catch block diverges from the error path.
2 -
union Error { Boom }
2 +
union Error: Copy { Boom }
3 3
4 4
fn fallible(flag: bool) -> i32 throws (Error) {
5 5
    if flag {
6 6
        throw Error::Boom();
7 7
    }
test/tests/try.optional.rad +1 -1
1 1
/// Error type for fallible functions.
2 -
union Error { Boom }
2 +
union Error: Copy { Boom }
3 3
4 4
/// Return a value or throw an error based on the flag.
5 5
fn fallible(flag: bool) -> i32 throws (Error) {
6 6
    if flag {
7 7
        throw Error::Boom();
test/tests/try.panic.rad +1 -1
1 1
/// Error type for fallible functions.
2 -
union Error { Boom }
2 +
union Error: Copy { Boom }
3 3
4 4
/// Return a value or throw an error based on the flag.
5 5
fn fallible(flag: bool) -> i32 throws (Error) {
6 6
    if flag {
7 7
        throw Error::Boom();
test/tests/undefined.aggregate.rad +1 -1
1 1
/// Test lowering of undefined for aggregate types.
2 -
record Point { x: i32, y: i32 }
2 +
record Point: Copy { x: i32, y: i32 }
3 3
4 4
fn test() -> i32 {
5 5
    let p: Point = undefined;
6 6
    return p.x;
7 7
}
test/tests/undefined.record.field.rad +3 -3
8 8
///
9 9
/// The fix skips stores for `undefined` fields entirely, leaving the
10 10
/// memory uninitialised.  Covers both named-field syntax (lowerRecordFields)
11 11
/// and positional constructor syntax (lowerRecordCtor).
12 12
13 -
record Small {
13 +
record Small: Copy {
14 14
    x: i32,
15 15
    y: i32,
16 16
}
17 17
18 -
record WithArray {
18 +
record WithArray: Copy {
19 19
    data: [i32; 4],
20 20
    len: i32,
21 21
}
22 22
23 23
/// Construct a record with one field `undefined` (named-field syntax).
38 38
fn fullInit() -> i32 {
39 39
    let s = Small { x: 10, y: 20 };
40 40
    return s.x + s.y;
41 41
}
42 42
43 -
union Tagged {
43 +
union Tagged: Copy {
44 44
    A { data: [i32; 4], tag: i32 },
45 45
    B,
46 46
}
47 47
48 48
/// Union variant with record payload containing an `undefined` field.
test/tests/union-tag.rad +1 -1
1 1
//! returns: 0
2 2
//! Test that union variant tags are stored correctly for unions with many variants.
3 3
4 -
union BigUnion {
4 +
union BigUnion: Copy {
5 5
    V0,
6 6
    V1,
7 7
    V2,
8 8
    V3,
9 9
    V4,
test/tests/union.bitfield.rad +1 -1
1 1
//! returns: 42
2 2
3 -
union Attribute {
3 +
union Attribute: Copy {
4 4
    None = 0b0,
5 5
    Export = 0b10,
6 6
    Default = 0b100,
7 7
    Extern = 0b1000,
8 8
    Test = 0b10000,
test/tests/union.ctor.rad +2 -2
1 1
/// Union with tag-only variants.
2 -
union Color { Red, Green, Blue }
2 +
union Color: Copy { Red, Green, Blue }
3 3
4 4
/// Union with and without payload variants.
5 -
union MaybeInt { None, Some(i32) }
5 +
union MaybeInt: Copy { None, Some(i32) }
6 6
7 7
/// Builds a tag-only union variant.
8 8
fn makeRed() -> Color {
9 9
    return Color::Red;
10 10
}
test/tests/union.discriminant.cast.rad +1 -1
1 1
//! returns: 0
2 2
//! Casting a void-union variant to `i32` should produce its explicit tag value.
3 3
4 -
union U {
4 +
union U: Copy {
5 5
    A = 7,
6 6
    B = 42,
7 7
    C = 255,
8 8
}
9 9
test/tests/union.edge.case.2.rad +1 -1
1 1
//! returns: 0
2 2
3 -
union NodeValue {
3 +
union NodeValue: Copy {
4 4
    Placeholder,
5 5
    Nil,
6 6
    Bool(bool),
7 7
}
8 8
test/tests/union.edge.case.3.rad +2 -2
1 1
//! returns: 0
2 2
//! Test union match through pointer dereference.
3 3
4 -
union Node {
4 +
union Node: Copy {
5 5
    Placeholder(u8),
6 6
    Nil(u8),
7 7
    Bool(bool),
8 8
}
9 9
10 -
record Parser {
10 +
record Parser: Copy {
11 11
    root: Node,
12 12
}
13 13
14 14
fn node(p: *mut Parser, value: Node) -> *Node {
15 15
    set p.root = value;
test/tests/union.eq.rad +4 -4
1 1
/// Void union - only tag comparison needed.
2 -
union Color { Red, Green, Blue }
2 +
union Color: Copy { Red, Green, Blue }
3 3
4 4
/// Union with one payload variant.
5 -
union MaybeInt { None, Some(i32) }
5 +
union MaybeInt: Copy { None, Some(i32) }
6 6
7 7
/// Union with multiple different payload types.
8 -
union Value { Empty, Int(i32), Byte(u8) }
8 +
union Value: Copy { Empty, Int(i32), Byte(u8) }
9 9
10 10
/// Union with multi-field record payload.
11 -
union Shape { None, Point { x: i32, y: i32 } }
11 +
union Shape: Copy { None, Point { x: i32, y: i32 } }
12 12
13 13
/// Compare void unions (tags only).
14 14
fn colorEq(a: Color, b: Color) -> bool {
15 15
    return a == b;
16 16
}
test/tests/union.eq.void.ctor.rad +1 -1
1 1
//! Regression test: comparing a void union variable against a constructor
2 2
//! literal must compare tag scalars directly, not load through a pointer.
3 3
4 -
union Op { Add, Sub, Mul }
4 +
union Op: Copy { Add, Sub, Mul }
5 5
6 6
/// Compare void union against constructor literal.
7 7
fn isAdd(op: Op) -> bool {
8 8
    return op == Op::Add;
9 9
}
test/tests/union.eq.void.rad +1 -1
1 1
/// Void union - only tag comparison needed.
2 -
union Color { Red, Green, Blue }
2 +
union Color: Copy { Red, Green, Blue }
3 3
4 4
/// Compare void unions (tags only).
5 5
fn colorEq(a: Color, b: Color) -> bool {
6 6
    return a == b;
7 7
}
test/tests/union.match.bind.rad +1 -1
1 1
/// Simple union for testing payload binding.
2 -
union Option { None, Some(u32) }
2 +
union Option: Copy { None, Some(u32) }
3 3
4 4
/// Extract payload from a union variant.
5 5
fn unwrap(x: Option) -> u32 {
6 6
    match x {
7 7
        case Option::None => return 0,
test/tests/union.match.ref.rad +2 -2
1 1
/// Void union.
2 -
union Color { Red, Green, Blue }
2 +
union Color: Copy { Red, Green, Blue }
3 3
4 4
/// Non-void union for testing ref matching.
5 -
union Option { None, Some(u32) }
5 +
union Option: Copy { None, Some(u32) }
6 6
7 7
/// Match on a void union reference.
8 8
fn matchColorRef(ptr: *Color) -> u32 {
9 9
    match ptr {
10 10
        case Color::Red => return 0,
test/tests/union.match.tag.rad +2 -2
1 1
/// Void union.
2 -
union Color { Red, Green, Blue }
2 +
union Color: Copy { Red, Green, Blue }
3 3
4 4
/// Non-void union for testing tag-only matching.
5 -
union Option { None, Some(u32) }
5 +
union Option: Copy { None, Some(u32) }
6 6
7 7
/// Match on void union tag.
8 8
fn matchColor(c: Color) -> i32 {
9 9
    match c {
10 10
        case Color::Red => return 0,
test/tests/union.mixed.assign.rad +2 -2
1 1
//! returns: 0
2 2
//! Test union variant assignment and if-let-case matching.
3 3
4 -
union Mixed {
4 +
union Mixed: Copy {
5 5
    Payload(i32),
6 6
    Standalone,
7 7
    AnotherPayload(bool),
8 8
    Final,
9 9
}
10 10
11 -
record Holder {
11 +
record Holder: Copy {
12 12
    value: Mixed,
13 13
}
14 14
15 15
fn storePayload(holder: *mut Holder, value: i32) {
16 16
    set holder.value = Mixed::Payload(value);
test/tests/union.payload.mutref.rad +3 -3
1 1
//! returns: 0
2 2
//! Test accessing and modifying union payload through mutable reference.
3 3
//! This mirrors the pattern in createBlockParam where we match on
4 4
//! &mut blk.sealState and push to incompleteVars.
5 5
6 -
record U32List {
6 +
record U32List: Copy {
7 7
    data: *mut [u32],
8 8
    len: u32,
9 9
}
10 10
11 -
union Sealed {
11 +
union Sealed: Copy {
12 12
    No { items: U32List },
13 13
    Yes,
14 14
}
15 15
16 -
record Block {
16 +
record Block: Copy {
17 17
    padding1: i32,
18 18
    padding2: i32,
19 19
    state: Sealed,
20 20
}
21 21
test/tests/union.payload.rad +1 -1
1 1
//! returns: 0
2 2
//! Test unions with payloads.
3 3
4 -
union Option { None, Some(i32) }
4 +
union Option: Copy { None, Some(i32) }
5 5
6 6
@default fn main() -> i32 {
7 7
    let none: Option = Option::None;
8 8
    let some: Option = Option::Some(42);
9 9
test/tests/union.payload.record.eq.rad +2 -2
1 1
// Test union equality with record payloads
2 2
3 -
record Point {
3 +
record Point: Copy {
4 4
    x: i32,
5 5
    y: i32,
6 6
}
7 7
8 -
union MaybePoint {
8 +
union MaybePoint: Copy {
9 9
    None,
10 10
    Some(Point),
11 11
}
12 12
13 13
fn maybePointEq(a: MaybePoint, b: MaybePoint) -> bool {
test/tests/union.record.forward.rad +2 -2
1 1
//! returns: 0
2 2
//! Test union containing large record payload.
3 3
4 -
union Wrapper {
4 +
union Wrapper: Copy {
5 5
    Data(Payload),
6 6
}
7 7
8 -
record Payload {
8 +
record Payload: Copy {
9 9
    f0: u32,
10 10
    f1: u32,
11 11
    f2: u32,
12 12
    f3: u32,
13 13
    f4: u32,
test/tests/union.record.literal.rad +1 -1
1 1
/// Union with record payload variant.
2 -
union Expr {
2 +
union Expr: Copy {
3 3
    Null,
4 4
    Pair { first: i32, second: i32 },
5 5
}
6 6
7 7
/// Create a Pair variant using record literal syntax.
test/tests/union.variant.access.rad +2 -2
1 1
/// Union with tag-only variants.
2 -
union Color { Red, Green, Blue }
2 +
union Color: Copy { Red, Green, Blue }
3 3
4 4
/// Union with payload and tag-only variants.
5 -
union Option { None, Some(i32) }
5 +
union Option: Copy { None, Some(i32) }
6 6
7 7
/// Accesses a tag-only union variant.
8 8
fn makeRed() -> Color {
9 9
    return Color::Red;
10 10
}
test/tests/union.void.match.rad +1 -1
1 1
//! returns: 0
2 2
3 -
union Color {
3 +
union Color: Copy {
4 4
    Red,
5 5
    Green,
6 6
    Blue,
7 7
}
8 8
test/tests/union.void.rad +1 -1
1 1
//! returns: 0
2 2
//! Test void unions.
3 3
//! These are passed by value as the tag itself.
4 4
5 -
union Color { Red, Green, Blue }
5 +
union Color: Copy { Red, Green, Blue }
6 6
7 7
@default fn main() -> i32 {
8 8
    let red: Color = Color::Red;
9 9
    let green: Color = Color::Green;
10 10
    let blue: Color = Color::Blue;
test/tests/var.infer.rad +1 -1
1 1
//! returns: 0
2 2
3 -
record Pair {
3 +
record Pair: Copy {
4 4
    left: bool,
5 5
    right: bool,
6 6
}
7 7
8 8
fn alwaysTrue() -> bool {
test/tests/void.throw.rad +1 -1
1 1
/// Throwing no-result function without explicit return should return success implicitly.
2 -
union Error { Boom }
2 +
union Error: Copy { Boom }
3 3
4 4
fn fallible(flag: bool) throws (Error) {
5 5
    if flag {
6 6
        throw Error::Boom();
7 7
    }
vim/radiance.vim +2 -2
16 16
17 17
" Keywords
18 18
syntax keyword radianceKeyword mod fn return if else while true false and or not case align static
19 19
syntax keyword radianceKeyword export break continue use loop in for match nil undefined
20 20
syntax keyword radianceKeyword let mut set as register device constant log record union trait instance
21 -
syntax keyword radianceKeyword throws throw try catch panic assert super
22 -
syntax keyword radianceType i8 i16 i32 i64 u8 u16 u32 u64 f32 void bool bit opaque
21 +
syntax keyword radianceKeyword throws throw try catch panic assert super unsafe
22 +
syntax keyword radianceType i8 i16 i32 i64 u8 u16 u32 u64 f32 void bool bit opaque Copy Linear
23 23
24 24
" Double-quoted strings
25 25
syntax region radianceString start=/"/ skip=/\\"/ end=/"/ contains=radianceEscape
26 26
" Characters
27 27
syntax region radianceCharacter start=/'/ skip=/\\'|\\\\/ end=/'/ oneline contains=radianceEscape