mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
turn unused module into a warning
This commit is contained in:
parent
a5e93cc21b
commit
407f8b9321
2 changed files with 36 additions and 17 deletions
|
@ -659,6 +659,7 @@ enum Msg<'a> {
|
||||||
solved_subs: Solved<Subs>,
|
solved_subs: Solved<Subs>,
|
||||||
decls: Vec<Declaration>,
|
decls: Vec<Declaration>,
|
||||||
module_timing: ModuleTiming,
|
module_timing: ModuleTiming,
|
||||||
|
unused_imports: MutSet<ModuleId>,
|
||||||
},
|
},
|
||||||
FinishedAllTypeChecking {
|
FinishedAllTypeChecking {
|
||||||
solved_subs: Solved<Subs>,
|
solved_subs: Solved<Subs>,
|
||||||
|
@ -870,6 +871,7 @@ enum BuildTask<'a> {
|
||||||
constraint: Constraint,
|
constraint: Constraint,
|
||||||
var_store: VarStore,
|
var_store: VarStore,
|
||||||
declarations: Vec<Declaration>,
|
declarations: Vec<Declaration>,
|
||||||
|
unused_imports: MutSet<ModuleId>,
|
||||||
},
|
},
|
||||||
BuildPendingSpecializations {
|
BuildPendingSpecializations {
|
||||||
module_timing: ModuleTiming,
|
module_timing: ModuleTiming,
|
||||||
|
@ -1607,6 +1609,7 @@ fn update<'a>(
|
||||||
solved_subs,
|
solved_subs,
|
||||||
decls,
|
decls,
|
||||||
mut module_timing,
|
mut module_timing,
|
||||||
|
mut unused_imports,
|
||||||
} => {
|
} => {
|
||||||
log!("solved types for {:?}", module_id);
|
log!("solved types for {:?}", module_id);
|
||||||
module_timing.end_time = SystemTime::now();
|
module_timing.end_time = SystemTime::now();
|
||||||
|
@ -1616,6 +1619,18 @@ fn update<'a>(
|
||||||
.type_problems
|
.type_problems
|
||||||
.insert(module_id, solved_module.problems);
|
.insert(module_id, solved_module.problems);
|
||||||
|
|
||||||
|
let existing = match state.module_cache.can_problems.entry(module_id) {
|
||||||
|
Vacant(entry) => entry.insert(std::vec::Vec::new()),
|
||||||
|
Occupied(entry) => entry.into_mut(),
|
||||||
|
};
|
||||||
|
|
||||||
|
for unused in unused_imports.drain() {
|
||||||
|
existing.push(roc_problem::can::Problem::UnusedImport(
|
||||||
|
unused,
|
||||||
|
Region::zero(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
let work = state.dependencies.notify(module_id, Phase::SolveTypes);
|
let work = state.dependencies.notify(module_id, Phase::SolveTypes);
|
||||||
|
|
||||||
// if there is a platform, the Pkg-Config module provides host-exposed,
|
// if there is a platform, the Pkg-Config module provides host-exposed,
|
||||||
|
@ -2742,14 +2757,6 @@ impl<'a> BuildTask<'a> {
|
||||||
stdlib,
|
stdlib,
|
||||||
);
|
);
|
||||||
|
|
||||||
if !unused_imports.is_empty() {
|
|
||||||
todo!(
|
|
||||||
"TODO gracefully handle unused import {:?} from module {:?}",
|
|
||||||
&unused_imports,
|
|
||||||
home,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next, solve this module in the background.
|
// Next, solve this module in the background.
|
||||||
Self::Solve {
|
Self::Solve {
|
||||||
module,
|
module,
|
||||||
|
@ -2759,6 +2766,7 @@ impl<'a> BuildTask<'a> {
|
||||||
var_store,
|
var_store,
|
||||||
declarations,
|
declarations,
|
||||||
module_timing,
|
module_timing,
|
||||||
|
unused_imports,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2772,6 +2780,7 @@ fn run_solve<'a>(
|
||||||
constraint: Constraint,
|
constraint: Constraint,
|
||||||
mut var_store: VarStore,
|
mut var_store: VarStore,
|
||||||
decls: Vec<Declaration>,
|
decls: Vec<Declaration>,
|
||||||
|
unused_imports: MutSet<ModuleId>,
|
||||||
) -> Msg<'a> {
|
) -> Msg<'a> {
|
||||||
// We have more constraining work to do now, so we'll add it to our timings.
|
// We have more constraining work to do now, so we'll add it to our timings.
|
||||||
let constrain_start = SystemTime::now();
|
let constrain_start = SystemTime::now();
|
||||||
|
@ -2819,6 +2828,7 @@ fn run_solve<'a>(
|
||||||
decls,
|
decls,
|
||||||
solved_module,
|
solved_module,
|
||||||
module_timing,
|
module_timing,
|
||||||
|
unused_imports,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3615,6 +3625,7 @@ fn run_task<'a>(
|
||||||
var_store,
|
var_store,
|
||||||
ident_ids,
|
ident_ids,
|
||||||
declarations,
|
declarations,
|
||||||
|
unused_imports,
|
||||||
} => Ok(run_solve(
|
} => Ok(run_solve(
|
||||||
module,
|
module,
|
||||||
ident_ids,
|
ident_ids,
|
||||||
|
@ -3623,6 +3634,7 @@ fn run_task<'a>(
|
||||||
constraint,
|
constraint,
|
||||||
var_store,
|
var_store,
|
||||||
declarations,
|
declarations,
|
||||||
|
unused_imports,
|
||||||
)),
|
)),
|
||||||
BuildPendingSpecializations {
|
BuildPendingSpecializations {
|
||||||
module_id,
|
module_id,
|
||||||
|
|
|
@ -28,15 +28,22 @@ pub fn can_problem<'b>(
|
||||||
.append(alloc.reflow(line)),
|
.append(alloc.reflow(line)),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
Problem::UnusedImport(module_id, region) => alloc.concat(vec![
|
Problem::UnusedImport(module_id, region) => {
|
||||||
alloc.reflow("Nothing from "),
|
alloc.stack(vec![
|
||||||
alloc.module(module_id),
|
alloc.concat(vec![
|
||||||
alloc.reflow(" is used in this module."),
|
alloc.reflow("Nothing from "),
|
||||||
alloc.region(region),
|
alloc.module(module_id),
|
||||||
alloc.reflow("Since "),
|
alloc.reflow(" is used in this module."),
|
||||||
alloc.module(module_id),
|
]),
|
||||||
alloc.reflow(" isn't used, you don't need to import it."),
|
alloc.region(region),
|
||||||
]),
|
alloc.concat(vec![
|
||||||
|
alloc.reflow("Since "),
|
||||||
|
alloc.module(module_id),
|
||||||
|
alloc.reflow(" isn't used, you don't need to import it."),
|
||||||
|
])
|
||||||
|
])
|
||||||
|
|
||||||
|
}
|
||||||
Problem::ExposedButNotDefined(symbol) => {
|
Problem::ExposedButNotDefined(symbol) => {
|
||||||
alloc.stack(vec![
|
alloc.stack(vec![
|
||||||
alloc
|
alloc
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue