Skip to content

Changing the display of fatal warnings#948

Merged
mshinwell merged 2 commits intoocaml:trunkfrom
v-gb:fatal-warnings
Mar 8, 2017
Merged

Changing the display of fatal warnings#948
mshinwell merged 2 commits intoocaml:trunkfrom
v-gb:fatal-warnings

Conversation

@v-gb
Copy link
Contributor

@v-gb v-gb commented Dec 5, 2016

This pull request changes the display of warnings that are errors, for instance from:

File "a.ml", line 1, characters 6-7:
Warning 27: unused variable x.
File "tmp.ml", line 1:
Error: Some fatal warnings were triggered (1 occurrences)

to

File "a.ml", line 1, characters 6-7:
Error: Warning 27: unused variable x.

The main motivation is that the message about fatal warnings has a location that does not respect the line directives in the source file, which is my case means random filenames show up in errors.

This change also means one can tell from the output what warnings are errors, which could be useful either for people or for parsing the output.

Finally, it makes for a shorter error message in the common case where the code is not full of warnings.

(errorf ~loc:(in_file !input_name)
"Some fatal warnings were triggered (%d occurrences)" n)

| Warnings.Errors _ -> Some non_displayed_error
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems a bit of a hack. What about capturing Warning.Errors directly in Location.report_exception (and just do nothing)?

Copy link
Contributor Author

@v-gb v-gb Dec 7, 2016

Choose a reason for hiding this comment

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

I started this way but there are two things that were a bit awkward:

  • it doesn't allow to define more exceptions that don't need to be displayed
  • Location.error_of_exn is exposed

ocamldoc can receive Warnings.Error but it uses Location.error_of_exn for instance, so it'd report some weird errors. But in fact, it doesn't even report warnings in mli because it's missing a call to Typecore.force_delayed_checks, and it doesn't stop on fatal warnings in ml because it's missing a call to Warnings.check_fatal (why is it even reporting warnings anyway?).

Looking at the uses of Location.error_of_exn, I think they are all worse than using Location.report_exception, so I guess I'll change that, and then it'd make sense to do what you say.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think Ast_mapper.ext_of_exn would behave weirdly if I did as you say. It would rethrow the exception, and the exception would be caught at the further down, instead of being converted into an error and sent to the compiler as the other exceptions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Was about the following: drop the Warnings.Error exception constructor altogether, have Warnings.check_fatal returns a boolean, and explicitly adapt all driver code to behave as they do currently (either exiting the process, or continuing in the case of the toplevel) when fatal warnings have been reported? It's a much more invasive change, but it will also paves the way to a nicer treatment of reporting multiple errors in general (e.g. adapting the type-checker to report errors without failing necessarily at the first one).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather have the compiler behave more like a library and less like a standalone program, so I don't really want to add calls to exit.
I don't see how the refactoring you suggest would help with reporting multiple type errors: it sounds like reporting such errors the same way as warning would work fine.

If the comparison with the empty string is what you want to remove, maybe renaming Warnings.Errors to Location.Already_displayed and changing Location.error_of_exn to have type exn -> [ Ok of error | Already_displayed ] option would work. This way Ast_mapper.ext_of_exn can serialize the Already_displayed case, and rethrow on the other side, and Location.report_exception would behave as you wrote earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any opinion on that last change, where I did what I described above?

; R (Location.warning_printer , warning_printer)
; R (Location.error_reporter , error_reporter )
[ R (Location.formatter_for_warnings , ppf)
; R (Location.printer , print_loc)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to keep those old hooks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The hooks were added in #171, so I don't think this refactoring means we can remove them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok.

@mshinwell
Copy link
Contributor

@alainfrisch I think we're waiting on your approval as to @sliquister 's latest comments.


exception Error of error

val print_error_prefix: formatter -> unit -> unit
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not against removing this function from the API, but is this related to the current proposal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the only use of this (in the expect test tool), so it seems appropriate to stop exposing it too.

@alainfrisch
Copy link
Contributor

Error: Warning 27:

The multiple colons do not look super nice. What about Fatal warning 27: ..., or Error (warning 27): ....

@v-gb
Copy link
Contributor Author

v-gb commented Jan 5, 2017

Fatal warning 27: .. was the first thing I tried, but I don't really like it: the "fatal" in fatal warning and fatal error don't mean the same thing so it's awkward. If it's an error, I'd rather print "Error". Error (warning 27): sounds fine though, so I used that.

@mshinwell
Copy link
Contributor

@alainfrisch Are you happy with this patch now that the colon issue has been fixed?
@sliquister Please rebase and add a Changes entry.

@v-gb
Copy link
Contributor Author

v-gb commented Feb 22, 2017

@mshinwell I made the changes.

I would squash the four middle commits too, but I'll wait until no one is asking for further changes.

@mshinwell
Copy link
Contributor

Silence from @alainfrisch taken as assent, given the nature of this patch, and previous comments.
@sliquister Please rebase again (sorry) and ping me to merge.

@v-gb v-gb force-pushed the fatal-warnings branch from b03ba0c to d3b628c Compare March 8, 2017 01:33
@v-gb
Copy link
Contributor Author

v-gb commented Mar 8, 2017

@mshinwell I rebased and squashed.

@mshinwell mshinwell merged commit 356d8a9 into ocaml:trunk Mar 8, 2017
@v-gb v-gb deleted the fatal-warnings branch September 17, 2017 13:33
sadiqj pushed a commit to sadiqj/ocaml that referenced this pull request Feb 21, 2023
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Mar 21, 2023
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Mar 21, 2023
b11eea1 flambda-backend: Introduce Import_info (ocaml#1036)
bc5b135 flambda-backend: Fix `ocamlobjinfo` on flambda2 .cmx files (ocaml#1029)
c8babbd flambda-backend: Compilation_unit optimisations (ocaml#1035)
e8d3e22 flambda-backend: Use 4.14.0 opam switch for building (includes upgrading ocamlformat to 0.24.1) (ocaml#1030)
eb14a86 flambda-backend: Port PR81 from ocaml-jst (ocaml#1024)
131bc12 flambda-backend: Merge ocaml-jst 2022-12-13 (ocaml#1022)
06c189a flambda-backend: Make stack allocation the default (ocaml#1013)
98debd5 flambda-backend: Initial support for value slots not of value kind (ocaml#946)
deb1714 flambda-backend: Add is_last flag to closinfo words (ocaml#938)
d07fce1 flambda-backend: Disable poll insertion in Configure (ocaml#967)
0f1ce0e flambda-backend: Regenerate ocaml/configure autoconf 2.69 (instead of 2.71) (ocaml#1012)
27132d8 flambda-backend: Fix for spurious typing error related to expanding through functor arguments (ocaml#997)
724fb68 flambda-backend: Use `Compilation_unit.t` instead of `Ident.t` for globals (ocaml#871)
396d5b8 flambda-backend: Add a test for frametable setup in natdynlinked libraries (ocaml#983)
b73ab12 flambda-backend: Fix invocation of `caml_shared_startup` in native dynlink (ocaml#980)
7c7d75a flambda-backend: Fix split_default_wrapper which did not trigger anymore with flambda2 (ocaml#970)
8fb75bd flambda-backend: Port ocaml#11727 and ocaml#11732 (ocaml#965)
fdb7987 flambda-backend: Fix include functor issue after 4.14 merge. (ocaml#948)
9745cdb flambda-backend: Print -dprofile/-dtimings output to stdout like 4.12 (ocaml#943)
5f51f21 flambda-backend: Merge pull request ocaml#932 from mshinwell/4.14-upgrade
841687d flambda-backend: Run make alldepend in ocaml/ (ocaml#936)
72a7658 flambda-backend: Remove reformatting changes only in dynlink/dune (preserving PR889 and adjusting to minimise diff)
6d758cd flambda-backend: Revert whitespace changes in dune files, to match upstream
c86bf6e flambda-backend: Remove duplicate tests for polling
971dbeb flambda-backend: Testsuite fixes
32f8356 flambda-backend: Topeval fix for symbols patch
befea01 flambda-backend: Compilation fixes / rectify merge faults
a84543f flambda-backend: Merge ocaml-jst
8e65056 flambda-backend: Merge ocaml-jst
4d70045 flambda-backend: Remove filename from system frametable (amd64) (ocaml#920)
5e57b7d flambda-backend: Bugfix for runtime frame_descr logic for C frames (ocaml#918)
6423d5e flambda-backend: Merge pull request ocaml#914 from mshinwell/merge-ocaml-jst-2022-10-24
ead605c flambda-backend: Add a missing Extract_exception (ocaml#916)
c8f1481 flambda-backend: Resolve conflicts and add specialise/specialised attributes to Builtin_attributes
cf4d0d3 flambda-backend: Merge fixes (ocaml#21)
c2f742f flambda-backend: Re-enable some tests for Flambda2 (ocaml#881)
3d38d13 flambda-backend: Long frames in frametable (ocaml#797)
85aec7b flambda-backend: Add loop attribute to Builtin_attributes
c0f16e3 flambda-backend: Compilation fixes
90dea23 flambda-backend: Merge flambda-backend/main
5acc6ea flambda-backend: Fixes after merge
e501946 flambda-backend: Merge ocaml-jst
115083b flambda-backend: Merge ocaml-jst
9943b2e flambda-backend: Revert "Revert "Transform tail-recursive functions into recursive continuations (ocaml#893)"" (ocaml#909)
ce339f1 flambda-backend: Fix alloc modes and call kinds for overapplications (ocaml#902)
e6a317c flambda-backend: Revert "Transform tail-recursive functions into recursive continuations (ocaml#893)"
853c488 flambda-backend: Transform tail-recursive functions into recursive continuations (ocaml#893)
5a977e4 flambda-backend: Fix missing End_region primitives on switch arms (ocaml#898)
7fa7f9d flambda-backend: Add missing dependencies to Dune files (ocaml#889)
3cd36f0 flambda-backend: Have Lambda `Pgetglobal` and `Psetglobal` take `Compilation_unit.t` (ocaml#896)
7565915 flambda-backend: [@poll error] attribute (ocaml#745)
9eb9448 flambda-backend: Backport the main safepoints PRs (ocaml#740)
689bdda flambda-backend: Add strict mode for ocamldep (ocaml#892)

git-subtree-dir: ocaml
git-subtree-split: b11eea1
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
* Import Rewrote Set Tutorial from V2 PR

@NebuPookins rewrote the set tutorial for [V2](https://github.com/ocaml/v2.ocaml.org) in 2021. The PR was neither merged nor rejected:

ocaml/v2.ocaml.org#1596

* Apply suggestions from code review

Co-authored-by: Christine Rose <[email protected]>

* Minor Fixes

As pointed by @Octachron

* line editing

* shorten a lot and present common operations instead of explaining functors

* Review edits

---------

Co-authored-by: Cuihtlauac ALVARADO <[email protected]>
Co-authored-by: Christine Rose <[email protected]>
Co-authored-by: Sabine Schmaltz <[email protected]>
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.

3 participants