-
Notifications
You must be signed in to change notification settings - Fork 155
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
unpack no longer warns #2397
Open
rowanG077
wants to merge
2
commits into
master
Choose a base branch
from
fix-2386
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
unpack no longer warns #2397
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FIXED: Clash no longer gives `Dubious primitive instantiation warning` | ||
when using `unpack` [#2386](https://github.com/clash-lang/clash-compiler/issues/2386). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ADDED: Add `Clash.XException.ShowX` instance for `Foreign.C.Types.CUShort`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ | |
Copyright : (C) 2013-2016, University of Twente, | ||
2016-2017, Myrtle Software Ltd, | ||
2017-2022, Google Inc., | ||
2017-2022, QBayLogic B.V. | ||
2017-2023, QBayLogic B.V. | ||
2023, LumiGuide Fietsdetectie B.V. | ||
License : BSD2 (see the file LICENSE) | ||
Maintainer : QBayLogic B.V. <[email protected]> | ||
-} | ||
|
@@ -2202,6 +2203,127 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of | |
-> reduce (boolToBoolLiteral tcm ty (s1 == s2)) | ||
| otherwise -> error (show args) | ||
|
||
"Clash.Class.BitPack.Internal.packInt8#" -- :: Int8 -> BitVector 8 | ||
| [DC _ [Left arg]] <- args | ||
, eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind | ||
#if MIN_VERSION_base(4,16,0) | ||
, mach2@Machine{mStack=[],mTerm=Literal (Int8Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#else | ||
, mach2@Machine{mStack=[],mTerm=Literal (IntLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#endif | ||
-> let resTyInfo = extractTySizeInfo tcm ty tys | ||
in Just $ mach2 | ||
{ mStack = mStack mach | ||
, mTerm = mkBitVectorLit' resTyInfo 0 i | ||
} | ||
|
||
"Clash.Class.BitPack.Internal.packInt16#" -- :: Int16 -> BitVector 16 | ||
| [DC _ [Left arg]] <- args | ||
, eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind | ||
#if MIN_VERSION_base(4,16,0) | ||
, mach2@Machine{mStack=[],mTerm=Literal (Int16Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#else | ||
, mach2@Machine{mStack=[],mTerm=Literal (IntLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#endif | ||
-> let resTyInfo = extractTySizeInfo tcm ty tys | ||
in Just $ mach2 | ||
{ mStack = mStack mach | ||
, mTerm = mkBitVectorLit' resTyInfo 0 i | ||
} | ||
|
||
"Clash.Class.BitPack.Internal.packInt32#" -- :: Int32 -> BitVector 32 | ||
| [DC _ [Left arg]] <- args | ||
, eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind | ||
#if MIN_VERSION_base(4,16,0) | ||
, mach2@Machine{mStack=[],mTerm=Literal (Int32Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#else | ||
, mach2@Machine{mStack=[],mTerm=Literal (IntLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#endif | ||
-> let resTyInfo = extractTySizeInfo tcm ty tys | ||
in Just $ mach2 | ||
{ mStack = mStack mach | ||
, mTerm = mkBitVectorLit' resTyInfo 0 i | ||
} | ||
|
||
"Clash.Class.BitPack.Internal.packInt64#" -- :: Int64 -> BitVector 64 | ||
| [DC _ [Left arg]] <- args | ||
, eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind | ||
#if MIN_VERSION_base(4,16,0) | ||
, mach2@Machine{mStack=[],mTerm=Literal (Int64Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#else | ||
, mach2@Machine{mStack=[],mTerm=Literal (IntLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#endif | ||
-> let resTyInfo = extractTySizeInfo tcm ty tys | ||
in Just $ mach2 | ||
{ mStack = mStack mach | ||
, mTerm = mkBitVectorLit' resTyInfo 0 i | ||
} | ||
|
||
"Clash.Class.BitPack.Internal.packWord#" -- :: Word -> BitVector WORD_SIZE_IN_BITS | ||
| [DC _ [Left arg]] <- args | ||
, eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind | ||
, mach2@Machine{mStack=[],mTerm=Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
-> let resTyInfo = extractTySizeInfo tcm ty tys | ||
in Just $ mach2 | ||
{ mStack = mStack mach | ||
, mTerm = mkBitVectorLit' resTyInfo 0 i | ||
} | ||
|
||
"Clash.Class.BitPack.Internal.packWord8#" -- :: Word8 -> BitVector 8 | ||
| [DC _ [Left arg]] <- args | ||
, eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind | ||
#if MIN_VERSION_base(4,16,0) | ||
, mach2@Machine{mStack=[],mTerm=Literal (Word8Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#else | ||
, mach2@Machine{mStack=[],mTerm=Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#endif | ||
-> let resTyInfo = extractTySizeInfo tcm ty tys | ||
in Just $ mach2 | ||
{ mStack = mStack mach | ||
, mTerm = mkBitVectorLit' resTyInfo 0 i | ||
} | ||
|
||
"Clash.Class.BitPack.Internal.packWord16#" -- :: Word16 -> BitVector 16 | ||
| [DC _ [Left arg]] <- args | ||
, eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind | ||
#if MIN_VERSION_base(4,16,0) | ||
, mach2@Machine{mStack=[],mTerm=Literal (Word16Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#else | ||
, mach2@Machine{mStack=[],mTerm=Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#endif | ||
-> let resTyInfo = extractTySizeInfo tcm ty tys | ||
in Just $ mach2 | ||
{ mStack = mStack mach | ||
, mTerm = mkBitVectorLit' resTyInfo 0 i | ||
} | ||
|
||
"Clash.Class.BitPack.Internal.packWord32#" -- :: Word32 -> BitVector 32 | ||
| [DC _ [Left arg]] <- args | ||
, eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind | ||
#if MIN_VERSION_base(4,16,0) | ||
, mach2@Machine{mStack=[],mTerm=Literal (Word32Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#else | ||
, mach2@Machine{mStack=[],mTerm=Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#endif | ||
-> let resTyInfo = extractTySizeInfo tcm ty tys | ||
in Just $ mach2 | ||
{ mStack = mStack mach | ||
, mTerm = mkBitVectorLit' resTyInfo 0 i | ||
} | ||
|
||
"Clash.Class.BitPack.Internal.packWord64#" -- :: Word64 -> BitVector 64 | ||
| [DC _ [Left arg]] <- args | ||
, eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind | ||
#if MIN_VERSION_base(4,16,0) | ||
, mach2@Machine{mStack=[],mTerm=Literal (Word64Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#else | ||
, mach2@Machine{mStack=[],mTerm=Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#endif | ||
-> let resTyInfo = extractTySizeInfo tcm ty tys | ||
in Just $ mach2 | ||
{ mStack = mStack mach | ||
, mTerm = mkBitVectorLit' resTyInfo 0 i | ||
} | ||
|
||
"Clash.Class.BitPack.Internal.packDouble#" -- :: Double -> BitVector 64 | ||
| [DC _ [Left arg]] <- args | ||
|
@@ -2223,6 +2345,114 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of | |
, mTerm = mkBitVectorLit' resTyInfo 0 (toInteger $ (pack :: Word32 -> BitVector 32) i) | ||
} | ||
|
||
"Clash.Class.BitPack.Internal.packCUShort#" -- :: CUShort -> BitVector 16 | ||
| [DC _ [Left arg]] <- args | ||
, eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind | ||
#if MIN_VERSION_base(4,16,0) | ||
, mach2@Machine{mStack=[],mTerm=Literal (Word16Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#else | ||
, mach2@Machine{mStack=[],mTerm=Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach) | ||
#endif | ||
-> let resTyInfo = extractTySizeInfo tcm ty tys | ||
in Just $ mach2 | ||
{ mStack = mStack mach | ||
, mTerm = mkBitVectorLit' resTyInfo 0 i | ||
} | ||
|
||
"Clash.Class.BitPack.Internal.unpackInt8#" -- BitVector 8 -> Int8 | ||
| [i] <- bitVectorLiterals' args | ||
-> let resTy = getResultTy tcm ty tys | ||
val = toInteger (unpack (toBV i) :: Signed 8) | ||
#if MIN_VERSION_base(4,16,0) | ||
proj = Int8Literal | ||
#else | ||
proj = IntLiteral | ||
#endif | ||
in reduce (mkIntCLit tcm proj val resTy) | ||
|
||
"Clash.Class.BitPack.Internal.unpackInt16#" -- BitVector 16 -> Int16 | ||
| [i] <- bitVectorLiterals' args | ||
-> let resTy = getResultTy tcm ty tys | ||
val = toInteger (unpack (toBV i) :: Signed 16) | ||
#if MIN_VERSION_base(4,16,0) | ||
proj = Int16Literal | ||
#else | ||
proj = IntLiteral | ||
#endif | ||
in reduce (mkIntCLit tcm proj val resTy) | ||
|
||
"Clash.Class.BitPack.Internal.unpackInt32#" -- BitVector 32 -> Int32 | ||
| [i] <- bitVectorLiterals' args | ||
-> let resTy = getResultTy tcm ty tys | ||
val = toInteger (unpack (toBV i) :: Signed 32) | ||
#if MIN_VERSION_base(4,16,0) | ||
proj = Int32Literal | ||
#else | ||
proj = IntLiteral | ||
#endif | ||
in reduce (mkIntCLit tcm proj val resTy) | ||
|
||
"Clash.Class.BitPack.Internal.unpackInt64#" -- BitVector 64 -> Int64 | ||
| [i] <- bitVectorLiterals' args | ||
-> let resTy = getResultTy tcm ty tys | ||
val = toInteger (unpack (toBV i) :: Signed 64) | ||
#if MIN_VERSION_base(4,16,0) | ||
proj = Int64Literal | ||
#else | ||
proj = IntLiteral | ||
#endif | ||
in reduce (mkIntCLit tcm proj val resTy) | ||
|
||
"Clash.Class.BitPack.Internal.unpackWord#" -- BitVector WORD_SIZE_IN_BITS -> Word | ||
| [i] <- bitVectorLiterals' args | ||
-> let resTy = getResultTy tcm ty tys | ||
val = toInteger (unpack (toBV i) :: Unsigned 64) | ||
in reduce (mkIntCLit tcm WordLiteral val resTy) | ||
|
||
"Clash.Class.BitPack.Internal.unpackWord8#" -- BitVector 8 -> Word8 | ||
| [i] <- bitVectorLiterals' args | ||
-> let resTy = getResultTy tcm ty tys | ||
val = toInteger (unpack (toBV i) :: Unsigned 8) | ||
#if MIN_VERSION_base(4,16,0) | ||
proj = Word8Literal | ||
#else | ||
proj = WordLiteral | ||
#endif | ||
in reduce (mkIntCLit tcm proj val resTy) | ||
|
||
"Clash.Class.BitPack.Internal.unpackWord16#" -- BitVector 16 -> Word16 | ||
| [i] <- bitVectorLiterals' args | ||
-> let resTy = getResultTy tcm ty tys | ||
val = toInteger (unpack (toBV i) :: Unsigned 16) | ||
#if MIN_VERSION_base(4,16,0) | ||
proj = Word16Literal | ||
#else | ||
proj = WordLiteral | ||
#endif | ||
in reduce (mkIntCLit tcm proj val resTy) | ||
|
||
"Clash.Class.BitPack.Internal.unpackWord32#" -- BitVector 32 -> Word32 | ||
| [i] <- bitVectorLiterals' args | ||
-> let resTy = getResultTy tcm ty tys | ||
val = toInteger (unpack (toBV i) :: Unsigned 32) | ||
#if MIN_VERSION_base(4,16,0) | ||
proj = Word32Literal | ||
#else | ||
proj = WordLiteral | ||
#endif | ||
in reduce (mkIntCLit tcm proj val resTy) | ||
|
||
"Clash.Class.BitPack.Internal.unpackWord64#" -- BitVector 64 -> Word64 | ||
| [i] <- bitVectorLiterals' args | ||
-> let resTy = getResultTy tcm ty tys | ||
val = toInteger (unpack (toBV i) :: Unsigned 64) | ||
#if MIN_VERSION_base(4,16,0) | ||
proj = Word64Literal | ||
#else | ||
proj = WordLiteral | ||
#endif | ||
in reduce (mkIntCLit tcm proj val resTy) | ||
|
||
"Clash.Class.BitPack.Internal.unpackFloat#" | ||
| [i] <- bitVectorLiterals' args | ||
-> let resTy = getResultTy tcm ty tys | ||
|
@@ -2235,6 +2465,17 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of | |
val = unpack (toBV i :: BitVector 64) | ||
in reduce (mkDoubleCLit tcm val resTy) | ||
|
||
"Clash.Class.BitPack.Internal.unpackCUShort#" | ||
| [i] <- bitVectorLiterals' args | ||
-> let resTy = getResultTy tcm ty tys | ||
val = toInteger (unpack (toBV i) :: Unsigned 16) | ||
#if MIN_VERSION_base(4,16,0) | ||
proj = Word16Literal | ||
#else | ||
proj = WordLiteral | ||
#endif | ||
in reduce (mkIntCLit tcm proj val resTy) | ||
|
||
"Clash.Class.BitPack.Internal.xToBV" | ||
| isSubj | ||
, Just (nTy, kn) <- extractKnownNat tcm tys | ||
|
@@ -2793,7 +3034,7 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of | |
"Clash.Sized.Internal.Index.fromEnum#" | ||
| [i] <- indexLiterals' args | ||
-> let resTy = getResultTy tcm ty tys | ||
in reduce (mkIntCLit tcm i resTy) | ||
in reduce (mkIntCLit tcm IntLiteral i resTy) | ||
|
||
-- Bounded | ||
"Clash.Sized.Internal.Index.maxBound#" | ||
|
@@ -2910,7 +3151,7 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of | |
"Clash.Sized.Internal.Signed.fromEnum#" | ||
| [i] <- signedLiterals' args | ||
-> let resTy = getResultTy tcm ty tys | ||
in reduce (mkIntCLit tcm i resTy) | ||
in reduce (mkIntCLit tcm IntLiteral i resTy) | ||
|
||
-- Bounded | ||
"Clash.Sized.Internal.Signed.minBound#" | ||
|
@@ -3128,7 +3369,7 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of | |
"Clash.Sized.Internal.Unsigned.fromEnum#" | ||
| [i] <- unsignedLiterals' args | ||
-> let resTy = getResultTy tcm ty tys | ||
in reduce (mkIntCLit tcm i resTy) | ||
in reduce (mkIntCLit tcm IntLiteral i resTy) | ||
|
||
-- Bounded | ||
"Clash.Sized.Internal.Unsigned.minBound#" | ||
|
@@ -4709,9 +4950,9 @@ bitVectorLitIntLit tcm tys args | |
| otherwise | ||
= Nothing | ||
|
||
mkIntCLit :: TyConMap -> Integer -> Type -> Term | ||
mkIntCLit tcm lit resTy = | ||
App (Data intDc) (Literal (IntLiteral lit)) | ||
mkIntCLit :: TyConMap -> (Integer -> Literal) -> Integer -> Type -> Term | ||
mkIntCLit tcm proj lit resTy = | ||
App (Data intDc) (Literal (proj lit)) | ||
where | ||
(_, tyView -> TyConApp intTcNm []) = splitFunForallTy resTy | ||
Just intTc = UniqMap.lookup intTcNm tcm | ||
|
@@ -5045,7 +5286,7 @@ liftBitVector2CInt | |
liftBitVector2CInt tcm resTy f args _p | ||
| [i] <- bitVectorLiterals' args | ||
= let val = f (toBV i) | ||
in Just $ mkIntCLit tcm val resTy | ||
in Just $ mkIntCLit tcm IntLiteral val resTy | ||
| otherwise | ||
= Nothing | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeps the line limit sensible