-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Inspection tests for Prisms #28
Comments
Tests are implemented, but they are failing after initial performance improvements. Current GHC Core result: test/Test/Prolens/Inspection.hs:89:1: matchMarkPrism === matchMarkManual failed:
LHS:
matchMarkPrism :: Grade -> Maybe Int
[LclIdX,
Arity=1,
Str=<S,1*U>,
Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True,
Guidance=ALWAYS_IF(arity=0,unsat_ok=True,boring_ok=True)
Tmpl= matchMarkPrism_s6zt
`cast` (<Grade>_R ->_R N:First[0] <Int>_N
:: Coercible (Grade -> First Int) (Grade -> Maybe Int))}]
matchMarkPrism
= matchMarkPrism_s6zt
`cast` (<Grade>_R ->_R N:First[0] <Int>_N
:: Coercible (Grade -> First Int) (Grade -> Maybe Int))
matchMarkPrism_s6zt :: Grade -> First Int
[LclId,
Arity=1,
Str=<S,1*U>,
Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True,
Guidance=ALWAYS_IF(arity=1,unsat_ok=True,boring_ok=False)
Tmpl= \ (x [Occ=Once!] :: Grade) ->
case x of {
Mark a [Occ=Once] ->
(Just @ Int a)
`cast` (Nth:3 (<Int>_R ->_R Sym (N:First[0]) <Int>_N)
:: Coercible (Maybe Int) (First Int));
Other _ [Occ=Dead] ->
(Nothing @ Int)
`cast` (Sym (N:First[0]) <Int>_N
:: Coercible (Maybe Int) (First Int))
}}]
matchMarkPrism_s6zt
= \ (x [Dmd=<S,1*U>] :: Grade) ->
case x of {
Mark a ->
(Just @ Int a)
`cast` (Nth:3 (<Int>_R ->_R Sym (N:First[0]) <Int>_N)
:: Coercible (Maybe Int) (First Int));
Other ipv [Dmd=<L,A>] ->
(Nothing @ Int)
`cast` (Sym (N:First[0]) <Int>_N
:: Coercible (Maybe Int) (First Int))
}
RHS:
matchMarkManual :: Grade -> Maybe Int
[LclIdX,
Arity=1,
Str=<S,1*U>,
Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True,
Guidance=ALWAYS_IF(arity=1,unsat_ok=True,boring_ok=False)
Tmpl= \ (grade [Occ=Once!] :: Grade) ->
case grade of {
Mark n [Occ=Once] -> Just @ Int n;
Other _ [Occ=Dead] -> Nothing @ Int
}}]
matchMarkManual
= \ (grade [Dmd=<S,1*U>] :: Grade) ->
case grade of {
Mark n -> Just @ Int n;
Other ipv [Dmd=<L,A>] -> Nothing @ Int
} |
Hi @chshersh I'm also getting an error when I run the tests Performance Inspection Testing for Lens: test/Test/Prolens/Inspection.hs:52:13:
1) Performance Inspection Testing, Lens, set, setting single via lens is efficient as manual record update
predicate failed on: Failure "test/Test/Prolens/Inspection.hs:52:15: ... " The expanded error message is the following: setNameViaLens === setNameManually failed:
LHS:
setNameViaLens :: Haskeller -> Haskeller
[LclIdX,
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=False, ConLike=False,
WorkFree=False, Expandable=False, Guidance=IF_ARGS [] 110 0}]
setNameViaLens
= set
@ (->)
@ Haskeller
@ Haskeller
@ String
@ String
(Eq# @ (* -> * -> *) @ (->) @ (->) @~ (<(->)>_N :: (->) ~ (->)))
(nameL @ (->) $fStrong->)
(unpackCString# "Dmitrii"#)
RHS:
setNameManually :: Haskeller -> Haskeller
[LclIdX,
Arity=1,
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True, Guidance=IF_ARGS [20] 70 40}]
setNameManually
= \ (h :: Haskeller) ->
case h of { Haskeller ds_dcjT ds_dcjU ds_dcjV ->
Haskeller (unpackCString# "Dmitrii"#) ds_dcjU ds_dcjV
} I think I'm not enabling a flag or something similar. Please, let me know and I could give it a try. |
Hi @CristhianMotoche! I think you build the project without optimizations. E.g. by passing the By default, Cabal passes cabal clean
cabal test all -O2 --enable-tests |
Thanks @chshersh I enabled |
I've never done inspection testing before, so it could take me some time to address this issue. |
Hi! I'm continue learning about inspection testing. The first thing that I tried was to see less Core so I added a few GHC flags as suggested in the inspection-testing library and the output looks like this:
They look almost the same except by this Thanks in advance. |
@CristhianMotoche Great work! 👏 Yes, that's I saw as well. The implementations in Core are almost identical. So the performance of both implementations should be the same. AFAIK, Haskell implements zero-cost coercions, so those two functions must be the same in terms of performance. But, because the look differently in Core, the test with I would love to have an answer to that! Possible solutions: fix the To move this forward, I can recommend the following steps:
|
@CristhianMotoche I managed to make it work! |
I'm glad to know you solved it @vrom911 Good job! 🎉 🙂 |
No description provided.
The text was updated successfully, but these errors were encountered: