Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Integer patterns that alias the same int32 value (e.g. `0xFFFF_FFFF` and `-1`) may now produce unused-case warnings. https://github.com/rescript-lang/rescript/pull/8717 https://github.com/rescript-lang/rescript/pull/8858
- Fix constant folding of a `switch` picking the wrong case for `@as(int)` constructors and for coerced variants. https://github.com/rescript-lang/rescript/pull/9318
- Fix constant folding of comparisons between `@as(int)` constructors and other constructors, and merging of switch arms returning them. https://github.com/rescript-lang/rescript/pull/9319
- Fix rewatch compiling one more level of unchanged dependents on every build after a module compiles without changing its interface. https://github.com/rescript-lang/rescript/issues/9487

#### :nail_care: Polish

Expand Down
18 changes: 15 additions & 3 deletions rewatch/src/build/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ pub fn compile(
);

let cmi_digest = helpers::compute_file_hash(Path::new(&cmi_path));
let cmi_modified = std::fs::metadata(&cmi_path).and_then(|m| m.modified()).ok();

let package = build_state
.get_package(&module.package_name)
Expand Down Expand Up @@ -252,6 +253,17 @@ pub fn compile(
_ => false,
};

// bsc rewrites the .cmi of a module with an interface file on every compile, and
// copying it to lib/ocaml gives it a new time on some platforms. Keep the old
// time when the content is the same: the next build compares it with the .cmt of
// the dependents to find the ones that must compile.
if is_clean_cmi && let Some(cmi_modified) = cmi_modified {
let _ = std::fs::File::options()
.write(true)
.open(&cmi_path)
.and_then(|file| file.set_modified(cmi_modified));
}

Some((
module_name.to_string(),
result,
Expand Down Expand Up @@ -991,7 +1003,7 @@ pub fn mark_modules_with_expired_deps_dirty(build_state: &mut BuildCommandState)
let dependent_module = build_state.modules.get(dependent).unwrap();
match dependent_module.source_type {
SourceType::SourceFile(_) => {
match (module.last_compiled_cmt, module.last_compiled_cmt) {
match (module.last_compiled_cmt, module.last_compiled_cmi) {
(None, None) | (Some(_), None) | (None, Some(_)) => {
// println!(
// "🛑 {} is a dependent of {} but has no cmt/cmi",
Expand All @@ -1005,7 +1017,7 @@ pub fn mark_modules_with_expired_deps_dirty(build_state: &mut BuildCommandState)
// we compare the last compiled time of the dependent module with the last
// compile of the interface of the module it depends on, if the interface
// didn't change it doesn't matter
match (dependent_module.last_compiled_cmt, module.last_compiled_cmt) {
match (dependent_module.last_compiled_cmt, module.last_compiled_cmi) {
(Some(last_compiled_dependent), Some(last_compiled)) => {
if last_compiled_dependent < last_compiled {
// println!(
Expand Down Expand Up @@ -1038,7 +1050,7 @@ pub fn mark_modules_with_expired_deps_dirty(build_state: &mut BuildCommandState)
let dependent_module = build_state.modules.get(dependent_of_namespace).unwrap();

if let (Some(last_compiled_dependent), Some(last_compiled)) =
(dependent_module.last_compiled_cmt, module.last_compiled_cmt)
(dependent_module.last_compiled_cmt, module.last_compiled_cmi)
&& last_compiled_dependent < last_compiled
{
modules_with_expired_deps.insert(dependent.to_string());
Expand Down
21 changes: 21 additions & 0 deletions rewatch/tests/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ rewatch build &> ../tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt
normalize_paths ../tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt
git checkout -- packages/with-dev-deps/src/FileToTest.res

# a compile that leaves a module's interface unchanged must not make later builds compile its dependents
expect_not_compiled() {
rewatch build &> /dev/null
output=$(rewatch build -v 2>&1)
if echo "$output" | grep -q "Compiling file: $2$"; then
error "$1: the next build compiled $2 again"
exit 1
else
success "$1: the next build did not compile $2"
fi
}
rewatch build &> /dev/null
touch packages/dep02/src/Dep02.res
expect_not_compiled "Recompiled dependency" Dep01
echo 'let value: int' > packages/main/src/InternalDep.resi
rewatch build &> /dev/null
touch packages/main/src/InternalDep.res
expect_not_compiled "Recompiled dependency with an interface file" Main
rm packages/main/src/InternalDep.resi
rewatch build &> /dev/null

# it should compile dev dependencies
rewatch clean &> /dev/null
rewatch build &> /dev/null;
Expand Down
2 changes: 1 addition & 1 deletion rewatch/tests/snapshots/rename-file-with-interface.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
 No implementation file found for interface file (skipping): src/ModuleWithInterface.resi
Cleaned 2/429
Parsed 2 source files
Compiled 3 modules
Compiled 2 modules

Warning number 32
/packages/watch-warnings/src/ModuleA.res:1:5-15
Expand Down
2 changes: 1 addition & 1 deletion rewatch/tests/snapshots/rename-interface-file.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
 No implementation file found for interface file (skipping): src/ModuleWithInterface2.resi
Cleaned 1/429
Parsed 2 source files
Compiled 3 modules
Compiled 2 modules

Warning number 32
/packages/watch-warnings/src/ModuleA.res:1:5-15
Expand Down
Loading