bynk_emit/project/diagnostics.rs
1use std::path::PathBuf;
2
3use bynk_project::AttributedError;
4use bynk_syntax::error::CompileError;
5
6// P4.1 (#1115): `ProjectAnalysis`/`ContextSequenceInfo`/`ContextBoundaryInfo`
7// relocated verbatim (Decision C) to `bynk-check/src/analysis.rs`, alongside
8// the new `bynk-check`-native analysis entry point that also needs to build
9// one. Re-exported here so `crate::project::{ProjectAnalysis, ...}` (this
10// module's own `pub use` chain, `project.rs:80`) — and every downstream
11// caller, including `bynk-ide`'s `bynk_emit::project::ProjectAnalysis`
12// import — keeps resolving unchanged. `Mode`/`ErrorSink`/`ProjectFailure`
13// below are unaffected: `Mode` and `ProjectFailure` are pipeline-driving
14// facts specific to `bynk-emit`'s own `run_checks` callers
15// (`compile_project`/`compile_in_memory`/`check_project`/
16// `analyse_in_memory_with_types`), not project-model or checker output.
17pub use bynk_check::analysis::{ContextBoundaryInfo, ContextSequenceInfo, ProjectAnalysis};
18// `ErrorSink` relocated to `bynk-check::project_model` too — every
19// `phase_*` function it moved alongside takes `&mut ErrorSink`, so the type
20// had to travel with them (the same "shared logic pulls its own types down
21// with it" reasoning `UnitTable`/`ConsumedType` already went through when
22// `symbols.rs` moved). Re-exported at this crate-private path so every
23// existing `bynk-emit`-internal call site is unchanged.
24pub(crate) use bynk_check::project_model::ErrorSink;
25
26/// Internal: do the work, given a source root (for commons/contexts) and a
27/// test root (for test units). When both roots are the same path the
28/// behaviour is identical to the v0.4+ single-tree layout. When they differ
29/// — v0.9.1's split-paths mode — sources and tests are discovered separately
30/// and the new `inconsistent_test_path` check fires.
31/// v0.24 (ADR 0052): how the project pipeline is driven. `Build` preserves
32/// the CLI contract exactly (bail at the structural and pre-emit gates);
33/// `Analyse` never bails after discovery, skips all emission, and lets
34/// independent unit groups resolve/check past another group's errors.
35#[derive(Clone, Copy, PartialEq, Eq)]
36pub(crate) enum Mode {
37 Build,
38 Analyse,
39}
40
41/// v0.24: a failed build with its attribution and snapshots intact — what
42/// the CLI renders rich (ariadne source context per file); the plain
43/// `compile_project*` wrappers flatten it to the pre-v0.24 error list.
44pub struct ProjectFailure {
45 pub errors: Vec<AttributedError>,
46 pub snapshots: Vec<(PathBuf, String)>,
47 /// #1772: the project or tree root the build was given, as the caller
48 /// spelled it. `snapshots` and each error's `source_path` are keyed by
49 /// identity path, relative to this root; a renderer shows
50 /// `display_root.join(identity)`, the path as typed from the working
51 /// directory. Empty for an in-memory build.
52 pub display_root: PathBuf,
53}
54
55impl ProjectFailure {
56 /// The pre-v0.24 contract: collection-ordered, attribution dropped.
57 pub fn flatten(self) -> Vec<CompileError> {
58 self.errors.into_iter().map(|a| a.error).collect()
59 }
60}