Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smaller closure #4385

Merged
merged 30 commits into from
Apr 2, 2018
Merged

Smaller closure #4385

merged 30 commits into from
Apr 2, 2018

Conversation

jacereda
Copy link
Contributor

Looks like something like this could be useful to reduce GC frequency. Thoughts?

rts/idris_rts.c Outdated
#define STATIC_ASSERT(COND,MSG) typedef char static_assertion_##MSG[(COND)?1:-1]


STATIC_ASSERT(sizeof(Closure) == 16, sizeofClosure);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be false on 32-bit systems depending on how double is aligned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess a 32-bit "test_c" job in the CI would be nice... I have a 32-bit Nix system at work, I can try there anyway.

@melted
Copy link
Contributor

melted commented Mar 19, 2018

Thanks for the PR!

@melted
Copy link
Contributor

melted commented Mar 19, 2018

I’ll take a serious look at it after work. Please try to test a 32-bit build also.

@jacereda
Copy link
Contributor Author

I don't expect this to be merged yet, I opened it to get some feedback on whether this is worth pursuing. I think I can make some further improvements to reduce memory usage even more (and maybe simplify it at the same time). Please, wait before doing a real review.

@jacereda
Copy link
Contributor Author

I'm trying an alternative approach using a header instead of a union at https://github.com/jacereda/Idris-dev/tree/smaller-closure-3 and the result seems promising. Should I open a separate PR or merge into this branch?

@melted
Copy link
Contributor

melted commented Mar 20, 2018

Better to keep it in one PR as only one of the ways will get in.

I don't think there should be bitfields. It makes it a pain to access from other languages than C, and it would be nice if one could mess with Idris internals from Idris code. Also, we don't have to reserve 56 bits for size, let's say that people who want to allocate more than 4GB have to use a pointer.

@jacereda
Copy link
Contributor Author

@melted, I think this is ready. I have a couple of branches on top of this one that make further improvements like reducing Bits8/Bits16 to 8 bytes and improving support for developing on NixOS/Nixpkgs, but I guess it would be better to go in small steps.

Also, I guess I should have opened a separate PR for 11130b1, since it's a bug.

The 32-bit test suite is still broken, but that's also the case in master.

Copy link
Contributor

@melted melted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking good!

config.mk Outdated
@@ -14,7 +14,7 @@ RANLIB ?=ranlib
CABAL :=cabal
# IDRIS_ENABLE_STATS should not be set in final release
# Any flags defined here which alter the RTS API must also be added to src/IRTS/CodegenC.hs
CFLAGS :=-O2 -Wall -std=c99 -D_POSIX_C_SOURCE=200809L -DHAS_PTHREAD -DIDRIS_ENABLE_STATS $(CFLAGS)
CFLAGS :=-O2 -Wall -g -std=c99 -D_POSIX_C_SOURCE=200809L -DHAS_PTHREAD -DIDRIS_ENABLE_STATS $(CFLAGS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

rts/idris_gc.c Outdated
heap_item->info.str_offset->str
= copy(vm, heap_item->info.str_offset->str);
break;
case CT_CON: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uneven indentation in the cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I add a .clang-format file that tries to be consistent with current formatting?

rts/idris_gmp.c Outdated
}

VAL idris_bigAnd(VM* vm, VAL x, VAL y) {
if (ISINT(x) && ISINT(y)) {
return INTOP(&, x, y);
} else {
return bigAnd(vm, GETBIG(vm, x), GETBIG(vm, y));
return bigAnd(vm, (VAL)GETBIG(vm, x), (VAL)GETBIG(vm, y));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GETBIG is defined with a cast to VAL already.

Further occurences below.

rts/idris_rts.h Outdated
typedef struct String {
Hdr hdr;
size_t slen;
#define _null hdr.u8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this and substitute hdr.u8 in the use sites and put in a comment that String uses the hdr.u8 field for null.

rts/idris_rts.h Outdated
typedef struct Con {
Hdr hdr;
uint32_t tag;
uint32_t arity;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arity could use one of the fields in the header. That would save four bytes on 32-bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not now, since the aligned() function is now requiring 8 bytes alignment, but aligned() could as well align to sizeof(intptr_t). I'll change that.

@melted
Copy link
Contributor

melted commented Apr 2, 2018

Let's merge this. I'll note it in the change log.

Thanks for the contribution!

@melted melted merged commit c2af016 into idris-lang:master Apr 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants