Skip to content
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

Update locations during destructive substitutions #1737

Merged
merged 5 commits into from May 30, 2018

Conversation

trefis
Copy link
Contributor

@trefis trefis commented Apr 24, 2018

This PR proposes to update locations when performing a destructive substitution, this is to avoid error messages like this one:

$ cat test.ml
module M : Set.S with type elt := unit = Set.Make (String)
$ ocamlc -c ./test.ml
File "./test.ml", line 1, characters 41-58:
Error: Signature mismatch:
       ...
       Values do not match:
         val mem : elt -> t -> bool
       is not included in
         val mem : unit -> t -> bool
       File "set.mli", line 77, characters 4-29: Expected declaration
       File "set.mli", line 77, characters 4-29: Actual declaration

After this PR, it becomes:

File "./test.ml", line 1, characters 41-58:
Error: Signature mismatch:
       ...
       Values do not match:
         val mem : elt -> t -> bool
       is not included in
         val mem : unit -> t -> bool
       File "./test.ml", line 1, characters 11-38: Expected declaration
       File "set.mli", line 77, characters 4-29: Actual declaration

@trefis
Copy link
Contributor Author

trefis commented Apr 24, 2018

PS: a bootstrap was apparently necessary (which surprised me a little) otherwise this would happen:

../../boot/ocamlrun ../../ocamlc -nostdlib -I ../../stdlib -I ../../utils -I ../../typing -I ../../bytecomp -I ../../asmcomp -absname -w +a-4-9-41-42-44-45-48 -bin-annot -g -I ../../stdlib -warn-error A -safe-string -strict-sequence -strict-formats -pack -o dynlinkaux.cmo ../../utils/misc.cmo ../../utils/config.cmo ../../utils/identifiable.cmo ../../utils/numbers.cmo ../../utils/arg_helper.cmo ../../utils/clflags.cmo ../../utils/tbl.cmo ../../utils/consistbl.cmo ../../utils/terminfo.cmo ../../utils/warnings.cmo ../../utils/build_path_prefix_map.cmo ../../parsing/asttypes.cmi ../../parsing/location.cmo ../../parsing/longident.cmo ../../parsing/docstrings.cmo ../../parsing/syntaxerr.cmo ../../parsing/ast_helper.cmo ../../parsing/ast_mapper.cmo ../../parsing/ast_iterator.cmo ../../parsing/attr_helper.cmo ../../parsing/builtin_attributes.cmo ../../typing/ident.cmo ../../typing/path.cmo ../../typing/primitive.cmo ../../typing/types.cmo ../../typing/btype.cmo ../../typing/subst.cmo ../../typing/predef.cmo ../../typing/datarepr.cmo ../../typing/cmi_format.cmo ../../typing/env.cmo ../../bytecomp/lambda.cmo ../../bytecomp/instruct.cmo ../../bytecomp/cmo_format.cmi ../../bytecomp/opcodes.cmo ../../bytecomp/runtimedef.cmo ../../bytecomp/bytesections.cmo ../../bytecomp/dll.cmo ../../bytecomp/meta.cmo ../../bytecomp/symtable.cmo
Fatal error: exception Invalid_argument("output_value: abstract value (outside heap)")
Raised by primitive operation at unknown location
Called from file "bytecomp/bytepackager.ml", line 249, characters 6-40
Re-raised at file "bytecomp/bytepackager.ml", line 277, characters 10-11
Called from file "bytecomp/bytepackager.ml", line 294, characters 6-67
Re-raised at file "bytecomp/bytepackager.ml", line 296, characters 36-37
Called from file "driver/main.ml", line 176, characters 6-94
Re-raised at file "parsing/location.ml", line 494, characters 22-25
Re-raised at file "parsing/location.ml", line 494, characters 22-25
Re-raised at file "parsing/location.ml", line 494, characters 22-25
Re-raised at file "parsing/location.ml", line 494, characters 22-25
Re-raised at file "parsing/location.ml", line 494, characters 22-25
Re-raised at file "parsing/location.ml", line 494, characters 22-25
Called from file "driver/main.ml", line 202, characters 4-35
Called from file "driver/main.ml", line 206, characters 2-9
make[3]: *** [dynlinkaux.cmo] Error 2

@trefis trefis force-pushed the subst-locs branch 3 times, most recently from 951b069 to 9e107ee Compare April 30, 2018 09:37
@trefis
Copy link
Contributor Author

trefis commented May 23, 2018

ping @Drup , @lpw25 : does one of you have time to review this?

@Drup
Copy link
Contributor

Drup commented May 29, 2018

I reviewed. The code looks fine and is pretty low risk (it only change location on things where locations used to be, well, mostly crap). Also, it works for both non-destructive and destructive substitutions.

The tests, however, could be improved:

  • It's missing the part of the information that it is supposed to test. In particular the error message you gave in the description is longer and more precise than the one in the testsuite.
  • It'll break when someone extends Map.Make. It should probably use a made-up local module.

@trefis
Copy link
Contributor Author

trefis commented May 29, 2018

It's missing the part of the information that it is supposed to test. In particular the error message you gave in the description is longer and more precise than the one in the testsuite.

Yes, that's because when printing error messages some locations aren't printed if they come from the toplevel. I rewrote the test to switch from using expect_test to ocamlc, the error message is now similar to the one given in the description of this PR.

It'll break when someone extends Map.Make. It should probably use a made-up local module.

Fair point, done.

Copy link
Contributor

@Drup Drup left a comment

Choose a reason for hiding this comment

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

The ocamltest script doesn't look very nice, but the tests are great! Looks good to me.

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.

None yet

2 participants