Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ fix #212 ] Be more flexible with unboxed records #213

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Agda2Hs/Compile/Record.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE NamedFieldPuns #-}
module Agda2Hs.Compile.Record where

import Control.Monad ( unless )
Expand Down Expand Up @@ -168,7 +169,11 @@ compileRecord target def = setCurrentRange (nameBindingSite $ qnameName $ defNam
return $ Hs.DataDecl () don Nothing hd [conDecl] ds

checkUnboxPragma :: Defn -> C ()
checkUnboxPragma def@Record{ recFields = (f:fs) }
| keepArg f , all (not . keepArg) fs , not (recRecursive def) = return ()
checkUnboxPragma _ = genericError $
"An unboxed type must be a non-recursive record type with exactly one non-erased field."
checkUnboxPragma def
| Record{recFields} <- def
, length (filter keepArg recFields) == 1
, not (recRecursive def)
= return ()

| otherwise
= genericError "An unboxed type must be a non-recursive record type with exactly one non-erased field."
7 changes: 7 additions & 0 deletions test/UnboxPragma.agda
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ open ∃ public

{-# COMPILE AGDA2HS ∃ unboxed #-}

record Σ0 (A : Set) (P : @0 A → Set) : Set where
field
@0 el : A
pf : P el

{-# COMPILE AGDA2HS Σ0 unboxed #-}
omelkonian marked this conversation as resolved.
Show resolved Hide resolved

postulate
IsSorted : List Int → Set
looksfine : {xs : List Int} → IsSorted xs
Expand Down
Loading