Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ocalm has a uniform representation of data
- everything is one word, which is either an immediate or a pointer to the heap
- polymorphism
- in ocaml, can have same machine code for all
- C++: compile multime assembly-language versions
- C#: do it at run time
- jit
- ocalm 5.0 was the first version to have parallelism
- all threads share the same heap
- C++: data race can result in crazy behavior
- data race on one variable can corrupt other variables
- things can go wrong before you access the variable
- bounded in time and space
- rust has a race-free programming model; can use a safe fragment
- of rust, and there's a guarantee of no data races
- ocaml
- doesn't give much control over memory layout of data
- an int64 takes 24 bytes
- an arry with elements that are not immediates has values that
- are all over the heap, can't be cached
- has to rule out data races dynamically, can't be done statically
- they want to fit into the main, normal ocaml ecosystem
- three features
- narrow and flat data layouts
- add new unboxed primitives like int32#
- unboxed records, passed in two registers
- arrays of unboxed records
- "Unboxed types are characterized by their layout," which is a kind
- a kind is a type of type
- bits64 = a layout for types that fit in 64 bits
- implement polymorphism using one copy of the function per layout,
- which is better than what C++ does, one function per type
- stack allocation
- ocaml has a major heap and minor heap
- stack allocation is faster: deallocation is trivial
- but what about pointers to the stack that have become invalid?
- don't create pointers from heap to stack
- don't return stack values
- add features to type system to keep track of what can and can't
- be stack-allocated
- why not use rust-style lifetimes?
- rust is manually managed, every value has a lifetime
- lifetimes aren't limited by lexical scope
- issues with higher-order polymorphism, type inference is
- undecidable, so user sometimes has to annotate lifetimes
- so instead of lifetimes, use modes, which are properties that
- can be applied to any type
- global mode = default, unconstrained
- local mode = must follow stack discipline
- type system automatically figures out the mode based on how you
- use the value
- race-free parallel programming
- create new modes for this
- contention = has been shared across threads
- portability = is safe to share between threads
- when you have a function that mutates data,
- that function is not portable
- they have 15 modes in 5 dimensions
- semantics of spawn and join makes requirements on modes
- manipulating pointers to shared memory
- as one choice, they provide an API for doing locking
- "we're nervous about complexity!"
- paper: "Data Race Freedom a la Mode"
- https://dl.acm.org/doi/10.1145/3704859
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement