Skip to content

Commit 5a15026

Browse files
committed
more simplification enabled by GeneratorContext::node_parents
1 parent 0b7a999 commit 5a15026

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

capnpc/src/codegen.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,6 @@ fn generate_node(
20382038
method.get_param_brand()?,
20392039
Leaf::Owned,
20402040
&param_scopes.join("::"),
2041-
Some(node_id),
20422041
)?;
20432042

20442043
let result_id = method.get_result_struct_type();
@@ -2061,7 +2060,6 @@ fn generate_node(
20612060
method.get_result_brand()?,
20622061
Leaf::Owned,
20632062
&result_scopes.join("::"),
2064-
Some(node_id),
20652063
)?;
20662064

20672065
dispatch_arms.push(
@@ -2136,15 +2134,8 @@ fn generate_node(
21362134
base_dispatch_arms.push(Line(format!(
21372135
"0x{type_id:x} => {}::dispatch_call_internal(&mut self.server, method_id, params, results),",
21382136
do_branding(
2139-
gen, type_id, brand, Leaf::ServerDispatch, &the_mod, None)?)));
2140-
base_traits.push(do_branding(
2141-
gen,
2142-
type_id,
2143-
brand,
2144-
Leaf::Server,
2145-
&the_mod,
2146-
None,
2147-
)?);
2137+
gen, type_id, brand, Leaf::ServerDispatch, &the_mod)?)));
2138+
base_traits.push(do_branding(gen, type_id, brand, Leaf::Server, &the_mod)?);
21482139
}
21492140
if !extends.is_empty() {
21502141
format!(": {}", base_traits.join(" + "))

capnpc/src/codegen_types.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,13 @@ impl<'a> RustTypeInfo for type_::Reader<'a> {
195195
st.get_brand()?,
196196
module,
197197
&gen.get_qualified_module(st.get_type_id()),
198-
None,
199198
),
200199
type_::Interface(interface) => do_branding(
201200
gen,
202201
interface.get_type_id(),
203202
interface.get_brand()?,
204203
module,
205204
&gen.get_qualified_module(interface.get_type_id()),
206-
None,
207205
),
208206
type_::List(ot1) => {
209207
let element_type = ot1.get_element_type()?;
@@ -345,7 +343,6 @@ pub fn do_branding(
345343
brand: brand::Reader,
346344
leaf: Leaf,
347345
the_mod: &str,
348-
mut parent_scope_id: Option<u64>,
349346
) -> Result<String, Error> {
350347
let scopes = brand.get_scopes()?;
351348
let mut brand_scopes = HashMap::new();
@@ -356,7 +353,7 @@ pub fn do_branding(
356353
let mut current_node_id = node_id;
357354
let mut accumulator: Vec<Vec<String>> = Vec::new();
358355
loop {
359-
let Some(current_node) = gen.node_map.get(&current_node_id) else { break };
356+
let current_node = gen.node_map[&current_node_id];
360357
let params = current_node.get_parameters()?;
361358
let mut arguments: Vec<String> = Vec::new();
362359
match brand_scopes.get(&current_node_id) {
@@ -388,11 +385,10 @@ pub fn do_branding(
388385
},
389386
}
390387
accumulator.push(arguments);
391-
current_node_id = current_node.get_scope_id();
392-
if let (0, Some(id)) = (current_node_id, parent_scope_id) {
393-
current_node_id = id
394-
}
395-
parent_scope_id = None; // Only consider on the first time around.
388+
current_node_id = match gen.node_parents.get(&current_node_id).copied() {
389+
Some(0) | None => break,
390+
Some(id) => id,
391+
};
396392
}
397393

398394
// Now add a lifetime parameter if the leaf has one.

0 commit comments

Comments
 (0)