cgen: improve code generation for seq
types
#1272
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
seq
payload type definition per C fileseq
if not used in apointer-like type (e.g.:
ptr seq[T]
,ref seq[T]
)Together, these improvements reduce the amount of C code output by the
NimSkull compiler, slightly improving compile times.
Details
Move the
tySequence
handling fromgetTypeDescWeak
togetTypeDescAux
, preventing different instances referring to the sametype, or the same instance, being pushed to the type stack multiple
times within a single module.
For each
tySequence
type instance pushed to the type stack, a payloadis emitted, with preventing duplicates previously being deferred to the
C compiler through use of a C pre-processor guard (
#ifdef
). Since thetype instance is now only pushed to the type stack once per module, the
pre-processor guard is unnecessary and thus removed.
In addition, for
ptr seq
,ref seq
, etc. types, only a forward-declaration of the sequence type is requested, preventing the full type
and all its dependencies being pulled in.
Finally, the
trecursive_table
test, intended to catch C codegenerator bugs with recursive
seq
types, is fixed. Sincep
wasneither used nor exported, the
T
type was never actually processed bythe code generator.