diff --git a/compiler/mercury_compile_front_end.m b/compiler/mercury_compile_front_end.m index 97b4aeb..a9af056 100644 --- a/compiler/mercury_compile_front_end.m +++ b/compiler/mercury_compile_front_end.m @@ -283,53 +283,49 @@ frontend_pass_after_typeclass_check(FoundUndefModeError, !FoundError, pretest_user_inst_table(!HLDS), post_typecheck_finish_preds(!HLDS, NumPostTypeCheckErrors, PostTypeCheckAlwaysSpecs, PostTypeCheckNoTypeErrorSpecs), + maybe_dump_hlds(!.HLDS, 19, "post_typecheck", !DumpInfo, !IO), % If the main part of typecheck detected some errors, then some of % the errors we detect during post-typecheck could be avalanche % messages. We get post_typecheck to put all such messages into - % PostTypeCheckNoTypeErrorSpecs, and we report them only if did not - % find any errors during typecheck. + % PostTypeCheckNoTypeErrorSpecs, and we report them only if + % we did not find any errors during typecheck. + !:Specs = !.Specs ++ PostTypeCheckAlwaysSpecs, ( FoundTypeError = no, - PostTypeCheckSpecs = PostTypeCheckAlwaysSpecs - ++ PostTypeCheckNoTypeErrorSpecs, - !:Specs = !.Specs ++ PostTypeCheckSpecs + !:Specs = !.Specs ++ PostTypeCheckNoTypeErrorSpecs ; - FoundTypeError = yes, - !:Specs = !.Specs ++ PostTypeCheckAlwaysSpecs + FoundTypeError = yes ), + ( if - ( SomeMissingTypeDefns = yes + ( FoundTypeError = yes + ; SomeMissingTypeDefns = yes ; NumPostTypeCheckErrors > 0 ) then - PostTypeCheckErrors = yes + % XXX It would be nice if we could go on and mode-check the + % predicates which didn't have type errors, but we need to run + % polymorphism before running mode analysis, and currently + % polymorphism may get internal errors if any of the predicates + % are not type-correct. + !:FoundError = yes else - PostTypeCheckErrors = no - ), - maybe_dump_hlds(!.HLDS, 19, "post_typecheck", !DumpInfo, !IO), - - % Stop here if `--typecheck-only' was specified. - globals.lookup_bool_option(Globals, typecheck_only, TypecheckOnly), - ( - TypecheckOnly = yes, - !:FoundError = bool.or(!.FoundError, PostTypeCheckErrors) - ; - TypecheckOnly = no, - ( if - ( FoundTypeError = yes - ; PostTypeCheckErrors = yes - ) - then - % XXX It would be nice if we could go on and mode-check the - % predicates which didn't have type errors, but we need to run - % polymorphism before running mode analysis, and currently - % polymorphism may get internal errors if any of the predicates - % are not type-correct. - !:FoundError = yes - else - puritycheck(Verbose, Stats, !HLDS, !Specs, !IO), - maybe_dump_hlds(!.HLDS, 20, "puritycheck", !DumpInfo, !IO), - + % We invoke purity check even if --typecheck-only was specified, + % because the resolution of predicate and function overloading + % is done during the purity pass, and errors in the resolution + % of such overloading are type errors. However, the code that + % does this resolution depends on the absence of the other type + % errors that post_typecheck.m is designed to discover. (See + % Mantis bug 113.) + + puritycheck(Verbose, Stats, !HLDS, !Specs, !IO), + maybe_dump_hlds(!.HLDS, 20, "puritycheck", !DumpInfo, !IO), + + globals.lookup_bool_option(Globals, typecheck_only, TypecheckOnly), + ( + TypecheckOnly = yes + ; + TypecheckOnly = no, % Substitute implementation-defined literals before clauses are % written out to `.opt' files. subst_implementation_defined_literals(Verbose, Stats, !HLDS, @@ -362,6 +358,11 @@ frontend_pass_after_typeclass_check(FoundUndefModeError, !FoundError, ) ). +:- pred spec_phase_match(error_phase::in, error_spec::in) is semidet. + +spec_phase_match(Phase, Spec) :- + Spec ^ error_phase = Phase. + %---------------------------------------------------------------------------% :- pred maybe_write_initial_optfile(bool::in, diff --git a/compiler/notes/compiler_design.html b/compiler/notes/compiler_design.html index 85ce4de..29ced3e 100644 --- a/compiler/notes/compiler_design.html +++ b/compiler/notes/compiler_design.html @@ -906,7 +906,7 @@ so that the compiler does the right thing for options such as module name resolution, and almost fully qualifies all predicate and functor names. It sets the map(var, type) field in the pred_info. However, typecheck.m doesn't figure out the pred_id - for function calls or calls to overloaded predicates; that can't + for function calls or calls to overloaded predicates. That can't be done in a single pass of typechecking, and so it is done later on (in purity.m for overloaded predicate calls, and in resolve_unify_functor.m for function calls) @@ -924,20 +924,18 @@ so that the compiler does the right thing for options such as that are used in a variety of different places within the compiler