Skip to content

Do not print stdout and stderr in stanc.js - #762

Closed
rok-cesnovar wants to merge 2 commits into
masterfrom
stancjs_dont_print_warnings
Closed

Do not print stdout and stderr in stanc.js#762
rok-cesnovar wants to merge 2 commits into
masterfrom
stancjs_dont_print_warnings

Conversation

@rok-cesnovar

Copy link
Copy Markdown
Member

Fixes #741

Stdout and stderr in stanc.js are rerouted to a ref (is there a more Ocamlish solution?) and the contents of stderr are returned as the warnings element of the return object. Stdout is ignored.

I think this is the more Javascript way of doing it and for use in Rstan we have to avoid printing anyways (see issue).
Currently, in order to print pedantic warnings in a browser, I had to reroute windows.console.error which is not how we want our API to work.

Release notes

Removed stdout and stderr in stanc.js.

Copyright and Licensing

By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)

Comment thread src/stancjs/stancjs.ml

let stan2cpp_wrapped name code (flags : Js.string_array Js.t Js.opt) =
stanc_stdout := "" ;
stanc_stderr := "" ;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.

Comment thread src/stancjs/stancjs.ml
cpp )

let stanc_stdout = ref ""
let stanc_stderr = ref ""

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to use a list or something?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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)

@rok-cesnovar

rok-cesnovar commented Dec 9, 2020

Copy link
Copy Markdown
Member Author

@seantalts sorry to keep tagging you with these stanc.js PRs, not sure who else knows enough about this.

If anyone else feels they can review this, feel free.

@wds15

wds15 commented Dec 9, 2020

Copy link
Copy Markdown

Let's hope this is the last wall for rstan to cross over... this is getting heroic to make it work.

@rok-cesnovar

Copy link
Copy Markdown
Member Author

The critical stuff should hopefully now be squashed.

We need to find a better way to support includes but that can be workaround for now.

@wds15

wds15 commented Dec 9, 2020

Copy link
Copy Markdown

We should make bets on a 2020 or a 2021 rstan 2.25...

@rok-cesnovar

Copy link
Copy Markdown
Member Author

Bump. Anyone up for reviewing this?

@seantalts

Copy link
Copy Markdown
Member

Taking a look!

Comment thread src/stancjs/stancjs.ml
cpp )

let stanc_stdout = ref ""
let stanc_stderr = ref ""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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)

Comment thread src/stancjs/stancjs.ml

let stan2cpp_wrapped name code (flags : Js.string_array Js.t Js.opt) =
stanc_stdout := "" ;
stanc_stderr := "" ;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

Comment thread src/stancjs/stancjs.ml
"Semantic check failed but reported no errors. This should never \
happen."
in
if is_flag_set "version" then Result.Ok (Fmt.strf "%s" version, [])

Copy link
Copy Markdown
Member

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.

@rok-cesnovar

Copy link
Copy Markdown
Member Author

Closing in favor of #777

@rok-cesnovar
rok-cesnovar deleted the stancjs_dont_print_warnings branch December 27, 2020 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

javascript parser chokes on #-style comments

3 participants