Skip to content

Commit d7f9e59

Browse files
committed
Add more codegen UI tests; update existing ones
1 parent 36685c7 commit d7f9e59

15 files changed

+1819
-23
lines changed

cmd/gravity/tests/cmd/basic.stdout

Lines changed: 187 additions & 16 deletions
Large diffs are not rendered by default.

cmd/gravity/tests/cmd/iface-method-returns-string.stdout

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,29 @@ func NewExampleFactory(
3636
) (*ExampleFactory, error) {
3737
wazeroRuntime := wazero.NewRuntime(ctx)
3838

39+
// Instantiate import host modules
3940
_, err0 := wazeroRuntime.NewHostModuleBuilder("arcjet:example/runtime").
4041
NewFunctionBuilder().
4142
WithFunc(func(
4243
ctx context.Context,
4344
mod api.Module,
4445
arg0 uint32,
4546
) {
47+
// CallInterface { func: Function { name: "os", kind: Freestanding, params: [], result: Some(String), docs: Docs { contents: None }, stability: Unknown }, async_: false }
4648
value0 := runtime.Os(ctx, )
49+
// GetArg { nth: 0 }
50+
// StringLower { realloc: Some("cabi_realloc") }
4751
memory1 := mod.Memory()
4852
realloc1 := mod.ExportedFunction("cabi_realloc")
4953
ptr1, len1, err1 := writeString(ctx, value0, memory1, realloc1)
5054
if err1 != nil {
5155
panic(err1)
5256
}
53-
mod.Memory().WriteUint32Le(arg0+4, uint32(len1))
54-
mod.Memory().WriteUint32Le(arg0+0, uint32(ptr1))
57+
// LengthStore { offset: ptrsz }
58+
mod.Memory().WriteUint32Le(uint32(arg0+4), uint32(len1))
59+
// PointerStore { offset: 0 }
60+
mod.Memory().WriteUint32Le(uint32(arg0+0), uint32(ptr1))
61+
// Return { amt: 0, func: Function { name: "os", kind: Freestanding, params: [], result: Some(String), docs: Docs { contents: None }, stability: Unknown } }
5562
}).
5663
Export("os").
5764
NewFunctionBuilder().
@@ -60,15 +67,21 @@ func NewExampleFactory(
6067
mod api.Module,
6168
arg0 uint32,
6269
) {
70+
// CallInterface { func: Function { name: "arch", kind: Freestanding, params: [], result: Some(String), docs: Docs { contents: None }, stability: Unknown }, async_: false }
6371
value0 := runtime.Arch(ctx, )
72+
// GetArg { nth: 0 }
73+
// StringLower { realloc: Some("cabi_realloc") }
6474
memory1 := mod.Memory()
6575
realloc1 := mod.ExportedFunction("cabi_realloc")
6676
ptr1, len1, err1 := writeString(ctx, value0, memory1, realloc1)
6777
if err1 != nil {
6878
panic(err1)
6979
}
70-
mod.Memory().WriteUint32Le(arg0+4, uint32(len1))
71-
mod.Memory().WriteUint32Le(arg0+0, uint32(ptr1))
80+
// LengthStore { offset: ptrsz }
81+
mod.Memory().WriteUint32Le(uint32(arg0+4), uint32(len1))
82+
// PointerStore { offset: 0 }
83+
mod.Memory().WriteUint32Le(uint32(arg0+0), uint32(ptr1))
84+
// Return { amt: 0, func: Function { name: "arch", kind: Freestanding, params: [], result: Some(String), docs: Docs { contents: None }, stability: Unknown } }
7285
}).
7386
Export("arch").
7487
NewFunctionBuilder().
@@ -78,12 +91,17 @@ func NewExampleFactory(
7891
arg0 uint32,
7992
arg1 uint32,
8093
) {
94+
// GetArg { nth: 0 }
95+
// GetArg { nth: 1 }
96+
// StringLift
8197
buf0, ok0 := mod.Memory().Read(arg0, arg1)
8298
if !ok0 {
8399
panic(errors.New("failed to read bytes from memory"))
84100
}
85101
str0 := string(buf0)
102+
// CallInterface { func: Function { name: "puts", kind: Freestanding, params: [("msg", String)], result: None, docs: Docs { contents: None }, stability: Unknown }, async_: false }
86103
runtime.Puts(ctx, str0)
104+
// Return { amt: 0, func: Function { name: "puts", kind: Freestanding, params: [("msg", String)], result: None, docs: Docs { contents: None }, stability: Unknown } }
87105
}).
88106
Export("puts").
89107
Instantiate(ctx)
@@ -154,6 +172,7 @@ func writeString(
154172
func (i *ExampleInstance) Hello(
155173
ctx context.Context,
156174
) (string, error) {
175+
// CallWasm { name: "hello", sig: WasmSignature { params: [], results: [Pointer], indirect_params: false, retptr: true } }
157176
raw0, err0 := i.module.ExportedFunction("hello").Call(ctx, )
158177
if err0 != nil {
159178
var default0 string
@@ -173,25 +192,30 @@ func (i *ExampleInstance) Hello(
173192
}()
174193

175194
results0 := raw0[0]
195+
// I32Load8U { offset: 0 }
176196
value1, ok1 := i.module.Memory().ReadByte(uint32(results0 + 0))
177197
if !ok1 {
178198
var default1 string
179199
return default1, errors.New("failed to read byte from memory")
180200
}
201+
// ResultLift { result: Result_ { ok: Some(String), err: Some(String) }, ty: Id { idx: 0 } }
181202
var value8 string
182203
var err8 error
183204
switch value1 {
184205
case 0:
206+
// PointerLoad { offset: ptrsz }
185207
ptr2, ok2 := i.module.Memory().ReadUint32Le(uint32(results0 + 4))
186208
if !ok2 {
187209
var default2 string
188210
return default2, errors.New("failed to read pointer from memory")
189211
}
212+
// LengthLoad { offset: (2*ptrsz) }
190213
len3, ok3 := i.module.Memory().ReadUint32Le(uint32(results0 + 8))
191214
if !ok3 {
192215
var default3 string
193216
return default3, errors.New("failed to read length from memory")
194217
}
218+
// StringLift
195219
buf4, ok4 := i.module.Memory().Read(ptr2, len3)
196220
if !ok4 {
197221
var default4 string
@@ -200,16 +224,19 @@ func (i *ExampleInstance) Hello(
200224
str4 := string(buf4)
201225
value8 = str4
202226
case 1:
227+
// PointerLoad { offset: ptrsz }
203228
ptr5, ok5 := i.module.Memory().ReadUint32Le(uint32(results0 + 4))
204229
if !ok5 {
205230
var default5 string
206231
return default5, errors.New("failed to read pointer from memory")
207232
}
233+
// LengthLoad { offset: (2*ptrsz) }
208234
len6, ok6 := i.module.Memory().ReadUint32Le(uint32(results0 + 8))
209235
if !ok6 {
210236
var default6 string
211237
return default6, errors.New("failed to read length from memory")
212238
}
239+
// StringLift
213240
buf7, ok7 := i.module.Memory().Read(ptr5, len6)
214241
if !ok7 {
215242
var default7 string
@@ -220,6 +247,8 @@ func (i *ExampleInstance) Hello(
220247
default:
221248
err8 = errors.New("invalid variant discriminant for expected")
222249
}
250+
// Flush { amt: 1 }
251+
// Return { amt: 1, func: Function { name: "hello", kind: Freestanding, params: [], result: Some(Id(Id { idx: 0 })), docs: Docs { contents: None }, stability: Unknown } }
223252
return value8, err8
224253
}
225254

cmd/gravity/tests/cmd/instructions.stdout

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func NewInstructionsFactory(
2222
) (*InstructionsFactory, error) {
2323
wazeroRuntime := wazero.NewRuntime(ctx)
2424

25+
// Instantiate import host modules
26+
2527
// Compiling the module takes a LONG time, so we want to do it once and hold
2628
// onto it with the Runtime
2729
module, err := wazeroRuntime.CompileModule(ctx, wasmFileInstructions)
@@ -87,15 +89,20 @@ func (i *InstructionsInstance) S8Roundtrip(
8789
val int8,
8890
) int8 {
8991
arg0 := val
92+
// GetArg { nth: 0 }
93+
// I32FromS8
9094
value0 := api.EncodeI32(int32(arg0))
95+
// CallWasm { name: "s8-roundtrip", sig: WasmSignature { params: [I32], results: [I32], indirect_params: false, retptr: false } }
9196
raw1, err1 := i.module.ExportedFunction("s8-roundtrip").Call(ctx, uint64(value0))
9297
// The return type doesn't contain an error so we panic if one is encountered
9398
if err1 != nil {
9499
panic(err1)
95100
}
96101

97102
results1 := raw1[0]
103+
// S8FromI32
98104
result2 := int8(api.DecodeI32(results1))
105+
// Return { amt: 1, func: Function { name: "s8-roundtrip", kind: Freestanding, params: [("val", S8)], result: Some(S8), docs: Docs { contents: None }, stability: Unknown } }
99106
return result2
100107
}
101108

@@ -104,15 +111,20 @@ func (i *InstructionsInstance) U8Roundtrip(
104111
val uint8,
105112
) uint8 {
106113
arg0 := val
114+
// GetArg { nth: 0 }
115+
// I32FromU8
107116
value0 := api.EncodeI32(int32(arg0))
117+
// CallWasm { name: "u8-roundtrip", sig: WasmSignature { params: [I32], results: [I32], indirect_params: false, retptr: false } }
108118
raw1, err1 := i.module.ExportedFunction("u8-roundtrip").Call(ctx, uint64(value0))
109119
// The return type doesn't contain an error so we panic if one is encountered
110120
if err1 != nil {
111121
panic(err1)
112122
}
113123

114124
results1 := raw1[0]
125+
// U8FromI32
115126
result2 := uint8(api.DecodeU32(results1))
127+
// Return { amt: 1, func: Function { name: "u8-roundtrip", kind: Freestanding, params: [("val", U8)], result: Some(U8), docs: Docs { contents: None }, stability: Unknown } }
116128
return result2
117129
}
118130

@@ -121,15 +133,20 @@ func (i *InstructionsInstance) S16Roundtrip(
121133
val int16,
122134
) int16 {
123135
arg0 := val
136+
// GetArg { nth: 0 }
137+
// I32FromS16
124138
value0 := api.EncodeI32(int32(arg0))
139+
// CallWasm { name: "s16-roundtrip", sig: WasmSignature { params: [I32], results: [I32], indirect_params: false, retptr: false } }
125140
raw1, err1 := i.module.ExportedFunction("s16-roundtrip").Call(ctx, uint64(value0))
126141
// The return type doesn't contain an error so we panic if one is encountered
127142
if err1 != nil {
128143
panic(err1)
129144
}
130145

131146
results1 := raw1[0]
147+
// S16FromI32
132148
result2 := int16(api.DecodeI32(results1))
149+
// Return { amt: 1, func: Function { name: "s16-roundtrip", kind: Freestanding, params: [("val", S16)], result: Some(S16), docs: Docs { contents: None }, stability: Unknown } }
133150
return result2
134151
}
135152

@@ -138,15 +155,20 @@ func (i *InstructionsInstance) U16Roundtrip(
138155
val uint16,
139156
) uint16 {
140157
arg0 := val
158+
// GetArg { nth: 0 }
159+
// I32FromU16
141160
value0 := api.EncodeI32(int32(arg0))
161+
// CallWasm { name: "u16-roundtrip", sig: WasmSignature { params: [I32], results: [I32], indirect_params: false, retptr: false } }
142162
raw1, err1 := i.module.ExportedFunction("u16-roundtrip").Call(ctx, uint64(value0))
143163
// The return type doesn't contain an error so we panic if one is encountered
144164
if err1 != nil {
145165
panic(err1)
146166
}
147167

148168
results1 := raw1[0]
169+
// U16FromI32
149170
result2 := uint16(api.DecodeU32(results1))
171+
// Return { amt: 1, func: Function { name: "u16-roundtrip", kind: Freestanding, params: [("val", U16)], result: Some(U16), docs: Docs { contents: None }, stability: Unknown } }
150172
return result2
151173
}
152174

@@ -155,15 +177,20 @@ func (i *InstructionsInstance) S32Roundtrip(
155177
val int32,
156178
) int32 {
157179
arg0 := val
180+
// GetArg { nth: 0 }
181+
// I32FromS32
158182
value0 := api.EncodeI32(arg0)
183+
// CallWasm { name: "s32-roundtrip", sig: WasmSignature { params: [I32], results: [I32], indirect_params: false, retptr: false } }
159184
raw1, err1 := i.module.ExportedFunction("s32-roundtrip").Call(ctx, uint64(value0))
160185
// The return type doesn't contain an error so we panic if one is encountered
161186
if err1 != nil {
162187
panic(err1)
163188
}
164189

165190
results1 := raw1[0]
191+
// S32FromI32
166192
result2 := api.DecodeI32(results1)
193+
// Return { amt: 1, func: Function { name: "s32-roundtrip", kind: Freestanding, params: [("val", S32)], result: Some(S32), docs: Docs { contents: None }, stability: Unknown } }
167194
return result2
168195
}
169196

@@ -172,15 +199,20 @@ func (i *InstructionsInstance) U32Roundtrip(
172199
val uint32,
173200
) uint32 {
174201
arg0 := val
202+
// GetArg { nth: 0 }
203+
// I32FromU32
175204
result0 := api.EncodeU32(arg0)
205+
// CallWasm { name: "u32-roundtrip", sig: WasmSignature { params: [I32], results: [I32], indirect_params: false, retptr: false } }
176206
raw1, err1 := i.module.ExportedFunction("u32-roundtrip").Call(ctx, uint64(result0))
177207
// The return type doesn't contain an error so we panic if one is encountered
178208
if err1 != nil {
179209
panic(err1)
180210
}
181211

182212
results1 := raw1[0]
183-
result2 := api.DecodeU32(results1)
213+
// U32FromI32
214+
result2 := api.DecodeU32(uint64(results1))
215+
// Return { amt: 1, func: Function { name: "u32-roundtrip", kind: Freestanding, params: [("val", U32)], result: Some(U32), docs: Docs { contents: None }, stability: Unknown } }
184216
return result2
185217
}
186218

@@ -189,15 +221,20 @@ func (i *InstructionsInstance) F32Roundtrip(
189221
val float32,
190222
) float32 {
191223
arg0 := val
192-
result0 := api.EncodeF32(arg0)
224+
// GetArg { nth: 0 }
225+
// CoreF32FromF32
226+
result0 := api.EncodeF32(float32(arg0))
227+
// CallWasm { name: "f32-roundtrip", sig: WasmSignature { params: [F32], results: [F32], indirect_params: false, retptr: false } }
193228
raw1, err1 := i.module.ExportedFunction("f32-roundtrip").Call(ctx, uint64(result0))
194229
// The return type doesn't contain an error so we panic if one is encountered
195230
if err1 != nil {
196231
panic(err1)
197232
}
198233

199234
results1 := raw1[0]
235+
// F32FromCoreF32
200236
result2 := api.DecodeF32(results1)
237+
// Return { amt: 1, func: Function { name: "f32-roundtrip", kind: Freestanding, params: [("val", F32)], result: Some(F32), docs: Docs { contents: None }, stability: Unknown } }
201238
return result2
202239
}
203240

@@ -206,15 +243,20 @@ func (i *InstructionsInstance) F64Roundtrip(
206243
val float64,
207244
) float64 {
208245
arg0 := val
209-
result0 := api.EncodeF64(arg0)
246+
// GetArg { nth: 0 }
247+
// CoreF64FromF64
248+
result0 := api.EncodeF64(float64(arg0))
249+
// CallWasm { name: "f64-roundtrip", sig: WasmSignature { params: [F64], results: [F64], indirect_params: false, retptr: false } }
210250
raw1, err1 := i.module.ExportedFunction("f64-roundtrip").Call(ctx, uint64(result0))
211251
// The return type doesn't contain an error so we panic if one is encountered
212252
if err1 != nil {
213253
panic(err1)
214254
}
215255

216256
results1 := raw1[0]
257+
// F64FromCoreF64
217258
result2 := api.DecodeF64(results1)
259+
// Return { amt: 1, func: Function { name: "f64-roundtrip", kind: Freestanding, params: [("val", F64)], result: Some(F64), docs: Docs { contents: None }, stability: Unknown } }
218260
return result2
219261
}
220262

cmd/gravity/tests/cmd/outlier.stderr

Whitespace-only changes.

0 commit comments

Comments
 (0)