Skip to content

Commit

Permalink
Compile inline functions without finalizing.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnwpark committed Sep 16, 2024
1 parent 5898890 commit 50377c8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
5 changes: 2 additions & 3 deletions edb/edgeql/compiler/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def compile_FunctionCall(
sn.QualName('default', 'foo'),
]
):
inline_func = s_func.compile_function(
inline_func = s_func.compile_function_inline(
schema=ctx.env.schema,
context=sd.CommandContext(
# Probably not correct. Need to store modaliases while compiling
Expand Down Expand Up @@ -448,8 +448,7 @@ def compile_FunctionCall(
)

argument_inliner = ArgumentInliner(inline_args, ctx=ctx)
inline_func_expr = inline_func.irast.expr
res.body = argument_inliner.visit(inline_func_expr)
res.body = argument_inliner.visit(inline_func)
res.inline_arg_path_ids = argument_inliner.mapped_args
else:
res = fcall
Expand Down
62 changes: 62 additions & 0 deletions edb/schema/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2452,3 +2452,65 @@ def compile_function(
)

return compiled


def compile_function_inline(
schema: s_schema.Schema,
context: sd.CommandContext,
*,
body: s_expr.Expression,
func_name: sn.QualName,
params: FuncParameterList,
language: qlast.Language,
return_type: s_types.Type,
return_typemod: ft.TypeModifier,
track_schema_ref_exprs: bool=False,
inlining_context: Optional[qlcontext.ContextLevel] = None,
) -> irast.Set:
assert language is qlast.Language.EdgeQL

from edb.edgeql.compiler import dispatch
from edb.edgeql.compiler import pathctx
from edb.edgeql.compiler import setgen
from edb.edgeql.compiler import stmtctx

has_inlined_defaults = bool(params.find_named_only(schema))

param_anchors = get_params_symtable(
params,
schema,
inlined_defaults=has_inlined_defaults,
)

ctx = stmtctx.init_context(
schema=schema,
options=qlcompiler.CompilerOptions(
anchors=param_anchors,
func_name=func_name,
func_params=params,
apply_query_rewrites=not context.stdmode,
track_schema_ref_exprs=track_schema_ref_exprs,
),
inlining_context=inlining_context,
)

ql_expr = body.parse()

if isinstance(ql_expr, qlast.Expr) and ctx.implicit_limit:
ql_expr = qlast.SelectQuery(result=ql_expr, implicit=True)
ql_expr.limit = qlast.Constant.integer(ctx.implicit_limit)

script_info = stmtctx.preprocess_script([ql_expr], ctx=ctx)
ctx.env.script_params = script_info.params

ir_set: irast.Set = dispatch.compile(ql_expr, ctx=ctx)

if inlining_context:
inlining_context.env.schema = ctx.env.schema

if (
pathctx.get_set_scope(ir_set, ctx=ctx) is None
):
ir_set = setgen.scoped_set(ir_set, ctx=ctx)

return ir_set

0 comments on commit 50377c8

Please sign in to comment.