text stringlengths 128 2.05k |
|---|
Values, ranged over by [MATH] , consist of casts and usual constructs from the call-by-value polymorphic lambda calculus—constants (denoted by [MATH] ), term abstractions, and type abstractions. Term abstractions [MATH] and type abstractions [MATH] bind [MATH] |
and [MATH] in the body [MATH] , respectively. Casts [MATH] from source type [MATH] to target type [MATH] check that arguments of [MATH] can behave as [MATH] at run time. Label [MATH] indicates an abstract location of the cast in source code and it is used to identify failure casts; in a typical implementation, it would... |
The first line of terms, ranged over by [MATH] , are standard—values, variables (denoted by [MATH] [MATH] [MATH] , etc.), primitive operations (denoted by [MATH] ), term applications, and type applications. We assume that each base type [MATH] is equipped with an equality operator |
[MATH] to distinguish different constants. The second line presents terms which appear at run time for contract checking. Waiting checks [MATH] , introduced for fussy cast semantics by Sekiyama et al. Sekiyama/Nishida/Igarashi_2015_POPL , check that the value of [MATH] satisfies the contract [MATH] by turning themselve... |
[MATH] , called blame Findler/Felleisen_2002_ICFP , is raised. We introduce usual notation. We write [MATH] and [MATH] for the sets of free term variables and free type variables that occur in [MATH] , respectively. Term [MATH] is closed if [MATH] |
[MATH] and [MATH] denote terms obtained by substituting [MATH] and [MATH] for variables [MATH] and [MATH] in [MATH] in a capture-avoiding manner, respectively. These notations are also applied to types, typing contexts, and evaluation contexts (introduced in Section 2.2 ). We write [MATH] for the set of term and type v... |
[MATH] for [MATH] 2.2. Operational Semantics [MATH] has call-by-value operational semantics in the small-step style, which is given by reduction [MATH] and evaluation [MATH] over closed terms. We write [MATH] and [MATH] for the reflexive transitive closures of |
[MATH] and [MATH] , respectively. Reduction and evaluation rules are shown in Figure R_Op says that reduction of primitive operations depends on function |
[MATH] , which gives a denotation to each primitive operation and maps tuples of constants to constants; for example, [MATH] denotes [MATH] We will describe requirements to [MATH] in Section 2.3 Term and type applications evaluate by the standard [MATH] -reduction R_Beta and R_TBeta ). |
Cast applications evaluate by combination of cast reduction rules, which are from Sekiyama et al. Sekiyama/Nishida/Igarashi_2015_POPL except |
R_Forall Casts between the same base type behave as an identity function R_Base Casts for function types produce a function wrapper involving casts which are contravariant on the domain types and covariant on the codomain types R_Fun In taking an argument, the wrapper converts the argument with the contravariant cast s... |
R_Fun renames [MATH] in the codomain type [MATH] of the source function type to [MATH] because [MATH] expects [MATH] to be replaced with arguments to [MATH] but they are actually denoted by [MATH] in the wrapper. Casts for universal types behave as in the previous work Belo/Greenberg/Igarashi/Pierce_2011_ESOP Sekiyama/... |
R_Forget and then check refinements in the target type with waiting checks R_PreCheck After checks of inner refinements finish, the outermost refinement will be checked by an active check R_Check If the check succeeds, the checked value is returned R_OK ; otherwise, the cast is blamed R_Fail |
Evaluation uses evaluation contexts Felleisen/Hieb_1992_TCS , given as follows, to reduce subterms E_Red and lift up blame E_Blame |
[EQUATION] This definition indicates that the semantics is call-by-value and arguments evaluate from left to right. Fussy versus sloppy |
Our cast semantics is fussy in that, when [MATH] is applied, all refinements in target type [MATH] are checked even if they have been ensured by source type [MATH] For example, let us consider reflexive cast |
[MATH] When applied to [MATH] , the cast application forgets the refinements in the source type of the cast R_Forget [EQUATION] and then refinements in the target type are checked from the innermost through the outermost by using waiting checks |
R_PreCheck [EQUATION] even though [MATH] would be typed at [MATH] and satisfy the refinements. In contrast, Belo et al.’s semantics Belo/Greenberg/Igarashi/Pierce_2011_ESOP is sloppy in that checks of refinements that have been ensured are skipped, which is represented by two cast reduction rules: |
[EQUATION] where [MATH] is the reduction relation in the sloppy semantics. The first rule processes reflexive casts as if they are identity functions and the second checks only the outermost refinement because others have been ensured by the source type. Under the sloppy semantics, |
[MATH] reduces to [MATH] in one step. The sloppy semantics allows a logical relation to take arbitrary binary relations on terms for interpretation of type variables Belo/Greenberg/Igarashi/Pierce_2011_ESOP |
It is found that, however, naive sloppy semantics does not satisfy the so-called cotermination ( LABEL:prop:fh-coterm-true ), a key property to show type soundness and parametricity in manifest contracts; Sekiyama et al. investigated this problem in detail Sekiyama/Igarashi/Greenberg_2016_TOPLAS Briefly speaking, the c... |
[MATH] also evaluate to [MATH] because reduction of subterm [MATH] to [MATH] must not change the evaluation result. However, [MATH] checks refinement [MATH] in |
[MATH] , which gives rise to blame; thus, the cotermination is invalidated. The problem above does not happen in the fussy semantics. Under the fussy semantics, since all refinements in a cast are checked, both casts [MATH] and [MATH] check refinement |
[MATH] and raise blame. 2.3. Type System The type system consists of three judgments: typing context well-formedness [MATH] type well-formedness [MATH] , and term typing [MATH] They are derived by rules in Figure The well-formedness rules are standard or easy to understand, and the typing rules are based on previous wo... |
[MATH] to have [MATH] because it is checked at run time that the evaluation result of [MATH] satisfies [MATH] which refers to [MATH] of |
[MATH] Although waiting checks are run-time terms, T_WCheck does not require [MATH] and [MATH] to be closed, unlike other run-time typing rules such as T_ACheck This relaxation allows type-preserving static decomposition of [MATH] |
into a smaller cast [MATH] and a waiting check for refinement [MATH] LABEL:prop:fh-cc-precheck in Section LABEL:sec:reasoning-cast-decomp ). Active checks [MATH] are well typed if [MATH] is an actual intermediate state of evaluation of [MATH] |
T_ACheck T_Forget and T_Exact are run-time typing rules: the former forgets a refinement and the latter adds a refinement that holds. |
T_Conv is a run-time typing rule to show subject reduction. To motivate it, let us consider application [MATH] where [MATH] and [MATH] are typed at [MATH] and [MATH] , respectively. This application would be typed at [MATH] by T_App If [MATH] reduces to [MATH] [MATH] would be at [MATH] , which is syntactically differen... |
[MATH] To this end, Belo et al. Belo/Greenberg/Igarashi/Pierce_2011_ESOP introduced a type conversion relation which relates [MATH] and |
[MATH] and added a typing rule that allows terms to be retyped at convertible types. Their type conversion turns out to be flawed, but it is fixed in the succeeding work Greenberg_2013_PhD Sekiyama/Nishida/Igarashi_2015_POPL Our type conversion [MATH] follows the fixed version. |
{defi} [Type Conversion] The binary relation [MATH] over types is defined as follows: [MATH] if there exist some [MATH] [MATH] [MATH] , and [MATH] such that |
[MATH] and [MATH] and [MATH] The type conversion [MATH] is the symmetric transitive closure of [MATH] Finally, we formalize requirements to constants and primitive operations. We first define auxiliary function [MATH] , which strips off refinements that are not under other type constructors: |
[EQUATION] Requirements to constants and primitive operations are as follows: For each constant [MATH] (1) [MATH] (2) [MATH] is derivable, and (3) [MATH] satisfies all refinements in [MATH] , that is, |
[MATH] For each primitive operation [MATH] [MATH] is a monomorphic dependent function type of the form [MATH] where, for any [MATH] , there exists some [MATH] such that |
[MATH] Furthermore, we require that [MATH] return a value satisfying the refinements in the return type [MATH] when taking constants satisfying the refinements in the argument types, that is: |
[EQUATION] In contrast, we assume that [MATH] is undefined if some [MATH] does not satisfy refinements in [MATH] , that is, [MATH] cannot be derived. |
2.4. Properties This section proves type soundness via progress and subject reduction Wright/Felleisen_1994_IC Type soundness can be shown as in the previous work Sekiyama/Nishida/Igarashi_2015_POPL Sekiyama/Igarashi/Greenberg_2016_TOPLAS |
and so we omit the most parts of its proof. We start with showing the cotermination ( LABEL:prop:fh-coterm-true ), a key property for proving not only type soundness but also parametricity and soundness of our logical relation with respect to contextual equivalence. It states that, if [MATH] , then [MATH] and [MATH] be... |
[MATH] is a weak bisimulation. We also refer to the names of the lemmas in the proof script coterm.v Proposition 1 (name=Unique Decomposition [ lemm_red_ectx_decomp in coterm.v ]) |
fh-red-decomp If [MATH] and [MATH] and [MATH] and [MATH] then [MATH] and [MATH] Proposition 2 (name=Determinism [ lemm_eval_deterministic in coterm.v ]) |
fh-eval-determinism If [MATH] and [MATH] , then [MATH] Proposition 4 (name=Weak bisimulation, left side [ lemm_coterm_left_eval in coterm.v ]) |
fh-coterm-left If [MATH] and [MATH] then there exists some [MATH] such that [MATH] and [MATH] (See the commuting diagram on the left in Figure .) |
Proposition 5 (name=Weak bisimulation, right side [ lemm_coterm_right_eval in coterm.v ]) fh-coterm-right If [MATH] and [MATH] then there exists some [MATH] such that [MATH] |
and [MATH] . (See the commuting diagram on the right in Figure .) Proposition 6 (name=Cotermination [ lemm_coterm_true in coterm.v ]) |
fh-coterm-true Suppose that [MATH] (1) If [MATH] , then [MATH] In particular, if [MATH] , then [MATH] (2) If [MATH] , then [MATH] In particular, if [MATH] , then [MATH] |
The cotermination implies the value inversion, which states that well-typed values satisfy refinements of their types. {defi} We define function [MATH] from types to sets of lambda abstractions that denote refinements: |
[EQUATION] We write [MATH] if, for any [MATH] [MATH] Proposition 7 fh-val-satis-c-conv For any closed value [MATH] if [MATH] , then [MATH] iff [MATH] |
Proposition 8 (name=Value Inversion) fh-val-satis-c If [MATH] , then [MATH] In addition to the value inversion, we need auxiliary, standard lemmas to show the progress and the subject reduction. In what follows, only key lemmas are stated; readers interested in other lemmas and their proofs are referred to Greenberg’s ... |
Proposition 10 (name=Term Weakening) fh-weak-term Let [MATH] be a fresh variable. Suppose that [MATH] {statements} (term) If [MATH] , then [MATH] |
(type) If [MATH] , then [MATH] (tctx) If [MATH] , then [MATH] Proposition 11 (name=Type Weakening) fh-weak-type Let [MATH] be a fresh type variable. |
{statements} (term) If [MATH] , then [MATH] (type) If [MATH] , then [MATH] (tctx) If [MATH] , then [MATH] Proposition 12 (name=Term Substitution) |
fh-subst-term Suppose that [MATH] {statements} (term) If [MATH] then [MATH] (type) If [MATH] then [MATH] (tctx) If [MATH] , then [MATH] |
Proposition 13 (name=Type Substitution) fh-subst-type Suppose that [MATH] {statements} (term) If [MATH] then [MATH] (type) If [MATH] then [MATH] |
(tctx) If [MATH] , then [MATH] Proposition 14 (name=Canonical Forms) fh-canonical Suppose that [MATH] {statements} (base) If [MATH] , then [MATH] |
(fun) If [MATH] , then [MATH] for some [MATH] [MATH] , and [MATH] , or [MATH] for some [MATH] [MATH] , and [MATH] (univ) If [MATH] , then |
[MATH] for some [MATH] Proposition 15 (name=Progress) fh-progress If [MATH] , then: [MATH] for some [MATH] [MATH] is a value; or |
[MATH] for some [MATH] Proposition 16 (name=Subject Reduction) fh-subjred If [MATH] and [MATH] , then [MATH] Proposition 17 (type=thm,name=Type Soundness) |
fh-type-sound If [MATH] , then one of the followings holds. [MATH] diverges; [MATH] for some [MATH] such that [MATH] and [MATH] ; or |
[MATH] for some [MATH] 3. Semityped Contextual Equivalence We introduce semityped contextual equivalence to formalize the upcast elimination property. It relates terms [MATH] and [MATH] such that (1) they are contextually equivalent, that is, behave equivalently under any well-typed program context, and (2) [MATH] is w... |
Figure shows the syntax of multi-hole program contexts [MATH] , value contexts [MATH] , and type contexts [MATH] Contexts have zero or more holes [MATH] indexed by positive numbers [MATH] , and the same hole [MATH] can occur in a context an arbitrary number of times. Thus, any term, value, and type are contexts without... |
[MATH] through [MATH] and any terms [MATH] , we write [MATH] , or [MATH] simply if [MATH] is clear from the context or not important, to denote a term obtained by replacing each hole |
[MATH] with term [MATH] In particular, [MATH] because there are zero holes in [MATH] We use similar notation for value and type contexts. |
Contexts having multiple holes is crucial in semityped contextual equivalence. If we restrict contexts to have a single hole, replacements of terms with contextually-equivalent ones would be performed one by one. However, a replacement with an ill-typed term produces an ill-typed program, and then, since semityped cont... |
[MATH] and [MATH] because both are ill typed. The same issue arises even if we first replace [MATH] and then [MATH] As a result, we could not show that [MATH] and [MATH] are contextually equivalent. This is problematic also in the upcast elimination, especially when programs have multiple upcasts. We address this issue... |
to [MATH] directly, not via [MATH] nor [MATH] The semityped contextual equivalence considers three kinds of observable results, that is, termination, blame, and being stuck—the last has to be considered because semityped contextual equivalence contains possibly ill-typed terms. We write |
[MATH] if [MATH] for some [MATH] [MATH] if [MATH] , and [MATH] if [MATH] for some [MATH] such that [MATH] cannot evaluate and it is neither a value nor blame. |
{defi} [Observable Equivalence] We write [MATH] if (1) [MATH] iff [MATH] (2) [MATH] iff [MATH] for any [MATH] , and (3) [MATH] iff [MATH] |
Now, we could define semityped contextual equivalence as follows. Terms [MATH] and [MATH] are contextually equivalent at [MATH] under [MATH] , respectively, when (1) for any [MATH] |
[MATH] and [MATH] , and (2) for any [MATH] and [MATH] if [MATH] then [MATH] Thanks to program contexts with multiple holes, we can replace two or more well-typed terms with possibly ill-typed, contextually equivalent terms at the same time. |
The semityped contextual equivalence defined in this way is well defined as it is but we find it more convenient to consider contexts as typed objects to discuss composition of contexts and terms rigorously. To this end, we introduce judgments for program context well-formedness [MATH] and type context well-formedness ... |
is typed at [MATH] under [MATH] for any [MATH] [MATH] and [MATH] are a well-typed term of [MATH] under [MATH] and a well-formed type under [MATH] , respectively. |
These well-formedness judgments need information on terms [MATH] with which holes are replaced as well as typing context and type information because whether composition of a context with terms produces a well-typed term rests on the composed terms. For example, let us consider [MATH] where [MATH] |
is typed at [MATH] [MATH] is well typed because the type of [MATH] matches with the source type of the cast, while [MATH] is not because the type of |
[MATH] is [MATH] , which is different from [MATH] If no type information in [MATH] depends on holes, the derivation of [MATH] refers only to [MATH] and |
[MATH] , not any of [MATH] Inference rules for the judgments are shown in Figures and ; they correspond to term typing and type well-formedness rules given in Section 2.3 |
We show a few properties of well-typed contexts: (1) composition of a well-formed context with well-typed terms produces a well-typed term, (2) free variables and free type variables are preserved by the composition, and (3) well-typed terms, well-typed values, well-formed types are well-formed program contexts, value ... |
Proposition 18 fh-ctxeq-typed Suppose [MATH] , …, [MATH] {statements} (term) If [MATH] then [MATH] (type) If [MATH] then [MATH] Proposition 19 |
fh-ctxeq-closed For any [MATH] [MATH] , and [MATH] such that [MATH] for any [MATH] {statements} (term) if [MATH] then [MATH] , and |
(type) if [MATH] then [MATH] Proposition 20 fh-ctxeq-refl For any [MATH] [MATH] , and [MATH] {statements} (term) if [MATH] , then [MATH] |
(val) if [MATH] , then [MATH] , and (type) if [MATH] , then [MATH] Finally, we define semityped contextual equivalence by using well-formed contexts. |
{defi} [Semityped Contextual Equivalence] Terms [MATH] and [MATH] are contextually equivalent at [MATH] under [MATH] , respectively, written as [MATH] if and only if (1) for any [MATH] |
[MATH] and [MATH] , and (2) for any [MATH] and [MATH] if [MATH] then [MATH] For simplification, we write [MATH] if [MATH] is not important and |
[MATH] if [MATH] We note that we state semityped contextual equivalence for pairs of terms and that equivalennce is preseved by dropping some pairs: that is, if [MATH] , then |
[MATH] for [MATH] Finally, we make a few remarks on semityped contextual equivalence. Although we call it semityped contextual “equivalence,” this relation is not quite an equivalence relation because symmetry does not hold (ill-typed terms cannot be on the left-hand side). More interestingly, even showing its transiti... |
[MATH] , then [MATH] and [MATH] behave equivalently under any program context [MATH] which is well formed for [MATH] We might expect that [MATH] and [MATH] behave in the same way under [MATH] but it is not clear because [MATH] may not be well formed for |
[MATH] Fortunately, our logical relation enables us to show (restricted) transitivity of semityped contextual equivalence via completeness with respect to semityped contextual equivalence ( |
Proposition 21 :reffh-lr-ctx-trans). In some work Lassen_1998_Phd Pitts_2005_ATTAPL , contextual equivalence is defined for A-normal forms, where arguments to functions are restricted to values and terms are composed by [MATH] -expressions (so, they are not shorthand of term applications there) to reduce clutter. In fa... |
[MATH] , which could be given as follows: [EQUATION] The problem is that the index type [MATH] possibly includes refinements which are not A-normal forms if [MATH] is neither a variable nor a value. For example, [MATH] is typed at |
[MATH] , but the refinement [MATH] is not in A-normal form. We might be able to define substitution so that [MATH] would be obtained, but we avoid such “peculiar” substitution. |
While semitypedness of our contextual equivalence is motivated by the upcast elimination, perhaps surprisingly, it appears unclear to us how to define typed contextual equivalence. One naive definition of it is to demand that, for each [MATH] in Definition 20 [MATH] is well typed at [MATH] under |
[MATH] However, this gives rise to ill-typed terms. For example, suppose that we want to equate [MATH] and [MATH] To show their contextual equivalence, we have to evaluate them in any program context. Here, a context [MATH] given above is well-formed for |
[MATH] but not for [MATH] ; note that we cannot apply CT_Conv to [MATH] due to the reference to free variable [MATH] A better definition may be to require contexts to be well-formed for both terms that we want to equate. This definition could exclude contexts like the above whereas it seems to cause another issue: are ... |
4. Logical Relation We develop a logical relation for two reasons. The first is parametricity, which ensures abstraction and enables reasoning for programs in polymorphic calculi Wadler_1989_FPCA Parametricity is usually stated as “any well typed term is logically related to itself.” The second is to show contextual eq... |
In this section, we first give an informal overview of main ideas in our logical relation in Section 4.1 . Then, after preliminary definitions in Section 4.2 , we formally define the logical relation in Section LABEL:sec:logical_relation-def |
and state its soundness and completeness with respect to semityped contextual equivalence in Section LABEL:sec:logical_relation-statement The completeness is given in a restricted form—two contextually equivalent, |
well-typed terms are logically related; completeness without restrictions is left open. 4.1. Informal Overview The definition of our logical relation follows Belo et al. Belo/Greenberg/Igarashi/Pierce_2011_ESOP and Sekiyama et al. Sekiyama/Igarashi/Greenberg_2016_TOPLAS . We start with two type-indexed families of rela... |
for closed values and [MATH] for closed terms and a relation [MATH] for (open) types. The type interpretation [MATH] assigns value relations to type variables—which is common to relational semantics for a polymorphic language—and [MATH] , called value assignment , gives pairs of values to free term variables in [MATH] ... |
[MATH] . Value assignments are introduced by Belo et al. Belo/Greenberg/Igarashi/Pierce_2011_ESOP to handle dependency of types on terms. Main differences from the previous work |
Belo/Greenberg/Igarashi/Pierce_2011_ESOP Sekiyama/Igarashi/Greenberg_2016_TOPLAS are that (1) our logical relation is semityped just like our contextual equivalence (whereas the previous work does not enforce well-typedness conditions) and that (2) different closure conditions are assumed for relations assigned to type... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.