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 two callers (`compile_project`/
15// `analyse_project_with`), not project-model or checker output.
16pub use bynk_check::analysis::{ContextBoundaryInfo, ContextSequenceInfo, ProjectAnalysis};
17// `ErrorSink` relocated to `bynk-check::project_model` too — every
18// `phase_*` function it moved alongside takes `&mut ErrorSink`, so the type
19// had to travel with them (the same "shared logic pulls its own types down
20// with it" reasoning `UnitTable`/`ConsumedType` already went through when
21// `symbols.rs` moved). Re-exported at this crate-private path so every
22// existing `bynk-emit`-internal call site is unchanged.
23pub(crate) use bynk_check::project_model::ErrorSink;
24
25/// Internal: do the work, given a source root (for commons/contexts) and a
26/// test root (for test units). When both roots are the same path the
27/// behaviour is identical to the v0.4+ single-tree layout. When they differ
28/// — v0.9.1's split-paths mode — sources and tests are discovered separately
29/// and the new `inconsistent_test_path` check fires.
30/// v0.24 (ADR 0052): how the project pipeline is driven. `Build` preserves
31/// the CLI contract exactly (bail at the structural and pre-emit gates);
32/// `Analyse` never bails after discovery, skips all emission, and lets
33/// independent unit groups resolve/check past another group's errors.
34#[derive(Clone, Copy, PartialEq, Eq)]
35pub(crate) enum Mode {
36 Build,
37 Analyse,
38}
39
40/// v0.24: a failed build with its attribution and snapshots intact — what
41/// the CLI renders rich (ariadne source context per file); the plain
42/// `compile_project*` wrappers flatten it to the pre-v0.24 error list.
43pub struct ProjectFailure {
44 pub errors: Vec<AttributedError>,
45 pub snapshots: Vec<(PathBuf, String)>,
46}
47
48impl ProjectFailure {
49 /// The pre-v0.24 contract: collection-ordered, attribution dropped.
50 pub fn flatten(self) -> Vec<CompileError> {
51 self.errors.into_iter().map(|a| a.error).collect()
52 }
53}