Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coq: Model subtype check on decoding, IDL-Soundness, Transitive Coherence #171

Merged
merged 23 commits into from
Apr 23, 2021

Conversation

nomeata
Copy link
Collaborator

@nomeata nomeata commented Jan 27, 2021

A revamp of the Coq development:

  • It models the subtype-checking on decoding (Spec: Do a subtyping check when decoding #168). Looks good
  • It connects MiniCandid to the IDL-Soundness theorem. The main work here is the subtyping-compositoinaliy lemma.
    If t1 <: t2 and s1 in t1 <: s2 in t2 then s1 <: s2.
    
    With this in place, instantiating the “canonical subtyping” proof there works nice.
  • It proofs transitive coherence with regard to the relaxed relation as per Meta-Theory: Clarify transitive coherence #173
  • Mild coqdoc’ifiacation. I’d like to eventually render these to HTML and host them somewhere.
    It’s very annoying that Github Action artifacts, even if they are HTML, are not directly accessible with the browser.
    Maybe setup Github pages?

It is still a Mini-Candid with a limited set of types, but I think it has all the interesting ones to cover the corner cases. Even adding vectors adds a lot of technical noise with little additional insight (see #154.)

nomeata and others added 17 commits January 20, 2021 15:59
this introduces a subtyping check

 * before even starting to decode
 * when decoding `opt` values.

An implementation can probably pre-compute something at first, and then
at each `opt` occurrence quickly look which way to go…

With these changes, the coercion relation never fails on well-typed
inputs, and it is anyways right-unique.
I am wondering if it makes sense to rewrite it as a family of functions,
indexed by the input and output types (like Andreas had it originally).
Co-authored-by: Andreas Rossberg <[email protected]>
this models #168 in Coq. So far so good.

The crucial bit will be connecting this to the IDL Soundness
formalization. That requires
 * adding a function reference type
 * proving a subtyping-compositionality lemma, namely
   ```
   If t1 <: t2 and s1 in t1 <: s2 in t2 then s1 <: s2.
   ```

That will be no small untertaking. I will probably remove the other
variants in the Coq file then?
@nomeata nomeata changed the title Coq: Model subtype check on decoding Coq: Model subtype check on decoding, IDL-Soundness, Transitive Coherence Jan 30, 2021
@nomeata nomeata marked this pull request as ready for review January 30, 2021 10:16
@nomeata
Copy link
Collaborator Author

nomeata commented Jan 30, 2021

(Should be merged after #168 hits master)

Copy link
Contributor

@rossberg rossberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool stuff. I had to realise far behind the curve my Coq expertise is, so I probably only have superficial comments on definitions and theorems.

(* We’d prefer the equation from [coerce_consituent_eq] below,
but that will not satisfy the termination checker,
so let’s repeat all the above ruls for OptT again.
*)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm confused why this does not need a case for e.g. OptT ReservedT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which case exactly are you missing? (coerce has three parameters)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess ResV, ResT, OptT ResT? (I was also wondering about OptT NullT, but I suppose that's covered by the default.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is handled by the final NullV producing catch-all. Remember that the constituent-to-opt rule only applies to t <: opt t if not (null <: opt t).

So reserved <: opt reserved will always result null.

coq/MiniCandid.v Outdated Show resolved Hide resolved
coq/MiniCandid.v Outdated Show resolved Hide resolved
coq/MiniCandid.v Outdated Show resolved Hide resolved
val_idx p (coerce t1 t2 v1) = Some iv2 ->
(iv2 = NullV \/ typ_idx' p t1 <: typ_idx' p t2) /\
val_idx' p v1 :: typ_idx' p t1 /\
coerce (typ_idx' p t1) (typ_idx' p t2) (val_idx' p v1) = iv2.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

Base automatically changed from joachim/spec-subtype-on-decode to beta April 22, 2021 21:53
spec/Candid.md Outdated Show resolved Hide resolved
@nomeata nomeata merged commit 6f3014d into beta Apr 23, 2021
@nomeata nomeata deleted the joachim/coq-subtype-on-decode branch April 23, 2021 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants