types.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. Types
  2. ~~~~~
  3. Every value has a unique type.
  4. Every slot has a unique type.
  5. The value held in a slot always has the same type as the slot.
  6. Limitation
  7. ~~~~~~~~~~
  8. Some types (and values) are "limited". A type is limited if:
  9. - It is declared as "lim".
  10. - It contains a limited slot.
  11. - It contains a process.
  12. Limited values cannot be copied or transmitted. See the memory
  13. model for discussion.
  14. Typestates
  15. ~~~~~~~~~~
  16. Every program containing symbolic expressions maps to a sequence of
  17. statements in a 3-operand-statement normal form with
  18. call-by-value-return move-semantics on slots and bindings.
  19. Every "point" (inbetween normalized statements) in a program has a
  20. typestate. Two typestates are therefore defined for each statement:
  21. its prestate and its poststate.
  22. A typestate is formally a set of N-ary boolean predicates over visible
  23. slots.
  24. Typestates form a semilattice ordered by subset-inclusion (x < y means
  25. x is a subset of y), where 'join' means 'set intersection'.
  26. When N statements lead to a single point, the point's typestate
  27. is the pairwise join of the N poststates of predeeding statements.
  28. All poststates can be dropped. Dropping the 'init' poststate from a
  29. slot causes heap memory to be released, if the slot holds the last
  30. owning heap reference to its referent. If the referent is a proc, the
  31. associated prog's fini() function is executed. All other predicates
  32. can be dropped without side-effect.
  33. When a statement writes to a slot, predicates holding over the slot
  34. are dropped.
  35. Every operation (statement type) has a set of preconditions,
  36. formulated as predicates.
  37. If a precondition names a predicate that is not present in the
  38. statement's prestate, one of two options exists:
  39. - If the missing predicates are all 'auto' and all the
  40. preconditions of the missing predicates are met, the
  41. compiler may insert assertions for each missing predicate.
  42. - Otherwise it is a compile-time error.
  43. If a type has an associated "formal typestate", it means that the
  44. predicates in the typestate hold over any slot (hence value) given
  45. that type, for all statements in which the slot is visible.
  46. Reflection
  47. ~~~~~~~~~~
  48. Types and predicates are reflected into runtime values. Runtime values
  49. can always be converted to type "dyn", which carries the type of its
  50. value (including formal typestate) along with it. Limited values
  51. cannot be placed in a dyn; but they can be placed in a "lim dyn". The
  52. runtime representation of a type can be compared to the runtime
  53. representation of another type. To connect runtime and compile-time
  54. values, a type-switch statement exists over 'dyn' values; each arm of
  55. the type-switch syntactically aliases the dyn's value into a typed
  56. slot.
  57. Relationships to other languages
  58. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59. We borrow structure (but not terminology) from Ada and Hermes when
  60. organizing the type system. In particular:
  61. - A type describes a particular set of values, as in both languages.
  62. - A constrained type (an Ada "subtype") is a base type plus a set of
  63. constraints. Constraints are formulated using Hermes-style
  64. typestate predicates rather than Ada's fixed set of constraints.
  65. - There is no subtype lattice (as in OO languages). There is only
  66. one type for each value.
  67. Pragmatic notes
  68. ~~~~~~~~~~~~~~~
  69. - Constrained types do not participate in overload resolution,
  70. because predicates can always be dropped.
  71. - If you wish to produce a new type that wraps an old type, you can
  72. just make a single-alternative alt or a single-field rec. The
  73. allocation rules should not impose any penalty for doing this.