diff --git a/compiler-cli/src/export.rs b/compiler-cli/src/export.rs index 9b58293e2c4..c34035e5a65 100644 --- a/compiler-cli/src/export.rs +++ b/compiler-cli/src/export.rs @@ -130,7 +130,7 @@ pub fn package_interface(path: Utf8PathBuf) -> Result<()> { // Build the project let mut built = crate::build::main( Options { - mode: Mode::Prod, + mode: Mode::PackageInterface, target: None, codegen: Codegen::All, compile: Compile::All, diff --git a/compiler-core/src/build.rs b/compiler-core/src/build.rs index 7f5b6dffad9..917f741b0ef 100644 --- a/compiler-core/src/build.rs +++ b/compiler-core/src/build.rs @@ -185,6 +185,7 @@ pub enum Mode { Dev, Prod, Lsp, + PackageInterface, } impl Mode { @@ -193,7 +194,7 @@ impl Mode { pub fn includes_tests(&self) -> bool { match self { Self::Dev | Self::Lsp => true, - Self::Prod => false, + Self::Prod | Self::PackageInterface => false, } } } @@ -209,7 +210,6 @@ fn mode_includes_tests() { pub struct Package { pub config: PackageConfig, pub modules: Vec, - pub cached_metadata: Vec, } impl Package { @@ -227,7 +227,7 @@ impl Package { } } -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct Module { pub name: EcoString, pub code: EcoString, diff --git a/compiler-core/src/build/module_loader.rs b/compiler-core/src/build/module_loader.rs index fef60167d2f..43ee3bc6977 100644 --- a/compiler-core/src/build/module_loader.rs +++ b/compiler-core/src/build/module_loader.rs @@ -84,7 +84,7 @@ where } } - Ok(Input::Cached(self.cached(name, meta.clone()), meta)) + Ok(Input::Cached(self.cached(name, meta))) } /// Read the timestamp file from the artefact directory for the given diff --git a/compiler-core/src/build/module_loader/tests.rs b/compiler-core/src/build/module_loader/tests.rs index 29cc5b7fb94..411dddd5cdc 100644 --- a/compiler-core/src/build/module_loader/tests.rs +++ b/compiler-core/src/build/module_loader/tests.rs @@ -213,13 +213,11 @@ fn write_cache( ) { let line_numbers = LineNumbers::new(source); let cache_metadata = CacheMetadata { - name: "".into(), mtime: SystemTime::UNIX_EPOCH + Duration::from_secs(seconds), codegen_performed, dependencies: vec![], fingerprint: SourceFingerprint::new(source), line_numbers, - interface: package_interface::ModuleInterface::default(), }; let path = Utf8Path::new(path); fs.write_bytes(&path, &cache_metadata.to_binary()).unwrap(); diff --git a/compiler-core/src/build/package_compiler.rs b/compiler-core/src/build/package_compiler.rs index c7532329b66..e4365c31000 100644 --- a/compiler-core/src/build/package_compiler.rs +++ b/compiler-core/src/build/package_compiler.rs @@ -106,7 +106,7 @@ where stale_modules: &mut StaleTracker, incomplete_modules: &mut HashSet, telemetry: &dyn Telemetry, - ) -> Outcome<(Vec, Vec), Error> { + ) -> Outcome, Error> { let span = tracing::info_span!("compile", package = %self.config.name.as_str()); let _enter = span.enter(); @@ -186,9 +186,7 @@ where let mut modules = match outcome { Outcome::Ok(modules) => modules, - Outcome::PartialFailure(modules, err) => { - return Outcome::PartialFailure((modules, loaded.cached_metadata), err) - } + Outcome::PartialFailure(modules, err) => return Outcome::PartialFailure(modules, err), Outcome::TotalFailure(err) => return Outcome::TotalFailure(err), }; @@ -202,7 +200,7 @@ where return error.into(); } - Outcome::Ok((modules, loaded.cached_metadata)) + Outcome::Ok(modules) } fn compile_erlang_to_beam(&mut self, modules: &HashSet) -> Result<(), Error> { @@ -309,13 +307,11 @@ where let name = format!("{}.cache_meta", &module_name); let path = artefact_dir.join(name); let info = CacheMetadata { - name: module.name.clone(), mtime: module.mtime, codegen_performed: self.perform_codegen, dependencies: module.dependencies.clone(), fingerprint: SourceFingerprint::new(&module.code), line_numbers: module.ast.type_info.line_numbers.clone(), - interface: package_interface::ModuleInterface::from_module(module), }; self.io.write_bytes(&path, &info.to_binary())?; @@ -601,28 +597,28 @@ pub(crate) fn module_name(package_path: &Utf8Path, full_module_path: &Utf8Path) #[derive(Debug)] pub(crate) enum Input { New(UncompiledModule), - Cached(CachedModule, CacheMetadata), + Cached(CachedModule), } impl Input { pub fn name(&self) -> &EcoString { match self { Input::New(m) => &m.name, - Input::Cached(m, _) => &m.name, + Input::Cached(m) => &m.name, } } pub fn source_path(&self) -> &Utf8Path { match self { Input::New(m) => &m.path, - Input::Cached(m, _) => &m.source_path, + Input::Cached(m) => &m.source_path, } } pub fn dependencies(&self) -> Vec { match self { Input::New(m) => m.dependencies.iter().map(|(n, _)| n.clone()).collect(), - Input::Cached(m, _) => m.dependencies.iter().map(|(n, _)| n.clone()).collect(), + Input::Cached(m) => m.dependencies.iter().map(|(n, _)| n.clone()).collect(), } } @@ -652,15 +648,13 @@ pub(crate) struct CachedModule { pub line_numbers: LineNumbers, } -#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)] +#[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct CacheMetadata { - pub name: EcoString, pub mtime: SystemTime, pub codegen_performed: bool, pub dependencies: Vec<(EcoString, SrcSpan)>, pub fingerprint: SourceFingerprint, pub line_numbers: LineNumbers, - pub interface: package_interface::ModuleInterface, } impl CacheMetadata { @@ -673,11 +667,10 @@ impl CacheMetadata { } } -#[derive(Debug, Default)] +#[derive(Debug, Default, PartialEq, Eq)] pub(crate) struct Loaded { pub to_compile: Vec, pub cached: Vec, - pub cached_metadata: Vec, } impl Loaded { @@ -685,12 +678,11 @@ impl Loaded { Self { to_compile: vec![], cached: vec![], - cached_metadata: vec![], } } } -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq)] pub(crate) struct UncompiledModule { pub path: Utf8PathBuf, pub name: EcoString, diff --git a/compiler-core/src/build/package_loader.rs b/compiler-core/src/build/package_loader.rs index dd5f56e2eb5..c7bb8e6d4fb 100644 --- a/compiler-core/src/build/package_loader.rs +++ b/compiler-core/src/build/package_loader.rs @@ -148,7 +148,7 @@ where // A cached module with dependencies that are stale must be // recompiled as the changes in the dependencies may have affect // the output, making the cache invalid. - Input::Cached(info, _) if self.stale_modules.includes_any(&info.dependencies) => { + Input::Cached(info) if self.stale_modules.includes_any(&info.dependencies) => { tracing::debug!(module = %info.name, "module_to_be_compiled"); self.stale_modules.add(info.name.clone()); let module = self.load_and_parse(info)?; @@ -157,12 +157,18 @@ where // A cached module with no stale dependencies can be used as-is // and does not need to be recompiled. - Input::Cached(info, meta) => { - tracing::debug!(module = %info.name, "module_to_load_from_cache"); - let module = self.load_cached_module(info)?; - loaded.cached.push(module); - loaded.cached_metadata.push(meta); - } + Input::Cached(info) => match self.mode { + Mode::PackageInterface => { + tracing::debug!(module = %info.name, "module_to_be_compiled"); + let module = self.load_and_parse(info)?; + loaded.to_compile.push(module); + } + _ => { + tracing::debug!(module = %info.name, "module_to_load_from_cache"); + let module = self.load_cached_module(info)?; + loaded.cached.push(module); + } + }, } } @@ -325,7 +331,7 @@ where src: module.code.clone(), } } - Input::Cached(cached_module, _) => { + Input::Cached(cached_module) => { let (_, location) = cached_module .dependencies .iter() diff --git a/compiler-core/src/build/package_loader/tests.rs b/compiler-core/src/build/package_loader/tests.rs index e2916dba4e0..5eb2c763c53 100644 --- a/compiler-core/src/build/package_loader/tests.rs +++ b/compiler-core/src/build/package_loader/tests.rs @@ -39,13 +39,11 @@ fn write_cache( let line_numbers = line_numbers::LineNumbers::new(src); let mtime = SystemTime::UNIX_EPOCH + Duration::from_secs(seconds); let cache_metadata = CacheMetadata { - name: name.into(), mtime, codegen_performed: true, dependencies: deps, fingerprint: SourceFingerprint::new(src), line_numbers: line_numbers.clone(), - interface: package_interface::ModuleInterface::default(), }; let path = Utf8Path::new("/artefact").join(format!("{name}.cache_meta")); fs.write_bytes(&path, &cache_metadata.to_binary()).unwrap(); diff --git a/compiler-core/src/build/project_compiler.rs b/compiler-core/src/build/project_compiler.rs index 2367dae3786..dc08b8fd742 100644 --- a/compiler-core/src/build/project_compiler.rs +++ b/compiler-core/src/build/project_compiler.rs @@ -208,11 +208,7 @@ where pub fn compile_root_package(&mut self) -> Outcome { let config = self.config.clone(); self.compile_gleam_package(&config, true, self.paths.root().to_path_buf()) - .map(|(modules, cached_metadata)| Package { - config, - modules, - cached_metadata, - }) + .map(|modules| Package { config, modules }) } /// Checks that version file found in the build directory matches the @@ -292,9 +288,7 @@ where // longer need to have the package borrowed from self.packages. let package = self.packages.get(name).expect("Missing package").clone(); let result = match usable_build_tools(&package)?.as_slice() { - &[BuildTool::Gleam] => self - .compile_gleam_dep_package(&package) - .map(|(modules, _)| modules), + &[BuildTool::Gleam] => self.compile_gleam_dep_package(&package), &[BuildTool::Rebar3] => self.compile_rebar3_dep_package(&package).map(|_| vec![]), &[BuildTool::Mix] => self.compile_mix_dep_package(&package).map(|_| vec![]), &[BuildTool::Mix, BuildTool::Rebar3] => self @@ -495,7 +489,7 @@ where fn compile_gleam_dep_package( &mut self, package: &ManifestPackage, - ) -> Result<(Vec, Vec), Error> { + ) -> Result, Error> { // TODO: Test let package_root = match &package.source { // If the path is relative it is relative to the root of the @@ -526,7 +520,7 @@ where config: &PackageConfig, is_root: bool, root_path: Utf8PathBuf, - ) -> Outcome<(Vec, Vec), Error> { + ) -> Outcome<(Vec), Error> { let out_path = self.paths .build_directory_for_package(self.mode(), self.target(), &config.name); diff --git a/compiler-core/src/config.rs b/compiler-core/src/config.rs index b583fa58a5e..1f814cfbd4e 100644 --- a/compiler-core/src/config.rs +++ b/compiler-core/src/config.rs @@ -137,7 +137,7 @@ impl PackageConfig { pub fn dependencies_for(&self, mode: Mode) -> Result { match mode { Mode::Dev | Mode::Lsp => self.all_drect_dependencies(), - Mode::Prod => Ok(self.dependencies.clone()), + Mode::Prod | Mode::PackageInterface => Ok(self.dependencies.clone()), } } diff --git a/compiler-core/src/docs/tests.rs b/compiler-core/src/docs/tests.rs index e8f3922b955..8469cea2be1 100644 --- a/compiler-core/src/docs/tests.rs +++ b/compiler-core/src/docs/tests.rs @@ -63,7 +63,7 @@ fn compile_with_markdown_pages( ) .unwrap(); - for module in &mut modules.0 { + for module in &mut modules { module.attach_doc_and_module_comments(); } @@ -79,7 +79,7 @@ fn compile_with_markdown_pages( super::generate_html( &paths, &config, - &modules.0, + &modules, &docs_pages, pages_fs, SystemTime::UNIX_EPOCH, diff --git a/compiler-core/src/package_interface.rs b/compiler-core/src/package_interface.rs index 33435add491..12104f4f8bd 100644 --- a/compiler-core/src/package_interface.rs +++ b/compiler-core/src/package_interface.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, ops::Deref}; use ecow::EcoString; use itertools::Itertools; -use serde::{Deserialize, Serialize}; +use serde::Serialize; #[cfg(test)] mod tests; @@ -28,7 +28,7 @@ pub struct PackageInterface { modules: HashMap, } -#[derive(Deserialize, Serialize, Debug, Clone, Default)] +#[derive(Serialize, Debug)] #[serde(rename_all = "kebab-case")] pub struct ModuleInterface { /// A vector with the lines composing the module's documentation (that is @@ -48,7 +48,7 @@ pub struct ModuleInterface { functions: HashMap, } -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Serialize, Debug)] #[serde(rename_all = "kebab-case")] pub struct TypeDefinitionInterface { /// The definition's documentation comment (that is every line preceded by @@ -71,7 +71,7 @@ pub struct TypeDefinitionInterface { constructors: Vec, } -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Serialize, Debug)] #[serde(rename_all = "kebab-case")] pub struct TypeConstructorInterface { /// The constructor's documentation comment (that is every line preceded by @@ -95,7 +95,7 @@ pub struct TypeConstructorInterface { parameters: Vec, } -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Serialize, Debug)] #[serde(rename_all = "kebab-case")] pub struct TypeAliasInterface { /// The constructor's documentation comment (that is every line preceded by @@ -118,7 +118,7 @@ pub struct TypeAliasInterface { alias: TypeInterface, } -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Serialize, Debug)] #[serde(rename_all = "kebab-case")] pub struct ConstantInterface { /// The constant's documentation comment (that is every line preceded by @@ -135,7 +135,7 @@ pub struct ConstantInterface { /// A module's function. This differs from a simple `Fn` type as its arguments /// can be labelled. -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Serialize, Debug)] #[serde(rename_all = "kebab-case")] pub struct FunctionInterface { /// The function's documentation comment (that is every line preceded by @@ -151,7 +151,7 @@ pub struct FunctionInterface { } /// Informations about how a value is implemented. -#[derive(Debug, Deserialize, Serialize, Copy, Clone)] +#[derive(Debug, Serialize, Copy, Clone)] #[serde(rename_all = "kebab-case")] pub struct ImplementationsInterface { /// Set to `true` if the const/function has a pure Gleam implementation @@ -273,7 +273,7 @@ impl ImplementationsInterface { } } -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Serialize, Debug)] #[serde(rename_all = "kebab-case")] pub struct DeprecationInterface { /// The reason for the deprecation. @@ -291,8 +291,8 @@ impl DeprecationInterface { } } -#[derive(Deserialize, Serialize, Debug, Clone)] -// #[serde(tag = "kind")] +#[derive(Serialize, Debug)] +#[serde(tag = "kind")] #[serde(rename_all = "kebab-case")] pub enum TypeInterface { /// A tuple type like `#(Int, Float)`. @@ -339,7 +339,7 @@ pub enum TypeInterface { }, } -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Serialize, Debug)] #[serde(rename_all = "kebab-case")] pub struct ParameterInterface { /// If the parameter is labelled this will hold the label's name. @@ -372,13 +372,6 @@ impl PackageInterface { .iter() .filter(|module| !package.config.is_internal_module(module.name.as_str())) .map(|module| (module.name.clone(), ModuleInterface::from_module(module))) - .chain( - package - .cached_metadata - .clone() - .into_iter() - .map(|module| (module.name.clone(), module.interface)), - ) .collect(), } } diff --git a/compiler-core/src/package_interface/tests.rs b/compiler-core/src/package_interface/tests.rs index 8bf9fbffdf4..5495a848db9 100644 --- a/compiler-core/src/package_interface/tests.rs +++ b/compiler-core/src/package_interface/tests.rs @@ -172,7 +172,6 @@ fn package_from_module(module: Module) -> Package { .expect("internals glob")]), }, modules: vec![module], - cached_metadata: vec![], } } diff --git a/compiler-core/src/parse/extra.rs b/compiler-core/src/parse/extra.rs index 72003014daf..b6e2cb6a060 100644 --- a/compiler-core/src/parse/extra.rs +++ b/compiler-core/src/parse/extra.rs @@ -4,7 +4,7 @@ use ecow::EcoString; use crate::ast::SrcSpan; -#[derive(Debug, PartialEq, Eq, Default, Clone)] +#[derive(Debug, PartialEq, Eq, Default)] pub struct ModuleExtra { pub module_comments: Vec, pub doc_comments: Vec,