mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-17 02:13:54 +00:00
Branches: main
Implement a type representation optimisation ("direct argument functors"),
where a functor with exactly one argument can be represented by a tagged
pointer to the argument value, which itself does not require the tag bits,
e.g.
:- type maybe_foo ---> yes(foo) ; no.
:- type foo ---> foo(int, int). % aligned pointer
To ensure that all modules which could construct or deconstruct the functor
agree on the type representation, I had planned to automatically output
extra information to .int files to notify importing modules about functors
using the optimised representation:
:- type maybe_foo ---> yes(foo) ; no
where direct_arg is [yes/1].
However, the compiler does not perform enough (or any) semantic analysis
while making interface files. The fallback solution is to only use the
optimised representation when all importing modules can be guaranteed to
import both the top-level type and the argument type, namely, when both
types are exported from the same module. We also allow certain built-in
argument types; currently this only includes tuples.
Non-exported types may use the optimised representation, but when
intermodule optimisation is enabled, they may be written out to .opt files.
Then, we *do* add direct_arg attributes to .opt files to ensure that importing
modules agree on the type representation. The attributes may also be added by
Mercury programmers to source files, which will be copied directly into .int
files without analysis. They will be checked when the module is actually
compiled.
This patch includes work by Zoltan, who independently implemented a version
of this change.
compiler/hlds_data.m:
Record the direct arg functors in hlds_du_type.
Add a new option to cons_tag.
Fix some comments.
compiler/prog_data.m:
compiler/prog_io_type_defn.m:
Parse and record `direct_arg' attributes on type definitions.
compiler/prog_io_pragma.m:
Issue an error if the `direct_arg' attribute is used with a foreign
type.
compiler/make_tags.m:
compiler/mercury_compile_front_end.m:
Add a pass to convert suitable functors to use the direct argument
representation. The argument type must have been added to the type
table, so we do this after all type definitions have been added.
Move code to compute cheaper_tag_test here.
compiler/ml_unify_gen.m:
compiler/unify_gen.m:
Generate different code to construct/deconstruct direct argument
functors.
compiler/intermod.m:
Write `direct_arg' attributes to .opt files for functors
using the direct argument representation.
compiler/mercury_to_mercury.m:
Write out `direct_arg' attributes.
compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
Add an option to the types which describe the location of secondary
tag options. The functors which can use the optimised representation
are a subset of those which require no secondary tag.
Output "MR_SECTAG_NONE_DIRECT_ARG" instead of "MR_SECTAG_NONE" in
RTTI structures when applicable.
compiler/add_pragma.m:
compiler/add_type.m:
compiler/bytecode_gen.m:
compiler/check_typeclass.m
compiler/code_info.m:
compiler/equiv_type.m:
compiler/export.m:
compiler/foreign.m:
compiler/hlds_code_util.m:
compiler/hlds_out_module.m:
compiler/inst_check.m:
compiler/ml_proc_gen.m:
compiler/ml_switch_gen.m:
compiler/ml_tag_switch.m:
compiler/ml_type_gen.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/post_term_analysis.m:
compiler/post_typecheck.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/simplify.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/tag_switch.m:
compiler/term_norm.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
Conform to changes.
Bump RTTI version number.
doc/reference_manual.texi:
Add commented out documentation for `direct_arg' attributes.
library/construct.m:
Handle MR_SECTAG_NONE_DIRECT_ARG in construct.construct/3.
library/private_builtin.m:
Add MR_SECTAG_NONE_DIRECT_ARG constant for Java for consistency,
though it won't be used.
runtime/mercury_grade.h:
Bump binary compatibility version number.
runtime/mercury_type_info.h:
Bump RTTI version number.
Add MR_SECTAG_NONE_DIRECT_ARG.
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_table_type_body.h:
runtime/mercury_term_size.c:
runtime/mercury_unify_compare_body.h:
Handle MR_SECTAG_NONE_DIRECT_ARG in RTTI code.
tests/debugger/Mmakefile:
tests/debugger/chooser_tag_test.exp:
tests/debugger/chooser_tag_test.inp:
tests/debugger/chooser_tag_test.m:
tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/construct_test.exp:
tests/hard_coded/construct_test.m:
tests/hard_coded/direct_arg_cyclic1.exp:
tests/hard_coded/direct_arg_cyclic1.m:
tests/hard_coded/direct_arg_cyclic2.m:
tests/hard_coded/direct_arg_cyclic3.m:
tests/hard_coded/direct_arg_intermod1.exp:
tests/hard_coded/direct_arg_intermod1.m:
tests/hard_coded/direct_arg_intermod2.m:
tests/hard_coded/direct_arg_intermod3.m:
tests/hard_coded/direct_arg_parent.exp:
tests/hard_coded/direct_arg_parent.m:
tests/hard_coded/direct_arg_sub.m:
tests/invalid/Mmakefile:
tests/invalid/where_direct_arg.err_exp:
tests/invalid/where_direct_arg.m:
tests/invalid/where_direct_arg2.err_exp:
tests/invalid/where_direct_arg2.m:
Add test cases.
tests/invalid/ee_invalid.err_exp:
Update expected output.
238 lines
5.5 KiB
Plaintext
238 lines
5.5 KiB
Plaintext
TESTING DISCRIMINATED UNIONS
|
|
3 functors in this type
|
|
2 - two/0 [] ordinal: 1 lex: 2
|
|
1 - three/0 [] ordinal: 2 lex: 1
|
|
0 - one/0 [] ordinal: 0 lex: 0
|
|
|
|
|
|
3 functors in this type
|
|
2 - two/0 [] ordinal: 1 lex: 2
|
|
1 - three/0 [] ordinal: 2 lex: 1
|
|
0 - one/0 [] ordinal: 0 lex: 0
|
|
|
|
|
|
3 functors in this type
|
|
2 - two/0 [] ordinal: 1 lex: 2
|
|
1 - three/0 [] ordinal: 2 lex: 1
|
|
0 - one/0 [] ordinal: 0 lex: 0
|
|
|
|
|
|
2 functors in this type
|
|
1 - banana/1 [banana_list] ordinal: 1 lex: 1
|
|
0 - apple/1 [apple_list] ordinal: 0 lex: 0
|
|
|
|
|
|
2 functors in this type
|
|
1 - banana/1 [banana_list] ordinal: 1 lex: 1
|
|
0 - apple/1 [apple_list] ordinal: 0 lex: 0
|
|
|
|
|
|
11 functors in this type
|
|
10 - zop/2 [_, _] ordinal: 10 lex: 10
|
|
9 - zoom/1 [_] ordinal: 7 lex: 9
|
|
8 - zip/2 [_, _] ordinal: 9 lex: 8
|
|
7 - zap/2 [_, _] ordinal: 8 lex: 7
|
|
6 - wombat/0 [] ordinal: 6 lex: 6
|
|
5 - qux/1 [_] ordinal: 3 lex: 5
|
|
4 - quux/1 [_] ordinal: 4 lex: 4
|
|
3 - quuux/2 [_, _] ordinal: 5 lex: 3
|
|
2 - foo/0 [] ordinal: 0 lex: 2
|
|
1 - bar/2 [_, _] ordinal: 2 lex: 1
|
|
0 - bar/1 [_] ordinal: 1 lex: 0
|
|
|
|
|
|
11 functors in this type
|
|
10 - zop/2 [_, _] ordinal: 10 lex: 10
|
|
9 - zoom/1 [_] ordinal: 7 lex: 9
|
|
8 - zip/2 [_, _] ordinal: 9 lex: 8
|
|
7 - zap/2 [_, _] ordinal: 8 lex: 7
|
|
6 - wombat/0 [] ordinal: 6 lex: 6
|
|
5 - qux/1 [_] ordinal: 3 lex: 5
|
|
4 - quux/1 [_] ordinal: 4 lex: 4
|
|
3 - quuux/2 [_, _] ordinal: 5 lex: 3
|
|
2 - foo/0 [] ordinal: 0 lex: 2
|
|
1 - bar/2 [_, _] ordinal: 2 lex: 1
|
|
0 - bar/1 [_] ordinal: 1 lex: 0
|
|
|
|
|
|
11 functors in this type
|
|
10 - zop/2 [_, _] ordinal: 10 lex: 10
|
|
9 - zoom/1 [_] ordinal: 7 lex: 9
|
|
8 - zip/2 [_, _] ordinal: 9 lex: 8
|
|
7 - zap/2 [_, _] ordinal: 8 lex: 7
|
|
6 - wombat/0 [] ordinal: 6 lex: 6
|
|
5 - qux/1 [_] ordinal: 3 lex: 5
|
|
4 - quux/1 [_] ordinal: 4 lex: 4
|
|
3 - quuux/2 [_, _] ordinal: 5 lex: 3
|
|
2 - foo/0 [] ordinal: 0 lex: 2
|
|
1 - bar/2 [_, _] ordinal: 2 lex: 1
|
|
0 - bar/1 [_] ordinal: 1 lex: 0
|
|
|
|
|
|
11 functors in this type
|
|
10 - zop/2 [_, _] ordinal: 10 lex: 10
|
|
9 - zoom/1 [_] ordinal: 7 lex: 9
|
|
8 - zip/2 [_, _] ordinal: 9 lex: 8
|
|
7 - zap/2 [_, _] ordinal: 8 lex: 7
|
|
6 - wombat/0 [] ordinal: 6 lex: 6
|
|
5 - qux/1 [_] ordinal: 3 lex: 5
|
|
4 - quux/1 [_] ordinal: 4 lex: 4
|
|
3 - quuux/2 [_, _] ordinal: 5 lex: 3
|
|
2 - foo/0 [] ordinal: 0 lex: 2
|
|
1 - bar/2 [_, _] ordinal: 2 lex: 1
|
|
0 - bar/1 [_] ordinal: 1 lex: 0
|
|
|
|
|
|
11 functors in this type
|
|
10 - zop/2 [_, _] ordinal: 10 lex: 10
|
|
9 - zoom/1 [_] ordinal: 7 lex: 9
|
|
8 - zip/2 [_, _] ordinal: 9 lex: 8
|
|
7 - zap/2 [_, _] ordinal: 8 lex: 7
|
|
6 - wombat/0 [] ordinal: 6 lex: 6
|
|
5 - qux/1 [_] ordinal: 3 lex: 5
|
|
4 - quux/1 [_] ordinal: 4 lex: 4
|
|
3 - quuux/2 [_, _] ordinal: 5 lex: 3
|
|
2 - foo/0 [] ordinal: 0 lex: 2
|
|
1 - bar/2 [_, _] ordinal: 2 lex: 1
|
|
0 - bar/1 [_] ordinal: 1 lex: 0
|
|
|
|
|
|
|
|
TESTING POLYMORPHISM
|
|
4 functors in this type
|
|
3 - poly_two/1 [_] ordinal: 1 lex: 3
|
|
2 - poly_three/3 [_, poly3_field2, _] ordinal: 2 lex: 2
|
|
1 - poly_one/1 [_] ordinal: 0 lex: 1
|
|
0 - poly_four/2 [_, _] ordinal: 3 lex: 0
|
|
|
|
|
|
4 functors in this type
|
|
3 - poly_two/1 [_] ordinal: 1 lex: 3
|
|
2 - poly_three/3 [_, poly3_field2, _] ordinal: 2 lex: 2
|
|
1 - poly_one/1 [_] ordinal: 0 lex: 1
|
|
0 - poly_four/2 [_, _] ordinal: 3 lex: 0
|
|
|
|
|
|
4 functors in this type
|
|
3 - poly_two/1 [_] ordinal: 1 lex: 3
|
|
2 - poly_three/3 [_, poly3_field2, _] ordinal: 2 lex: 2
|
|
1 - poly_one/1 [_] ordinal: 0 lex: 1
|
|
0 - poly_four/2 [_, _] ordinal: 3 lex: 0
|
|
|
|
|
|
|
|
TESTING BUILTINS
|
|
no functors in this type
|
|
|
|
no functors in this type
|
|
|
|
no functors in this type
|
|
|
|
no functors in this type
|
|
|
|
no functors in this type
|
|
|
|
no functors in this type
|
|
|
|
no functors in this type
|
|
|
|
no functors in this type
|
|
|
|
no functors in this type
|
|
|
|
no functors in this type
|
|
|
|
no functors in this type
|
|
|
|
no functors in this type
|
|
|
|
1 functors in this type
|
|
0 - {}/4 [_, _, _, _] ordinal: 0 lex: 0
|
|
|
|
|
|
2 functors in this type
|
|
1 - [|]/2 [_, _] ordinal: 1 lex: 1
|
|
0 - []/0 [] ordinal: 0 lex: 0
|
|
|
|
|
|
|
|
TESTING OTHER TYPES
|
|
1 functors in this type
|
|
0 - var/1 [_] ordinal: 0 lex: 0
|
|
|
|
|
|
1 functors in this type
|
|
0 - var_supply/1 [_] ordinal: 0 lex: 0
|
|
|
|
|
|
1 functors in this type
|
|
0 - var_supply/1 [_] ordinal: 0 lex: 0
|
|
|
|
|
|
4 functors in this type
|
|
3 - two/4 [_, _, _, _] ordinal: 1 lex: 3
|
|
2 - three/7 [_, _, _, _, _, _, _] ordinal: 2 lex: 2
|
|
1 - four/10 [_, _, _, _, _, _, _, _, _, _] ordinal: 3 lex: 1
|
|
0 - empty/0 [] ordinal: 0 lex: 0
|
|
|
|
|
|
1 functors in this type
|
|
0 - qwerty/1 [qwerty_field] ordinal: 0 lex: 0
|
|
|
|
|
|
1 functors in this type
|
|
0 - dummy/0 [] ordinal: 0 lex: 0
|
|
|
|
|
|
2 functors in this type
|
|
1 - unboxed_arg/1 [_] ordinal: 1 lex: 1
|
|
0 - no/0 [] ordinal: 0 lex: 0
|
|
|
|
|
|
1 functors in this type
|
|
0 - xyzzy/1 [f21name] ordinal: 0 lex: 0
|
|
|
|
|
|
About to construct three/0
|
|
Constructed: three
|
|
About to construct apple/1
|
|
Constructed: apple([1, 2, 3])
|
|
About to construct banana/1
|
|
Constructed: banana([one, two, three])
|
|
About to construct foo/0
|
|
Constructed: foo
|
|
About to construct bar/1
|
|
Constructed: bar(1)
|
|
About to construct bar/2
|
|
Constructed: bar(1, 1)
|
|
About to construct qux/1
|
|
Constructed: qux(1)
|
|
About to construct quux/1
|
|
Constructed: quux(1)
|
|
About to construct quuux/2
|
|
Constructed: quuux(1, 1)
|
|
About to construct wombat/0
|
|
Constructed: wombat
|
|
About to construct zoom/1
|
|
Constructed: zoom(1)
|
|
About to construct zap/2
|
|
Constructed: zap(1, 2.1)
|
|
About to construct zip/2
|
|
Constructed: zip(1, 1)
|
|
About to construct zop/2
|
|
Constructed: zop(2.1, 2.1)
|
|
About to construct qwerty/1
|
|
Constructed: qwerty(1)
|
|
About to construct unboxed_arg/1
|
|
Constructed: unboxed_arg(unboxed_struct(12, 34))
|
|
About to construct poly_one/1
|
|
Constructed: poly_one(1)
|
|
About to construct poly_two/1
|
|
Constructed: poly_two("goodbye")
|
|
About to construct poly_four/2
|
|
Constructed: poly_four(1, "goodbye")
|
|
About to construct {}/3
|
|
Constructed: {4, "five", '6'}
|
|
About to call construct_tuple
|
|
Constructed tuple: univ_cons({[1, 2, 3], [one, two, three], 1, 2.1})
|