Skip to content

Commit 5e76298

Browse files
pmderodatraph-amiard
authored andcommitted
Adalog: remove comparers
The symbolic solver does not handle comparers, so it makes no sense to keep them in Langkit. TN: SB20-024
1 parent 1c2221d commit 5e76298

19 files changed

+127
-341
lines changed

langkit/compile_context.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -665,11 +665,6 @@ def __init__(self,
665665
Set of properties used as converters in logic equations.
666666
"""
667667

668-
self.logic_comparer_props: Set[PropertyDef] = set()
669-
"""
670-
Set of properties used as comparers in logic equations.
671-
"""
672-
673668
self.default_unit_provider = default_unit_provider
674669
self.case_insensitive = case_insensitive
675670
self.symbol_canonicalizer = symbol_canonicalizer
@@ -977,11 +972,6 @@ def sorted_logic_converters(self):
977972
return sorted(self.logic_converter_props,
978973
key=lambda x: x.name.camel)
979974

980-
@property
981-
def sorted_logic_comparers(self):
982-
return sorted(self.logic_comparer_props,
983-
key=lambda x: x.name.camel)
984-
985975
def sorted_types(self, type_set):
986976
"""
987977
Turn "type_set" into a list of types sorted by name.
@@ -1005,21 +995,17 @@ def sorted_exception_types(self) -> List[GeneratedException]:
1005995
return sorted(self.exception_types.values(),
1006996
key=lambda e: e.doc_entity)
1007997

1008-
def do_generate_logic_functors(self, convert_property=None,
1009-
eq_property=None):
998+
def do_generate_logic_functors(self, convert_property=None):
1010999
"""
10111000
Generate a logic binder with the given conversion property.
10121001
10131002
If you call this function several times for the same property, only one
10141003
binder will be generaed.
10151004
10161005
:param PropertyDef convert_property: The conversion property.
1017-
:param PropertyDef eq_property: The equality property.
10181006
"""
10191007
if convert_property:
10201008
self.logic_converter_props.add(convert_property)
1021-
if eq_property:
1022-
self.logic_comparer_props.add(eq_property)
10231009

10241010
@staticmethod
10251011
def grammar_rule_api_name(rule):

langkit/dsl_unparse.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,6 @@ def handle_designated_env_macro():
12211221
elif isinstance(expr, Bind):
12221222
return "%eq({})".format(", ".join(keep([
12231223
ee(expr.from_expr), ee(expr.to_expr),
1224-
"eq_prop={}".format(fqn(expr.eq_prop)) if expr.eq_prop else ""
12251224
"conv_prop={}".format(fqn(expr.conv_prop)) if expr.conv_prop else ""
12261225
])))
12271226

langkit/expressions/logic.py

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ class Bind(AbstractExpression):
4343
return any ``ASTNode`` subclass. It is used to convert `from_expr` into a
4444
value to which `to_expr` is compared.
4545
46-
If provided, `eq_prop` must be a property that takes one ``ASTNode``
47-
subclass argument and that compares it to ``Self``. In this case, the
48-
argument must be of the same type that the node that owns the property. It
49-
is used to compare the two logic variables (after `conv_prop` call, if
50-
applicable).
51-
5246
For instance, in order to express the following logical equation::
5347
5448
B = A.some_property()
@@ -61,12 +55,10 @@ class Bind(AbstractExpression):
6155
class Expr(CallExpr):
6256
def __init__(self,
6357
conv_prop: PropertyDef,
64-
eq_prop: PropertyDef,
6558
lhs: ResolvedExpression,
6659
rhs: ResolvedExpression,
6760
abstract_expr: Optional[AbstractExpression] = None):
6861
self.conv_prop = conv_prop
69-
self.eq_prop = eq_prop
7062
self.lhs = lhs
7163
self.rhs = rhs
7264

@@ -81,19 +73,14 @@ def __init__(self,
8173
("Cache_Value", LiteralExpr("<>", None)),
8274
))
8375

84-
if eq_prop:
85-
constructor_args.append(self.functor_expr(
86-
eq_prop, f"Eq => Comparer_{self.eq_prop.uid}"
87-
))
88-
8976
if abstract_expr:
9077
constructor_args.append(
9178
f"Debug_String => {sloc_info_arg(abstract_expr.location)}"
9279
)
9380

9481
if rhs.type.matches(T.root_node.entity):
9582
fn_name = 'Solver.Create_Assign'
96-
elif conv_prop or eq_prop:
83+
elif conv_prop:
9784
fn_name = 'Solver.Create_Propagate'
9885
else:
9986
fn_name = 'Solver.Create_Unify'
@@ -129,14 +116,13 @@ def functor_expr(prop: PropertyDef,
129116
@property
130117
def subexprs(self):
131118
return {'conv_prop': self.conv_prop,
132-
'eq_prop': self.eq_prop,
133119
'lhs': self.lhs,
134120
'rhs': self.rhs}
135121

136122
def __repr__(self):
137123
return '<Bind.Expr>'
138124

139-
def __init__(self, from_expr, to_expr, conv_prop=None, eq_prop=None):
125+
def __init__(self, from_expr, to_expr, conv_prop=None):
140126
"""
141127
:param AbstractExpression from_expr: An expression resolving to a
142128
logical variable that is the source of the bind.
@@ -147,20 +133,11 @@ def __init__(self, from_expr, to_expr, conv_prop=None, eq_prop=None):
147133
For convenience, it can be a property on any subclass of the root
148134
AST node class, and can return any subclass of the root AST node
149135
class.
150-
:param PropertyDef|None eq_prop: The property to use to test for
151-
equality between the value of the two expressions. For convenience,
152-
it can be a property on a subclass of the root AST node class,
153-
however:
154-
155-
1. It needs to take exactly two parameters, the self parameter and
156-
another parameter.
157-
2. The two parameters must be of exactly the same type.
158136
"""
159137
super().__init__()
160138
self.from_expr = from_expr
161139
self.to_expr = to_expr
162140
self.conv_prop = conv_prop
163-
self.eq_prop = eq_prop
164141

165142
def resolve_props(self):
166143
from langkit.expressions import FieldAccess
@@ -181,10 +158,6 @@ def resolve(name, prop):
181158

182159
return prop
183160

184-
self.eq_prop = resolve('eq_prop', self.eq_prop)
185-
if self.eq_prop:
186-
self.eq_prop.root_property
187-
188161
self.conv_prop = resolve('conv_prop', self.conv_prop)
189162
if self.conv_prop:
190163
self.conv_prop = self.conv_prop.root_property
@@ -193,7 +166,7 @@ def construct(self):
193166
from langkit.compile_context import get_context
194167
self.resolve_props()
195168

196-
get_context().do_generate_logic_functors(self.conv_prop, self.eq_prop)
169+
get_context().do_generate_logic_functors(self.conv_prop)
197170

198171
# We have to wait for the construct pass for the following checks
199172
# because they rely on type information, which is not supposed to be
@@ -209,45 +182,14 @@ def construct(self):
209182
'Bind property must belong to a subtype of {}'.format(
210183
T.root_node.dsl_name
211184
)),
212-
])
213185

214-
DynamicVariable.check_call_bindings(
215-
self.conv_prop, "In Bind's conv_prop {prop}"
216-
)
217-
218-
# Those checks are run in construct, because we need the eq_prop to be
219-
# prepared already, which is not certain in do_prepare (order
220-
# dependent).
221-
222-
if self.eq_prop:
223-
args = self.eq_prop.natural_arguments
224-
check_multiple([
225-
(self.eq_prop.type == T.Bool,
226-
'Equality property must return boolean'),
227-
228-
(self.eq_prop.struct.matches(T.root_node),
229-
'Equality property must belong to a subtype of {}'.format(
230-
T.root_node.dsl_name
231-
)),
232-
233-
(len(args) == 1,
234-
'Equality property: expected 1 argument, got {}'.format(
235-
len(args)
236-
)),
186+
(all(arg.default_value is not None
187+
for arg in self.conv_prop.natural_arguments),
188+
'Bind property can take only optional arguments'),
237189
])
238190

239-
other_type = args[0].type
240-
check_source_language(
241-
other_type.is_entity_type,
242-
"First arg of equality property should be an entity type"
243-
)
244-
check_source_language(
245-
other_type.element_type == self.eq_prop.struct,
246-
"Self and first argument should be of the same type"
247-
)
248-
249191
DynamicVariable.check_call_bindings(
250-
self.eq_prop, "In Bind's eq_prop {prop}"
192+
self.conv_prop, "In Bind's conv_prop {prop}"
251193
)
252194

253195
# Left operand must be a logic variable. Make sure the resulting
@@ -282,8 +224,7 @@ def construct(self):
282224
from langkit.expressions import Cast
283225
rhs = Cast.Expr(rhs, T.root_node.entity)
284226

285-
return Bind.Expr(self.conv_prop, self.eq_prop,
286-
lhs, rhs, abstract_expr=self)
227+
return Bind.Expr(self.conv_prop, lhs, rhs, abstract_expr=self)
287228

288229

289230
class DomainExpr(ComputingExpr):

langkit/templates/astnode_types_ada.mako

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66

77
<%def name="logic_helpers()">
8-
## Generate predicate, converter and comparer functors, which wrap
9-
## properties to be used in logic equations.
8+
## Generate predicate and converter functors, which wrap properties to be
9+
## used in logic equations.
1010
##
1111
## Note that we need to generate them before the properties bodies, because
1212
## they'll be used in the bodies.
@@ -18,9 +18,6 @@
1818
% for conv_prop in ctx.sorted_logic_converters:
1919
${prop_helpers.logic_converter(conv_prop)}
2020
% endfor
21-
% for eq_prop in ctx.sorted_logic_comparers:
22-
${prop_helpers.logic_equal(eq_prop)}
23-
% endfor
2421
</%def>
2522

2623

langkit/templates/parsers/pkg_main_body_ada.mako

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ package body ${ada_lib_name}.Parsers is
9292

9393
type Dontskip_Parser_Function is access function
9494
(Parser : in out Parser_Type;
95-
Pos : Token_Index)
96-
return ${ctx.root_grammar_class.storage_type_name};
95+
Pos : Token_Index) return ${ctx.root_grammar_class.storage_type_name};
9796

9897
package Dont_Skip_Fn_Vectors
9998
is new Ada.Containers.Vectors (Natural, Dontskip_Parser_Function);

langkit/templates/properties/helpers.mako

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -96,72 +96,6 @@
9696
end Image;
9797
</%def>
9898

99-
<%def name="logic_equal(eq_prop)">
100-
<%
101-
struct = eq_prop.struct
102-
type_name = 'Comparer_{}'.format(eq_prop.uid)
103-
%>
104-
105-
${dynamic_vars_holder_decl(
106-
type_name, "Solver_Ifc.Comparer_Type", eq_prop.dynamic_vars
107-
)}
108-
109-
overriding function Image (Self : ${type_name}) return String;
110-
overriding function Compare
111-
(Self : ${type_name}; L, R : ${T.entity.name}) return Boolean;
112-
113-
-----------
114-
-- Image --
115-
-----------
116-
117-
overriding function Image (Self : ${type_name}) return String is
118-
begin
119-
return ("${eq_prop.qualname}");
120-
end Image;
121-
122-
-------------
123-
-- Compare --
124-
-------------
125-
126-
overriding function Compare
127-
(Self : ${type_name}; L, R : ${T.entity.name}) return Boolean
128-
is
129-
% if not eq_prop.dynamic_vars:
130-
pragma Unreferenced (Self);
131-
% endif
132-
begin
133-
-- If any node pointer is null, then use that for equality
134-
if L.Node = null or else R.Node = null then
135-
return L.Node = R.Node;
136-
end if;
137-
138-
-- Check that both arguments have appropriate types for the property
139-
-- call.
140-
if L.Node.Kind not in ${struct.ada_kind_range_name} then
141-
raise Property_Error with
142-
"Wrong type for ${eq_prop.qualname}'s ""self"" argument";
143-
elsif R.Node.Kind not in ${struct.ada_kind_range_name} then
144-
raise Property_Error with
145-
"Wrong type for ${eq_prop.qualname}'s"
146-
& " ""${eq_prop.natural_arguments[0].dsl_name}"" argument";
147-
end if;
148-
149-
-- All is good: do the call
150-
declare
151-
R_Entity : constant ${struct.entity.name} := (R.Node, R.Info);
152-
begin
153-
return ${eq_prop.name}
154-
(${eq_prop.self_arg_name} => L.Node,
155-
${eq_prop.natural_arguments[0].name} => R_Entity,
156-
% for dynvar in eq_prop.dynamic_vars:
157-
${dynvar.argument_name} => Self.${dynvar.argument_name},
158-
% endfor
159-
${eq_prop.entity_info_name} => L.Info);
160-
end;
161-
end Compare;
162-
163-
</%def>
164-
16599
<%def name="logic_predicates(prop)">
166100
% for (args_types, default_passed_args, pred_id) in prop.logic_predicates:
167101

support/langkit_support-adalog-generic_main_support.adb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,7 @@ package body Langkit_Support.Adalog.Generic_Main_Support is
274274
procedure Run_Main (Main : access procedure) is
275275
begin
276276
Setup_Traces;
277-
278-
begin
279-
Main.all;
280-
exception
281-
when Exc : Unsupported_Error =>
282-
Put_Line
283-
(Exception_Name (Exc) & ": " & Exception_Message (Exc));
284-
end;
285-
277+
Main.all;
286278
Finalize;
287279
end Run_Main;
288280

support/langkit_support-adalog-generic_main_support.ads

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ package Langkit_Support.Adalog.Generic_Main_Support is
7878
function Propagate
7979
(L, R : Refs.Logic_Var;
8080
Conv : Converter_Type'Class := No_Converter;
81-
Eq : Comparer_Type'Class := No_Comparer;
8281
Dbg_String : String := "") return Relation
8382
is
84-
(+Create_Propagate (L, R, Conv, Eq, -Dbg_String));
83+
(+Create_Propagate (L, R, Conv, -Dbg_String));
8584

8685
function Unify
8786
(L, R : Refs.Logic_Var; Dbg_String : String := "") return Relation
@@ -91,10 +90,9 @@ package Langkit_Support.Adalog.Generic_Main_Support is
9190
(L : Refs.Logic_Var;
9291
R : T;
9392
Conv : Converter_Type'Class := No_Converter;
94-
Eq : Comparer_Type'Class := No_Comparer;
9593
Dbg_String : String := "") return Relation
9694
is
97-
(+Create_Assign (L, R, Conv, Eq, -Dbg_String));
95+
(+Create_Assign (L, R, Conv, -Dbg_String));
9896

9997
function Predicate
10098
(L : Refs.Logic_Var;

support/langkit_support-adalog-solver.adb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,16 +1650,10 @@ package body Langkit_Support.Adalog.Solver is
16501650
(Logic_Var : Logic_Vars.Logic_Var;
16511651
Value : Value_Type;
16521652
Conv : Converter_Type'Class := No_Converter;
1653-
Eq : Comparer_Type'Class := No_Comparer;
16541653
Debug_String : String_Access := null) return Relation
16551654
is
16561655
Conv_Ptr : Converter_Access := null;
16571656
begin
1658-
if not Is_No_Comparer (Eq) then
1659-
raise Unsupported_Error with
1660-
"Comparer_Type not supported with the symbolic solver";
1661-
end if;
1662-
16631657
if not Is_No_Converter (Conv) then
16641658
Conv_Ptr := new Converter_Type'Class'(Conv);
16651659
end if;
@@ -1711,16 +1705,10 @@ package body Langkit_Support.Adalog.Solver is
17111705
function Create_Propagate
17121706
(From, To : Logic_Var;
17131707
Conv : Converter_Type'Class := No_Converter;
1714-
Eq : Comparer_Type'Class := No_Comparer;
17151708
Debug_String : String_Access := null) return Relation
17161709
is
17171710
Conv_Ptr : Converter_Access := null;
17181711
begin
1719-
if not Is_No_Comparer (Eq) then
1720-
raise Unsupported_Error with
1721-
"Comparer_Type not supported with the symbolic solver";
1722-
end if;
1723-
17241712
if not Is_No_Converter (Conv) then
17251713
Conv_Ptr := new Converter_Type'Class'(Conv);
17261714
end if;

0 commit comments

Comments
 (0)