nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.63k stars 1.47k forks source link

fixes #24378; supportsCopyMem can fail from macro context with tuples #24383

Closed ringabout closed 4 weeks ago

ringabout commented 1 month ago

fixes #24378

type Win = typeof(`body`)
doAssert not supportsCopyMem((int, Win))

semAfterMacroCall doesn't skip the children aliases types in the tuple typedesc construction while the normal program seem to skip the aliases types somewhere

(int, Win) is kept as (int, alias string) instead of expected (int, string)

metagn commented 1 month ago

I didn't notice this before, I think this is the problem:

The propagation of tfHasAsgn is restricted to some type kinds, which includes tySequence but not tyString, which fails the ast.hasDestructor condition for the typetrait. And in isGCRef, strings and seqs are excluded from counting as GC'd memory, so the other containsGarbageCollectedRef check also fails.

I would guess the solution is including string types in the filter in propagateToOwner (which makes it work) but could it break something else?

Araq commented 1 month ago

but could it break something else?

I don't think so.

github-actions[bot] commented 4 weeks ago

Thanks for your hard work on this PR! The lines below are statistics of the Nim compiler built from 5e56f0a356bc86fd4b135c170c0fee2e96e7257b

Hint: mm: orc; opt: speed; options: -d:release 176086 lines; 8.889s; 655.141MiB peakmem