Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Improve inline source mapping and error reporting #349

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

arichiardi
Copy link
Collaborator

@arichiardi arichiardi commented Feb 4, 2018

This patch follows some guidelines from Planck and aims at improving source map
consumption in lumo.

The first step was to enable source maps in case of a "load form" (require, ...)
and to refactor make-eval-opts so that it can be reused in repl.cljs. After that the :source-maps key needs to be passed to the cljs.stacktrace machinery for mapping. Additionally, we patch every instance of <embedded> in stacktrace entries so that we can read from the bundled main.js.map file the mapping.

This patch changes this:

1 is not ISeqable
	 Object.cljs.core.seq (NO_SOURCE_FILE <embedded>:506:410)
	 Object.cljs.core.first (NO_SOURCE_FILE <embedded>:507:213)
	 cljs.core.ffirst (NO_SOURCE_FILE <embedded>:567:464)
	 (evalmachine.<anonymous>:1:18)
	 ContextifyScript.Script.runInThisContext (vm.cljs:50:33)
	 Object.runInThisContext (vm.cljs:139:38)
	 (Object.ft)
	 (Object.lumo.repl.caching_node_eval)
	 (NO_SOURCE_FILE <embedded>:5837:273)
	 E (NO_SOURCE_FILE <embedded>:5838:269)

To this:

1 is not ISeqable
        cljs.core/seq (cljs/core.cljs:1223:20)
	cljs.core/first (cljs/core.cljs:1232:16)
	cljs.core/ffirst (cljs/core.cljs:1744:11)
	ContextifyScript/Script/runInThisContext (vm.cljs:50:33)
	vm/runInThisContext (vm.cljs:139:38)

A couple of glitches in ClojureScript where identified and fixed (CLJS-2492 and CLJS-2493) so probably some parts will evolve more in the future but this is mapping fine now! 🎉 👍 🥇

Note that the loading of main.js.map is onerous the first time that it is done and the patching should be considered an experimental feature.

Also big thanks to @mfikes for doing the custom parsing and demunging for planck.

@arichiardi arichiardi changed the title Improve source maps WIP - Improve source maps Feb 4, 2018
@arichiardi arichiardi requested a review from anmonteiro February 4, 2018 03:30
@arichiardi arichiardi changed the title WIP - Improve source maps WIP - Improve source mapping and error reporting Feb 4, 2018
@arichiardi arichiardi changed the title WIP - Improve source mapping and error reporting WIP - Improve inline source mapping and error reporting Feb 5, 2018
@arichiardi arichiardi force-pushed the improve-source-maps branch 2 times, most recently from b8c7b66 to 33ce429 Compare February 8, 2018 01:51
@arichiardi arichiardi changed the title WIP - Improve inline source mapping and error reporting Improve inline source mapping and error reporting Feb 8, 2018
@arichiardi arichiardi force-pushed the improve-source-maps branch 2 times, most recently from ff56240 to 42f262c Compare February 9, 2018 00:14
@arichiardi
Copy link
Collaborator Author

arichiardi commented Feb 14, 2018

CLJS-2493 got applied.

CLJS-2492 did not, but David suggested a different approach for reading/writing source maps I can try

@arichiardi
Copy link
Collaborator Author

arichiardi commented Feb 14, 2018

I updated the code in order to include planck-repl/planck@27a8e07 and planck-repl/planck@15a89b0 as well.

I tried to compile against the latest master of ClojureScript but I get a weird error with the cache-edn->transit step of the build.

@arichiardi
Copy link
Collaborator Author

There is a new patch for CLJS-2492, waiting for some feedback.

@arichiardi
Copy link
Collaborator Author

CLJS-2492 has been merged! I will rebase this branch on master but I feel #353 should go in first so that it is easier to build against newer ClojureScript versions. What do you think @anmonteiro?

@arichiardi arichiardi changed the title Improve inline source mapping and error reporting WIP - Improve inline source mapping and error reporting Feb 20, 2018
@arichiardi arichiardi changed the title WIP - Improve inline source mapping and error reporting Improve inline source mapping and error reporting Feb 20, 2018
@arichiardi
Copy link
Collaborator Author

arichiardi commented Feb 25, 2018

@anmonteiro this basically does part of the work you have in the older https://github.com/anmonteiro/lumo/commits/smaps.

It does not have core files and source maps loading but it works pretty well at the REPL because every required namespace already populates the :source-maps compiler key now that the two ClojureScript patches are in.

How about merging and adding core file maps on top? In a separate PR I mean?

@arichiardi arichiardi force-pushed the improve-source-maps branch from 5f49e7b to 313cbfe Compare March 18, 2018 19:47
@arichiardi arichiardi force-pushed the improve-source-maps branch from 313cbfe to 3dd2561 Compare April 3, 2018 21:39
@arichiardi
Copy link
Collaborator Author

Rebased.

@arichiardi arichiardi force-pushed the improve-source-maps branch 2 times, most recently from f94fa15 to 323bff1 Compare April 5, 2018 20:47
@arichiardi arichiardi force-pushed the improve-source-maps branch from 323bff1 to e013702 Compare May 7, 2018 18:35
@arichiardi arichiardi changed the title Improve inline source mapping and error reporting WIP - Improve inline source mapping and error reporting May 8, 2018
@arichiardi
Copy link
Collaborator Author

Back into WIP mode in order to add the final hack touch 😄

@arichiardi arichiardi force-pushed the improve-source-maps branch 6 times, most recently from 6272fd0 to a7ae700 Compare May 15, 2018 17:42
@arichiardi arichiardi changed the title WIP - Improve inline source mapping and error reporting Improve inline source mapping and error reporting May 15, 2018
@arichiardi arichiardi requested a review from mfikes May 15, 2018 17:53
@arichiardi
Copy link
Collaborator Author

This should be ready to review, I added Mike as well for visibility 👍 but probably things are slightly different in planck regarding source maps.

@arichiardi arichiardi force-pushed the improve-source-maps branch 3 times, most recently from a0eea8f to 6ff8914 Compare May 15, 2018 18:40
This patch enables source maps for expressions that include a load form and
only for that. Eval option decision-making is now centralized in
make-eval-opts.
Thanks to CLJS-2492 we can safely pass a namespace to the name parameter and
this will be used as key in (:source-maps @st). The namespace will be extracted
from the input expression if and only if it is a ns form.
The patch follows in the footsteps of Planck, reading from (:source-maps @st),
introducing calls to cljs.stacktrace and printing out the stack traces.
@arichiardi arichiardi force-pushed the improve-source-maps branch from 6ff8914 to 1d361b1 Compare May 18, 2018 22:18
Copy link
Collaborator

@mfikes mfikes left a comment

Choose a reason for hiding this comment

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

LGTM, but hard to tell without running the code.

@arichiardi
Copy link
Collaborator Author

Yep this is actually slowing down things, especially the guessing part. It is there mainly for showing what is possible with some magic (aka - stack trace string parsing).

I was able to get Clojure-like stack traces 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants