Skip to content

Commit

Permalink
Avoid cycles in subclass closure
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarx committed Dec 13, 2023
1 parent d84c817 commit 6f13c1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions helpers/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ fn main() {
)
.init();

log::info!("Log level set to {}", log::max_level());

if cli.no_derived && cli.only == Some(Action::Derived) {
log::error!("--no-derived and --only=derived are mutually exclusive");
std::process::exit(1);
Expand Down
13 changes: 12 additions & 1 deletion helpers/rust/src/types/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ impl DumpStatistics {
}

fn close_subclasses(&mut self) -> usize {
log::info!("Computing subclass closure");

let mut added = 0;
let direct_superclasses = self
.classes
Expand All @@ -85,6 +87,7 @@ impl DumpStatistics {

while let Some(class) = class_queue.pop_front() {
let record = self.classes.entry(class).or_default();
let mut done = HashSet::new();
let mut superclasses = record
.direct_superclasses
.iter()
Expand All @@ -93,10 +96,16 @@ impl DumpStatistics {

while let Some(superclass) = superclasses.pop_front() {
record.superclasses.insert(superclass);
done.insert(superclass);
added += 1;

if let Some(new_superclasses) = direct_superclasses.get(&superclass) {
superclasses.extend(new_superclasses.iter().cloned());
superclasses.extend(
new_superclasses
.iter()
.filter(|superclass| !done.contains(superclass))
.cloned(),
);
}
}
}
Expand All @@ -116,6 +125,8 @@ impl DumpStatistics {
})
.collect::<Vec<_>>();

log::info!("Found {} non-empty classes", classes.len());

for (class, superclasses) in classes {
for super_class in superclasses {
let record = self.classes.entry(super_class).or_default();
Expand Down

0 comments on commit 6f13c1b

Please sign in to comment.