Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ dev.s
*.vok
*.vos
tmp.v
promises.prof
7,048 changes: 3,526 additions & 3,522 deletions BOOTSTRAP/cli.c

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ LSTSFLAGS = MALLOC_CHECK_=3
# recommendation: ulimit -s unlimited

dev: install-production
lm tests/promises/vector/constructor.lsts
$(CC) $(CFLAGS) tmp.c
./a.out
sh profile-promises.sh

build: compile-production
time env $(LSTSFLAGS) ./production --v23 --c -o deploy1.c SRC/index.lsts
Expand Down
22 changes: 8 additions & 14 deletions SRC/type-constructor.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@
# new allocations = 0
let ta = TAny;

# new allocations = 1
# 1 from close
# 0 from 0 length list
# this is an upper bound, because the list implementation should be replaced with vector eventually
# new allocations = 0
# 0 from 0 length vector
let t0(tag: CString): Type = TGround(tag, mk-vector(type(Type)));

# new allocations = 2
# 1 from close
# 1 from 1 length list
# this is an upper bound, because the list implementation should be replaced with vector eventually
# new allocations = 1
# 1 from 1 length vector
let t1(tag: CString, p1: Type): Type = TGround(tag, mk-vector(type(Type)).push(p1));

# new allocations = 3
# 1 from close
# 2 from 2 length list
# this is an upper bound, because the list implementation should be replaced with vector eventually
# new allocations = 1
# 1 from 2 length vector
let t2(tag: CString, p1: Type, p2: Type): Type = TGround(tag, mk-vector(type(Type)).push(p2).push(p1));

# new allocations = 0
Expand Down Expand Up @@ -61,6 +55,7 @@ let $"&&"(lt: Type, rt: Type): Type = (
);

# new allocations = 0 if either argument is ?
# | 0 if able to reuse left conjugate
# | 1
let .extend(lt: Type, rt: Type): Type = (
match (lt, rt) {
Expand Down Expand Up @@ -93,8 +88,7 @@ let .extend(lt: Type, rt: Type): Type = (
};
);

# new allocations = 1
# this is an upper bound, because the list implementation should be replaced with vector eventually
# new allocations = 0
let ts(tag: CString, ps: Vector<Type>): Type = TGround( tag, ps );

# new allocations = 0
Expand Down
26 changes: 26 additions & 0 deletions SRC/unit-main-core.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ let print-toks-json(fp: CString): Nil = (
);

let show-alloc-count = false;
let show-alloc-count-in-program = false;

let main(argc: C_int, argv: CString[]): Nil = (
config-v23 = false;
Expand Down Expand Up @@ -57,6 +58,7 @@ let main(argc: C_int, argv: CString[]): Nil = (
);
c"--stripdebug" => config-strip-debug = true;
c"--showalloc" => show-alloc-count = true;
c"--showallocgen" => show-alloc-count-in-program = true;
c"--profile-ast" => config-profile-ast = true;
c"-o" => (
argi = argi + 1;
Expand Down Expand Up @@ -100,6 +102,30 @@ let main(argc: C_int, argv: CString[]): Nil = (
);
_ => (
for list fp4 in input.reverse { frontend(fp4); };
if show-alloc-count-in-program {
ast-parsed-program = ast-parsed-program +
mk-app( mk-var(c"print"),
mk-app(
mk-var(c"+"),
mk-cons(
mk-lit(c"TOTAL ALLOCATED: ").ascript(t0(c"String")),
mk-app(
mk-var(c"+"),
mk-cons(
mk-app(
mk-var(c".into"),
mk-cons(
mk-var(c"safe-alloc-block-count-monotonic-history"),
mk-atype(t1(c"Type",t0(c"String")))
)
),
mk-lit(c"\\n").ascript(t0(c"String"))
)
)
)
)
);
};
match config-mode {
ModeTypecheck{} => (preprocess(); typecheck(););
ModeCompile{} => (preprocess(); typecheck(); plugin-current-backend(); );
Expand Down
3 changes: 3 additions & 0 deletions lib/core/array.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let mark-memory-as-safe(ptr: t[], len: USize): Nil = (
# safe-alloc-block-count-monotonic is an increment-only counter to track historical malloc blocks
let safe-alloc-block-count = 0_u64;
let safe-alloc-block-count-monotonic = 0_u64;
let safe-alloc-block-count-monotonic-history = 0_u64;

let safe-alloc-semaphore = false;

Expand All @@ -55,6 +56,7 @@ let safe-alloc-impl(nb: USize, tt: Type<t>): t[] = (
# TODO: wrap counter adjustments in conditional compilation
safe-alloc-block-count = safe-alloc-block-count + 1;
safe-alloc-block-count-monotonic = safe-alloc-block-count-monotonic + 1;
safe-alloc-block-count-monotonic-history = safe-alloc-block-count-monotonic-history + 1;

ptr
);
Expand All @@ -72,6 +74,7 @@ let safe-realloc-impl(ptr: ?[], nb: USize): ?[] = (

# TODO: wrap counter adjustments in conditional compilation
safe-alloc-block-count-monotonic = safe-alloc-block-count-monotonic + 1;
safe-alloc-block-count-monotonic-history = safe-alloc-block-count-monotonic-history + 1;

new-ptr
);
Expand Down
18 changes: 18 additions & 0 deletions profile-promises.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#/usr/bin/bash

rm -rf promises.prof

for fp in `ls tests/promises/lm-type/*.lsts`;
do
echo "Processing promise file $fp"
rm -f tmp.c a.out
echo "Processing promise file $fp" >> promises.prof
lm --showallocgen $fp
if [ -f tmp.c ]; then
gcc -w -O2 -march=native -mtune=native tmp.c -o a.out
if [ -f a.out ]; then
./a.out >> promises.prof
fi
fi
done

26 changes: 13 additions & 13 deletions tests/promises/lm-type/bound-constructor.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ safe-alloc-block-count-monotonic = 0;

assert( t0(c"A") == t0(c"A") );
assert( safe-alloc-block-count == 0 );
assert( safe-alloc-block-count-monotonic <= 2 );
assert( safe-alloc-block-count-monotonic == 0 );
safe-alloc-block-count-monotonic = 0;

assert( t1(c"A",ta) == t1(c"A",ta) );
assert( safe-alloc-block-count == 0 );
assert( safe-alloc-block-count-monotonic <= 4 );
assert( safe-alloc-block-count-monotonic == 2 );
safe-alloc-block-count-monotonic = 0;

assert( t2(c"A",ta,ta) == t2(c"A",ta,ta) );
assert( safe-alloc-block-count == 0 );
assert( safe-alloc-block-count-monotonic <= 6 );
assert( safe-alloc-block-count-monotonic == 2 );
safe-alloc-block-count-monotonic = 0;

assert( tv(c"a") == tv(c"a") );
Expand All @@ -30,7 +30,7 @@ safe-alloc-block-count-monotonic = 0;

assert( (ta && t0(c"A")) == t0(c"A") );
assert( safe-alloc-block-count == 0 );
assert( safe-alloc-block-count-monotonic <= 2 );
assert( safe-alloc-block-count-monotonic == 0 );
safe-alloc-block-count-monotonic = 0;

assert( (tv(c"a") && ta) == tv(c"a") );
Expand All @@ -40,37 +40,37 @@ safe-alloc-block-count-monotonic = 0;

assert( (tv(c"a") && t0(c"A")) == (tv(c"a") && t0(c"A")) );
assert( safe-alloc-block-count == 0 );
assert( safe-alloc-block-count-monotonic <= 4 );
assert( safe-alloc-block-count-monotonic == 2 );
safe-alloc-block-count-monotonic = 0;

assert( (tv(c"a") && (t0(c"A") && t0(c"B"))) == (tv(c"a") && (t0(c"A") && t0(c"B"))) );
assert( safe-alloc-block-count == 0 );
assert( safe-alloc-block-count-monotonic <= 8 );
assert( safe-alloc-block-count-monotonic == 4 );
safe-alloc-block-count-monotonic = 0;

assert( ((tv(c"a") && t0(c"A")) && t0(c"B")) == ((tv(c"a") && t0(c"A")) && t0(c"B")) );
assert( safe-alloc-block-count == 0 );
assert( safe-alloc-block-count-monotonic <= 8 );
assert( safe-alloc-block-count-monotonic == 4 );
safe-alloc-block-count-monotonic = 0;

assert( ( (tv(c"a") && t0(c"A")) && (t0(c"B") && t0(c"C")) ) == ( (tv(c"a") && t0(c"A")) && (t0(c"B") && t0(c"C")) ) );
assert( safe-alloc-block-count == 0 );
assert( safe-alloc-block-count-monotonic <= 12 );
assert( safe-alloc-block-count-monotonic == 6 );
safe-alloc-block-count-monotonic = 0;

assert( ts(c"A",mk-vector(type(Type)).push(ta)) == ts(c"A",mk-vector(type(Type)).push(ta)) );
assert( safe-alloc-block-count == 0 );
assert( safe-alloc-block-count-monotonic <= 4 );
assert( safe-alloc-block-count-monotonic == 2 );
safe-alloc-block-count-monotonic = 0;

assert( ts(c"A",mk-vector(type(Type)).push(ta).push(ta)) == ts(c"A",mk-vector(type(Type)).push(ta).push(ta)) );
assert( safe-alloc-block-count == 0 );
assert( safe-alloc-block-count-monotonic <= 6 );
assert( safe-alloc-block-count-monotonic == 2 );
safe-alloc-block-count-monotonic = 0;

assert( (ta || t0(c"A")) == t0(c"A") );
assert( safe-alloc-block-count == 0 );
assert( safe-alloc-block-count-monotonic <= 2 );
assert( safe-alloc-block-count-monotonic == 0 );
safe-alloc-block-count-monotonic = 0;

assert( (tv(c"a") || ta) == tv(c"a") );
Expand All @@ -80,10 +80,10 @@ safe-alloc-block-count-monotonic = 0;

assert( (tv(c"a") || t0(c"A")) == tv(c"a") );
assert( safe-alloc-block-count == 0 );
assert( safe-alloc-block-count-monotonic <= 1 );
assert( safe-alloc-block-count-monotonic == 0 );
safe-alloc-block-count-monotonic = 0;

assert( tand(mk-vector(type(Type)).push(t0(c"A")).push(t0(c"B"))) == tand(mk-vector(type(Type)).push(t0(c"A")).push(t0(c"B"))) );
assert( safe-alloc-block-count == 0 );
assert( safe-alloc-block-count-monotonic <= 6 );
assert( safe-alloc-block-count-monotonic == 2 );
safe-alloc-block-count-monotonic = 0;
Loading