From 090a503a3d843188b5a78f44999714c5c6243afd Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Fri, 20 Sep 2024 22:04:35 -0700 Subject: [PATCH] Infer volatility for Pointer on its own (#7786) A leftover TODO from the Pointer refactor. We still need to do this for cardinality and multiplicity, and cardinality inference at least needs some thought. --- edb/edgeql/compiler/inference/volatility.py | 47 ++++++++++----------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/edb/edgeql/compiler/inference/volatility.py b/edb/edgeql/compiler/inference/volatility.py index 0a15f1a8ae6..a23e3e9156a 100644 --- a/edb/edgeql/compiler/inference/volatility.py +++ b/edb/edgeql/compiler/inference/volatility.py @@ -159,7 +159,29 @@ def _infer_pointer( ir: irast.Pointer, env: context.Environment, ) -> InferredVolatility: - raise AssertionError('TODO: properly infer Pointer-as-Expr ') + vol = _infer_volatility(ir.source, env) + # If there's an expression on an rptr, and it comes from + # the schema, we need to actually infer it, since it won't + # have been processed at a shape declaration. + if ir.expr is not None and not ir.ptrref.defined_here: + vol = _max_volatility(( + vol, + _infer_volatility(ir.expr, env), + )) + + # If source is an object, then a pointer reference implies + # a table scan, and so we can assume STABLE at the minimum. + # + # A single dereference of a singleton path can be IMMUTABLE, + # though, which we need in order to enforce that indexes + # don't call STABLE functions. + if ( + irtyputils.is_object(ir.source.typeref) + and ir.source.path_id not in env.singletons + ): + vol = _max_volatility((vol, STABLE)) + + return vol @_infer_volatility_inner.register @@ -169,31 +191,8 @@ def __infer_set( ) -> InferredVolatility: vol: InferredVolatility - # TODO: Migrate to Pointer-as-Expr a little less half-assedly. if ir.path_id in env.singletons: vol = IMMUTABLE - elif isinstance(ir.expr, irast.Pointer): - vol = _infer_volatility(ir.expr.source, env) - # If there's an expression on an rptr, and it comes from - # the schema, we need to actually infer it, since it won't - # have been processed at a shape declaration. - if ir.expr.expr is not None and not ir.expr.ptrref.defined_here: - vol = _max_volatility(( - vol, - _infer_volatility(ir.expr.expr, env), - )) - - # If source is an object, then a pointer reference implies - # a table scan, and so we can assume STABLE at the minimum. - # - # A single dereference of a singleton path can be IMMUTABLE, - # though, which we need in order to enforce that indexes - # don't call STABLE functions. - if ( - irtyputils.is_object(ir.expr.source.typeref) - and ir.expr.source.path_id not in env.singletons - ): - vol = _max_volatility((vol, STABLE)) else: vol = _infer_volatility(ir.expr, env)