release: v2.1.4 isolated HTTP execute (ADR 0009)
Default execute/sse-live/stream to Supervisor worker pool; MR-01 gold; /_runtime/*; bump CLI/wasm/ext to 2.1.4. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
58e13ee6d3
commit
3cabe53da2
56 files changed
+4957
-304
No files matched your search
+47
-27
@@ -240,32 +240,24 @@ pub struct Compilation {
|
||||
/// side-effect free: it never loads plugins, evaluates expressions or fetches
|
||||
/// sources.
|
||||
pub fn compile_project(options: &CompileOptions) -> Result<Compilation> {
|
||||
let t_index = std::time::Instant::now();
|
||||
let root = ProjectRoot::new(&options.project_root)?;
|
||||
let index = ProjectIndex::build(root.clone())?;
|
||||
let index_ms = t_index.elapsed().as_millis();
|
||||
// Reuse parsed modules from ProjectIndex — same input snapshot, no second parse (M-R5b).
|
||||
let mut files = BTreeMap::new();
|
||||
let mut diagnostics = Vec::new();
|
||||
for file in root.source_files()? {
|
||||
let text = fs::read_to_string(&file)
|
||||
.with_context(|| format!("read semantic source {}", file.display()))?;
|
||||
match crate::load::parse_source_auto(&text) {
|
||||
Ok(module) => {
|
||||
let module_id = index
|
||||
.modules()
|
||||
.iter()
|
||||
.find_map(|(id, path)| (path == &file).then(|| id.clone()));
|
||||
if let Some(module_id) = module_id {
|
||||
files.insert(module_id, (file, text, module));
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
diagnostics.push(
|
||||
Diagnostic::new(Some(&file), Span::new(1, 1), error.to_string())
|
||||
.with_code("parse.semantic")
|
||||
.with_severity(Severity::Error),
|
||||
);
|
||||
}
|
||||
}
|
||||
for (module_id, parsed) in index.parsed_modules() {
|
||||
files.insert(
|
||||
module_id.clone(),
|
||||
(
|
||||
parsed.path.clone(),
|
||||
parsed.text.clone(),
|
||||
parsed.module.clone(),
|
||||
),
|
||||
);
|
||||
}
|
||||
let _ = index_ms; // ProjectIndex build duration (M-R5b span)
|
||||
|
||||
// Wire import_modules from already-parsed project files so BoundCall path
|
||||
// resolve shares `resolve_for_exec` (no plugin load / no re-parse).
|
||||
@@ -288,12 +280,8 @@ pub fn compile_project(options: &CompileOptions) -> Result<Compilation> {
|
||||
collect_functions(&module.functions, &mut Vec::new(), &mut by_path);
|
||||
let narrative_links = crate::parse::scan_narrative_links(text);
|
||||
let module_prov = super::provenance::parse_module_provenance(text);
|
||||
let module_symbols: Vec<&SymbolDecl> = index
|
||||
.symbols()
|
||||
.iter()
|
||||
.filter(|s| &s.module == module_id)
|
||||
.collect();
|
||||
for symbol in index.symbols().iter().filter(|s| &s.module == module_id) {
|
||||
let module_symbols = index.symbols_in_module(module_id);
|
||||
for symbol in index.symbols_in_module(module_id) {
|
||||
let function = by_path.get(&symbol.declaration_path).expect("symbol collected from module");
|
||||
let owned_links: Vec<_> = narrative_links
|
||||
.iter()
|
||||
@@ -1315,12 +1303,44 @@ pub fn write_semantic_projections(out_dir: &Path, compilation: &Compilation) ->
|
||||
fs::create_dir_all(gen_dir.join("verification"))?;
|
||||
write_generation_tree(&gen_dir, compilation)?;
|
||||
|
||||
// Publish journal + CAS (M-R6): record expected CURRENT before switching.
|
||||
let expected = fs::read_to_string(out_dir.join("CURRENT"))
|
||||
.ok()
|
||||
.map(|s| s.trim().to_string())
|
||||
.filter(|s| !s.is_empty());
|
||||
let source_digest = {
|
||||
let mut h = Sha256::new();
|
||||
for a in &compilation.semantics.artifacts {
|
||||
h.update(a.hashes.artifact.0.as_bytes());
|
||||
}
|
||||
format!("sha256:{:x}", h.finalize())
|
||||
};
|
||||
// Staging already written under gen_dir; journal tracks CURRENT switch.
|
||||
let mut journal = crate::runtime::PublishJournal::begin(
|
||||
out_dir,
|
||||
&compilation.semantics.project_id,
|
||||
expected,
|
||||
&build_id,
|
||||
&source_digest,
|
||||
)
|
||||
.map_err(|e| anyhow::anyhow!("publish journal: {e}"))?;
|
||||
// Point journal staging at the generation we just wrote (already complete).
|
||||
journal.staging_dir = gen_dir.clone();
|
||||
journal.generation_dir = gen_dir.clone();
|
||||
journal
|
||||
.mark(out_dir, crate::runtime::publish::PublishPhase::Validated)
|
||||
.map_err(|e| anyhow::anyhow!("publish journal mark: {e}"))?;
|
||||
|
||||
// Atomic generation pointer: only publish CURRENT after the tree is complete.
|
||||
let current_tmp = out_dir.join("CURRENT.tmp");
|
||||
fs::write(¤t_tmp, format!("{build_id}\n"))
|
||||
.with_context(|| format!("write {}", current_tmp.display()))?;
|
||||
fs::rename(¤t_tmp, out_dir.join("CURRENT"))
|
||||
.with_context(|| format!("publish CURRENT under {}", out_dir.display()))?;
|
||||
journal
|
||||
.mark(out_dir, crate::runtime::publish::PublishPhase::CurrentSwitched)
|
||||
.map_err(|e| anyhow::anyhow!("publish journal current: {e}"))?;
|
||||
let _ = fs::remove_file(out_dir.join("publish_journal.json"));
|
||||
|
||||
// Compatibility root: stage a full mirror, then swap names (best-effort for
|
||||
// legacy readers that do not follow CURRENT).
|
||||
|
||||
@@ -92,15 +92,29 @@ pub struct SymbolDecl {
|
||||
pub line: u32,
|
||||
}
|
||||
|
||||
/// Parsed module retained so `compile_project` does not re-parse (M-R5b).
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ParsedModule {
|
||||
pub path: PathBuf,
|
||||
pub text: String,
|
||||
pub module: crate::ast::Module,
|
||||
}
|
||||
|
||||
/// Deterministic read-only view of all declarations in one project.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ProjectIndex {
|
||||
project_id: String,
|
||||
root: ProjectRoot,
|
||||
modules: BTreeMap<ModuleId, PathBuf>,
|
||||
/// path → module id (avoids linear scan per file in compile_project).
|
||||
path_to_module: BTreeMap<PathBuf, ModuleId>,
|
||||
symbols: Vec<SymbolDecl>,
|
||||
by_id: BTreeMap<SymbolId, usize>,
|
||||
by_name: BTreeMap<String, Vec<usize>>,
|
||||
/// module → symbol indexes (avoids filtering the full symbol table per module).
|
||||
symbols_by_module: BTreeMap<ModuleId, Vec<usize>>,
|
||||
/// Shared parsed AST/text for the same input snapshot.
|
||||
parsed: BTreeMap<ModuleId, ParsedModule>,
|
||||
}
|
||||
|
||||
impl ProjectIndex {
|
||||
@@ -108,7 +122,9 @@ impl ProjectIndex {
|
||||
let project_id = project_id(root.path());
|
||||
let files = root.source_files()?;
|
||||
let mut modules = BTreeMap::new();
|
||||
let mut path_to_module = BTreeMap::new();
|
||||
let mut symbols = Vec::new();
|
||||
let mut parsed = BTreeMap::new();
|
||||
|
||||
for file in files {
|
||||
let source = fs::read_to_string(&file)
|
||||
@@ -121,6 +137,7 @@ impl ProjectIndex {
|
||||
file.display()
|
||||
);
|
||||
}
|
||||
path_to_module.insert(file.clone(), module_id.clone());
|
||||
let module = crate::load::parse_source_auto(&source)
|
||||
.with_context(|| format!("parse source {}", file.display()))?;
|
||||
for function in &module.functions {
|
||||
@@ -134,28 +151,47 @@ impl ProjectIndex {
|
||||
&mut symbols,
|
||||
)?;
|
||||
}
|
||||
parsed.insert(
|
||||
module_id.clone(),
|
||||
ParsedModule {
|
||||
path: file,
|
||||
text: source,
|
||||
module,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
symbols.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
let mut by_id = BTreeMap::new();
|
||||
let mut by_name: BTreeMap<String, Vec<usize>> = BTreeMap::new();
|
||||
let mut symbols_by_module: BTreeMap<ModuleId, Vec<usize>> = BTreeMap::new();
|
||||
for (index, symbol) in symbols.iter().enumerate() {
|
||||
if by_id.insert(symbol.id.clone(), index).is_some() {
|
||||
bail!("duplicate symbol id `{}`", symbol.id);
|
||||
}
|
||||
by_name.entry(symbol.name.clone()).or_default().push(index);
|
||||
symbols_by_module
|
||||
.entry(symbol.module.clone())
|
||||
.or_default()
|
||||
.push(index);
|
||||
}
|
||||
for indexes in by_name.values_mut() {
|
||||
indexes.sort_by(|a, b| symbols[*a].id.cmp(&symbols[*b].id));
|
||||
}
|
||||
for indexes in symbols_by_module.values_mut() {
|
||||
indexes.sort_by(|a, b| symbols[*a].id.cmp(&symbols[*b].id));
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
project_id,
|
||||
root,
|
||||
modules,
|
||||
path_to_module,
|
||||
symbols,
|
||||
by_id,
|
||||
by_name,
|
||||
symbols_by_module,
|
||||
parsed,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -171,6 +207,21 @@ impl ProjectIndex {
|
||||
&self.modules
|
||||
}
|
||||
|
||||
pub fn module_id_for_path(&self, path: &Path) -> Option<&ModuleId> {
|
||||
self.path_to_module.get(path)
|
||||
}
|
||||
|
||||
pub fn symbols_in_module(&self, module_id: &ModuleId) -> Vec<&SymbolDecl> {
|
||||
self.symbols_by_module
|
||||
.get(module_id)
|
||||
.map(|idxs| idxs.iter().map(|i| &self.symbols[*i]).collect())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn parsed_modules(&self) -> &BTreeMap<ModuleId, ParsedModule> {
|
||||
&self.parsed
|
||||
}
|
||||
|
||||
pub fn symbols(&self) -> &[SymbolDecl] {
|
||||
&self.symbols
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user