@@ -21,239 +21,8 @@ pub enum Direction {
2121 Export ,
2222}
2323
24- // #[derive(Default)]
25- // pub struct Types {
26- // type_info: HashMap<TypeId, TypeInfo>,
27- // }
28-
29- // #[derive(Default, Clone, Copy, Debug)]
30- // pub struct TypeInfo {
31- // /// Whether or not this type is ever used (transitively) within the
32- // /// parameter of an imported function.
33- // ///
34- // /// This means that it's used in a context where ownership isn't
35- // /// relinquished.
36- // pub borrowed: bool,
37-
38- // /// Whether or not this type is ever used (transitively) within the
39- // /// parameter or result of an export, or the result of an import.
40- // ///
41- // /// This means that it's used in a context where ownership is required and
42- // /// memory management is necessary.
43- // pub owned: bool,
44-
45- // /// Whether or not this type is ever used (transitively) within the
46- // /// error case in the result of a function.
47- // pub error: bool,
48-
49- // /// Whether or not this type (transitively) has a list (or string).
50- // pub has_list: bool,
51-
52- // /// Whether or not this type (transitively) has a resource (or handle).
53- // pub has_resource: bool,
54-
55- // /// Whether or not this type (transitively) has a borrow handle.
56- // pub has_borrow_handle: bool,
57-
58- // /// Whether or not this type (transitively) has an own handle.
59- // pub has_own_handle: bool,
60- // }
61-
62- // impl std::ops::BitOrAssign for TypeInfo {
63- // fn bitor_assign(&mut self, rhs: Self) {
64- // self.borrowed |= rhs.borrowed;
65- // self.owned |= rhs.owned;
66- // self.error |= rhs.error;
67- // self.has_list |= rhs.has_list;
68- // self.has_resource |= rhs.has_resource;
69- // self.has_borrow_handle |= rhs.has_borrow_handle;
70- // self.has_own_handle |= rhs.has_own_handle;
71- // }
72- // }
73-
74- // impl TypeInfo {
75- // pub fn is_clone(&self) -> bool {
76- // !self.has_resource
77- // }
78- // pub fn is_copy(&self) -> bool {
79- // !self.has_list && !self.has_resource
80- // }
81- // }
82-
83- // impl Types {
84- // pub fn analyze(&mut self, resolve: &Resolve) {
85- // for (t, _) in resolve.types.iter() {
86- // self.type_id_info(resolve, t);
87- // }
88- // for (_, world) in resolve.worlds.iter() {
89- // for (import, (_, item)) in world
90- // .imports
91- // .iter()
92- // .map(|i| (true, i))
93- // .chain(world.exports.iter().map(|i| (false, i)))
94- // {
95- // match item {
96- // WorldItem::Function(f) => {
97- // self.type_info_func(resolve, f, import);
98- // }
99- // WorldItem::Interface(id) => {
100- // for (_, f) in resolve.interfaces[*id].functions.iter() {
101- // self.type_info_func(resolve, f, import);
102- // }
103- // }
104- // WorldItem::Type(_) => {}
105- // }
106- // }
107- // }
108- // }
109-
110- // fn type_info_func(&mut self, resolve: &Resolve, func: &Function, import: bool) {
111- // let mut live = LiveTypes::default();
112- // for (_, ty) in func.params.iter() {
113- // self.type_info(resolve, ty);
114- // live.add_type(resolve, ty);
115- // }
116- // for id in live.iter() {
117- // if resolve.types[id].name.is_some() {
118- // let info = self.type_info.get_mut(&id).unwrap();
119- // if import {
120- // info.borrowed = true;
121- // } else {
122- // info.owned = true;
123- // }
124- // }
125- // }
126- // let mut live = LiveTypes::default();
127- // for ty in func.results.iter_types() {
128- // self.type_info(resolve, ty);
129- // live.add_type(resolve, ty);
130- // }
131- // for id in live.iter() {
132- // if resolve.types[id].name.is_some() {
133- // self.type_info.get_mut(&id).unwrap().owned = true;
134- // }
135- // }
136-
137- // for ty in func.results.iter_types() {
138- // let id = match ty {
139- // Type::Id(id) => *id,
140- // _ => continue,
141- // };
142- // let err = match &resolve.types[id].kind {
143- // TypeDefKind::Result(Result_ { err, .. }) => err,
144- // _ => continue,
145- // };
146- // if let Some(Type::Id(id)) = err {
147- // // When an interface `use`s a type from another interface, it creates a new typeid
148- // // referring to the definition typeid. Chase any chain of references down to the
149- // // typeid of the definition.
150- // fn resolve_type_definition_id(resolve: &Resolve, mut id: TypeId) -> TypeId {
151- // loop {
152- // match resolve.types[id].kind {
153- // TypeDefKind::Type(Type::Id(def_id)) => id = def_id,
154- // _ => return id,
155- // }
156- // }
157- // }
158- // let id = resolve_type_definition_id(resolve, *id);
159- // self.type_info.get_mut(&id).unwrap().error = true;
160- // }
161- // }
162- // }
163-
164- // pub fn get(&self, id: TypeId) -> TypeInfo {
165- // self.type_info[&id]
166- // }
167-
168- // pub fn type_id_info(&mut self, resolve: &Resolve, ty: TypeId) -> TypeInfo {
169- // if let Some(info) = self.type_info.get(&ty) {
170- // return *info;
171- // }
172- // let mut info = TypeInfo::default();
173- // match &resolve.types[ty].kind {
174- // TypeDefKind::Record(r) => {
175- // for field in r.fields.iter() {
176- // info |= self.type_info(resolve, &field.ty);
177- // }
178- // }
179- // TypeDefKind::Resource => {
180- // info.has_resource = true;
181- // }
182- // TypeDefKind::Handle(handle) => {
183- // match handle {
184- // Handle::Borrow(_) => info.has_borrow_handle = true,
185- // Handle::Own(_) => info.has_own_handle = true,
186- // }
187- // info.has_resource = true;
188- // }
189- // TypeDefKind::Tuple(t) => {
190- // for ty in t.types.iter() {
191- // info |= self.type_info(resolve, ty);
192- // }
193- // }
194- // TypeDefKind::Flags(_) => {}
195- // TypeDefKind::Enum(_) => {}
196- // TypeDefKind::Variant(v) => {
197- // for case in v.cases.iter() {
198- // info |= self.optional_type_info(resolve, case.ty.as_ref());
199- // }
200- // }
201- // TypeDefKind::List(ty) => {
202- // info = self.type_info(resolve, ty);
203- // info.has_list = true;
204- // }
205- // TypeDefKind::Type(ty) => {
206- // info = self.type_info(resolve, ty);
207- // }
208- // TypeDefKind::Option(ty) => {
209- // info = self.type_info(resolve, ty);
210- // }
211- // TypeDefKind::Result(r) => {
212- // info = self.optional_type_info(resolve, r.ok.as_ref());
213- // info |= self.optional_type_info(resolve, r.err.as_ref());
214- // }
215- // TypeDefKind::Future(_) | TypeDefKind::Stream(_) | TypeDefKind::Error => {}
216- // TypeDefKind::Unknown => unreachable!(),
217- // }
218- // let prev = self.type_info.insert(ty, info);
219- // assert!(prev.is_none());
220- // info
221- // }
222-
223- // pub fn type_info(&mut self, resolve: &Resolve, ty: &Type) -> TypeInfo {
224- // let mut info = TypeInfo::default();
225- // match ty {
226- // Type::String => info.has_list = true,
227- // Type::Id(id) => return self.type_id_info(resolve, *id),
228- // _ => {}
229- // }
230- // info
231- // }
232-
233- // fn optional_type_info(&mut self, resolve: &Resolve, ty: Option<&Type>) -> TypeInfo {
234- // match ty {
235- // Some(ty) => self.type_info(resolve, ty),
236- // None => TypeInfo::default(),
237- // }
238- // }
239- // }
240-
24124pub trait WorldGenerator {
24225 fn generate ( & mut self , resolve : & Resolve , id : WorldId , files : & mut Files ) -> Result < ( ) > {
243- // TODO: Should we refine this test to inspect only types reachable from
244- // the specified world?
245- if !cfg ! ( feature = "async" )
246- && resolve
247- . types
248- . iter ( )
249- . any ( |( _, ty) | matches ! ( ty. kind, TypeDefKind :: Future ( _) | TypeDefKind :: Stream ( _) ) )
250- {
251- anyhow:: bail!(
252- "must enable `async` feature when using WIT files \
253- containing future, stream, or error types"
254- ) ;
255- }
256-
25726 let world = & resolve. worlds [ id] ;
25827 self . preprocess ( resolve, id) ;
25928
0 commit comments