mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
These allow types to be defined in the following manner:
:- type job ---> job(pred(int::out, io::di, io::uo) is det).
For any construction unification using this functor the argument must
have the required higher-order inst; it is a mode error if it does not.
When terms of type job with inst ground are deconstructed, the argument
is inferred to have the given inst, allowing a higher-order call in that
mode.
The new type syntax is currently only permitted as the direct argument of
a functor in a du type definition. In future it would be meaningful to
support this syntax in other locations, but that is left for a separate
change.
In order to correctly implement the construct/3 library predicate, we
need to be able to dynamically check that arguments do not violate
any constraints on the argument insts. At the moment, we conservatively
abort if any such constraints are present irrespective of whether they
are satisfied or not. Since these constraints are a new feature, no
existing code will abort in this way.
The implementation refers to the inst information associated with types
as "subtype information". This is because, generally, we think of the
combination of a type with a fully bound inst (i.e., one that describes
terms that contain no unbound variables) describes a subtype of that type.
compiler/inst_util.m:
Ensure that arguments have the necessary insts in construction
unifications.
Where available, propagate the insts into arguments rather than
using ground(shared, none).
compiler/prog_io_type_name.m:
Parse the new form of types.
compiler/unparse.m:
Unparse the new form of types.
compiler/prog_io_type_defn.m:
Allow the new form of types in functor arguments.
compiler/prog_ctgc.m:
compiler/prog_io_item.m:
compiler/prog_io_mutable.m:
compiler/prog_io_pragma.m:
compiler/prog_io_typeclass.m:
compiler/superhomogeneous.m:
Disallow the new form of types in places other than functor
arguments.
compiler/prog_data.m:
Go back to representing function types with result type appended
to the arguments. In most case this now results in simpler code.
compiler/prog_type.m:
Abstract away the representation of predicate vs function arguments
by using a predicate to construct these types.
compiler/rtti.m:
compiler/type_ctor_info.m:
Include subtype information about the arguments of a du functor
and about the argument of a notag functor. Generate this
information from the argument types.
Currently, the information is one bit which says whether or not
any subtypes exist in the arguments.
Bump the RTTI version number from the compiler side.
compiler/rtti_out.m:
Output functor subtype information for the low-level C backend.
compiler/rtti_to_mlds.m:
Include functor subtype information in the MLDS.
compiler/mlds_to_cs.m:
Add the new runtime type to the special cases.
compiler/erl_rtti.m:
compiler/erlang_rtti.m:
library/erlang_rtti_implementation.m:
Include functor subtype info in the erlang RTTI.
java/runtime/DuFunctorDesc.java:
java/runtime/FunctorSubtypeInfo.java:
Include functor subtype information in the Java runtime.
runtime/mercury_dotnet.cs.in:
Include functor subtype information in the C# runtime.
runtime/mercury_type_info.h:
Include functor subtype information in the C runtime.
Bump the RTTI version number in the runtime.
Define macros to access the new field. These macros can correctly
handle the previous RTTI version, therefore we do not need to
change the minimum version at this time.
library/private_builtin.m:
Define constants for use by the Java backend.
library/construct.m:
library/rtti_implementation.m:
Use the new RTTI to ensure we don't attempt to construct terms
that violate the new insts.
compiler/prog_rep_tables.m:
Ignore the new inst info for now.
compiler/*.m:
Changes to conform to above.
doc/reference_manual.texi:
Document the new feature.
tests/hard_coded/functor_ho_inst.{m,exp}:
tests/hard_coded/functor_ho_inst_2.{m,exp}:
tests/hard_coded/functor_ho_inst_excp.{m,exp}:
tests/hard_coded/functor_ho_inst_excp_2.{m,exp}:
Test the new functionality.
tests/invalid/combined_ho_type_inst.{m,err_exp}:
tests/invalid/combined_ho_type_inst_2.{m,err_exp}:
Test that we don't allow the new types where they are not permitted,
or are incomplete.
tests/invalid/functor_ho_inst_bad.{m,err_exp}:
tests/invalid/functor_ho_inst_bad_2.{m,err_exp}:
tests/invalid/functor_ho_inst_bad_3.{m,err_exp}:
Test that the argument inst information is enforced as required.
tests/hard_coded/Mmakefile:
tests/invalid/Mmakefile:
Run the new test cases.
56 lines
1.9 KiB
Java
56 lines
1.9 KiB
Java
//
|
|
// Copyright (C) 2001-2004, 2011 The University of Melbourne.
|
|
// This file may only be copied under the terms of the GNU Library General
|
|
// Public License - see the file COPYING.LIB in the Mercury distribution.
|
|
//
|
|
|
|
package jmercury.runtime;
|
|
|
|
public class DuFunctorDesc implements java.io.Serializable {
|
|
|
|
public java.lang.String du_functor_name;
|
|
public int du_functor_orig_arity;
|
|
public int du_functor_arg_type_contains_var;
|
|
public Sectag_Locn du_functor_sectag_locn;
|
|
public int du_functor_primary;
|
|
public int du_functor_secondary;
|
|
public int du_functor_ordinal;
|
|
// XXX PseudoTypeInfo's have not been implemented properly
|
|
// yet, so this may not be correct.
|
|
public /*final*/ PseudoTypeInfo[] du_functor_arg_types;
|
|
public /*final*/ java.lang.String[] du_functor_arg_names;
|
|
public /*final*/ DuArgLocn[] du_functor_arg_locns;
|
|
public /*final*/ DuExistInfo du_functor_exist_info;
|
|
public FunctorSubtypeInfo du_functor_subtype_info;
|
|
|
|
public DuFunctorDesc()
|
|
{
|
|
}
|
|
|
|
public void init(java.lang.String functor_name, int orig_arity,
|
|
int arg_type_contains_var, int sectag_locn, int primary,
|
|
int secondary, int ordinal,
|
|
// XXX why do we need to use Object here?
|
|
java.lang.Object arg_types,
|
|
java.lang.Object arg_names,
|
|
java.lang.Object arg_locns,
|
|
java.lang.Object exist_info,
|
|
int functor_subtype_info)
|
|
{
|
|
du_functor_name = functor_name;
|
|
du_functor_orig_arity = orig_arity;
|
|
du_functor_ordinal = ordinal;
|
|
du_functor_arg_type_contains_var = arg_type_contains_var;
|
|
du_functor_sectag_locn = new Sectag_Locn(sectag_locn);
|
|
du_functor_primary = primary;
|
|
du_functor_secondary = secondary;
|
|
du_functor_ordinal = ordinal;
|
|
du_functor_arg_types = (PseudoTypeInfo []) arg_types;
|
|
du_functor_arg_names = (java.lang.String []) arg_names;
|
|
du_functor_arg_locns = (DuArgLocn []) arg_locns;
|
|
du_functor_exist_info = (DuExistInfo) exist_info;
|
|
du_functor_subtype_info =
|
|
new FunctorSubtypeInfo(functor_subtype_info);
|
|
}
|
|
}
|