1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//! The interface table: which interfaces this contract implements, collected
//! by the linker from its `#[contract]` impl blocks.
//!
//! Every `#[contract] impl Trait for T` (and every bare `#[contract] impl T`)
//! expands to one 8-byte [`InterfaceId`] record via
//! [`__interface_record!`](crate::__interface_record). [`implements!`](crate::implements)
//! answers whether a given id is among them. This is what `thruput-erc165-if`
//! builds `supports_interface` on: the claim is read off the impls that
//! actually linked, so there is no list to maintain and nothing to get wrong.
//!
//! # Layout and cost
//!
//! On the guest the records use the entrypoint table's shape: `#[used]`
//! statics in the `thruput_rv32_interfaces` input section, which the
//! runtime linker script `KEEP`s and brackets as its own output section.
//! Whether that section reaches the deployed image is the lowerer's call,
//! made the way it already drops the raw spec section: the reader below
//! touches a one-word anchor in `thruput_rv32_interfaces_anchor`, an
//! ordinary GC-able section that survives the link only if the table reader
//! behind [`implements!`](crate::implements) was instantiated. The lowerer copies the table into VM memory only when
//! the anchor section is present. A contract with no ERC-165 impl therefore
//! ships an image byte-identical to one built without this module; one with
//! an impl pays four bytes of anchor plus 8 per impl block, plus the scan.
//!
//! # What counts as "this contract"
//!
//! The unit is the contract image, not the storage struct. A crate with
//! `impl X for A` and `impl Y for B` links both into one image whose
//! dispatch table answers to both interfaces at one address, so its table
//! holds both ids and `supports_interface` says yes to both — which is the
//! truth ERC-165 asks about. On the guest the table is simply the whole
//! image. On the host, where one test process holds many contracts, the
//! records go through a `linkme` slice keyed by the package that expanded
//! them, name and version both, so [`implements!`](crate::implements) from
//! inside a contract crate sees every impl block of that crate — `A`'s and
//! `B`'s alike, the same as the guest — while another contract crate's
//! records, or another version of this one (a migration test may link two),
//! stay apart. That is the scope the entrypoint guards and the mock
//! registry already use for "one contract".
use crateInterfaceId;
/// One host-side record: the package (name and version) whose `#[contract]`
/// impl block expanded it, and the interface that block implements.
pub static HOST_RECORDS: ;
/// True if the contract identified by `package`/`version` carries a
/// `#[contract]` impl of the interface identified by `interface_id`.
///
/// [`implements!`](crate::implements) supplies the caller crate's own
/// package name and version, which is the form contracts use. On the guest
/// there is one contract per image, so the scope is not consulted and the
/// table is scanned whole; on the host the records are filtered to that
/// package. Neither touches storage.
/// True if the contract identified by `package`/`version` carries a
/// `#[contract]` impl of the interface identified by `interface_id`.
///
/// [`implements!`](crate::implements) supplies the caller crate's own
/// package name and version, which is the form contracts use. On the guest
/// there is one contract per image, so the scope is not consulted and the
/// table is scanned whole; on the host the records are filtered to that
/// package. Neither touches storage.
/// True if this contract carries a `#[contract]` impl of the interface
/// identified by the given [`InterfaceId`].
///
/// Expands to [`interface_table::implements_in`](crate::interface_table::implements_in)
/// scoped to the invoking crate's package name and version, so it must be
/// invoked from the contract crate itself — which is where a
/// `supports_interface` body lives:
///
/// ```ignore
/// fn supports_interface(id: InterfaceId) -> bool {
/// thruput_sdk::implements!(id)
/// }
/// ```
/// Register one interface-table record for the invoking crate. Emitted by
/// `#[contract]` for every impl block; not for hand-written use.