tamer: ir::asg::section: Reduce fields
This is intended to represent the sections written to the final xmle file, and there was unnecessary complexity in separating everything. By reducing this IR further, we can begin to constrain its types to eliminate some of the runtime panics and error checking we have/had in the writer.main
parent
f70f5653b2
commit
de62a2acbc
|
@ -299,18 +299,18 @@ where
|
||||||
|
|
||||||
match ident.kind() {
|
match ident.kind() {
|
||||||
Some(kind) => match kind {
|
Some(kind) => match kind {
|
||||||
IdentKind::Meta => deps.meta.push_body(ident),
|
IdentKind::Meta
|
||||||
IdentKind::Worksheet => deps.worksheet.push_body(ident),
|
| IdentKind::Worksheet
|
||||||
IdentKind::Param(_, _) => deps.params.push_body(ident),
|
| IdentKind::Param(_, _)
|
||||||
IdentKind::Type(_) => deps.types.push_body(ident),
|
| IdentKind::Type(_)
|
||||||
IdentKind::Func(_, _) => deps.funcs.push_body(ident),
|
| IdentKind::Func(_, _)
|
||||||
|
| IdentKind::Const(_, _) => deps.st.push_body(ident),
|
||||||
IdentKind::MapHead
|
IdentKind::MapHead
|
||||||
| IdentKind::Map
|
| IdentKind::Map
|
||||||
| IdentKind::MapTail => deps.map.push_body(ident),
|
| IdentKind::MapTail => deps.map.push_body(ident),
|
||||||
IdentKind::RetMapHead
|
IdentKind::RetMapHead
|
||||||
| IdentKind::RetMap
|
| IdentKind::RetMap
|
||||||
| IdentKind::RetMapTail => deps.retmap.push_body(ident),
|
| IdentKind::RetMapTail => deps.retmap.push_body(ident),
|
||||||
IdentKind::Const(_, _) => deps.consts.push_body(ident),
|
|
||||||
_ => deps.rater.push_body(ident),
|
_ => deps.rater.push_body(ident),
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
|
@ -888,11 +888,9 @@ mod test {
|
||||||
fn graph_sort() -> SortableAsgResult<(), u16> {
|
fn graph_sort() -> SortableAsgResult<(), u16> {
|
||||||
let mut sut = Sut::new();
|
let mut sut = Sut::new();
|
||||||
|
|
||||||
let mut meta = vec![];
|
let mut st = vec![];
|
||||||
let mut worksheet = vec![];
|
|
||||||
let mut map = vec![];
|
let mut map = vec![];
|
||||||
let mut retmap = vec![];
|
let mut retmap = vec![];
|
||||||
let mut consts = vec![];
|
|
||||||
|
|
||||||
let base = "sym1".intern();
|
let base = "sym1".intern();
|
||||||
let base_node = sut
|
let base_node = sut
|
||||||
|
@ -900,9 +898,9 @@ mod test {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
add_syms!(sut, base, {
|
add_syms!(sut, base, {
|
||||||
meta <- meta1: IdentKind::Meta,
|
st <- meta1: IdentKind::Meta,
|
||||||
worksheet <- work1: IdentKind::Worksheet,
|
st <- work1: IdentKind::Worksheet,
|
||||||
consts <- const1: IdentKind::Const(Dim::from_u8(0), DataType::Float),
|
st <- const1: IdentKind::Const(Dim::from_u8(0), DataType::Float),
|
||||||
map <- map1: IdentKind::MapHead,
|
map <- map1: IdentKind::MapHead,
|
||||||
map <- map2: IdentKind::Map,
|
map <- map2: IdentKind::Map,
|
||||||
map <- map3: IdentKind::MapTail,
|
map <- map3: IdentKind::MapTail,
|
||||||
|
@ -913,22 +911,20 @@ mod test {
|
||||||
retmap <- retmap5: IdentKind::RetMap,
|
retmap <- retmap5: IdentKind::RetMap,
|
||||||
map <- map4: IdentKind::MapHead,
|
map <- map4: IdentKind::MapHead,
|
||||||
map <- map5: IdentKind::Map,
|
map <- map5: IdentKind::Map,
|
||||||
meta <- meta2: IdentKind::Meta,
|
st <- meta2: IdentKind::Meta,
|
||||||
worksheet <- work2: IdentKind::Worksheet,
|
st <- work2: IdentKind::Worksheet,
|
||||||
map <- map6: IdentKind::MapTail,
|
map <- map6: IdentKind::MapTail,
|
||||||
retmap <- retmap6: IdentKind::RetMapHead,
|
retmap <- retmap6: IdentKind::RetMapHead,
|
||||||
consts <- const2: IdentKind::Const(Dim::from_u8(2), DataType::Float),
|
st <- const2: IdentKind::Const(Dim::from_u8(2), DataType::Float),
|
||||||
});
|
});
|
||||||
|
|
||||||
map.push(base);
|
map.push(base);
|
||||||
|
|
||||||
let sections = sut.sort(&vec![base_node])?;
|
let sections = sut.sort(&vec![base_node])?;
|
||||||
|
|
||||||
assert_section_sym!(sections.meta, meta);
|
assert_section_sym!(sections.st, st);
|
||||||
assert_section_sym!(sections.worksheet, worksheet);
|
|
||||||
assert_section_sym!(sections.map, map);
|
assert_section_sym!(sections.map, map);
|
||||||
assert_section_sym!(sections.retmap, retmap);
|
assert_section_sym!(sections.retmap, retmap);
|
||||||
assert_section_sym!(sections.consts, consts);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,11 @@ impl<'a, T> Iterator for SectionIter<'a, T> {
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
self.0.next().map(|x| *x)
|
self.0.next().map(|x| *x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
|
let (low, high) = self.0.size_hint();
|
||||||
|
(low, high.map(|x| x + 2))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ASG objects organized into logical sections.
|
/// ASG objects organized into logical sections.
|
||||||
|
@ -121,12 +126,7 @@ impl<'a, T> Iterator for SectionIter<'a, T> {
|
||||||
pub struct Sections<'a, T> {
|
pub struct Sections<'a, T> {
|
||||||
pub map: Section<'a, T>,
|
pub map: Section<'a, T>,
|
||||||
pub retmap: Section<'a, T>,
|
pub retmap: Section<'a, T>,
|
||||||
pub meta: Section<'a, T>,
|
pub st: Section<'a, T>,
|
||||||
pub worksheet: Section<'a, T>,
|
|
||||||
pub params: Section<'a, T>,
|
|
||||||
pub types: Section<'a, T>,
|
|
||||||
pub funcs: Section<'a, T>,
|
|
||||||
pub consts: Section<'a, T>,
|
|
||||||
pub rater: Section<'a, T>,
|
pub rater: Section<'a, T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,12 +137,7 @@ impl<'a, T: IdentObjectData> Sections<'a, T> {
|
||||||
Self {
|
Self {
|
||||||
map: Section::new(),
|
map: Section::new(),
|
||||||
retmap: Section::new(),
|
retmap: Section::new(),
|
||||||
meta: Section::new(),
|
st: Section::new(),
|
||||||
worksheet: Section::new(),
|
|
||||||
params: Section::new(),
|
|
||||||
types: Section::new(),
|
|
||||||
funcs: Section::new(),
|
|
||||||
consts: Section::new(),
|
|
||||||
rater: Section::new(),
|
rater: Section::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,12 +158,7 @@ impl<'a, T: IdentObjectData> Sections<'a, T> {
|
||||||
self.map
|
self.map
|
||||||
.iter()
|
.iter()
|
||||||
.chain(self.retmap.iter())
|
.chain(self.retmap.iter())
|
||||||
.chain(self.meta.iter())
|
.chain(self.st.iter())
|
||||||
.chain(self.worksheet.iter())
|
|
||||||
.chain(self.params.iter())
|
|
||||||
.chain(self.types.iter())
|
|
||||||
.chain(self.funcs.iter())
|
|
||||||
.chain(self.consts.iter())
|
|
||||||
.chain(self.rater.iter()),
|
.chain(self.rater.iter()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -185,15 +175,7 @@ impl<'a, T: IdentObjectData> Sections<'a, T> {
|
||||||
/// they may change or be combined in the future.
|
/// they may change or be combined in the future.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn iter_static(&self) -> SectionsIter<T> {
|
pub fn iter_static(&self) -> SectionsIter<T> {
|
||||||
SectionsIter(SectionsIterType::Static(
|
SectionsIter(SectionsIterType::Single(self.st.iter()))
|
||||||
self.meta
|
|
||||||
.iter()
|
|
||||||
.chain(self.worksheet.iter())
|
|
||||||
.chain(self.params.iter())
|
|
||||||
.chain(self.types.iter())
|
|
||||||
.chain(self.funcs.iter())
|
|
||||||
.chain(self.consts.iter()),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct an iterator over the map section.
|
/// Construct an iterator over the map section.
|
||||||
|
@ -235,16 +217,11 @@ impl<'a, T: IdentObjectData> Sections<'a, T> {
|
||||||
type SIter<'a, T> = SectionIter<'a, T>;
|
type SIter<'a, T> = SectionIter<'a, T>;
|
||||||
type CSIter1<'a, T, L> = Chain<L, SIter<'a, T>>;
|
type CSIter1<'a, T, L> = Chain<L, SIter<'a, T>>;
|
||||||
type CSIter2<'a, T, L> = CSIter1<'a, T, CSIter1<'a, T, L>>;
|
type CSIter2<'a, T, L> = CSIter1<'a, T, CSIter1<'a, T, L>>;
|
||||||
type CSIter4<'a, T, L> = CSIter2<'a, T, CSIter2<'a, T, L>>;
|
type SIter4<'a, T> = CSIter2<'a, T, CSIter1<'a, T, SIter<'a, T>>>;
|
||||||
type CSIter8<'a, T, L> = CSIter4<'a, T, CSIter4<'a, T, L>>;
|
|
||||||
|
|
||||||
type SIter6<'a, T> = CSIter4<'a, T, CSIter1<'a, T, SIter<'a, T>>>;
|
|
||||||
type SIter9<'a, T> = CSIter8<'a, T, SIter<'a, T>>;
|
|
||||||
|
|
||||||
/// Types of iterators encapsulated by [`SectionsIter`].
|
/// Types of iterators encapsulated by [`SectionsIter`].
|
||||||
enum SectionsIterType<'a, T> {
|
enum SectionsIterType<'a, T> {
|
||||||
All(SIter9<'a, T>),
|
All(SIter4<'a, T>),
|
||||||
Static(SIter6<'a, T>),
|
|
||||||
Single(SIter<'a, T>),
|
Single(SIter<'a, T>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +239,6 @@ impl<'a, T> Iterator for SectionsIter<'a, T> {
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
match &mut self.0 {
|
match &mut self.0 {
|
||||||
SectionsIterType::All(inner) => inner.next(),
|
SectionsIterType::All(inner) => inner.next(),
|
||||||
SectionsIterType::Static(inner) => inner.next(),
|
|
||||||
SectionsIterType::Single(inner) => inner.next(),
|
SectionsIterType::Single(inner) => inner.next(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,7 +247,6 @@ impl<'a, T> Iterator for SectionsIter<'a, T> {
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
match &self.0 {
|
match &self.0 {
|
||||||
SectionsIterType::All(inner) => inner.size_hint(),
|
SectionsIterType::All(inner) => inner.size_hint(),
|
||||||
SectionsIterType::Static(inner) => inner.size_hint(),
|
|
||||||
SectionsIterType::Single(inner) => inner.size_hint(),
|
SectionsIterType::Single(inner) => inner.size_hint(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -382,7 +357,7 @@ mod test {
|
||||||
fn sections_iter_all() {
|
fn sections_iter_all() {
|
||||||
let mut sections = Sections::new();
|
let mut sections = Sections::new();
|
||||||
|
|
||||||
let objs = (0..=10)
|
let objs = (0..=5)
|
||||||
.map(|i| IdentObject::Missing(i.to_string().into()))
|
.map(|i| IdentObject::Missing(i.to_string().into()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
@ -390,13 +365,8 @@ mod test {
|
||||||
sections.map.body.push(&objs[1]);
|
sections.map.body.push(&objs[1]);
|
||||||
sections.map.set_tail(&objs[2]);
|
sections.map.set_tail(&objs[2]);
|
||||||
sections.retmap.body.push(&objs[3]);
|
sections.retmap.body.push(&objs[3]);
|
||||||
sections.meta.body.push(&objs[4]);
|
sections.st.body.push(&objs[4]);
|
||||||
sections.worksheet.body.push(&objs[5]);
|
sections.rater.body.push(&objs[5]);
|
||||||
sections.params.body.push(&objs[6]);
|
|
||||||
sections.types.body.push(&objs[7]);
|
|
||||||
sections.funcs.body.push(&objs[8]);
|
|
||||||
sections.consts.body.push(&objs[9]);
|
|
||||||
sections.rater.body.push(&objs[10]);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
sections.iter_all().collect::<Vec<_>>(),
|
sections.iter_all().collect::<Vec<_>>(),
|
||||||
|
|
|
@ -178,7 +178,7 @@ fn test_writes_deps() -> TestResult {
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
objs.iter().for_each(|x| sections.consts.push_body(x));
|
objs.iter().for_each(|x| sections.st.push_body(x));
|
||||||
|
|
||||||
let mut iter = parser_from(
|
let mut iter = parser_from(
|
||||||
lower_iter(§ions, "pkg".intern(), relroot)
|
lower_iter(§ions, "pkg".intern(), relroot)
|
||||||
|
@ -468,5 +468,5 @@ macro_rules! test_exec_sec {
|
||||||
|
|
||||||
test_exec_sec!(test_map_exec, QN_L_MAP_EXEC, map);
|
test_exec_sec!(test_map_exec, QN_L_MAP_EXEC, map);
|
||||||
test_exec_sec!(test_retmap_exec, QN_L_RETMAP_EXEC, retmap);
|
test_exec_sec!(test_retmap_exec, QN_L_RETMAP_EXEC, retmap);
|
||||||
test_exec_sec!(test_static, QN_L_STATIC, params); // just pick a static
|
test_exec_sec!(test_static, QN_L_STATIC, st);
|
||||||
test_exec_sec!(test_exec, QN_L_EXEC, rater);
|
test_exec_sec!(test_exec, QN_L_EXEC, rater);
|
||||||
|
|
Loading…
Reference in New Issue