[m-rev.] for review: fix missing foreign type errors

Simon Taylor staylr at gmail.com
Tue May 1 12:36:01 AEST 2007


Estimated hours taken: 3
Branches: main

Fix failure of tests/valid/foreign_type_spec.

compiler/add_type.m:
	Fix a place where error codes were being `and'ed together
	rather than `or'ed, resulting in missing foreign type
	declarations not being reported and compiler aborts later.

	Remove code to only test GRADEFLAGS when generating code.
	GRADEFLAGS is passed for all compilation targets now.

library/bitmap.m:
	Uncomment the IL definition of the bitmap type to allow
	this module to compile (but not work) in IL grades.

tests/invalid/Mmakefile:
tests/invalid/Mercury.options:
tests/invalid/foreign_type_missing.{m,err_exp}:
	Test case for missing foreign type declarations for
	the current back-end.

tests/valid/Mercury.options:
	Fix a typo which caused different parts of the foreign_type_spec
	test case to be compiled in different grades.

Index: compiler/add_type.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/add_type.m,v
retrieving revision 1.25
diff -u -u -r1.25 add_type.m
--- compiler/add_type.m	8 Jan 2007 03:03:08 -0000	1.25
+++ compiler/add_type.m	28 Apr 2007 02:16:37 -0000
@@ -405,7 +405,7 @@
         check_foreign_type(TypeCtor, ForeignTypeBody, Context,
             NewFoundError, !ModuleInfo, !Specs)
     ),
-    !:FoundError = !.FoundError `and` NewFoundError,
+    !:FoundError = !.FoundError `or` NewFoundError,
     (
         !.FoundError = yes
     ->
@@ -442,58 +442,26 @@
     ( have_foreign_type_for_backend(Target, ForeignTypeBody, yes) ->
         FoundError = no
     ;
-        GeneratingCode = generating_code(Globals),
-        (
-            GeneratingCode = yes,
-            ( Target = target_c, LangStr = "C"
-            ; Target = target_il, LangStr = "IL"
-            ; Target = target_java, LangStr = "Java"
-            ; Target = target_asm, LangStr = "C"
-            ; Target = target_x86_64, LangStr = "C"
-            ),
-            MainPieces = [words("Error: no"), fixed(LangStr),
-                fixed("`pragma foreign_type'"), words("declaration for"),
-                sym_name_and_arity(Name/Arity), nl],
-            VerbosePieces = [words("There are representations for this type"),
-                words("on other back-ends, but none for this back-end."), nl],
-            Msg = simple_msg(Context,
-                [always(MainPieces), 
-                option_is_set(very_verbose, yes, [always(VerbosePieces)])]),
-            Spec = error_spec(severity_error, phase_parse_tree_to_hlds,
-                [Msg]),
-            !:Specs = [Spec | !.Specs]
-        ;
-            GeneratingCode = no
-            % If we're not generating code the error may only have occurred
-            % because the grade options weren't passed.
+        ( Target = target_c, LangStr = "C"
+        ; Target = target_il, LangStr = "IL"
+        ; Target = target_java, LangStr = "Java"
+        ; Target = target_asm, LangStr = "C"
+        ; Target = target_x86_64, LangStr = "C"
         ),
+        MainPieces = [words("Error: no"), fixed(LangStr),
+            fixed("`pragma foreign_type'"), words("declaration for"),
+            sym_name_and_arity(Name/Arity), nl],
+        VerbosePieces = [words("There are representations for this type"),
+            words("on other back-ends, but none for this back-end."), nl],
+        Msg = simple_msg(Context,
+            [always(MainPieces), 
+            option_is_set(very_verbose, yes, [always(VerbosePieces)])]),
+        Spec = error_spec(severity_error, phase_parse_tree_to_hlds,
+            [Msg]),
+        !:Specs = [Spec | !.Specs],
         FoundError = yes
     ).
 
-    % Do the options imply that we will generate code for a specific back-end?
-    %
-:- func generating_code(globals) = bool.
-
-generating_code(Globals) = bool.not(NotGeneratingCode) :-
-    lookup_bool_option(Globals, make_short_interface, MakeShortInterface),
-    lookup_bool_option(Globals, make_interface, MakeInterface),
-    lookup_bool_option(Globals, make_private_interface, MakePrivateInterface),
-    lookup_bool_option(Globals, make_transitive_opt_interface,
-        MakeTransOptInterface),
-    lookup_bool_option(Globals, generate_source_file_mapping,
-        GenSrcFileMapping),
-    lookup_bool_option(Globals, generate_dependencies, GenDepends),
-    lookup_bool_option(Globals, generate_dependency_file, GenDependFile),
-    lookup_bool_option(Globals, convert_to_mercury, ConvertToMercury),
-    lookup_bool_option(Globals, typecheck_only, TypeCheckOnly),
-    lookup_bool_option(Globals, errorcheck_only, ErrorCheckOnly),
-    lookup_bool_option(Globals, output_grade_string, OutputGradeString),
-    bool.or_list([MakeShortInterface, MakeInterface,
-        MakePrivateInterface, MakeTransOptInterface,
-        GenSrcFileMapping, GenDepends, GenDependFile, ConvertToMercury,
-        TypeCheckOnly, ErrorCheckOnly, OutputGradeString],
-        NotGeneratingCode).
-
 :- pred merge_foreign_type_bodies(compilation_target::in, bool::in,
     hlds_type_body::in, hlds_type_body::in, hlds_type_body::out)
     is semidet.
Index: library/bitmap.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/bitmap.m,v
retrieving revision 1.17
diff -u -u -r1.17 bitmap.m
--- library/bitmap.m	6 Mar 2007 05:48:32 -0000	1.17
+++ library/bitmap.m	30 Apr 2007 23:44:00 -0000
@@ -1396,11 +1396,9 @@
     where equality is bitmap_equal, comparison is bitmap_compare.
 :- pragma foreign_type("Java", bitmap, "mercury.bitmap.MercuryBitmap") 
     where equality is bitmap_equal, comparison is bitmap_compare.
-/* XXX UNTESTED
 :- pragma foreign_type("IL", bitmap,
     "class [mercury]mercury.bitmap__csharp_code.MercuryBitmap") 
     where equality is bitmap_equal, comparison is bitmap_compare.
-*/
 
 :- pred bitmap_equal(bitmap, bitmap).
 :- mode bitmap_equal(in, in) is semidet.
Index: tests/invalid/Mercury.options
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mercury.options,v
retrieving revision 1.20
diff -u -u -r1.20 Mercury.options
--- tests/invalid/Mercury.options	15 Dec 2006 03:58:43 -0000	1.20
+++ tests/invalid/Mercury.options	28 Apr 2007 02:12:47 -0000
@@ -23,6 +23,8 @@
 				--no-automatic-intermodule-optimization
 MCFLAGS-foreign_decl_line_number = --no-errorcheck-only --line-numbers --compile-only
 MCFLAGS-foreign_type_line_number = --no-errorcheck-only --line-numbers --compile-only
+MCFLAGS-foreign_type_missing =  --grade il --no-intermodule-optimization \
+                                --no-automatic-intermodule-optimization
 MCFLAGS-foreign_singleton =	--halt-at-warn
 MCFLAGS-foreign_type =		--compile-only
 MCFLAGS-foreign_type_2 =	--no-intermodule-optimization \
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.211
diff -u -u -r1.211 Mmakefile
--- tests/invalid/Mmakefile	5 Apr 2007 02:52:47 -0000	1.211
+++ tests/invalid/Mmakefile	28 Apr 2007 02:12:06 -0000
@@ -84,6 +84,7 @@
 	field_syntax_error \
 	foreign_purity_mismatch \
 	foreign_singleton \
+	foreign_type_missing \
 	foreign_type_2 \
 	foreign_type_visibility \
 	fp_dup_bug \
Index: tests/invalid/foreign_type_missing.err_exp
===================================================================
RCS file: tests/invalid/foreign_type_missing.err_exp
diff -N tests/invalid/foreign_type_missing.err_exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/foreign_type_missing.err_exp	28 Apr 2007 02:13:32 -0000
@@ -0,0 +1,2 @@
+foreign_type_missing.m:009: Error: no IL `pragma foreign_type' declaration for
+foreign_type_missing.m:009:   `foreign_type_missing.foreign'/0
Index: tests/invalid/foreign_type_missing.m
===================================================================
RCS file: tests/invalid/foreign_type_missing.m
diff -N tests/invalid/foreign_type_missing.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/foreign_type_missing.m	28 Apr 2007 02:16:16 -0000
@@ -0,0 +1,11 @@
+:- module foreign_type_missing.
+
+:- interface.
+
+:- type ft2
+        --->    f(foreign).
+
+	% This test is always run using `--grade il'.
+:- type foreign.
+:- pragma foreign_type("C", foreign, "int").
+
Index: tests/valid/Mercury.options
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mercury.options,v
retrieving revision 1.34
diff -u -u -r1.34 Mercury.options
--- tests/valid/Mercury.options	27 Feb 2007 23:49:57 -0000	1.34
+++ tests/valid/Mercury.options	30 Apr 2007 23:42:04 -0000
@@ -20,7 +20,7 @@
 GRADEFLAGS-agc_unused_in	= --gc accurate
 GRADEFLAGS-csharp_hello		=  --grade il
 GRADEFLAGS-foreign_type_spec	=  --grade il
-GRADEFLAGS-foreign_type_spec.foreign = --grade il
+GRADEFLAGS-foreign_type_spec.foreign_type = --grade il
 
 MCFLAGS-builtin_false		= --intermodule-optimization
 MCFLAGS-compl_unify_bug		= -O3
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list