Commit d24fb18
## Summary
A service reference is represented by the principal of its canister, so
it is natural to use one wherever a `principal` is expected. This adds
the subtyping rule `service <actortype> <: principal` and its coercion.
Long discussed in caffeinelabs/motoko#2264 (rossberg, chenyan-dfinity, and
nomeata converged on it being reasonable at the Candid level).
This PR also cuts the corresponding **`candid` 0.10.32** release (see
*Release* below).
## Spec (`spec/Candid.md`)
Modelled exactly on the existing `nat <: int` rule — an unconditional,
premise-free widening in the *Primitive Types* subsections (`principal`
is itself primitive), with a value-preserving coercion:
- subtyping: `service <actortype> <: principal`
- coercion: `service <text> : service <actortype> ~> principal <text> :
principal`
It is a **conservative extension**: it only enlarges `<:` (no existing
judgment is lost), and it is decode-sound because a service reference is
*already* wire-encoded exactly like a principal — `M`/`R` are
byte-identical (`i8(0)` opaque; `i8(1) M(v* : vec nat8)` transparent) —
so the coercion is the identity on the reference. **No change to the
binary format** (`T`/`M`/`R`). The reverse (`principal <: service`) is
intentionally not added.
## Reference implementation (`rust/candid`)
- `types/subtype.rs`: `(Service(_), Principal)` accepted in both
matchers, unconditional (like `(Nat, Int)`).
- `de.rs`: `deserialize_principal` now matches the wire type directly
against `principal` or `service <…>` (instead of asserting `wire ==
principal`), so a service reference decodes at `principal` (identical
`PrincipalBytes`). It deliberately does *not* use the general
`check_subtype()`, which would also admit `empty` (bottom) `<:
principal` and let a payload be decoded as a principal from arbitrary
trailing bytes.
## Tests
- `test/subtypes.test.did`: `service {}` and `service {m:()->()}` `<:
principal`; `principal` `</:` `service {}`.
- `test/reference.test.did`: a service reference *value* decodes at
`principal` (empty & non-empty); the reverse was already rejected.
Both were confirmed to fail without the corresponding checker/decoder
change.
## Metatheory (`coq/`)
- `MiniCandid.v`: extended with `ServiceT`/`PrincipalT` +
`ServiceV`/`PrincipalV`, the rule `ServiceT <: PrincipalT` (modelled on
`NatT <: IntT`), and the coercion. `soundness` and
`transitive_coherence` re-verify with the new constructors — the rule is
machine-checked sound.
- Build: re-pinned `coq/nix` to a modern nixpkgs that provides
`coq_8_18` (the `nixos-20.09` niv pin no longer evaluates; the default
`coq` is now Rocq 9.x, which renamed `Coq.*`→`Stdlib.*` and moved
`FunInd`). Removed the now-unused niv machinery (`sources.{nix,json}`)
and pinned the `fetchTarball` NAR hash. `nix-build -A theories coq` is
green in CI.
## Release (`candid` / `candid_derive` 0.10.32)
This PR also cuts the `candid` release that carries the change:
- Bump `candid` and `candid_derive` `0.10.31 → 0.10.32` (kept in
lockstep per the "sync with the version" comments) and the internal
`candid_derive` dependency pin; refresh the workspace and `rust/bench`
lockfiles.
- `CHANGELOG.md`: new dated section documenting `service <: principal`
as a non-breaking change.
## Follow-ups (not in this PR)
- Porting the Coq development to Rocq 9.1.1 (separate issue).
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: mraszyk <31483726+mraszyk@users.noreply.github.com>
Co-authored-by: Linwei Shang <linwei.shang@dfinity.org>
1 parent 294ec65 commit d24fb18
14 files changed
Lines changed: 185 additions & 236 deletions
File tree
- coq
- nix
- rust
- bench
- candid_derive
- candid
- src
- types
- spec
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
3 | 10 | | |
4 | 11 | | |
5 | 12 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
| 59 | + | |
| 60 | + | |
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
| |||
91 | 95 | | |
92 | 96 | | |
93 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
94 | 104 | | |
95 | 105 | | |
96 | 106 | | |
| |||
105 | 115 | | |
106 | 116 | | |
107 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
108 | 121 | | |
109 | 122 | | |
110 | 123 | | |
| |||
179 | 192 | | |
180 | 193 | | |
181 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
182 | 198 | | |
183 | 199 | | |
184 | 200 | | |
| |||
195 | 211 | | |
196 | 212 | | |
197 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
198 | 217 | | |
199 | 218 | | |
200 | 219 | | |
| |||
237 | 256 | | |
238 | 257 | | |
239 | 258 | | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
240 | 269 | | |
241 | 270 | | |
242 | 271 | | |
| |||
254 | 283 | | |
255 | 284 | | |
256 | 285 | | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
257 | 289 | | |
258 | 290 | | |
259 | 291 | | |
| |||
293 | 325 | | |
294 | 326 | | |
295 | 327 | | |
296 | | - | |
| 328 | + | |
297 | 329 | | |
298 | 330 | | |
299 | 331 | | |
| |||
319 | 351 | | |
320 | 352 | | |
321 | 353 | | |
| 354 | + | |
| 355 | + | |
322 | 356 | | |
323 | 357 | | |
324 | 358 | | |
| |||
338 | 372 | | |
339 | 373 | | |
340 | 374 | | |
| 375 | + | |
| 376 | + | |
341 | 377 | | |
342 | 378 | | |
343 | 379 | | |
| |||
370 | 406 | | |
371 | 407 | | |
372 | 408 | | |
| 409 | + | |
| 410 | + | |
373 | 411 | | |
374 | 412 | | |
375 | 413 | | |
| |||
405 | 443 | | |
406 | 444 | | |
407 | 445 | | |
408 | | - | |
| 446 | + | |
409 | 447 | | |
410 | 448 | | |
411 | 449 | | |
412 | 450 | | |
413 | 451 | | |
414 | 452 | | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
415 | 497 | | |
416 | 498 | | |
417 | 499 | | |
| |||
737 | 819 | | |
738 | 820 | | |
739 | 821 | | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
740 | 826 | | |
741 | 827 | | |
742 | 828 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | 3 | | |
6 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
7 | 16 | | |
8 | 17 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | 18 | | |
13 | 19 | | |
14 | 20 | | |
15 | 21 | | |
16 | 22 | | |
17 | 23 | | |
18 | | - | |
19 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
| |||
31 | 38 | | |
32 | 39 | | |
33 | 40 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | 41 | | |
50 | 42 | | |
51 | 43 | | |
52 | 44 | | |
53 | | - | |
54 | | - | |
| 45 | + | |
This file was deleted.
0 commit comments