tamer: Remove {ret}map:___{head,tail}

These have been a pain in the ass since TAMER began.

It seemed like a good idea at the time to have static code generated in this
way, but the lack of explicit dependencies just makes this a mess and works
against the operating theory of the system.

Furthermore, the _same_ static fragments were generated for each and every
map package.

There is still a post-link step (standalones) handled in XSLT; the
previously-static code has been moved there.  This will eventually be
integrated into tameld itself, once TAMER has facilities for JS generation.

(This was discovered while trying to parent identifiers to packages.)

DEV-13162
main
Mike Gerwitz 2023-04-28 16:40:26 -04:00
parent 77ada079e1
commit 068804b397
6 changed files with 12 additions and 146 deletions

View File

@ -1,4 +1,4 @@
# This number is incremented for every linker change to force rebuilding
# of xmle files.
4
5 # Removal of {ret,}map:___{head,tail}

View File

@ -127,27 +127,12 @@
$pkg-with-symtable/preproc:sym-deps" />
<preproc:fragments>
<!-- special fragment to be output as the head -->
<preproc:fragment id=":map:___head">
<!-- use a callback just in case we need to make portions of this async in the
future -->
<text>function( input, callback ) {</text>
<text>var output = {};</text>
</preproc:fragment>
<!-- compile mapped -->
<apply-templates select="./lvm:*" mode="lvmc:compile">
<with-param name="rater" select="$rater" />
<with-param name="type" select="'map'" />
<with-param name="symtable" select="$pkg-with-symtable/preproc:symtable"
tunnel="yes"/>
</apply-templates>
<!-- special fragment to be output as the foot -->
<preproc:fragment id=":map:___tail">
<text>callback(output);</text>
<text>};</text>
</preproc:fragment>
</preproc:fragments>
<sequence select="$pkg-with-symtable/preproc:sym-deps/following-sibling::*" />
@ -204,27 +189,12 @@
$pkg-with-symtable/preproc:sym-deps" />
<preproc:fragments>
<!-- special fragment to be output as the head -->
<preproc:fragment id=":retmap:___head">
<!-- use a callback just in case we need to make portions of this async in the
future -->
<text>function( input, callback ) {</text>
<text>var output = {};</text>
</preproc:fragment>
<!-- compile mapped -->
<apply-templates select="./lvm:*" mode="lvmc:compile">
<with-param name="rater" select="$rater" />
<with-param name="type" select="'retmap'" />
<with-param name="symtable" select="$pkg-with-symtable/preproc:symtable"
tunnel="yes"/>
</apply-templates>
<!-- special fragment to be output as the foot -->
<preproc:fragment id=":retmap:___tail">
<text>callback(output);</text>
<text>};</text>
</preproc:fragment>
</preproc:fragments>
<sequence select="$pkg-with-symtable/preproc:sym-deps/following-sibling::*" />
@ -236,19 +206,6 @@
<param name="type-prefix" select="'map'" />
<preproc:symtable>
<!-- purposely non-polluting. @ignore-dup is intended to be
temporary until static generation of these names is resolved;
this will not cause problems, since the code is always the
same (future bug pending!) -->
<preproc:sym name=":{$type-prefix}:___head"
type="{$type-prefix}:head"
pollute="true"
ignore-dup="true"
no-deps="true" />
<preproc:sym name=":{$type-prefix}:___tail"
type="{$type-prefix}:tail"
ignore-dup="true"
no-deps="true" />
</preproc:symtable>
</template>

View File

@ -75,34 +75,16 @@
<variable name="retmap" select="/lv:package/l:retmap-exec" />
<!-- store a reference to the mapper in rater.fromMap() -->
<text>rater.fromMap = </text>
<choose>
<when test="/lv:package/l:dep/preproc:sym[@type='map'][1]">
<value-of disable-output-escaping="yes" select="$map/text()" />
</when>
<!-- no map available -->
<otherwise>
<!-- simply invoke the conintuation with the provided data -->
<text>function(d,c){c(d);}</text>
</otherwise>
</choose>
<text>; </text>
<text>rater.fromMap=function(input,callback){</text>
<text>var output={};</text>
<value-of disable-output-escaping="yes" select="$map/text()" />
<text>callback(output);}; </text>
<!-- return map -->
<text>rater._retmap = </text>
<choose>
<when test="/lv:package/l:dep/preproc:sym[@type='retmap'][1]">
<value-of disable-output-escaping="yes" select="$retmap/text()" />
</when>
<!-- no map available -->
<otherwise>
<!-- simply invoke the conintuation with the provided data -->
<text>function(d,c){c(d);}</text>
</otherwise>
</choose>
<text>; </text>
<text>rater._retmap=function(input,callback){</text>
<text>var output={};</text>
<value-of disable-output-escaping="yes" select="$retmap/text()" />
<text>callback(output);}; </text>
<!-- we'll export a version that automatically performs the mapping -->
<text>module.exports = function( args_base, _canterm ) { </text>

View File

@ -23,12 +23,10 @@
use super::section::{SectionsError, XmleSections};
use crate::{
asg::{visit::topo_sort, Asg, AsgError, Ident, Object},
asg::{visit::topo_sort, Asg, AsgError, Object},
diagnose::{Annotate, Diagnostic},
diagnostic_unreachable,
parse::util::SPair,
span::UNKNOWN_SPAN,
sym::{st, GlobalSymbolResolve, SymbolId},
};
// Result of [`sort`].
@ -41,12 +39,6 @@ pub fn sort<'a, S: XmleSections<'a>>(asg: &'a Asg, mut dest: S) -> SortResult<S>
where
S: XmleSections<'a>,
{
// These are always generated by the map compiler,
// but do not have edges that would allow them to be properly ordered
// (adding an edge to every map object would be wasteful).
dest.push(get_ident(asg, st::L_MAP_UUUHEAD))?;
dest.push(get_ident(asg, st::L_RETMAP_UUUHEAD))?;
let roots = [asg.root(UNKNOWN_SPAN).widen()].into_iter();
for result in topo_sort(asg, roots) {
@ -72,27 +64,9 @@ where
}
}
dest.push(get_ident(asg, st::L_MAP_UUUTAIL))?;
dest.push(get_ident(asg, st::L_RETMAP_UUUTAIL))?;
Ok(dest)
}
fn get_ident<S>(depgraph: &Asg, name: S) -> &Ident
where
S: Into<SymbolId>,
{
let oi_root = depgraph.root(UNKNOWN_SPAN);
let sym = name.into();
depgraph
.lookup(oi_root, SPair(sym, UNKNOWN_SPAN))
.and_then(|id| depgraph.get(id))
.unwrap_or_else(|| {
panic!("missing internal identifier: {}", sym.lookup_str())
})
}
/// Error during graph sorting.
///
/// These errors reflect barriers to meaningfully understanding the

View File

@ -23,7 +23,7 @@ use crate::{
ld::xmle::{section::PushResult, Sections},
parse::util::SPair,
span::dummy::*,
sym::GlobalSymbolIntern,
sym::SymbolId,
};
fn declare(
@ -43,43 +43,7 @@ fn lookup_or_missing(asg: &mut Asg, name: SPair) -> ObjectIndex<Ident> {
/// Create a graph with the expected {ret,}map head/tail identifiers.
fn make_asg() -> Asg {
let mut asg = Asg::new();
let text = "dummy fragment".intern();
{
let sym = SPair(st::L_MAP_UUUHEAD.into(), S1);
declare(&mut asg, sym, IdentKind::MapHead, Default::default())
.unwrap()
.set_fragment(&mut asg, text)
.unwrap();
}
{
let sym = SPair(st::L_MAP_UUUTAIL.into(), S2);
declare(&mut asg, sym, IdentKind::MapTail, Default::default())
.unwrap()
.set_fragment(&mut asg, text)
.unwrap();
}
{
let sym = SPair(st::L_RETMAP_UUUHEAD.into(), S3);
declare(&mut asg, sym, IdentKind::RetMapHead, Default::default())
.unwrap()
.set_fragment(&mut asg, text)
.unwrap();
}
{
let sym = SPair(st::L_RETMAP_UUUTAIL.into(), S4);
declare(&mut asg, sym, IdentKind::RetMapTail, Default::default())
.unwrap()
.set_fragment(&mut asg, text)
.unwrap();
}
asg
Asg::new()
}
#[test]
@ -156,16 +120,10 @@ fn graph_sort() -> SortResult<()> {
assert_eq!(
sections.pushed,
vec![
// Static head
get_ident(&asg, st::L_MAP_UUUHEAD),
get_ident(&asg, st::L_RETMAP_UUUHEAD),
// Post-order
asg.get(adepdep).unwrap(),
asg.get(adep).unwrap(),
asg.get(a).unwrap(),
// Static tail
get_ident(&asg, st::L_MAP_UUUTAIL),
get_ident(&asg, st::L_RETMAP_UUUTAIL),
]
.into_iter()
.collect::<Vec<_>>()

View File

@ -720,11 +720,6 @@ pub mod st {
CC_ANY_OF: cid "anyOf",
L_MAP_UUUHEAD: str ":map:___head",
L_MAP_UUUTAIL: str ":map:___tail",
L_RETMAP_UUUHEAD: str ":retmap:___head",
L_RETMAP_UUUTAIL: str ":retmap:___tail",
U_TRUE: cid "TRUE",
URI_LV_CALC: uri "http://www.lovullo.com/calc",