-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should not sleep Fixes #356
base: master
Are you sure you want to change the base?
Changes from 6 commits
0471800
109ae64
3d15d6a
0415643
23693c7
6a14a25
dc54c72
ca20006
ebc661c
3a60844
e554514
3429a01
c5667bf
505a52c
da085a7
c6d4ba5
b9a0314
f19545a
569cfc4
e934dac
92cc07f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
extern crate dreamchecker as dc; | ||
|
||
use dc::test_helpers::check_errors_match; | ||
|
||
const PURE_ERRORS: &[(u32, u16, &str)] = &[ | ||
(12, 16, "/mob/proc/test2 sets SpacemanDMM_should_be_pure but calls a /proc/impure that does impure operations"), | ||
]; | ||
|
||
#[test] | ||
fn pure() { | ||
let code = r##" | ||
/proc/pure() | ||
return 1 | ||
/proc/impure() | ||
world << "foo" | ||
/proc/foo() | ||
pure() | ||
/proc/bar() | ||
impure() | ||
/mob/proc/test() | ||
set SpacemanDMM_should_be_pure = TRUE | ||
return foo() | ||
/mob/proc/test2() | ||
set SpacemanDMM_should_be_pure = TRUE | ||
bar() | ||
"##.trim(); | ||
check_errors_match(code, PURE_ERRORS); | ||
} | ||
|
||
// these tests are separate because the ordering the errors are reported in isn't determinate and I CBF figuring out why -spookydonut Jan 2020 | ||
// TODO: find out why | ||
const PURE2_ERRORS: &[(u32, u16, &str)] = &[ | ||
(5, 5, "call to pure proc test discards return value"), | ||
]; | ||
|
||
#[test] | ||
fn pure2() { | ||
let code = r##" | ||
/mob/proc/test() | ||
set SpacemanDMM_should_be_pure = TRUE | ||
return 1 | ||
/mob/proc/test2() | ||
test() | ||
/mob/proc/test3() | ||
return test() | ||
"##.trim(); | ||
check_errors_match(code, PURE2_ERRORS); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,17 @@ impl<'a> TypeRef<'a> { | |
} | ||
} | ||
|
||
/// Recursively visit this and all child **types**. | ||
pub fn recurse_types<F: FnMut(TypeRef<'a>)>(&self, f: &mut F) { | ||
self.recurse(f); | ||
for parent_typed_idx in &self.tree.redirected_parent_types { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is going to visit things multiple times There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it? |
||
let parent_typed = &self.tree.graph[parent_typed_idx.index()]; | ||
if parent_typed.parent_type_index().unwrap() == self.index() { | ||
f(TypeRef::new(self.tree, *parent_typed_idx)); | ||
} | ||
} | ||
} | ||
|
||
/// Recursively visit this and all parent **types**. | ||
pub fn visit_parent_types<F: FnMut(TypeRef<'a>)>(&self, f: &mut F) { | ||
let mut next = Some(*self); | ||
|
@@ -569,7 +580,7 @@ impl<'a> ProcRef<'a> { | |
|
||
/// Recursively visit this and all public-facing procs which override it. | ||
pub fn recurse_children<F: FnMut(ProcRef<'a>)>(self, f: &mut F) { | ||
self.ty.recurse(&mut move |ty| { | ||
self.ty.recurse_types(&mut move |ty| { | ||
if let Some(proc) = ty.get().procs.get(self.name) { | ||
f(ProcRef { | ||
ty, | ||
|
@@ -628,6 +639,7 @@ impl<'a> std::hash::Hash for ProcRef<'a> { | |
pub struct ObjectTree { | ||
graph: Vec<Type>, | ||
types: BTreeMap<String, NodeIndex>, | ||
redirected_parent_types: Vec<NodeIndex>, | ||
} | ||
|
||
impl ObjectTree { | ||
|
@@ -752,6 +764,7 @@ impl Default for ObjectTreeBuilder { | |
let mut tree = ObjectTree { | ||
graph: Vec::with_capacity(0x4000), | ||
types: Default::default(), | ||
redirected_parent_types: Vec::new() | ||
}; | ||
tree.graph.push(Type { | ||
path: String::new(), | ||
|
@@ -906,7 +919,11 @@ impl ObjectTreeBuilder { | |
} | ||
}; | ||
|
||
self.inner.graph[type_idx.index()].parent_type = idx; | ||
let type_ref = &mut self.inner.graph[type_idx.index()]; | ||
type_ref.parent_type = idx; | ||
if type_ref.parent_path != idx { | ||
self.inner.redirected_parent_types.push(type_idx); | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way this was implemented wasn't effective and the cause of the misses because it didn't catch overrides that called that called procs that slept.