[m-rev.] diff: don't unify dummy variables (erlang)

Peter Wang novalazy at gmail.com
Thu Jun 4 18:03:49 AEST 2009


Branches: main

compiler/erl_unify_gen.m:
        Don't generate code to compare variables with dummy types.
        Such variables might not exist in the generated code.

tests/valid/Mmakefile:
tests/valid/unify_dummy.m:
        Add test case.


diff --git a/compiler/erl_unify_gen.m b/compiler/erl_unify_gen.m
index 506446e..f98871a 100644
--- a/compiler/erl_unify_gen.m
+++ b/compiler/erl_unify_gen.m
@@ -115,16 +115,25 @@ erl_gen_unification(Unification, CodeModel,
_Context, MaybeSuccessExpr,
     Unification = simple_test(Var1, Var2),
     expect(unify(CodeModel, model_semi), this_file,
         "erl_code_gen: simple_test not semidet"),
-    %
-    % case Var1 =:= Var2 of
-    %   true  -> MaybeSuccessExpr ;
-    %   false -> fail
-    % end
-    %
-    Statement = elds_case_expr(Test, [TrueCase, FalseCase]),
-    Test      = elds_binop((=:=), expr_from_var(Var1), expr_from_var(Var2)),
-    TrueCase  = elds_case(elds_true, expr_or_void(MaybeSuccessExpr)),
-    FalseCase = elds_case(elds_false, elds_term(elds_fail)).
+    erl_gen_info_get_module_info(!.Info, ModuleInfo),
+    erl_variable_type(!.Info, Var1, VarType),
+    IsDummy = check_dummy_type(ModuleInfo, VarType),
+    (
+        IsDummy = is_dummy_type,
+        Statement = expr_or_void(MaybeSuccessExpr)
+    ;
+        IsDummy = is_not_dummy_type,
+        %
+        % case Var1 =:= Var2 of
+        %   true  -> MaybeSuccessExpr ;
+        %   false -> fail
+        % end
+        %
+        Statement = elds_case_expr(Test, [TrueCase, FalseCase]),
+        Test      = elds_binop((=:=), expr_from_var(Var1),
expr_from_var(Var2)),
+        TrueCase  = elds_case(elds_true, expr_or_void(MaybeSuccessExpr)),
+        FalseCase = elds_case(elds_false, elds_term(elds_fail))
+    ).

 erl_gen_unification(Unification, CodeModel, Context, MaybeSuccessExpr,
         Statement, !Info) :-
diff --git a/tests/valid/Mmakefile b/tests/valid/Mmakefile
index 0bff3a6..0afb14b 100644
--- a/tests/valid/Mmakefile
+++ b/tests/valid/Mmakefile
@@ -234,6 +234,7 @@ OTHER_PROGS= \
 	unbound_inst_var \
 	unbound_tvar_in_lambda \
 	undead_proc \
+	unify_dummy \
 	uniq_mode_inf_bug \
 	uniq_unify \
 	unreachable_code \
diff --git a/tests/valid/unify_dummy.m b/tests/valid/unify_dummy.m
new file mode 100644
index 0000000..a903a37
--- /dev/null
+++ b/tests/valid/unify_dummy.m
@@ -0,0 +1,24 @@
+% In rotd-2009-06-03 and earlier the Erlang backend would generate code to
+% check two dummy type variables are equal, but those variables might not
+% exist.
+
+:- module unify_dummy.
+:- interface.
+
+:- type blah
+    --->    blah(int, dum).
+
+:- type dum
+    --->    dum.
+
+:- pred same_dumdum(blah::in, dum::in) is semidet.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+same_dumdum(blah(_, DumDum), DumDum).
+
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=8 sts=4 sw=4 et
--------------------------------------------------------------------------
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