dart-decimate 0.0.77 → 0.0.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +8 -8
- package/package.json +2 -2
- package/src/boundaries.rs +1 -9
- package/src/cli/analyze.rs +33 -3
- package/src/cli/error.rs +16 -0
- package/src/cli/list_run.rs +3 -1
- package/src/cli/scope_args.rs +14 -3
- package/src/config.rs +12 -8
- package/src/dart_parser.rs +100 -9
- package/src/dependencies/analyze.rs +4 -3
- package/src/dependencies/discovery.rs +10 -2
- package/src/dependencies/flutter_usage.rs +4 -0
- package/src/dependencies/tests.rs +5 -5
- package/src/dependencies/usage.rs +0 -9
- package/src/dependencies.rs +12 -7
- package/src/dupes/declarations.rs +1 -2
- package/src/dupes.rs +1 -10
- package/src/explain/misc.rs +1 -1
- package/src/explain.rs +1 -1
- package/src/extract/members.rs +24 -15
- package/src/extract/tests.rs +89 -0
- package/src/extract.rs +51 -15
- package/src/graph.rs +9 -0
- package/src/lib.rs +3 -2
- package/src/output/duplication_findings.rs +1 -2
- package/src/output/human.rs +7 -2
- package/src/output/human_details.rs +6 -0
- package/src/output/next_steps.rs +111 -0
- package/src/output/route_cycle/aliases.rs +1 -2
- package/src/output/route_cycle/wrappers.rs +1 -2
- package/src/output/types.rs +2 -0
- package/src/output.rs +27 -5
- package/src/outside/loader.rs +133 -0
- package/src/outside/loader_tests.rs +136 -0
- package/src/outside/resolver.rs +484 -0
- package/src/outside/tests.rs +242 -0
- package/src/outside.rs +186 -0
- package/src/package_map.rs +30 -1
- package/src/report_schema.rs +1 -0
- package/src/routes.rs +2 -0
- package/src/scan.rs +24 -3
- package/src/security/detect/process_arguments.rs +106 -0
- package/src/security/detect.rs +98 -40
- package/src/symbols/extensions.rs +42 -27
- package/src/symbols/path_filters.rs +10 -1
- package/src/symbols/tests.rs +15 -0
- package/src/symbols.rs +489 -67
- package/src/trace.rs +6 -5
- package/src/widgets/reads.rs +4 -8
- package/src/widgets/resolution.rs +63 -10
- package/src/workspace_scope.rs +1 -10
package/src/symbols.rs
CHANGED
|
@@ -6,7 +6,9 @@ use serde::{Deserialize, Serialize};
|
|
|
6
6
|
use crate::dependencies::{PackageScope, package_scopes};
|
|
7
7
|
use crate::generated::is_generated_dart_path;
|
|
8
8
|
use crate::graph::normalize_against;
|
|
9
|
-
use crate::
|
|
9
|
+
use crate::outside::{OutsideTypes, SharedLoader};
|
|
10
|
+
use crate::package_map::find_package_config;
|
|
11
|
+
use crate::widgets::resolution::{ClassKey, DeclarationResolver, Resolution};
|
|
10
12
|
use crate::{
|
|
11
13
|
DartCombinatorKind, DeadCodeReport, DeclarationKind, DependencyKind, Location,
|
|
12
14
|
MemberDeclaration, MemberKind, ScannedProject, TopLevelDeclaration,
|
|
@@ -15,13 +17,13 @@ use crate::{
|
|
|
15
17
|
mod duplicate_declarations;
|
|
16
18
|
mod extensions;
|
|
17
19
|
mod index;
|
|
18
|
-
mod path_filters;
|
|
20
|
+
pub(crate) mod path_filters;
|
|
19
21
|
mod private_type_leaks;
|
|
20
22
|
mod riverpod;
|
|
21
23
|
mod semantic_evidence;
|
|
22
24
|
use duplicate_declarations::duplicate_declarations_across_libraries;
|
|
23
25
|
use extensions::extend_implicit_extension_references;
|
|
24
|
-
use path_filters::{is_library_source, is_private, is_public_library_entry};
|
|
26
|
+
use path_filters::{is_bin_source, is_library_source, is_private, is_public_library_entry};
|
|
25
27
|
pub use private_type_leaks::PrivateTypeLeak;
|
|
26
28
|
use private_type_leaks::private_type_leaks;
|
|
27
29
|
use riverpod::extend_generated_provider_owner_references;
|
|
@@ -40,6 +42,26 @@ pub struct SymbolReport {
|
|
|
40
42
|
pub duplicate_exports: Vec<DuplicateExport>,
|
|
41
43
|
/// Conservative Rust-native semantic evidence for retained candidates and type edges.
|
|
42
44
|
pub semantic: crate::SemanticReport,
|
|
45
|
+
/// Supertype names that SDK or package sources could not resolve for class member checks.
|
|
46
|
+
#[serde(default, skip_serializing)]
|
|
47
|
+
pub outside_types_unread: usize,
|
|
48
|
+
/// Package folders, relative to the scan root, whose package config could not give those sources.
|
|
49
|
+
#[serde(default, skip_serializing)]
|
|
50
|
+
pub outside_unread_folders: Vec<(String, bool)>,
|
|
51
|
+
/// Local imports whose file is missing, as package folder and file relative to that folder.
|
|
52
|
+
#[serde(default, skip_serializing)]
|
|
53
|
+
pub outside_missing_imports: Vec<MissingFile>,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// A local import or part file that does not exist.
|
|
57
|
+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
58
|
+
pub struct MissingFile {
|
|
59
|
+
/// Package folder that owns the file, relative to the scan root when inside it.
|
|
60
|
+
pub folder: String,
|
|
61
|
+
/// File path relative to that folder.
|
|
62
|
+
pub file: String,
|
|
63
|
+
/// Whether a `part` directive names the file.
|
|
64
|
+
pub part: bool,
|
|
43
65
|
}
|
|
44
66
|
|
|
45
67
|
/// Options for symbol-level dead-code analysis.
|
|
@@ -153,14 +175,15 @@ pub fn analyze_symbols_with_options(
|
|
|
153
175
|
} else {
|
|
154
176
|
Vec::new()
|
|
155
177
|
};
|
|
156
|
-
let (unused_exports, unused_members
|
|
157
|
-
(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
178
|
+
let (unused_exports, (unused_members, outside_types_unread, outside_unread)) =
|
|
179
|
+
if let Some(dead_code) = dead_code {
|
|
180
|
+
(
|
|
181
|
+
unused_exports(project, dead_code, &index, options),
|
|
182
|
+
unused_members(project, dead_code, &index),
|
|
183
|
+
)
|
|
184
|
+
} else {
|
|
185
|
+
(Vec::new(), (Vec::new(), 0, UnreadOutside::default()))
|
|
186
|
+
};
|
|
164
187
|
let semantic = semantic_report(
|
|
165
188
|
project,
|
|
166
189
|
&index,
|
|
@@ -176,6 +199,9 @@ pub fn analyze_symbols_with_options(
|
|
|
176
199
|
private_type_leaks,
|
|
177
200
|
duplicate_exports,
|
|
178
201
|
semantic,
|
|
202
|
+
outside_types_unread,
|
|
203
|
+
outside_unread_folders: outside_unread.folders,
|
|
204
|
+
outside_missing_imports: outside_unread.missing,
|
|
179
205
|
}
|
|
180
206
|
}
|
|
181
207
|
|
|
@@ -247,7 +273,7 @@ fn unused_members(
|
|
|
247
273
|
project: &ScannedProject,
|
|
248
274
|
dead_code: &DeadCodeReport,
|
|
249
275
|
index: &SymbolIndex,
|
|
250
|
-
) -> Vec<UnusedMember
|
|
276
|
+
) -> (Vec<UnusedMember>, usize, UnreadOutside) {
|
|
251
277
|
let reachable_files = dead_code
|
|
252
278
|
.reachable_files
|
|
253
279
|
.iter()
|
|
@@ -299,7 +325,121 @@ fn unused_members(
|
|
|
299
325
|
))
|
|
300
326
|
});
|
|
301
327
|
|
|
302
|
-
|
|
328
|
+
let skips = &public_members.interface_skips;
|
|
329
|
+
let base = nearest_package(&project.root.join("pubspec.yaml"), &project.root);
|
|
330
|
+
let folders = skips
|
|
331
|
+
.unread_packages
|
|
332
|
+
.iter()
|
|
333
|
+
.filter(|package| {
|
|
334
|
+
let has_missing = skips
|
|
335
|
+
.missing_imports
|
|
336
|
+
.keys()
|
|
337
|
+
.any(|file| nearest_package(file, &project.root) == **package);
|
|
338
|
+
let config = find_package_config(package);
|
|
339
|
+
!has_missing || config.is_none_or(|config| skips.config_gaps.contains(&config))
|
|
340
|
+
})
|
|
341
|
+
.map(|package| {
|
|
342
|
+
let flutter = std::fs::read_to_string(package.join("pubspec.yaml"))
|
|
343
|
+
.is_ok_and(|pubspec| pubspec.contains("sdk: flutter"));
|
|
344
|
+
(package_folder(&base, package), flutter)
|
|
345
|
+
})
|
|
346
|
+
.collect();
|
|
347
|
+
let missing = skips
|
|
348
|
+
.missing_imports
|
|
349
|
+
.iter()
|
|
350
|
+
.map(|(file, part)| {
|
|
351
|
+
let folder = nearest_package(file, &project.root);
|
|
352
|
+
MissingFile {
|
|
353
|
+
folder: package_folder(&base, &folder),
|
|
354
|
+
file: package_folder(&folder, file),
|
|
355
|
+
part: *part,
|
|
356
|
+
}
|
|
357
|
+
})
|
|
358
|
+
.collect();
|
|
359
|
+
(
|
|
360
|
+
unused_members,
|
|
361
|
+
skips.unread_names.len(),
|
|
362
|
+
UnreadOutside { folders, missing },
|
|
363
|
+
)
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
#[derive(Default)]
|
|
367
|
+
struct UnreadOutside {
|
|
368
|
+
folders: Vec<(String, bool)>,
|
|
369
|
+
missing: Vec<MissingFile>,
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
fn reachable_missing_files(
|
|
373
|
+
project: &ScannedProject,
|
|
374
|
+
unread_libraries: &BTreeSet<PathBuf>,
|
|
375
|
+
) -> BTreeMap<PathBuf, bool> {
|
|
376
|
+
let scanned = project
|
|
377
|
+
.files
|
|
378
|
+
.iter()
|
|
379
|
+
.map(|file| (normalize_against(&project.root, &file.path), file))
|
|
380
|
+
.collect::<BTreeMap<_, _>>();
|
|
381
|
+
let mut missing = BTreeMap::new();
|
|
382
|
+
let mut visited = BTreeSet::new();
|
|
383
|
+
let mut pending = unread_libraries.iter().cloned().collect::<Vec<_>>();
|
|
384
|
+
while let Some(path) = pending.pop() {
|
|
385
|
+
if !visited.insert(path.clone()) {
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
let parsed;
|
|
389
|
+
let file = if let Some(file) = scanned.get(&path) {
|
|
390
|
+
*file
|
|
391
|
+
} else if let Some(file) = std::fs::read_to_string(&path)
|
|
392
|
+
.ok()
|
|
393
|
+
.and_then(|source| crate::extract::extract_dart_outline(&path, &source).ok())
|
|
394
|
+
{
|
|
395
|
+
parsed = file;
|
|
396
|
+
&parsed
|
|
397
|
+
} else {
|
|
398
|
+
continue;
|
|
399
|
+
};
|
|
400
|
+
let directives = file
|
|
401
|
+
.imports
|
|
402
|
+
.iter()
|
|
403
|
+
.map(|import| (&import.uri, false))
|
|
404
|
+
.chain(file.exports.iter().map(|export| (&export.uri, false)))
|
|
405
|
+
.chain(file.parts.iter().map(|part| (&part.uri, true)));
|
|
406
|
+
for (uri, part) in directives {
|
|
407
|
+
if uri.starts_with("dart:") {
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
let Some((target, local)) = project.graph.resolve_specifier(&path, uri) else {
|
|
411
|
+
continue;
|
|
412
|
+
};
|
|
413
|
+
if !local {
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
if target.is_file() {
|
|
417
|
+
pending.push(target);
|
|
418
|
+
} else {
|
|
419
|
+
missing.insert(target, part);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
missing
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
fn nearest_package(file: &Path, fallback: &Path) -> PathBuf {
|
|
427
|
+
file.ancestors()
|
|
428
|
+
.find(|folder| folder.join("pubspec.yaml").is_file())
|
|
429
|
+
.map_or_else(|| fallback.to_path_buf(), Path::to_path_buf)
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
fn package_folder(root: &Path, package: &Path) -> String {
|
|
433
|
+
let folder = package
|
|
434
|
+
.strip_prefix(root)
|
|
435
|
+
.unwrap_or(package)
|
|
436
|
+
.to_string_lossy()
|
|
437
|
+
.into_owned();
|
|
438
|
+
if std::path::MAIN_SEPARATOR == '\\' {
|
|
439
|
+
folder.replace('\\', "/")
|
|
440
|
+
} else {
|
|
441
|
+
folder
|
|
442
|
+
}
|
|
303
443
|
}
|
|
304
444
|
|
|
305
445
|
fn unused_export_from_declaration(
|
|
@@ -366,7 +506,7 @@ fn unused_member_from_declaration(
|
|
|
366
506
|
|| !reachable_files.contains(&indexed.path)
|
|
367
507
|
|| dead_files.contains(&indexed.path)
|
|
368
508
|
|| is_generated_dart_path(&indexed.path)
|
|
369
|
-
|| !public_members.
|
|
509
|
+
|| !public_members.in_checked_source(&project.root, &indexed.path)
|
|
370
510
|
|| !should_check_member(index, public_members, indexed)
|
|
371
511
|
{
|
|
372
512
|
return None;
|
|
@@ -430,6 +570,7 @@ const CONTRACT_MEMBER_NAMES: &[&str] = &[
|
|
|
430
570
|
];
|
|
431
571
|
|
|
432
572
|
struct PublicMemberContext {
|
|
573
|
+
root: PathBuf,
|
|
433
574
|
class_owners: BTreeSet<(PathBuf, String)>,
|
|
434
575
|
generated_part_libraries: BTreeSet<PathBuf>,
|
|
435
576
|
entry_points: BTreeSet<PathBuf>,
|
|
@@ -442,8 +583,8 @@ struct HierarchyClass {
|
|
|
442
583
|
extended: BTreeSet<ClassKey>,
|
|
443
584
|
mixed: BTreeSet<ClassKey>,
|
|
444
585
|
implemented: BTreeSet<ClassKey>,
|
|
445
|
-
|
|
446
|
-
|
|
586
|
+
unread_extended: BTreeSet<String>,
|
|
587
|
+
unread_interface: BTreeSet<String>,
|
|
447
588
|
}
|
|
448
589
|
|
|
449
590
|
#[derive(Default)]
|
|
@@ -456,6 +597,26 @@ struct DeclaredNames {
|
|
|
456
597
|
struct InterfaceSkips {
|
|
457
598
|
whole_classes: BTreeSet<ClassKey>,
|
|
458
599
|
named_members: BTreeMap<ClassKey, BTreeSet<String>>,
|
|
600
|
+
unread_names: BTreeSet<String>,
|
|
601
|
+
unread_packages: BTreeSet<PathBuf>,
|
|
602
|
+
missing_imports: BTreeMap<PathBuf, bool>,
|
|
603
|
+
config_gaps: BTreeSet<PathBuf>,
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
struct PackageRoots {
|
|
607
|
+
root: PathBuf,
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
impl PackageRoots {
|
|
611
|
+
fn new(project: &ScannedProject) -> Self {
|
|
612
|
+
Self {
|
|
613
|
+
root: project.root.clone(),
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
fn of(&self, path: &Path) -> PathBuf {
|
|
618
|
+
nearest_package(path, &self.root)
|
|
619
|
+
}
|
|
459
620
|
}
|
|
460
621
|
|
|
461
622
|
impl InterfaceSkips {
|
|
@@ -468,10 +629,132 @@ impl InterfaceSkips {
|
|
|
468
629
|
}
|
|
469
630
|
}
|
|
470
631
|
|
|
471
|
-
|
|
472
|
-
BTreeMap<ClassKey, HierarchyClass>,
|
|
473
|
-
BTreeMap<ClassKey, DeclaredNames>,
|
|
474
|
-
|
|
632
|
+
struct Hierarchy {
|
|
633
|
+
classes: BTreeMap<ClassKey, HierarchyClass>,
|
|
634
|
+
member_names: BTreeMap<ClassKey, DeclaredNames>,
|
|
635
|
+
outside: BTreeSet<ClassKey>,
|
|
636
|
+
config_gaps: BTreeSet<PathBuf>,
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
struct LinkResolver<'a> {
|
|
640
|
+
resolver: &'a DeclarationResolver,
|
|
641
|
+
outside: &'a mut OutsideTypes,
|
|
642
|
+
path: &'a Path,
|
|
643
|
+
library: &'a Path,
|
|
644
|
+
imports: &'a [crate::DartImport],
|
|
645
|
+
exports: &'a BTreeMap<PathBuf, &'a [crate::DartExport]>,
|
|
646
|
+
reached: Option<Vec<crate::DartImport>>,
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
impl LinkResolver<'_> {
|
|
650
|
+
fn imports_with_project_exports(&mut self) -> &[crate::DartImport] {
|
|
651
|
+
self.reached.get_or_insert_with(|| {
|
|
652
|
+
let mut directives = BTreeMap::<(PathBuf, usize, usize), usize>::new();
|
|
653
|
+
let mut all = self.imports.to_vec();
|
|
654
|
+
for reach in self.resolver.export_reach(self.path) {
|
|
655
|
+
for export in self.exports.get(&reach.file).copied().into_iter().flatten() {
|
|
656
|
+
if !(export.uri.starts_with("package:") || export.uri.starts_with("dart:")) {
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
let next = directives.len();
|
|
660
|
+
let serial = *directives
|
|
661
|
+
.entry((
|
|
662
|
+
reach.file.clone(),
|
|
663
|
+
export.location.line,
|
|
664
|
+
export.location.column,
|
|
665
|
+
))
|
|
666
|
+
.or_insert(next);
|
|
667
|
+
let mut combinators = reach.combinators.clone();
|
|
668
|
+
combinators.extend(export.combinators.iter().cloned());
|
|
669
|
+
all.push(crate::DartImport {
|
|
670
|
+
uri: export.uri.clone(),
|
|
671
|
+
condition: export.condition.clone(),
|
|
672
|
+
prefix: reach.prefix.clone(),
|
|
673
|
+
deferred: false,
|
|
674
|
+
combinators,
|
|
675
|
+
location: crate::Location {
|
|
676
|
+
line: usize::MAX - serial,
|
|
677
|
+
column: 0,
|
|
678
|
+
},
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
all
|
|
683
|
+
})
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
fn resolve_all(&mut self, names: &[String]) -> (BTreeSet<ClassKey>, BTreeSet<String>) {
|
|
687
|
+
let mut found = BTreeSet::new();
|
|
688
|
+
let mut unread = BTreeSet::new();
|
|
689
|
+
for name in names {
|
|
690
|
+
match self.resolver.resolve_detailed(self.path, name) {
|
|
691
|
+
Resolution::Found(classes) if !classes.is_empty() => found.extend(classes),
|
|
692
|
+
Resolution::Absent => {
|
|
693
|
+
let imports = self.imports_with_project_exports().to_vec();
|
|
694
|
+
match self.outside.link(self.library, &imports, name, false) {
|
|
695
|
+
Some(class) => {
|
|
696
|
+
found.insert(class);
|
|
697
|
+
}
|
|
698
|
+
None => {
|
|
699
|
+
unread.insert(name.clone());
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
Resolution::Found(_) | Resolution::Unknown => {
|
|
704
|
+
unread.insert(name.clone());
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
(found, unread)
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
fn hierarchy_class(&mut self, class: &crate::ClassSupertypes) -> HierarchyClass {
|
|
712
|
+
let superclasses = class
|
|
713
|
+
.names
|
|
714
|
+
.iter()
|
|
715
|
+
.chain(&class.constraints)
|
|
716
|
+
.filter(|name| !matches!(name.as_str(), "Object" | "core.Object"))
|
|
717
|
+
.cloned()
|
|
718
|
+
.collect::<Vec<_>>();
|
|
719
|
+
let (extended, unread_extended) = self.resolve_all(&superclasses);
|
|
720
|
+
let (mixed, mut unread_interface) = self.resolve_all(&class.mixins);
|
|
721
|
+
let (implemented, unread_implemented) = self.resolve_all(&class.implemented);
|
|
722
|
+
unread_interface.extend(unread_implemented);
|
|
723
|
+
HierarchyClass {
|
|
724
|
+
extended,
|
|
725
|
+
mixed,
|
|
726
|
+
implemented,
|
|
727
|
+
unread_extended,
|
|
728
|
+
unread_interface,
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
fn scanned_files(project: &ScannedProject) -> std::rc::Rc<BTreeSet<PathBuf>> {
|
|
734
|
+
std::rc::Rc::new(
|
|
735
|
+
project
|
|
736
|
+
.files
|
|
737
|
+
.iter()
|
|
738
|
+
.map(|file| normalize_against(&project.root, &file.path))
|
|
739
|
+
.collect(),
|
|
740
|
+
)
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
fn directives_by_path<T>(
|
|
744
|
+
project: &ScannedProject,
|
|
745
|
+
directives: impl Fn(&crate::DartFile) -> &[T],
|
|
746
|
+
) -> BTreeMap<PathBuf, &[T]> {
|
|
747
|
+
project
|
|
748
|
+
.files
|
|
749
|
+
.iter()
|
|
750
|
+
.map(|file| {
|
|
751
|
+
(
|
|
752
|
+
normalize_against(&project.root, &file.path),
|
|
753
|
+
directives(file),
|
|
754
|
+
)
|
|
755
|
+
})
|
|
756
|
+
.collect()
|
|
757
|
+
}
|
|
475
758
|
|
|
476
759
|
fn class_hierarchy(project: &ScannedProject, index: &SymbolIndex) -> Hierarchy {
|
|
477
760
|
let resolver = DeclarationResolver::new(
|
|
@@ -481,6 +764,12 @@ fn class_hierarchy(project: &ScannedProject, index: &SymbolIndex) -> Hierarchy {
|
|
|
481
764
|
name: indexed.declaration.name.clone(),
|
|
482
765
|
}),
|
|
483
766
|
);
|
|
767
|
+
let imports_by_path = directives_by_path(project, |file| file.imports.as_slice());
|
|
768
|
+
let exports_by_path = directives_by_path(project, |file| file.exports.as_slice());
|
|
769
|
+
let roots = PackageRoots::new(project);
|
|
770
|
+
let mut outsides = BTreeMap::<PathBuf, OutsideTypes>::new();
|
|
771
|
+
let loader = SharedLoader::default();
|
|
772
|
+
let scanned = scanned_files(project);
|
|
484
773
|
let mut classes = BTreeMap::<ClassKey, HierarchyClass>::new();
|
|
485
774
|
let mut member_names = BTreeMap::<ClassKey, DeclaredNames>::new();
|
|
486
775
|
for file in &project.files {
|
|
@@ -497,49 +786,80 @@ fn class_hierarchy(project: &ScannedProject, index: &SymbolIndex) -> Hierarchy {
|
|
|
497
786
|
declared.without_body.insert(member.name.clone());
|
|
498
787
|
}
|
|
499
788
|
}
|
|
789
|
+
let library = index.library_path(&path).to_path_buf();
|
|
790
|
+
let config = find_package_config(&roots.of(&path));
|
|
791
|
+
let reader_root = config
|
|
792
|
+
.as_deref()
|
|
793
|
+
.and_then(|config| config.parent()?.parent())
|
|
794
|
+
.map_or_else(|| project.root.clone(), Path::to_path_buf);
|
|
795
|
+
let mut links = LinkResolver {
|
|
796
|
+
resolver: &resolver,
|
|
797
|
+
outside: outsides
|
|
798
|
+
.entry(config.clone().unwrap_or_else(|| project.root.clone()))
|
|
799
|
+
.or_insert_with(|| {
|
|
800
|
+
OutsideTypes::with_loader(&reader_root, loader.clone(), &scanned)
|
|
801
|
+
}),
|
|
802
|
+
path: &path,
|
|
803
|
+
library: &library,
|
|
804
|
+
imports: imports_by_path.get(&library).copied().unwrap_or_default(),
|
|
805
|
+
exports: &exports_by_path,
|
|
806
|
+
reached: None,
|
|
807
|
+
};
|
|
500
808
|
for class in &file.class_supertypes {
|
|
501
|
-
let resolve_all = |names: &[String]| {
|
|
502
|
-
let sets = names
|
|
503
|
-
.iter()
|
|
504
|
-
.map(|name| resolver.resolve(&path, name))
|
|
505
|
-
.collect::<Vec<_>>();
|
|
506
|
-
let outside = sets.iter().any(BTreeSet::is_empty);
|
|
507
|
-
(sets.into_iter().flatten().collect::<BTreeSet<_>>(), outside)
|
|
508
|
-
};
|
|
509
|
-
let superclasses = class
|
|
510
|
-
.names
|
|
511
|
-
.iter()
|
|
512
|
-
.filter(|name| !matches!(name.as_str(), "Object" | "core.Object"))
|
|
513
|
-
.cloned()
|
|
514
|
-
.collect::<Vec<_>>();
|
|
515
|
-
let (extended, outside_extended) = resolve_all(&superclasses);
|
|
516
|
-
let (mixed, outside_mixed) = resolve_all(&class.mixins);
|
|
517
|
-
let (implemented, outside_implemented) = resolve_all(&class.implemented);
|
|
518
809
|
let key = ClassKey {
|
|
519
810
|
path: path.clone(),
|
|
520
811
|
name: class.owner.clone(),
|
|
521
812
|
};
|
|
522
|
-
classes.insert(
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
outside_interface: outside_mixed || outside_implemented,
|
|
530
|
-
},
|
|
531
|
-
);
|
|
813
|
+
classes.insert(key, links.hierarchy_class(class));
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
let mut outside_keys = BTreeSet::new();
|
|
817
|
+
for (key, class) in outsides.values_mut().flat_map(OutsideTypes::expand) {
|
|
818
|
+
if scanned.contains(&key.path) {
|
|
819
|
+
continue;
|
|
532
820
|
}
|
|
821
|
+
outside_keys.insert(key.clone());
|
|
822
|
+
member_names.insert(
|
|
823
|
+
key.clone(),
|
|
824
|
+
DeclaredNames {
|
|
825
|
+
all: class.names,
|
|
826
|
+
without_body: BTreeSet::new(),
|
|
827
|
+
},
|
|
828
|
+
);
|
|
829
|
+
classes.insert(
|
|
830
|
+
key,
|
|
831
|
+
HierarchyClass {
|
|
832
|
+
extended: class.extended,
|
|
833
|
+
mixed: class.mixed,
|
|
834
|
+
implemented: class.implemented,
|
|
835
|
+
unread_extended: class.unread_extended,
|
|
836
|
+
unread_interface: class.unread_interface,
|
|
837
|
+
},
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
let config_gaps = config_gaps(&outsides);
|
|
841
|
+
Hierarchy {
|
|
842
|
+
classes,
|
|
843
|
+
member_names,
|
|
844
|
+
outside: outside_keys,
|
|
845
|
+
config_gaps,
|
|
533
846
|
}
|
|
534
|
-
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
fn config_gaps(outsides: &BTreeMap<PathBuf, OutsideTypes>) -> BTreeSet<PathBuf> {
|
|
850
|
+
outsides
|
|
851
|
+
.iter()
|
|
852
|
+
.filter(|(_, outside)| outside.has_package_config_gaps())
|
|
853
|
+
.map(|(config, _)| config.clone())
|
|
854
|
+
.collect()
|
|
535
855
|
}
|
|
536
856
|
|
|
537
857
|
fn reached_interfaces(
|
|
538
858
|
class: &HierarchyClass,
|
|
539
859
|
classes: &BTreeMap<ClassKey, HierarchyClass>,
|
|
540
|
-
) -> (BTreeMap<ClassKey, bool>,
|
|
860
|
+
) -> (BTreeMap<ClassKey, bool>, BTreeSet<String>) {
|
|
541
861
|
let mut reached = BTreeMap::<ClassKey, bool>::new();
|
|
542
|
-
let mut open = class.
|
|
862
|
+
let mut open = class.unread_interface.clone();
|
|
543
863
|
let mut pending = class
|
|
544
864
|
.mixed
|
|
545
865
|
.iter()
|
|
@@ -552,7 +872,7 @@ fn reached_interfaces(
|
|
|
552
872
|
)
|
|
553
873
|
.collect::<Vec<_>>();
|
|
554
874
|
if !class.mixed.is_empty() {
|
|
555
|
-
open
|
|
875
|
+
open.extend(class.unread_extended.iter().cloned());
|
|
556
876
|
pending.extend(class.extended.iter().map(|parent| (parent.clone(), false)));
|
|
557
877
|
}
|
|
558
878
|
while let Some((reached_class, duty)) = pending.pop() {
|
|
@@ -564,7 +884,8 @@ fn reached_interfaces(
|
|
|
564
884
|
}
|
|
565
885
|
reached.insert(reached_class.clone(), duty);
|
|
566
886
|
if let Some(parent) = classes.get(&reached_class) {
|
|
567
|
-
open
|
|
887
|
+
open.extend(parent.unread_extended.iter().cloned());
|
|
888
|
+
open.extend(parent.unread_interface.iter().cloned());
|
|
568
889
|
pending.extend(
|
|
569
890
|
parent
|
|
570
891
|
.extended
|
|
@@ -583,12 +904,40 @@ fn reached_interfaces(
|
|
|
583
904
|
(reached, open)
|
|
584
905
|
}
|
|
585
906
|
|
|
907
|
+
fn checkable_classes(index: &SymbolIndex) -> BTreeSet<ClassKey> {
|
|
908
|
+
index
|
|
909
|
+
.members
|
|
910
|
+
.iter()
|
|
911
|
+
.filter(|indexed| {
|
|
912
|
+
matches!(
|
|
913
|
+
indexed.member.kind,
|
|
914
|
+
MemberKind::Field | MemberKind::Getter | MemberKind::Setter | MemberKind::Method
|
|
915
|
+
)
|
|
916
|
+
})
|
|
917
|
+
.map(|indexed| ClassKey {
|
|
918
|
+
path: indexed.path.clone(),
|
|
919
|
+
name: indexed.member.owner.clone(),
|
|
920
|
+
})
|
|
921
|
+
.collect()
|
|
922
|
+
}
|
|
923
|
+
|
|
586
924
|
fn interface_skips(project: &ScannedProject, index: &SymbolIndex) -> InterfaceSkips {
|
|
587
|
-
let
|
|
588
|
-
|
|
589
|
-
|
|
925
|
+
let Hierarchy {
|
|
926
|
+
classes,
|
|
927
|
+
member_names,
|
|
928
|
+
outside,
|
|
929
|
+
config_gaps,
|
|
930
|
+
} = class_hierarchy(project, index);
|
|
931
|
+
let checkable = checkable_classes(index);
|
|
932
|
+
let roots = PackageRoots::new(project);
|
|
933
|
+
let mut unread_libraries = BTreeSet::<PathBuf>::new();
|
|
934
|
+
let mut skips = InterfaceSkips {
|
|
935
|
+
config_gaps,
|
|
936
|
+
..InterfaceSkips::default()
|
|
937
|
+
};
|
|
938
|
+
for (class_key, class) in &classes {
|
|
590
939
|
let (reached, open) = reached_interfaces(class, &classes);
|
|
591
|
-
if reached.is_empty() &&
|
|
940
|
+
if reached.is_empty() && open.is_empty() {
|
|
592
941
|
continue;
|
|
593
942
|
}
|
|
594
943
|
let mut ancestors = BTreeSet::new();
|
|
@@ -605,7 +954,15 @@ fn interface_skips(project: &ScannedProject, index: &SymbolIndex) -> InterfaceSk
|
|
|
605
954
|
pending.extend(parent.extended.iter().chain(&parent.mixed).cloned());
|
|
606
955
|
}
|
|
607
956
|
}
|
|
608
|
-
if open {
|
|
957
|
+
if !open.is_empty() {
|
|
958
|
+
if ancestors
|
|
959
|
+
.iter()
|
|
960
|
+
.any(|ancestor| checkable.contains(ancestor))
|
|
961
|
+
{
|
|
962
|
+
skips.unread_names.extend(open);
|
|
963
|
+
skips.unread_packages.insert(roots.of(&class_key.path));
|
|
964
|
+
unread_libraries.insert(index.library_path(&class_key.path).to_path_buf());
|
|
965
|
+
}
|
|
609
966
|
skips.whole_classes.extend(ancestors);
|
|
610
967
|
continue;
|
|
611
968
|
}
|
|
@@ -616,7 +973,7 @@ fn interface_skips(project: &ScannedProject, index: &SymbolIndex) -> InterfaceSk
|
|
|
616
973
|
.filter(|(reached_class, _)| *reached_class != ancestor)
|
|
617
974
|
.filter_map(|(reached_class, duty)| {
|
|
618
975
|
member_names.get(reached_class).map(|declared| {
|
|
619
|
-
if *duty || !ancestor_is_reached {
|
|
976
|
+
if *duty || !ancestor_is_reached || outside.contains(reached_class) {
|
|
620
977
|
&declared.all
|
|
621
978
|
} else {
|
|
622
979
|
&declared.without_body
|
|
@@ -633,9 +990,73 @@ fn interface_skips(project: &ScannedProject, index: &SymbolIndex) -> InterfaceSk
|
|
|
633
990
|
.extend(names);
|
|
634
991
|
}
|
|
635
992
|
}
|
|
993
|
+
for (key, class) in &classes {
|
|
994
|
+
if outside.contains(key) {
|
|
995
|
+
continue;
|
|
996
|
+
}
|
|
997
|
+
let (names, unread) = inherited(class, &classes, &member_names);
|
|
998
|
+
if unread.is_empty() {
|
|
999
|
+
skips
|
|
1000
|
+
.named_members
|
|
1001
|
+
.entry(key.clone())
|
|
1002
|
+
.or_default()
|
|
1003
|
+
.extend(names);
|
|
1004
|
+
} else {
|
|
1005
|
+
if checkable.contains(key) {
|
|
1006
|
+
skips.unread_names.extend(unread);
|
|
1007
|
+
skips.unread_packages.insert(roots.of(&key.path));
|
|
1008
|
+
unread_libraries.insert(index.library_path(&key.path).to_path_buf());
|
|
1009
|
+
}
|
|
1010
|
+
skips.whole_classes.insert(key.clone());
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
skips.missing_imports = reachable_missing_files(project, &unread_libraries);
|
|
636
1014
|
skips
|
|
637
1015
|
}
|
|
638
1016
|
|
|
1017
|
+
fn inherited(
|
|
1018
|
+
class: &HierarchyClass,
|
|
1019
|
+
classes: &BTreeMap<ClassKey, HierarchyClass>,
|
|
1020
|
+
member_names: &BTreeMap<ClassKey, DeclaredNames>,
|
|
1021
|
+
) -> (BTreeSet<String>, BTreeSet<String>) {
|
|
1022
|
+
let mut names = BTreeSet::new();
|
|
1023
|
+
let mut unread = class
|
|
1024
|
+
.unread_extended
|
|
1025
|
+
.iter()
|
|
1026
|
+
.chain(&class.unread_interface)
|
|
1027
|
+
.cloned()
|
|
1028
|
+
.collect::<BTreeSet<_>>();
|
|
1029
|
+
let mut seen = BTreeSet::new();
|
|
1030
|
+
let mut pending = class
|
|
1031
|
+
.extended
|
|
1032
|
+
.iter()
|
|
1033
|
+
.chain(&class.mixed)
|
|
1034
|
+
.chain(&class.implemented)
|
|
1035
|
+
.cloned()
|
|
1036
|
+
.collect::<Vec<_>>();
|
|
1037
|
+
while let Some(ancestor) = pending.pop() {
|
|
1038
|
+
if !seen.insert(ancestor.clone()) {
|
|
1039
|
+
continue;
|
|
1040
|
+
}
|
|
1041
|
+
if let Some(declared) = member_names.get(&ancestor) {
|
|
1042
|
+
names.extend(declared.all.iter().cloned());
|
|
1043
|
+
}
|
|
1044
|
+
if let Some(parent) = classes.get(&ancestor) {
|
|
1045
|
+
unread.extend(parent.unread_extended.iter().cloned());
|
|
1046
|
+
unread.extend(parent.unread_interface.iter().cloned());
|
|
1047
|
+
pending.extend(
|
|
1048
|
+
parent
|
|
1049
|
+
.extended
|
|
1050
|
+
.iter()
|
|
1051
|
+
.chain(&parent.mixed)
|
|
1052
|
+
.chain(&parent.implemented)
|
|
1053
|
+
.cloned(),
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
(names, unread)
|
|
1058
|
+
}
|
|
1059
|
+
|
|
639
1060
|
fn owning_scope<'scope>(
|
|
640
1061
|
packages: &'scope [PackageScope],
|
|
641
1062
|
path: &Path,
|
|
@@ -648,7 +1069,7 @@ fn owning_scope<'scope>(
|
|
|
648
1069
|
|
|
649
1070
|
impl PublicMemberContext {
|
|
650
1071
|
fn new(project: &ScannedProject, dead_code: &DeadCodeReport, index: &SymbolIndex) -> Self {
|
|
651
|
-
let packages = package_scopes(&project.root);
|
|
1072
|
+
let packages = package_scopes(&project.root, &project.ignore_patterns);
|
|
652
1073
|
let public_classes = public_exported_declarations_from(project, |path| {
|
|
653
1074
|
owning_scope(&packages, path).map_or_else(
|
|
654
1075
|
|| is_public_library_entry(&project.root, path),
|
|
@@ -659,6 +1080,7 @@ impl PublicMemberContext {
|
|
|
659
1080
|
.map(|exported| (exported.path, exported.declaration.name))
|
|
660
1081
|
.collect();
|
|
661
1082
|
Self {
|
|
1083
|
+
root: project.root.clone(),
|
|
662
1084
|
interface_skips: interface_skips(project, index),
|
|
663
1085
|
packages,
|
|
664
1086
|
public_classes,
|
|
@@ -696,16 +1118,16 @@ impl PublicMemberContext {
|
|
|
696
1118
|
.contains(&(path.to_path_buf(), owner.to_owned()))
|
|
697
1119
|
}
|
|
698
1120
|
|
|
699
|
-
fn
|
|
700
|
-
owning_scope(&self.packages, path).
|
|
701
|
-
|
|
702
|
-
|scope| is_library_source(&scope.root, path),
|
|
703
|
-
)
|
|
1121
|
+
fn in_checked_source(&self, root: &Path, path: &Path) -> bool {
|
|
1122
|
+
let root = owning_scope(&self.packages, path).map_or(root, |scope| scope.root.as_path());
|
|
1123
|
+
is_library_source(root, path) || is_bin_source(root, path)
|
|
704
1124
|
}
|
|
705
1125
|
|
|
706
|
-
fn is_runtime_entry(&self, path: &Path) -> bool {
|
|
1126
|
+
fn is_runtime_entry(&self, root: &Path, path: &Path) -> bool {
|
|
1127
|
+
let scope = owning_scope(&self.packages, path);
|
|
707
1128
|
self.entry_points.contains(path)
|
|
708
|
-
&&
|
|
1129
|
+
&& scope.is_none_or(|scope| !scope.application)
|
|
1130
|
+
&& !is_bin_source(scope.map_or(root, |scope| scope.root.as_path()), path)
|
|
709
1131
|
}
|
|
710
1132
|
|
|
711
1133
|
fn checks(&self, index: &SymbolIndex, indexed: &IndexedMember) -> bool {
|
|
@@ -721,7 +1143,7 @@ impl PublicMemberContext {
|
|
|
721
1143
|
},
|
|
722
1144
|
&indexed.member.name,
|
|
723
1145
|
)
|
|
724
|
-
&& !self.is_runtime_entry(&indexed.path)
|
|
1146
|
+
&& !self.is_runtime_entry(&self.root, &indexed.path)
|
|
725
1147
|
&& !self.exports_class(&indexed.path, &indexed.member.owner)
|
|
726
1148
|
&& !self
|
|
727
1149
|
.generated_part_libraries
|