preproc/symtable: Linear-time type resolution

This was optimized previously, having introduced
`@need-resolve-dtype`.  But, while that solved the problem for some
packages, it was not enough for a package with 40,000 symbols.

This introduces a map for typedefs' symbols and eliminates ~15s for that
package.

DEV-15114
main
Mike Gerwitz 2023-10-19 12:43:17 -04:00
parent 959ff06539
commit 297bf4a506
1 changed files with 6 additions and 4 deletions

View File

@ -256,7 +256,10 @@
<apply-templates mode="preproc:symtable-complete" <apply-templates mode="preproc:symtable-complete"
select="$newresult/preproc:sym"> select="$newresult/preproc:sym">
<with-param name="syms" select="$newresult/preproc:sym" /> <with-param name="typedef-symtable-map" tunnel="yes"
select="map:merge(
for $sym in $newresult/preproc:sym[ @type = 'type' ]
return map{ string( $sym/@name ) : $sym } ) " />
</apply-templates> </apply-templates>
</preproc:symtable> </preproc:symtable>
@ -845,14 +848,13 @@
<template mode="preproc:symtable-complete" priority="5" <template mode="preproc:symtable-complete" priority="5"
match="preproc:sym[ @need-resolve-dtype='true' ]"> match="preproc:sym[ @need-resolve-dtype='true' ]">
<param name="syms" as="element( preproc:sym )*" /> <param name="typedef-symtable-map" as="map(*)" tunnel="yes" />
<!-- attempt to derive type information from a typedef --> <!-- attempt to derive type information from a typedef -->
<!-- TODO: also check symbol table after import (post-process) --> <!-- TODO: also check symbol table after import (post-process) -->
<variable name="type" select="@dtype" /> <variable name="type" select="@dtype" />
<variable name="typedef" as="element( preproc:sym )?" <variable name="typedef" as="element( preproc:sym )?"
select="$syms[ @type = 'type' select="$typedef-symtable-map( $type )" />
and @name = $type ]" />
<if test="not( $typedef and $typedef/@dtype )"> <if test="not( $typedef and $typedef/@dtype )">
<message terminate="yes"> <message terminate="yes">