Missing introspection? "How exactly this type is actually used"

Ali Çehreli acehreli at yahoo.com
Fri May 20 19:19:25 UTC 2022


On 5/20/22 11:31, Adam D Ruppe wrote:
 > On Friday, 20 May 2022 at 18:23:47 UTC, Ali Çehreli wrote:
 >> The issue with the member variables remains: Currently, there is no
 >> way of determining that a member variable is used only by a set of
 >> member function instances that are never generated, meaning that the
 >> member variable could be eliminated.
 >
 > What's your goal here? To minimize the memory used at runtime?

Nothing is important really. My thought process was the following:

DbI allows range algorithms to e.g. provide random access:

   iota(10)
     .map!(i => i)
     .take(3)[1];

iota is uneful enough to provide opIndex, which is propagated by map and 
take and that random access works.

What if say, map used some expensive members (imagine some range type 
keeps an int[1000] for some reason) just because iota was 
isRandomAccessRange etc. (Same for take.) If the user never had any 
interest for that machinery (for this particular use) then there would 
be both compile-time and runtime cost.

That's when I realized that there is no way of cutting that cost other 
than the user explicitly saying something like justInputRangePlease and 
it would be more efficient:

   iota!justInputRangePlease(10)  // <-- Here
     .map!(i => i)
     .take(3);

Just an observation. Nothing to fix here. :)

Ali



More information about the Digitalmars-d mailing list