-
Notifications
You must be signed in to change notification settings - Fork 298
[Merged by Bors] - refactor(tactic/polyrith): use the autogenerated json parser #15429
Conversation
Thanks for this! This will conflict with #15425 and should be merged first. I'm closing Lean for a bit but will review soon -- it looks like a huge improvement! |
src/tactic/polyrith.lean
Outdated
let e : exceptional (sage_json_success ⊕ sage_json_failure) := | ||
-- try the error format first, so that if both fail we get the message from the success parser | ||
(sum.inr <$> of_json sage_json_failure j) <|> (sum.inl <$> of_json sage_json_success j), | ||
match e with | ||
| exceptional.exception f := exceptional.exception (λ s, format!"internal json error: " ++ f s) | ||
| exceptional.success (sum.inr f) := | ||
fail!"polyrith failed to retrieve a solution from Sage! {f.error_name}: {f.error_value}" | ||
| exceptional.success (sum.inl s) := do | ||
do { some t ← pure s.trace | skip, tactic.trace t}, | ||
pure s.data | ||
end |
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.
let e : exceptional (sage_json_success ⊕ sage_json_failure) := | |
-- try the error format first, so that if both fail we get the message from the success parser | |
(sum.inr <$> of_json sage_json_failure j) <|> (sum.inl <$> of_json sage_json_success j), | |
match e with | |
| exceptional.exception f := exceptional.exception (λ s, format!"internal json error: " ++ f s) | |
| exceptional.success (sum.inr f) := | |
fail!"polyrith failed to retrieve a solution from Sage! {f.error_name}: {f.error_value}" | |
| exceptional.success (sum.inl s) := do | |
do { some t ← pure s.trace | skip, tactic.trace t}, | |
pure s.data | |
end | |
(do f ← of_json sage_json_failure j, | |
fail!"polyrith failed to retrieve a solution from Sage! {f.error_name}: {f.error_value}") <|> | |
(do s ← decorate_ex "internal json error: " $ of_json sage_json_success j, | |
s.trace.mmap trace, | |
pure s.data) |
I think this is a slicker version of the same thing!
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.
That doesn't work correctly, because if an error message is recieved the failure is treated as a parsing failure, and then it tries to reparse as a success message. Still a helpful comment though, I didn't know about decorate_ex
and didn't think of option.mmap
!
/-- A schema for failure messages from the python script -/ | ||
@[derive [non_null_json_serializable, inhabited]] | ||
structure sage_json_failure := | ||
(success : {b : bool // b = ff}) |
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.
I trust this is right (also because it works), but what's the significance of this weird subtype? Is the idea that only json data with success: false
should be parsed into this type? Is the non_null_json_serializable
derive handler the part that's taking this into account?
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.
The subtype.non_null_json_serializable
parser is the one that handles this; it parses the value, and uses decidability for the proof.
I could also have used
(success : {b : bool // b = ff}) | |
(success : bool) | |
(success_eq_ff : success = ff) |
and then the derive handler would have handled it; but then the inhabited
derive handler (which I'm using only to appease the linter) wouldn't have worked.
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.
Thanks!
bors merge |
This acts as a nice demonstration of how to use `@[derive non_null_json_serializable]`
Build failed (retrying...): |
This acts as a nice demonstration of how to use `@[derive non_null_json_serializable]`
This PR was included in a batch that was canceled, it will be automatically retried |
This acts as a nice demonstration of how to use `@[derive non_null_json_serializable]`
Pull request successfully merged into master. Build succeeded: |
This acts as a nice demonstration of how to use `@[derive non_null_json_serializable]`
This acts as a nice demonstration of how to use
@[derive non_null_json_serializable]