|
1 | 1 | use crate::graph::{ |
2 | | - type_desc, CompositionGraph, EncodeOptions, ExportIndex, ImportIndex, InstanceId, |
| 2 | + CompositionGraph, EncodeOptions, ExportIndex, ImportIndex, InstanceId, type_desc, |
3 | 3 | }; |
4 | | -use anyhow::{anyhow, bail, Result}; |
| 4 | +use anyhow::{Result, anyhow, bail}; |
5 | 5 | use indexmap::{IndexMap, IndexSet}; |
6 | 6 | use petgraph::EdgeDirection; |
7 | 7 | use smallvec::SmallVec; |
8 | | -use std::collections::{hash_map::Entry, HashMap}; |
| 8 | +use std::collections::{HashMap, hash_map::Entry}; |
9 | 9 | use std::mem; |
10 | 10 | use wasm_encoder::*; |
11 | 11 | use wasmparser::{ |
| 12 | + ComponentExternalKind, |
12 | 13 | component_types::{ |
13 | 14 | self as ct, AnyTypeId, ComponentAnyTypeId, ComponentCoreModuleTypeId, ComponentCoreTypeId, |
14 | 15 | ComponentDefinedType, ComponentDefinedTypeId, ComponentEntityType, ComponentFuncTypeId, |
15 | 16 | ComponentInstanceTypeId, ComponentTypeId, RecordType, Remap, Remapping, ResourceId, |
16 | 17 | SubtypeCx, TupleType, VariantType, |
17 | 18 | }, |
18 | 19 | names::KebabString, |
19 | | - types, ComponentExternalKind, |
| 20 | + types, |
20 | 21 | }; |
21 | 22 |
|
22 | 23 | fn type_ref_to_export_kind(ty: wasmparser::ComponentTypeRef) -> ComponentExportKind { |
@@ -605,17 +606,17 @@ impl<'a> TypeEncoder<'a> { |
605 | 606 | return match id { |
606 | 607 | AnyTypeId::Core(ComponentCoreTypeId::Sub(_)) => unreachable!(), |
607 | 608 | AnyTypeId::Core(ComponentCoreTypeId::Module(id)) => self.module_type(state, id), |
608 | | - AnyTypeId::Component(id) => { |
609 | | - match id { |
610 | | - ComponentAnyTypeId::Resource(r) => { |
611 | | - unreachable!("should have been handled in `TypeEncoder::component_entity_type`: {r:?}") |
612 | | - } |
613 | | - ComponentAnyTypeId::Defined(id) => self.defined_type(state, id), |
614 | | - ComponentAnyTypeId::Func(id) => self.component_func_type(state, id), |
615 | | - ComponentAnyTypeId::Instance(id) => self.component_instance_type(state, id), |
616 | | - ComponentAnyTypeId::Component(id) => self.component_type(state, id), |
| 609 | + AnyTypeId::Component(id) => match id { |
| 610 | + ComponentAnyTypeId::Resource(r) => { |
| 611 | + unreachable!( |
| 612 | + "should have been handled in `TypeEncoder::component_entity_type`: {r:?}" |
| 613 | + ) |
617 | 614 | } |
618 | | - } |
| 615 | + ComponentAnyTypeId::Defined(id) => self.defined_type(state, id), |
| 616 | + ComponentAnyTypeId::Func(id) => self.component_func_type(state, id), |
| 617 | + ComponentAnyTypeId::Instance(id) => self.component_instance_type(state, id), |
| 618 | + ComponentAnyTypeId::Component(id) => self.component_type(state, id), |
| 619 | + }, |
619 | 620 | }; |
620 | 621 | } |
621 | 622 |
|
@@ -1017,13 +1018,14 @@ impl<'a> ImportMap<'a> { |
1017 | 1018 | .values() |
1018 | 1019 | .filter(|e| !e.instances.is_empty()) |
1019 | 1020 | { |
1020 | | - assert!(self |
1021 | | - .0 |
1022 | | - .insert( |
1023 | | - &entry.component.name, |
1024 | | - ImportMapEntry::Component(&entry.component), |
1025 | | - ) |
1026 | | - .is_none()); |
| 1021 | + assert!( |
| 1022 | + self.0 |
| 1023 | + .insert( |
| 1024 | + &entry.component.name, |
| 1025 | + ImportMapEntry::Component(&entry.component), |
| 1026 | + ) |
| 1027 | + .is_none() |
| 1028 | + ); |
1027 | 1029 | } |
1028 | 1030 | } |
1029 | 1031 |
|
@@ -1087,10 +1089,10 @@ impl<'a> ImportMap<'a> { |
1087 | 1089 | indexmap::map::Entry::Occupied(mut e) => match e.get_mut() { |
1088 | 1090 | ImportMapEntry::Component(_) => { |
1089 | 1091 | bail!( |
1090 | | - "cannot import {ty} `{name}` for an instantiation argument of component `{cname}` because it conflicts with a component imported with the same name", |
1091 | | - ty = type_desc(ty), |
1092 | | - cname = entry.component.name, |
1093 | | - ); |
| 1092 | + "cannot import {ty} `{name}` for an instantiation argument of component `{cname}` because it conflicts with a component imported with the same name", |
| 1093 | + ty = type_desc(ty), |
| 1094 | + cname = entry.component.name, |
| 1095 | + ); |
1094 | 1096 | } |
1095 | 1097 | ImportMapEntry::Argument(existing) => { |
1096 | 1098 | existing.merge(arg, remapping)?; |
@@ -1410,10 +1412,11 @@ impl<'a> CompositionGraphEncoder<'a> { |
1410 | 1412 | let type_index = self.define_component_type(encoded, component); |
1411 | 1413 | let index = self.import(encoded, name, ComponentTypeRef::Component(type_index)); |
1412 | 1414 |
|
1413 | | - assert!(self |
1414 | | - .encoded_components |
1415 | | - .insert(PtrKey(component), index) |
1416 | | - .is_none()); |
| 1415 | + assert!( |
| 1416 | + self.encoded_components |
| 1417 | + .insert(PtrKey(component), index) |
| 1418 | + .is_none() |
| 1419 | + ); |
1417 | 1420 |
|
1418 | 1421 | index |
1419 | 1422 | } |
@@ -1572,10 +1575,11 @@ impl<'a> CompositionGraphEncoder<'a> { |
1572 | 1575 | .filter(|e| !e.instances.is_empty()) |
1573 | 1576 | { |
1574 | 1577 | let index = self.define_component(encoded, &entry.component); |
1575 | | - assert!(self |
1576 | | - .encoded_components |
1577 | | - .insert(PtrKey(&entry.component), index) |
1578 | | - .is_none()); |
| 1578 | + assert!( |
| 1579 | + self.encoded_components |
| 1580 | + .insert(PtrKey(&entry.component), index) |
| 1581 | + .is_none() |
| 1582 | + ); |
1579 | 1583 | } |
1580 | 1584 | } |
1581 | 1585 |
|
|
0 commit comments