[m-rev.] for review: Make is_type_a_dummy_loop handle abstractly imported dummy types.
Peter Wang
novalazy at gmail.com
Wed Apr 7 11:16:21 AEST 2021
compiler/type_util.m:
Make is_type_a_dummy_loop return is_dummy_type for an
abstractly imported subtype whose base type is a dummy type.
Make is_type_a_dummy_loop return is_dummy_type for abstract dummy
types. (I believe this currently has no effect because the bodies
of abstractly exported dummy types will be available from the .int
or .int2 file of the module they are defined in.)
tests/hard_coded/subtype_pack.exp:
Enable field with abstractly imported subtype. Previously the
compiler would generate a unify/compare predicate which tried to
unify/compare the dummy field, which either caused and exception
later, or generated target code that would not compile.
diff --git a/compiler/type_util.m b/compiler/type_util.m
index 18bbcad1b..54bff0808 100644
--- a/compiler/type_util.m
+++ b/compiler/type_util.m
@@ -861,11 +861,32 @@ is_type_a_dummy_loop(TypeTable, Type, CoveredTypes) = IsDummy :-
IsDummy = is_type_a_dummy_loop(TypeTable,
SingleArgType, [Type | CoveredTypes])
)
+ ;
+ TypeBody = hlds_abstract_type(AbstractDetails),
+ (
+ ( AbstractDetails = abstract_type_general
+ ; AbstractDetails = abstract_type_fits_in_n_bits(_)
+ ; AbstractDetails = abstract_notag_type
+ ; AbstractDetails = abstract_solver_type
+ ),
+ IsDummy = is_not_dummy_type
+ ;
+ AbstractDetails = abstract_dummy_type,
+ IsDummy = is_dummy_type
+ ;
+ AbstractDetails = abstract_subtype(SuperTypeCtor),
+ % It does not matter what the supertype type parameters
+ % are bound to, only that they are not dummy types.
+ SuperTypeCtor = type_ctor(_, Arity),
+ list.duplicate(Arity, int_type, FakeArgTypes),
+ construct_type(SuperTypeCtor, FakeArgTypes, SuperType),
+ IsDummy = is_type_a_dummy_loop(TypeTable, SuperType,
+ [Type | CoveredTypes])
+ )
;
( TypeBody = hlds_eqv_type(_)
; TypeBody = hlds_foreign_type(_)
; TypeBody = hlds_solver_type(_)
- ; TypeBody = hlds_abstract_type(_)
),
IsDummy = is_not_dummy_type
)
diff --git a/tests/hard_coded/subtype_pack.exp b/tests/hard_coded/subtype_pack.exp
index 325cce5ab..59fb5b0b9 100644
--- a/tests/hard_coded/subtype_pack.exp
+++ b/tests/hard_coded/subtype_pack.exp
@@ -1,2 +1,2 @@
-struct(orange, lemon, dummy, notag(notag0(orange)), notag(notag0(lemon)), tagged(42), tagged(4242), lemon, 3.14159, dog, dog, abs_notag(42))
-struct(orange, lemon, dummy, notag(notag0(orange)), notag(notag0(lemon)), tagged(42), tagged(4242), lemon, 3.14159, dog, dog, abs_notag(42))
+struct(orange, lemon, dummy, notag(notag0(orange)), notag(notag0(lemon)), tagged(42), tagged(4242), lemon, 3.14159, dog, dog, dummy, abs_notag(42))
+struct(orange, lemon, dummy, notag(notag0(orange)), notag(notag0(lemon)), tagged(42), tagged(4242), lemon, 3.14159, dog, dog, dummy, abs_notag(42))
diff --git a/tests/hard_coded/subtype_pack.m b/tests/hard_coded/subtype_pack.m
index a2a515b5b..bec47d692 100644
--- a/tests/hard_coded/subtype_pack.m
+++ b/tests/hard_coded/subtype_pack.m
@@ -82,10 +82,7 @@
f6 :: U, % word
f7_1 :: sub_abs_enum, % 3 bits (packed)
f7_2 :: sub_abs_enum, % 3 bits (packed)
- % XXX SUBTYPE
- % This currently results in an abort in the LLDS backend, and
- % the MLDS backends generate code that won't compile.
- %f8_0 :: sub_abs_dummy, % 0 bits
+ f8_0 :: sub_abs_dummy, % 0 bits
f8 :: sub_abs_notag % word
).
@@ -102,7 +99,7 @@
s_f6 :: float, % differs from base
s_f7_1 :: sub_abs_enum,
s_f7_2 :: sub_abs_enum,
- %s_f8_0 :: sub_abs_dummy,
+ s_f8_0 :: sub_abs_dummy,
s_f8 :: sub_abs_notag
).
@@ -119,7 +116,7 @@ main(!IO) :-
3.14159,
make_sub_abs_enum,
make_sub_abs_enum,
- % make_sub_abs_dummy,
+ make_sub_abs_dummy,
make_sub_abs_notag
),
io.print_line(Sub : substruct, !IO),
--
2.30.0
More information about the reviews
mailing list