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

Tidy up SimpleJSON.hs #5936

Merged
merged 1 commit into from
Apr 30, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ instance FromJSON Model where
{- We always have an "arguments" field which is a Value. Usually it's
actually an Object (ie, a map) representing a linear function, but
sometimes it contains other data, and in those cases we need to
coerce it to an Object (with objOf) to extract the relevant date.
coerce it to an Object (with objOf) to extract the relevant data.
We could do that once here and rely on laziness to save us in the
cases when we don't have an Object, but that looks a bit misleading. -}
case ty of
Expand All @@ -93,18 +93,14 @@ instance FromJSON Model where
"quadratic_in_y" -> QuadraticInY <$> parseJSON args
"quadratic_in_z" -> QuadraticInZ <$> parseJSON args
"literal_in_y_or_linear_in_z" -> LiteralInYOrLinearInZ <$> parseJSON args
"subtracted_sizes" ->
SubtractedSizes <$> parseJSON args <*> objOf args .: "minimum"
"const_above_diagonal" ->
let o = objOf args in ConstAboveDiagonal <$> o .: "constant" <*> o .: "model"
"const_below_diagonal" ->
let o = objOf args in ConstBelowDiagonal <$> o .: "constant" <*> o .: "model"
"const_off_diagonal" ->
let o = objOf args in ConstOffDiagonal <$> o .: "constant" <*> o .: "model"
-- An adaptor to deal with the old "linear_on_diagonal" tag. See Note [Backward
-- compatibility for costing functions]. We never want to convert back to JSON here,
-- so it's OK to forget that we originally got something tagged with
-- "linear_on_diagonal".
"subtracted_sizes" -> SubtractedSizes <$> parseJSON args <*> objOf args .: "minimum"
"const_above_diagonal" -> modelWithConstant ConstAboveDiagonal args
"const_below_diagonal" -> modelWithConstant ConstBelowDiagonal args
"const_off_diagonal" -> modelWithConstant ConstOffDiagonal args
{- An adaptor to deal with the old "linear_on_diagonal" tag. See Note [Backward
compatibility for costing functions]. We never want to convert back to JSON
here, so it's OK to forget that we originally got something tagged with
"linear_on_diagonal". -}
"linear_on_diagonal" ->
let o = objOf args
in do
Expand All @@ -119,6 +115,9 @@ instance FromJSON Model where
objOf _ =
errorWithoutStackTrace "Failed to get Object while parsing \"arguments\""

modelWithConstant constr x = constr <$> o .: "constant" <*> o .: "model"
where o = objOf x

{- | A CPU usage modelling function and a memory usage modelling function bundled
together -}
data CpuAndMemoryModel = CpuAndMemoryModel {cpuModel :: Model, memoryModel :: Model}
Expand Down