-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathanalyzer.rs
More file actions
85 lines (73 loc) · 3.22 KB
/
Copy pathanalyzer.rs
File metadata and controls
85 lines (73 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use crate::{
PackageStoreComputeProperties, core, cyclic_callables,
scaffolding::InternalPackageStoreComputeProperties,
};
use qsc_data_structures::target::TargetCapabilityFlags;
use qsc_fir::fir::{PackageId, PackageStore};
/// A runtime capabilities analyzer.
pub struct Analyzer<'a> {
package_store: &'a PackageStore,
scaffolding: InternalPackageStoreComputeProperties,
target_capabilities: TargetCapabilityFlags,
}
impl<'a> Analyzer<'a> {
#[must_use]
pub fn init(
package_store: &'a PackageStore,
target_capabilities: TargetCapabilityFlags,
) -> Self {
Self {
package_store,
scaffolding: InternalPackageStoreComputeProperties::init(package_store),
target_capabilities,
}
}
#[must_use]
pub fn init_with_compute_properties(
package_store: &'a PackageStore,
target_capabilities: TargetCapabilityFlags,
package_store_compute_properties: PackageStoreComputeProperties,
) -> Self {
Self {
package_store,
scaffolding: package_store_compute_properties.into(),
target_capabilities,
}
}
#[must_use]
pub fn analyze_all(self) -> PackageStoreComputeProperties {
let scaffolding = InternalPackageStoreComputeProperties::init(self.package_store);
// Then, we need to analyze the callable specializations with cycles. Otherwise, we cannot safely analyze the
// rest of the items without causing an infinite analysis loop.
let cyclic_callables_analyzer =
cyclic_callables::Analyzer::new(self.package_store, scaffolding);
let scaffolding = cyclic_callables_analyzer.analyze_all();
// Now we can safely analyze the rest of the items.
let core_analyzer =
core::Analyzer::new(self.package_store, scaffolding, self.target_capabilities);
let result: PackageStoreComputeProperties = core_analyzer.analyze_all().into();
#[cfg(debug_assertions)]
crate::invariants::assert_arity_consistency(self.package_store, &result);
result
}
#[must_use]
pub fn analyze_package(self, package_id: PackageId) -> PackageStoreComputeProperties {
// Even when analyzing just one package we need to first analyze cyclic callables and then the rest of the items
// to avoid an infinite analysis loop.
let cyclic_callables_analyzer =
cyclic_callables::Analyzer::new(self.package_store, self.scaffolding);
let scaffolding = cyclic_callables_analyzer.analyze_package(package_id);
let core_analyzer =
core::Analyzer::new(self.package_store, scaffolding, self.target_capabilities);
let result: PackageStoreComputeProperties =
core_analyzer.analyze_package(package_id).into();
// Note: `analyze_package` is the incremental compiler path. The full-store invariant
// is still valuable for catching regressions introduced by incremental updates, so
// run it here in debug builds as well.
#[cfg(debug_assertions)]
crate::invariants::assert_arity_consistency(self.package_store, &result);
result
}
}