From 15468a910d93bf550098cfc93863f4bc2cf61cb4 Mon Sep 17 00:00:00 2001 From: DOOM1EM8Cover Date: Tue, 29 Aug 2023 05:02:43 +0100 Subject: [PATCH] Attempt at lifetimes and RefCell only for interpretation --- core/README.md | 4 ++ core/examples/dev.ids | 15 +++---- core/src/project/build/mod.rs | 44 +++++++++--------- core/src/project/ir/compiler/interpret.rs | 14 +++--- core/src/project/ir/context.rs | 31 ++++++------- core/src/project/ir/diff/mod.rs | 14 +++--- core/src/project/ir/frozen/mod.rs | 5 +-- core/src/project/ir/interpreter/freezing.rs | 4 +- core/src/project/ir/interpreter/interpret.rs | 12 +++-- core/src/project/ir/interpreter/mod.rs | 23 ++++++---- core/src/schema/idl/parser_new.rs | 11 +++-- .../ir/compiler/interpreted/interpreter.rs | 31 ++++++------- .../ir/compiler/interpreted/primitive.rs | 1 + .../ir/compiler/interpreter/meta_stage.rs | 45 +++++++------------ .../ir/compiler/interpreter/object_stage.rs | 1 + .../ir/compiler/interpreter/semi_frozen.rs | 1 + core/src/schema/ir/context.rs | 30 ++++++------- core/src/schema/ir/frozen/unit.rs | 5 ++- core/tests/package/test/health.ids | 1 + 19 files changed, 147 insertions(+), 145 deletions(-) diff --git a/core/README.md b/core/README.md index e3929a4..2c4988f 100644 --- a/core/README.md +++ b/core/README.md @@ -18,3 +18,7 @@ https://docs.rs/codemap/latest/codemap/ https://www.youtube.com/watch?v=m64SWl9bfvk https://www.youtube.com/watch?v=ApHpmA1k73k + +### Optimizing AST parsing and allocation +https://cs.hofstra.edu/~cscccl/rustlr_project/chapter6.html + diff --git a/core/examples/dev.ids b/core/examples/dev.ids index 2a4df0d..21ce300 100644 --- a/core/examples/dev.ids +++ b/core/examples/dev.ids @@ -1,7 +1,4 @@ -tag @? -namespace examples.full - -// Standard Imports +namespace dev import std::str::StringBounds settings { @@ -10,7 +7,7 @@ settings { } -@affects=struct protocol +@affects=[struct protocol] settings MailSettings { indexed=true } @@ -24,16 +21,16 @@ struct Mail { struct Article { @validators=[StringBounds(min_chars=3 max_chars=32] - 1# title: str + title: str @validators=[StringBounds(min_chars=24 max_chars=412] - 2# content: str + content: str } @hidden @settings=MailSettings protocol Mail { - 1# async function send(Mail) + async function send(mail: Mail) } @@ -44,5 +41,5 @@ protocol Feed { // Fetches new articles since last fetch @flexible async stream #timeout=1000ms per_send_timeout=10s cooldown=10s - 1# function fetch_articles() -> Article[SENT_ARTICLES_MAX] + function fetch_articles() -> Article[SENT_ARTICLES_MAX] } diff --git a/core/src/project/build/mod.rs b/core/src/project/build/mod.rs index af4902f..848ab59 100644 --- a/core/src/project/build/mod.rs +++ b/core/src/project/build/mod.rs @@ -1,10 +1,9 @@ +use std::cell::RefCell; // Standard Uses use std::path::Path; use std::collections::HashMap; use std::fs::File; use std::io::Write; -use std::rc::Rc; -use std::cell::RefCell; // Crate Uses use crate::codegen; @@ -38,7 +37,8 @@ pub fn build(path: &Path) -> Result<()> { let latest_frozen = frozen::loader::from_latest_frozen(&frozen_path); - let compiled_project = ProjectInterpreter::from_origin(config_path); + let (compiled_project, frozen) + = ProjectInterpreter::from_origin(config_path)?; // TODO: Check integrity of the frozen contents, if they are valid, if something is broken, etc @@ -49,33 +49,31 @@ pub fn build(path: &Path) -> Result<()> { ); } - let mut project_ctx = RefCell::borrow_mut(&compiled_project.0); - for relative in frozen::schema_paths(&compiled_project.1) { + let mut project_ctx = compiled_project.borrow_mut(); + let schema_paths = frozen::schema_paths(&frozen); + for relative in schema_paths { let concrete = format!("{:}/{}", path.to_str().unwrap(), relative); let concrete_path = Path::new(&concrete); let unit = idl::parser_new::from_path(concrete_path)?; - let context = Rc::new(RefCell::new( - ir::context::SchemaContext::with_project_and_main( - unit, compiled_project.0.clone() - ) - )); + let context = ir::context::SchemaContext::with_project_and_main( + unit, &compiled_project + ); - project_ctx.add_schema_context(context.clone()); + project_ctx.add_schema_context(RefCell::new(context)); } - compiler::interpret::interpret_context(&project_ctx)?; + compiler::interpret::interpret_context(&compiled_project)?; - // We drop here since we should not need mutability anymore - drop(project_ctx); + // generate_code_for_targets(&compiled_project).unwrap(); - generate_code_for_targets(&compiled_project).unwrap(); + todo!() - Ok(()) + // Ok(()) } -pub fn generate_code_for_targets(compiled_project: &FrozenWhole) -> Result<()> { +pub fn generate_code_for_targets(compiled_project: &mut FrozenWhole) -> Result<()> { for item in compiled_project.1.iter() { match item { FrozenUnit::CodeGeneration(details) => { @@ -101,9 +99,7 @@ pub fn generate_code_for_targets(compiled_project: &FrozenWhole) -> Result<()> { ) } - generate_code_for_context( - &compiled_project.0.borrow(), generator, &path - )?; + generate_code_for_context(&compiled_project.0, generator, &path)?; }, _ => {} } @@ -131,12 +127,13 @@ pub fn resolve_path_query(query: &Option, args: Args) -> Result, target_path: &Path ) -> Result<()> { + /* for schema_context in context.schema_contexts.iter() { - let ctx = schema_context.borrow(); - let frozen_schema = ctx.frozen_schema.as_ref().unwrap(); + let frozen_schema = schema_context.frozen_schema.as_ref().unwrap(); let mut code = "Generated code with Comline compiler".to_owned(); @@ -146,6 +143,9 @@ pub fn generate_code_for_context( } Ok(()) + */ + + todo!() } pub fn build_index(frozen_path: &Path) { diff --git a/core/src/project/ir/compiler/interpret.rs b/core/src/project/ir/compiler/interpret.rs index a957afc..b6f1360 100644 --- a/core/src/project/ir/compiler/interpret.rs +++ b/core/src/project/ir/compiler/interpret.rs @@ -1,18 +1,22 @@ // Standard Uses -use std::cell::RefMut; +use std::cell::RefCell; // Crate Uses use crate::project::ir::context::ProjectContext; -use crate::schema::ir::compiler::interpreted::interpreter; use crate::schema::ir::compiler::interpreter::meta_stage; // External Uses use eyre::{anyhow, Result}; -pub fn interpret_context(project_context: &RefMut) -> Result<()> { - for schema_context in project_context.schema_contexts.iter() { - meta_stage::compile_schema_metadata(schema_context, project_context) +pub fn interpret_context<'a>(project_context: &'a RefCell>) -> Result<()> { + let len = project_context.borrow().schema_contexts.len(); + + for i in 0..len { + let project_ctx = &project_context.borrow(); + let schema_ctx = &project_ctx.schema_contexts[i]; + + meta_stage::compile_schema_metadata(&schema_ctx) .map_err(|e| anyhow!("{}", e))?; } diff --git a/core/src/project/ir/context.rs b/core/src/project/ir/context.rs index 502c31a..25d0813 100644 --- a/core/src/project/ir/context.rs +++ b/core/src/project/ir/context.rs @@ -6,7 +6,6 @@ use std::rc::Rc; // Crate Uses use crate::project::idl::ast::{SourcedWhole as ProjectSourcedWhole}; use crate::schema::ir::context::SchemaContext; -use crate::schema::idl::ast::unit::{ASTUnit, Details}; // External Uses @@ -17,18 +16,17 @@ pub enum Origin { Disk(PathBuf) } -#[derive(Clone)] -pub struct ProjectContext { +pub struct ProjectContext<'a> { pub origin: Origin, pub config: ProjectSourcedWhole, - pub schema_contexts: Vec>>, + pub schema_contexts: Vec>>, - pub relative_projects: Vec>, + pub relative_projects: Vec>, } #[allow(unused)] -impl ProjectContext { +impl<'a> ProjectContext<'a> { pub fn with_config_origin(origin: Origin, config: ProjectSourcedWhole) -> Self { Self { origin, config, @@ -47,7 +45,7 @@ impl ProjectContext { pub(crate) fn add_relative_project(mut self, sourced: ProjectSourcedWhole) { self.relative_projects.push( - Rc::from(Self::with_config(sourced)) + Self::with_config(sourced) ) } @@ -55,7 +53,7 @@ impl ProjectContext { todo!() } - pub(crate) fn add_schema_context(&mut self, context: Rc>) { + pub(crate) fn add_schema_context(&mut self, context: RefCell>) { self.schema_contexts.push(context); } @@ -63,21 +61,24 @@ impl ProjectContext { todo!() } - pub(crate) fn find_schema_by_import(&self, import: &str) -> Option<&Rc>> { - for schema_context in self.schema_contexts.iter() { - let ctx = schema_context.borrow(); - let units = &ctx.schema.1; - - if let Some(unit) = units.find_namespace() { + pub(crate) fn find_schema_by_import(&self, import: &str) + -> Option<&mut SchemaContext> + { + /* + for schema_context in self.schema_contexts { + if let Some(unit) = schema_context.schema.1.find_namespace() { if let ASTUnit::Namespace(_, namespace) = &unit.1 { if namespace == import { - return Some(schema_context) + return Some(*schema_context) } } } } None + */ + + todo!() } /* diff --git a/core/src/project/ir/diff/mod.rs b/core/src/project/ir/diff/mod.rs index d786ed3..5f76976 100644 --- a/core/src/project/ir/diff/mod.rs +++ b/core/src/project/ir/diff/mod.rs @@ -4,14 +4,13 @@ pub mod versioning; // Standard Uses use std::fmt::Debug; +use std::cell::RefCell; // Crate Uses -use crate::autodoc::document::Document; +use crate::project::ir::context::ProjectContext; use crate::project::ir::frozen::{Dependency, FrozenUnit, FrozenWhole}; -use crate::project::ir::diff::versioning::Versioning; // External Uses -use semver::Version; use downcast_rs::{Downcast, impl_downcast}; @@ -23,20 +22,24 @@ pub trait Differ: Downcast + Debug { // fn on_assignment_changed(&self, old: AssignmentUnit, new: AssignmentUnit); + #[allow(unused)] fn differ( &self, previous: &Vec, next: &FrozenWhole, document_gen: bool, auto_version: bool ) { - differ(previous, next, document_gen, auto_version) + // differ(previous, next, document_gen, auto_version) } } impl_downcast!(Differ); #[allow(unused)] pub fn differ( - previous: &Vec, next: &FrozenWhole, + previous: &Vec, next: &RefCell, document_gen: bool, auto_version: bool ) { + todo!() + + /* let mut previous_version = versioning::version_from(previous).unwrap_or( &Version::parse("0.0.0").unwrap().to_string() ); @@ -50,6 +53,7 @@ pub fn differ( let document = listeners[0].downcast_ref::().unwrap(); let versioning = listeners[1].downcast_ref::().unwrap(); + */ } #[allow(unused)] diff --git a/core/src/project/ir/frozen/mod.rs b/core/src/project/ir/frozen/mod.rs index aaa4bcc..9286f7b 100644 --- a/core/src/project/ir/frozen/mod.rs +++ b/core/src/project/ir/frozen/mod.rs @@ -3,9 +3,6 @@ pub mod loader; pub mod meta; // Standard Uses -use std::rc::Rc; -use std::cell::RefCell; - use std::slice::Iter; use std::iter::FilterMap; @@ -15,7 +12,7 @@ use crate::project::ir::context::ProjectContext; // External Uses -pub type FrozenWhole = (Rc>, Vec); +pub type FrozenWhole<'a> = (ProjectContext<'a>, Vec); #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] diff --git a/core/src/project/ir/interpreter/freezing.rs b/core/src/project/ir/interpreter/freezing.rs index 19fc768..70569f2 100644 --- a/core/src/project/ir/interpreter/freezing.rs +++ b/core/src/project/ir/interpreter/freezing.rs @@ -202,8 +202,8 @@ fn interpret_assigment_publish_targets(items: &Vec) } #[allow(unused)] -pub fn into_frozen_whole( - context: &ProjectContext, interpreted: Vec +pub fn into_frozen_whole<'a>( + context: &'a ProjectContext<'a>, interpreted: Vec ) -> Result> { todo!() diff --git a/core/src/project/ir/interpreter/interpret.rs b/core/src/project/ir/interpreter/interpret.rs index d03295b..24c9d43 100644 --- a/core/src/project/ir/interpreter/interpret.rs +++ b/core/src/project/ir/interpreter/interpret.rs @@ -1,10 +1,8 @@ // Standard Uses -use std::cell::RefCell; -use std::rc::Rc; // Crate Uses use crate::project::ir::context::ProjectContext; -use crate::project::ir::frozen::{FrozenUnit, FrozenWhole}; +use crate::project::ir::frozen::FrozenUnit; use crate::project::ir::compiler::report::CompileError; use crate::project::ir::interpreter::freezing; use crate::report::ReportDetails; @@ -13,10 +11,10 @@ use crate::report::ReportDetails; #[allow(unused)] -pub fn interpret_context(context: ProjectContext) - -> Result> +pub fn interpret_context<'a>(mut context: &ProjectContext) + -> Result, ReportDetails> { - let mut interpreted: Vec = vec![]; + let mut interpreted = vec![]; for node in &context.config.1 { let file = context.config.0.files().first().unwrap(); @@ -27,6 +25,6 @@ pub fn interpret_context(context: ProjectContext) ); } - Ok((Rc::new(RefCell::new(context)), interpreted)) + Ok(interpreted) // freezing::into_frozen_whole(&context, interpreted) } diff --git a/core/src/project/ir/interpreter/mod.rs b/core/src/project/ir/interpreter/mod.rs index 71a1c2b..6dff159 100644 --- a/core/src/project/ir/interpreter/mod.rs +++ b/core/src/project/ir/interpreter/mod.rs @@ -3,28 +3,29 @@ pub mod report; pub mod interpret; pub mod freezing; +use std::cell::RefCell; // Standard Uses use std::path::Path; // Crate Uses -use crate::project; use crate::project::idl::parser_new; use crate::project::idl::ast::{ASTUnit, SourcedWhole}; use crate::project::ir::context::{Origin, ProjectContext}; -use crate::project::ir::frozen::FrozenWhole; +use crate::project::ir::frozen::FrozenUnit; use crate::project::ir::compiler::Compile; // External Uses +use eyre::{anyhow, Result}; #[allow(unused)] -pub struct Interpreter { - context: ProjectContext +pub struct Interpreter<'a> { + context: ProjectContext<'a> } #[allow(unused)] -impl Compile for Interpreter { - type Output = FrozenWhole; +impl<'a> Compile for Interpreter<'a> { + type Output = Result<(RefCell>, Vec)>; fn from_ast(ast: Vec) -> Self::Output { todo!() @@ -32,8 +33,10 @@ impl Compile for Interpreter { fn from_sourced_whole(sourced: SourcedWhole) -> Self::Output { let context = ProjectContext::with_config(sourced); + let frozen = interpret::interpret_context(&context) + .map_err(|e| anyhow!("{:?}", e))?; - interpret::interpret_context(context).unwrap() + Ok((RefCell::new(context), frozen)) } fn from_source(source: &str) -> Self::Output { @@ -47,11 +50,13 @@ impl Compile for Interpreter { } fn from_origin(origin: &Path) -> Self::Output { - let sourced = project::idl::parser_new::from_path(&origin).unwrap(); + let sourced = parser_new::from_path(&origin).unwrap(); let context = ProjectContext::with_config_origin( Origin::Disk(origin.to_path_buf()), sourced ); + let frozen = interpret::interpret_context(&context) + .map_err(|e| anyhow!("{:?}", e))?; - interpret::interpret_context(context).unwrap() + Ok((RefCell::new(context), frozen)) } } diff --git a/core/src/schema/idl/parser_new.rs b/core/src/schema/idl/parser_new.rs index e9ec72f..8c0feaa 100644 --- a/core/src/schema/idl/parser_new.rs +++ b/core/src/schema/idl/parser_new.rs @@ -5,10 +5,10 @@ use std::sync::Arc; // Local Uses use crate::utils::codemap::{CodeMap, FileMap}; -use crate::schema::idl::ast::unit::{ASTUnit, SourcedWholeRc, SpannedUnit}; +use crate::schema::idl::ast::unit::{ASTUnit, SourcedWhole, SourcedWholeRc, SpannedUnit}; // External Uses -use eyre::{bail, Result}; +use eyre::Result; use pest::iterators::Pair; use pest::Parser; @@ -18,7 +18,11 @@ use pest::Parser; pub struct SchemaParser; -pub fn from_path(path: &Path) -> Result { +#[allow(unused)] +pub fn from_path(path: &Path) -> Result { + todo!(); + + /* if !path.exists() { bail!("Path doesn't exist: {:?}", path) } let source = std::fs::read_to_string(path).unwrap(); @@ -28,6 +32,7 @@ pub fn from_path(path: &Path) -> Result { ); sourced_whole + */ } pub fn parse_source(source: String, name: String) -> Result { diff --git a/core/src/schema/ir/compiler/interpreted/interpreter.rs b/core/src/schema/ir/compiler/interpreted/interpreter.rs index bf8240c..0d58899 100644 --- a/core/src/schema/ir/compiler/interpreted/interpreter.rs +++ b/core/src/schema/ir/compiler/interpreted/interpreter.rs @@ -1,6 +1,5 @@ // Standard Uses -use std::cell::{RefCell, RefMut}; -use std::rc::Rc; +use std::cell::RefMut; // Local Uses use crate::schema::idl::ast::unit::{ASTUnit, SpannedUnit}; @@ -16,14 +15,13 @@ use crate::report::ReportDetails; #[allow(unused)] -pub fn interpret_context( - schema_context: &Rc>, project_context: &RefMut +pub fn interpret_context<'a>( + schema_context: &'a mut SchemaContext<'a>, project_context: &RefMut ) -> Result<(), ReportDetails> { let mut interpreted: Vec = vec![]; - let mut context = Some(schema_context.borrow()); - for i in 0..context.as_ref().unwrap().schema.1.len() { - let spanned_unit = &context.unwrap().schema.1[i]; + for i in 0..schema_context.schema.1.len() { + let spanned_unit = &schema_context.schema.1[i]; use crate::schema::idl::ast::unit::ASTUnit::*; match &spanned_unit.1 { @@ -47,13 +45,10 @@ pub fn interpret_context( }) }; - context = None; - let mut ctx_mut = schema_context.borrow_mut(); - - if let Some(name) = &ctx_mut.compile_state.namespace { + if let Some(name) = &schema_context.compile_state.borrow_mut().namespace { panic!("Namespace {} was already previously set", name) } else { - ctx_mut.compile_state.namespace = Some(name) + schema_context.compile_state.borrow_mut().namespace = Some(name) } } Docstring {..} => { @@ -92,8 +87,6 @@ pub fn interpret_context( Validator { .. } => {} Field { .. } => {} } - - context = Some(schema_context.borrow()); } // Ok(context.unwrap().compile_state.to_frozen()) @@ -155,11 +148,13 @@ pub fn interpret_context( } #[allow(unused)] -pub fn interpret_node(context: &SchemaContext, node: &ASTUnit) +pub fn interpret_node(schema_context: &SchemaContext, node: &ASTUnit) -> Result> { - let schema_ctx = context.project_context.clone().unwrap(); - let project_ctx = context.project_context.clone().unwrap(); + let Some(project_ctx) = schema_context.project_context else { + panic!() + }; + let project_ctx = project_ctx.borrow_mut(); use crate::schema::idl::ast::unit::ASTUnit::*; match node { @@ -188,7 +183,7 @@ pub fn interpret_node(context: &SchemaContext, node: &ASTUnit) */ } Import(_, i) => { - let relative_unit = project_ctx.borrow().find_schema_by_import(&i); + let relative_unit = project_ctx.find_schema_by_import(&i); /* if relative_unit.is_none() { diff --git a/core/src/schema/ir/compiler/interpreted/primitive.rs b/core/src/schema/ir/compiler/interpreted/primitive.rs index 8354c8d..291d2ba 100644 --- a/core/src/schema/ir/compiler/interpreted/primitive.rs +++ b/core/src/schema/ir/compiler/interpreted/primitive.rs @@ -158,6 +158,7 @@ fn to_kind_only(kind: &(Span, String)) -> KindValue { } } +#[allow(unused)] fn to_primitive( schema_context: &Rc>, kind: &(Span, String), value: String diff --git a/core/src/schema/ir/compiler/interpreter/meta_stage.rs b/core/src/schema/ir/compiler/interpreter/meta_stage.rs index 125bb94..1e928bd 100644 --- a/core/src/schema/ir/compiler/interpreter/meta_stage.rs +++ b/core/src/schema/ir/compiler/interpreter/meta_stage.rs @@ -1,31 +1,29 @@ // Standard Uses -use std::cell::{RefCell, RefMut}; -use std::rc::Rc; +use std::cell::RefCell; // Crate Uses use crate::report::ReportDetails; use crate::schema::ir::compiler::report::CompileError; use crate::schema::ir::context::SchemaContext; -use crate::project::ir::context::ProjectContext; -use crate::schema::ir::compiler::interpreter::semi_frozen::SemiFrozenUnit; // External Uses -pub fn compile_schema_metadata( - schema_context: &Rc>, project_context: &RefMut +pub fn compile_schema_metadata<'a>( + schema_context: &'a RefCell>, ) -> Result<(), ReportDetails> { - let mut context = Some(RefCell::borrow(&schema_context)); + let schema_ctx = schema_context.borrow(); + let project_ctx = schema_ctx.project_context.unwrap().borrow(); - for i in 0..context.as_ref().unwrap().schema.1.len() { - let spanned_unit = &context.as_ref().unwrap().schema.1[i]; + for i in 0..schema_ctx.schema.1.len() { + let spanned_unit = &schema_ctx.schema.1[i]; use crate::schema::idl::ast::unit::ASTUnit::*; match &spanned_unit.1 { Namespace(_, n) => { + let name = n.clone(); - let Some(_) - = project_context.find_schema_by_import(&n) else + let Some(_) = project_ctx.find_schema_by_import(&n) else { return Err(ReportDetails { // kind: "Namespace".to_string(), @@ -42,15 +40,11 @@ pub fn compile_schema_metadata( }) }; - context = None; - let mut ctx_mut = schema_context.borrow_mut(); - - if let Some(name) = &ctx_mut.compile_state.namespace { + if let Some(name) = &schema_ctx.compile_state.borrow_mut().namespace { panic!("Namespace {} was already previously set", name) } else { - ctx_mut.compile_state.namespace = Some(name) + schema_ctx.compile_state.borrow_mut().namespace = Some(name) } - drop(ctx_mut); } Docstring {..} => { todo!() @@ -64,19 +58,14 @@ pub fn compile_schema_metadata( */ } // Docstring { .. } => {} + #[allow(unused)] Constant { name, ..} => { - let name = name.clone(); - - context = None; - - let mut ctx_mut = schema_context.borrow_mut(); - let spanned_unit = &schema_context.borrow().schema.1[i]; - let su = Rc::clone(&spanned_unit); - ctx_mut.compile_state.consts.entry(su).or_insert( + /* + schema_ctx.compile_state.borrow_mut().consts + .entry(&spanned_unit).or_insert( SemiFrozenUnit::Constant { name: name.clone() } ); - - context = Some(RefCell::borrow(&schema_context)); + */ } Property { .. } => {} Parameter { .. } => {} @@ -92,8 +81,6 @@ pub fn compile_schema_metadata( Validator { .. } => {} Field { .. } => {} } - - context = Some(RefCell::borrow(&schema_context)); } Ok(()) diff --git a/core/src/schema/ir/compiler/interpreter/object_stage.rs b/core/src/schema/ir/compiler/interpreter/object_stage.rs index e3c757f..80ee862 100644 --- a/core/src/schema/ir/compiler/interpreter/object_stage.rs +++ b/core/src/schema/ir/compiler/interpreter/object_stage.rs @@ -10,6 +10,7 @@ use crate::schema::ir::context::SchemaContext; // External Uses +#[allow(unused)] pub fn compile_schema_metadata(schema_context: &Rc> ) -> Result<(), ReportDetails> { diff --git a/core/src/schema/ir/compiler/interpreter/semi_frozen.rs b/core/src/schema/ir/compiler/interpreter/semi_frozen.rs index 1b89881..f632a74 100644 --- a/core/src/schema/ir/compiler/interpreter/semi_frozen.rs +++ b/core/src/schema/ir/compiler/interpreter/semi_frozen.rs @@ -6,6 +6,7 @@ use crate::utils::codemap::Span; // External Uses +#[derive(Clone)] pub enum SemiFrozenUnit { Constant { name: (Span, String) diff --git a/core/src/schema/ir/context.rs b/core/src/schema/ir/context.rs index 62f7d66..b4e2429 100644 --- a/core/src/schema/ir/context.rs +++ b/core/src/schema/ir/context.rs @@ -1,24 +1,22 @@ -// Standard Uses -use std::rc::Rc; use std::cell::RefCell; use std::collections::HashMap; // Local Uses use crate::project::ir::context::ProjectContext; -use crate::schema::idl::ast::unit::{SourcedWholeRc, SpannedUnit}; +use crate::schema::idl::ast::unit::{SourcedWhole, SpannedUnit}; use crate::schema::ir::compiler::interpreter::semi_frozen::SemiFrozenUnit; use crate::schema::ir::frozen::unit::FrozenUnit; // External Uses -#[derive(Default)] -pub struct CompileState { +#[derive(Clone, Default)] +pub struct CompileState<'a> { pub namespace: Option, - pub consts: HashMap, SemiFrozenUnit> + pub consts: HashMap<&'a SpannedUnit, SemiFrozenUnit> } -impl CompileState { +impl<'a> CompileState<'_> { pub(crate) fn to_frozen(&self) -> Vec { let mut interpreted = vec![]; @@ -28,16 +26,18 @@ impl CompileState { } } -pub struct SchemaContext { - pub schema: SourcedWholeRc, +pub struct SchemaContext<'a> { + pub schema: SourcedWhole, pub frozen_schema: Option>, - pub project_context: Option>>, - pub compile_state: CompileState + pub project_context: Option<&'a RefCell>>, + // pub project_context: Option<&'a mut ProjectContext<'a>>, + pub compile_state: RefCell> + // pub compile_state: RefCell } #[allow(unused)] -impl SchemaContext { - pub fn with_main(schema: SourcedWholeRc) -> Self{ +impl<'a> SchemaContext<'a> { + pub fn with_main(schema: SourcedWhole) -> Self{ Self { schema, frozen_schema: None, @@ -47,7 +47,7 @@ impl SchemaContext { } pub fn with_project_and_main( - schema: SourcedWholeRc, project: Rc> + schema: SourcedWhole, project: &'a RefCell> ) -> Self { Self { schema, @@ -57,7 +57,7 @@ impl SchemaContext { } } - pub fn with_main_no_std(schema: SourcedWholeRc) -> Self{ + pub fn with_main_no_std(schema: SourcedWhole) -> Self{ Self { schema, frozen_schema: None, diff --git a/core/src/schema/ir/frozen/unit.rs b/core/src/schema/ir/frozen/unit.rs index 238becd..6eadfd5 100644 --- a/core/src/schema/ir/frozen/unit.rs +++ b/core/src/schema/ir/frozen/unit.rs @@ -7,9 +7,10 @@ use crate::schema::ir::compiler::interpreted::primitive::KindValue; // External Uses -pub type FrozenWhole = (SchemaContext, Vec); +pub type FrozenWhole<'a> = (SchemaContext<'a>, Vec); -#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)] +#[derive(Deserialize, Serialize)] +#[derive(Debug, Eq, PartialEq)] pub enum FrozenUnit { // TODO: Are Tags really necessary anymore since we hash Frozen Units by blob, trees and commits? // Tag(String), diff --git a/core/tests/package/test/health.ids b/core/tests/package/test/health.ids index beb7bfd..dac0fbb 100644 --- a/core/tests/package/test/health.ids +++ b/core/tests/package/test/health.ids @@ -9,5 +9,6 @@ struct Capabilities { @provider=Any protocol HealthCheck { function alive() -> bool + function capabilities() -> Capabilities }