ClojureScript

Docstrings are included in compiled output

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Trivial Trivial
  • Resolution: Completed
  • Affects Version/s: 1.9.293
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code

Description

Looking at code compiled with 'advanced':

$cljs$core$cst$0sym$0_STAR_print_DASH_base_STAR_$$, "target/release-browser/cljs/pprint.cljs", 13, 1, !0, 672, 675, $cljs$core$List$EMPTY$$, "The base to use for printing integers and rationals.", $cljs$core$truth_$$($cljs$pprint$STAR_print_base_STAR$$) ? $cljs$pprint$STAR_print_base_STAR$$.$cljs$lang$test$ : null]))]);

...

$cljs$core$cst$0sym$0cljs$0pprint$$, $cljs$core$cst$0sym$0_STAR_print_DASH_right_DASH_margin_STAR_$$, "target/release-browser/cljs/pprint.cljs", 22, 1, !0, 625, 630, $cljs$core$List$EMPTY$$, "Pretty printing will try to avoid anything going beyond this column.\nSet it to nil to have pprint let the line be arbitrarily long. This will ignore all\nnon-mandatory newlines.", $cljs$core$truth_$$($cljs$pprint$STAR_print_right_margin_STAR$$) ? $cljs$pprint$STAR_print_right_margin_STAR$$.$cljs$lang$test$ :

It looks like docstrings aren't stripped from dynamic vars, only from functions.

This is a bit of a waste of space...

Activity

Hide
António Nuno Monteiro added a comment -

I'm not seeing this behavior. Can you provide a minimal repro which exhibits the bug you're seeing?

Show
António Nuno Monteiro added a comment - I'm not seeing this behavior. Can you provide a minimal repro which exhibits the bug you're seeing?
Hide
Richard Newman added a comment -
Show
Richard Newman added a comment - Here's a repro case. https://github.com/rnewman/cljs-1853
Hide
António Nuno Monteiro added a comment -

After some investigation, the issue seems unrelated to the description of this ticket.

Specifically, the problem occurs because there's a map which refers to Vars directly. See:
https://github.com/clojure/clojurescript/blob/95fd110f55c57b890422763ed8f2644cfbf159de/src/main/cljs/cljs/pprint.cljs#L692

Show
António Nuno Monteiro added a comment - After some investigation, the issue seems unrelated to the description of this ticket. Specifically, the problem occurs because there's a map which refers to Vars directly. See: https://github.com/clojure/clojurescript/blob/95fd110f55c57b890422763ed8f2644cfbf159de/src/main/cljs/cljs/pprint.cljs#L692
Hide
Richard Newman added a comment -

Feel free to rename the ticket to "Required library code that includes a map that refers to vars that have associated metadata results in that metadata appearing in the compiled output, regardless of whether the metadata is ever accessed".

From an optimization perspective, I regard this behavior (however you'd like to characterize it!) as a bug — code that simply requires and uses 'cljs.pprint' ends up, when compiled at any optimization level, containing a pile of unused verbose English strings.

Show
Richard Newman added a comment - Feel free to rename the ticket to "Required library code that includes a map that refers to vars that have associated metadata results in that metadata appearing in the compiled output, regardless of whether the metadata is ever accessed". From an optimization perspective, I regard this behavior (however you'd like to characterize it!) as a bug — code that simply requires and uses 'cljs.pprint' ends up, when compiled at any optimization level, containing a pile of unused verbose English strings.
Hide
Richard Newman added a comment -

It seems like an easy 'fix' for this specific issue is to just delete `write-option-table` entirely — it's private and unused. But I don't see why `write-option-table` wouldn't be discarded by the compiler or the optimizer, and even if it exists I don't see why unused metadata wouldn't be stripped. So perhaps that's three bugs of varying specificity, each of which would make ClojureScript a little bit more production-ready.

Show
Richard Newman added a comment - It seems like an easy 'fix' for this specific issue is to just delete `write-option-table` entirely — it's private and unused. But I don't see why `write-option-table` wouldn't be discarded by the compiler or the optimizer, and even if it exists I don't see why unused metadata wouldn't be stripped. So perhaps that's three bugs of varying specificity, each of which would make ClojureScript a little bit more production-ready.
Hide
António Nuno Monteiro added a comment -

Attached a patch commenting out the `cljs.pprint/write-option-table` map, as per the Slack discussion.

Show
António Nuno Monteiro added a comment - Attached a patch commenting out the `cljs.pprint/write-option-table` map, as per the Slack discussion.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: