Skip to content

Commit

Permalink
Mark tuples for dropping too
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljharvey committed May 28, 2024
1 parent 8cc3ef4 commit 07129e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion wasm-calc9/src/Calc/Linearity/Validate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ addLetBinding (PWildcard ty) = do
addLetBinding (PBox ty pat) =
PBox (ty, Just DropMe) <$> addLetBinding pat
addLetBinding (PTuple ty p ps) = do
PTuple (ty, Nothing)
PTuple (ty, Just DropMe)
<$> addLetBinding p
<*> traverse addLetBinding ps

Expand Down
13 changes: 11 additions & 2 deletions wasm-calc9/test/Test/Linearity/LinearitySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ runTC = runTypecheckM (TypecheckEnv mempty mempty 0)

spec :: Spec
spec = do
fdescribe "LinearitySpec" $ do
describe "LinearitySpec" $ do
describe "decorate" $ do
let dVar = EVar Nothing
dBool = EPrim Nothing . PBool
Expand Down Expand Up @@ -59,6 +59,15 @@ spec = do
(EBox Nothing (EAnn Nothing dTyInt64 (dInt 100)))
(dVar "a")
),
( "function dropTupleAfterUse() -> Int64 { let (a,_) = ((100: Int64),(200: Int64)); a }",
ELet
Nothing
(PTuple (Just DropMe) (PVar Nothing "a") (NE.singleton $ PVar Nothing "_fresh_name1"))
(ETuple Nothing (EAnn Nothing dTyInt64 (dInt 100))
(NE.singleton $ EAnn Nothing dTyInt64 (dInt 200))
)
(dVar "a")
),
( "function incrementallyDropBoxesAfterUse() -> Int64 { let Box(outer) = Box(Box((100: Int64))); let Box(inner) = outer; inner }",
ELet
Nothing
Expand Down Expand Up @@ -93,7 +102,7 @@ spec = do
letAEqualsTuple
( ELet
(dropIdents [("a", tyTuple [tyInt32, tyInt32])])
(PTuple Nothing (PVar Nothing "b") (NE.singleton (PVar Nothing "c")))
(PTuple (Just DropMe) (PVar Nothing "b") (NE.singleton (PVar Nothing "c")))
(dVar "a")
(EInfix Nothing OpAdd (dVar "b") (dVar "c"))
)
Expand Down
2 changes: 1 addition & 1 deletion wasm-calc9/test/Test/Wasm/WasmSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ spec = do
describe "From module" $ do
traverse_ testWithNode testVals

fdescribe "Test with interpreter" $ do
describe "Test with interpreter" $ do
let asTest str = "export function test() -> Int64 { " <> str <> " }"
let testVals =
[ (asTest "42", Wasm.VI64 42),
Expand Down

0 comments on commit 07129e1

Please sign in to comment.