test/shared/support.rad 1.7 KiB raw
1
//! Shared dependency with private writable state.
2
3
/// Value read by dependent packages.
4
export unsafe static value: i32 = 7;
5
6
/// Large private allocation before the final zero-initialized scalar.
7
unsafe static padding: [u8; 8192] = [0; 8192];
8
/// Zero-initialized value at a large package offset.
9
unsafe static tail: i32 = 0;
10
11
/// Read this domain's value.
12
export fn read() -> i32 {
13
    unsafe {
14
        set padding[8191] = 0;
15
        return value + tail;
16
    }
17
}
18
19
/// Value with a public nominal identity and one trait implementation.
20
export record Number: Copy {
21
    /// Value read through the trait.
22
    value: i32,
23
    /// Second word that requires a caller-provided return buffer.
24
    extra: u64,
25
}
26
27
/// Read access to a value.
28
export trait Reading {
29
    /// Read the receiver's value.
30
    fn (&Reading) get() -> i32;
31
}
32
33
/// Reading access to a Number.
34
instance Reading for Number {
35
    /// Read the receiver's value.
36
    fn (self: &Number) get() -> i32 {
37
        return self.value;
38
    }
39
}
40
41
/// Preserve the input storage region in the result.
42
export fn borrow(value: &'a Number) -> &'a Number {
43
    return value;
44
}
45
46
/// Return a record through the caller's output buffer.
47
export fn copied(value: &Number) -> Number {
48
    return *value;
49
}
50
51
/// Dispatch through a borrowed trait supplied by the caller.
52
export fn reading(value: &opaque Reading) -> i32 {
53
    return value.get();
54
}
55
56
/// A borrowed value returned through the caller's storage.
57
export record Reference['r]: Copy {
58
    /// Storage borrowed from the input value.
59
    value: &'r Number,
60
}
61
62
/// Transfer the input borrow into the caller's result buffer.
63
export fn referenced(value: &'r Number) -> Reference['r] {
64
    return Reference { value };
65
}