roc icon indicating copy to clipboard operation
roc copied to clipboard

Arena allocation example

Open dullbananas opened this issue 3 years ago • 9 comments

dullbananas avatar Dec 30 '21 05:12 dullbananas

we have a test that checks that all examples are part of a cli_run test (to prevent the examples going stale). Could you add such a test?

folkertdev avatar Dec 31 '21 13:12 folkertdev

i tried to add a test, but it fails

output of cargo test arena_allocator in cli_run directory:

running 1 test
test cli_run::arena_allocator ... FAILED

failures:

---- cli_run::arena_allocator stdout ----
thread 'cli_run::arena_allocator' panicked at '`valgrind` exited with exit code 127. valgrind stdout was: ""

valgrind stderr was: "/workspaces/roc/examples/arena-allocator/arena-alloc: symbol lookup error: /workspaces/roc/examples/arena-allocator/arena-alloc: undefined symbol: roc__mainForHost_size
==7068==  If you believe this happened as a result of a stack
==7068==  overflow in your program's main thread (unlikely but
==7068==  possible), you can try to increase the size of the
==7068==  main thread stack using the --main-stacksize= flag.
==7068==  The main thread stack size used in this run was 8388608.
"', cli/tests/cli_run.rs:117:17

dullbananas avatar Dec 31 '21 20:12 dullbananas

@bhansconnect the test/program fails when using the surgical linker. Not sure if that is easy to fix or if we should find a workaround for now

folkertdev avatar Dec 31 '21 21:12 folkertdev

I can't currently test, but hopefully will be able to check into it in the next couple of days.

bhansconnect avatar Dec 31 '21 21:12 bhansconnect

I am not fully sure the issue, but the root cause is this:

usingnamespace struct {
    extern fn roc__mainForHost_1_exposed(output: [*]u8) void;
    pub const roc_main = roc__mainForHost_1_exposed;

    extern fn roc__mainForHost_size() i64;
    pub const roc_main_size = roc__mainForHost_size;

    extern fn roc__mainForHost_1_Fx_caller(flags: *const u8, closure_data: [*]u8, output: [*]u8) void;
    pub const call_fx = roc__mainForHost_1_Fx_caller;

    extern fn roc__mainForHost_1_Fx_size() i64;
    pub const fx_size = roc__mainForHost_1_Fx_size;

    extern fn roc__mainForHost_1_Fx_result_size() i64;
    pub const fx_result_size = roc__mainForHost_1_Fx_result_size;
};

If each function is used directly in global scope, it works as expected. I will need to look into what the exact structure generated here is in order to make the surgical linker deal with it.

Honestly a bit surprised this breaks at all.

bhansconnect avatar Jan 04 '22 03:01 bhansconnect

@dullbananas @folkertdev @bhansconnect Do you still want this? An arena allocator example sounds like a great thing to have, do any of our other examples today happen to use such a system?

kili-ilo avatar Sep 25 '22 02:09 kili-ilo

None of the other example platforms have arena allocation or anything else that doesn't just call malloc, so this example should still be added

dullbananas avatar Oct 05 '22 00:10 dullbananas

Any known issues with this PR? Maybe just rebasing would heal some of the testing issues?

kili-ilo avatar Oct 07 '22 03:10 kili-ilo

I think it is mostly a matter of updating to latest roc and maybe modifying the platform slightly.

bhansconnect avatar Oct 08 '22 04:10 bhansconnect