[m-rev.] diff: fix github issue #89

Julien Fischer jfischer at opturion.com
Sun May 17 01:12:18 AEST 2020


There are currently some issues with the running the test case;
I'll look into that separately.

--------------------

Fix github issue #89.

The current source-to-source debugger transformation cannot handle the
predicates introduced by higher-order specialization. There are likely similar
issues with other HLDS->HLDS transformations.

The fix (for now) is to disable most HLDS->HLDS transformations in .ssdebug
grades.

compiler/handle_options.m:
     Disable most HLDS->HLDS optimizations when the ss-trace level is
     shallow or deep.

     Add an XXX comment about a separate issue.

compiler/ssdebug.m:
     Add an XXX comment about predicates produced by higher-order
     specialization.

tests/WS_FLAGS.ws:
     Add a missing include.

tests/valid/Mmakefile:
tests/valid/Mercury.options:
tests/valid/gh89.m:
     Add the test case from github issue 89.

Julien.

diff --git a/compiler/handle_options.m b/compiler/handle_options.m
index 3aa5ac3..9e85cc5 100644
--- a/compiler/handle_options.m
+++ b/compiler/handle_options.m
@@ -1635,8 +1635,32 @@ convert_options_to_globals(OptionTable0, OpMode, Target, GC_Method,
          add_error(phase_options, TraceHLSpec, !Specs)
      ),

+    % Source-to-source debugging requires disabling many HLDS->HLDS
+    % optimizations. This is so that the trace being generated relates to the
+    % source code and also because the SSDB transformation cannot (yet) handle
+    % the specialised predicates introduced by many optimizations.
+    (
+        ( SSTraceLevel = shallow
+        ; SSTraceLevel = deep
+        ),
+        globals.set_option(allow_inlining, bool(no), !Globals),
+        globals.set_option(optimize_unused_args, bool(no), !Globals),
+        globals.set_option(optimize_higher_order, bool(no), !Globals),
+        globals.set_option(type_specialization, bool(no), !Globals),
+        globals.set_option(user_guided_type_specialization, bool(no),
+            !Globals),
+        globals.set_option(deforestation, bool(no), !Globals),
+        globals.set_option(constraint_propagation, bool(no), !Globals),
+        globals.set_option(local_constraint_propagation, bool(no), !Globals),
+        globals.set_option(optimize_duplicate_calls, bool(no), !Globals),
+        globals.set_option(optimize_constructor_last_call, bool(no), !Globals)
+    ;
+        SSTraceLevel = none
+    ),
+
      % The pthreads headers on some architectures (Solaris, Linux)
      % don't work with -ansi.
+    % XXX we don't pass -ansi to the C compiler anymore.
      option_implies(parallel, ansi_c, bool(no), !Globals),

      option_neg_implies(inline_builtins, constant_propagation, bool(no),
diff --git a/compiler/ssdebug.m b/compiler/ssdebug.m
index 0116391..1db1748 100644
--- a/compiler/ssdebug.m
+++ b/compiler/ssdebug.m
@@ -1035,6 +1035,8 @@ ssdebug_process_proc_erroneous(SSTraceLevel, PredId, ProcId,
      list(prog_var)::out, list(prog_var)::out, list(mer_mode)::out) is det.

  get_stripped_headvars(PredInfo, ProcInfo, FullHeadVars, HeadVars, ArgModes) :-
+    % XXX using orig_arity here does not work when the predicate is one
+    % produced by higher-order specialization. See tests/valid/gh89.m.
      PredArity = pred_info_orig_arity(PredInfo),
      proc_info_get_headvars(ProcInfo, FullHeadVars),
      proc_info_get_argmodes(ProcInfo, FullArgModes),
diff --git a/tests/WS_FLAGS.ws b/tests/WS_FLAGS.ws
index a37fee9..ed8b3aa 100644
--- a/tests/WS_FLAGS.ws
+++ b/tests/WS_FLAGS.ws
@@ -2,6 +2,7 @@
  -I at WORKSPACE@/library
  -I at WORKSPACE@/browser
  -I at WORKSPACE@/mdbcomp
+-I at WORKSPACE@/ssdb
  --c-include-directory @WORKSPACE@/boehm_gc
  --c-include-directory @WORKSPACE@/boehm_gc/include
  --c-include-directory @WORKSPACE@/runtime
diff --git a/tests/valid/Mercury.options b/tests/valid/Mercury.options
index 375d439..9a7f97f 100644
--- a/tests/valid/Mercury.options
+++ b/tests/valid/Mercury.options
@@ -54,6 +54,9 @@ MCFLAGS-exists_cast_bug		= --trace rep -O0 --optimize-saved-vars-const
  MCFLAGS-explicit_quant		= --halt-at-warn
  MCFLAGS-foreign_underscore_var	= --halt-at-warn
  MCFLAGS-fzn_debug_abort		= --trace rep
+# XXX we should pass --ssdb-trace deep or --ss-debug to gh89
+# but that currently doesn't work in non ssdb grades.
+MCFLAGS-gh89 = --intermodule-optimization -O3 --no-warn-missing-opt-files
  MCFLAGS-higher_order4		= -O3
  MCFLAGS-higher_order_implied_mode = -O-1
  MCFLAGS-ho_and_type_spec_bug	= -O4
diff --git a/tests/valid/Mmakefile b/tests/valid/Mmakefile
index de5c7f7..cbd6f03 100644
--- a/tests/valid/Mmakefile
+++ b/tests/valid/Mmakefile
@@ -135,6 +135,7 @@ OTHER_PROGS = \
  	func_default_modes \
  	func_in_head \
  	gh65 \
+	gh89 \
  	github_50 \
  	hawkins_switch_bug \
  	headvar_not_found \
diff --git a/tests/valid/gh89.m b/tests/valid/gh89.m
new file mode 100644
index 0000000..432f9d8
--- /dev/null
+++ b/tests/valid/gh89.m
@@ -0,0 +1,59 @@
+%---------------------------------------------------------------------------%
+% vim: ts=4 sw=4 et ft=mercury
+%---------------------------------------------------------------------------%
+%
+% This is a regression test for github issue #89.
+%
+% Any copyright is dedicated to the Public Domain.
+% https://creativecommons.org/publicdomain/zero/1.0/
+%
+% Released by Transnat Games for testing purposes.
+%
+% Crashes with the following compiler flags:
+% mmc --make crash -O 6 --intermodule-optimization --use-grade-subdirs \
+%  --grade=hlc.gc.spf.ssdebug
+%
+% Crashes as:
+% Making Mercury/hlc.gc.spf.ssdebug/x86_64-unknown-openbsd6.5/Mercury/cs/crash.c
+% Uncaught Mercury exception:
+% Software Error: list.m: predicate `list.det_drop'/3: Unexpected: index out of range
+% ** Error making `Mercury/hlc.gc.spf.ssdebug/x86_64-unknown-openbsd6.5/Mercury/cs/crash.c'.
+%
+% The crash requires an optimization level (I'm not sure which, 1 is fine but 6
+% is not), intermodule optimizations, grade subdirs, and an ssdebug grade.
+%
+%---------------------------------------------------------------------------%
+%
+% The cause of the abort is the the source-to-source debugging transformation
+% does not understand how to process the specializations produced by the
+% higher-order optimization.  Until it does, we have disabled the use of that
+% optimization (and a bunch of others) by default with source-to-source
+% debugging.
+%
+%---------------------------------------------------------------------------%
+
+:- module gh89.
+:- interface.
+
+:- use_module array.
+
+:- pred measure(array.array(int)::in, int::out, int::out) is det.
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+%------------------------------------------------------------------------------%
+
+:- pred measure(_, int, int, int, int).
+:- mode measure(in, in, out, in, out) is det.
+
+measure(_, W, W, H, H).
+
+%------------------------------------------------------------------------------%
+
+measure(Glyphs, W, H) :-
+    % There has to be something that actually uses the first argument to this
+    % predicate, otherwise the crash doesn't happen.
+    array.foldl2(measure, Glyphs, 0, W, 0, H).


More information about the reviews mailing list