Skip to content

Dump location mappings between intermediate representations (cmm, lambda...) and source code.#155

Merged
poechsel merged 4 commits intooxcaml:mainfrom
poechsel:ocaml_ir
Oct 27, 2021
Merged

Dump location mappings between intermediate representations (cmm, lambda...) and source code.#155
poechsel merged 4 commits intooxcaml:mainfrom
poechsel:ocaml_ir

Conversation

@poechsel
Copy link
Copy Markdown
Contributor

This PR adds a [-dlocations-mapping] flag that when used in conjunction with [-dump-into-file] and some of [-dcmm, -dflambda/ ...] will create a binary file ..dump.map holding mapping information of locations between .ml and ..dump.

These information is stored as a list of (label, location in source, location in file). No filtering is done on these so the list may include locations which are not coming from the source code but for something that has been inlined.

The implementation in itself is based on formatter:

  • Calling Tracking_formatter.create on a formatter will enhance this formatter to track locations while its being used to print some irs
  • let with_location_mapping ?label ~dbg ppf f can they be used to store a mapping between dbg and what will be printed when invoking f ().

Right now I've only implemented tracking for cmm as a proof of concept.

@mshinwell mshinwell added the driver Compiler driver label Aug 18, 2021
@poechsel poechsel force-pushed the ocaml_ir branch 2 times, most recently from 6c6ec7e to c6554bc Compare August 23, 2021 11:04
@mshinwell
Copy link
Copy Markdown
Collaborator

As discussed, can we try to rearrange the code so that this doesn't touch the ocaml/ subdirectory? This will presumably involve duplicating a couple of the printing files, but that's ok.

@poechsel
Copy link
Copy Markdown
Contributor Author

poechsel commented Sep 16, 2021

Done! I had to duplicate printast (which I've moved in a new subdirectory printer/ where future printers will go). I also had to duplicate compile_common.ml.

I've also remove the compiler flags -- location can be dumped if and only activated by calling Location_tracker_formatter.activate_tracking ()

Copy link
Copy Markdown
Contributor

@xclerc xclerc left a comment

Choose a reason for hiding this comment

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

(I am pretty sure I don't understand enough of
Format, and its semantic tags, to have anything
useful to say...)

representations

Add clflag to dump locations mapping

Add location tracker formatter

Prepare location tracker for actually tracking things

Use tracking formatter in cmm

Track locations in printast

Install optmaindriver

Expose more things in location_tracker_formatter

Remove changes from ocaml/

Only keep changes in printer
Copy link
Copy Markdown
Contributor

@gretay-js gretay-js left a comment

Choose a reason for hiding this comment

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

The new printer/printcmm_with_locations.ml is almost a duplicate of backend/printcmm.ml . It would be better to update Printcmm to work with and without location tracking, if possible, and use printer only for frontend ASTs.

@poechsel
Copy link
Copy Markdown
Contributor Author

I agree -- I moved the location tracking bit back to backend/printcmm.ml.

It can be turned on/off using Location_tracker_formatter.activate_tracking and Location_tracker_formatter.activate_tracking

@poechsel poechsel merged commit f00aed7 into oxcaml:main Oct 27, 2021
mshinwell pushed a commit that referenced this pull request Oct 29, 2021
…bda...) and source code. (#155)

Add printers able to track mappings between source code and intermediate representations
mshinwell added a commit to mshinwell/oxcaml that referenced this pull request Apr 28, 2023
6c5197b Merge pull request oxcaml#166 from mshinwell/merge-flambda-backend-2023-04-28
0c3dcf9 Fix for ocamldoc
09b9e1c Fix for -zero-alloc-check
71e5e07 Compilation fixes after merge
bf66257 Merge flambda-backend changes
a2556fc Add `[%exclave]` support (oxcaml#51)
ebe9576 Add data race freedom proposal (oxcaml#161)
3f3fc49 Merge pull request oxcaml#159 from riaqn/merge-backend
6c635dc minor changes after merge
99a0d85 Merge flambda-backend changes
2642463 Include the modes of values in debugging information (oxcaml#153)
4ecc8a4 Remove i386 CI check (oxcaml#155)

git-subtree-dir: ocaml
git-subtree-split: 6c5197b
ccasin added a commit to ccasin/oxcaml that referenced this pull request Apr 29, 2023
bba15422dbf Accept changed test, fix dune file
2f0a6b48399 Layouts version 1
6c5197b Merge pull request oxcaml#166 from mshinwell/merge-flambda-backend-2023-04-28
0c3dcf9 Fix for ocamldoc
09b9e1c Fix for -zero-alloc-check
71e5e07 Compilation fixes after merge
bf66257 Merge flambda-backend changes
a2556fc Add `[%exclave]` support (oxcaml#51)
ebe9576 Add data race freedom proposal (oxcaml#161)
3f3fc49 Merge pull request oxcaml#159 from riaqn/merge-backend
6c635dc minor changes after merge
99a0d85 Merge flambda-backend changes
2642463 Include the modes of values in debugging information (oxcaml#153)
4ecc8a4 Remove i386 CI check (oxcaml#155)

git-subtree-dir: ocaml
git-subtree-split: bba15422dbf736511e37db6ea3e952905ff406ed
mshinwell added a commit to mshinwell/oxcaml that referenced this pull request May 1, 2023
REVERT: 6c5197b Merge pull request oxcaml#166 from mshinwell/merge-flambda-backend-2023-04-28
REVERT: 0c3dcf9 Fix for ocamldoc
REVERT: 09b9e1c Fix for -zero-alloc-check
REVERT: 71e5e07 Compilation fixes after merge
REVERT: bf66257 Merge flambda-backend changes
REVERT: a2556fc Add `[%exclave]` support (oxcaml#51)
REVERT: ebe9576 Add data race freedom proposal (oxcaml#161)
REVERT: 3f3fc49 Merge pull request oxcaml#159 from riaqn/merge-backend
REVERT: 6c635dc minor changes after merge
REVERT: 99a0d85 Merge flambda-backend changes
REVERT: 2642463 Include the modes of values in debugging information (oxcaml#153)
REVERT: 4ecc8a4 Remove i386 CI check (oxcaml#155)

git-subtree-dir: ocaml
git-subtree-split: a7d005a
mshinwell added a commit to mshinwell/oxcaml that referenced this pull request May 1, 2023
e3076d2 Unboxed types v1 (oxcaml#139)
e68c72d update HACKING.jst.adoc (oxcaml#165)
6c5197b Merge pull request oxcaml#166 from mshinwell/merge-flambda-backend-2023-04-28
0c3dcf9 Fix for ocamldoc
09b9e1c Fix for -zero-alloc-check
71e5e07 Compilation fixes after merge
bf66257 Merge flambda-backend changes
a2556fc Add `[%exclave]` support (oxcaml#51)
ebe9576 Add data race freedom proposal (oxcaml#161)
3f3fc49 Merge pull request oxcaml#159 from riaqn/merge-backend
6c635dc minor changes after merge
99a0d85 Merge flambda-backend changes
2642463 Include the modes of values in debugging information (oxcaml#153)
4ecc8a4 Remove i386 CI check (oxcaml#155)

git-subtree-dir: ocaml
git-subtree-split: e3076d2
@riaqn
Copy link
Copy Markdown
Contributor

riaqn commented Jun 10, 2024

This PR doesnt have tests, which is slightly sad as we are going to add more things to parsetree and thus printast_with_mappings.mli. We want to know if our changes produce expected output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

driver Compiler driver

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants