Stream: compiler development

Topic: List.map* args


view this post on Zulip Brendan Hansknecht (Dec 21 2023 at 15:20):

Should List.map2, etc. be taking all of the input lists as owned arguments? Couldn't that often lead to an unnecessary copy of the entire list? Technically, List.map2 only needs to copy the elements in the list if they need to be modified instead of copying the entire list to get ownership.

Side note, as they are written currently, I think they free all the elements in the list, but leak the list itself.

view this post on Zulip Ayaz Hafiz (Dec 22 2023 at 01:56):

Taking the list as owned means you can reuse the allocation though, right? For the common case you’re mapping from one type to the same, or the elements can be transmuted to the same size

view this post on Zulip Brendan Hansknecht (Dec 22 2023 at 02:11):

Yeah, but in map2 it takes both with ownership. Map3 takes all 3 as owned, etc

view this post on Zulip Brendan Hansknecht (Dec 22 2023 at 02:11):

I guess we could check all of them for potential reuse, just feels strange to me

view this post on Zulip Brendan Hansknecht (Dec 22 2023 at 02:12):

Also, we probably should add in reuse. I don't think we have it currently. At least based on the zig bitcode.

view this post on Zulip Ayaz Hafiz (Dec 23 2023 at 00:53):

We have reuse as a static optimization, though yeah not oportunistic at RT I guess

view this post on Zulip Brendan Hansknecht (Dec 23 2023 at 00:54):

Ah. Compile time deals with it. Makes sense.

view this post on Zulip Brendan Hansknecht (Dec 23 2023 at 00:55):

So that means owning all 3 is intended behaviour for map3 then? Cause it enables more compile time reuse?

view this post on Zulip Ayaz Hafiz (Dec 23 2023 at 00:58):

I think @Folkert de Vries knows best


Last updated: Jul 06 2025 at 12:14 UTC