Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e0745bb
added feature to reset explicit region
mikkelwillen Dec 9, 2025
0f20fab
rm bloat
mikkelwillen Dec 9, 2025
2f51303
Christmas cleanup 2025 (#199)
melsman Dec 16, 2025
9d96f1e
change linker flags on macos
melsman Dec 16, 2025
76c0681
increase timeout on job step
melsman Dec 16, 2025
023e9b9
new version
melsman Dec 16, 2025
5b71716
added funtionality: ccall can take explicit region parameters, and ex…
mikkelwillen Jan 21, 2026
ebf5058
distribute mlkit-generated executable
melsman Jan 9, 2026
44e60f7
bump version
melsman Jan 9, 2026
f9193ac
fix missing chararray in type environment during intermediate languag…
melsman Jan 10, 2026
abb659d
new version
melsman Jan 10, 2026
5fb2ab4
fix issue with string-list options (#201)
melsman Jan 11, 2026
ecf8db1
Save lnkfile also when content is unchanged (#202)
melsman Jan 13, 2026
41a18a4
new release
melsman Jan 13, 2026
8b01627
January cleanup (#203)
melsman Jan 15, 2026
b281ae4
new version
melsman Jan 15, 2026
5ae55ff
added invariant tests
mikkelwillen Feb 9, 2026
937ea92
removed `getThreadNumAllocatedPages` and related functions + added ad…
mikkelwillen Feb 9, 2026
2ab60cb
changes
mikkelwillen Mar 9, 2026
1e4eac8
added simpleio function, so we can read to nonglobal region
mikkelwillen Mar 13, 2026
c502d6b
REML signature matching (#204)
melsman Feb 13, 2026
0b36110
optimiser: transform calls to imported functions also when optimisati…
melsman Feb 16, 2026
7414dde
Fix layout of LambdaExp string patterns (#205)
Skyb0rg007 Feb 16, 2026
0537be1
added feature to reset explicit region
mikkelwillen Dec 9, 2025
8c17376
removed `getThreadNumAllocatedPages` and related functions + added ad…
mikkelwillen Feb 9, 2026
0b5b3f8
added Prof support for region info functions
mikkelwillen Mar 20, 2026
9290bc7
updated timeToGC to take the unpacked type as input
mikkelwillen Apr 3, 2026
f7d01e9
updated size to only count data in regions
mikkelwillen Apr 3, 2026
c0556ce
added a few more explicit region tests
mikkelwillen Apr 4, 2026
b4a8a90
added more tests
mikkelwillen Apr 4, 2026
2831af9
Delete gitDiffs.txt
mikkelwillen Apr 14, 2026
ef2bb2e
Delete flags.txt
mikkelwillen Apr 14, 2026
c81fcc3
Delete .gitignore.swp
mikkelwillen Apr 14, 2026
b1e2f6d
Delete run
mikkelwillen Apr 14, 2026
e212ee2
more pdfs, changes to example, renamed region module
mikkelwillen Jun 5, 2026
9a1ba87
more pdfs, changes to example, renamed region module
mikkelwillen Jun 5, 2026
2f6c94e
Merge remote-tracking branch 'upstream/master'
mikkelwillen Jun 5, 2026
e476787
removed a file
mikkelwillen Jun 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ lib
config.log
config.status
configure
*~
src/.ccls-cache
*~
56 changes: 56 additions & 0 deletions basis/REGION.sig
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
(** Operations and information about regions. *)

signature REGION =
sig
(* \/ r. r * unit -> unit *)
val resetRegion : unit -> unit


(* \/ r. r * unit -> bool *)
val isAtbot : unit -> bool

(* \/ r. r * unit -> int *)
val numPagesOfRegion : unit -> int

(* \/ r. r * unit -> int *)
val memoryUsageOfRegion : unit -> int


val getPageSizeBytes : unit -> int

val getNumAllocatedPages : unit -> int

val getFreeListSize: unit -> int


val getThreadFreeListSize : unit -> int

val giveThreadFreeListToGlobal : unit -> unit
end

(**
[resetRegion [r] ()] resets the explicit region parameter. Warnings will be
generated if there are any live references into the region, but the region will
still be reset. This operation it thus not guaranteed to be sound.


[isAtbot [r] ()] returns true if the explicit region parameter is at bottom.

[memoryUsage [r] ()] returns an integer describing the memory usage (in bytes)
of the explicit region parameter.

[numPages [r] ()] returns the number of pages allocated to the explicit region


[getPageSizeBytes ()] returns the size of a memory page (in bytes).

[getNumAllocatedPages ()] returns the total number of allocated pages, including
free list.

[getFreeListSize ()] returns the size of the global free list (in number of pages).


[getThreadFreeListSize ()] returns the size of the thread-local free list (in number of pages). If the program is single-threaded, this is equivalent to getFreeListSize ().

[giveThreadFreeListToGlobal] gives pages of thread local free list back to global free list.
*)
25 changes: 25 additions & 0 deletions basis/Region.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(* Region.sml *)

structure Region : REGION =
struct
fun resetRegion `[r] () = prim `[r] ("resetRegion", ())


fun isAtbot `[r] () = prim `[r] ("is_Atbot", ())

fun numPagesOfRegion `[r] () = prim `[r] ("num_Pages", ())

fun memoryUsageOfRegion `[r] () = prim `[r] ("get_Region_Memory_Usage_Bytes", ())


fun getPageSizeBytes () = prim ("get_Page_Size_Bytes", ())

fun getNumAllocatedPages () = prim ("get_Num_Allocated_Pages", ())

fun getFreeListSize () = prim ("get_Free_List_Size", ())


fun getThreadFreeListSize () = prim ("get_Thread_Free_List_Size", ())

fun giveThreadFreeListToGlobal () = prim ("give_Thread_Free_List_To_Global", ())
end
Empty file added basis/Regions.sml
Empty file.
2 changes: 2 additions & 0 deletions basis/basis-reml.mlb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
basis.mlb
reml.mlb
1 change: 1 addition & 0 deletions basis/par-reml.mlb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local
basis.mlb
in
reml.mlb
THREAD.sig
ThreadSeq.sml
Thread-reml.sml
Expand Down
6 changes: 6 additions & 0 deletions basis/reml.mlb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local
basis.mlb
in
REGION.sig
Region.sml
end
2,473 changes: 2,473 additions & 0 deletions examples/fragAssembling/big_test_packets.txt

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions examples/fragAssembling/driver.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
signature SERVICE =
sig
type serviceState
type conn = int
val service : serviceState * conn * string -> conn option * serviceState
val emptySs : unit -> serviceState
val timeToGC : serviceState -> bool
val copySs : serviceState -> serviceState
en

signature DRIVER =
sig
val run : string -> unit
end

functor Driver (structure TcpState: TCP_STATE
structure Service: SERVICE) :> DRIVER =
struct
open TcpState
open SimpleIO

exception EOF

(* read line from file. (msgID, packetID, data) *)
fun read is =
case inputLine is of
NONE => NONE
| SOME line =>
case String.fields (fn c => c = #";") line of
(msgID::pkID::rest) => (
case (Int.fromString msgID, Int.fromString pkID) of
(SOME msgID', SOME pkID') => SOME
(msgID', (pkID', String.concatWith ";" rest))
| (_, _) => NONE
)
| _ => NONE

fun loop is (arg as (state, ss)) =
let val arg' =
case read is of
NONE => raise EOF
| SOME (msgID, packet) =>
case insert (msgID, packet, state) of
NONE => arg
| SOME state1 =>
(case extract state1 of
NONE => (print ("state size: " ^ Int.toString (stateSize state1) ^ " bytes\n");
(state1, ss))
| SOME (msgID, msg, state2) =>
let
val msg' = msg ^ ""
val (connOpt, ss') = Service.service (ss, msgID, msg')

(* Double copy GC on the assemlber state *)
(* val state' = if stateSize state2 > 10000 then *)
(* let val temp = copyState state2 *)
(* val _ = forceResetting state2 *)
(* val _ = forceResetting state *)
(* val _ = print ("state size: " ^ Int.toString (stateSize state2) ^ " bytes\n") *)
(* in copyState temp *)
(* end *)
(* else state2 *)
(* val _ = print ("state size: " ^ Int.toString (stateSize state') ^ " bytes\n") *)
val temp = copyState state2
val _ = forceResetting state
val state' = copyState temp
val state'' =
case connOpt of
NONE => state'
| SOME conn => closeConn (conn, state')
(* val _ = print ("state size: " ^ Int.toString (stateSize state'') ^ " bytes\n") *)

(* Double copy GC on the service state *)
val ss'' = if Service.timeToGC ss' then
let val temp = Service.copySs ss'
val _ = forceResetting ss'
in Service.copySs temp
end
else ss'
in
(state'', ss'')
end
)
in loop is arg'
end


fun run file =
let
val is = openIn file
val state = emptyState ()
val serviceState = Service.emptySs ()
in
(loop is (state, serviceState) handle EOF => (
closeIn is;
print ("Service loop exited\n")
)
)
end
end

Binary file added examples/fragAssembling/profile.rp
Binary file not shown.
Binary file added examples/fragAssembling/region.pdf
Binary file not shown.
Binary file added examples/fragAssembling/region.ps
Binary file not shown.
Binary file added examples/fragAssembling/regionBGC.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionCT.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionDB.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionF.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionFunTest.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionGC.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionMerge.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionModule.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionModule10.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionModule2.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionN.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionNF.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionNoGC.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionSS.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionSimpleIO.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionSsGC.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionUB.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionUBB.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionUBGC.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionWhile.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionX4.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regionold.pdf
Binary file not shown.
Binary file added examples/fragAssembling/regiontailLoop.pdf
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/fragAssembling/service.mlb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$(SML_LIB)/basis/reml.mlb
size.sig
service.sml
90 changes: 90 additions & 0 deletions examples/fragAssembling/service.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
(*
* service.sml
*
* Maintains per-connection partial prefixes until a message is complete.
* A message is considered complete when two newlines: "\n\n", are found.

* When a message completes, it is printed to stdout and removed from the
* service state.
*)

structure Service : SERVICE =
struct
type conn = int
type serviceState = (conn * string) list

fun emptySs () : serviceState = []

(* removeConn removes the entry for connection c from the state, if it exists *)
fun removeConn (_: conn, []: serviceState) = []
| removeConn (c, (c',buf)::rest) =
if c = c' then rest else (c',buf)::removeConn (c, rest)

(* lookupConn looks up the buffer for connection c in the state, returning
SOME buf if found, or NONE if not found *)
fun lookupConn (_: conn, []: serviceState) = NONE
| lookupConn (c, (c',buf)::rest) =
if c = c' then SOME buf else lookupConn (c, rest)

(* addConn adds chunk to the buffer for connection c, or creates a new entry
if c is not in the state *)
fun addConn (c, chunk, ss) =
let
fun appendChunk (_: conn, _: string, []: serviceState) = []
| appendChunk (c, chunk, (c',buf)::rest) =
if c = c' then (c, buf ^ chunk)::rest else (c',buf)::appendChunk (c, chunk, rest)
in
case lookupConn (c, ss) of
SOME _ => appendChunk (c, chunk, ss)
| NONE => (c, chunk) :: ss
end

(* Check if string s contains "\n\n". Returns SOME s', where s' is the string
up untill "\n\n", and NONE otherwise *)
fun findEnd (s:string) : string option =
let
fun go (i:int) =
if i >= String.size s - 1 then NONE
else if String.substring (s, i, 2) = "\n\n" then
SOME (String.substring (s, 0, i + 2))
else go (i + 1)
in
go 0
end

fun copySs [] = []
| copySs ((c, buf)::rest) = (c, buf ^ "") :: copySs rest

fun timeToGC`[r1 r2 r3] (ss : (conn * string`r1)`r3 list`r2) : bool =
let val total = Region.memoryUsageOfRegion `[r1] ()
+ Region.memoryUsageOfRegion `[r2] ()
+ Region.memoryUsageOfRegion `[r3] ()
val live = Size.size (Size.list (Size.tup2 Size.int Size.string)) ss
in live * 10 < total
end
(* fun timeToGC ss = false *)

(* fun timeToGC `[r1 r2 r3] (ss : (conn * string`r1)`r3 list`r2) : bool = *)
(* let val total = Region.memoryUsageOfRegion `[r1] () *)
(* + Region.memoryUsageOfRegion `[r2] () *)
(* + Region.memoryUsageOfRegion `[r3] () *)
(* in if total < 1000000 then false *)
(* else *)
(* let val live = Size.size (Size.list (Size.tup2 Size.int Size.string)) ss *)
(* in live * 4 < total *)
(* end *)
(* end *)

fun service (ss, c, chunk) =
let val tempState = addConn (c, chunk, ss)
in
case lookupConn (c, tempState) of
SOME buf =>
(case findEnd buf of
SOME s =>
(print ("msg is: \n" ^ s);
(SOME c, removeConn (c, tempState)))
| NONE => (NONE, tempState))
| NONE => (NONE, tempState)
end
end
10 changes: 10 additions & 0 deletions examples/fragAssembling/service_driver.mlb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local
$(SML_LIB)/basis/basis-reml.mlb
tcp_state.sig
simpleio.mlb
size.mlb
in
tcp_state.sml
driver.sml
service.sml
end
2 changes: 2 additions & 0 deletions examples/fragAssembling/simpleio.mlb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$(SML_LIB)/basis/basis.mlb
simpleio.sml
36 changes: 36 additions & 0 deletions examples/fragAssembling/simpleio.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(* A simple I/O library *)

structure SimpleIO = struct
type instream = {ic: int, name: string}

exception CannotOpen

fun getCtx () : foreignptr = prim("__get_ctx",())

fun chr_unsafe (i:int):char = prim ("id", i)

fun input1_ (ic:int) : int = prim ("input1Stream", ic)

fun input1 ({ic, name} : instream) : char option =
let val res = input1_ ic
in if res < 0 then NONE
else SOME (chr_unsafe res)
end

fun openIn (f: string) : instream =
{ic=prim("openInStream",(getCtx(), f, CannotOpen)),
name=f} handle exn => raise Fail "openIn"

fun closeIn ({ic,...} : instream) : unit = prim ("closeStream", ic)

fun inputLine is =
let fun loop(acc) =
case input1 is
of SOME (c as #"\n") => SOME(implode(rev(c :: acc)))
| SOME c => loop(c::acc)
| NONE => case acc
of [] => NONE
| _ => SOME(implode(rev(#"\n" :: acc)))
in loop([])
end
end
3 changes: 3 additions & 0 deletions examples/fragAssembling/size.mlb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$(SML_LIB)/basis/basis.mlb
size.sig
size.sml
21 changes: 21 additions & 0 deletions examples/fragAssembling/size.sig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
signature SIZE =
sig
type 'a sz

(* Primitives *)
val int : int sz
val bool : bool sz
val char : char sz
val word : word sz
val real : real sz
val unit : unit sz
val string : string sz

(* Combinators *)
val list : 'a sz -> 'a list sz
val option : 'a sz -> 'a option sz
val tup2 : 'a sz -> 'b sz -> ('a * 'b) sz
val tup3 : 'a sz -> 'b sz -> 'c sz -> ('a * 'b * 'c) sz

val size : 'a sz -> 'a -> int
end
Loading