Skip to content

Print diagnostics at runtime for Invalid #530

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

Merged
merged 3 commits into from
Feb 14, 2022

Conversation

mshinwell
Copy link
Collaborator

This makes it much easier to fix occurrences of Invalid at runtime. For example:

% cat inv.ml
type t = {
  mutable x : float;
}

let foo () =
  let t = 1, 2 in
  Array.unsafe_get ((Obj.magic t) : int array) 0

let (_ : int) = foo ()
% ./inv
[ocaml] [flambda2] Invalid code:
(Defining_expr_of_let (bound_pattern Parrayrefu/22)
 (defining_expr
  (((Array_load Immediates Mutable) Inv.camlInv__const_block9 0)
   inv.ml:7,2--48)))

This might have arisen from a wrong use of [Obj.magic].
Consider using [Sys.opaque_identity].
zsh: abort      ./inv

I've removed the flags for the distinction between "halt and catch fire" and "treat as unreachable". I think we should just choose the right semantics. There is one place that makes a distinction between these two settings at the moment -- I have maintained this as it was for "halt and catch fire", lest the alternative causes problems. I have left a CR to fix this later however.

I was wondering about just using exit but in the end decided abort is probably better: it's possible that the exact address of failure might still be useful, in case of ambiguity in the printed diagnostic.

@mshinwell mshinwell added flambda2 Prerequisite for, or part of, flambda2 flambda2 beta labels Feb 10, 2022
@mshinwell mshinwell force-pushed the flambda2-better-invalid branch from 1704b18 to 56a913c Compare February 10, 2022 13:37
* Always use caml_flambda2_invalid for unreachable in to_cmm

* Include debuginfo in dead closure elts invalid msg
@mshinwell mshinwell merged commit b8187a9 into ocaml-flambda:main Feb 14, 2022
stedolan added a commit to stedolan/flambda-backend that referenced this pull request Mar 7, 2022
64235a3 flambda-backend: Change Float.nan from sNaN to qNaN (ocaml-flambda#466)
14a8e27 flambda-backend: Track GC work for all managed bigarray allocations (upstream 11022) (ocaml-flambda#569)
c3cda96 flambda-backend: Add two new methods to targetint for dwarf (ocaml-flambda#560)
e6f1fed flambda-backend: Handle arithmetic overflow in select_addr (ocaml-flambda#570)
dab7209 flambda-backend: Add Target_system to ocaml/utils (ocaml-flambda#542)
82d5044 flambda-backend: Enhance numbers.ml with more primitive types (ocaml-flambda#544)
216be99 flambda-backend: Fix flambda_o3 and flambda_oclassic attributes (ocaml-flambda#536)
4b56e07 flambda-backend: Test naked pointer root handling (ocaml-flambda#550)
40d69ce flambda-backend: Stop local function optimisation from moving code into function bodies; opaque_identity fixes for class compilation (ocaml-flambda#537)
f08ae58 flambda-backend: Implemented inlining history and use it inside inlining reports (ocaml-flambda#365)
ac496bf flambda-backend: Disable the local keyword in typing (ocaml-flambda#540)
7d46712 flambda-backend: Bugfix for Typedtree generation of arrow types (ocaml-flambda#539)
61a7b47 flambda-backend: Insert missing page table check in roots_nat.c (ocaml-flambda#541)
323bd36 flambda-backend: Compiler error when -disable-all-extensions and -extension are used (ocaml-flambda#534)
d8956b0 flambda-backend: Persistent environment and reproducibility (ocaml-flambda#533)
4a0c89f flambda-backend: Revert "Revert bswap PRs (480 and 482)" (ocaml-flambda#506)
7803705 flambda-backend: Cause a C warning when CAMLreturn is missing in C stubs. (ocaml-flambda#376)
6199db5 flambda-backend: Improve unboxing during cmm for Flambda (ocaml-flambda#295)
96b9e1b flambda-backend: Print diagnostics at runtime for Invalid (ocaml-flambda#530)
42ab88e flambda-backend: Disable bytecode compilers in ocamltest (ocaml-flambda#504)
58c72d5 flambda-backend: Backport ocaml/ocaml#10595 from upstream/trunk (ocaml-flambda#471)
1010539 flambda-backend: Use C++ name mangling convention (ocaml-flambda#483)
81881bb flambda-backend: Local allocation test no longer relies on lifting (ocaml-flambda#525)
f5c4719 flambda-backend: Fix an assertion in Closure that breaks probes (ocaml-flambda#505)
c2cf2b2 flambda-backend: Add some missing command line arguments to ocamlnat (ocaml-flambda#499)

git-subtree-dir: ocaml
git-subtree-split: 64235a3
stedolan added a commit that referenced this pull request Mar 7, 2022
64235a3 flambda-backend: Change Float.nan from sNaN to qNaN (#466)
14a8e27 flambda-backend: Track GC work for all managed bigarray allocations (upstream 11022) (#569)
c3cda96 flambda-backend: Add two new methods to targetint for dwarf (#560)
e6f1fed flambda-backend: Handle arithmetic overflow in select_addr (#570)
dab7209 flambda-backend: Add Target_system to ocaml/utils (#542)
82d5044 flambda-backend: Enhance numbers.ml with more primitive types (#544)
216be99 flambda-backend: Fix flambda_o3 and flambda_oclassic attributes (#536)
4b56e07 flambda-backend: Test naked pointer root handling (#550)
40d69ce flambda-backend: Stop local function optimisation from moving code into function bodies; opaque_identity fixes for class compilation (#537)
f08ae58 flambda-backend: Implemented inlining history and use it inside inlining reports (#365)
ac496bf flambda-backend: Disable the local keyword in typing (#540)
7d46712 flambda-backend: Bugfix for Typedtree generation of arrow types (#539)
61a7b47 flambda-backend: Insert missing page table check in roots_nat.c (#541)
323bd36 flambda-backend: Compiler error when -disable-all-extensions and -extension are used (#534)
d8956b0 flambda-backend: Persistent environment and reproducibility (#533)
4a0c89f flambda-backend: Revert "Revert bswap PRs (480 and 482)" (#506)
7803705 flambda-backend: Cause a C warning when CAMLreturn is missing in C stubs. (#376)
6199db5 flambda-backend: Improve unboxing during cmm for Flambda (#295)
96b9e1b flambda-backend: Print diagnostics at runtime for Invalid (#530)
42ab88e flambda-backend: Disable bytecode compilers in ocamltest (#504)
58c72d5 flambda-backend: Backport ocaml/ocaml#10595 from upstream/trunk (#471)
1010539 flambda-backend: Use C++ name mangling convention (#483)
81881bb flambda-backend: Local allocation test no longer relies on lifting (#525)
f5c4719 flambda-backend: Fix an assertion in Closure that breaks probes (#505)
c2cf2b2 flambda-backend: Add some missing command line arguments to ocamlnat (#499)

git-subtree-dir: ocaml
git-subtree-split: 64235a3
TheNumbat added a commit that referenced this pull request Nov 13, 2023
Implements caml_flambda2_invalid runtime diagonstic.
See #530
TheNumbat added a commit that referenced this pull request Nov 13, 2023
Implements caml_flambda2_invalid runtime diagonstic.
See #530
mshinwell pushed a commit that referenced this pull request Nov 14, 2023
* Install runtime/caml headers

Updates the dune build system to install the runtime5 headers.

Covers #77

* Add CAML_RUNTIME_5 macro to runtime.

This allows code using the runtime (particularly otherlibs/) to condition on 4 vs. 5.
Alternatively, otherlibs/ could be duplicated between 4 and 5, but only minimal changes were necessary.

* unix/fork.c conditionals

When building with runtime5, fork needs to use runtime_events instead of eventlog.

* unix/signals.c conditionals

Runtime5 removes caml_sigmask_hook, so the code should use pthread_sigmask directly.
See CR for discussion - the upstream unix/signals.c uses sigprocmask, which seems incorrect.

* Upstream build system fixes

- Fixes unquoted 'yes' call
- Fixes unsubstituted runtime_suffix generator
- Disables stack allocation when runtime5 is enabled
- Regenerates configure script

* Add runtime5 compile-time constant

Implements "%runtime5" primitive for checking whether we're configured with runtime5 at compile time.
In the compiler, it just returns the config bool.
In runtime/ it returns true; in runtime4/ false.

Also implements caml_sys_const_naked_pointers_checked in runtime/.

* Runtime5 global symbol seperator

Runtime5 renames global symbols to 'caml_module.name' instead of 'caml_module__name'.
The backend now cases on the configured runtime.

* Forward port caml_flambda2_invalid

Implements caml_flambda2_invalid runtime diagonstic.
See #530

* Forward port caml_obj_make_forward

Runtime/ did not include this function, so the implementation is copied from runtime4.
The same code works with the new OCaml 5 lazy implementation.

* With_async_exns conditional

Uses the runtime5 compile-time constant to conditionally implement with_async_exns as a try/catch block.
Future work will implement with_async_exns properly in runtime5, at which point this should be removed.

* Bootstrap 4 compiler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flambda2 beta flambda2 Prerequisite for, or part of, flambda2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants