Skip to content
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

Fixed export package-definitions not including cached modules #3669

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler-cli/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion compiler-core/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::ast::{
CallArg, CustomType, DefinitionLocation, Pattern, TypeAst, TypedArg, TypedDefinition,
TypedExpr, TypedFunction, TypedPattern, TypedStatement,
};
use crate::package_interface;
use crate::type_::Type;
use crate::{
ast::{Definition, SrcSpan, TypedModule},
Expand Down Expand Up @@ -184,6 +185,7 @@ pub enum Mode {
Dev,
Prod,
Lsp,
PackageInterface,
}

impl Mode {
Expand All @@ -192,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,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler-core/src/build/module_loader/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
build::SourceFingerprint,
io::{memory::InMemoryFileSystem, FileSystemWriter},
line_numbers::LineNumbers,
package_interface,
};
use std::time::Duration;

Expand Down
9 changes: 6 additions & 3 deletions compiler-core/src/build/package_compiler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::analyse::{ModuleAnalyzerConstructor, TargetSupport};
use crate::line_numbers::{self, LineNumbers};
use crate::package_interface::{self, ModuleInterface};
use crate::type_::PRELUDE_MODULE_NAME;
use crate::{
ast::{SrcSpan, TypedModule, UntypedModule},
Expand All @@ -22,6 +23,7 @@ use crate::{
};
use askama::Template;
use ecow::EcoString;
use std::borrow::BorrowMut;
use std::collections::HashSet;
use std::{collections::HashMap, fmt::write, time::SystemTime};
use vec1::Vec1;
Expand Down Expand Up @@ -182,9 +184,10 @@ where
incomplete_modules,
);

let modules = match outcome {
let mut modules = match outcome {
Outcome::Ok(modules) => modules,
Outcome::PartialFailure(_, _) | Outcome::TotalFailure(_) => return outcome,
Outcome::PartialFailure(modules, err) => return Outcome::PartialFailure(modules, err),
Outcome::TotalFailure(err) => return Outcome::TotalFailure(err),
};

tracing::debug!("performing_code_generation");
Expand Down Expand Up @@ -646,7 +649,7 @@ pub(crate) struct CachedModule {
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub(crate) struct CacheMetadata {
pub struct CacheMetadata {
pub mtime: SystemTime,
pub codegen_performed: bool,
pub dependencies: Vec<(EcoString, SrcSpan)>,
Expand Down
17 changes: 12 additions & 5 deletions compiler-core/src/build/package_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +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) => {
tracing::debug!(module = %info.name, "module_to_load_from_cache");
let module = self.load_cached_module(info)?;
loaded.cached.push(module);
}
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);
}
},
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler-core/src/build/package_loader/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
use crate::{
build::SourceFingerprint,
io::{memory::InMemoryFileSystem, FileSystemWriter},
line_numbers,
line_numbers, package_interface,
parse::extra::ModuleExtra,
warning::NullWarningEmitterIO,
Warning,
Expand Down Expand Up @@ -62,7 +62,7 @@ fn write_cache(
warnings: vec![],
minimum_required_version: Version::new(0, 1, 0),
};
let path = Utf8Path::new("/artefact").join(format!("{name}.cache"));
let path: Utf8PathBuf = Utf8Path::new("/artefact").join(format!("{name}.cache"));
fs.write_bytes(
&path,
&metadata::ModuleEncoder::new(&cache).encode().unwrap(),
Expand Down
10 changes: 6 additions & 4 deletions compiler-core/src/build/project_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
use ecow::EcoString;
use hexpm::version::Version;
use itertools::Itertools;
use pubgrub::range::Range;
use pubgrub::{package, range::Range};
use std::{
cmp,
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -520,7 +520,7 @@ where
config: &PackageConfig,
is_root: bool,
root_path: Utf8PathBuf,
) -> Outcome<Vec<Module>, Error> {
) -> Outcome<(Vec<Module>), Error> {
let out_path =
self.paths
.build_directory_for_package(self.mode(), self.target(), &config.name);
Expand Down Expand Up @@ -590,14 +590,16 @@ where
};

// Compile project to Erlang or JavaScript source code
compiler.compile(
let outcome = compiler.compile(
&mut self.warnings,
&mut self.importable_modules,
&mut self.defined_modules,
&mut self.stale_modules,
&mut self.incomplete_modules,
self.telemetry,
)
);

outcome
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl PackageConfig {
pub fn dependencies_for(&self, mode: Mode) -> Result<Dependencies> {
match mode {
Mode::Dev | Mode::Lsp => self.all_drect_dependencies(),
Mode::Prod => Ok(self.dependencies.clone()),
Mode::Prod | Mode::PackageInterface => Ok(self.dependencies.clone()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler-core/src/package_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl PackageInterface {
}

impl ModuleInterface {
fn from_module(module: &Module) -> ModuleInterface {
pub fn from_module(module: &Module) -> ModuleInterface {
let mut types = HashMap::new();
let mut type_aliases = HashMap::new();
let mut constants = HashMap::new();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: test-package-compiler/src/generated_tests.rs
assertion_line: 8
expression: "./cases/alias_unqualified_import"
---
//// /out/lib/the_package/_gleam_artefacts/one.cache
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: test-package-compiler/src/generated_tests.rs
assertion_line: 63
expression: "./cases/erlang_escape_names"
---
//// /out/lib/the_package/_gleam_artefacts/one.cache
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: test-package-compiler/src/generated_tests.rs
assertion_line: 74
expression: "./cases/erlang_import"
---
//// /out/lib/the_package/_gleam_artefacts/one.cache
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: test-package-compiler/src/generated_tests.rs
assertion_line: 85
expression: "./cases/erlang_import_shadowing_prelude"
---
//// /out/lib/the_package/_gleam_artefacts/one.cache
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: test-package-compiler/src/generated_tests.rs
assertion_line: 96
expression: "./cases/erlang_nested"
---
//// /out/lib/the_package/_gleam_artefacts/[email protected]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: test-package-compiler/src/generated_tests.rs
assertion_line: 118
expression: "./cases/hello_joe"
---
//// /out/lib/the_package/_gleam_artefacts/hello_joe.cache
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: test-package-compiler/src/generated_tests.rs
assertion_line: 151
expression: "./cases/import_shadowed_name_warning"
---
//// /out/lib/the_package/_gleam_artefacts/one.cache
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: test-package-compiler/src/generated_tests.rs
assertion_line: 162
expression: "./cases/imported_constants"
---
//// /out/lib/the_package/_gleam_artefacts/one.cache
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: test-package-compiler/src/generated_tests.rs
assertion_line: 173
expression: "./cases/imported_external_fns"
---
//// /out/lib/the_package/_gleam_artefacts/one.cache
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: test-package-compiler/src/generated_tests.rs
assertion_line: 184
expression: "./cases/imported_record_constructors"
---
//// /out/lib/the_package/_gleam_artefacts/[email protected]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: test-package-compiler/src/generated_tests.rs
assertion_line: 237
expression: "./cases/not_overwriting_erlang_module"
---
//// /out/lib/the_package/_gleam_artefacts/[email protected]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: test-package-compiler/src/generated_tests.rs
assertion_line: 316
expression: "./cases/variable_or_module"
---
//// /out/lib/the_package/_gleam_artefacts/main.cache
Expand Down