@@ -140,12 +140,8 @@ impl<'a> TrampolineCompiler<'a> {
140
140
host:: stream_new,
141
141
TrapSentinel :: NegativeOne ,
142
142
) ,
143
- Trampoline :: StreamRead {
144
- ty,
145
- err_ctx_ty,
146
- options,
147
- } => {
148
- let tys = & [ ty. as_u32 ( ) , err_ctx_ty. as_u32 ( ) ] ;
143
+ Trampoline :: StreamRead { ty, options } => {
144
+ let tys = & [ ty. as_u32 ( ) ] ;
149
145
if let Some ( info) = self . flat_stream_element_info ( * ty) . cloned ( ) {
150
146
self . translate_flat_stream_call ( tys, options, host:: flat_stream_read, & info)
151
147
} else {
@@ -182,25 +178,20 @@ impl<'a> TrampolineCompiler<'a> {
182
178
host:: stream_close_readable,
183
179
TrapSentinel :: Falsy ,
184
180
) ,
185
- Trampoline :: StreamCloseWritable { ty, err_ctx_ty } => self
186
- . translate_future_or_stream_call (
187
- & [ ty. as_u32 ( ) , err_ctx_ty. as_u32 ( ) ] ,
188
- None ,
189
- host:: stream_close_writable,
190
- TrapSentinel :: Falsy ,
191
- ) ,
181
+ Trampoline :: StreamCloseWritable { ty } => self . translate_future_or_stream_call (
182
+ & [ ty. as_u32 ( ) ] ,
183
+ None ,
184
+ host:: stream_close_writable,
185
+ TrapSentinel :: Falsy ,
186
+ ) ,
192
187
Trampoline :: FutureNew { ty } => self . translate_future_or_stream_call (
193
188
& [ ty. as_u32 ( ) ] ,
194
189
None ,
195
190
host:: future_new,
196
191
TrapSentinel :: NegativeOne ,
197
192
) ,
198
- Trampoline :: FutureRead {
199
- ty,
200
- err_ctx_ty,
201
- options,
202
- } => self . translate_future_or_stream_call (
203
- & [ ty. as_u32 ( ) , err_ctx_ty. as_u32 ( ) ] ,
193
+ Trampoline :: FutureRead { ty, options } => self . translate_future_or_stream_call (
194
+ & [ ty. as_u32 ( ) ] ,
204
195
Some ( & options) ,
205
196
host:: future_read,
206
197
TrapSentinel :: NegativeOne ,
@@ -223,13 +214,12 @@ impl<'a> TrampolineCompiler<'a> {
223
214
host:: future_close_readable,
224
215
TrapSentinel :: Falsy ,
225
216
) ,
226
- Trampoline :: FutureCloseWritable { ty, err_ctx_ty } => self
227
- . translate_future_or_stream_call (
228
- & [ ty. as_u32 ( ) , err_ctx_ty. as_u32 ( ) ] ,
229
- None ,
230
- host:: future_close_writable,
231
- TrapSentinel :: Falsy ,
232
- ) ,
217
+ Trampoline :: FutureCloseWritable { ty } => self . translate_future_or_stream_call (
218
+ & [ ty. as_u32 ( ) ] ,
219
+ None ,
220
+ host:: future_close_writable,
221
+ TrapSentinel :: Falsy ,
222
+ ) ,
233
223
Trampoline :: ErrorContextNew { ty, options } => self . translate_error_context_call (
234
224
* ty,
235
225
options,
@@ -246,12 +236,12 @@ impl<'a> TrampolineCompiler<'a> {
246
236
Trampoline :: ErrorContextDrop { ty } => self . translate_error_context_drop_call ( * ty) ,
247
237
Trampoline :: ResourceTransferOwn => {
248
238
self . translate_host_libcall ( host:: resource_transfer_own, |me, rets| {
249
- rets[ 0 ] = me. raise_if_negative_one ( rets[ 0 ] ) ;
239
+ rets[ 0 ] = me. raise_if_negative_one_and_truncate ( rets[ 0 ] ) ;
250
240
} )
251
241
}
252
242
Trampoline :: ResourceTransferBorrow => {
253
243
self . translate_host_libcall ( host:: resource_transfer_borrow, |me, rets| {
254
- rets[ 0 ] = me. raise_if_negative_one ( rets[ 0 ] ) ;
244
+ rets[ 0 ] = me. raise_if_negative_one_and_truncate ( rets[ 0 ] ) ;
255
245
} )
256
246
}
257
247
Trampoline :: ResourceEnterCall => {
@@ -277,17 +267,17 @@ impl<'a> TrampolineCompiler<'a> {
277
267
) ,
278
268
Trampoline :: FutureTransfer => {
279
269
self . translate_host_libcall ( host:: future_transfer, |me, rets| {
280
- rets[ 0 ] = me. raise_if_negative_one ( rets[ 0 ] ) ;
270
+ rets[ 0 ] = me. raise_if_negative_one_and_truncate ( rets[ 0 ] ) ;
281
271
} )
282
272
}
283
273
Trampoline :: StreamTransfer => {
284
274
self . translate_host_libcall ( host:: stream_transfer, |me, rets| {
285
- rets[ 0 ] = me. raise_if_negative_one ( rets[ 0 ] ) ;
275
+ rets[ 0 ] = me. raise_if_negative_one_and_truncate ( rets[ 0 ] ) ;
286
276
} )
287
277
}
288
278
Trampoline :: ErrorContextTransfer => {
289
279
self . translate_host_libcall ( host:: error_context_transfer, |me, rets| {
290
- rets[ 0 ] = me. raise_if_negative_one ( rets[ 0 ] ) ;
280
+ rets[ 0 ] = me. raise_if_negative_one_and_truncate ( rets[ 0 ] ) ;
291
281
} )
292
282
}
293
283
}
@@ -373,12 +363,22 @@ impl<'a> TrampolineCompiler<'a> {
373
363
let call = self . call_libcall ( vmctx, get_libcall, args) ;
374
364
375
365
let result = self . builder . func . dfg . inst_results ( call) [ 0 ] ;
366
+ let result_ty = self . builder . func . dfg . value_type ( result) ;
367
+ let expected = & self . builder . func . signature . returns ;
376
368
match sentinel {
377
369
TrapSentinel :: NegativeOne => {
378
- let result = self . raise_if_negative_one ( result) ;
370
+ assert_eq ! ( expected. len( ) , 1 ) ;
371
+ let result = match ( result_ty, expected[ 0 ] . value_type ) {
372
+ ( ir:: types:: I64 , ir:: types:: I32 ) => {
373
+ self . raise_if_negative_one_and_truncate ( result)
374
+ }
375
+ ( ir:: types:: I64 , ir:: types:: I64 ) => self . raise_if_negative_one ( result) ,
376
+ other => panic ! ( "unsupported NegativeOne combo {other:?}" ) ,
377
+ } ;
379
378
self . abi_store_results ( & [ result] ) ;
380
379
}
381
380
TrapSentinel :: Falsy => {
381
+ assert_eq ! ( expected. len( ) , 0 ) ;
382
382
self . raise_if_host_trapped ( result) ;
383
383
self . builder . ins ( ) . return_ ( & [ ] ) ;
384
384
}
@@ -887,7 +887,7 @@ impl<'a> TrampolineCompiler<'a> {
887
887
) ;
888
888
let call = self . call_libcall ( vmctx, host:: resource_new32, & host_args) ;
889
889
let result = self . builder . func . dfg . inst_results ( call) [ 0 ] ;
890
- let result = self . raise_if_negative_one ( result) ;
890
+ let result = self . raise_if_negative_one_and_truncate ( result) ;
891
891
self . abi_store_results ( & [ result] ) ;
892
892
}
893
893
@@ -916,7 +916,7 @@ impl<'a> TrampolineCompiler<'a> {
916
916
) ;
917
917
let call = self . call_libcall ( vmctx, host:: resource_rep32, & host_args) ;
918
918
let result = self . builder . func . dfg . inst_results ( call) [ 0 ] ;
919
- let result = self . raise_if_negative_one ( result) ;
919
+ let result = self . raise_if_negative_one_and_truncate ( result) ;
920
920
self . abi_store_results ( & [ result] ) ;
921
921
}
922
922
@@ -1423,11 +1423,16 @@ impl<'a> TrampolineCompiler<'a> {
1423
1423
self . raise_if_host_trapped ( succeeded) ;
1424
1424
}
1425
1425
1426
+ fn raise_if_negative_one_and_truncate ( & mut self , ret : ir:: Value ) -> ir:: Value {
1427
+ let ret = self . raise_if_negative_one ( ret) ;
1428
+ self . builder . ins ( ) . ireduce ( ir:: types:: I32 , ret)
1429
+ }
1430
+
1426
1431
fn raise_if_negative_one ( & mut self , ret : ir:: Value ) -> ir:: Value {
1427
1432
let minus_one = self . builder . ins ( ) . iconst ( ir:: types:: I64 , -1 ) ;
1428
1433
let succeeded = self . builder . ins ( ) . icmp ( IntCC :: NotEqual , ret, minus_one) ;
1429
1434
self . raise_if_host_trapped ( succeeded) ;
1430
- self . builder . ins ( ) . ireduce ( ir :: types :: I32 , ret)
1435
+ ret
1431
1436
}
1432
1437
1433
1438
fn call_libcall (
0 commit comments