Skip to content

Commit 7e4f765

Browse files
committed
Activate properties traces on a per-property basis
This allows to only activate logging for a subset of properties, which is generally more useful.
1 parent 2956da2 commit 7e4f765

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

langkit/expressions/base.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,7 +2892,8 @@ def __init__(self, expr, prefix, name=None, doc=None, public=None,
28922892
uses_entity_info=None, uses_envs=None,
28932893
optional_entity_info=False, warn_on_unused=True,
28942894
ignore_warn_on_node=None,
2895-
call_non_memoizable_because=None):
2895+
call_non_memoizable_because=None,
2896+
activate_tracing=False):
28962897
"""
28972898
:param expr: The expression for the property. It can be either:
28982899
* An expression.
@@ -2995,6 +2996,9 @@ def __init__(self, expr, prefix, name=None, doc=None, public=None,
29952996
of this property in a memoized context impossible. Must be used for
29962997
external properties that do side effects (such as loading an
29972998
analysis unit), as this conflicts with the memoization machinery.
2999+
3000+
:param bool activate_tracing: Whether we want to activate tracing for
3001+
this property's execution.
29983002
"""
29993003

30003004
self.prefix = prefix
@@ -3153,6 +3157,8 @@ def __init__(self, expr, prefix, name=None, doc=None, public=None,
31533157
variable.
31543158
"""
31553159

3160+
self.activate_tracing = activate_tracing
3161+
31563162
@property
31573163
def has_debug_info(self):
31583164
"""
@@ -4134,7 +4140,8 @@ def langkit_property(public=None, return_type=None, kind=AbstractKind.concrete,
41344140
call_memoizable=False, memoize_in_populate=False,
41354141
external=False, uses_entity_info=None, uses_envs=None,
41364142
warn_on_unused=True, ignore_warn_on_node=None,
4137-
call_non_memoizable_because=None):
4143+
call_non_memoizable_because=None,
4144+
activate_tracing=False):
41384145
"""
41394146
Decorator to create properties from real Python methods. See Property for
41404147
more details.
@@ -4162,6 +4169,7 @@ def decorator(expr_fn):
41624169
warn_on_unused=warn_on_unused,
41634170
ignore_warn_on_node=ignore_warn_on_node,
41644171
call_non_memoizable_because=call_non_memoizable_because,
4172+
activate_tracing=activate_tracing,
41654173
)
41664174
return decorator
41674175

langkit/templates/pkg_implementation_spec_ada.mako

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,10 @@ private package ${ada_lib_name}.Implementation is
288288
function "+" (Left, Right : Big_Integer_Type) return Big_Integer_Type;
289289
function "-" (Left, Right : Big_Integer_Type) return Big_Integer_Type;
290290

291+
% if ctx.properties_logging:
291292
function Trace_Image (I : Big_Integer_Type) return String;
293+
% endif
294+
292295
------------------------------------------------------
293296
-- AST node derived types (incomplete declarations) --
294297
------------------------------------------------------

langkit/templates/properties/def_ada.mako

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ is
8585
begin
8686
${gdb_property_body_start()}
8787

88-
% if ctx.properties_logging:
88+
% if has_logging:
8989
Properties_Traces.Trace
9090
("${property.qualname} ("
9191
% if property._has_self_entity:
@@ -147,15 +147,15 @@ begin
147147
Mmz_Val := Memoization_Maps.Element (Mmz_Cur);
148148

149149
if Mmz_Val.Kind = Mmz_Evaluating then
150-
% if ctx.properties_logging:
150+
% if has_logging:
151151
Properties_Traces.Trace
152152
("Result: infinite recursion");
153153
% endif
154154
${gdb_memoization_return()}
155155
raise Property_Error with "Infinite recursion detected";
156156

157157
elsif Mmz_Val.Kind = Mmz_Property_Error then
158-
% if ctx.properties_logging:
158+
% if has_logging:
159159
Properties_Traces.Trace
160160
("Result: Property_Error");
161161
Properties_Traces.Decrease_Indent;
@@ -169,7 +169,7 @@ begin
169169
Inc_Ref (Property_Result);
170170
% endif
171171

172-
% if ctx.properties_logging:
172+
% if has_logging:
173173
Properties_Traces.Trace
174174
("Result: " & Trace_Image (Property_Result));
175175
Properties_Traces.Decrease_Indent;
@@ -212,7 +212,7 @@ begin
212212
% endif
213213
% endif
214214

215-
% if ctx.properties_logging:
215+
% if has_logging:
216216
Properties_Traces.Trace ("Result: " & Trace_Image (Property_Result));
217217
Properties_Traces.Decrease_Indent;
218218
% endif
@@ -221,7 +221,7 @@ begin
221221

222222
% if property.vars.root_scope.has_refcounted_vars(True) or \
223223
property.memoized or \
224-
ctx.properties_logging:
224+
has_logging:
225225
exception
226226
when Property_Error =>
227227
% for scope in all_scopes:
@@ -242,7 +242,7 @@ begin
242242
% endif
243243
% endif
244244

245-
% if ctx.properties_logging:
245+
% if has_logging:
246246
Properties_Traces.Trace ("Result: Properties_Error");
247247
Properties_Traces.Decrease_Indent;
248248
% endif

0 commit comments

Comments
 (0)