From 3e5230d8c79f414c1a63a0848720db8b32cabf2f Mon Sep 17 00:00:00 2001 From: dnwpark Date: Mon, 23 Sep 2024 20:34:54 -0400 Subject: [PATCH] Disable inlined defaults when inlining the function body. --- edb/edgeql/compiler/func.py | 12 ++++++++---- edb/edgeql/compiler/polyres.py | 5 ++++- edb/schema/functions.py | 5 ++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/edb/edgeql/compiler/func.py b/edb/edgeql/compiler/func.py index b412f67754bf..5d60de8b2ae3 100644 --- a/edb/edgeql/compiler/func.py +++ b/edb/edgeql/compiler/func.py @@ -377,8 +377,9 @@ def compile_FunctionCall( # TODO: Global parameters still use the implicit globals parameter. # They should be directly substituted in whenever possible. - inline_args: dict[int | str, irast.CallArg | irast.Set] = {} + inline_args: dict[str, irast.CallArg | irast.Set] = {} + # Collect non-default call args to inline for param_shortname, arg_key in param_name_to_arg_key.items(): if ( isinstance(arg_key, int) @@ -388,6 +389,9 @@ def compile_FunctionCall( continue arg = final_args[arg_key] + if arg.is_default: + continue + inline_args[param_shortname] = arg # Package variadic arguments into an array @@ -416,7 +420,7 @@ def compile_FunctionCall( for param in matched_func_params.objects(env.schema): param_shortname = param.get_parameter_name(env.schema) - if param_shortname in param_name_to_arg_key: + if param_shortname in inline_args: continue else: @@ -462,7 +466,6 @@ def compile_FunctionCall( arg.expr, optional=( arg.param_typemod == ft.TypeModifier.OptionalType - or arg.is_default ), ctx=ctx, ) @@ -474,10 +477,11 @@ def compile_FunctionCall( class ArgumentInliner(ast.NodeTransformer): mapped_args: dict[irast.PathId, irast.PathId] + inlined_arg_keys: list[int | str] def __init__( self, - inline_args: dict[int | str, irast.CallArg | irast.Set], + inline_args: dict[str, irast.CallArg | irast.Set], ctx: context.ContextLevel, ) -> None: super().__init__() diff --git a/edb/edgeql/compiler/polyres.py b/edb/edgeql/compiler/polyres.py index 44862c1a9665..87b6728e79ea 100644 --- a/edb/edgeql/compiler/polyres.py +++ b/edb/edgeql/compiler/polyres.py @@ -313,7 +313,10 @@ def _get_cast_distance( variadic_arg_id: Optional[int] = None variadic_arg_count: Optional[int] = None no_args_call = not args and not kwargs - has_inlined_defaults = func.has_inlined_defaults(schema) + has_inlined_defaults = ( + func.has_inlined_defaults(schema) + and not func.get_is_inlined(schema) + ) func_params = func.get_params(schema) diff --git a/edb/schema/functions.py b/edb/schema/functions.py index ed90172b81a5..c5975f6260dc 100644 --- a/edb/schema/functions.py +++ b/edb/schema/functions.py @@ -2509,7 +2509,10 @@ def get_compiler_options( inlining_context: Optional[qlcontext.ContextLevel] = None, ) -> qlcompiler.CompilerOptions: - has_inlined_defaults = bool(params.find_named_only(schema)) + has_inlined_defaults = ( + bool(params.find_named_only(schema)) + and inlining_context is None + ) param_anchors = get_params_symtable( params,