Skip to main content

A Delta for Hybrid Type Checking

  • Chapter
  • First Online:
A List of Successes That Can Change the World

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 9600))

Abstract

A hybrid type checker defers parts of the type checking to run time. At compile time, the checker attempts to statically verify as many subtyping constraints as possible. Constraints that cannot be proved by the static checker, are reified as run-time casts in an intermediate language, which is a variant of the blame calculus.

The goal of this work is to simplify casts in the intermediate blame calculus by exploiting context information. To this end, we develop a coercion calculus that corresponds to the blame calculus via a pair of translations and we define the formal framework to simplify these coercions. We give a concrete instance of the calculus and demonstrate that simplification can be regarded as a synthesis problem.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    This notation is borrowed from Swamy [11]. It stands for a dependent type with argument type \(x \,{:}\, \mathsf {int} \{ x>0\}\) and result type \(y \,{:}\, \mathsf {int} \{ y>x\}\) where the scope of x extends to the result type. We sometimes omit the type annotation \(:\mathsf {int}\) if the base type is clear from the context.

References

  1. Aspinall, D., Compagnoni, A.B.: Subtyping dependent types. Theoret. Comput. Sci. 266(1–2), 273–309 (2001)

    Article  MathSciNet  MATH  Google Scholar 

  2. Bornholt, J., Torlak, E., Grossman, D., Ceze, L.: Optimizing synthesis with metasketches. In: The 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016 (2016)

    Google Scholar 

  3. Findler, R.B., Felleisen, M.: Contracts for higher-order functions. In: Peyton-Jones, S. (ed.) Proceedings ICFP 2002, pp. 48–59. ACM, New York (2002)

    Google Scholar 

  4. Greenberg, M., Pierce, B.C., Weirich, S.: Contracts made manifest. In: Proceedings of the 37th ACM Symposium POPL, pp. 353–364. ACM, Madrid, January 2010

    Google Scholar 

  5. Henglein, F.: Dynamic typing: syntax and proof theory. Sci. Comput. Program. 22, 197–230 (1994)

    Article  MathSciNet  MATH  Google Scholar 

  6. Herman, D., Tomb, A., Flanagan, C.: Space-efficient gradual typing. In: Trends in Functional Programming (TFP) (2007)

    Google Scholar 

  7. Knowles, K.L., Flanagan, C.: Hybrid type checking. ACM Trans. Program. Lang. Syst. 32(2), 1–34 (2010)

    Article  Google Scholar 

  8. Ou, X., Tan, G., Mandelbaum, Y., Walker, D.: Dynamic typing with dependent types. In: Lévy, J.J., Mayr, E.W., Mitchell, J.C. (eds.) IFIP TCS, pp. 437–450. Kluwer, Netherlands (2004)

    Google Scholar 

  9. Siek, J., Thiemann, P., Wadler, P.: Blame and coercion: together again for the first time. In: Blackburn, S. (ed.) PLDI, pp. 425–435. ACM, Portland (2015)

    Google Scholar 

  10. Sjöberg, V., Casinghino, C., Ahn, K.Y., Collins, N.,Eades III, H.D., Fu, P., Kimmell, G., Sheard, T., Stump, A., Weirich, S.: Irrelevance, heterogeneous equality, and call-by-value dependent type systems. In: Chapman, J., Levy, P.B. (eds) Proceedings Fourth Workshop on Mathematically Structured Functional Programming, MSFP 2012, Tallinn, Estonia, 25 March 2012, vol. 76 ofEPTCS, pp. 112–162 (2012)

    Google Scholar 

  11. Swamy, N., Chen, J., Fournet, C., Strub, P., Bhargavan, K., Yang, J.: Secure distributed programming with value-dependent types. In: Danvy, O. (ed.) Proceedings ICFP, Tokyo, Japan, September 2011, pp. 266–278. ACM, New York (2011)

    Google Scholar 

  12. Torlak, E., Bodík, R.: Growing solver-aided languages with rosette. In: Hosking, A.L., Eugster, P.T., Hirschfeld, R. (eds.) Onward! 2013, pp. 135–152. ACM, Indianapolis (2013)

    Google Scholar 

  13. Torlak, E., Bodík, R.: A lightweight symbolic virtual machine for solver-aided host languages. In: O’Boyle, M.F.P., Pingali, K. (eds.) PLDI, p. 54. ACM, New York (2014)

    Google Scholar 

  14. Wadler, P., Findler, R.B.: Well-typed programs can’t be blamed. In: Castagna, G. (ed.) ESOP 2009. LNCS, vol. 5502, pp. 1–16. Springer, Heidelberg (2009)

    Chapter  Google Scholar 

  15. Wright, A., Felleisen, M.: A syntactic approach to type soundness. Inf. Comput. 115(1), 38–94 (1994)

    Article  MathSciNet  MATH  Google Scholar 

Download references

Acknowledgment

Emina Torlak graciously helped getting up to speed with her Rosette system. Jeremy Siek offered some helpful suggestions. Michael Greenberg answered subtle questions about manifest contract systems.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Peter Thiemann .

Editor information

Editors and Affiliations

A Proofs

A Proofs

1.1 A.1 Preservation for \(\lambda _{hb}\)

Proof of Proposition 2

Induction on the derivation of \(M \longrightarrow N\).

Case \((\lambda x.M)\,W \longrightarrow M[W/x]\).

  1. 1.

    Inversion of \(\cdot \vdash (\lambda x.M)\,W : T\) yields the next two items

  2. 2.
  3. 3.

    \(\cdot \vdash T'[W/x] \le T\)

  4. 4.

    Inversion on the first premise of Item 2 yields the next two items

  5. 5.

    \(x:S' \vdash M : T''\)

  6. 6.

    \(\cdot \vdash (x:S') \rightarrow T'' \le (x:S) \rightarrow T'\) which implies \(\cdot \vdash S \le S'\) and \(x:S \vdash T'' \le ~T'\)

  7. 7.

    From Items 5 and 6 and the premise \(\cdot \vdash W : S\) in Item 2, the substitution lemma yields \(\cdot \vdash M[W/x] : T''[W/x]\)

  8. 8.

    From Item 6 and substitution, we obtain \(\cdot \vdash T''[W/x] \le T'[W/x]\)

  9. 9.

    Item 3, transitivity of subtyping, and subsumption yield \(\cdot \vdash M[W/x] : T\)

Case \(\lceil m\rceil +\lceil n\rceil \longrightarrow \lceil m+n\rceil \).

  1. 1.

    Inversion of \(\cdot \vdash \lceil m\rceil +\lceil n\rceil : T\) yields the following three items

  2. 2.

    \(\cdot \vdash z \,{:}\, \mathsf {int} \{ \exists xy.z=x+y \wedge P\wedge Q\} \le T\)

  3. 3.

    \(\cdot \vdash \lceil m\rceil : x \,{:}\, \mathsf {int} \{ P\}\) where \(\cdot \vdash x \,{:}\, \mathsf {int} \{ x=m\} \le x \,{:}\, \mathsf {int} \{ P\}\)

  4. 4.

    \(\cdot \vdash \lceil n\rceil : y \,{:}\, \mathsf {int} \{ Q\}\) where \(\cdot \vdash y \,{:}\, \mathsf {int} \{ y=n\} \le y \,{:}\, \mathsf {int} \{ Q\}\)

  5. 5.

    Hence, \(x=m \supset P\) and \(y=n \supset Q\)

  6. 6.

    Now \(\cdot \vdash \lceil m+n\rceil : z \,{:}\, \mathsf {int} \{ z=m+n\}\)

  7. 7.

    The predicate is equivalent to \(\exists xy. z=x+y \wedge x=m \wedge y=n\).

  8. 8.

    By Item 5, the predicate in Item 7 implies \(\exists xy. z=x+y \wedge P\wedge Q\)

  9. 9.

    Taking Items 6, 7, 8, and 2 and applying subsumption yields \(\cdot \vdash \lceil m+n\rceil : T\)

Case .

  1. 1.

    Inversion applied to \(\cdot \vdash \lceil m\rceil : x \,{:}\, B \{ P\}\Rightarrow x \,{:}\, B \{ Q\}: T\) yields

  2. 2.

    \(\cdot \vdash x \,{:}\, B \{ Q\}\le T\) and

  3. 3.

    \(\cdot \vdash \lceil m\rceil : x \,{:}\, B \{ P\}\) and

  4. 4.

    \(\models Q[m/x]\)

  5. 5.

    For the reduct, \(\cdot \vdash \lceil m\rceil : x \,{:}\, B \{ x = m\}\)

  6. 6.

    Since \(\models Q[m/x]\), we have \(\models \forall x. x=m \wedge Q\), which establishes the subtyping \(\cdot \vdash x \,{:}\, B \{ x = m\} \le x \,{:}\, B \{ Q\}\)

  7. 7.

    The claim follows by subsumption with Item 2.

Case .

  1. 1.

    Applying inversion to \(\cdot \vdash (V : (x:S) \rightarrow T \Rightarrow (x:S') \rightarrow T')\, W : T'[W/x]\) yields the following items

  2. 2.

    \(\cdot \vdash (V : (x:S) \rightarrow T \Rightarrow (x:S') \rightarrow T') : (x:S') \rightarrow T'\)

  3. 3.

    \(\cdot \vdash W : S'\)

  4. 4.

    \(\cdot \vdash T'[W/x]\)

  5. 5.

    Inverting the premise of Cast-Arg-Base, we further obtain

  6. 6.

    \(S = x \,{:}\, B \{ P\}\)

  7. 7.

    \(S' = x \,{:}\, B \{ P\}'\)

  8. 8.

    \(\models {P}'[W/x]\)

  9. 9.

    From Item 3 and 6, we obtain \(\models P[W/x]\)

  10. 10.

    Applying inversion to Item 2, we obtain

  11. 11.

    \(\cdot \vdash V : (x:S) \rightarrow T\) and

  12. 12.

    \(\lfloor (x:S) \rightarrow T\rfloor = \lfloor (x:S') \rightarrow T'\rfloor \)

  13. 13.

    Using Item 9, we obtain \(\cdot \vdash W : S\) (with an intermediate subsumption step)

  14. 14.

    Hence \(\cdot \vdash T[W/x]\) and \(\cdot \vdash V\, W : T[W/x]\)

  15. 15.

    We conclude that \(\cdot \vdash (V\, W : (T \Rightarrow T')[W/x]) : T'[W/x]\)

Case .

  1. 1.

    From the premise, we know that \(\lfloor S'\rfloor = \lfloor S\rfloor = G \rightarrow G'\)

  2. 2.

    Applying inversion to \(\cdot \vdash (V : (x:S) \rightarrow T \Rightarrow (x:S') \rightarrow T')\, W : T_0\) yields

  3. 3.

    \(T_0 = T'[W/x]\)

  4. 4.

    \(\cdot \vdash W: S'\)

  5. 5.

    \(\cdot \vdash (V : (x:S) \rightarrow T \Rightarrow (x:S') \rightarrow T') : (x:S') \rightarrow T'\)

  6. 6.

    From Item 1 and 3, we obtain \(T_0 = T'[W/x] = T'\) and, in fact, \(T'[N/x] = T'\) and \(T[N/x]=T\), for any N, because all free variables in types are restricted to base types.

  7. 7.

    Inversion of Item 5 yields the following

  8. 8.

    \(\cdot \vdash V : (x:S) \rightarrow T\) and

  9. 9.

    \(\lfloor (x:S) \rightarrow T\rfloor = \lfloor (x:S') \rightarrow T'\rfloor \)

  10. 10.

    From Item 5, we conclude \(\cdot \vdash (W : S' \Rightarrow S) : S\)

  11. 11.

    From Item 10 and 8, we obtain \(\cdot \vdash (V\, (W : S' \Rightarrow S)) : T[(W : S' \Rightarrow S)/x]\), where Item 6 assures us that \(T[(W : S' \Rightarrow S)/x] = T\) is well-formed.

  12. 12.

    We conclude that \(\cdot \vdash (V\, (W : S' \Rightarrow S) : (T \Rightarrow T')) : T'\) where \(T' = T'[W/x] = T_0\) by Item 6.

Case reduction in context: immediate by application of the inductive hypothesis.     \(\square \)

1.2 A.2 Preservation for \(\lambda _{hc}\)

Proof of Proposition 2

; cases for \(\lambda _{hc}\). We just state the additional inductive cases for the reductions involving coercions.

Case .

  1. 1.

    From \(\cdot \vdash \lceil m\rceil \langle x.R\rangle : T\) (wlog, we omit inversion of a potential outermost application of the subsumption rule) we obtain the following two items

  2. 2.

    \(\cdot \vdash \lceil m\rceil : S\)

  3. 3.

    \(\cdot \vdash {x.R} \,{:}{:}\, S \Longrightarrow T\)

  4. 4.

    Inversion of Item 2 yields \(\cdot \vdash x \,{:}\, B \{ x=m\} \le S\)

  5. 5.

    Hence, \(S = x \,{:}\, B \{ P\}\) for some \(P\) such that \(\forall x. x=m \supset P\)

  6. 6.

    Inversion of Item 3 yields \(T = x \,{:}\, B \{ Q\}\) such that \(\forall x:B. P\supset (Q\Leftrightarrow R)\).

  7. 7.

    Since \(\models R[m/x]\), we obtain that \(\forall x. x=m \supset P\wedge R\) and thus \(\forall x. x=m \supset Q\) by Item 6.

  8. 8.

    Hence, \(\cdot \vdash \lceil m\rceil : T = x \,{:}\, B \{ Q\}\) by subsumption.

Case .

  1. 1.

    From the premise, we obtain

  2. 2.

    \(k = x.R\) and

  3. 3.

    \(\models R[W/x]\).

  4. 4.

    Applying inversion to \(\cdot \vdash (V \langle (x:k) \rightarrow d\rangle )\, W : T_0\) yields

  5. 5.

    \(\cdot \vdash (V \langle (x:k) \rightarrow d\rangle ) : (x:S') \rightarrow T'\)

  6. 6.

    \(\cdot \vdash W : S'\)

  7. 7.

    \(\cdot \vdash T_0\) where \(T_0 = T'[W/x]\)

  8. 8.

    Inversion of Item 5 yields

  9. 9.

    \(\cdot \vdash (x:k) \rightarrow d \,{:}{:}\, (x:S) \rightarrow T \Longrightarrow (x:S') \rightarrow T'\)

  10. 10.

    \(\cdot \vdash V : (x:S) \rightarrow T\)

  11. 11.

    From Item 9, we obtain by inversion

  12. 12.

    \(\cdot \vdash k \,{:}{:}\, S' \Longrightarrow S\) and

  13. 13.

    \(x : S \vdash d \,{:}{:}\, T \Longrightarrow T'\).

  14. 14.

    Hence, \(S = x \,{:}\, B \{ P\}\) and \(S' = x \,{:}\, B \{ P\}'\)

  15. 15.

    Using Item 3, \(\cdot \vdash W: S\)

  16. 16.

    Hence \(\cdot \vdash (V\, W) : T[W/x]\)

  17. 17.

    By substitution on Item 13: \(\cdot \vdash d[W/x] \,{:}{:}\, T[W/x] \Longrightarrow T'[W/x]\)

  18. 18.

    Hence \(\cdot \vdash (V\, W) \langle d[W/x]\rangle : T'[W/x]\)

figure h
  1. 1.

    From the premise, we obtain that \(k = (x':k') \rightarrow d'\) a function coercion.

  2. 2.

    By inversion on \(\cdot \vdash (V \langle (x:k) \rightarrow d\rangle )\, W : T_0\) we obtain

  3. 3.

    \(\cdot \vdash (V \langle (x:k) \rightarrow d\rangle ) : (x:S') \rightarrow T'\)

  4. 4.

    \(\cdot \vdash W : S'\)

  5. 5.

    \(\cdot \vdash T_0\) where \(T_0 = T'[W/x]\)

  6. 6.

    Further inversion on Item 3 yields

  7. 7.

    \(\cdot \vdash V : (x:S) \rightarrow T\) and

  8. 8.

    \(\cdot \vdash (x:k) \rightarrow d \,{:}{:}\, (x:S) \rightarrow T \Longrightarrow (x:S') \rightarrow T'\)

  9. 9.

    By inversion \(\cdot \vdash k \,{:}{:}\, S' \Longrightarrow S\) and \(x:S \vdash d \,{:}{:}\, T \Longrightarrow T'\)

  10. 10.

    By the premise, we know that \(\lfloor S\rfloor = G\rightarrow G'\)

  11. 11.

    Hence x does not occur free in T, \(T'\), and d

  12. 12.

    Hence \(\cdot \vdash \,{:}{:}\, T \Longrightarrow T'\)

  13. 13.

    Thus \(\cdot \vdash W \langle k\rangle : S\) (using Item 9)

  14. 14.

    By Item 11, \(\cdot \vdash T[W \langle k\rangle /x]\) because \(T[W \langle k\rangle /x] = T\)

  15. 15.

    Hence \(\cdot \vdash V (W \langle k\rangle ) : T\)

  16. 16.

    We conclude \(\cdot \vdash (V (W \langle k\rangle )) \langle d\rangle : T'\)     \(\square \)

Rights and permissions

Reprints and permissions

Copyright information

© 2016 Springer International Publishing Switzerland

About this chapter

Cite this chapter

Thiemann, P. (2016). A Delta for Hybrid Type Checking. In: Lindley, S., McBride, C., Trinder, P., Sannella, D. (eds) A List of Successes That Can Change the World. Lecture Notes in Computer Science(), vol 9600. Springer, Cham. https://doi.org/10.1007/978-3-319-30936-1_22

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-30936-1_22

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-30935-4

  • Online ISBN: 978-3-319-30936-1

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics