Skip to content

Commit

Permalink
Merge 1ea636b into 5085545
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBatty committed Jul 23, 2024
2 parents 5085545 + 1ea636b commit 03149bf
Show file tree
Hide file tree
Showing 16 changed files with 735 additions and 106 deletions.
4 changes: 2 additions & 2 deletions forc-pkg/src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ impl PackageManifest {
})
.map_err(|e| anyhow!("failed to parse manifest: {}.", e))?;
for warning in warnings {
println_warning(&warning);
//println_warning(&warning);
}
manifest.implicitly_include_std_if_missing();
manifest.implicitly_include_default_build_profiles_if_missing();
Expand Down Expand Up @@ -955,7 +955,7 @@ impl WorkspaceManifest {
})
.map_err(|e| anyhow!("failed to parse manifest: {}.", e))?;
for warning in warnings {
println_warning(&warning);
//println_warning(&warning);
}
Ok(manifest)
}
Expand Down
13 changes: 13 additions & 0 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,7 @@ pub fn check(

let mut results = vec![];
for (idx, &node) in plan.compilation_order.iter().enumerate() {
let now = std::time::Instant::now();
let pkg = &plan.graph[node];
let manifest = &plan.manifest_map()[&pkg.id()];

Expand All @@ -2670,6 +2671,7 @@ pub fn check(
let contract_id_value =
(idx == plan.compilation_order.len() - 1).then(|| DUMMY_CONTRACT_ID.to_string());

let dep_now = std::time::Instant::now();
let mut dep_namespace = dependency_namespace(
&lib_namespace_map,
&compiled_contract_deps,
Expand All @@ -2680,12 +2682,14 @@ pub fn check(
experimental,
)
.expect("failed to create dependency namespace");
eprintln!("⏱️ Dependency namespace took {:?}", dep_now.elapsed());

let profile = BuildProfile {
terse: terse_mode,
..BuildProfile::debug()
};

let build_config_now = std::time::Instant::now();
let build_config = sway_build_config(
manifest.dir(),
&manifest.entry_path(),
Expand All @@ -2694,9 +2698,11 @@ pub fn check(
)?
.with_include_tests(include_tests)
.with_lsp_mode(lsp_mode.clone());
eprintln!("⏱️ Build config took {:?}", build_config_now.elapsed());

let input = manifest.entry_string()?;
let handler = Handler::default();
let compile_to_ast_now = std::time::Instant::now();
let programs_res = sway_core::compile_to_ast(
&handler,
engines,
Expand All @@ -2706,11 +2712,13 @@ pub fn check(
&pkg.name,
retrigger_compilation.clone(),
);
eprintln!("⏱️ Compile to AST took {:?}", compile_to_ast_now.elapsed());

if retrigger_compilation
.as_ref()
.is_some_and(|b| b.load(std::sync::atomic::Ordering::SeqCst))
{
eprintln!("🪓 🪓 compilation was cancelled 2716");
bail!("compilation was retriggered")
}

Expand Down Expand Up @@ -2746,6 +2754,11 @@ pub fn check(
return Ok(results);
}
results.push((programs_res.ok(), handler));
eprintln!(
"⏱️ Compiling package {:?} took {:?}",
pkg.name,
now.elapsed()
);
}

if results.is_empty() {
Expand Down
1 change: 1 addition & 0 deletions sway-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ parking_lot = "0.12"
pest = "2.1.3"
pest_derive = "2.1"
petgraph = "0.6"
rayon = "1.5"
rustc-hash = "1.1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.91"
Expand Down
49 changes: 48 additions & 1 deletion sway-core/src/decl_engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
sync::Arc,
};

use sway_types::{Named, ProgramId, Spanned};
use sway_types::{Named, ProgramId, SourceId, Spanned};

use crate::{
concurrent_slab::ConcurrentSlab,
Expand Down Expand Up @@ -375,6 +375,53 @@ decl_engine_clear_program!(
type_alias_slab, ty::TyTypeAliasDecl;
);

macro_rules! decl_engine_clear_module {
($($slab:ident, $decl:ty);* $(;)?) => {
impl DeclEngine {
pub fn clear_module(&mut self, source_id: &SourceId) {
self.parents.write().retain(|key, _| {
match key {
AssociatedItemDeclId::TraitFn(decl_id) => {
self.get_trait_fn(decl_id).span().source_id().map_or(true, |src_id| src_id != source_id)
},
AssociatedItemDeclId::Function(decl_id) => {
self.get_function(decl_id).span().source_id().map_or(true, |src_id| src_id != source_id)
},
AssociatedItemDeclId::Type(decl_id) => {
self.get_type(decl_id).span().source_id().map_or(true, |src_id| src_id != source_id)
},
AssociatedItemDeclId::Constant(decl_id) => {
self.get_constant(decl_id).span().source_id().map_or(true, |src_id| src_id != source_id)
},
}
});

$(
self.$slab.retain(|_k, ty| match ty.span().source_id() {
Some(src_id) => src_id != source_id,
None => true,
});
)*
}
}
};
}

decl_engine_clear_module!(
function_slab, ty::TyFunctionDecl;
trait_slab, ty::TyTraitDecl;
trait_fn_slab, ty::TyTraitFn;
trait_type_slab, ty::TyTraitType;
impl_self_or_trait_slab, ty::TyImplTrait;
struct_slab, ty::TyStructDecl;
storage_slab, ty::TyStorageDecl;
abi_slab, ty::TyAbiDecl;
constant_slab, ty::TyConstantDecl;
configurable_slab, ty::TyConfigurableDecl;
enum_slab, ty::TyEnumDecl;
type_alias_slab, ty::TyTypeAliasDecl;
);

impl DeclEngine {
/// Given a [DeclRef] `index`, finds all the parents of `index` and all the
/// recursive parents of those parents, and so on. Does not perform
Expand Down
42 changes: 41 additions & 1 deletion sway-core/src/decl_engine/parsed_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
};

use std::sync::Arc;
use sway_types::{ProgramId, Spanned};
use sway_types::{ProgramId, SourceId, Spanned};

use super::parsed_id::ParsedDeclId;

Expand Down Expand Up @@ -167,6 +167,46 @@ decl_engine_clear_program!(
.span()),
);

macro_rules! decl_engine_clear_module {
($(($slab:ident, $getter:expr)),* $(,)?) => {
impl ParsedDeclEngine {
pub fn clear_module(&mut self, program_id: &SourceId) {
$(
self.$slab.retain(|_k, item| {
#[allow(clippy::redundant_closure_call)]
let span = $getter(item);
match span.source_id() {
Some(src_id) => src_id != program_id,
None => true,
}
});
)*
}
}
};
}

decl_engine_clear_module!(
(variable_slab, |item: &VariableDeclaration| item.name.span()),
(function_slab, |item: &FunctionDeclaration| item.name.span()),
(trait_slab, |item: &TraitDeclaration| item.name.span()),
(trait_fn_slab, |item: &TraitFn| item.name.span()),
(trait_type_slab, |item: &TraitTypeDeclaration| item
.name
.span()),
(impl_self_or_trait_slab, |item: &ImplSelfOrTrait| item
.block_span
.clone()),
(struct_slab, |item: &StructDeclaration| item.name.span()),
(storage_slab, |item: &StorageDeclaration| item.span.clone()),
(abi_slab, |item: &AbiDeclaration| item.name.span()),
(constant_slab, |item: &ConstantDeclaration| item.name.span()),
(enum_slab, |item: &EnumDeclaration| item.name.span()),
(type_alias_slab, |item: &TypeAliasDeclaration| item
.name
.span()),
);

impl ParsedDeclEngine {
/// Friendly helper method for calling the `get` method from the
/// implementation of [ParsedDeclEngineGet] for [ParsedDeclEngine]
Expand Down
8 changes: 8 additions & 0 deletions sway-core/src/engine_threading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ impl Engines {
self.parsed_decl_engine.clear_program(program_id);
}

/// Removes all data associated with `source_id` from the declaration and type engines.
/// It is intended to be used during garbage collection to remove any data that is no longer needed.
pub fn clear_module(&mut self, source_id: &sway_types::SourceId) {
self.type_engine.clear_module(source_id);
self.decl_engine.clear_module(source_id);
self.parsed_decl_engine.clear_module(source_id);
}

/// Helps out some `thing: T` by adding `self` as context.
pub fn help_out<T>(&self, thing: T) -> WithEngines<'_, T> {
WithEngines {
Expand Down
Loading

0 comments on commit 03149bf

Please sign in to comment.