partway through fixes, macro system needs resdesign
Some checks failed
Rust / build (push) Has been cancelled
Some checks failed
Rust / build (push) Has been cancelled
This commit is contained in:
@@ -21,11 +21,11 @@ use crate::api;
|
||||
use crate::ctx::Ctx;
|
||||
use crate::dealias::{ChildErrorKind, Tree, absolute_path, resolv_glob, walk};
|
||||
use crate::expr::{Expr, ExprFromApiCtx, PathSetBuilder};
|
||||
use crate::parsed::{ItemKind, ParsedMemberKind, ParsedModule};
|
||||
use crate::parsed::{ItemKind, ParsedMemKind, ParsedModule};
|
||||
use crate::system::System;
|
||||
|
||||
pub struct RootData {
|
||||
pub root: Module,
|
||||
pub root: Mod,
|
||||
pub consts: MemoMap<Sym, Expr>,
|
||||
pub ctx: Ctx,
|
||||
}
|
||||
@@ -34,17 +34,13 @@ pub struct Root(pub Rc<RwLock<RootData>>);
|
||||
impl Root {
|
||||
#[must_use]
|
||||
pub fn new(ctx: Ctx) -> Self {
|
||||
Root(Rc::new(RwLock::new(RootData {
|
||||
root: Module::default(),
|
||||
consts: MemoMap::default(),
|
||||
ctx,
|
||||
})))
|
||||
Root(Rc::new(RwLock::new(RootData { root: Mod::default(), consts: MemoMap::default(), ctx })))
|
||||
}
|
||||
#[must_use]
|
||||
pub async fn from_api(api: api::Module, sys: &System) -> Self {
|
||||
let consts = MemoMap::new();
|
||||
let mut tfac = TreeFromApiCtx { consts: &consts, path: iv(&[][..]).await, sys };
|
||||
let root = Module::from_api(api, &mut tfac).await;
|
||||
let root = Mod::from_api(api, &mut tfac).await;
|
||||
Root(Rc::new(RwLock::new(RootData { root, consts, ctx: sys.ctx().clone() })))
|
||||
}
|
||||
pub async fn merge(&self, new: &Root) -> Result<Self, MergeErr> {
|
||||
@@ -71,14 +67,14 @@ impl Root {
|
||||
root: &this.root,
|
||||
ctx: &this.ctx,
|
||||
};
|
||||
let mut module = Module::from_parsed(parsed, pars_prefix.clone(), &mut tfpctx).await;
|
||||
let mut module = Mod::from_parsed(parsed, pars_prefix.clone(), &mut tfpctx).await;
|
||||
for step in pars_prefix.iter().rev() {
|
||||
let kind = OnceCell::from(MemberKind::Module(module));
|
||||
let kind = OnceCell::from(MemKind::Module(module));
|
||||
let members = HashMap::from([(
|
||||
step.clone(),
|
||||
Rc::new(Member { public: true, lazy: RefCell::new(None), kind }),
|
||||
)]);
|
||||
module = Module { imports: HashMap::new(), members }
|
||||
module = Mod { imports: HashMap::new(), members }
|
||||
}
|
||||
let root = (this.root.merge(&module, this.ctx.clone(), &consts).await)
|
||||
.expect("Merge conflict between parsed and existing module");
|
||||
@@ -159,11 +155,11 @@ pub struct ResolvedImport {
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Module {
|
||||
pub struct Mod {
|
||||
pub imports: HashMap<IStr, Result<ResolvedImport, Vec<ResolvedImport>>>,
|
||||
pub members: HashMap<IStr, Rc<Member>>,
|
||||
}
|
||||
impl Module {
|
||||
impl Mod {
|
||||
#[must_use]
|
||||
pub async fn from_api(api: api::Module, ctx: &mut TreeFromApiCtx<'_>) -> Self {
|
||||
let mut members = HashMap::new();
|
||||
@@ -178,11 +174,11 @@ impl Module {
|
||||
let cx = ExprFromApiCtx { ctx: ctx.sys.ctx().clone(), sys: ctx.sys.id() };
|
||||
let expr = Expr::from_api(val, PathSetBuilder::new(), cx).await;
|
||||
ctx.consts.insert(name.clone(), expr);
|
||||
(None, Some(MemberKind::Const))
|
||||
(None, Some(MemKind::Const))
|
||||
},
|
||||
api::MemberKind::Module(m) => {
|
||||
let m = Self::from_api(m, &mut ctx.push(mem_name.clone()).await).boxed_local().await;
|
||||
(None, Some(MemberKind::Module(m)))
|
||||
(None, Some(MemKind::Module(m)))
|
||||
},
|
||||
};
|
||||
members.insert(
|
||||
@@ -305,7 +301,7 @@ impl Module {
|
||||
match &item.kind {
|
||||
ItemKind::Member(mem) => {
|
||||
let path = path.to_vname().suffix([mem.name.clone()]).to_sym().await;
|
||||
let kind = OnceCell::from(MemberKind::from_parsed(&mem.kind, path.clone(), ctx).await);
|
||||
let kind = OnceCell::from(MemKind::from_parsed(&mem.kind, path.clone(), ctx).await);
|
||||
members.insert(
|
||||
mem.name.clone(),
|
||||
Rc::new(Member { kind, lazy: RefCell::default(), public: mem.exported }),
|
||||
@@ -314,14 +310,14 @@ impl Module {
|
||||
ItemKind::Import(_) => (),
|
||||
}
|
||||
}
|
||||
Module { imports, members }
|
||||
Mod { imports, members }
|
||||
}
|
||||
pub async fn merge(
|
||||
&self,
|
||||
other: &Module,
|
||||
other: &Mod,
|
||||
ctx: Ctx,
|
||||
consts: &MemoMap<Sym, Expr>,
|
||||
) -> Result<Module, MergeErr> {
|
||||
) -> Result<Mod, MergeErr> {
|
||||
if !self.imports.is_empty() || !other.imports.is_empty() {
|
||||
return Err(MergeErr { path: VPath::new([]), kind: MergeErrKind::Imports });
|
||||
}
|
||||
@@ -335,7 +331,7 @@ impl Module {
|
||||
return Err(MergeErr { path: VPath::new([]), kind: MergeErrKind::Visibility });
|
||||
}
|
||||
match (own.kind(ctx.clone(), consts).await, mem.kind(ctx.clone(), consts).await) {
|
||||
(MemberKind::Module(own_sub), MemberKind::Module(sub)) => {
|
||||
(MemKind::Module(own_sub), MemKind::Module(sub)) => {
|
||||
match own_sub.merge(sub, ctx.clone(), consts).boxed_local().await {
|
||||
Ok(module) => {
|
||||
members.insert(
|
||||
@@ -343,7 +339,7 @@ impl Module {
|
||||
Rc::new(Member {
|
||||
lazy: RefCell::new(None),
|
||||
public: own.public,
|
||||
kind: OnceCell::from(MemberKind::Module(module)),
|
||||
kind: OnceCell::from(MemKind::Module(module)),
|
||||
}),
|
||||
);
|
||||
},
|
||||
@@ -361,7 +357,7 @@ impl Module {
|
||||
slot.insert(mem.clone());
|
||||
}
|
||||
}
|
||||
Ok(Module { imports: HashMap::new(), members })
|
||||
Ok(Mod { imports: HashMap::new(), members })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,13 +376,13 @@ pub enum MergeErrKind {
|
||||
pub struct FromParsedCtx<'a> {
|
||||
pars_prefix: Sym,
|
||||
pars_root: &'a ParsedModule,
|
||||
root: &'a Module,
|
||||
root: &'a Mod,
|
||||
ctx: &'a Ctx,
|
||||
consts: &'a MemoMap<Sym, Expr>,
|
||||
deferred_consts: &'a mut Vec<(Sym, api::SysId, api::ParsedConstId)>,
|
||||
}
|
||||
|
||||
impl Tree for Module {
|
||||
impl Tree for Mod {
|
||||
type Ctx<'a> = (Ctx, &'a MemoMap<Sym, Expr>);
|
||||
async fn child(
|
||||
&self,
|
||||
@@ -401,8 +397,8 @@ impl Tree for Module {
|
||||
return Err(ChildErrorKind::Private);
|
||||
}
|
||||
match &member.kind(ctx.clone(), consts).await {
|
||||
MemberKind::Module(m) => Ok(m),
|
||||
MemberKind::Const => Err(ChildErrorKind::Constant),
|
||||
MemKind::Module(m) => Ok(m),
|
||||
MemKind::Const => Err(ChildErrorKind::Constant),
|
||||
}
|
||||
}
|
||||
fn children(&self, public_only: bool) -> hashbrown::HashSet<IStr> {
|
||||
@@ -413,11 +409,11 @@ impl Tree for Module {
|
||||
pub struct Member {
|
||||
pub public: bool,
|
||||
pub lazy: RefCell<Option<LazyMemberHandle>>,
|
||||
pub kind: OnceCell<MemberKind>,
|
||||
pub kind: OnceCell<MemKind>,
|
||||
}
|
||||
impl Member {
|
||||
#[must_use]
|
||||
pub async fn kind<'a>(&'a self, ctx: Ctx, consts: &MemoMap<Sym, Expr>) -> &'a MemberKind {
|
||||
pub async fn kind<'a>(&'a self, ctx: Ctx, consts: &MemoMap<Sym, Expr>) -> &'a MemKind {
|
||||
(self.kind.get_or_init(async {
|
||||
let handle = self.lazy.borrow_mut().take().expect("If kind is uninit, lazy must be Some");
|
||||
handle.run(ctx, consts).await
|
||||
@@ -426,20 +422,20 @@ impl Member {
|
||||
}
|
||||
}
|
||||
|
||||
pub enum MemberKind {
|
||||
pub enum MemKind {
|
||||
Const,
|
||||
Module(Module),
|
||||
Module(Mod),
|
||||
}
|
||||
impl MemberKind {
|
||||
impl MemKind {
|
||||
#[must_use]
|
||||
async fn from_parsed(parsed: &ParsedMemberKind, path: Sym, ctx: &mut FromParsedCtx<'_>) -> Self {
|
||||
async fn from_parsed(parsed: &ParsedMemKind, path: Sym, ctx: &mut FromParsedCtx<'_>) -> Self {
|
||||
match parsed {
|
||||
ParsedMemberKind::Const(id, sys) => {
|
||||
ParsedMemKind::Const(id, sys) => {
|
||||
ctx.deferred_consts.push((path, sys.id(), *id));
|
||||
MemberKind::Const
|
||||
MemKind::Const
|
||||
},
|
||||
ParsedMemberKind::Mod(m) =>
|
||||
MemberKind::Module(Module::from_parsed(m, path, ctx).boxed_local().await),
|
||||
ParsedMemKind::Mod(m) =>
|
||||
MemKind::Module(Mod::from_parsed(m, path, ctx).boxed_local().await),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -452,7 +448,7 @@ pub struct LazyMemberHandle {
|
||||
}
|
||||
impl LazyMemberHandle {
|
||||
#[must_use]
|
||||
pub async fn run(mut self, ctx: Ctx, consts: &MemoMap<Sym, Expr>) -> MemberKind {
|
||||
pub async fn run(mut self, ctx: Ctx, consts: &MemoMap<Sym, Expr>) -> MemKind {
|
||||
let sys = ctx.system_inst(self.sys).await.expect("Missing system for lazy member");
|
||||
match sys.get_tree(self.id).await {
|
||||
api::MemberKind::Const(c) => {
|
||||
@@ -460,12 +456,12 @@ impl LazyMemberHandle {
|
||||
let expr = Expr::from_api(c, PathSetBuilder::new(), ctx).await;
|
||||
let (.., path) = self.destructure();
|
||||
consts.insert(path, expr);
|
||||
MemberKind::Const
|
||||
MemKind::Const
|
||||
},
|
||||
api::MemberKind::Module(m) => {
|
||||
let (.., path) = self.destructure();
|
||||
MemberKind::Module(
|
||||
Module::from_api(m, &mut TreeFromApiCtx { sys: &sys, consts, path: path.tok() }).await,
|
||||
MemKind::Module(
|
||||
Mod::from_api(m, &mut TreeFromApiCtx { sys: &sys, consts, path: path.tok() }).await,
|
||||
)
|
||||
},
|
||||
api::MemberKind::Lazy(id) => {
|
||||
|
||||
Reference in New Issue
Block a user