Skip to content

Commit 5e17fa0

Browse files
Merge pull request #2900 from gallais/v2.0-joss-submission-mac
[ re #2896 ] Restrict clock types
2 parents c5d0315 + 0869322 commit 5e17fa0

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

src/System/Clock.agda

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,13 @@ open import System.Clock.Primitive as Prim
3737
-- System-wide monotonic time since an arbitrary point in the past
3838
; monotonic
3939
-- System-wide real time since the Epoch
40-
; realTime
40+
; realtime
4141
-- Amount of execution time of the current process
4242
; processCPUTime
4343
-- Amount of execution time of the current OS thread
4444
; threadCPUTime
4545
-- A raw hardware version of Monotonic ignoring adjustments
4646
; monotonicRaw
47-
-- Linux-specific clocks
48-
-- Similar to Monotonic, includes time spent suspended
49-
; bootTime
50-
-- Faster but less precise alternative to Monotonic
51-
; monotonicCoarse
52-
-- Faster but less precise alternative to RealTime
53-
; realTimeCoarse
5447
)
5548

5649
------------------------------------------------------------------------
@@ -86,9 +79,9 @@ record Timed (A : Set a) : Set a where
8679

8780
time : IO A IO (Timed A)
8881
time io = do
89-
start lift! $ getTime realTime
82+
start lift! $ getTime realtime
9083
a io
91-
end lift! $ getTime realTime
84+
end lift! $ getTime realtime
9285
pure $ mkTimed a $ diff (lower start) (lower end)
9386

9487
time′ : IO {0ℓ} A IO Time

src/System/Clock/Primitive.agda

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,39 @@ open import IO.Primitive using (IO)
1313
open import Foreign.Haskell using (Pair)
1414

1515
data Clock : Set where
16-
monotonic realTime processCPUTime : Clock
17-
threadCPUTime monotonicRaw bootTime : Clock
18-
monotonicCoarse realTimeCoarse : Clock
16+
monotonic realtime processCPUTime : Clock
17+
threadCPUTime monotonicRaw : Clock
1918

20-
{-# COMPILE GHC Clock = data Clock (Monotonic | Realtime | ProcessCPUTime
21-
| ThreadCPUTime | MonotonicRaw | Boottime
22-
| MonotonicCoarse | RealtimeCoarse )
19+
{-# FOREIGN GHC import System.Clock #-}
20+
21+
{-# FOREIGN GHC
22+
data AgdaClock
23+
= AgdaMonotonic
24+
| AgdaRealtime
25+
| AgdaProcessCPUTime
26+
| AgdaThreadCPUTime
27+
| AgdaMonotonicRaw
28+
29+
fromAgdaClock :: AgdaClock -> Clock
30+
fromAgdaClock ac = case ac of
31+
AgdaMonotonic -> Monotonic
32+
AgdaRealtime -> Realtime
33+
AgdaProcessCPUTime -> ProcessCPUTime
34+
AgdaThreadCPUTime -> ThreadCPUTime
35+
AgdaMonotonicRaw -> MonotonicRaw
36+
#-}
37+
38+
{-# COMPILE GHC Clock =
39+
data AgdaClock
40+
( AgdaMonotonic
41+
| AgdaRealtime
42+
| AgdaProcessCPUTime
43+
| AgdaThreadCPUTime
44+
| AgdaMonotonicRaw
45+
)
2346
#-}
2447

2548
postulate getTime : Clock IO (Pair Nat Nat)
2649

27-
{-# FOREIGN GHC import System.Clock #-}
2850
{-# FOREIGN GHC import Data.Function #-}
29-
{-# COMPILE GHC getTime = fmap (\ (TimeSpec a b) -> ((,) `on` fromIntegral) a b) . getTime #-}
51+
{-# COMPILE GHC getTime = fmap (\ (TimeSpec a b) -> ((,) `on` fromIntegral) a b) . getTime . fromAgdaClock #-}

0 commit comments

Comments
 (0)