Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Fengmin Zhu
Tutorial POPL20
Commits
af43752f
Commit
af43752f
authored
Jan 17, 2020
by
Amin Timany
Browse files
coqdoc for interp.v and sem_type_formers.v
parent
aae79b93
Changes
2
Hide whitespace changes
Inline
Sidebyside
theories/interp.v
View file @
af43752f
From
tutorial_popl20
Require
Export
sem_type_formers
types
.
(** * Here we use semantic type formers to define semantics of syntactic types.
This is done by a straightforward induction on the syntactic type. *)
Reserved
Notation
"⟦ τ ⟧"
.
Fixpoint
interp
`
{
heapG
Σ
}
(
τ
:
ty
)
(
ρ
:
list
(
sem_ty
Σ
))
:
sem_ty
Σ
:
=
match
τ
return
_
with
...
...
theories/sem_type_formers.v
View file @
af43752f
From
tutorial_popl20
Require
Export
sem_types
.
(** The definitions of the type formers *)
(** * The definitions of the semantic type formers
These type formers correspond to those of syntactic types, e.g., a
product former that given two semantic types [A] and [B], gives
the semantic type of the product [A * B], i.e., values that are
pairs where the first component belongs to [A] and the second
component to [B]. *)
Section
types
.
Context
`
{
heapG
Σ
}.
...
...
@@ 25,17 +31,76 @@ Section types.
(* REMOVE *)
Definition
sem_ty_sum
(
A1
A2
:
sem_ty
Σ
)
:
sem_ty
Σ
:
=
SemTy
(
λ
w
,
(
∃
w1
,
⌜
w
=
InjLV
w1
⌝
∧
A1
w1
)
∨
(
∃
w2
,
⌜
w
=
InjRV
w2
⌝
∧
A2
w2
))%
I
.
(** The value interpretation for function types is as follows: *)
Definition
sem_ty_arr
(
A1
A2
:
sem_ty
Σ
)
:
sem_ty
Σ
:
=
SemTy
(
λ
w
,
□
∀
v
,
A1
v

∗
WP
App
w
v
{{
A2
}})%
I
.
(** This definition is very close to the usual way of defining the
value interpretation of the function type [A1 → A2] in ordinary
logical relations: it expresses that arguments of semantic type
[A1] are mapped to results of semantic type [A2] . The only Iris
specific feature one has to take into account is the [□]
modality. Recall that the value interpretation should be a
persistent predicate; however, even if both [P] and [Q] are
persistent propositions, the magic wand [P ∗ Q] is not
necessarily persistent. Hence, we use the [□] modality to make
the magic wand persistent. *)
(** The value interpretation for type variables, universal types,
and existential types is: *)
Definition
sem_ty_forall
(
C
:
sem_ty
Σ
→
sem_ty
Σ
)
:
sem_ty
Σ
:
=
SemTy
(
λ
w
,
□
∀
A
:
sem_ty
Σ
,
WP
w
#()
{{
w
,
C
A
w
}})%
I
.
Definition
sem_ty_exist
(
C
:
sem_ty
Σ
→
sem_ty
Σ
)
:
sem_ty
Σ
:
=
SemTy
(
λ
w
,
∃
A
:
sem_ty
Σ
,
C
A
w
)%
I
.
(** The interpretations of these types are fairly straightforward.
Given a higherorder type former [C] that maps semantic types to
semantic types, we define the universal type [sem_ty_forall A]
using the universal quantification in Iris. That is, a value [w]
is considered a polymorphic value if for any semantic type [A],
when [w] is specialized to the type [A] (written as [w #()] as
(semantic) types never appear in terms in our untyped syntax)
the _resulting expression_ is an expression in the semantics of
the type [C A] (defined using WP).
Similarly, given a higherorder type former [C] that maps
semantic types to semantic types, we define the existential type
[sem_ty_exist A] using the existential quantification in Iris.
Notice how the impredicative nature of Iris propositions and
predicates allows us to quantify over Iris predicates to define
an Iris predicate. This is crucial for giving semantics to
parametric polymorphism, i.e., universal and existential types.
Remark: notice that for technical reasons (related to the value
restriction problem in MLlike languages) universally quantified
expressions are not evaluated until they are applied to a
specific type. *)
(** The value interpretation of reference types is as follows: *)
Definition
tyN
:
=
nroot
.@
"ty"
.
Definition
sem_ty_ref
(
A
:
sem_ty
Σ
)
:
sem_ty
Σ
:
=
SemTy
(
λ
w
,
∃
l
:
loc
,
⌜
w
=
#
l
⌝
∧
inv
(
tyN
.@
l
)
(
∃
v
,
l
↦
v
∗
A
v
))%
I
.
(** Intuitively, values of the reference type [sem_ty_ref A] should
be locations l that hold a value [w] in the semantic type [A] at
all times. In order to express this intuition in a formal way, we
make use of two features of Iris:
 The pointsto connective l ↦ v (from vanilla separation logic)
provides exclusive ownership of the location l with value
v. The pointsto connective is an ephemeral proposition, and
necessarily not a persistent proposition.
 The invariant assertion [inv N P] expresses that a (typically
ephemeral) proposition [P] holds at all times  i.e., [P] is
invariant. The invariant assertion is persistent. *)
(** Remark: Iris is also capable giving semantics to recursive
types. However, for the sake of simplicity we did not consider
recursive types for this tutorial. In particular, to give the
semantics of recursive types one needs to use Iris's guarded
fixpoints which in turn requires us to enforce that semantics types,
in addition to being persistent, are also nonexpansive. *)
End
types
.
(** We introduce nicely looking notations for our semantic types. This allows
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment