-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgc_types.rs
More file actions
870 lines (862 loc) · 34.5 KB
/
Copy pathgc_types.rs
File metadata and controls
870 lines (862 loc) · 34.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
//! Deterministic WebAssembly GC type and layout planning.
use wasm_encoder::{
AbstractHeapType, ArrayType, CompositeInnerType, CompositeType, FieldType, FuncType, HeapType,
RefType, StorageType, StructType, SubType, TypeSection, ValType,
};
use crate::{
ast::{EnumDecl, Program},
semantic::SemanticModel,
stdlib::{
DeclaredTypeRef, RuntimeRepresentation, StandardLibrary, StdlibTypeConstructorId,
StdlibTypeId, TypeRef,
},
types::{
ResolvedApplicationType, ResolvedArrayType, ResolvedAsyncType, ResolvedCallableType,
ResolvedIteratorType, ResolvedOptionType, ResolvedRangeType, ResolvedResultType,
ResolvedSetType, TypeId, TypeKind,
},
};
use super::{
GcLayout, Type, array_element_type, async_frame::AsyncFrameLayouts, enum_variant_payload,
managed_snapshot_field_type, option_value_type, reachability, result_value_type, semantic_type,
standard_field_type, struct_field_type, value_type,
};
pub(super) struct EncodedTypes {
pub section: TypeSection,
pub next_type_index: u32,
pub layout: GcLayout,
}
pub(super) struct Inputs<'a> {
pub standard_library: &'a StandardLibrary,
pub program: &'a Program,
pub wasm_ir: &'a crate::wasm_ir::Program,
pub semantics: &'a SemanticModel,
pub async_frames: &'a AsyncFrameLayouts,
pub enums: &'a [EnumDecl],
pub array_types: &'a [ResolvedArrayType],
pub option_types: &'a [ResolvedOptionType],
pub result_types: &'a [ResolvedResultType],
pub async_types: &'a [ResolvedAsyncType],
pub iterator_types: &'a [ResolvedIteratorType],
pub callable_types: &'a [ResolvedCallableType],
pub set_types: &'a [ResolvedSetType],
pub application_types: &'a [ResolvedApplicationType],
pub range_types: &'a [ResolvedRangeType],
pub reachability: &'a reachability::Reachability,
}
pub(super) fn encode(inputs: Inputs<'_>) -> EncodedTypes {
let Inputs {
standard_library,
program,
wasm_ir,
semantics,
async_frames,
enums,
array_types,
option_types,
result_types,
async_types,
iterator_types,
callable_types,
set_types,
application_types,
range_types,
reachability,
} = inputs;
let layout = GcLayout::plan(super::gc_layout::Inputs {
standard_library: standard_library.clone(),
program,
wasm_ir,
enums,
semantics,
arrays: array_types,
options: option_types,
results: result_types,
asyncs: async_types,
iterators: iterator_types,
callables: callable_types,
sets: set_types,
applications: application_types,
ranges: range_types,
async_frames,
reachability,
});
let mut recursive_types = vec![SubType {
is_final: true,
supertype_idx: None,
composite_type: CompositeType {
inner: CompositeInnerType::Struct(StructType {
fields: semantics
.state_storage_fields()
.iter()
.map(|field| FieldType {
element_type: layout.storage_type(value_type(*field, semantics)),
mutable: true,
})
.collect(),
}),
shared: false,
descriptor: None,
describes: None,
},
}];
for declaration in standard_library.all_types() {
let inner = match declaration.representation {
RuntimeRepresentation::Scalar { .. } => continue,
RuntimeRepresentation::GcArray {
element, mutable, ..
} => CompositeInnerType::Array(ArrayType(FieldType {
element_type: layout
.storage_type(Type::from_declared(DeclaredTypeRef::Core(element))),
mutable,
})),
RuntimeRepresentation::GcStruct { .. } => CompositeInnerType::Struct(StructType {
fields: standard_library
.fields_of(declaration.id)
.map(|field| FieldType {
element_type: layout.storage_type(standard_field_type(field.id, semantics)),
mutable: false,
})
.collect(),
}),
RuntimeRepresentation::Enum { .. } => CompositeInnerType::Struct(StructType {
fields: std::iter::once(FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: false,
})
.chain(
standard_library
.variants_of(declaration.id)
.map(|_| FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: false,
}),
)
.collect(),
}),
};
recursive_types.push(SubType {
is_final: true,
supertype_idx: None,
composite_type: CompositeType {
inner,
shared: false,
descriptor: None,
describes: None,
},
});
}
let mut fields = Vec::with_capacity(
1 + async_frames
.actions()
.map(|(_, layout)| layout.types.len())
.sum::<usize>(),
);
fields.push(FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: true,
});
for (_, frame_layout) in async_frames.actions() {
debug_assert!(
frame_layout.types.iter().all(|ty| *ty != Type::Never),
"async frame contains a `Never` field: {frame_layout:?}"
);
fields.extend(frame_layout.types.iter().enumerate().map(|(position, ty)| {
let field = frame_layout.base_fields + position as u32;
FieldType {
element_type: if frame_layout.capture_cell_fields.contains(&field) {
layout.capture_cell_storage_type(*ty)
} else {
layout.frame_storage_type(*ty)
},
mutable: true,
}
}));
}
recursive_types.push(SubType {
is_final: true,
supertype_idx: None,
composite_type: CompositeType {
inner: CompositeInnerType::Struct(StructType {
fields: fields.into(),
}),
shared: false,
descriptor: None,
describes: None,
},
});
for ty in layout.dynamic_types() {
let (inner, is_final, supertype_idx) = match ty {
Type::Struct(id) => {
let structure = program
.structs
.iter()
.find(|structure| structure.id == id)
.expect("reachable struct layouts have declarations");
(
CompositeInnerType::Struct(StructType {
fields: structure
.fields
.iter()
.map(|field| FieldType {
element_type: layout
.storage_type(struct_field_type(field.id, semantics)),
mutable: false,
})
.collect(),
}),
true,
None,
)
}
Type::ManagedClass(id) => {
let class = program
.managed_class(id)
.expect("reachable managed class shapes have declarations");
(
CompositeInnerType::Struct(StructType {
fields: class
.all_fields()
.filter(|field| !field.is_static)
.map(|field| FieldType {
element_type: layout
.storage_type(managed_snapshot_field_type(field.id, semantics)),
mutable: false,
})
.collect(),
}),
true,
None,
)
}
Type::Enum(id) => {
let enumeration = enums
.iter()
.find(|enumeration| enumeration.id == id)
.expect("reachable enum layouts have declarations");
(
CompositeInnerType::Struct(StructType {
fields: std::iter::once(FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: false,
})
.chain(enumeration.variants.iter().map(|variant| FieldType {
element_type: enum_variant_payload(variant.id, semantics).map_or(
StorageType::Val(ValType::I32),
|ty| {
if ty.has_runtime_value() {
layout.storage_type(ty)
} else {
StorageType::Val(ValType::I32)
}
},
),
mutable: false,
}))
.collect(),
}),
true,
None,
)
}
Type::Array(id) => {
let declaration = array_types
.iter()
.find(|array| array.id == id)
.expect("reachable arrays have resolved declarations");
let backing = array_types
.iter()
.find(|array| {
array.length.is_none()
&& super::try_array_element_type(array.id, semantics)
== super::try_array_element_type(declaration.id, semantics)
})
.unwrap_or(declaration);
(
CompositeInnerType::Struct(StructType {
fields: vec![
FieldType {
element_type: layout.storage_type(Type::ArrayStorage(backing.id)),
mutable: true,
},
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: true,
},
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: true,
},
]
.into(),
}),
true,
None,
)
}
Type::ArrayStorage(id) => {
let declaration = array_types
.iter()
.find(|array| array.id == id)
.expect("reachable array storage has a resolved declaration");
let supertype_idx = declaration.length.and_then(|_| {
array_types
.iter()
.find(|array| {
array.length.is_none()
&& super::try_array_element_type(array.id, semantics)
== super::try_array_element_type(declaration.id, semantics)
})
.map(|array| layout.index(Type::ArrayStorage(array.id)))
});
(
CompositeInnerType::Array(ArrayType(FieldType {
element_type: layout
.array_element_storage_type(array_element_type(id, semantics)),
mutable: true,
})),
declaration.length.is_some(),
supertype_idx,
)
}
Type::Option(id) => (
CompositeInnerType::Struct(StructType {
fields: vec![FieldType {
element_type: layout.storage_type(option_value_type(id, semantics)),
mutable: false,
}]
.into(),
}),
true,
None,
),
Type::Result(id) => (
CompositeInnerType::Struct(StructType {
fields: vec![
FieldType {
element_type: layout.storage_type(result_value_type(id, semantics)),
mutable: false,
},
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: false,
},
FieldType {
element_type: StorageType::Val(
layout.val_type(Type::Standard(StdlibTypeId::String)),
),
mutable: false,
},
]
.into(),
}),
true,
None,
),
Type::Set(id) => {
let set = set_types
.iter()
.find(|set| set.id == id)
.expect("reachable sets have resolved declarations");
(
CompositeInnerType::Struct(StructType {
fields: vec![
FieldType {
element_type: layout.storage_type(Type::ArrayStorage(set.backing)),
mutable: true,
},
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: true,
},
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: true,
},
]
.into(),
}),
true,
None,
)
}
Type::Range(id) => {
let range = range_types
.iter()
.find(|range| range.id == id)
.expect("reachable ranges have resolved declarations");
let crate::types::ResolvedTypeRef::Core(bound) = range.bound else {
unreachable!("range bounds are concrete integer types")
};
let bound = Type::from_core(bound);
let owner = match range.kind {
crate::ast::RangeKind::Exclusive => StdlibTypeConstructorId::ExclusiveRange,
crate::ast::RangeKind::Inclusive => StdlibTypeConstructorId::InclusiveRange,
};
let fields = standard_library
.fields_of_constructor(owner)
.map(|field| {
let ty = match field.ty {
TypeRef::Parameter(_) => bound,
TypeRef::Core(core) => Type::from_core(core),
TypeRef::Standard(standard) => Type::from_standard(standard),
_ => unreachable!(
"constructed GC fields currently use direct declared types"
),
};
FieldType {
element_type: layout.storage_type(ty),
mutable: false,
}
})
.collect();
(
CompositeInnerType::Struct(StructType { fields }),
true,
None,
)
}
Type::Application(id) => {
let application = application_types
.iter()
.find(|application| application.id == id)
.expect("reachable named applications have resolved declarations");
let declaration = standard_library.type_constructor(application.constructor);
let arguments = semantics
.types()
.iter()
.find_map(|(_, kind)| match kind {
TypeKind::Application {
layout, arguments, ..
} if *layout == id => Some(arguments.as_slice()),
_ => None,
})
.expect("reachable named applications have semantic argument types");
let variables = declaration
.parameters
.iter()
.zip(arguments)
.map(|(parameter, argument)| (parameter.name, *argument))
.collect::<std::collections::HashMap<_, _>>();
(
CompositeInnerType::Struct(StructType {
fields: standard_library
.fields_of_constructor(application.constructor)
.map(|field| FieldType {
element_type: layout.storage_type(semantic_type(
instantiated_catalog_type(field.ty, &variables, semantics),
semantics,
)),
// These generic structs currently back
// compiler-owned iterator cursors. Their
// storage is source-private, while `next()`
// advances the cursor in place.
mutable: true,
})
.collect(),
}),
true,
None,
)
}
Type::Callable(id) => {
let TypeKind::Callable {
parameters, result, ..
} = semantics
.types()
.iter()
.find_map(|(_, kind)| {
matches!(kind, TypeKind::Callable { layout: candidate, .. } if *candidate == id)
.then_some(kind)
})
.expect("reachable callables have semantic signatures")
else {
unreachable!()
};
debug_assert_eq!(
layout.callable_function_index(id),
recursive_types.len() as u32
);
let params = std::iter::once(ValType::Ref(RefType {
nullable: true,
heap_type: HeapType::Abstract {
shared: false,
ty: AbstractHeapType::Any,
},
}))
.chain(parameters.iter().filter_map(|parameter| {
let ty = semantic_type(*parameter, semantics);
ty.has_runtime_value().then(|| layout.val_type(ty))
}))
.collect::<Vec<_>>();
let result_ty = semantic_type(*result, semantics);
let results = result_ty
.has_runtime_value()
.then(|| layout.val_type(result_ty))
.into_iter()
.collect::<Vec<_>>();
recursive_types.push(SubType {
is_final: true,
supertype_idx: None,
composite_type: CompositeType {
inner: CompositeInnerType::Func(FuncType::new(params, results)),
shared: false,
descriptor: None,
describes: None,
},
});
(
CompositeInnerType::Struct(StructType {
fields: vec![
FieldType {
element_type: StorageType::Val(ValType::Ref(RefType {
nullable: false,
heap_type: HeapType::Concrete(
layout.callable_function_index(id),
),
})),
mutable: false,
},
FieldType {
element_type: StorageType::Val(ValType::Ref(RefType {
nullable: true,
heap_type: HeapType::Abstract {
shared: false,
ty: AbstractHeapType::Any,
},
})),
mutable: false,
},
]
.into(),
}),
true,
None,
)
}
_ => unreachable!("only dynamic GC types are ordered by GcLayout"),
};
recursive_types.push(SubType {
is_final,
supertype_idx,
composite_type: CompositeType {
inner,
shared: false,
descriptor: None,
describes: None,
},
});
}
for ty in layout.capture_cell_types() {
debug_assert_eq!(layout.capture_cell_index(ty), recursive_types.len() as u32);
recursive_types.push(SubType {
is_final: true,
supertype_idx: None,
composite_type: CompositeType {
inner: CompositeInnerType::Struct(StructType {
fields: [FieldType {
element_type: layout.storage_type(ty),
mutable: true,
}]
.into(),
}),
shared: false,
descriptor: None,
describes: None,
},
});
}
for instance in reachability.closure_instances() {
let closure = wasm_ir
.closure(instance.expression)
.expect("reachable closure instances have bodies");
if closure.captures.is_empty() {
continue;
}
debug_assert_eq!(
layout
.closure_environment_index(instance)
.expect("capturing closures have environment layouts"),
recursive_types.len() as u32
);
recursive_types.push(SubType {
is_final: true,
supertype_idx: None,
composite_type: CompositeType {
inner: CompositeInnerType::Struct(StructType {
fields: closure
.captures
.iter()
.map(|capture| {
let ty = instance.owner.as_ref().map_or_else(
|| value_type(capture.value, semantics),
|owner| {
super::semantic_type(
semantics.specialize_type(
owner,
semantics
.value_type(capture.value)
.expect("checked captures have types"),
),
semantics,
)
},
);
FieldType {
element_type: if capture.mutable && ty.has_runtime_value() {
layout.capture_cell_storage_type(ty)
} else {
layout.storage_type(ty)
},
mutable: false,
}
})
.collect(),
}),
shared: false,
descriptor: None,
describes: None,
},
});
}
for future in async_types
.iter()
.filter(|future| reachability.contains_async_type(future.id))
{
debug_assert_eq!(
layout.index(Type::Async(future.id)),
recursive_types.len() as u32
);
recursive_types.push(SubType {
is_final: false,
supertype_idx: None,
composite_type: CompositeType {
inner: CompositeInnerType::Struct(StructType {
fields: vec![
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: true,
},
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: false,
},
FieldType {
element_type: StorageType::Val(ValType::I64),
mutable: true,
},
]
.into(),
}),
shared: false,
descriptor: None,
describes: None,
},
});
}
for iterator in iterator_types
.iter()
.filter(|iterator| reachability.contains_iterator_type(iterator.id))
{
debug_assert_eq!(
layout.index(Type::Iterator(iterator.id)),
recursive_types.len() as u32
);
recursive_types.push(SubType {
is_final: false,
supertype_idx: None,
composite_type: CompositeType {
inner: CompositeInnerType::Struct(StructType {
fields: vec![
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: true,
},
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: false,
},
FieldType {
element_type: StorageType::Val(ValType::I64),
mutable: true,
},
]
.into(),
}),
shared: false,
descriptor: None,
describes: None,
},
});
}
for (instance, frame) in async_frames.functions() {
let result = semantics.specialize_type(
instance,
semantics
.function_result(instance.function)
.expect("checked functions have result types"),
);
let result = super::semantic_type(result, semantics);
let supertype = match result {
Type::Async(future) => layout.index(Type::Async(future)),
Type::Iterator(iterator) => layout.index(Type::Iterator(iterator)),
_ => unreachable!("continuation-backed functions return async or iterator values"),
};
let frame_index = layout.function_frame_index(instance);
debug_assert_eq!(frame_index, recursive_types.len() as u32);
recursive_types.push(SubType {
is_final: true,
supertype_idx: Some(supertype),
composite_type: CompositeType {
inner: CompositeInnerType::Struct(StructType {
fields: [
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: true,
},
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: false,
},
FieldType {
element_type: StorageType::Val(ValType::I64),
mutable: true,
},
]
.into_iter()
.chain(frame.types.iter().enumerate().map(|(position, ty)| {
let field = frame.base_fields + position as u32;
FieldType {
element_type: if frame.capture_cell_fields.contains(&field) {
layout.capture_cell_storage_type(*ty)
} else {
layout.frame_storage_type(*ty)
},
mutable: true,
}
}))
.collect(),
}),
shared: false,
descriptor: None,
describes: None,
},
});
}
for (instance, frame) in async_frames.closures() {
let closure_type = wasm_ir
.expression(instance.expression)
.expect("reachable closure expressions belong to Wasm IR")
.ty;
let closure_type = instance.owner.as_ref().map_or(closure_type, |owner| {
semantics.specialize_type(owner, closure_type)
});
let TypeKind::Callable { result, .. } = semantics.types().kind(closure_type) else {
unreachable!("checked closure expressions have callable types")
};
let result = super::semantic_type(*result, semantics);
let supertype = match result {
Type::Async(future) => layout.index(Type::Async(future)),
Type::Iterator(iterator) => layout.index(Type::Iterator(iterator)),
_ => unreachable!("continuation-backed closures return async or iterator values"),
};
let frame_index = layout.closure_frame_index(instance);
debug_assert_eq!(frame_index, recursive_types.len() as u32);
recursive_types.push(SubType {
is_final: true,
supertype_idx: Some(supertype),
composite_type: CompositeType {
inner: CompositeInnerType::Struct(StructType {
fields: [
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: true,
},
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: false,
},
FieldType {
element_type: StorageType::Val(ValType::I64),
mutable: true,
},
]
.into_iter()
.chain(frame.types.iter().enumerate().map(|(position, ty)| {
let field = frame.base_fields + position as u32;
FieldType {
element_type: if frame.capture_cell_fields.contains(&field) {
layout.capture_cell_storage_type(*ty)
} else {
layout.frame_storage_type(*ty)
},
mutable: true,
}
}))
.collect(),
}),
shared: false,
descriptor: None,
describes: None,
},
});
}
for (instance, frame) in async_frames.leaves() {
let Type::Async(future) = frame.future else {
unreachable!("leaf future layouts have async value types")
};
let frame_index = layout.leaf_frame_index(instance);
debug_assert_eq!(frame_index, recursive_types.len() as u32);
recursive_types.push(SubType {
is_final: true,
supertype_idx: Some(layout.index(Type::Async(future))),
composite_type: CompositeType {
inner: CompositeInnerType::Struct(StructType {
fields: [
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: true,
},
FieldType {
element_type: StorageType::Val(ValType::I32),
mutable: false,
},
FieldType {
element_type: StorageType::Val(ValType::I64),
mutable: true,
},
]
.into_iter()
.chain(frame.types.iter().map(|ty| FieldType {
element_type: layout.frame_storage_type(*ty),
mutable: true,
}))
.collect(),
}),
shared: false,
descriptor: None,
describes: None,
},
});
}
let mut types = TypeSection::new();
types.ty().rec(recursive_types);
// `TypeSection::len` counts encoded entries, while a recursive group can
// contain multiple indexed subtypes. State, Duration, String, the attach
// Module, the attach continuation frame, and then user structs occupy the
// first indices.
EncodedTypes {
section: types,
next_type_index: layout.type_count,
layout,
}
}
pub(super) fn instantiated_catalog_type(
ty: TypeRef,
variables: &std::collections::HashMap<&'static str, TypeId>,
semantics: &SemanticModel,
) -> TypeId {
semantics
.instantiated_catalog_type(ty, variables)
.expect("instantiated catalog types have semantic layouts")
}