-
-
Notifications
You must be signed in to change notification settings - Fork 57
Do not print stdout and stderr in stanc.js #762
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,21 +45,20 @@ let stan2cpp model_name model_string flags = | |
| "Semantic check failed but reported no errors. This should never \ | ||
| happen." | ||
| in | ||
| if is_flag_set "version" then Result.Ok (Fmt.strf "%s" version, []) | ||
| if is_flag_set "version" then Result.Ok (Fmt.strf "%s" version) | ||
| else | ||
| Result.bind ast | ||
| ~f: | ||
| (Fn.compose semantic_err_to_string | ||
| Semantic_check.semantic_check_program) | ||
| |> Result.map ~f:(fun typed_ast -> | ||
| if is_flag_set "print-canonical" then | ||
| ( Pretty_printing.pretty_print_typed_program | ||
| (Canonicalize.canonicalize_program typed_ast) | ||
| , [] ) | ||
| Pretty_printing.pretty_print_typed_program | ||
| (Canonicalize.canonicalize_program typed_ast) | ||
| else if is_flag_set "auto-format" then | ||
| match ast with | ||
| | Result.Ok f -> (Pretty_printing.pretty_print_program f, []) | ||
| | _ -> ("Error: This should not happend!", []) | ||
| | Result.Ok f -> Pretty_printing.pretty_print_program f | ||
| | _ -> "Error: This should not happend!" | ||
| else | ||
| let mir = Ast_to_Mir.trans_prog model_name typed_ast in | ||
| let tx_mir = Transform_Mir.trans_prog mir in | ||
|
|
@@ -72,21 +71,26 @@ let stan2cpp model_name model_string flags = | |
| Pedantic_analysis.print_warn_uninitialized mir ; | ||
| if is_flag_set "warn-pedantic" then | ||
| Pedantic_analysis.print_warn_pedantic mir ; | ||
| (cpp, []) ) | ||
| cpp ) | ||
|
|
||
| let stanc_stdout = ref "" | ||
| let stanc_stderr = ref "" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to use a list or something?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, a list would be constant time to append to instead of O(N) |
||
|
|
||
| let wrap_result = function | ||
| | Result.Ok (s, k) -> | ||
| | Result.Ok s -> | ||
| Js.Unsafe.obj | ||
| [| ("result", Js.Unsafe.inject (Js.string s)) | ||
| ; ( "warnings" | ||
| , Js.Unsafe.inject | ||
| (Js.array (List.to_array (List.map ~f:Js.string k))) ) |] | ||
| ; ("warnings", Js.Unsafe.inject (Js.string !stanc_stderr)) |] | ||
| | Error e -> | ||
| Js.Unsafe.obj | ||
| [| ("errors", Js.Unsafe.inject (Array.map ~f:Js.string [|e|])) | ||
| ; ("warnings", Js.Unsafe.inject Js.array_empty) |] | ||
| ; ("warnings", Js.Unsafe.inject (Js.string !stanc_stderr)) |] | ||
|
|
||
| let stan2cpp_wrapped name code (flags : Js.string_array Js.t Js.opt) = | ||
| stanc_stdout := "" ; | ||
| stanc_stderr := "" ; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to reset every time because these are global variables. If we don't, we just accumulate warnings from all previous compilations.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A better pattern would be to have the components return warnings and errors rather than printing them. Could we do that instead or would that mess up the timing for a release or something?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was my first plan, but I quickly realized that is a pretty big refactor. Particulary not sure on how to return from the parser for example. |
||
| Sys_js.set_channel_flusher stdout (fun s -> stanc_stdout := !stanc_stdout ^ s) ; | ||
| Sys_js.set_channel_flusher stderr (fun s -> stanc_stderr := !stanc_stderr ^ s) ; | ||
| stan2cpp (Js.to_string name) (Js.to_string code) | ||
| Js.( | ||
| Opt.map flags (fun a -> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| var stanc = require('../../src/stancjs/stancjs.bc.js'); | ||
| var utils = require("./utils/utils.js"); | ||
|
|
||
| var deprecated_model = ` | ||
| parameters { | ||
| real y; | ||
| # hash comment is deprecated | ||
| } | ||
| model { | ||
| y ~ normal(0,1); | ||
| } | ||
| ` | ||
| var deprecated_test = stanc.stanc("deprecated", deprecated_model); | ||
| console.log(deprecated_test.warnings) |
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 think we want to do something to keep the ability for phases of the compiler to return warnings rather than delete these for-now empty lists.