Skip to content

Commit 2e4e7e0

Browse files
author
Kristian Larsson
committed
Lower unboxed bool calls
The boxing pass can see zero-argument __bool__ calls on numeric values whose receiver has already been lowered to an unboxed representation. The generic method-call path leaves that as a Dot on a raw receiver, which QuickType cannot schema and which caused http2.client to fail on an UNBOXED u32 receiver. Handle that case during boxing by lowering numeric truthiness directly to a raw nonzero comparison. The comparison stays in the unboxed representation, and only the resulting Acton bool is boxed for the surrounding expression.
1 parent a7703da commit 2e4e7e0

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

compiler/lib/src/Acton/Boxing.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,12 @@ instance Boxing Expr where
487487
-- let res = eCallP (tApp (eDot e1 n) ts) (fixargs env p1 r)
488488
-- return (ws1++ws2, tryBox t res)
489489
-- where TFun _ _ r _ t = typeOf env a
490+
boxing env (Call l (Dot _ e n) PosNil KwdNil)
491+
| n == boolKW,
492+
Just rt <- unboxedRepType (typeOf env e)
493+
= do (ws1,e1) <- boxing env e
494+
let z = UnBox rt (Int l 0 "0")
495+
return (ws1, Box tBool $ CompOp l (forceUnbox env rt e1) [OpArg NEq z])
490496
boxing env (Call l f p KwdNil) = do (ws1,f1) <- boxing env f
491497
(ws2,p1) <- boxing env p
492498
let c = eCallP f1 (fixargs env p1 r)

0 commit comments

Comments
 (0)