Skip to content

Commit 4b83841

Browse files
committed
WIP: misc
- service process - CC-guided implementation of Hash Array Mapped Trie (HAMT) that exposed some missing basic functions but also exposes further opportunities for optimization, i.e., in RawOpt.
1 parent dd8f228 commit 4b83841

File tree

20 files changed

+995
-19
lines changed

20 files changed

+995
-19
lines changed

.experiments/whats-next.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
# What's next
22

33

4+
5+
46
## Infra
57

68

9+
[ ] Implement spawn as the top level primitive that does all
10+
the pattern matching and then calls into local_spawn when needed.
11+
12+
[ ] Look into making HAMT faster
13+
14+
[ ] Inline one-time declared joins (maybe? | this needs profiling)
15+
16+
717
## Integrity
818

919
- [ ] Integrity of blocking and mailboxes

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ libs:
3030
$(COMPILER) ./lib/raft_debug.trp -l
3131
$(COMPILER) ./lib/bst.trp -l
3232
$(COMPILER) ./lib/localregistry.trp -l
33+
$(COMPILER) ./lib/hamt.trp -l
3334

3435
service:
3536
$(COMPILER) ./trp-rt/service.trp -l

compiler/src/IR.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ instance WellFormedIRCheck IRExpr where
274274
, "blockendorseto"
275275
, "ceil"
276276
, "cert"
277+
, "charCodeAtWithDefault"
277278
, "consume"
278279
, "_debug"
279280
, "debugpc"
@@ -289,6 +290,7 @@ instance WellFormedIRCheck IRExpr where
289290
, "getType"
290291
, "getNanoTime"
291292
, "getStdout"
293+
, "_getSystemProcess"
292294
, "guard"
293295
, "inputLine"
294296
, "intToString"
@@ -330,6 +332,7 @@ instance WellFormedIRCheck IRExpr where
330332
, "sqrt"
331333
, "substring"
332334
, "stringToInt"
335+
, "strlen"
333336
, "restore"
334337
, "toStringL"
335338
, "toString"

compiler/src/Raw.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,9 @@ qqFields fields =
309309

310310
ppIR :: RawInst -> PP.Doc
311311
ppIR SetBranchFlag = text "<setbranchflag>"
312-
ppIR (AssignRaw vn st) = ppId vn <+> text "=" <+> ppRawExpr st
312+
ppIR (AssignRaw vn st) = ppId vn <+> text "=(raw)" <+> ppRawExpr st
313313
ppIR (AssignLVal vn expr) =
314-
ppId vn <+> text "=" <+> ppRawExpr expr
314+
ppId vn <+> text "=(lval)" <+> ppRawExpr expr
315315
-- ppIR (ConstructLVal x v lv lt) =
316316
-- ppId x <+> text
317317
ppIR (RTAssertion a) = ppRTAssertion a

compiler/src/RawOpt.hs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import IR ( Identifier(..)
2222
import qualified Data.List
2323
import qualified Data.Ord
2424

25+
import Debug.Trace
2526
--------------------------------------------------
2627
-- substitutions for Raw
2728
--------------------------------------------------
@@ -300,7 +301,7 @@ pevalInst i = do
300301
markUsed v
301302
let m0 = stateLVals pstate
302303
let m1 = Map.insert (v, field) r m0
303-
put $ pstate { stateLVals = m1 }
304+
put $ pstate { stateLVals = m1 }
304305
AssignRaw r rexpr -> _keep $ do
305306
markUsed rexpr
306307
case guessType rexpr of
@@ -489,7 +490,23 @@ instance PEval RawBBTree where
489490
funopt :: FunDef -> FunDef
490491
funopt (FunDef hfn consts bb ir) =
491492

492-
let constTypes = foldl (\m (x, lit) ->
493+
let
494+
(m_consts, m_subst) = foldl (\(m1, m2) (x,lit) ->
495+
case Map.lookup lit m1 of
496+
Just r -> (m1, Map.insert x r m2 )
497+
Nothing -> (Map.insert lit x m1, m2 )
498+
) (Map.empty, Map.empty) consts
499+
500+
(consts', constTypes) = Map.foldrWithKey (\lit x (acc,m) ->
501+
let new_acc = (x, lit) : acc
502+
new_m = case typeOfLit lit of
503+
Just t -> Map.insert x t m
504+
Nothing -> m
505+
in (new_acc, new_m))
506+
([],Map.empty)
507+
m_consts
508+
509+
constTypes_obs = foldl (\m (x, lit) ->
493510
case typeOfLit lit of
494511
Just t -> Map.insert x t m
495512
Nothing -> m
@@ -498,12 +515,12 @@ funopt (FunDef hfn consts bb ir) =
498515
pstate = PState {stateMon = Map.empty,
499516
stateLVals = Map.empty,
500517
stateJoins = Map.empty,
501-
stateSubst = Subst (Map.empty),
518+
stateSubst = Subst (m_subst),
502519
stateChange = False,
503520
stateTypes = constTypes
504521
}
505522
(bb', _, _) = runRWS (peval bb) () pstate
506-
new = FunDef hfn consts bb' ir
523+
new = FunDef hfn consts' bb' ir
507524
in if bb /= bb' then funopt new else new
508525

509526

0 commit comments

Comments
 (0)