linker: Remove classifier vs. calculation distinction

This is something that I thought would be useful back in the day when TAME
was in its infancy, but it is not important.  Rather than having the linker
spend time trying to figure out what symbols belong in the classifier---and
rather than keeping that complexity around---this simplifies things by
making the existing `classify' method simply perform _all_ calculations, and
then yield only the classification portion of the result.

This isn't a problem in practice because, if we only desire the use of a
classifier, then we create a "supplier" that only uses classifications and
has no other dependencies.  The end result is, as far as we care, the same.

* src/current/compiler/js.xsl (compiler:entry-rater)[lv:package]: Initialize
    `classes' rather than invoking classifier
  (compiler:entry-classifier)[lv:package]: Invoke all calculations and
    return only classes to provide equivalent behavior.
  (compiler:exit-classifier): Post-process classifications from calculation
    results, iterating through classmap.
  (compiler:classifier-yields-map)[lv:package]: Output all classifications
    that are not generated.  This differs slightly from the original
    implementation in that it includes all non-generated classes rather than
    just classes that have a non-generated `@yields'; this distinction is
    important since `compiler:exit-classifier' is now using it to produce a
    classification result set that doesn't contain all the generated
    stuff (since it didn't before, and shouldn't now).
* src/current/compiler/linker.xsl: Update copyright year.
  (l:resolv-deps)[preproc:sym[@l:mark-inclass]]: Remove template.
  (l:resolv-deps)[preproc:sym...@l:mark-inclass...]: Remove template.
  (l:depgen-sym): Set type of result to `element(preproc:sym)', since
    `l:mark-inclass' is no longer produced.
    [inclass, needs-class-mark]: Remove variables and all instances where
      they are used.
  (l:dep-aug)[inclass]: Remove param.  Stop producing `@inclass' attribute.
  (l:link-classifier)[lv:package]: Do not process any dependencies.  This
    can be removed entirely in the future since it now only produces static
    code, which we can perhaps combine with a different block.
  (l:link-rater)[lv:package]: Remove mention of `inclass' for dependencies;
    all dependencies will now be compiled into this block.
master
Mike Gerwitz 2018-07-13 13:08:52 -04:00
parent 844c6512c9
commit f2db9f1268
2 changed files with 18 additions and 127 deletions

View File

@ -99,9 +99,8 @@
<!-- handle defaults -->
<text>init_defaults( args, params );</text>
<!-- perform classifications -->
<value-of select="$compiler:nl" />
<text>var classes = rater.classify( args, _canterm );</text>
<text>var classes = {};</text>
<!-- for @external generated clases -->
<text>var genclasses = {};</text>
</template>
@ -110,34 +109,23 @@
<!-- allow classification of any arbitrary dataset -->
<value-of select="$compiler:nl" />
<text>rater.classify = function( args, _canterm ) {</text>
<text>_canterm = ( _canterm == undefined ) ? true : !!_canterm;</text>
<!-- XXX: Remove this; shouldn't be magic -->
<text>consts['__DATE_YEAR__'] = ( new Date() ).getFullYear(); </text>
<!-- object into which all classifications will be stored -->
<text>var classes = {}, genclasses = {}; </text>
<!-- TODO: We need to do something with this... -->
<text>var req_params = {}; </text>
return rater( args, _canterm ).classes;
<text> };</text>
</template>
<template match="lv:package" mode="compiler:exit-classifier">
<text>return classes;</text>
<text> };</text>
<!-- TODO: make sure fromMap has actually been compiled -->
<text>rater.classify.fromMap = function( args_base, _canterm ) { </text>
<text>var ret = {}; </text>
<text>rater.fromMap( args_base, function( args ) {</text>
<text>var classes = rater.classify( args, _canterm ); </text>
<text>var result = rater( args, _canterm ); </text>
<text>
for ( var c in classes )
for ( var c in rater.classify.classmap )
{
ret[ c ] = {
is: !!classes[ c ],
indexes: args[ rater.classify.classmap[ c ] ]
is: !!result.classes[ c ],
indexes: result.vars[ rater.classify.classmap[ c ] ]
};
}
</text>
@ -221,15 +209,15 @@
<!-- for each cgen symbol (which is the classification @yields), map the
classification name (the @parent) to the cgen symbol name -->
<for-each select="$symbols[ @type='cgen' ]">
<for-each select="$symbols[ @type='class' and not( @preproc:generated ) ]">
<if test="position() > 1">
<text>,</text>
</if>
<text>'</text>
<value-of select="substring-after( @parent, ':class:' )" />
<value-of select="substring-after( @name, ':class:' )" />
<text>':'</text>
<value-of select="@name" />
<value-of select="@yields" />
<text>'</text>
</for-each>
</template>

View File

@ -2,7 +2,7 @@
<!--
Assembles code fragments into a final executable
Copyright (C) 2016, 2017 R-T Specialty, LLC.
Copyright (C) 2016, 2017, 2018 R-T Specialty, LLC.
This file is part of TAME.
@ -228,56 +228,12 @@
</template>
<!-- replace marks with the symbols that they reference (note that the linker
will not add duplicates, so we needn't worry about them) -->
<template mode="l:resolv-deps" as="element( preproc:sym )"
priority="8"
match="preproc:sym[ @l:mark-inclass ]">
<!-- FIXME: I sometimes return more than one symbol! -->
<variable name="sym" as="element( preproc:sym )*"
select="root(.)/preproc:sym[
@name = current()/@name ]" />
<!-- sanity check; hopefully never necessary -->
<if test="not( $sym )">
<call-template name="log:internal-error">
<with-param name="name" select="'link'" />
<with-param name="msg">
<text>l:mark-class found for non-existing symbol </text>
<value-of select="@name" />
<text>; there is a bug in l:depgen-process-sym</text>
</with-param>
</call-template>
</if>
<!-- copy the element and mark as inclass (no need to check @src, since at
this point, such conflicts would have already resulted in an error -->
<preproc:sym>
<sequence select="$sym/@*" />
<!-- override attribute -->
<attribute name="inclass" select="'true'" />
</preproc:sym>
</template>
<!-- any now-inclass symbols should be stripped of their original position -->
<template mode="l:resolv-deps" priority="7"
match="preproc:sym[
@name = root(.)/preproc:sym[ @l:mark-inclass ]
/@name ]">
<!-- bye-bye -->
</template>
<template match="*" mode="l:resolv-deps" priority="1">
<sequence select="." />
</template>
<!-- FIXME: I want element( l:preproc:sym ), but we also have
l:mark-inclass -->
<template name="l:depgen-sym" as="element()*">
<template name="l:depgen-sym" as="element( preproc:sym )*">
<param name="pending" as="element( preproc:sym )*" />
<param name="stack" as="element( l:sym-stack )" />
<param name="path" as="xs:string"
@ -494,16 +450,6 @@
<variable name="cur" as="element( preproc:sym )"
select="." />
<!-- determines if the compile destination for these dependencies will be
within the classifier; this is the case for all class dependencies
*unless* the class is external -->
<variable name="inclass" as="xs:boolean"
select="( ( $cur/@type='class' )
and not( $cur/@extclass='true' ) )
or $processing/preproc:sym[
@type='class'
and not( @extclass='true' ) ]" />
<!-- perform circular dependency check and blow up if found (we cannot choose
a proper linking order without a correct dependency tree); the only
exception is if the circular dependency is a function, since that simply
@ -567,17 +513,6 @@
</call-template>
</if>
<!-- determine if class already exists, but needs to be marked for
inclusion within the classifier -->
<variable name="needs-class-mark" as="xs:boolean"
select="$existing
and $inclass
and not( $existing/@inclass='true' )
and not( $stack/preproc:sym[
@l:mark-inclass
and @name=$cur/@name
and @src=$cur/@src ] )" />
<!-- continue with the remainder of the symbol list -->
<call-template name="l:depgen-sym">
<with-param name="pending" select="remove( $pending, 1 )" />
@ -588,7 +523,7 @@
re-adding it (note that we check both the symbol name and its source
since symbols could very well share a name due to exporting rules) -->
<choose>
<when test="not( $existing ) or $needs-class-mark">
<when test="not( $existing )">
<!-- does this symbol have any dependencies? -->
<variable name="deps" as="element( preproc:sym )*">
<apply-templates select="$cur" mode="l:depgen-sym" />
@ -607,7 +542,6 @@
<call-template name="l:dep-aug">
<with-param name="cur" select="$cur" />
<with-param name="deps" select="$deps" />
<with-param name="inclass" select="$inclass" />
<with-param name="mypath" select="$mypath" />
</call-template>
</variable>
@ -629,20 +563,9 @@
</call-template>
<!-- finally, we can output ourself -->
<choose>
<!-- existing symbol needs to be marked -->
<when test="$needs-class-mark">
<preproc:sym l:mark-inclass="true" name="{$cur/@name}" src="{$cur/@src}" />
</when>
<!-- new symbol -->
<otherwise>
<preproc:sym>
<sequence select="$cur/@*" />
<attribute name="inclass" select="$inclass" />
</preproc:sym>
</otherwise>
</choose>
<preproc:sym>
<sequence select="$cur/@*" />
</preproc:sym>
</l:sym-stack>
</when>
@ -662,8 +585,6 @@
<template name="l:dep-aug" as="element( preproc:sym )*">
<param name="cur" as="element( preproc:sym )" />
<param name="deps" as="element( preproc:sym )*" />
<param name="inclass" as="xs:boolean"
select="false()" />
<param name="proc-barrier" as="xs:boolean"
select="false()" />
<param name="parent-name" as="xs:string"
@ -709,11 +630,6 @@
<!-- set new src path -->
<attribute name="src" select="$newsrc" />
<!-- flag for inclusion into classifier, if necessary -->
<if test="$inclass">
<attribute name="inclass" select="$inclass" />
</if>
<if test="$proc-barrier">
<attribute name="l:proc-barrier" select="'true'" />
</if>
@ -991,8 +907,6 @@
<template match="lv:package" mode="l:link-classifier">
<param name="deps" />
<call-template name="log:info">
<with-param name="name" select="'link'" />
<with-param name="msg">
@ -1002,17 +916,7 @@
<!-- link everything that shall be a part of the classifier -->
<apply-templates select="." mode="compiler:entry-classifier" />
<apply-templates select="." mode="l:do-link">
<with-param name="symbols" select="
$deps[
@inclass='true'
and not( @type='param' )
and not( @type='type' )
and not( @type='meta' )
and not( @type='worksheet' )
]
" />
</apply-templates>
<!-- TODO: get rid of me completely! -->
<apply-templates select="." mode="compiler:exit-classifier" />
</template>
@ -1090,8 +994,7 @@
<apply-templates select="." mode="l:do-link">
<with-param name="symbols" select="
$deps[
not( @inclass='true' )
and not( @type='param' )
not( @type='param' )
and not( @type='type' )
and not( @type='func' )
and not( @type='meta' )