Ticket #4902 (closed feature request: fixed)

Opened 2 years ago

Last modified 2 years ago

Create a primop for getting the size of an Array#

Reported by: tibbe Owned by:
Priority: normal Milestone:
Component: Runtime System Version: 7.0.1
Keywords: Cc: pumpkingod@…, johan.tibell@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

We currently store the size of Array#s (and MutableArray#s):

typedef struct {
    StgHeader   header;
    StgWord     ptrs;
    StgWord     size; // ptrs plus card table
    StgClosure *payload[FLEXIBLE_ARRAY];
    // see also: StgMutArrPtrs macros in ClosureMacros.h
} StgMutArrPtrs;

However, there's currently no way to read this information. This means that array types defined in terms of the two primitive array types need to store this size, even though it's already stored by GHC.

I think we should expose sizeOfArray# and sizeOfMutableArray#.

Attachments

sizeof.dpatch Download (66.1 KB) - added by tibbe 2 years ago.
arraysizeof.dpatch Download (72.1 KB) - added by pumpkin 2 years ago.
arraysizeof-tests.dpatch Download (121.7 KB) - added by tibbe 2 years ago.

Change History

Changed 2 years ago by pumpkin

  • cc pumpkingod@… added

I've written a patch for this and either I or Johan will be attaching it to this ticket when we get a chance to test it.

Changed 2 years ago by tibbe

Changed 2 years ago by tibbe

  • status changed from new to patch

I've attached a patch. Credits go to Daniel Peebles.

Changed 2 years ago by simonmar

Thanks. Strictly speaking we should have an OFFSET_ macro for the size field, and a test would be nice too...

Changed 2 years ago by pumpkin

Yep, I agree about the OFFSET_ macro, but wasn't able to figure out how to do that last night. I was going to add a test today, but haven't had a chance to yet :)

Changed 2 years ago by pumpkin

Changed 2 years ago by pumpkin

I'm using the correct offset now. It currently makes no difference because it happens to be 0, but it makes us more future-proof. Still no tests, but I probably won't have a chance to write any for a little bit, so if anyone else wants to in the mean time I certainly won't be offended!

Changed 2 years ago by tibbe

Changed 2 years ago by tibbe

  • cc johan.tibell@… added

I've added a test to the test suite. All tests pass (for arrays of size [0..1000]). Please review.

Changed 2 years ago by simonmar

  • status changed from patch to closed
  • resolution set to fixed

Pushed, thanks!

Wed Jan 26 05:15:54 GMT 2011  Daniel Peebles <pumpkingod@gmail.com>
  * Add sizeof(Mutable)Array# primitives
Tue Feb  1 06:30:17 GMT 2011  Daniel Peebles <pumpkingod@gmail.com>
  * Fix Array sizeof primops to use the correct offset (which happens to be 0, so it worked before anyway). Makes us more future-proof, at least
Sun Feb  6 22:25:43 GMT 2011  Johan Tibell <johan.tibell@gmail.com>
  * Add test for sizeofArray# and sizeofMutableArray#
Note: See TracTickets for help on using tickets.