Advertisement
tinyevil

Untitled

May 27th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. T
  2. -- the actual object
  3. -- has its own identity
  4.  
  5. T[n]
  6. -- an array of size n
  7. -- n must be a compile time constant
  8.  
  9. ptr T
  10. -- memory address
  11. -- ptr is how you break the type system/lifetime analysis
  12. -- in case you need to do something it does not understand
  13. -- (actually, any low level stuff)
  14. -- as ptr is inherently unsafe, it is Discardable, Duplicable and Relocatable
  15. -- ptr[] T - pointer to an array of T of an unknown length
  16.  
  17. ref[lifetime] T
  18. -- an alias to another identity
  19. -- tracks its lifetime, does not allow dangling references (unless pointers are involved)
  20. -- a code using only refs is safe (in the sense that if you have a memory corruption bug,
  21. -- it is somewhere else)
  22. -- ref T is always Discardable, Duplicable and Relocatable
  23.  
  24. in[lifetime] T
  25. -- ref who's also identity thief
  26. -- after 'in'-reference is created to some identity, this identity is no more
  27. -- if T isn't Discardable, `in T` is not Discardable either
  28.  
  29. out[lifetime] T
  30. -- ref to uninitialized object
  31. -- 'out T' is not Discardable and not Duplicable, but Relocatable
  32. -- the only way to "discard" an 'out'-reference, is to assign a value to it
  33. -- this turns out- reference into a ref- reference of the same lifetime
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement