Skip to content

Commit f509f5e

Browse files
committed
address comments
1 parent cbd6f44 commit f509f5e

File tree

8 files changed

+539
-338
lines changed

8 files changed

+539
-338
lines changed

src/metagen/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub mod shared;
3131

3232
mod fdk_py;
3333
mod fdk_rs;
34-
// mod fdk_substantial;
34+
mod fdk_substantial;
3535
mod fdk_ts;
3636

3737
mod client_py;
@@ -156,16 +156,16 @@ impl GeneratorRunner {
156156
},
157157
},
158158
),
159-
// (
160-
// "fdk_substantial".to_string(),
161-
// GeneratorRunner {
162-
// op: |workspace_path: &Path, val| {
163-
// let config = fdk_substantial::FdkSubstantialGenConfig::from_json(val, workspace_path)?;
164-
// let generator = fdk_substantial::Generator::new(config)?;
165-
// Ok(Box::new(generator))
166-
// },
167-
// },
168-
// ),
159+
(
160+
"fdk_substantial".to_string(),
161+
GeneratorRunner {
162+
op: |workspace_path: &Path, val| {
163+
let config = fdk_substantial::FdkSubstantialGenConfig::from_json(val, workspace_path)?;
164+
let generator = fdk_substantial::Generator::new(config)?;
165+
Ok(Box::new(generator))
166+
},
167+
},
168+
),
169169
(
170170
"fdk_ts".to_string(),
171171
GeneratorRunner {

src/typegraph/graph/src/conv/map.rs

Lines changed: 95 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,44 @@ impl<K: DupKey> ValueType<K> {
5656
pub fn is_empty(&self) -> bool {
5757
self.default.is_none() && self.variants.is_empty()
5858
}
59+
60+
fn extend(
61+
&mut self,
62+
node: Type,
63+
rpath: RelativePath,
64+
dup_key_gen: &impl DuplicationKeyGenerator<Key = K>,
65+
) -> Result<()> {
66+
let rpath: ValueTypePath = rpath
67+
.try_into()
68+
.map_err(|e| eyre!("relative path is not a value type: {:?}", e))?;
69+
let dkey = dup_key_gen.gen_from_type(&node);
70+
let key = node.key();
71+
if key.1 == 0 {
72+
debug_assert!(dkey.is_default());
73+
if self.default.is_some() {
74+
bail!("duplicate default value type: {:?}", key);
75+
}
76+
self.default = Some(MapValueItem {
77+
ty: node.clone(),
78+
relative_paths: std::iter::once(rpath).collect(),
79+
});
80+
} else {
81+
debug_assert!(!dkey.is_default());
82+
let index = key.1 - 1;
83+
if index != self.variants.len() as u32 {
84+
bail!("unexpected ordinal number for type registration: {:?}", key);
85+
}
86+
self.variants.insert(
87+
dkey,
88+
MapValueItem {
89+
ty: node.clone(),
90+
relative_paths: std::iter::once(rpath).collect(),
91+
},
92+
);
93+
}
94+
95+
Ok(())
96+
}
5997
}
6098

6199
#[derive(Debug)]
@@ -73,6 +111,61 @@ impl<K: DupKey> MapItem<K> {
73111
_ => None,
74112
}
75113
}
114+
115+
fn new(
116+
ty: &Type,
117+
rpath: RelativePath,
118+
dup_key_gen: &impl DuplicationKeyGenerator<Key = K>,
119+
) -> Result<Self> {
120+
Ok(match &rpath {
121+
RelativePath::Function(_) => MapItem::Function(ty.assert_func()?.clone()),
122+
RelativePath::NsObject(path) => {
123+
MapItem::Namespace(ty.assert_object()?.clone(), path.clone())
124+
}
125+
RelativePath::Input(_) => {
126+
let dkey = dup_key_gen.gen_from_type(ty);
127+
if dkey.is_default() || !ty.is_composite() {
128+
MapItem::Value(ValueType {
129+
default: Some(MapValueItem {
130+
ty: ty.clone(),
131+
relative_paths: std::iter::once(rpath.clone().try_into().map_err(
132+
|e| eyre!("relative path is not a value type: {:?}", e),
133+
)?)
134+
.collect(),
135+
}),
136+
variants: Default::default(),
137+
})
138+
} else {
139+
let variant =
140+
MapValueItem {
141+
ty: ty.clone(),
142+
relative_paths: std::iter::once(rpath.clone().try_into().map_err(
143+
|e| eyre!("relative path is not a value type: {:?}", e),
144+
)?)
145+
.collect(),
146+
};
147+
let variants = std::iter::once((dkey, variant)).collect();
148+
MapItem::Value(ValueType {
149+
default: None,
150+
variants,
151+
})
152+
}
153+
}
154+
RelativePath::Output(_) => MapItem::Value(ValueType {
155+
default: Some(MapValueItem {
156+
ty: ty.clone(),
157+
relative_paths: std::iter::once(
158+
rpath
159+
.clone()
160+
.try_into()
161+
.map_err(|e| eyre!("relative path is not a value type: {:?}", e))?,
162+
)
163+
.collect(),
164+
}),
165+
variants: Default::default(),
166+
}),
167+
})
168+
}
76169
}
77170

78171
#[derive(Debug)]
@@ -127,87 +220,15 @@ impl<G: DuplicationKeyGenerator> ConversionMap<G> {
127220
let key = node.key();
128221
let item = std::mem::replace(&mut self.direct[key.0 as usize], MapItem::Unset);
129222
let item = match item {
130-
MapItem::Unset => match &rpath {
131-
RelativePath::Function(_) => MapItem::Function(node.assert_func()?.clone()),
132-
RelativePath::NsObject(path) => {
133-
MapItem::Namespace(node.assert_object()?.clone(), path.clone())
134-
}
135-
RelativePath::Input(_) => {
136-
let dkey = self.dup_key_gen.gen_from_type(&node);
137-
if dkey.is_default() || !node.is_composite() {
138-
MapItem::Value(ValueType {
139-
default: Some(MapValueItem {
140-
ty: node.clone(),
141-
relative_paths: std::iter::once(rpath.clone().try_into().map_err(
142-
|e| eyre!("relative path is not a value type: {:?}", e),
143-
)?)
144-
.collect(),
145-
}),
146-
variants: Default::default(),
147-
})
148-
} else {
149-
let variant = MapValueItem {
150-
ty: node.clone(),
151-
relative_paths: std::iter::once(rpath.clone().try_into().map_err(
152-
|e| eyre!("relative path is not a value type: {:?}", e),
153-
)?)
154-
.collect(),
155-
};
156-
let variants = std::iter::once((dkey, variant)).collect();
157-
MapItem::Value(ValueType {
158-
default: None,
159-
variants,
160-
})
161-
}
162-
}
163-
RelativePath::Output(_) => {
164-
MapItem::Value(ValueType {
165-
default: Some(MapValueItem {
166-
ty: node.clone(),
167-
relative_paths: std::iter::once(rpath.clone().try_into().map_err(
168-
|e| eyre!("relative path is not a value type: {:?}", e),
169-
)?)
170-
.collect(),
171-
}),
172-
variants: Default::default(),
173-
})
174-
}
175-
},
223+
MapItem::Unset => MapItem::new(&node, rpath.clone(), &self.dup_key_gen)?,
176224
MapItem::Namespace(_, _) => {
177225
bail!("unexpected duplicate namespace type: {:?}", key)
178226
}
179227
MapItem::Function(_) => {
180228
bail!("unexpected duplicate function type: {:?}", key)
181229
}
182230
MapItem::Value(mut value_type) => {
183-
let rpath: ValueTypePath = rpath
184-
.clone()
185-
.try_into()
186-
.map_err(|e| eyre!("relative path is not a value type: {:?}", e))?;
187-
let dkey = self.dup_key_gen.gen_from_type(&node);
188-
if key.1 == 0 {
189-
debug_assert!(dkey.is_default());
190-
if value_type.default.is_some() {
191-
bail!("duplicate default value type: {:?}", key);
192-
}
193-
value_type.default = Some(MapValueItem {
194-
ty: node.clone(),
195-
relative_paths: std::iter::once(rpath).collect(),
196-
});
197-
} else {
198-
debug_assert!(!dkey.is_default());
199-
let index = key.1 - 1;
200-
if index != value_type.variants.len() as u32 {
201-
bail!("unexpected ordinal number for type registration: {:?}", key);
202-
}
203-
value_type.variants.insert(
204-
dkey,
205-
MapValueItem {
206-
ty: node.clone(),
207-
relative_paths: std::iter::once(rpath).collect(),
208-
},
209-
);
210-
}
231+
value_type.extend(node, rpath.clone(), &self.dup_key_gen)?;
211232
MapItem::Value(value_type)
212233
}
213234
};

src/typegraph/graph/src/injection.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
2+
// SPDX-License-Identifier: MPL-2.0
3+
14
use std::{collections::BTreeMap, sync::Arc};
25

36
use tg_schema::EffectType;

src/typegraph/graph/src/naming/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ mod default {
4747
impl NamingEngine for DefaultNamingEngine {
4848
fn name_value_types<K: DupKey>(&mut self, value_type: &ValueType<K>) -> Result<()> {
4949
if value_type.is_empty() {
50+
// the type has not been converted
5051
unreachable!("no registered type");
5152
}
5253
if let Some(item) = value_type.default.as_ref() {

0 commit comments

Comments
 (0)