Commit Graph

102 Commits

Author SHA1 Message Date
Zoltan Somogyi
fa9ca36d03 This diff makes several files easier to read and to maintain (as well as
Estimated hours taken: 5
Branches: main

This diff makes several files easier to read and to maintain (as well as
more than 400 lines shorter), but contains no changes in algorithms whatsoever.

compiler/deep_profiling.m:
compiler/foreign.m:
compiler/hlds_module.m:
compiler/hlds_data.m:
compiler/make_hlds.m:
compiler/post_typecheck.m:
compiler/prog_data.m:
compiler/purity.m:
compiler/type_util.m:
	Bring these modules into line with our current coding standards.

	Use predmode declarations and state variable syntax when appropriate.

	Reorder arguments of predicates where necessary for the use of state
	variable syntax, and where this improves readability.

	Replace predicates with functions where appropriate.

	Standardize indentation.

compiler/*.m:
	Conform to the changes above.
2003-12-21 05:04:38 +00:00
Simon Taylor
82c6cdb55e Make definitions of abstract types available when generating
Estimated hours taken: 100
Branches: main

Make definitions of abstract types available when generating
code for importing modules.  This is necessary for the .NET
back-end, and for `:- pragma export' on the C back-end.

compiler/prog_data.m:
compiler/modules.m:
compiler/make.dependencies.m:
compiler/recompilation.version.m:
	Handle implementation sections in interface files.

	There is a new pseudo-declaration `abstract_imported'
	which is applied to items from the implementation
	section of an interface file.  `abstract_imported'
	items may not be used in the error checking passes
	for the curent module.

compiler/equiv_type_hlds.m:
compiler/notes/compiler_design.html:
	New file.

	Go over the HLDS expanding all types fully after
	semantic checking has been run.

compiler/mercury_compile.m:
	Add the new pass.

	Don't write the `.opt' file if there are any errors.

compiler/instmap.m:
	Add a predicate instmap_delta_map_foldl to apply
	a procedure to all insts in an instmap.

compiler/equiv_type.m:
	Export predicates for use by equiv_type_hlds.m

	Reorder arguments so state variables and higher-order
	programming can be used.

compiler/prog_data.m:
compiler/prog_io_pragma.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
	Handle `:- pragma foreign_type' as a form of type
	declaration rather than a pragma.

compiler/hlds_data.m:
compiler/*.m:
	Add a field to the type_info_cell_constructor cons_id
	to identify the type_ctor, which is needed by
	equiv_type_hlds.m.

compiler/module_qual.m:
	Donn't allow items from the implementation section of
	interface files to match items in the current module.

compiler/*.m:
tests/*/*.m:
	Add missing imports which only became apparent with
	the bug fixes above.

	Remove unnecessary imports which only became apparent with
	the bug fixes above.

tests/hard_coded/Mmakefile:
tests/hard_coded/export_test2.{m,exp}:
	Test case.

tests/invalid/Mmakefile:
tests/invalid/missing_interface_import2.{m,err_exp}:
	Test case.
2003-12-01 15:56:15 +00:00
Zoltan Somogyi
4b1cf91069 Address Fergus's review comments.
Estimated hours taken: 0.1
Branches: main

compiler/prog_data.m:
	Address Fergus's review comments.
2003-11-05 06:05:25 +00:00
Zoltan Somogyi
9b9d7b81e0 Add field names to the pragma_type type.
Estimated hours taken: 0.25
Branches: main

compiler/prog_data.m:
	Add field names to the pragma_type type.
2003-11-05 03:12:20 +00:00
Zoltan Somogyi
03cbbf4fc0 Improve the clarity of polymorphism.m further.
Estimated hours taken: 2
Branches: main

Improve the clarity of polymorphism.m further.

compiler/polymorphism.m:
	When a data structure involving type variables has several versions
	which differ in which tvarset those type variables come from (the raw
	tvarset of a called predicate's pred_info, the renamed-apart version
	in which those type variables have been lifted into the caller's
	newly expanded tvarset, and the version in which the type variables
	in the types of the formal parameters been replaced with the actual
	(possibly polymorphic) types from the actual arguments), use a
	mnemonic prefix to distinguish them, not a numerical suffix of
	the kind we use for other kinds of transformations.

	Put the code handling foreign_procs into its own predicate, to
	make debugging easier.

compiler/prog_data.m:
	Add field names to the class_constraints type, for use in
	polymorphism.m.

compiler/type_util.m:
	Add a utility predicate, factoring out repeated code from
	polymorphism.m.

library/varset.m:
	Clarify the documentation of varset__merge_subst.
2003-10-27 05:36:53 +00:00
Simon Taylor
5fa9a4b111 Remove the unimplemented aditi_filter and aditi_modify
Estimated hours taken: 0.5
Branches: main

compiler/*.m:
	Remove the unimplemented aditi_filter and aditi_modify
	goals -- they will never be implemented.

	Remove the `aditi_top_down' lambda_eval_method, which was only
	used for those update goals.  Even if those update goals were
	to be implemented, a special type of lambda expression
	shouldn't actually be needed.

	Use clearer names for the updates in the constructors
	of the aditi_builtin type.
2003-09-19 11:10:04 +00:00
David Overton
2ad2f0a28e Allow types to be declared as "solver" types using the syntax
Estimated hours taken: 120
Branches: main

Allow types to be declared as "solver" types using the syntax
`:- solver type ...'.

For a non-solver type t (i.e. any type declared without using the
`solver' keyword), the inst `any' should be considered to be equivalent
to a bound inst i where i contains all the functors of the type t and
each argument has inst `any'.  For solver types, `any' retains its
previous meaning.

This is required to allow us to represent HAL's `old' inst using `any'.
In HAL, `old' is like `any' if the type is an instance of a particular
type class (`solver/1').  However, for types that are not instances of
`solver/1', `old' needs to be treated as though it is `bound'.

library/ops.m:
	Add `solver' as a unary prefix operator.

compiler/prog_data.m:
	Add a field to the type `type_defn' to record whether or not the
	type is a solver type.

compiler/hlds_data.m:
	Add an equivalent field to the type `hlds_type_body'.

compiler/prog_io.m:
compiler/make_hlds.m:
compiler/modules.m:
compiler/mercury_to_mercury.m:
compiler/hlds_out.m:
	Handle the new ":- solver type ..." syntax.

compiler/det_report.m:
compiler/equiv_type.m:
compiler/foreign.m:
compiler/hlds_code_util.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_code_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/module_qual.m:
compiler/post_typecheck.m:
compiler/pragma_c_gen.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/special_pred.m:
compiler/stack_opt.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
	Handle the changes to `type_defn' and `hlds_type_body'.

compiler/type_util.m:
	Add predicates `type_util__is_solver_type' and
	`type_body_is_solver_type'.

compiler/inst_match.m:
compiler/inst_util.m:
	In inst_matches_{initial,final,binding} and
	abstractly_unify_inst_functor, when we are comparing `any' insts, check
	whether or not the type is a solver type and treat it appropriately.

compiler/instmap.m:
compiler/modecheck_unify.m:
	Pass type information to abstractly_unify_inst_functor.

compiler/mode_util.m:
	Add a predicate `constructors_to_bound_any_insts' which is the same as
	`constructors_to_bound_insts' except that it makes the arguments of the
	bound inst `any' instead of `ground'.

tests/invalid/any_mode.m:
tests/invalid/any_mode.err_exp:
tests/hard_coded/any_free_unify.m:
	Modify these test cases to use a "solver" type instead of `int'.

tests/valid/any_matches_bound.m:
tests/valid/Mmakefile:
tests/invalid/Mmakefile:
tests/invalid/any_should_not_match_bound.m:
tests/invalid/any_should_not_match_bound.err_exp:
	Add new test cases.

extras/trailed_update/var.m:
clpr/cfloat.m:
	Modify to use the new `:- solver type' syntax.
2003-07-25 02:27:37 +00:00
David Overton
127fe0f85f Fixes to allow testing of ground' matches bound'.
Estimated hours taken: 10
Branches: main

Fixes to allow testing of `ground' matches `bound'.

compiler/modules.m:
	When writing discriminated union types to the .int2 file, write
	out the full type definition rather than an abstract type
	declaration.  This is necessary because a module which
	transitively imports the .int2 file may need to know the
	constructors to allow `ground' to be compared with `bound'
	insts.  See the new test case `transitive_inst_type' for an
	example.  If the type has user-defined equality and/or comparison
	predicates then we write "... where type_is_abstract_noncanonical"
	to the .int2 file instead of giving the predicate names.

compiler/make_hlds.m:
	If a discriminated union type is imported from a .int2 file, mark it
	as `abstract_imported'.

compiler/typecheck.m:
	When type checking var-functor unifications, do not allow functors
	whose types are `abstract_imported', unless we are type checking an
	`opt_imported' predicate.

compiler/prog_data.m:
	Add a new alternative `abstract_noncanonical_type' to the type
	`unify_compare' to represent "where type_is_abstract_noncanonical"
	annotations read from .int2 files.

compiler/prog_io.m:
	Parse "where type_is_abstract_noncanonical" annotations on
	discriminated union types.

compiler/special_pred.m:
compiler/unify_proc.m:
	Avoid creating unification and comparison predicates
	for types with `type_is_abstract_noncanonical' annotations.

compiler/intermod.m:
	Handle the change to the `unify_compare' type.

compiler/type_util.m:
	Do not remove module qualifiers from constructors before looking
	them up in the cons table.  Some cons ids only have the
	qualified version in the table.

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
tests/hard_coded/transitive_inst_type.exp:
tests/hard_coded/transitive_inst_type.m:
tests/hard_coded/transitive_inst_type2.m:
tests/hard_coded/transitive_inst_type3.m:
tests/hard_coded/trans_intermod_user_equality.exp:
tests/hard_coded/trans_intermod_user_equality.m:
tests/hard_coded/trans_intermod_user_equality2.m:
tests/hard_coded/trans_intermod_user_equality3.m:
	Add some test cases.
2003-07-22 07:04:26 +00:00
Fergus Henderson
016d874f7e Add some comments.
Estimated hours taken: 0.5
Branches: main

compiler/prog_data.m:
	Add some comments.
2003-06-17 07:53:28 +00:00
Zoltan Somogyi
3cc05d4aa6 Add field names to the main types defined here, and use them to
Estimated hours taken: 0.2
Branches: main

compiler/hlds_data.m:
	Add field names to the main types defined here, and use them to
	implement get and set predicates where they exist.

	Indent some type definitions by one less tab, to make it easier
	to write comments on the fields.

	Comment out the condition fields in these types, since we don't use
	them, and they can be added back later trivially.

compiler/prog_data,m:
	Add field names to the various kinds of items.

	Leave the condition fields in items as they are, since if we deleted
	them, adding them back later would be a bit more than trivial.

compiler/intermod.m:
compiler/make_hlds.m:
compiler/mode_util.m:
compiler/recompilation.usage.m:
	Ignore condition fields where relevant.
2003-05-08 03:39:56 +00:00
Zoltan Somogyi
9551640f55 Import only one compiler module per line. Sort the blocks of imports.
Estimated hours taken: 2
Branches: main

compiler/*.m:
	Import only one compiler module per line. Sort the blocks of imports.
	This makes it easier to merge in changes.

	In a couple of places, remove unnecessary imports.
2003-03-15 03:09:14 +00:00
Simon Taylor
482105e074 Allow user-defined comparison functions using the syntax
Estimated hours taken: 10
Branches: main

Allow user-defined comparison functions using the syntax
:- type t ---> t where equality is t_equal, comparison is t_compare.
.
Allow user-defined equality and comparison for foreign types using the syntax
:- pragma foreign_type(c, t, "c_t") where
		equality is t_equal, comparison is t_compare.

compiler/prog_data.m:
compiler/mercury_to_mercury.m:
compiler/hlds_out.m:
compiler/*.m:
	Allow comparison predicates in `type' and `pragma foreign_type'
	declarations

compiler/hlds_data.m:
compiler/*.m:
	Allow equality and comparison predicates to be attached
	to foreign types.

compiler/prog_io.m:
compiler/prog_io_pragma.m:
	Parse the new syntax.

compiler/make_hlds.m:
	Don't add the types to the HLDS or do typechecking if
	there are errors in the type declarations.
	Test case: tests/invalid/foreign_type_visibility.m.

compiler/foreign.m:
compiler/special_pred.m:
compiler/type_util.m:
	Check whether foreign types have user-defined equality.

compiler/unify_proc.m:
	Generate clauses for user-defined comparison,
	and clauses for unification for foreign types.

compiler/intermod.m:
	Resolve overloading before writing the `.opt' files.

library/builtin.m:
	Add `uo' modes for promise_only_solution, for use in
	user-defined comparison predicates.

	Add types and insts to allow declaration of user-defined
	comparison predicates using `with_type` and `with_inst`.
	We already have types and insts `builtin__comparison_pred',
	but they have a different argument ordering to `compare/3'.

NEWS:
doc/reference_manual.texi:
	Document the change.

tests/hard_coded/Mmakefile:
tests/hard_coded/user_compare.{m,exp}:
	Test case.

tests/invalid/Mmakefile:
tests/invalid/typeclass_test_{9,10}.{m,err_exp}:
tests/invalid/purity/purity_nonsense{,2}.{m,err_exp}:
	The change to error-checking in make_hlds.m meant that
	the compilation stopped before some errors in
	typeclass_test_9.m were detected. The code which
	tests for those errors is now in typeclass_test_10.m.
2003-02-12 22:58:20 +00:00
Michael Wybrow
cdca9fed0a Add Java support to the foreign language interface.
Estimated hours taken: 70
Branches: main

Add Java support to the foreign language interface.

mercury/compiler/compile_target_code.m:
mercury/compiler/make.module_target.m:
mercury/compiler/mercury_compile.m:
	Pass `compile_java_file' a Java filename rather than a module name.

mercury/compiler/globals.m:
	Add `java' as a `foreign_language'.

mercury/compiler/handle_options.m:
	Allow Java as a back-end foreign language if the target language
	is Java.

mercury/compiler/hlds_data.m:
	Allow Java foreign_types.

mercury/compiler/intermod.m:
mercury/compiler/foreign.m:
mercury/compiler/make.util.m:
mercury/compiler/make_hlds.m:
mercury/compiler/mercury_compile.m:
mercury/compiler/mercury_to_mercury.m:
mercury/compiler/ml_code_gen.m:
mercury/compiler/mlds.m:
mercury/compiler/mlds_to_c.m:
mercury/compiler/mlds_to_il.m:
mercury/compiler/mlds_to_ilasm.m:
mercury/compiler/mlds_to_java.m:
mercury/compiler/pragma_c_gen.m:
mercury/compiler/prog_data.m:
mercury/compiler/prog_io_pragma.m:
	Add or modify existing code to support `java' as a `foreign_language'
	and Java `foreign_type's.

mercury/compiler/mlds_to_java.m:
	Nicely indent the generated code that unboxes arguments from
	return-argument	arrays which are used for methods with multiple
	return arguments.
2003-02-11 02:14:28 +00:00
Fergus Henderson
17f53149a4 Implement `:- pragma reserve_tag(<TypeName>/<Arity>).'.
Estimated hours taken: 6
Branches: main

Implement `:- pragma reserve_tag(<TypeName>/<Arity>).'.
This has the same effect as the `--reserve-tag' option,
except that it only applies to specified type, rather than
to all types.

doc/reference_manual.texi:
	Document the new feature.
	(However, the documentation is currently commented out.)

compiler/prog_data.m:
	Add `reserve_tag(sym_name, arity)' to the `pragma_type' type.

compiler/hlds_data.m:
	Add a new boolean field to the representation of discriminated union
	type bodies to record whether or not the type has a reserved tag.

compiler/prog_io_pragma.m:
	Add code to parse the new pragma.

compiler/make_hlds.m:
	Add code to process the new pragma:
	- check all the appropriate semantic restrictions:
		- the pragma must have the same visibility as the type
		- the type must be defined
		- the type must be a discriminated union type
	- warn if there are multiple such pragmas for the same type
	- call make_tags.m to recompute the tags used for the constructor.
	- record the presence of the reserve_tag pragma in the HLDS type
	  definition body

compiler/make_tags.m:
compiler/type_util.m:
	Add an extra argument to assign_constructor_tags (in make_tags.m)
	and type_constructors_should_be_no_tag (in type_util.m)
	to specify whether or not there was a `reserve_tag' pragma.
	Reserve a tag if either this argument or the global `reserve_tag'
	option is set.

compiler/intermod.m:
	Output a `:- reserve_tag' pragma whenever outputting a type
	to which such a pragma applies.

compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
	Ignore the reserved_tag field.
	XXX This means that the `reserve_tag' pragma (or the compiler
	    option) won't have much effect if --high-level-data is set.

compiler/code_util.m:
compiler/det_report.m:
compiler/hlds_out.m:
compiler/magic_util.m:
compiler/mercury_to_mercury.m:
compiler/mode_util.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/post_typecheck.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/special_pred.m:
compiler/stack_opt.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
	Trivial changes to handle the new reserved_tag field of
	hlds_type_defn_body.

tests/valid/Mmakefile:
tests/valid/reserve_tag.m:
tests/invalid/Mmakefile:
tests/invalid/reserve_tag.m:
tests/invalid/reserve_tag.err_exp:
	Some tests of the new feature.
2003-01-14 16:42:44 +00:00
Fergus Henderson
2c1fc7f0c2 Order the declarations of the different pragma types into
Estimated hours taken: 0.25
Branches: main

compiler/prog_data.m:
	Order the declarations of the different pragma types into
	logically related groups.  Add some comments.
2003-01-10 10:58:17 +00:00
Simon Taylor
681d78c92b Fix a bug which caused misleading error messages when
Estimated hours taken: 1
Branches: main

Fix a bug which caused misleading error messages when
the module qualifier for an undefined symbol matched a
module imported only by ancestor modules.

compiler/make_hlds.m:
	Add modules imported by ancestor modules to the list
	of imported modules.

compiler/modules.m:
compiler/prog_data.m:
compiler/hlds_pred.m:
compiler/*.m:
	Record which items are imported from ancestor modules.

	Reorder the arguments of `modules__append_pseudo_decl'
	to make it easier to use with state variables.

	Use state variable syntax in `modules__grab_imported_modules'.

compiler/hlds_module.m:
	Remove an XXX comment documenting this bug.

configure.in:
	Check for state variable syntax when checking whether
	the compiler is up-to-date.

tests/invalid/Mmakefile:
tests/invalid/import_in_parent.{m,err_exp}:
	Test case.
2002-10-24 04:36:57 +00:00
Zoltan Somogyi
41724c68de Add two new annotations for foreign_procs, tabled_for_descendant_io and
Estimated hours taken: 16
Branches: main

Add two new annotations for foreign_procs, tabled_for_descendant_io and
tabled_for_io_unitize.

By adding the tabled_for_descendant_io annotation to a foreign_proc with I/O
states, the programmer is asserting that the foreign_proc itself doesn't do
I/O, and nor does any foreign language code it calls, though the Mercury
predicates it calls may.

By adding the tabled_for_io_unitize annotation to a foreign_proc with I/O
states, the programmer is saying that both the foreign_proc itself and the
Mercury predicates it calls may do I/O. To avoid the I/O tabling problems
that would arise on retries from Mercury code called by the foreign_proc,
the programmer is requesting that the debugger treat calls to the foreign_proc
as a unit. This means that if I/O tabling is turned on, then the implementation
will disable both debugging and I/O tabling inside Mercury code called from
the foreign_proc.

compiler/prog_data.m:
	Add the tabled_for_descendant_io and tabled_for_io_unitize annotations.

	Parameterize the eval_table_io eval_method to accommodate the
	unitization of foreign_procs.

compiler/prog_io_pragma.m:
	Add code to read in the tabled_for_descendant_io and
	tabled_for_io_unitize annotations.

compiler/table_gen.m:
	Handle the new annotations. Procedures with tabled_for_descendant_io
	annotations don't need to be transformed at all; procedures with
	tabled_for_io_unitize annotations need a small variation of the
	existing transformation.

	Fix an existing bug that made the HLDS not type-correct. Create new
	variables with the appropriate type; do not assume all new variables
	are c_pointers, since some are integers.

library/table_builtin.m:
	Add two new predicates that table_gen.m emits calls to on either side
	of the code of foreign_procs with tabled_for_io_unitize annotations.

compiler/hlds_out.m:
compiler/layout_out.m:
compiler/mercury_to_mercury.m:
	Update the mechanisms for printing out eval methods.

compiler/hlds_pred.m:
	Update the mechanisms for performing tests on eval methods.
	Change some of the predicates involved to functions, partly in order
	to make future maintenance easier.

compiler/det_analysis.m:
compiler/det_report.m:
compiler/make_hlds.m:
compiler/modes.m:
	Conform to the change from predicates to functions.

runtime/mercury_trace_base.c:
	Update the documentation of MR_trace_enabled.

runtime/mercury_stack_layout.h:
	Add names for the new eval methods.

trace/mercury_trace.c:
	Handle the new eval methods.

tests/debugger/tabled_read_unitize.{m,inp,exp,data}:
	A new test case to check the handling of unitized foreign_procs.

tests/debugger/Mmakefile:
	Turn on the new test case.
2002-07-26 04:20:14 +00:00
Ralph Becket
b746233ac4 Implemented state variable transformation.
Estimated hours taken: 600
Branches: main

Implemented state variable transformation.

NEWS:
	Record new syntax and withdrawl of !/0 as Prolog cut.

compiler/hlds_goal.m:
compiler/hlds_out.m:
	Added implicit/1 constructor to unify_main_context for cases where
	variables are introduced by compiler transformations.

compiler/make_hlds.m:
	Integrated the state variable transformation with the conversion to
	HLDS.

	Changed references to foreign_type and du_type constructors to
	match recent changes to the foreign type interface.

compiler/mercury_compile.m:
	Removed two unnecessary Prolog cuts left over from the Dark
	Ages.

compiler/mercury_to_mercury.m:
	Added code to output the new goal_expr constructors for state
	variable quantifiers (some_state_vars and all_state_vars.)

	Adapted to handle changes to if_then and if_then_else
	goal_expr constructors which now include lists of state
	variables that scope over the condition- and then-goals.

compiler/module_qual.m:
compiler/prog_util.m:
	Changes to handle some_state_vars, all_state_vars, and changes
	to if_then and if_then_else goal_expr constructors.

compiler/prog_data.m:
	Added some_state_vars, all_state_vars constructors and changed
	if_then and if_then_else constructors in type goal_expr.

compiler/prog_io_dcg.m:
	Changes to handle quantified state variables.

compiler/prog_io_goal.m:
	parse_some_vars_goal now also separates out quantified state
	variables.

compiler/prog_io_util.m:
	Added pred parse_quantifier_vars/3 which also detects state
	variables.

compiler/typecheck.m:
	Added case to report_error_undef_cons to handle any uncaught
	uses of !/1.

doc/reference_manual.texi:
	Documented the transformation.

library/builtin.m:
library/prolog.m:
	Deleted code for `!' as fake Prolog cut.

library/lexer.m:
	Made `!' a graphic token rather char than a special token.

library/ops.m:
	Added `!', `!.' and `!:' as prefix ops.

library/term.m:
	Added func var_id/1 which returns an int associated with its
	var argument which is unique in the context of the given var
	and the varset it belongs to.

library/varset.m:
	Added pred new_uniquely_named_var/4 which creates a named
	variable with a unique (w.r.t. the varset) number suffix.

tests/general/Mmakefile:
tests/general/state_vars_tests.exp:
tests/general/state_vars_tests.m:
tests/general/state_vars_typeclasses.exp:
tests/general/state_vars_typeclasses.m:
tests/invalid/Mmakefile:
tests/invalid/state_vars_test1.err_exp:
tests/invalid/state_vars_test1.m:
tests/invalid/state_vars_test2.err_exp:
tests/invalid/state_vars_test2.m:
tests/invalid/state_vars_test3.err_exp:
tests/invalid/state_vars_test3.m:
tests/invalid/state_vars_test4.err_exp:
tests/invalid/state_vars_test4.m:
tests/invalid/state_vars_test5.err_exp:
tests/invalid/state_vars_test5.m:
	Added.
2002-07-09 01:31:12 +00:00
Simon Taylor
0387a6e9c2 Improvements for `:- pragma foreign_type'.
Estimated hours taken: 10
Branches: main

Improvements for `:- pragma foreign_type'.
- Allow default Mercury definitions. The Mercury definition must define
  a discriminated union type. The constructors of the Mercury type are
  only visible in predicates which have implementations for all the
  foreign languages the type has implementations for. In all other
  predicates the type is treated as an abstract type (the check for
  this isn't quite right).
- Allow polymorphic foreign types.
- Don't require the `:- pragma foreign_type' for exported foreign types
  to be in the interface. We now only require that all definitions
  have the same visibility.

compiler/prog_data.m:
compiler/prog_io_pragma.m:
	Allow polymorphic foreign types.

compiler/prog_io.m:
	Export code to parse the type name in a type definition for
	use by prog_io_pragma.m.

compiler/make_hlds.m:
	Handle Mercury definitions for foreign types.

	Separate out the code to add constructors and special predicates
	to the HLDS into a separate pass. For foreign types, we don't know
	what to add until all type definitions have been seen.

	Use the C definition for foreign types with `--target asm'.

compiler/modules.m:
	Distinguish properly between `exported' and `exported_to_submodules'.
	Previously, if a module had sub-modules, all declarations,
	including those in the interface, had import_status
	`exported_to_submodules'. Now, the declarations in the
	interface have status `exported' or `abstract_exported'.
	This is needed to check that the visibility of all the
	definitions of a type is the same.

compiler/hlds_pred.m:
	Add a predicate status_is_exported_to_non_submodules, which
	fails if an item is local to the module and its sub-modules.

compiler/hlds_data.m:
compiler/*.m:
	Record whether a du type has foreign definitions as well.

	Also record whether uses of the type or its constructors
	need to be qualified (this is needed now that adding
	the constructors to the HLDS is a separate pass).

compiler/typecheck.m:
	Check that a predicate or function has foreign clauses before
	allowing the use of a constructor of a type which also has
	foreign definitions.

compiler/hlds_pred.m:
compiler/make_hlds.m:
	Simplify the code to work out the goal_type for a predicate.

compiler/hlds_out.m:
	Don't abort on foreign types.

	Print the goal type for each predicate.

compiler/error_util.m:
	Handle the case where the message being written is a
	continuation of an existing message, so the first line
	should be indented.

compiler/module_qual.m:
	Remove unnecessary processing of foreign types.

doc/reference_manual.tex:
	Document the change.

	Update the documentation for mixing Mercury and foreign clauses.
	The Mercury clauses no longer need to be mode-specific.

tests/hard_coded/Mmakefile:
tests/hard_coded/foreign_type2.{m,exp}:
tests/hard_coded/foreign_type.m:
tests/hard_coded/intermod_foreign_type.{m,exp}:
tests/hard_coded/intermod_foreign_type2.m:
tests/invalid/Mmakefile:
tests/invalid/foreign_type_2.{m,err_exp}:
tests/invalid/foreign_type_visibility.{m,err_exp}:
	Test cases.

tests/invalid/record_syntax.err_exp:
	Update expected output.
2002-06-30 17:07:20 +00:00
Peter Ross
ddd77f6f0e Get pragma foreign_type working for the C backend.
Estimated hours taken: 16
Branches: main

Get pragma foreign_type working for the C backend.

doc/reference_manual.texi:
    Document C pragma foreign_types.

compiler/prog_data.m:
    Add il_foreign_type and c_foreign_type which contain all the
    necessary data to output a foreign_type on the respective backends.
    Change foreign_language_type to refer to these new types.

compiler/prog_io_pragma.m:
    Handle the changes to foreign_language_type, and parse C
    foreign_type declarations.

compiler/hlds_data.m:
    Change the hlds_data__foreign_type type so that it records both the
    C and IL foreign types.  This will allow one to output both foreign
    type declarations when doing intermodule optimization.

compiler/make_hlds.m:
    Changes so that we store both the IL and C foreign types in
    hlds_data__foreign_type.
    Also add an error checking pass where we check that there is a
    foreign type for the back-end we are currently compiling to.

compiler/foreign.m:
    Change to_exported_type so that it works for both the C and IL
    backends by getting either the C or IL foreign_type definition.

compiler/llds.m:
compiler/pragma_c_gen.m:
    Change pragma_c_input and pragma_c_output so that they record
    whether or not a type is a foreign_type and if so what is the string
    which represents that foreign_type.

compiler/llds_out.m:
    When outputting pragma c_code variables that represent foreign_types
    get the casts correct.  Note that this adds the constraint on C
    foreign types that they are word sized, as all we are doing is
    casts, not boxing and unboxing.

compiler/mlds.m:
    Change mlds__foreign_type so that we store whether a type is an IL
    type or a C type.  It is the responsibility of the code generator
    that we never create a reference to a IL foreign type when on the C
    back-end, and vice versa.

compiler/mercury_to_mercury.m:
    Handle changes to prog_data__foreign_type.

compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_code_gen.m:
compiler/ml_type_gen.m:
compiler/recompilation_usage.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
    Handle changes to hlds_data__foreign_type.

compiler/exprn_aux.m:
compiler/livemap.m:
compiler/middle_rec.m:
compiler/opt_util.m:
    Handle changes to the pragma_c_input and pragma_c_output types.

compiler/ml_code_util.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_c.m:
    Handle changes to mlds__foreign_type.
2002-05-07 11:03:17 +00:00
Fergus Henderson
7597790760 Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.

compiler/libs.m:
compiler/backend_libs.m:
compiler/parse_tree.m:
compiler/hlds.m:
compiler/check_hlds.m:
compiler/transform_hlds.m:
compiler/bytecode_backend.m:
compiler/aditi_backend.m:
compiler/ml_backend.m:
compiler/ll_backend.m:
compiler/top_level.m:
	New files.  One module for each of the major components of the
	Mercury compiler.  These modules contain (as separate sub-modules)
	all the other modules in the Mercury compiler, except gcc.m and
	mlds_to_gcc.m.

Mmakefile:
compiler/Mmakefile:
	Handle the fact that the top-level module is now `top_level',
	not `mercury_compile' (since `mercury_compile' is a sub-module
	of `top_level').

compiler/Mmakefile:
	Update settings of *FLAGS-<modulename> to use the appropriate
	nested module names.

compiler/recompilation_check.m:
compiler/recompilation_version.m:
compiler/recompilation_usage.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/recompilation.version.m:
	Convert the `recompilation_*' modules into sub-modules of the
	`recompilation' module.

compiler/*.m:
compiler/*.pp:
	Module-qualify the module names in `:- module', `:- import_module',
	and `:- use_module' declarations.

compiler/base_type_info.m:
compiler/base_type_layout.m:
	Deleted these unused empty modules.

compiler/prog_data.m:
compiler/globals.m:
	Move the `foreign_language' type from prog_data to globals.

compiler/mlds.m:
compiler/ml_util.m:
compiler/mlds_to_il.m:
	Import `globals', for `foreign_language'.

Mmake.common.in:
trace/Mmakefile:
runtime/Mmakefile:
	Rename the %.check.c targets as %.check_hdr.c,
	to avoid conflicts with compiler/recompilation.check.c.
2002-03-20 12:37:56 +00:00
Simon Taylor
d96f7a9bd5 Allow declarations of the form
Estimated hours taken: 40
Branches: main

Allow declarations of the form
:- pred p `with_type` higher_order_type `with_inst` higher_order_inst.

XXX We should allow `with_inst` annotations on higher-order terms.

compiler/prog_data.m:
	Add fields to `pred_or_func' and `pred_or_func_mode'
	items to hold the `with_type` and `with_inst` annotations.

compiler/prog_io.m:
compiler/prog_io_typeclass.m:
	Parse the annotations.

compiler/module_qual.m:
	Module qualify the annotations.

compiler/equiv_type.m:
	Expand away `with_type` and `with_inst`. Report errors.

	Strip items containing errors from the item list.

	Record smart recompilation dependencies on the types and
	modes expanded. Also record a dependency on the arity of
	predicate and function declarations before expansion.

	Use error_util for error messages.

compiler/mercury_to_mercury.m:
	Write `with_type` and `with_inst` annotations to interface files.

compiler/make_hlds.m:
	Ignore `with_type` and `with_inst` fields in predicate and
	function declarations.

compiler/recompilation.m:
	Changes to allow equiv_type.m to record dependencies on
	arbitrary items, not just types.

compiler/recompilation_usage.m:
compiler/recompilation_check.m:
	Allow searches in the sets of used predicates and functions using
	name, not name and arity, as the key. This is needed because
	the actual arity of a predicate defined using `with_type` is
	not known when writing the interface files.

compiler/recompilation_version.m:
	Handle `with_inst` and `with_type`.

	Pragmas now need to be recorded in the version_numbers even
	if there is no matching `:- pred' or `:- func' declaration --
	the pragma may apply to a predicate or function declared using
	`with_type`.

compiler/mode_util.m:
	Export inst_subsitute_arg_list for use by equiv_type.m.

compiler/error_util.m:
	Add predicate `pred_or_func_to_string'.

library/std_util.m:
	Add std_util__map_foldl_maybe and std_util__map_foldl2_maybe,
	which are like list__map_foldl and list__map_foldl2, but
	apply to the item stored in a value of type std_util__maybe.

NEWS:
doc/reference_manual.texi:
	Document the new syntax and library predicates.

tests/invalid/Mmakefile:
tests/invalid/with_type.m:
tests/invalid/with_type.err_exp:
tests/invalid/constrained_poly_insts.err_exp:
tests/recompilation/TESTS:
tests/recompilation/unchanged_with_type_nr*:
tests/recompilation/with_type_re*:
	Test cases.

tests/invalid/errors1.err_exp:
tests/invalid/type_loop.err_exp:
tests/invalid/vars_in_wrong_places.err_exp:
	Update expected output.
2002-03-15 07:32:27 +00:00
Zoltan Somogyi
41a27af862 Change type_id to the more descriptive type_ctor everywhere.
Estimated hours taken: 6
Branches: main

compiler/*.m:
	Change type_id to the more descriptive type_ctor everywhere.
2002-03-07 08:30:28 +00:00
Zoltan Somogyi
7fbb09dc04 Delete the code "handling" undiscrimited unions.
Estimated hours taken: 1
Branches: main

compiler/*.m:
	Delete the code "handling" undiscrimited unions. Their presence
	slows things down, the error messages they lead to can confuse
	users, and we are unlikely to ever implement them in the form
	now assumed by the code.

tests/invalid/bigtest.err_exp:
tests/invalid/uu_type.err_exp:
	Update these expected error messages.
2002-02-26 02:46:05 +00:00
Zoltan Somogyi
13f0e7610a A large step towards declarative debugging of goals that do I/O.
Estimated hours taken: 40
Branches: main

A large step towards declarative debugging of goals that do I/O. This step
does everything needed for that except modify the declarative debugger itself;
that is for Mark to do.

If you give the new option --trace-table-io-decl, the transformation performed
by the compiler on I/O primitives will preserve not just the output arguments
of the primitive, so that the primitive can be "reexecuted" without performing
any side-effects, but also the input arguments and the identity of the I/O
primitive itself. The I/O table therefore will contain a list of the I/O
primitives executed by the program after I/O tabling is started.

You can test this via the new debugger commands "print action <action-number>"
and "browse action <action-number>".

The new option is currently not documented, because the declarative debugger
does not yet use the information it provides. The new debugger commands are
not documented because they are meant only for implementors, at least for
now.

Since this change adds a field to proc_layout structures, any workspaces
compiled with debugging enabled will need to do a cvs update when this change
is installed.

compiler/options.m:
	Add the option --trace-table-io-decl. When set, this causes the
	compiler to transform I/O action primitives to allow declarative
	debugging of I/O actions.

compiler/handle_options.m:
	Make --trace-table-io-decl imply --trace-table-io.

compiler/table_gen.m:
	Perform the transformation, which is similar to the existing
	--trace-table-io transformation, but preserves the identity of all
	non-io-state arguments (not just the outputs) and the identity
	of the I/O primitive itself.

	Provide better names for variables generated by tabling
	transformations.

compiler/hlds_goal.m:
	Add extra parameters to procedures whose job it is to create new
	goals to name the variables in those goals.

compiler/layout.m:
	Add a new layout structure to contain the information the runtime
	system needs to interpret the information saved by the new
	transformation.

compiler/layout_out.m:
	Output the new layout structure.

compiler/continuation_info.m:
	Add a field to proc_layouts to point to the declarative I/O tabling
	structure, and another to identify the proc_layout without using LLDS
	types.

compiler/code_gen.m:
	Provide the definition of this field when appropriate.

compiler/hlds_pred.m:
	Add a field to proc_infos to store the information from the tabling
	transformation until code generation.

compiler/stack_layout.m:
	Add a mechanism for transforming the high level description of I/O
	action tabling data in proc_infos to the low level description we need
	to generate C data structures.

compiler/hlds_data.m:
	Add a new cons_id and a new cons_tag; they are used to refer to I/O
	tabling structures in code generated by the new transformation.

compiler/*.m:
	Handle the updates to global data types above.

library/table_builtin.m:
	Modernize some old code.

	Fix an old off-by-one error: make I/O tabling use the first slot
	in the I/O action table.

library/varset.m:
	Add a mechanism for creating a variable that is named iff the caller
	has a name for it.

runtime/mercury_layout_util.[ch]:
	Add a function for materializing type parameters from an answer block,
	not from registers or a closure.

runtime/mercury_stack_layout.h:
	Declare a C type for the data structure holding information about
	I/O primitives transformed by --trace-table-io-decl, and add a field
	to proc_layout structures to point to these new structures.

	Add a new evaluation method for --trace-table-io-decl.

runtime/mercury_tabling_macros.h:
	Add some conditionally-compiled debugging code to the primitive for
	saving answers.

trace/mercury_trace_vars.[ch]:
	Add functions for printing I/O action goals.

trace/mercury_trace_internal.c:
	Add code for recognizing and implementing commands to print I/O
	action goals.

trace/mercury_trace.c:
	Add code for handling the new eval method.

tests/debugger/tabled_read.{m,inp,exp*}:
	Add a polymorphic I/O action primitive, add calls to it, and test
	the printing of both monomorphic and polymorphic action goals.

tests/debugger/tabled_read_decl.{m,inp,exp*,data}:
	A new test case. It does the same things as the new version of
	tabled_read, but it is compiled with --trace-table-io-decl, not
	just --trace-table-io. It therefore can (and does) test the printing
	of tabled I/O actions.

tests/debugger/Mmakefile:
	Add the new test case.
2002-02-20 03:14:51 +00:00
Lars Yencken
cca3d674e1 Added parsing and pretty printing of new promise ex declarations, and
Estimated hours taken: 50
Branches: main

Added parsing and pretty printing of new promise ex declarations, and
appropriate documentation.

library/ops.m:
	Added the new operators to op_table.

compiler/prog_io.m:
	Added clauses to enter promise ex declarations into the parse
	tree.

compiler/prog_out.m:
	Added predicates useful in outputting promise declarations.

compiler/prog_data.m:
	Changed assertion constructor in type item to a more gereral
	promise constructor to be used for assertions and promise ex
	declarations. Added the type promise_type to differentiate
	between different promise declarations.

compiler/mercury_to_mercury.m:
	Added clauses to output promise items, including assertions
	and promise ex declarations.

compiler/make_hlds.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation_check.m:
compiler/recompilation_version.m:
	Updated to reflect change in item type.

compiler/notes/glossary.html:
	Added new terminology, updated use of `promise'.

compiler/notes/todo.html:
	Added todo list for promise ex declarations.

compiler/notes/promise_ex.html:
	A new file documenting development of promise ex declarations.
2002-02-08 02:27:15 +00:00
Tyson Dowd
a800e84609 Make foreign_proc impure by default.
Estimated hours taken: 12
Branches: main

Make foreign_proc impure by default.

The majority of this change is to correctly handle older pragma c_code
and import declarations, which are assumed to have the the purity of
their declaration.

The declared purity is not known at the time we parse the pragma c_code,
so we need to handle these cases at purity checking time by setting the
purity attribute on the procedure to the declared purity.  We can then
continue with normal purity checking.

compiler/make_hlds.m:
	Make fact table implementations pure.
	(no need to mess around with legacy purity behaviour here as we
	know for fact tables what the purity is declared to be).

compiler/prog_data.m:
	Set the default purity to impure.

	Add a new attribute on foreign_procs, indicating whether the
	foreign_proc should have legacy purity behaviour (because it was
	written using pragma c_code or pragma import) or whether it
	should use the new purity behaviour.

compiler/prog_io_pragma.m:
	Set the legacy_purity_behaviour attribute depending upon the
	c_code and import behaviour.

compiler/purity.m:
	Handle legacy_purity_behaviour attributes.
	Change an XXX about assuming foreign_procs to be pure -- the
	code near there seems to be correct in either case, we still
	don't assume that a foreign_proc is impure simply because it has
	multiple modes.

doc/reference_manual.texi:
	Document that pragma foreign_proc is now impure by default.
2002-01-30 01:40:34 +00:00
Tyson Dowd
aa23ac1b26 A few minor fixes promped by petdr's addition of support for value types
Estimated hours taken: 0.5
Branches: main

A few minor fixes promped by petdr's addition of support for value types
for foreign_type.

compiler/ilasm.m:
compiler/ilds.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_il.m:
compiler/mlds_to_mcpp.m:
	Mirror the IL syntax more closely, use valuetype instead of
	value_class.

compiler/prog_data.m:
	Add some comments and improve formatting of type declarations for
	pragma foreign_type.

doc/reference_manual.texi:
	Improve the documentation wording for pragma foreign_type, and
	remove the XXX saying that we should accept value types, because
	we now accept value types.
2002-01-21 04:39:23 +00:00
Peter Ross
dffdb3fd0b Allow the foreign_type declaration to accept value types.
Estimated hours taken: 4
Branches: main

Allow the foreign_type declaration to accept value types.

compiler/prog_data.m:
    Add an indicator to il foreign types whether or not they are
    reference or value types.

compiler/prog_io_pragma.m:
    Parse whether or not the foreign type is a reference or a value type.

compiler/make_hlds.m:
    Decide whether or not a foreign_type is already boxed.

compiler/hlds_data.m:
compiler/mlds.m:
    Add to the foreign_type an indicator of whether or not it is already
    boxed.

compiler/mlds_to_il.m:
    Remove code which attempted to determine when a value type was
    incorrectly defined as a reference type.
    Unboxed types on the .NET backend are value types.
    Fix a bug where converting a value_class to a value_class was
    failing.

compiler/ilasm.m:
    Remove name_to_simple_type from the interface as it is no longer
    needed in mlds_to_il.

compiler/mercury_to_mercury.m:
    Output the new foreign_type format.

compiler/foreign.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_type_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/recompilation_usage.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
    Changes to handle the boxed indicator.


doc/reference_manual.texi:
    Document how to specify a value type.
2002-01-16 01:13:47 +00:00
Tyson Dowd
70eb377888 Fix and enable the new foreign_type syntax.
Estimated hours taken: 10
Branches: main

Fix and enable the new foreign_type syntax.  We now accept declarations
such as:

:- pragma foreign_type(il, xmldoc, "class [System.Xml]System.Xml.XmlDocument").

compiler/prog_data.m:
	Remove the foreign type location from the foreign_type pragma,
	it is better to make this part of the foreign_language_type.
	Rename backend as foreign_language_type as it specifies a type in a
	particular language.

compiler/prog_io_pragma.m:
	Uncomment the foreign_type parsing code, change the syntax.
	Write some simple code to parse CIL type names.

compiler/make_hlds.m:
	Check that there is a :- type declaration, and
	that it has the same visibility as the pragma foreign_type.

compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation_version.m:
	Handle changes to backend_type and the foreign_type pragma.

doc/reference_manual.texi:
	Document the new syntax.
2001-12-12 00:30:22 +00:00
Tyson Dowd
c79a467975 Accept promise_pure and promise_semipure as foreign proc attributes.
Estimated hours taken: 6
Branches: main

Accept promise_pure and promise_semipure as foreign proc attributes.
Make changes required to make pragma foreign_proc impure by default,
but leave the actual default setting commented out for now.

(next step is to fix the purity of the preds/funcs in the library).

compiler/prog_data.m:
	Add purity to the pragma_foreign_proc_attributes.
	We keep the default purity pure, but we have a commented out
	default of impure that can be switched on later.

compiler/prog_io_pragma.m:
	Parse the new promise_pure and promise_semipure declarations.
	Add a promise_pure for :- pragma c_code and :- pragma import so
	that it is backwards compatible.
	Improve the code used to process the list of attributes.

compiler/purity.m:
	Mark the code that needs to be removed once we have bootstrapped
	this change and fixed the library.
	Calculate expression purity from foreign_proc from the
	attributes rather than looking up the declared purity.

doc/reference_manual.texi:
	Document the new syntax, and add commented out comments to
	indicate the intended change to make the default purity for
	foreign_proc pure.
2001-11-20 13:54:00 +00:00
Simon Taylor
5de7305cfe Implement `:- pragma foreign_import_module(Lang, Module)', which tells
Estimated hours taken: 10

Implement `:- pragma foreign_import_module(Lang, Module)', which tells
the compiler that the foreign code in the module containing the
declaration uses `:- pragma export'ed procedures from module `Module'.
This information is needed for mmake to build things in the right order.
Currently programmers can hand code the required mmake rules, but
`mmc --make' will have no mechanism for doing this.

`:- pragma c_import_module(Module)' is a synonym for
`:- pragma foreign_import_module("C", Module)'.

compiler/prog_io_pragma.m:
	Parse the new pragmas.

compiler/prog_data.m:
compiler/foreign.m:
compiler/hlds_module.m:
compiler/mlds.m:
compiler/modules.m:
	Add the `:- pragma foreign_import_module' to the
	compiler's datastructures.

compiler/make_hlds.m:
	Insert `:- pragma foreign_import_module' declarations
	into the HLDS.

compiler/modules.m:
	Add the extra dependency information from
	`:- pragma foreign_import_module' declarations
	to the `.d' files.

compiler/llds.m:
compiler/foreign.m:
	Move some non-backend-specific types describing the foreign
	language interface from llds.m to foreign.m.

compiler/intermod.m:
	Write `:- pragma foreign_import_module' declarations
	to `.opt' files. XXX mmake doesn't support this properly yet.

compiler/mercury_compile.m:
compiler/foreign.m:
compiler/ml_code_gen.m:
compiler/ml_code_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_mcpp.m:
	Convert `:- pragma foreign_import_module' to `#include'
	statements where appropriate depending on the target
	language.

compiler/*.m:
	Handle `:- pragma foreign_import_module'.
	Import foreign.m rather than llds.m for the foreign
	interface types.

doc/reference_manual.texi:
NEWS:
	Document the new pragmas.
	Minor fixes for the foreign code documentation.

tests/hard_coded/Mmakefile:
tests/hard_coded/foreign_import_module.m:
tests/hard_coded/foreign_import_module_2.m:
tests/hard_coded/foreign_import_module.exp:
	Test case.
2001-11-06 15:21:27 +00:00
Peter Ross
77a1261d3b Merge the foreign_type pragma changes from the dotnet branch to the main
Estimated hours taken: 10
Branches: main

Merge the foreign_type pragma changes from the dotnet branch to the main
branch, plus do some more development work to generalise the change.

compiler/prog_data.m:
    Add a type to hold the data from parsing a pragma foreign_type decl.

compiler/prog_io_pragma.m:
    Parse the pragma foreign_type.  This code is currently commented
    out, while we decide on the syntax.

compiler/hlds_data.m:
    Add a new alternative to hlds_type_body where the body of the type
    is a foreign type.

compiler/make_hlds.m:
    Place the foreign_type pragmas into the HLDS.

compiler/foreign.m:
    Implement to_type_string which replaces export__type_to_type_string,
    unlike export__type_to_type_string foreign__to_type_string takes an
    argument specifying which language the representation is meant to be
    in.  to_type_string also needs to take a module_info to handle
    foreign_types correctly.  To avoid the need for the module_info to
    be passed around the MLDS backend we provide a new type
    exported_type which provides enough information for an alternate
    version of to_type_string to be called.

compiler/export.m:
    Delete export__type_to_type_string.

compiler/llds.m:
    Since foreign__to_type_string needs a module_info, we add a new
    field to pragma_c_arg_decl which is the result of calling
    foreign__to_type_string.  This avoids threading the module_info
    around various llds passes.

compiler/mlds.m:
    Record with in the mercury_type the exported_type, this avoids
    passing the module_info around the MLDS backend.
    Also add the foreign_type alternative to mlds__type.
    Update mercury_type_to_mlds_type so that it handles types which are
    foreign types.

compiler/mlds_to_il.m:
    Convert a mlds__foreign_type into an ilds__type.

compiler/ilds.m:
    The CLR spec requires that System.Object and System.String be
    treated specially in the IL assembly so add them as simple types.

compiler/ilasm.m:
    Before outputting a class name into the IL assembly check whether it
    it can be simplified to a builtin type, and if so output that name
    instead as required by the ECMA spec.
    Changes for the addition of string and object as simple types.

doc/reference_manual.texi:
    Document the new pragma, this is currently commented out because it
    refers to syntax that has not yet been finalised.

compiler/fact_table.m:
compiler/llds_out.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/pragma_c_gen.m:
compiler/rtti_to_mlds.m:
    Changes to handle using foreign__to_type_string.

compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_type_gen.m:
compiler/recompilation_usage.m:
compiler/recompilation_version.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
    Changes to handle the new hlds_type_body.

compiler/mercury_to_mercury.m:
    Output the pragma foreign_type declaration.

compiler/module_qual.m:
    Qualify the pragma foreign_type declarations.

compiler/modules.m:
    Pragma foreign_type is allowed in the interface.
2001-10-24 13:34:41 +00:00
Tyson Dowd
b994075a22 Add support for foreign_proc("il", ....)
Estimated hours taken: 50
Branches: main


Add support for foreign_proc("il", ....)

To use it, you need to give the options
	--use-foreign-language il
	--backend-foreign-language il

Begin documenting foreign_proc.


compiler/foreign.m:
compiler/globals.m:
	Handle the addition of il as a language option.

compiler/inlining.m:
	Mention that we don't allow il code to be inlined yet and give a
	pointer into ml_code_gen.m which has the reason along with the
	offending code.

compiler/il_peephole.m:
compiler/ilasm.m:
	Handle the addition of il_asm_code as inlineable code.

compiler/ilds.m:
	Add a handwritten scope to the different scope types.

compiler/ml_code_gen.m:
	Handle the generation of code for IL foreign language interfacing.
	Put the max_stack_size attribute into IL foreign language code.
	Document the problem with inlining.

compiler/ml_elim_nested.m:
	Handle the new field in blocks indicating whether the block contains
	handwritten code.

compiler/mlds.m:
	Add lang_il as a possible target language.
	Add attributes to target code (max_stack_size is the only one so far).

compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
	Handle the addition of il as a language option.

compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
	Generate inline code for foreign_proc using IL.

compiler/prog_data.m:
	Add il as a language option.

	Add extra attributes to the pragma_foreign_proc_attributes.
	Currently there is just one extra attribute, max_stack_size.

compiler/prog_io_pragma.m:
	Parse max_stack_size as an attribute on foreign_proc.
	Improve error message output: previously we tried to parse the
	third term of a foreign_proc, and then tried to parse the second term
	(which we will accept for "c_code" but not foreign_proc).
	But we should give the error message as if the "c_code" handling is
	not present, as this will eventually go away.
	Check for foreign_language attributes such as max_stack_size.

doc/reference_manual.texi:
	Add a section for foreign_proc (and other multi-language foreign
	language interfacing pragmas).
	At the moment we have some reasonable documentation for "C" and
	"IL" foreign_proc, and some documentation on foreign_decl and
	foreign_code for C.

doc/user_guide.texi:
	The language and implementation specific documentation of
	the foreign language interface.
2001-07-18 10:21:03 +00:00
Simon Taylor
9dd11b2fc6 Smart recompilation. Record version numbers for each item
Estimated hours taken: 400

Smart recompilation. Record version numbers for each item
in interface files. Record which items are used in each compilation.
Only recompile a module if the output file does not exist or
nothing has changed.

There is still some work to do on this:
- it doesn't work with inter-module optimization.
- it doesn't work when the module name doesn't match the file name.
  (this problem will go away when mmake functionality is moved into
  the compiler.

I'll hold off documenting this change in the NEWS file and
on the web page for a month or so, until I've had a bit more
experience using it.

compiler/options.m:
compiler/handle_options.m:
doc/user_guide.texi:
	Add an option `--smart-recompilation', currently off by default.

	Add an internal option `--generate-version-numbers' to control
	whether version numbers are written to the interface files. If
	`--smart-recompilation' is disabled because the module
	is being compiled with `--intermodule-optimization' (e.g. in the
	standard library), we still want to write the version numbers
	to the interface files.

	Add an option `--verbose-recompilation' (default off)
	to write messages describing why recompilation is needed.

	Add an option `--warn-smart-recompilation' (default on)
	to control warnings relating to the smart recompilation
	system. Warn if smart recompilation will not work with
	the output and inter-module optimization options given.

compiler/recompilation.m:
	Type declarations for smart recompilation.
	Predicates to record program items used by compilation.

compiler/recompilation_version.m:
	Compute version numbers for program items in interface files.

compiler/recompilation_usage.m:
	Find all items used by a compilation.

compiler/recompilation_check.m:
	Check whether recompilation is necessary.

compiler/timestamp.m:
	Timestamp ADT for smart recompilation.

compiler/mercury_compile.m:
	Invoke the smart recompilation passes.

compiler/modules.m:
compiler/prog_io.m:
	Return timestamps for modules read.

	When reading a module make sure the current input stream
	is reset to its old value, not stdin.

	Handle version number items in interface files.

compiler/module_qual.m:
compiler/unify_proc.m:
compiler/make_hlds.m:
	Record all items used by local items.

compiler/make_hlds.m:
	Process `:- pragma type_spec' declarations in
	add_item_list_clauses. The qual_info is needed
	when processing `:- pragma type_spec' declarations
	so that any equivalence types used by the declaration
	can be recorded as used by the predicate or function to
	which the `:- pragma type_spec' applies.

compiler/equiv_type.m:
	For each imported item, record which equivalence types
	are used by that item.

compiler/hlds_module.m:
	Add a field to the module_info to store information about
	items used during compilation of a module.

compiler/check_typeclass.m:
	Make sure any items used in clauses for typeclass method
	implementations are recorded in the `.used' file.

compiler/prog_data.m:
compiler/*.m:
	Factor out some duplicated code by combining the
	pred and func, and pred_mode and func_mode items.

	Make it easier to extract the name of a type, inst or mode
	from its declaration.

	Add an item type to hold the version numbers for an interface file.

	Allow warnings to be reported for `nothing' items (used for
	reporting when version numbers are written using an
	obsolete format).

compiler/prog_io.m:
compiler/prog_io_util.m:
compiler/typecheck.m:
compiler/type_util.m:
compiler/*.m:
	Strip contexts from all types, not just those in class constraints.
	This makes it possible to use ordinary unification to check
	whether items have changed (with the exception of clauses).

	Remove code to create types with contexts in typechecking.

	Remove code scattered through the compiler to remove contexts
	from types in class constraints.

compiler/hlds_pred.m:
compiler/prog_util.m:
	Move hlds_pred__adjust_func_arity to prog_util, so that it
	can be used by the pre-hlds passes.

compiler/typecheck.m:
compiler/hlds_module.m:
	Move typecheck__visible_modules to hlds_module.m, so it can
	be used by recompilation_usage.m.

compiler/typecheck.m:
	Add a comment telling where updates may be required if the
	code to typecheck a var-functor unification changes.

compiler/error_util.m:
	Allow writing messages without contexts (used for the verbose
	recompilation messages).

	Add functions to format sym_name and sym_name_and_arity,
	and to add punctuation to the end of an error message
	without unwanted line breaks before the punctuation.

scripts/Mmake.rules:
compiler/modules.m:
	Don't remove the output file before running the compiler. We need
	to leave the old output file intact if smart recompilation detects
	that recompilation is not needed.

compiler/notes/compiler_design.html:
	Document the new modules.

library/io.m:
NEWS:
	Add predicates to find the modification time of files
	and input_streams.

library/set.m:
NEWS:
	Add a predicate version of set__fold

	Don't sort the output of set__filter, it's already sorted.

library/std_util.m:
NEWS:
	Add a predicate `std_util__map_maybe/3' and a function
  	`std_util__map_maybe/2' to apply a predicate or a function to
    	a value stored in a term of type `std_util__maybe'.

configure.in:
runtime/mercury_conf.h.in:
runtime/RESERVED_MACRO_NAMES:
	When checking whether the compiler is recent enough, check for
	the --warn-smart-recompilation option.

	Check for stat().

library/Mmakefile:
	Disable warnings about smart recompilation not working with
	`--intermodule-optimization'.

browser/Mmakefile:
	Disable warnings about smart recompilation not working when
	the module name doesn't match the file name.

runtime/mercury_string.h:
	Add a macro MR_make_string_const() which automates computation
	of the length of string argument to MR_string_const().

tests/recompilation/Mmakefile:
tests/recompilation/runtests:
tests/recompilation/test_functions:
tests/recompilation/TESTS:
tests/recompilation/README:
	A framework for testing smart recompilation.
	The option currently only works for the recompilation directory.

tests/recompilation/TEST.m.{1,2}:
tests/recompilation/TEST_2.m.{1,2}:
tests/recompilation/TEST.exp.{1,2}:
tests/recompilation/TEST.err_exp.2:
	Test cases, where TEST is one of add_constructor_r, add_instance_r,
	add_instance_2_r, add_type_nr, change_class_r, change_instance_r,
	change_mode_r, field_r, func_overloading_nr, func_overloading_r,
	lambda_mode_r, nested_module_r, no_version_numbers_r,
	pragma_type_spec_r, pred_ctor_ambiguity_r, pred_overloading_r,
	add_type_re, remove_type_re, type_qual_re.

tests/handle_options:
	Add an option `-e' to generate any missing expected output files.
2001-06-27 05:05:21 +00:00
Simon Taylor
d74eb22905 Fix a bug in the module import mechanism -- use_module should
Estimated hours taken: 8

Fix a bug in the module import mechanism -- use_module should
not be transitive. This change is needed for smart recompilation
to avoid needing to check whether the removal of a transitive
import could cause compilation errors -- it never should.

Also fix some bugs in the handling of type class declarations.

compiler/prog_data.m:
	Add a `transitively_imported' pseudo-declaration, which
	is placed before the items from `.int2' files and `.opt'
	files.

	Fix the representation of type class bodies.
	`:- typeclass foo where [].' declares a typeclass with no
	methods. `:- typeclass foo.' declares an abstract typeclass.
	The old representation made no distinction between these cases.

compiler/hlds_data.m:
compiler/prog_data.m:
compiler/module_qual.m:
	Move the declaration of type type_id from hlds_data.m to prog_data.m.
	This avoids a duplicate declaration in module_qual.m.

compiler/modules.m:
	Add a `transitively_imported' pseudo-declaration before the
	items from `.int2' files.

	Remove the bodies of typeclass declarations placed in `.int2'
	files -- the methods should not be available unless the module
	is explicitly imported.

compiler/module_qual.m:
	Items after the `transitively_imported' pseudo-declaration
	should not be considered when module qualifying locally
	declared items.

compiler/equiv_type.m:
compiler/mercury_to_mercury.m:
compiler/prog_io_typeclass.m:
	Handle the change to the representation of typeclass bodies.

compiler/prog_io_typeclass.m:
	Check that the arguments of a typeclass declaration
	are distinct variables.

compiler/make_hlds.m:
	Handle abstract typeclass declarations.

compiler/check_typeclass.m:
	Check that all typeclasses have a definition somewhere.

compiler/intermod.m:
	Write abstract_exported typeclasses to the `.opt' file.

compiler/add_trail_ops.m:
compiler/context.m:
compiler/llds.m:
compiler/vn_type.m:
	Add missing imports.

compiler/magic_util.m:
compiler/ml_type_gen.m:
	Remove unnecessary imports.

NEWS:
	Note that this change may break existing programs.

compiler/notes/todo.html:
	Remove the item relating to this change.

tests/invalid/transitive_import.{m,err_exp}:
	Add some tests for uses of transitively imported items.

tests/invalid/transitive_import_class.m:
tests/invalid/transitive_import_class2.m:
tests/invalid/transitive_import_class3.m:
tests/invalid/transitive_import_class.err_exp:
	Add a test for use of transitively imported class methods.

tests/invalid/invalid_typeclass.{m,err_exp}:
	Add some tests for invalid typeclass declarations.

tests/invalid/Mmakefile:
	Add the new tests.
2001-05-02 17:34:50 +00:00
Tyson Dowd
76ac44335d Implement a C# interface for the .NET backend.
Estimated hours taken: 45
Branches: main

Implement a C# interface for the .NET backend.

To use it, you currently need to set
	--backend-foreign-language csharp --use-foreign-language csharp
in your MCFLAGS.

The C# foreign language interface works by introducing a new sort of
MLDS statement called outline_foreign_proc.  outline_foreign_proc is expected
to be turned into a separate procedure in a separate file.  This is
quite different to normal foreign code which has been renamed as inline
target code, as it is really intended to be generated inline, inside the
generated code.

Because outline_foreign_proc is expected to be generated outside the
normal code, we don't need to generate variable renamings,
initializations, casts and other complicated interfacing code.

Any marshalling is done by the backend, which knows how to marshall
arguments across the boundary into the outline code and back.  In the
case of marshalling to C# from the .NET backend, we currently don't do
anything special (part of the point of .NET is that data
representation don't have to change very often just because you are
using different languages, so this is a property we should try to
preserve).

The actual implementation of the foreign code is therefore very simple.
Simply generate an appropriate procedure, and insert the user's code in
the middle.

The bulk of this change to delay the mangling of MLDS var names, so we
can still use the original user's var name when we output the outline
procedure (since the user's foreign code will refer to these var names,
it's important to keep them around).

compiler/foreign.m:
	Handle the csharp foreign language.

compiler/globals.m:
	Fix an XXX about converting to lowercase to do language name
	comparisons.
	Add new predicates to make conversion of foreign languages
	to strings more uniform.

compiler/handle_options.m:
	Don't set backend_foreign_language to the default if it has
	already been set by hand.

compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
	Delay the mangling of MLDS var names by keeping the variable
	number around until the output phase.

	Slightly generalize the handling of foreign language interfacing.
	Handle C# foreign language interfacing.

	Add value_output_vars to the ml_gen_info, which are the variables
	returned rather than passed by reference.  We need to know
	these variables for C# interfacing so that we can handle the return
	value of the forwarding function.

	Mark the beginning and end of the MLDS foreign language processing as
	a "sub-module" (in comments at least).  Later I may put this code
	into a separate module.

	Rename some predicates from c_code to foreign_code.

compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_string_switch.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/rtti_to_mlds.m:
	Handle the new var_name type, and the new target_code constructors.

compiler/mlds.m:
	Add outline_foreign_proc which is handled differently to the old
	target_code (which has been renamed inline_target_code).

	Change the definiton for mlds__var_name.

compiler/mlds_to_c.m:
	Factor out mlds_output_to_file.
	Handle the new var_name type, and the new target_code constructors.

compiler/mlds_to_csharp.m:
	A new module to generate C# code suitable for foreign language
	interfacing.  This is largely lifted from the MC++ code, with a few
	changes to the output syntax.

compiler/mlds_to_il.m:
	Return the set of foreign languages processed instead of a bool
	saying wither MC++ was present.  This is so we can generate the
	appropriate output .cs or .cpp files, and because we need to keep
	track of all the external assembly references we need to put in the
	.il file.

	Handle the inline_target_code and mlds__var_name changes.

compiler/mlds_to_ilasm.m:
	Output .cpp and .cs files conditionally.
	Factor out output_to_file.
	Move MC++ output code to mlds_to_mcpp.m

compiler/mlds_to_java.m:
	Factor out output_to_file.
	Handle the new var_name type, and the new target_code constructors.

compiler/mlds_to_mcpp.m:
	New file to handle generating MC++ code suitable for foreign language
	interfacing.

compiler/options.m:
	Add a way of setting the backend-foreign-language option.

compiler/passes_aux.m:
	Add output_to_file which is used by the MLDS backend to generate
	output files.

compiler/prog_data.m:
	Uncomment csharp as a foreign language.
2001-05-02 11:36:41 +00:00
Tyson Dowd
711da78188 Rename foreign_code as foreign_proc where appropriate in the compiler.
Estimated hours taken: 4.0
Branches: main

Rename foreign_code as foreign_proc where appropriate in the compiler.
The rationale for this change is that it makes maintaining the code much
simpler because it is clear whether `foreign' refers to a slab of code
(foreign_code) or a procedure (foreign_proc).

:- type pragma_foreign_code_attributes
:- type pragma_foreign_proc_attributes

The functors for pragma_type
	foreign(Lang, BodyCode)
	foreign(Attributes, Name, PredOrFunc, Vars, Varset, Impl)
become
	foreign_code(Lang, BodyCode)
	foreign_proc(Attributes, Name, PredOrFunc, Vars, Varset, Impl)

And the HLDS goal `pragma_foreign_code' becomes `foreign_proc'.

compiler/*.m:
	Update the compiler to use the new names.
2001-04-03 03:20:33 +00:00
Simon Taylor
a3819d359c Fix the handling of purity in the optimization and tabling passes.
Estimated hours taken: 15
Branches: main

Fix the handling of purity in the optimization and tabling passes.
Without this change tests/tabling/unused_args.m fails with
inter-module optimization.

compiler/purity.m:
compiler/post_typecheck.m:
	Allow purity checking to be rerun on a single procedure
	without requiring an io__state. If the purity is worse
	(due to inlining a predicate with a `:- pragma promise_pure'
	declaration), add `promised_pure' or `promised_semipure'
	to the pred_info.

compiler/hlds_out.m:
compiler/hlds_pred.m:
compiler/intermod.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/prog_data.m:
compiler/prog_io_pragma.m:
compiler/purity.m:
doc/reference_manual.texi:
NEWS:
	Implement `:- pragma promise_semipure'. This is needed if
	an predicate marked `promised_pure' which calls impure
	predicates is inlined into  a semipure predicate.

compiler/inlining.m:
	Make sure the purity markers on the goal_infos are correct
	after inlining predicates which are promised pure.

	Export a predicate inlining__can_inline_proc which is used
	by deforestation to determine whether inlining a procedure
	will change the semantics or will break code generator invariants.

compiler/deforest.m:
	Use the same method as inlining.m to work out whether
	a procedure can be inlined. Don't inline predicates which
	are promised pure because the extra impurity which
	will be propagated through the goal will stop deforestation
	working on the goal.

compiler/simplify.m:
	Make sure the goal_info resulting from converting a singleton
	switch into a conjunction has the correct purity.

compiler/table_gen.m:
	Make sure the purity markers on the generated goal_infos are
	correct.

	Make sure that call_table_gen goal features cannot be removed
	by optimization passes.

	Don't put unnecessary `impure' markers on calls to error/1.

tests/debugger/loopcheck.exp:
tests/debugger/retry.exp:
	Adjust the expected output. The change to ensure that
	`call_table_gen' goal features can't be removed alters
	the goal paths slightly.

tests/invalid/impure_method_impl.m:
	Adjust the expected output now that predicates can
	be promised semipure.
2001-03-27 05:23:23 +00:00
Zoltan Somogyi
ebe9f9a3ec Add tabling of I/O actions for the debugger.
Estimated hours taken: 80

Add tabling of I/O actions for the debugger.

compiler/options.m:
	Add a new option, --trace-table-io, that enables the tabling of I/O
	actions, and another, --trace-table-io-states, that governs whether the
	tabling includes the I/O state variables themselves. (You want to table
	these variables iff they contain meaningful information that is not
	stored in global variables.) These options are for developers only
	for now.

compiler/modules.m:
	Implicitly import table_builtin if --trace-table-io is specified.

compiler/prog_data.m:
	Add eval_table_io as a new eval method.

compiler/hlds_pred.m:
	Add a mechanism for checking whether a predicate has an input/output
	pair of io__state args.

	Extend the tables indexed by eval_method to handle eval_table_io.

compiler/hlds_out.m:
	Print the eval method in HLDS dumps.

compiler/table_gen.m:
	If a procedure has a pair of I/O state args and is defined using pragma
	C code that has the tabled_for_io marker, and --trace-table-io is
	specified, then perform I/O tabling on it and mark it as tabled.

compiler/notes/compiler_design.m:
	Document that table_gen.m can now change the evaluation methods of
	procedures (to eval_table_io).

compiler/stack_layout.m:
runtime/mercury_stack_layout.h:
	Add an extra field to proc layouts. If debugging is enabled and a
	procedure has I/O state arguments, this field gives the number of the
	stack slot which will be filled with the I/O action counter at the
	time of the call, so that on retry the debugger can reset the I/O
	action counter to this value.

compiler/trace.m:
	Add code to reserve and fill this stack slot.

	Make the order of fields in the trace_slots structure match the order
	in proc layouts.

compiler/code_info.m:
compiler/live_vars.m:
	Pass a module_info to trace__setup and trace__reserved_slots.

library/io.m:
	Mark the I/O primitives (i.e. procedures that are defined by pragma C
	code and do I/O) with the tabled_for_io feature. (See the discussion
	of I/O primitives in compiler/table_gen.m.)

	Standardize the formatting of predicates defined by pragma C codes.

library/table_builtin.m:
	Define the predicates that perform I/O tabling, to which calls are
	inserted in I/O tabled predicates. These depend on knowing what the
	maximum MR_Unsigned value is.

library/table_builtin.m:
runtime/mercury_tabling_macros.h:
	Table nodes implementing a simple kind of trie, which can also be
	viewed as a hash table with the hash function hash(n) = hash - start
	were already supported by mercury_tabling.c. They are used to
	implement I/O tabling, since I/O the tabled action numbers form a
	contiguous sequence. Now allow that functionality to be accessed
	from the library through macros.

runtime/mercury_trace_base.[ch]:
	Add the global variables required by I/O tabling.

trace/mercury_trace.c:
	Implement retry across I/O by resetting the I/O counter to the value
	it had on entry to the retried call. However, since this is not safe
	in general, ask the user for permission first.

trace/mercury_trace.h:
	Add two extra arguments to MR_trace_retry to specify the input and
	output streams on which to ask permission.

trace/mercury_trace_internal.c:
	Add commands to start and stop I/O tabling. For now, they are for use
	by developers only and are undocumented; I expect they will change
	significantly before being let loose on users.

trace/mercury_trace_external.c:
trace/mercury_trace_declarative.c:
	Pass extra arguments to MR_trace_retry to indicate that these modules
	are not interested (at least for now) in retry across I/O, since they
	do not (yet) have mechanisms for asking the user for permission.

tests/debugger/tabled_read.{m,inp,exp,data}:
	A new test case to check retry across tabled and non-tabled I/O.

tests/debugger/Mmakefile:
	Enable the new test case.
2000-12-06 06:06:06 +00:00
Tyson Dowd
477ecb18f6 Implement pragma foreign_code for Managed C++.
Estimated hours taken: 60

Implement pragma foreign_code for Managed C++.

Currently you can only write MC++ code if your backend is capable of
generating use MC++ as its "native" foreign language.  The IL backend is
the only backend that does this at the moment (the other backends have C
as their "native" foreign language).

Most of the machinery is in place to call from C to (normal) C++
but there is little work done on actually spitting out the C++ code into
a separate file.  The IL backend does this step already with managed C++.
The intention is to turn foreign_code for C++ into a pragma import
(which imports the C++ function from a separate file) and
foreign_code for C (which calls the imported function).  The C++ code
will be inserted into a separate file that is compiled using C linkage.

The important improvement this change gives is that you can write a
module with a C and a MC++ implementations side-by-side.  The target
backend will select the most appropriate foreign language to use.
You can override its choice using --use-foreign-language.  Later on
we will probably want more flexibility than just a single language
selection option).

This change also implements :- pragma foreign_decl, which allows header
file style declarations to be written in languages other than C.

compiler/code_gen.m:
	Reject code that is not C when generating LLDS.

compiler/export.m:
	Start renaming C as foreign.
	Reject code that is not C when generating exports.

compiler/foreign.m:
	A new module to handle foreign language interfacing.
	The bulk of the code for pragma import has been moved here from
	make_hlds.

compiler/globals.m:
	Convert foreign language names to foreign_language.
	This code has been moved closer to the similar conversion we do
	for target language names.
	Add globals__io_lookup_foreign_language_option to make it easier
	to deterministically lookup the options relating to foreign
	languages.


compiler/hlds_module.m:
	Move module_add_foreign_decl and module_add_foreign_body_code
	from make_hlds.m (where they were called module_add_c_header and
	module_add_c_code).

compiler/hlds_out.m:
	Write the foreign language out in HLDS dumps.

compiler/llds.m:
	Change foreign_header_info to foreign_decl_info.
	Change definitions of foreign_decl_code and foreign_body_code to
	include the language.

compiler/llds_out.m:
	Reject code that is not C when writing out LLDS.

compiler/make_hlds.m:
	Add foreign language information to the bodys and decls when
	creating them.
	Update error messages to refer to foreign code instead of C
	code.
	Use foreign.m to generate interfaces from the backend language
	to the foreign language.
	Hardcode C as the language for fact tables.

compiler/mercury_compile.m:
	Collect the appropriate foreign language code together for
	output to the backend.

compiler/intermod.m:
compiler/mercury_to_mercury.m:
	Output the foreign language string.
	Change a few names to foreign_code instead of c_code.

compiler/ml_code_gen.m:
	Filter the foreign language bodys and decls so that we only get
	the ones we are in (given by the use-foreign-language option).

compiler/mlds_to_c.m:
	Abort if we are given non C foreign language code to output
	(we might handle it here in future, or we might handle it
	elsewhere).

compiler/mlds_to_ilasm.m:
	Abort if we are given non MC++ foreign language code to output
	(we might handle it here in future, or we might handle it
	elsewhere).

compiler/options.m:
compiler/handle_options.m:
	Add --use-foreign-language as a user option to control the
	preferred foreign language to use as the implementation of this
	module.
	Add backend_foreign_language as an internal option which stores
	the foreign language that the compiler will use as a default
	(e.g. the natural foreign language for the backend to use).
	Set the preferred backend foreign language depending on the
	target.

compiler/prog_data.m:
	Add managedcplusplus as a new alternative for the
	foreign_language type.
	Make c_header_code into foreign_decl.
	Give the foreign language for foreign_code as an attribute of
	the code.
	Write code to turn attributes into a list of strings (suitable
	for writing out by mercury_to_mercury).  This fixes what appears
	to be a bug in tabled_for_io -- the tabled_for_io attribute was not
	being written out.  Structure the code so this bug is
	difficult to repeat in future.

compiler/prog_io_pragma.m:
	Parse foreign_decl.
	Turn c_header_code into a special case of foreign_decl.

compiler/*.m:
	Remove the language field from pragma_foreign_code, it is now an
	attribute of the code.
	Various type and variable renamings.

tests/invalid/pragma_c_code_and_clauses1.err_exp:
tests/invalid/pragma_c_code_dup_var.err_exp:
tests/warnings/singleton_test.exp:
	Update the tests to reflect the new error messages talking
	about :- pragma foreign_code rather than :- pragma c_code.
2000-11-17 17:48:52 +00:00
Fergus Henderson
e6769ef622 Record the module that each instance declaration came from.
Estimated hours taken: 8

Record the module that each instance declaration came from.
This is needed for the IL back-end, which includes that
module name in the symbol name that it generates for each
instance declaration.

compiler/prog_data.m:
	Add a module_name field to the `instance' item.

compiler/prog_io_typeclass.m:
	When parsing `instance' declarations, store the
	module name that they came from in the module_name field
	of the `instance' item.

compiler/hlds_data.m:
	Add a module_name field to the `hlds_instance_defn' structure.

compiler/make_hlds.m:
	Copy the module_name field from the `instance' item to the
	`hlds_instance_defn' structure.

compiler/polymorphism.m:
	Fix an old XXX: when constructing `base_typeclass_info_const's,
	use the module name from the `hlds_instance_defn', rather than
	hard-coding the invalid value "some bogus module name".

compiler/rtti.m:
	Add a module_name field to the `base_typeclass_info' rtti_name
	and rtti_data.

compiler/base_typeclass_info.m:
	Copy the module_name field in the `hlds_instance_defn' to the
	module_name field in the `base_typeclass_info' rtti_data
	and rtti_name.

compiler/rtti_to_mlds.m:
	When constructing mlds `data_addr's, use the module_name from
	the `base_typeclass_info' rtti_name, rather than assuming that
	such references always refer to instance declarations in the
	current module.  (That assumption would be a safe one currently,
	but doing it this way is probably a bit more robust against
	future changes.)

compiler/*.m:
	Trivial changes to reflect the above data structure changes.
2000-11-01 05:12:14 +00:00
Zoltan Somogyi
702b512aaf Add a new type of annotation on procedures defined by pragma foreign
Estimated hours taken: 1

compiler/prog_data.m:
	Add a new type of annotation on procedures defined by pragma foreign
	code. For now the annotation is ignored. When I/O tabling is
	implemented (soon), this annotation will ask for the procedure
	to be considered an I/O predicate and tabled accordingly.

compiler/prog_io_pragma.m:
	Parse the new annotation.

tests/valid/tabled_for_io.m:
	Test case to check that the compiler accepts the new annotation.

tests/valid/Mmakefile:
	Enable the test case.
2000-10-27 03:13:04 +00:00
David Overton
82378c381b Allow polymorphic ground insts. This change assumes that all inst
Estimated hours taken: 80

Allow polymorphic ground insts.  This change assumes that all inst
parameters in the mode declaration for a predicate or function are
constrained to be ground-shared.  This is a temporary measure until we
work out a nice syntax to allow the programmer to tell the compiler that
certain inst parameters may be treated as ground insts.  Since we don't
currently support unconstrained inst parameters anyway, this shouldn't
cause a problem.

	TODO:
		- Add syntax, something like `:- mode p(in(I)) <= ground(I).',
		  to specify that an inst parameter represents a ground inst.
		- Allow abstract ground insts that are treated in a similar
		  way to what we've done here with ground inst parameters.
		- Make mode checking more efficient (i.e. rewrite the mode
		  system).

compiler/inst.m:
	Add a new alternative for ground insts:
		`constrained_inst_var(inst_var)'.
	Define the type `inst_var_sub'.

compiler/inst_match.m:
	Change inst_matches_initial so that it:
		- handles constrained_inst_vars correctly;
		- returns the inst_var substitutions necessary for the call;
		- handles inst_matches_initial(ground(...), bound(...), ...)
		  properly (this requires knowing the type of the variable).

	  The last change has also been made for inst_matches_final
	  and inst_matches_binding.  However, the check is disabled for
	  now because, without alias tracking, the mode checker
	  becomes too conservative.

compiler/hlds_pred.m:
compiler/mode_info.m:
compiler/simplify.m:
compiler/det_util.m:
	Include the inst_varset in the proc_info, mode_info and simplify_info.
	Add a vartypes field to the det_info.
	Remove the vartypes field from the simplify_info since it is
	now in the det_info.
	Use record syntax for these data structures and their access predicates
	to make future changes easier.

compiler/prog_io.m:
	When processing pred and func mode declarations, convert all inst_var(V)
	insts to ground(shared, constrained_inst_var(V)).

compiler/prog_data.m:
compiler/hlds_data.m:
compiler/make_hlds.m:
compiler/mode_util.m:
	Use inst_vars instead of inst_params.

compiler/modes.m:
compiler/modecheck_call.m:
compiler/unique_modes.m:
compiler/mode_util.m:
	When checking or recomputing initial insts of a call, build up
	an inst_var substitution (using the modified
	inst_matches_initial) and apply this to the final insts of the
	called procedure before checking/recomputing them.

compiler/mode_util.m:
	Make sure that recompute_instmap_delta recomputes the
	instmap_deltas for lambda_goals even when RecomputeAtomic = no.

compiler/type_util.m:
	Add a new predicate, type_util__cons_id_arg_types which
	nondeterministically returns the cons_ids and argument types for a
	given type.
	Add a new predicate type_util__get_consid_non_existential_arg_types
	which is the same as type_util__get_existential_arg_types except
	that it fails rather than aborting for existenially typed arguments.

compiler/accumulator.m:
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/common.m:
compiler/continuation_info.m:
compiler/deforest.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/det_util.m:
compiler/dnf.m:
compiler/follow_code.m:
compiler/goal_store.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/inst_util.m:
compiler/instmap.m:
compiler/lambda.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/mercury_to_mercury.m:
compiler/modecheck_unify.m:
compiler/module_qual.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/prog_io_util.m:
compiler/prog_rep.m:
compiler/saved_vars.m:
compiler/stack_layout.m:
compiler/table_gen.m:
compiler/unify_proc.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
	Pass inst_varsets and types where needed.
	Changes to reflect change in definition of the inst data type.

compiler/inlining.m:
	Recompute the instmap deltas for a procedure after inlining.
	This bug showed up compiling tests/hard_coded/lp.m with
	inlining and deforestation turned on: deforestation was
	getting incorrect instmap deltas from inlining, causing
	the transformation to break mode-correctness.  It has only
	just shown up because of the added call to
	`inst_matches_initial' from within `recompute_instmap_delta'.

tests/invalid/Mmakefile:
tests/invalid/unbound_inst_var.m:
tests/invalid/unbound_inst_var.err_exp:
tests/valid/Mmakefile:
tests/valid/unbound_inst_var.m:
	Move the `unbound_inst_var' test case from `invalid' to `valid'
	and extend its coverage a bit.
2000-10-13 13:56:17 +00:00
Fergus Henderson
4d0dff1860 Allow typeclass instance declarations to contain clauses, as an
Estimated hours taken: 10

Allow typeclass instance declarations to contain clauses, as an
alternative to the current `pred(<MethodName>) is <ImplName>)' syntax.
This avoids the need for the user to explicitly define names for
procedures that just implement type class methods.

XXX Note that currently we only permit one clause per method.

compiler/prog_data.m:
	Change the second `sym_name' field of `instance_method'
	into a new type `instance_proc_def', which has two alternatives.
	The first, `name(sym_name)', is for the old syntax.
	The second, `clauses(list(item))', is for the new syntax.

compiler/prog_io_typeclass.m:
	Parse the new syntax.

compiler/make_hlds.m:
	Add new predicate `produce_instance_method_clauses',
	for use by check_typeclass.m.  This handles the generation of
	HLDS clauses_infos for both the old and new syntax for
	instance method definitions.
	Return the qual_info produced by `parse_tree_to_hlds',
	so that it can be passed to `produce_instance_method_clauses'.

compiler/mercury_compile.m:
	Pass the qual_info returned by make_hlds.m to check_typeclass.m.

compiler/check_typeclass.m:
	Move the code which produces HLDS definitions for instance
	methods into `produce_instance_method_clauses' in make_hlds.m.
	Thread the io__state and qual_info throughout most of the code,
	since this they are needed to process the new syntax.
	(The io__state is needed so we can spit out warnings about
	singleton variables in clauses in type class methods, and
	the qual_info is needed to handle explicit type qualifiers
	in such clauses.)

compiler/mercury_to_mercury.m:
	Output the new syntax.

tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/instance_clauses.m:
tests/hard_coded/typeclasses/instance_clauses.exp:
	A test case for the new feature.

doc/reference_manual.texi:
	Document the new feature.
2000-09-16 00:08:32 +00:00
Tyson Dowd
c192d50143 Add preliminary support for a new pragma:
Estimated hours taken: 15

Add preliminary support for a new pragma:

:- pragma foreign_code(LanguageString, .... <same args as c_code>).

This is intended to be the eventual replacement of pragma c_code.
Presently the only valid language is "C".
The existing pragma c_code is simply turned into pragma foreign_code.

pragma foreign_code is not a supported pragma at the moment.  There are
several other changes that are intended (for example, foreign_code will
be impure by default).

This change also changes the HLDS goal pragma_c_code/7 to
pragma_foreign_code/8 where the extra argument is the foreign language.

Any code currently generating output for pragma C code simply checks
that the foreign language is set to "c".  Since this is the only
alternative of the type foreign_language, it will always succeed.
However when new alternatives are added it should be fairly easy to find
where the changes need to be made.

Some type names and predicate names have also been updated, however
there are many more that haven't yet been touched.

compiler/prog_io_pragma.m:
	Accept the new syntax.	Turn the old syntax into the new item.

compiler/hlds_goal.m:
	Change pragma_c_code/7 to pragma_foreign_code/8.
	Define the foreign_language type.

compiler/llds.m:
	Change user_c_code/2 to user_foreign_code/3.

compiler/*.m:
	Update the rest of the compiler to handle these types.
	Make a few small changes to update variable names, predicate
	names and type names.
2000-08-09 07:48:04 +00:00
Peter Ross
a48beedc9d Fix a bug where pragma imports of polymorphic predicates where not
Estimated hours taken: 16

Fix a bug where pragma imports of polymorphic predicates where not
having typeinfos prepended to the call.

compiler/prog_data.m:
    Add a the new functor import/4 to pragma_c_code impl.
    The functor stores all the information needed to constuct a C code
    fragment a pragma import.

compiler/make_hlds.m:
    Rather then constructing the C code fragment immediately, construct
    the sub-parts and store them in import/4.

compiler/polymorphism.m:
    Prepend the typeinfos to the list of variables passed to the
    imported C function.

compiler/ml_code_gen.m:
compiler/pragma_c_gen.m:
    Construct the C code fragment then call the routine which handles
    `ordinary' pragma c_code.

compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
    Add code to recognise the import/4 functor.
2000-07-20 11:24:12 +00:00
Simon Taylor
a033b2e748 Fix a bug which caused intermod.m to abort when a type class
Estimated hours taken: 2

Fix a bug which caused intermod.m to abort when a type class
contained a predicate or function with more than one mode.

compiler/check_typeclass.m:
	Reorder the method declarations in each instance so that they
	match the order of the list of pred_proc_ids for the instance
	implementation.

compiler/intermod.m:
	Remove duplicate pred_ids from the list of methods in an
	instance declaration when module qualifying the original
	instance declaration before writing it to the `.opt' file.

	Make sure that predicates referred to by an instance declaration
	in a `.opt' file are made exported.

compiler/prog_data.m:
	Simplify the code by replacing the `pred_instance' and
	`func_instance' constructors of the `instance_method/0'
	type with a single constructor with a `pred_or_func' argument.

compiler/mercury_to_mercury.m:
compiler/check_typeclass.m:
compiler/prog_io_typeclass.m:
compiler/intermod.m:
	Handle the change to the `instance_method/0' type.

tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/intermod_typeclass_bug.m:
tests/hard_coded/typeclasses/intermod_typeclass_bug2.m:
tests/hard_coded/typeclasses/intermod_typeclass_bug.exp:
	Test case.
2000-07-06 06:25:25 +00:00
Tyson Dowd
79d75acdb0 Add impure functions to Mercury, clean up the purity module somewhat,
Estimated hours taken: 30

Add impure functions to Mercury, clean up the purity module somewhat,
fix some bugs in purity, update and expand the purity documentation,
and re-organize the purity checks.

Impure functions can be declared just like impure preds.
However, they can only be called in an explicit unification preceeded
by a purity level:

	impure X = some_impure_func(Y, Z)

The bug fixed was the fact that closures of impure predicates
were only being detected when using lambda syntax.  Purity information
was discarded and impure closures could be created like this:

	Pred = some_impure_pred

You could then use this predicate anywhere you like without any purity
declarations.

compiler/hlds_module.m:
	Add get_pred_id pred which will return the pred_id of a
	predicate matching a given type.  This is like
	get_pred_and_proc_id, but only gets the information we are
	interested in, and is semidet.
	We need a semidet version to handle cases where type inference
	cannot infer a type before the limit is reached, but we try to
	purity check this code.  (The bug mentioned above was stopping
	us from purity checking the test case for this before).

compiler/make_hlds.m:
	Check for "impure" unifications with expressions that are not
	function calls and issue appropriate error messages.
	When unravelling impure function call unifications, put the input
	parameter unifications (if any) before the actual call.
	Only mark the goal_info for the function call as impure.

compiler/mercury_to_goedel.m:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/prog_data.m:
compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_goal.m:
compiler/prog_util.m:
	Add purity information to unify goals.
	Don't assume unify goals are pure.

compiler/purity.m:
	Allow impure functions.
	Check unification goals for purity (not just lambda unification).
	Check unifications that are transformed into calls to make sure
	the call is purity correct.
	Put purity checking logic into separate predicates.
	Use an enum to return different errors and warnings.
	(The last two changes make it much easier to see the
	similarities between checking goals and checking predicates for
	purity correctness).
	Give different error messages for impure functions (highlight
	that you need to use them in an explicit unification).
	Handle unknown predicate lookups (can occur when unifying with
	a higher order term whose type could not be inferred).
	Add a few comments delineating where changes might need to be
	made to make foreign code impure by default in future.

compiler/notes/authors.html:
	Add Peter Schachte to the authors list.

doc/reference_manual.texi:
	Document impure functions.
	Expand more on what impure predicates/functions can do.
	Explain the concept of worst purity, and use it to explain the
	"inferred purity"/"declared purity" concepts.
	Make it more explicit that only impure goals obey
	strict-sequential like semantics.

tests/invalid/type_inf_loop.err_exp2:
	Fix this test case to reflect the new error message new that we
	check the purity of this code correctly (or rather, we correctly
	fail to be able to purity check this code).

tests/hard_coded/Mmakefile:
tests/hard_coded/purity.exp:
tests/hard_coded/purity.m:
tests/hard_coded/purity/Mmakefile:
tests/hard_coded/purity/impure_func_t1.m:
tests/hard_coded/purity/purity.m:
tests/hard_coded/purity/runtests:
	Remove purity tests from the hard_coded directory, give it a
	sub-directory of its own.

tests/invalid/Mmakefile:
tests/invalid/purity.err_exp:
tests/invalid/purity.m:
tests/invalid/purity_nonsense.err_exp:
tests/invalid/purity_nonsense.m:
tests/invalid/purity/Mmakefile:
tests/invalid/purity/impure_func_t2.err_exp:
tests/invalid/purity/impure_func_t2.m:
tests/invalid/purity/impure_func_t3.err_exp:
tests/invalid/purity/impure_func_t3.m:
tests/invalid/purity/impure_func_t4.err_exp:
tests/invalid/purity/impure_func_t4.m:
tests/invalid/purity/impure_func_t5.err_exp:
tests/invalid/purity/impure_func_t5.m:
tests/invalid/purity/impure_pred_t1.err_exp:
tests/invalid/purity/impure_pred_t1.m:
tests/invalid/purity/impure_pred_t2.err_exp:
tests/invalid/purity/impure_pred_t2.m:
tests/invalid/purity/purity.err_exp:
tests/invalid/purity/purity.m:
tests/invalid/purity/purity_nonsense.err_exp:
tests/invalid/purity/purity_nonsense.m:
tests/invalid/purity/runtests:
	Remove purity tests from the invalid directory, give it a
	sub-directory of its own.
2000-04-22 07:12:53 +00:00
David Jeffery
0dab66d926 Allow class methods to be impure or semipure.
Estimated hours taken: 6

Allow class methods to be impure or semipure. Previously any purity annotation
on a class method was ignored, and the method assumed to be pure. (We have
for some time caught the case of providing an impure implementation for
a (pure) class method, though).

compiler/prog_data.m:
        Add purity to the information we store about each method.
compiler/prog_io_typeclass.m:
        Record the declared purity of each method.
compiler/make_hlds.m:
        For the predicate we generate corresponding to a method, add any
        purity annotations that the method has.
compiler/check_typeclass.m:
        Add the appropriate impurity marker to the predicate we generate for
        each instance method.
compiler/purity.m:
        Be careful not to spit out spurious purity warnings:
                - Never warn about excessive impurity for a class methods.
                  (The body of the method is just class_method_call, which
                  never looks impure as far as it is concerned).
                - Never warn about excessive impurity for class instance
                  method. The fact that a method is impure doesn't mean that
                  its instances need to be impure, and it would be excessive
                  to warn about it, seeing that there is no way for the user
                  to avoid it (other than actually making their implementation
                  impure...).
compiler/mercury_to_mercury.m:
        Print out method purity in interface files.
compiler/module_qual.m:
compiler/equiv_type.m:
        Handle the fact that we now store purity info for class methods.

tests/hard_coded/typeclasses/impure_methods.{m,exp}:
        A test case for this change.
tests/hard_coded/typeclasses/Mmakefile:
        Turn this change on.
tests/invalid/impure_methods.{m,err_exp}:
        A test case for invalid use of impurity and class methods
tests/invalid/Mmakefile:
        Turn this change on.
2000-03-27 05:08:07 +00:00