Skip to content

Commit 385ebf6

Browse files
committed
feat(routines): add typed compiler pipeline
Compose resolution, scalar ABI projection, name allocation, source claims, and capability-rooted declaration checks behind one typed entry point. Preserve exact stage errors and add full-chain, precedence, limits, and root-isolation coverage.
1 parent d624ea7 commit 385ebf6

3 files changed

Lines changed: 1051 additions & 0 deletions

File tree

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//! Capability-rooted composition of the typed routine compiler stages.
2+
//!
3+
//! The entry point accepts validated in-memory inputs and returns only the bound
4+
//! scalar projection. Source bytes are read only after resolution, ABI projection,
5+
//! name allocation, and source-claim projection have succeeded.
6+
7+
use std::fmt;
8+
9+
use crate::bound_scalars::BoundScalarProjection;
10+
use crate::declaration_pipeline::{
11+
DeclarationRootPipelineError, DeclarationRootPipelineLimits,
12+
check_declaration_pipeline_from_roots,
13+
};
14+
use crate::declaration_source::DeclarationSourceRoots;
15+
use crate::resolution::{
16+
ResolutionError, ResolutionLimits, ValidatedResolutionInput, resolve_validated,
17+
};
18+
use crate::scalar_abi::{EnumAbiMapping, ScalarAbiError, project_scalar_abi};
19+
use crate::scalar_names::{ScalarNameError, allocate_scalar_names};
20+
use crate::scalar_source_claims::{
21+
SourceClaimError, SourceClassClaim, SourceInventory, SourceMemberBinding, SourcePin,
22+
project_scalar_source_claims,
23+
};
24+
25+
/// Failure from the first compiler stage that rejects its input.
26+
#[derive(Clone, Debug, PartialEq, Eq)]
27+
pub enum CompilerPipelineError {
28+
/// Validated-input resolution failed.
29+
Resolution(ResolutionError),
30+
/// Scalar ABI projection or enum mapping failed.
31+
ScalarAbi(ScalarAbiError),
32+
/// Scalar-name allocation failed.
33+
ScalarNames(ScalarNameError),
34+
/// Inventory-anchored source-claim projection failed.
35+
SourceClaims(SourceClaimError),
36+
/// Declaration preparation, acquisition, or syntax checking failed.
37+
Declaration(DeclarationRootPipelineError),
38+
}
39+
40+
impl fmt::Display for CompilerPipelineError {
41+
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
42+
match self {
43+
Self::Resolution(error) => write!(formatter, "resolution failed: {error}"),
44+
Self::ScalarAbi(error) => write!(formatter, "scalar ABI projection failed: {error}"),
45+
Self::ScalarNames(error) => {
46+
write!(formatter, "scalar name allocation failed: {error}")
47+
}
48+
Self::SourceClaims(error) => {
49+
write!(formatter, "source claim projection failed: {error}")
50+
}
51+
Self::Declaration(error) => write!(formatter, "declaration pipeline failed: {error}"),
52+
}
53+
}
54+
}
55+
56+
impl std::error::Error for CompilerPipelineError {
57+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
58+
match self {
59+
Self::Resolution(error) => Some(error),
60+
Self::ScalarAbi(error) => Some(error),
61+
Self::ScalarNames(error) => Some(error),
62+
Self::SourceClaims(error) => Some(error),
63+
Self::Declaration(error) => Some(error),
64+
}
65+
}
66+
}
67+
68+
/// Runs the typed compiler stages and reads declarations through borrowed roots.
69+
///
70+
/// Resolution and declaration limits are forwarded to their owning stages. The
71+
/// function stops on the first error and returns no intermediate projection.
72+
/// Inputs and directory capabilities remain borrowed.
73+
///
74+
/// # Errors
75+
///
76+
/// Returns the failed stage with its unchanged error.
77+
#[allow(clippy::too_many_arguments)]
78+
pub fn compile_validated_from_roots(
79+
resolution_input: &ValidatedResolutionInput,
80+
resolution_limits: ResolutionLimits,
81+
enum_mappings: &[EnumAbiMapping],
82+
source_inventory: &SourceInventory,
83+
source_pins: &[SourcePin],
84+
class_claims: &[SourceClassClaim],
85+
member_bindings: &[SourceMemberBinding],
86+
roots: DeclarationSourceRoots<'_>,
87+
declaration_limits: DeclarationRootPipelineLimits,
88+
) -> Result<BoundScalarProjection, CompilerPipelineError> {
89+
let resolved = resolve_validated(resolution_input, resolution_limits)
90+
.map_err(CompilerPipelineError::Resolution)?;
91+
let scalar_abi =
92+
project_scalar_abi(&resolved, enum_mappings).map_err(CompilerPipelineError::ScalarAbi)?;
93+
let named = allocate_scalar_names(&scalar_abi).map_err(CompilerPipelineError::ScalarNames)?;
94+
let source_claims = project_scalar_source_claims(
95+
&named,
96+
source_inventory,
97+
source_pins,
98+
class_claims,
99+
member_bindings,
100+
)
101+
.map_err(CompilerPipelineError::SourceClaims)?;
102+
check_declaration_pipeline_from_roots(&named, &source_claims, roots, declaration_limits)
103+
.map_err(CompilerPipelineError::Declaration)
104+
}
105+
106+
#[cfg(test)]
107+
mod tests;

0 commit comments

Comments
 (0)