Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoseph Frazer <joseph.frazer@ryansg.com>2020-03-07 10:49:41 -0500
committerJoseph Frazer <joseph.frazer@ryansg.com>2020-03-09 08:23:13 -0400
commitf373a00a80a4a366573d178911f455561fc2c0ff (patch)
tree201b1f3d37207658003e7e87cba48eb4948e8eca /tamer/src/ld/poc.rs
parent2a5551a04a6705d20e16c54aca1f875198ae89ab (diff)
downloadtame-f373a00a80a4a366573d178911f455561fc2c0ff.tar.gz
tame-f373a00a80a4a366573d178911f455561fc2c0ff.tar.bz2
tame-f373a00a80a4a366573d178911f455561fc2c0ff.zip
[DEV-7134] Propagate sorting errors
If a node is found while sorting that is not expected, we should show the error to the user.
Diffstat (limited to 'tamer/src/ld/poc.rs')
-rw-r--r--tamer/src/ld/poc.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/tamer/src/ld/poc.rs b/tamer/src/ld/poc.rs
index 6d3d175..6e0a7fe 100644
--- a/tamer/src/ld/poc.rs
+++ b/tamer/src/ld/poc.rs
@@ -21,7 +21,9 @@
//! banished to its own file to try to make that more clear.
use crate::global;
-use crate::ir::asg::{Asg, DefaultAsg, IdentKind, Object, ObjectRef, Source};
+use crate::ir::asg::{
+ Asg, AsgError, DefaultAsg, IdentKind, Object, ObjectRef, Source,
+};
use crate::obj::xmle::writer::{Sections, XmleWriter};
use crate::obj::xmlo::reader::{XmloError, XmloEvent, XmloReader};
use crate::sym::{DefaultInterner, Interner, Symbol};
@@ -76,7 +78,7 @@ pub fn main(package_path: &str, output: &str) -> Result<(), Box<dyn Error>> {
.filter_map(|sym| depgraph.lookup(sym)),
);
- let mut sorted = sort_deps(&depgraph, &roots);
+ let mut sorted = sort_deps(&depgraph, &roots)?;
//println!("Sorted ({}): {:?}", sorted.len(), sorted);
@@ -239,7 +241,7 @@ fn load_xmlo<'a, 'i, I: Interner<'i>>(
fn sort_deps<'a, 'i>(
depgraph: &'a LinkerAsg<'i>,
roots: &Vec<LinkerObjectRef>,
-) -> Sections<'a, 'i> {
+) -> Result<Sections<'a, 'i>, Box<dyn Error>> {
// @type=meta, @preproc:elig-class-yields
// @type={ret}map{,:head,:tail}
@@ -259,7 +261,7 @@ fn sort_deps<'a, 'i>(
// TODO: can we encapsulate NodeIndex?
while let Some(index) = dfs.next(&depgraph) {
- let ident = depgraph.get(index).unwrap();
+ let ident = depgraph.get(index).expect("missing node");
match ident {
Object::Ident(_, kind, _)
@@ -277,11 +279,15 @@ fn sort_deps<'a, 'i>(
| IdentKind::RetMapTail => deps.retmap.push_body(ident),
_ => deps.rater.push_body(ident),
},
- _ => panic!("unexpected node: {:?}", ident),
+ _ => {
+ return Err(
+ AsgError::UnexpectedNode(format!("{:?}", ident)).into()
+ )
+ }
}
}
- deps
+ Ok(deps)
}
fn get_interner_value<'a, 'i, I: Interner<'i>>(