Skip to content

Commit

Permalink
chore: remove PhantomCall struct
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Jul 22, 2024
1 parent 37ee9e6 commit d11dcca
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 86 deletions.
27 changes: 2 additions & 25 deletions assembly/src/assembler/module_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,20 @@ mod analysis;
mod callgraph;
mod debug;
mod name_resolver;
mod phantom;
mod procedure_cache;
mod rewrites;

pub use self::callgraph::{CallGraph, CycleError};
pub use self::name_resolver::{CallerInfo, ResolvedTarget};
pub use self::procedure_cache::ProcedureCache;

use alloc::{
boxed::Box,
collections::{BTreeMap, BTreeSet},
sync::Arc,
vec::Vec,
};
use alloc::{boxed::Box, collections::BTreeMap, sync::Arc, vec::Vec};
use core::ops::Index;
use vm_core::Kernel;

use smallvec::{smallvec, SmallVec};

use self::{
analysis::MaybeRewriteCheck, name_resolver::NameResolver, phantom::PhantomCall,
rewrites::ModuleRewriter,
};
use self::{analysis::MaybeRewriteCheck, name_resolver::NameResolver, rewrites::ModuleRewriter};
use super::{GlobalProcedureIndex, ModuleIndex};
use crate::{
ast::{
Expand Down Expand Up @@ -60,13 +51,6 @@ pub struct ModuleGraph {
roots: BTreeMap<RpoDigest, SmallVec<[GlobalProcedureIndex; 1]>>,
/// The set of procedures in this graph which have known MAST roots
digests: BTreeMap<GlobalProcedureIndex, RpoDigest>,
/// The set of procedures which have no known definition in the graph, aka "phantom calls".
/// Since we know the hash of these functions, we can proceed with compilation, but in some
/// contexts we wish to disallow them and raise an error if any such calls are present.
///
/// When we merge graphs, we attempt to resolve phantoms by attempting to find definitions in
/// the opposite graph.
phantoms: BTreeSet<PhantomCall>,
kernel_index: Option<ModuleIndex>,
kernel: Kernel,
}
Expand Down Expand Up @@ -243,7 +227,6 @@ impl ModuleGraph {
for module in pending.iter() {
resolver.push_pending(module);
}
let mut phantoms = BTreeSet::default();
let mut edges = Vec::new();
let mut finished = Vec::<Arc<Module>>::new();

Expand All @@ -254,9 +237,6 @@ impl ModuleGraph {
let mut rewriter = ModuleRewriter::new(&resolver);
rewriter.apply(module_id, &mut module)?;

// Gather the phantom calls found while rewriting the module
phantoms.extend(rewriter.phantoms());

for (index, procedure) in module.procedures().enumerate() {
let procedure_id = ProcedureIndex::new(index);
let gid = GlobalProcedureIndex {
Expand Down Expand Up @@ -286,7 +266,6 @@ impl ModuleGraph {
drop(resolver);

// Extend the graph with all of the new additions
self.phantoms.extend(phantoms);
self.modules.append(&mut finished);
edges
.into_iter()
Expand Down Expand Up @@ -337,8 +316,6 @@ impl ModuleGraph {
let mut rewriter = ModuleRewriter::new(&resolver);
rewriter.apply(module_id, &mut module)?;

self.phantoms.extend(rewriter.phantoms());

Ok(Some(Arc::from(module)))
} else {
Ok(None)
Expand Down
45 changes: 0 additions & 45 deletions assembly/src/assembler/module_graph/phantom.rs

This file was deleted.

18 changes: 2 additions & 16 deletions assembly/src/assembler/module_graph/rewrites/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::ops::ControlFlow;

use crate::{
assembler::{
module_graph::{CallerInfo, NameResolver, PhantomCall},
module_graph::{CallerInfo, NameResolver},
ModuleIndex, ResolvedTarget,
},
ast::{
Expand All @@ -24,7 +24,6 @@ pub struct ModuleRewriter<'a, 'b: 'a> {
resolver: &'a NameResolver<'b>,
module_id: ModuleIndex,
invoked: BTreeSet<Invoke>,
phantoms: BTreeSet<PhantomCall>,
source_file: Option<Arc<SourceFile>>,
}

Expand All @@ -35,7 +34,6 @@ impl<'a, 'b: 'a> ModuleRewriter<'a, 'b> {
resolver,
module_id: ModuleIndex::new(u16::MAX as usize),
invoked: Default::default(),
phantoms: Default::default(),
source_file: None,
}
}
Expand All @@ -56,11 +54,6 @@ impl<'a, 'b: 'a> ModuleRewriter<'a, 'b> {
Ok(())
}

/// Take the set of accumulated phantom calls out of this rewriter
pub fn phantoms(&mut self) -> BTreeSet<PhantomCall> {
core::mem::take(&mut self.phantoms)
}

fn rewrite_target(
&mut self,
kind: InvokeKind,
Expand All @@ -81,14 +74,7 @@ impl<'a, 'b: 'a> ModuleRewriter<'a, 'b> {
target: target.clone(),
});
}
Ok(ResolvedTarget::Phantom(callee)) => {
let call = PhantomCall {
span: target.span(),
source_file: self.source_file.clone(),
callee,
};
self.phantoms.insert(call);
}
Ok(ResolvedTarget::Phantom(_)) => (),
Ok(ResolvedTarget::Exact { .. }) => {
self.invoked.insert(Invoke {
kind,
Expand Down

0 comments on commit d11dcca

Please sign in to comment.