unison-runtime-0.0.0
Safe HaskellNone
LanguageHaskell2010

Unison.Runtime.MCode

Synopsis

Documentation

data Args' Source #

Constructors

Arg1 !Int 
Arg2 !Int !Int 
ArgN !(PrimArray Int) 
ArgR !Int !Int 

Instances

Instances details
Show Args' Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> Args' -> ShowS #

show :: Args' -> String #

showList :: [Args'] -> ShowS #

data Args Source #

Constructors

ZArgs 
VArg1 !Int 
VArg2 !Int !Int 
VArgR !Int !Int 
VArgN !(PrimArray Int) 
VArgV !Int 

Instances

Instances details
Show Args Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> Args -> ShowS #

show :: Args -> String #

showList :: [Args] -> ShowS #

Eq Args Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

(==) :: Args -> Args -> Bool #

(/=) :: Args -> Args -> Bool #

Ord Args Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

compare :: Args -> Args -> Ordering #

(<) :: Args -> Args -> Bool #

(<=) :: Args -> Args -> Bool #

(>) :: Args -> Args -> Bool #

(>=) :: Args -> Args -> Bool #

max :: Args -> Args -> Args #

min :: Args -> Args -> Args #

newtype FieldRef Source #

Efficient mapping for record field names

Constructors

FieldRef Word64 

data RecordShape Source #

The shape of a record: which fields it has, and where each one sits in a record value's slots.

One of these is built per record-construction site and is carried by every value built there. Reaching it from the value is what lets Eq and compareClosure -- which are pure, with no access to the code cache -- order two records of *different* shapes by field name. That case is reachable: two records with different fields can be compared once they are wrapped in Any, which erases their types.

Constructors

RecordShape 

Fields

Instances

Instances details
Show RecordShape Source # 
Instance details

Defined in Unison.Runtime.MCode

Eq RecordShape Source #

Records are equal and ordered by field name, never by shapeRef, so that the result doesn't depend on the order field names happened to be interned.

Instance details

Defined in Unison.Runtime.MCode

Ord RecordShape Source # 
Instance details

Defined in Unison.Runtime.MCode

mkRecordShape :: RecordRef -> Vector FieldName -> [FieldRef] -> RecordShape Source #

A shape from its reference, its field names ascending, and the number of each field in that order (so the field at slot i has number refs !! i).

shapeSlot :: RecordShape -> FieldRef -> Int Source #

The slot of a field in a record of this shape: a binary search of shapeKeys. A field the shape lacks is an error, not a result: typechecked code only reads fields the record has, so there is nothing to recover from, and nothing to allocate on the way out.

recordShape :: MonadState RecordFieldMappings m => RecordRef -> RecordSchema -> m RecordShape Source #

Build the shape for a record schema, assigning a FieldRef to any field name not yet seen.

recordShapeFrom :: RecordFieldMappings -> RecordRef -> RecordSchema -> Maybe RecordShape Source #

Build the shape for a record schema from already-interned field names. Returns Nothing if any of them is unknown, which shouldn't happen for a schema that is itself already interned.

data RefNums Source #

Constructors

RN 

Fields

data MLit Source #

Constructors

MI !Int 
MN !Word64 
MC !Char 
MD !Double 
MT !Text 
MM !Referent 
MY !Reference 

Instances

Instances details
Show MLit Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> MLit -> ShowS #

show :: MLit -> String #

showList :: [MLit] -> ShowS #

Eq MLit Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

(==) :: MLit -> MLit -> Bool #

(/=) :: MLit -> MLit -> Bool #

Ord MLit Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

compare :: MLit -> MLit -> Ordering #

(<) :: MLit -> MLit -> Bool #

(<=) :: MLit -> MLit -> Bool #

(>) :: MLit -> MLit -> Bool #

(>=) :: MLit -> MLit -> Bool #

max :: MLit -> MLit -> MLit #

min :: MLit -> MLit -> MLit #

data GInstr comb Source #

Instances

Instances details
Functor GInstr Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

fmap :: (a -> b) -> GInstr a -> GInstr b #

(<$) :: a -> GInstr b -> GInstr a #

Foldable GInstr Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

fold :: Monoid m => GInstr m -> m #

foldMap :: Monoid m => (a -> m) -> GInstr a -> m #

foldMap' :: Monoid m => (a -> m) -> GInstr a -> m #

foldr :: (a -> b -> b) -> b -> GInstr a -> b #

foldr' :: (a -> b -> b) -> b -> GInstr a -> b #

foldl :: (b -> a -> b) -> b -> GInstr a -> b #

foldl' :: (b -> a -> b) -> b -> GInstr a -> b #

foldr1 :: (a -> a -> a) -> GInstr a -> a #

foldl1 :: (a -> a -> a) -> GInstr a -> a #

toList :: GInstr a -> [a] #

null :: GInstr a -> Bool #

length :: GInstr a -> Int #

elem :: Eq a => a -> GInstr a -> Bool #

maximum :: Ord a => GInstr a -> a #

minimum :: Ord a => GInstr a -> a #

sum :: Num a => GInstr a -> a #

product :: Num a => GInstr a -> a #

Traversable GInstr Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

traverse :: Applicative f => (a -> f b) -> GInstr a -> f (GInstr b) #

sequenceA :: Applicative f => GInstr (f a) -> f (GInstr a) #

mapM :: Monad m => (a -> m b) -> GInstr a -> m (GInstr b) #

sequence :: Monad m => GInstr (m a) -> m (GInstr a) #

Show comb => Show (GInstr comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> GInstr comb -> ShowS #

show :: GInstr comb -> String #

showList :: [GInstr comb] -> ShowS #

Eq (GInstr comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

(==) :: GInstr comb -> GInstr comb -> Bool #

(/=) :: GInstr comb -> GInstr comb -> Bool #

Ord (GInstr comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

compare :: GInstr comb -> GInstr comb -> Ordering #

(<) :: GInstr comb -> GInstr comb -> Bool #

(<=) :: GInstr comb -> GInstr comb -> Bool #

(>) :: GInstr comb -> GInstr comb -> Bool #

(>=) :: GInstr comb -> GInstr comb -> Bool #

max :: GInstr comb -> GInstr comb -> GInstr comb #

min :: GInstr comb -> GInstr comb -> GInstr comb #

type RInstr val = GInstr (RComb val) Source #

data GSection comb Source #

Constructors

Ins !(GInstr comb) !(GSection comb) 
Call !Bool !CombIx comb !Args 
DMatch !(Maybe Reference) !Int !(GBranch comb) 
Let !(GSection comb) !CombIx !Int !(GSection comb) !(Ptr NativeCell) 
Yield !Args 
App !Bool !(GRef comb) !Args 
Jump !Int !Args 
Match !Int !(GBranch comb) 
Die String 
Exit 
NMatch !(Maybe Reference) !Int !(GBranch comb) 
RMatch !Int !(GSection comb) !(EnumMap Word64 (GBranch comb)) 

Bundled Patterns

pattern MatchT :: Int -> GSection comb -> Map Text (GSection comb) -> GSection comb 
pattern MatchW :: Int -> GSection comb -> EnumMap Word64 (GSection comb) -> GSection comb 

Instances

Instances details
Functor GSection Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

fmap :: (a -> b) -> GSection a -> GSection b #

(<$) :: a -> GSection b -> GSection a #

Foldable GSection Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

fold :: Monoid m => GSection m -> m #

foldMap :: Monoid m => (a -> m) -> GSection a -> m #

foldMap' :: Monoid m => (a -> m) -> GSection a -> m #

foldr :: (a -> b -> b) -> b -> GSection a -> b #

foldr' :: (a -> b -> b) -> b -> GSection a -> b #

foldl :: (b -> a -> b) -> b -> GSection a -> b #

foldl' :: (b -> a -> b) -> b -> GSection a -> b #

foldr1 :: (a -> a -> a) -> GSection a -> a #

foldl1 :: (a -> a -> a) -> GSection a -> a #

toList :: GSection a -> [a] #

null :: GSection a -> Bool #

length :: GSection a -> Int #

elem :: Eq a => a -> GSection a -> Bool #

maximum :: Ord a => GSection a -> a #

minimum :: Ord a => GSection a -> a #

sum :: Num a => GSection a -> a #

product :: Num a => GSection a -> a #

Traversable GSection Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

traverse :: Applicative f => (a -> f b) -> GSection a -> f (GSection b) #

sequenceA :: Applicative f => GSection (f a) -> f (GSection a) #

mapM :: Monad m => (a -> m b) -> GSection a -> m (GSection b) #

sequence :: Monad m => GSection (m a) -> m (GSection a) #

Show comb => Show (GSection comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> GSection comb -> ShowS #

show :: GSection comb -> String #

showList :: [GSection comb] -> ShowS #

Eq comb => Eq (GSection comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

(==) :: GSection comb -> GSection comb -> Bool #

(/=) :: GSection comb -> GSection comb -> Bool #

Ord comb => Ord (GSection comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

compare :: GSection comb -> GSection comb -> Ordering #

(<) :: GSection comb -> GSection comb -> Bool #

(<=) :: GSection comb -> GSection comb -> Bool #

(>) :: GSection comb -> GSection comb -> Bool #

(>=) :: GSection comb -> GSection comb -> Bool #

max :: GSection comb -> GSection comb -> GSection comb #

min :: GSection comb -> GSection comb -> GSection comb #

type RSection val = GSection (RComb val) Source #

data GComb val comb Source #

Constructors

Comb 

Fields

  • !(GCombInfo comb)
     
  • !FrameLayout

    the frame layout, when this is the body of an indirect let: the value slot and width of each wide variable of the let's frame, counting from the top (wideSlots); empty for a top-level combinator, whose arguments are one slot each

CachedVal !Word64 !val 

Bundled Patterns

pattern Lam :: Int -> Int -> GSection comb -> GComb val comb

Matches any combinator, ignoring its native code cell. Building one with this gives it the shared "never compiled" cell, so don't use it to rebuild a combinator that already has a cell of its own.

Instances

Instances details
Bifoldable GComb Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

bifold :: Monoid m => GComb m m -> m #

bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> GComb a b -> m #

bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> GComb a b -> c #

bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> GComb a b -> c #

Bifunctor GComb Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

bimap :: (a -> b) -> (c -> d) -> GComb a c -> GComb b d #

first :: (a -> b) -> GComb a c -> GComb b c #

second :: (b -> c) -> GComb a b -> GComb a c #

Bitraversable GComb Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> GComb a b -> f (GComb c d) #

Functor (GComb val) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

fmap :: (a -> b) -> GComb val a -> GComb val b #

(<$) :: a -> GComb val b -> GComb val a #

Foldable (GComb val) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

fold :: Monoid m => GComb val m -> m #

foldMap :: Monoid m => (a -> m) -> GComb val a -> m #

foldMap' :: Monoid m => (a -> m) -> GComb val a -> m #

foldr :: (a -> b -> b) -> b -> GComb val a -> b #

foldr' :: (a -> b -> b) -> b -> GComb val a -> b #

foldl :: (b -> a -> b) -> b -> GComb val a -> b #

foldl' :: (b -> a -> b) -> b -> GComb val a -> b #

foldr1 :: (a -> a -> a) -> GComb val a -> a #

foldl1 :: (a -> a -> a) -> GComb val a -> a #

toList :: GComb val a -> [a] #

null :: GComb val a -> Bool #

length :: GComb val a -> Int #

elem :: Eq a => a -> GComb val a -> Bool #

maximum :: Ord a => GComb val a -> a #

minimum :: Ord a => GComb val a -> a #

sum :: Num a => GComb val a -> a #

product :: Num a => GComb val a -> a #

Traversable (GComb val) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

traverse :: Applicative f => (a -> f b) -> GComb val a -> f (GComb val b) #

sequenceA :: Applicative f => GComb val (f a) -> f (GComb val a) #

mapM :: Monad m => (a -> m b) -> GComb val a -> m (GComb val b) #

sequence :: Monad m => GComb val (m a) -> m (GComb val a) #

(Show comb, Show val) => Show (GComb val comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> GComb val comb -> ShowS #

show :: GComb val comb -> String #

showList :: [GComb val comb] -> ShowS #

(Eq comb, Eq val) => Eq (GComb val comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

(==) :: GComb val comb -> GComb val comb -> Bool #

(/=) :: GComb val comb -> GComb val comb -> Bool #

(Ord comb, Ord val) => Ord (GComb val comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

compare :: GComb val comb -> GComb val comb -> Ordering #

(<) :: GComb val comb -> GComb val comb -> Bool #

(<=) :: GComb val comb -> GComb val comb -> Bool #

(>) :: GComb val comb -> GComb val comb -> Bool #

(>=) :: GComb val comb -> GComb val comb -> Bool #

max :: GComb val comb -> GComb val comb -> GComb val comb #

min :: GComb val comb -> GComb val comb -> GComb val comb #

data FrameLayout Source #

What a let body's combinator knows about the frame it is resumed over: the wide variables of the frame, each as (the index of its value slot from the top of the frame, its width in slots), in increasing order; and, for a section the explosion rewrote, the frames the unoptimized code has at this point, for a continuation written out (Deopt).

Constructors

FrameLayout 

Fields

  • wideVars :: [(Int, Int)]
     
  • baseFrames :: Maybe Deopt
     
  • frameDepth :: Int

    the depth of the context at the let, in slots, counting the enclosing frames when the let is inside a binding: the frame's slot j from the top is offset frameDepth - j in the liveness of the body (Live, used by the serializer)

  • enclosingLets :: Int

    how many lets of the same function the let is inside the binding of: that many Push frames outward in a continuation are the frames of those lets, which this section's code reads into

layoutPadding :: Int -> FrameLayout -> Int Source #

The slots a frame layout adds over one per variable, for a frame that holds n variables. A section inside a let's binding lists the wide variables of the enclosing frames too, below its own slots (wideSlots walks the whole context), and those are not this frame's: a wide variable at wide index i is the frame's when its narrow index, i less the padding of the wide variables above it, is below n. (Until 2026-11-02 every listed variable counted, so a frame inside a binding with a wide variable in the enclosing frame came up short.)

widePadding :: Int -> FrameLayout -> Int Source #

The same for a frame of f slots, wide.

data Deopt Source #

How a continuation's frame for a section the explosion rewrote is written out as the frames the unoptimized code has at that point (design.md, "Continuations across processes"; built by deoptOf, applied by deoptCont). The frames come innermost first, each as the index of the unoptimized section it resumes, in the group, and its slots from the top; a let whose binding the rewrite moved into the enclosing frame (sinkCalls) gives two, the binding's and the let's, and the optimized frame's pending arguments go with the last. A slot is copied from the optimized frames, by frame (0 this one, 1 the enclosing let's, counting the continuation's Push frames outward) and narrowed index from the top, or is a product the optimized code no longer holds, packed from such slots, or is dead, a slot the unoptimized code never reads there, written as unit.

Constructors

Deopt [BaseFrame] 

Instances

Instances details
Show Deopt Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> Deopt -> ShowS #

show :: Deopt -> String #

showList :: [Deopt] -> ShowS #

Eq Deopt Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

(==) :: Deopt -> Deopt -> Bool #

(/=) :: Deopt -> Deopt -> Bool #

Ord Deopt Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

compare :: Deopt -> Deopt -> Ordering #

(<) :: Deopt -> Deopt -> Bool #

(<=) :: Deopt -> Deopt -> Bool #

(>) :: Deopt -> Deopt -> Bool #

(>=) :: Deopt -> Deopt -> Bool #

max :: Deopt -> Deopt -> Deopt #

min :: Deopt -> Deopt -> Deopt #

data BaseFrame Source #

Constructors

BaseFrame !Word64 [Slot] 

Instances

Instances details
Show BaseFrame Source # 
Instance details

Defined in Unison.Runtime.MCode

Eq BaseFrame Source # 
Instance details

Defined in Unison.Runtime.MCode

Ord BaseFrame Source # 
Instance details

Defined in Unison.Runtime.MCode

data Slot Source #

Instances

Instances details
Show Slot Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> Slot -> ShowS #

show :: Slot -> String #

showList :: [Slot] -> ShowS #

Eq Slot Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

(==) :: Slot -> Slot -> Bool #

(/=) :: Slot -> Slot -> Bool #

Ord Slot Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

compare :: Slot -> Slot -> Ordering #

(<) :: Slot -> Slot -> Bool #

(<=) :: Slot -> Slot -> Bool #

(>) :: Slot -> Slot -> Bool #

(>=) :: Slot -> Slot -> Bool #

max :: Slot -> Slot -> Slot #

min :: Slot -> Slot -> Slot #

data GCombInfo comb Source #

Constructors

LamI !Int !Int !(GSection comb) !(Ptr NativeCell) 

Instances

Instances details
Functor GCombInfo Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

fmap :: (a -> b) -> GCombInfo a -> GCombInfo b #

(<$) :: a -> GCombInfo b -> GCombInfo a #

Foldable GCombInfo Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

fold :: Monoid m => GCombInfo m -> m #

foldMap :: Monoid m => (a -> m) -> GCombInfo a -> m #

foldMap' :: Monoid m => (a -> m) -> GCombInfo a -> m #

foldr :: (a -> b -> b) -> b -> GCombInfo a -> b #

foldr' :: (a -> b -> b) -> b -> GCombInfo a -> b #

foldl :: (b -> a -> b) -> b -> GCombInfo a -> b #

foldl' :: (b -> a -> b) -> b -> GCombInfo a -> b #

foldr1 :: (a -> a -> a) -> GCombInfo a -> a #

foldl1 :: (a -> a -> a) -> GCombInfo a -> a #

toList :: GCombInfo a -> [a] #

null :: GCombInfo a -> Bool #

length :: GCombInfo a -> Int #

elem :: Eq a => a -> GCombInfo a -> Bool #

maximum :: Ord a => GCombInfo a -> a #

minimum :: Ord a => GCombInfo a -> a #

sum :: Num a => GCombInfo a -> a #

product :: Num a => GCombInfo a -> a #

Traversable GCombInfo Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

traverse :: Applicative f => (a -> f b) -> GCombInfo a -> f (GCombInfo b) #

sequenceA :: Applicative f => GCombInfo (f a) -> f (GCombInfo a) #

mapM :: Monad m => (a -> m b) -> GCombInfo a -> m (GCombInfo b) #

sequence :: Monad m => GCombInfo (m a) -> m (GCombInfo a) #

Show comb => Show (GCombInfo comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> GCombInfo comb -> ShowS #

show :: GCombInfo comb -> String #

showList :: [GCombInfo comb] -> ShowS #

Eq comb => Eq (GCombInfo comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

(==) :: GCombInfo comb -> GCombInfo comb -> Bool #

(/=) :: GCombInfo comb -> GCombInfo comb -> Bool #

Ord comb => Ord (GCombInfo comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

compare :: GCombInfo comb -> GCombInfo comb -> Ordering #

(<) :: GCombInfo comb -> GCombInfo comb -> Bool #

(<=) :: GCombInfo comb -> GCombInfo comb -> Bool #

(>) :: GCombInfo comb -> GCombInfo comb -> Bool #

(>=) :: GCombInfo comb -> GCombInfo comb -> Bool #

max :: GCombInfo comb -> GCombInfo comb -> GCombInfo comb #

min :: GCombInfo comb -> GCombInfo comb -> GCombInfo comb #

data NativeCell Source #

A native code cell (see unison-runtimesrcUnisonRuntimeJIT/design.md): the mutable part of a combinator, 40 bytes outside the Haskell heap, never moved and never freed, so generated code can refer to it by address. As a C struct:

struct cell {
  void    *code;    // offset 0: the compiled entry point, NULL until compiled
  int64_t  count;   // offset 8: calls made while code was NULL
  int64_t  state;   // offset 16: 0 not yet requested, 1 queued, 2 taken by the compile thread
  int64_t  verdict; // offset 24: whether it is worth compiling (see readNativeVerdict)
  void    *entry;   // offset 32: the register entry, for native callers in other modules
};

The state only moves forward, so a combinator is asked for only once. The layout is a contract between two readers: this module (the and accessors below, at those offsets) and the generated code, which loads at offset 0 or at offset 32 to call through a cell and writes @ at offset 8 (JIT/Codegen.hs); nothing in the C runtime reads a cell. The register entry is a function with the signature native code agrees on across modules for the combinator's arity (design.md, "The register entry"): null when the combinator is not compiled, or compiled without a worker.

The count starts at minus the JIT's compilation threshold when the JIT compiles what gets hot, so that "hot" is the count reaching zero: the interpreter's test is one comparison with a constant. A count that starts at zero or above never gets there.

readNativeCode :: Ptr NativeCell -> IO (Ptr ()) Source #

Reads the compiled code pointer of a cell. Null means "interpret". An atomic (acquire) load: the compile thread writes a module's pool entries and exit and frame tables before it publishes the code pointer, and an interpreter thread that sees the pointer must then see those too, which on a weakly ordered machine (arm64) a plain load does not promise (an ldar, a few cycles on an entry that costs tens of nanoseconds).

readNativeEntry :: Ptr NativeCell -> IO (Ptr ()) Source #

The compiled code the interpreter should enter, if any. Null means "interpret": there is no code, or the function is so small that getting into native code and back costs more than interpreting it (verdict 3; native callers still call it directly).

writeNativeCode :: Ptr NativeCell -> Ptr () -> IO () Source #

Installs compiled code. A single atomic (release) pointer write: readers on other threads see either the old value or the new one, and a reader that sees the new one sees everything the compile thread wrote before it (see readNativeCode).

bumpNativeCount :: Ptr NativeCell -> IO Bool Source #

Counts a call made while the cell had no compiled code, and says whether that made it hot (the count reached zero). Not atomic; a lost count under contention does not matter.

writeNativeCount :: Ptr NativeCell -> Int -> IO () Source #

Sets a cell's count: negative, to make it hot after that many more calls.

claimNativeCell :: Ptr NativeCell -> IO Bool Source #

Marks the cell as requested (state 0 to 1), atomically, and says whether this call was the one that did. Whoever does owns the request, and queues it.

nativeRegisterEntryOffset :: Int Source #

The offset of the register entry in a cell, for the generated code.

writeNativeRegisterEntry :: Ptr NativeCell -> Ptr () -> IO () Source #

Installs the register entry (null for none), the same way as the code pointer; written before the code pointer, so that a thread which sees the code sees the entry.

releaseNativeCell :: Ptr NativeCell -> IO () Source #

Puts the state back to 0: for a request that could not be queued.

takeNativeCell :: Ptr NativeCell -> IO Bool Source #

The compile thread takes the cell (state 2), whether it was requested or not, and says whether this call was the one that did. A combinator that is taken is being compiled, or has been, or can't be. A request found already taken when it comes off the queue is dropped: its combinator went into an earlier batch.

nativeCellRequested :: Ptr NativeCell -> IO Bool Source #

Whether a request for the cell is queued.

readNativeVerdict :: Ptr NativeCell -> IO Int Source #

What the JIT has decided about compiling the cell's combinator. Zero: nothing yet. Otherwise the low two bits say: 1 worth compiling, 2 better left to the interpreter, because native code for it would spend its time leaving native code, 3 worth compiling for native callers but too small to be worth entering from the interpreter. The bits above hold an estimate the JIT keeps for judging callers (see JIT.Estimate). Only the thread that compiles writes this; the interpreter reads it when it finds code in the cell.

data NativeCellPool Source #

Cells are handed out from a pool, so that loading code (an STM transaction) never has to allocate memory: a retried transaction would leak it. The pool is a block of cells and a count of how many are in use. When it runs out, a new block is allocated outside the transaction with growNativeCellPool. Old blocks stay in use, and are never freed.

Constructors

NativeCellPool !(Ptr NativeCell) !Int !Int 

newNativeCells :: Int -> IO (Ptr NativeCell) Source #

Allocates zeroed cells for n combinators, as one block that is never freed.

nativeCellAt :: Ptr NativeCell -> Int -> Ptr NativeCell Source #

The cell at index i of a block from newNativeCells.

takeNativeCells :: Int -> NativeCellPool -> Maybe (Ptr NativeCell, NativeCellPool) Source #

Takes n cells from the pool, or fails if it has fewer left.

growNativeCellPool :: Int -> Int -> NativeCellPool -> IO NativeCellPool Source #

A fresh block with room for at least n cells, and at least twice the old capacity so that growing stays rare.

noNativeCell :: Ptr NativeCell Source #

A shared cell for combinators that are never compiled: builtins, and combinators that were not loaded through the code cache.

attachNativeCells :: Ptr NativeCell -> EnumMap Word64 (GCombs val comb) -> (Int, EnumMap Word64 (GCombs val comb)) Source #

Gives every combinator in a group of freshly loaded code its own cell from base, numbering them in order. Returns the count used.

newtype RComb val Source #

The fixed point of a GComb where all references to a Comb are themselves Combs.

Constructors

RComb 

Fields

Instances

Instances details
Show (RComb val) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> RComb val -> ShowS #

show :: RComb val -> String #

showList :: [RComb val] -> ShowS #

type RCombInfo val = GCombInfo (RComb val) Source #

type GCombs val comb = EnumMap Word64 (GComb val comb) Source #

Map of combinators, parameterized by comb reference type

type RCombs val = GCombs val (RComb val) Source #

data CombIx Source #

Constructors

CIx !Reference !Word64 !Word64 

Instances

Instances details
Show CombIx Source # 
Instance details

Defined in Unison.Runtime.MCode

Eq CombIx Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

(==) :: CombIx -> CombIx -> Bool #

(/=) :: CombIx -> CombIx -> Bool #

Ord CombIx Source # 
Instance details

Defined in Unison.Runtime.MCode

data GRef comb Source #

Constructors

Stk !Int 
Env !CombIx comb 
Dyn !Word64 

Instances

Instances details
Functor GRef Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

fmap :: (a -> b) -> GRef a -> GRef b #

(<$) :: a -> GRef b -> GRef a #

Foldable GRef Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

fold :: Monoid m => GRef m -> m #

foldMap :: Monoid m => (a -> m) -> GRef a -> m #

foldMap' :: Monoid m => (a -> m) -> GRef a -> m #

foldr :: (a -> b -> b) -> b -> GRef a -> b #

foldr' :: (a -> b -> b) -> b -> GRef a -> b #

foldl :: (b -> a -> b) -> b -> GRef a -> b #

foldl' :: (b -> a -> b) -> b -> GRef a -> b #

foldr1 :: (a -> a -> a) -> GRef a -> a #

foldl1 :: (a -> a -> a) -> GRef a -> a #

toList :: GRef a -> [a] #

null :: GRef a -> Bool #

length :: GRef a -> Int #

elem :: Eq a => a -> GRef a -> Bool #

maximum :: Ord a => GRef a -> a #

minimum :: Ord a => GRef a -> a #

sum :: Num a => GRef a -> a #

product :: Num a => GRef a -> a #

Traversable GRef Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

traverse :: Applicative f => (a -> f b) -> GRef a -> f (GRef b) #

sequenceA :: Applicative f => GRef (f a) -> f (GRef a) #

mapM :: Monad m => (a -> m b) -> GRef a -> m (GRef b) #

sequence :: Monad m => GRef (m a) -> m (GRef a) #

Show comb => Show (GRef comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> GRef comb -> ShowS #

show :: GRef comb -> String #

showList :: [GRef comb] -> ShowS #

Eq (GRef comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

(==) :: GRef comb -> GRef comb -> Bool #

(/=) :: GRef comb -> GRef comb -> Bool #

Ord (GRef comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

compare :: GRef comb -> GRef comb -> Ordering #

(<) :: GRef comb -> GRef comb -> Bool #

(<=) :: GRef comb -> GRef comb -> Bool #

(>) :: GRef comb -> GRef comb -> Bool #

(>=) :: GRef comb -> GRef comb -> Bool #

max :: GRef comb -> GRef comb -> GRef comb #

min :: GRef comb -> GRef comb -> GRef comb #

type RRef val = GRef (RComb val) Source #

type Ref = GRef CombIx Source #

A reference to a combinator, parameterized by comb

data Prim1 Source #

Instances

Instances details
Bounded Prim1 Source # 
Instance details

Defined in Unison.Runtime.MCode

Enum Prim1 Source # 
Instance details

Defined in Unison.Runtime.MCode

Show Prim1 Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> Prim1 -> ShowS #

show :: Prim1 -> String #

showList :: [Prim1] -> ShowS #

Eq Prim1 Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

(==) :: Prim1 -> Prim1 -> Bool #

(/=) :: Prim1 -> Prim1 -> Bool #

Ord Prim1 Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

compare :: Prim1 -> Prim1 -> Ordering #

(<) :: Prim1 -> Prim1 -> Bool #

(<=) :: Prim1 -> Prim1 -> Bool #

(>) :: Prim1 -> Prim1 -> Bool #

(>=) :: Prim1 -> Prim1 -> Bool #

max :: Prim1 -> Prim1 -> Prim1 #

min :: Prim1 -> Prim1 -> Prim1 #

Tag Prim1 Source # 
Instance details

Defined in Unison.Runtime.Serialize

Methods

tag2word :: Prim1 -> Word8 Source #

word2tag :: forall (m :: Type -> Type). PrimBase m => Word8 -> Get m Prim1 Source #

data Prim2 Source #

Instances

Instances details
Bounded Prim2 Source # 
Instance details

Defined in Unison.Runtime.MCode

Enum Prim2 Source # 
Instance details

Defined in Unison.Runtime.MCode

Show Prim2 Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> Prim2 -> ShowS #

show :: Prim2 -> String #

showList :: [Prim2] -> ShowS #

Eq Prim2 Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

(==) :: Prim2 -> Prim2 -> Bool #

(/=) :: Prim2 -> Prim2 -> Bool #

Ord Prim2 Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

compare :: Prim2 -> Prim2 -> Ordering #

(<) :: Prim2 -> Prim2 -> Bool #

(<=) :: Prim2 -> Prim2 -> Bool #

(>) :: Prim2 -> Prim2 -> Bool #

(>=) :: Prim2 -> Prim2 -> Bool #

max :: Prim2 -> Prim2 -> Prim2 #

min :: Prim2 -> Prim2 -> Prim2 #

Tag Prim2 Source # 
Instance details

Defined in Unison.Runtime.Serialize

Methods

tag2word :: Prim2 -> Word8 Source #

word2tag :: forall (m :: Type -> Type). PrimBase m => Word8 -> Get m Prim2 Source #

data GBranch comb Source #

Constructors

Test1 !Word64 !(Arm comb) !(GSection comb) 
Test2 !Word64 !(Arm comb) !Word64 !(Arm comb) !(GSection comb) 
TestW !(GSection comb) !(EnumMap Word64 (Arm comb)) 
TestT !(GSection comb) !(Map Text (GSection comb)) 
TestY !(GSection comb) !(Map Bytes (GSection comb)) 

Instances

Instances details
Functor GBranch Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

fmap :: (a -> b) -> GBranch a -> GBranch b #

(<$) :: a -> GBranch b -> GBranch a #

Foldable GBranch Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

fold :: Monoid m => GBranch m -> m #

foldMap :: Monoid m => (a -> m) -> GBranch a -> m #

foldMap' :: Monoid m => (a -> m) -> GBranch a -> m #

foldr :: (a -> b -> b) -> b -> GBranch a -> b #

foldr' :: (a -> b -> b) -> b -> GBranch a -> b #

foldl :: (b -> a -> b) -> b -> GBranch a -> b #

foldl' :: (b -> a -> b) -> b -> GBranch a -> b #

foldr1 :: (a -> a -> a) -> GBranch a -> a #

foldl1 :: (a -> a -> a) -> GBranch a -> a #

toList :: GBranch a -> [a] #

null :: GBranch a -> Bool #

length :: GBranch a -> Int #

elem :: Eq a => a -> GBranch a -> Bool #

maximum :: Ord a => GBranch a -> a #

minimum :: Ord a => GBranch a -> a #

sum :: Num a => GBranch a -> a #

product :: Num a => GBranch a -> a #

Traversable GBranch Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

traverse :: Applicative f => (a -> f b) -> GBranch a -> f (GBranch b) #

sequenceA :: Applicative f => GBranch (f a) -> f (GBranch a) #

mapM :: Monad m => (a -> m b) -> GBranch a -> m (GBranch b) #

sequence :: Monad m => GBranch (m a) -> m (GBranch a) #

Show comb => Show (GBranch comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> GBranch comb -> ShowS #

show :: GBranch comb -> String #

showList :: [GBranch comb] -> ShowS #

Eq comb => Eq (GBranch comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

(==) :: GBranch comb -> GBranch comb -> Bool #

(/=) :: GBranch comb -> GBranch comb -> Bool #

Ord comb => Ord (GBranch comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

compare :: GBranch comb -> GBranch comb -> Ordering #

(<) :: GBranch comb -> GBranch comb -> Bool #

(<=) :: GBranch comb -> GBranch comb -> Bool #

(>) :: GBranch comb -> GBranch comb -> Bool #

(>=) :: GBranch comb -> GBranch comb -> Bool #

max :: GBranch comb -> GBranch comb -> GBranch comb #

min :: GBranch comb -> GBranch comb -> GBranch comb #

data Arm comb Source #

A case of a branch: the fields it binds and its code.

Constructors

Arm !ConstructorArity !(GSection comb) 

Instances

Instances details
Functor Arm Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

fmap :: (a -> b) -> Arm a -> Arm b #

(<$) :: a -> Arm b -> Arm a #

Foldable Arm Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

fold :: Monoid m => Arm m -> m #

foldMap :: Monoid m => (a -> m) -> Arm a -> m #

foldMap' :: Monoid m => (a -> m) -> Arm a -> m #

foldr :: (a -> b -> b) -> b -> Arm a -> b #

foldr' :: (a -> b -> b) -> b -> Arm a -> b #

foldl :: (b -> a -> b) -> b -> Arm a -> b #

foldl' :: (b -> a -> b) -> b -> Arm a -> b #

foldr1 :: (a -> a -> a) -> Arm a -> a #

foldl1 :: (a -> a -> a) -> Arm a -> a #

toList :: Arm a -> [a] #

null :: Arm a -> Bool #

length :: Arm a -> Int #

elem :: Eq a => a -> Arm a -> Bool #

maximum :: Ord a => Arm a -> a #

minimum :: Ord a => Arm a -> a #

sum :: Num a => Arm a -> a #

product :: Num a => Arm a -> a #

Traversable Arm Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

traverse :: Applicative f => (a -> f b) -> Arm a -> f (Arm b) #

sequenceA :: Applicative f => Arm (f a) -> f (Arm a) #

mapM :: Monad m => (a -> m b) -> Arm a -> m (Arm b) #

sequence :: Monad m => Arm (m a) -> m (Arm a) #

Show comb => Show (Arm comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

showsPrec :: Int -> Arm comb -> ShowS #

show :: Arm comb -> String #

showList :: [Arm comb] -> ShowS #

Eq comb => Eq (Arm comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

(==) :: Arm comb -> Arm comb -> Bool #

(/=) :: Arm comb -> Arm comb -> Bool #

Ord comb => Ord (Arm comb) Source # 
Instance details

Defined in Unison.Runtime.MCode

Methods

compare :: Arm comb -> Arm comb -> Ordering #

(<) :: Arm comb -> Arm comb -> Bool #

(<=) :: Arm comb -> Arm comb -> Bool #

(>) :: Arm comb -> Arm comb -> Bool #

(>=) :: Arm comb -> Arm comb -> Bool #

max :: Arm comb -> Arm comb -> Arm comb #

min :: Arm comb -> Arm comb -> Arm comb #

type ConstructorArity = Int Source #

How many fields a match arm binds: the number of slots emitCase lays the arm's context out with. A data or request match's arm carries it (Arm), because it is the one thing about an arm that the object being matched cannot say: the interpreter pushes the object's own fields and runs the arm only when their count is the arm's (dataBranch), and native code reads the object's count (its pointer tag, or the lengths of a wide constructor's arrays) and takes the arm only when the two agree. The arms of a match on an unboxed value bind no fields (0).

armSection :: Arm comb -> GSection comb Source #

type RBranch val = GBranch (RComb val) Source #

emptyRecordFieldMappings :: RecordFieldMappings Source #

No field names assigned yet. The starting state for emitCombs and friends, in the same spirit as emptyRNs.

convertFieldNamesToRefs :: (MonadState RecordFieldMappings m, Traversable f) => f FieldName -> m (f FieldRef) Source #

Note that the Ord instance for Field Refs is arbitrary and not tied to the field name Ord instance.

emitCombs :: Var v => RefNums -> Reference -> Word64 -> Word64 -> SuperGroup Reference v -> State RecordFieldMappings (EnumMap Word64 Comb, Maybe (EnumMap Word64 Comb)) Source #

The combinators of a group, under its number, and, when the explosion rewrote any of its lambdas so that a frame differs, the group as the unoptimized code has it, under the second number: what a continuation written out by this process resumes in another, and what one from another process resumes here (design.md, "Continuations across processes").

emptyRCtx :: RCtx v Source #

resolveCombs :: Maybe (EnumMap Word64 (RCombs val)) -> EnumMap Word64 (GCombs val CombIx) -> EnumMap Word64 (RCombs val) Source #

lazily replace all references to combinators with the combinators themselves, tying the knot recursively when necessary.

sanitizeCombsOfForeignFuncs :: Bool -> Set ForeignFunc -> EnumMap Word64 (EnumMap Word64 (GComb Void CombIx)) -> EnumMap Word64 (EnumMap Word64 (GComb Void CombIx)) Source #

If running in a sandboxed environment, replace all restricted foreign functions with an error.

pushCount :: GInstr comb -> Maybe Int Source #

How many slots an instruction pushes onto the frame, or Nothing where the interpreter takes over from here (a capture, a sandboxing failure). The one account of an instruction's effect on the frame: the JIT's code generator lays frames out by it and resultCount counts a primitive's results by it, so the two cannot disagree.

combDeps :: GComb val comb -> [Word64] Source #

combTypes :: GComb any comb -> [Word64] Source #

prettyComb :: (Show val, Show comb) => Word64 -> Word64 -> GComb val comb -> ShowS Source #

prettySection :: Show comb => Int -> GSection comb -> ShowS Source #

prettyIns :: Show comb => GInstr comb -> ShowS Source #