Skip to content

Commit

Permalink
srcctx -> span
Browse files Browse the repository at this point in the history
  • Loading branch information
aljazerzen committed Mar 26, 2024
1 parent de83e2d commit 1a7cd4a
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 116 deletions.
88 changes: 44 additions & 44 deletions edb/edgeql/compiler/casts.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def compile_cast(
) -> irast.Set:

if new_stype.is_polymorphic(ctx.env.schema) and span is not None:
# If we have no srcctx we don't know whether this is a direct cast
# If we have no span we don't know whether this is a direct cast
# or some implicit cast being processed.
raise errors.QueryError(
f'cannot cast into generic type '
Expand Down Expand Up @@ -154,11 +154,11 @@ def compile_cast(
)
):
return _cast_array_literal(
ir_set, orig_stype, new_stype, srcctx=span, ctx=ctx)
ir_set, orig_stype, new_stype, span=span, ctx=ctx)

if orig_stype.is_tuple(ctx.env.schema):
return _cast_tuple(
ir_set, orig_stype, new_stype, srcctx=span, ctx=ctx)
ir_set, orig_stype, new_stype, span=span, ctx=ctx)

if isinstance(orig_stype, s_types.Array):
if not s_types.is_type_compatible(
Expand All @@ -178,7 +178,7 @@ def compile_cast(
ir_set, el_type, orig_stype, ctx=ctx)

return _cast_array(
ir_set, orig_stype, new_stype, srcctx=span, ctx=ctx)
ir_set, orig_stype, new_stype, span=span, ctx=ctx)

if isinstance(orig_stype, s_types.Range):
if s_types.is_type_compatible(
Expand All @@ -203,7 +203,7 @@ def compile_cast(
ir_set, orig_stype, mr_stype,
cardinality_mod=cardinality_mod, ctx=ctx)
return _cast_multirange(
ir_set, mr_stype, new_stype, srcctx=span, ctx=ctx)
ir_set, mr_stype, new_stype, span=span, ctx=ctx)

else:
# The subtypes match, so this is a direct upcast from
Expand All @@ -213,7 +213,7 @@ def compile_cast(
cardinality_mod=cardinality_mod, ctx=ctx)

return _cast_range(
ir_set, orig_stype, new_stype, srcctx=span, ctx=ctx)
ir_set, orig_stype, new_stype, span=span, ctx=ctx)

if orig_stype.is_multirange():
if s_types.is_type_compatible(
Expand All @@ -225,7 +225,7 @@ def compile_cast(
return ir_set
else:
return _cast_multirange(
ir_set, orig_stype, new_stype, srcctx=span, ctx=ctx)
ir_set, orig_stype, new_stype, span=span, ctx=ctx)

if orig_stype.issubclass(ctx.env.schema, new_stype):
# The new type is a supertype of the old type,
Expand Down Expand Up @@ -295,7 +295,7 @@ def compile_cast(
orig_stype,
new_stype,
cardinality_mod,
srcctx=span,
span=span,
ctx=ctx,
)

Expand All @@ -305,7 +305,7 @@ def compile_cast(
orig_stype,
new_stype,
cardinality_mod,
srcctx=span,
span=span,
ctx=ctx,
)

Expand All @@ -315,7 +315,7 @@ def compile_cast(
orig_stype,
new_stype,
cardinality_mod,
srcctx=span,
span=span,
ctx=ctx,
)

Expand All @@ -342,7 +342,7 @@ def compile_cast(
orig_stype,
new_stype,
cardinality_mod=cardinality_mod,
srcctx=span,
span=span,
ctx=ctx,
)

Expand Down Expand Up @@ -382,19 +382,19 @@ def _compile_cast(
ir_expr: Union[irast.Set, irast.Expr],
orig_stype: s_types.Type,
new_stype: s_types.Type, *,
srcctx: Optional[parsing.Span],
span: Optional[parsing.Span],
ctx: context.ContextLevel,
cardinality_mod: Optional[qlast.CardinalityModifier]) -> irast.Set:

ir_set = setgen.ensure_set(ir_expr, ctx=ctx)
cast = _find_cast(orig_stype, new_stype, srcctx=srcctx, ctx=ctx)
cast = _find_cast(orig_stype, new_stype, span=span, ctx=ctx)

if cast is None:
raise errors.QueryError(
f'cannot cast '
f'{orig_stype.get_displayname(ctx.env.schema)!r} to '
f'{new_stype.get_displayname(ctx.env.schema)!r}',
span=srcctx or ir_set.span)
span=span or ir_set.span)

return _cast_to_ir(ir_set, cast, orig_stype, new_stype,
cardinality_mod, ctx=ctx)
Expand Down Expand Up @@ -560,7 +560,7 @@ def get_abstract(self, schema: s_schema.Schema) -> bool:
def _find_cast(
orig_stype: s_types.Type,
new_stype: s_types.Type, *,
srcctx: Optional[parsing.Span],
span: Optional[parsing.Span],
ctx: context.ContextLevel) -> Optional[s_casts.Cast]:

# Don't try to pick up casts when there is a direct subtyping
Expand Down Expand Up @@ -596,7 +596,7 @@ def _find_cast(
f'cannot unambiguously cast '
f'{orig_stype.get_displayname(ctx.env.schema)!r} '
f'to {new_stype.get_displayname(ctx.env.schema)!r}',
span=srcctx)
span=span)
else:
return None

Expand All @@ -607,7 +607,7 @@ def _cast_json_to_tuple(
new_stype: s_types.Tuple,
cardinality_mod: Optional[qlast.CardinalityModifier],
*,
srcctx: Optional[parsing.Span],
span: Optional[parsing.Span],
ctx: context.ContextLevel) -> irast.Set:

with ctx.new() as subctx:
Expand Down Expand Up @@ -652,7 +652,7 @@ def _cast_json_to_tuple(
val = compile_cast(
val, new_st,
cardinality_mod=qlast.CardinalityModifier.Required,
ctx=subctx, span=srcctx)
ctx=subctx, span=span)

elements.append(irast.TupleElement(name=new_el_name, val=val))

Expand All @@ -667,7 +667,7 @@ def _cast_tuple(
ir_set: irast.Set,
orig_stype: s_types.Type,
new_stype: s_types.Type, *,
srcctx: Optional[parsing.Span],
span: Optional[parsing.Span],
ctx: context.ContextLevel) -> irast.Set:

assert isinstance(orig_stype, s_types.Tuple)
Expand All @@ -677,7 +677,7 @@ def _cast_tuple(
# the tuple indirections.
pathctx.register_set_in_scope(ir_set, ctx=ctx)

direct_cast = _find_cast(orig_stype, new_stype, srcctx=srcctx, ctx=ctx)
direct_cast = _find_cast(orig_stype, new_stype, span=span, ctx=ctx)
orig_subtypes = dict(orig_stype.iter_subtypes(ctx.env.schema))

if direct_cast is not None:
Expand All @@ -695,7 +695,7 @@ def _cast_tuple(
)
val_type = setgen.get_set_type(val, ctx=ctx)
# Element cast
val = compile_cast(val, new_stype, ctx=ctx, span=srcctx)
val = compile_cast(val, new_stype, ctx=ctx, span=span)

elements.append(irast.TupleElement(name=n, val=val))

Expand All @@ -712,7 +712,7 @@ def _cast_tuple(
raise errors.QueryError(
f'cannot cast {orig_stype.get_displayname(ctx.env.schema)!r} '
f'to {new_stype.get_displayname(ctx.env.schema)!r}',
span=srcctx)
span=span)

assert isinstance(new_stype, s_types.Tuple)
new_subtypes = list(new_stype.iter_subtypes(ctx.env.schema))
Expand All @@ -721,7 +721,7 @@ def _cast_tuple(
f'cannot cast {orig_stype.get_displayname(ctx.env.schema)!r} '
f'to {new_stype.get_displayname(ctx.env.schema)!r}: '
f'the number of elements is not the same',
span=srcctx)
span=span)

# For tuple-to-tuple casts we generate a new tuple
# to simplify things on sqlgen side.
Expand All @@ -737,7 +737,7 @@ def _cast_tuple(
new_el_name, new_st = new_subtypes[i]
if val_type != new_st:
# Element cast
val = compile_cast(val, new_st, ctx=ctx, span=srcctx)
val = compile_cast(val, new_st, ctx=ctx, span=span)

elements.append(irast.TupleElement(name=new_el_name, val=val))

Expand All @@ -752,12 +752,12 @@ def _cast_range(
ir_set: irast.Set,
orig_stype: s_types.Type,
new_stype: s_types.Type, *,
srcctx: Optional[parsing.Span],
span: Optional[parsing.Span],
ctx: context.ContextLevel) -> irast.Set:

assert isinstance(orig_stype, s_types.Range)

direct_cast = _find_cast(orig_stype, new_stype, srcctx=srcctx, ctx=ctx)
direct_cast = _find_cast(orig_stype, new_stype, span=span, ctx=ctx)
if direct_cast is not None:
return _cast_to_ir(
ir_set, direct_cast, orig_stype, new_stype, ctx=ctx
Expand All @@ -767,18 +767,18 @@ def _cast_range(
raise errors.QueryError(
f'cannot cast {orig_stype.get_displayname(ctx.env.schema)!r} '
f'to {new_stype.get_displayname(ctx.env.schema)!r}',
span=srcctx)
span=span)
assert isinstance(new_stype, s_types.Range)
el_type = new_stype.get_subtypes(ctx.env.schema)[0]
orig_el_type = orig_stype.get_subtypes(ctx.env.schema)[0]
ql_el_type = typegen.type_to_ql_typeref(el_type, ctx=ctx)

el_cast = _find_cast(orig_el_type, el_type, srcctx=srcctx, ctx=ctx)
el_cast = _find_cast(orig_el_type, el_type, span=span, ctx=ctx)
if el_cast is None:
raise errors.QueryError(
f'cannot cast {orig_stype.get_displayname(ctx.env.schema)!r} '
f'to {new_stype.get_displayname(ctx.env.schema)!r}',
span=srcctx)
span=span)

with ctx.new() as subctx:
subctx.anchors = subctx.anchors.copy()
Expand Down Expand Up @@ -828,12 +828,12 @@ def _cast_multirange(
ir_set: irast.Set,
orig_stype: s_types.Type,
new_stype: s_types.Type, *,
srcctx: Optional[parsing.Span],
span: Optional[parsing.Span],
ctx: context.ContextLevel) -> irast.Set:

assert isinstance(orig_stype, s_types.MultiRange)

direct_cast = _find_cast(orig_stype, new_stype, srcctx=srcctx, ctx=ctx)
direct_cast = _find_cast(orig_stype, new_stype, span=span, ctx=ctx)
if direct_cast is not None:
return _cast_to_ir(
ir_set, direct_cast, orig_stype, new_stype, ctx=ctx
Expand All @@ -843,17 +843,17 @@ def _cast_multirange(
raise errors.QueryError(
f'cannot cast {orig_stype.get_displayname(ctx.env.schema)!r} '
f'to {new_stype.get_displayname(ctx.env.schema)!r}',
span=srcctx)
span=span)
assert isinstance(new_stype, s_types.MultiRange)
el_type = new_stype.get_subtypes(ctx.env.schema)[0]
orig_el_type = orig_stype.get_subtypes(ctx.env.schema)[0]

el_cast = _find_cast(orig_el_type, el_type, srcctx=srcctx, ctx=ctx)
el_cast = _find_cast(orig_el_type, el_type, span=span, ctx=ctx)
if el_cast is None:
raise errors.QueryError(
f'cannot cast {orig_stype.get_displayname(ctx.env.schema)!r} '
f'to {new_stype.get_displayname(ctx.env.schema)!r}',
span=srcctx)
span=span)

ctx.env.schema, new_range_type = s_types.Range.from_subtypes(
ctx.env.schema, [el_type])
Expand Down Expand Up @@ -897,7 +897,7 @@ def _cast_json_to_range(
new_stype: s_types.Range,
cardinality_mod: Optional[qlast.CardinalityModifier],
*,
srcctx: Optional[parsing.Span],
span: Optional[parsing.Span],
ctx: context.ContextLevel) -> irast.Set:

with ctx.new() as subctx:
Expand Down Expand Up @@ -1005,7 +1005,7 @@ def _cast_json_to_multirange(
new_stype: s_types.MultiRange,
cardinality_mod: Optional[qlast.CardinalityModifier],
*,
srcctx: Optional[parsing.Span],
span: Optional[parsing.Span],
ctx: context.ContextLevel) -> irast.Set:

ctx.env.schema, new_range_type = s_types.Range.from_subtypes(
Expand Down Expand Up @@ -1054,19 +1054,19 @@ def _cast_array(
ir_set: irast.Set,
orig_stype: s_types.Type,
new_stype: s_types.Type, *,
srcctx: Optional[parsing.Span],
span: Optional[parsing.Span],
ctx: context.ContextLevel) -> irast.Set:

assert isinstance(orig_stype, s_types.Array)

direct_cast = _find_cast(orig_stype, new_stype, srcctx=srcctx, ctx=ctx)
direct_cast = _find_cast(orig_stype, new_stype, span=span, ctx=ctx)

if direct_cast is None:
if not new_stype.is_array():
raise errors.QueryError(
f'cannot cast {orig_stype.get_displayname(ctx.env.schema)!r} '
f'to {new_stype.get_displayname(ctx.env.schema)!r}',
span=srcctx)
span=span)
assert isinstance(new_stype, s_types.Array)
el_type = new_stype.get_subtypes(ctx.env.schema)[0]
elif new_stype.is_json(ctx.env.schema):
Expand All @@ -1079,7 +1079,7 @@ def _cast_array(

orig_el_type = orig_stype.get_subtypes(ctx.env.schema)[0]

el_cast = _find_cast(orig_el_type, el_type, srcctx=srcctx, ctx=ctx)
el_cast = _find_cast(orig_el_type, el_type, span=span, ctx=ctx)

if el_cast is not None and el_cast.get_from_cast(ctx.env.schema):
# Simple cast
Expand Down Expand Up @@ -1155,21 +1155,21 @@ def _cast_array_literal(
ir_set: irast.Set,
orig_stype: s_types.Type,
new_stype: s_types.Type, *,
srcctx: Optional[parsing.Span],
span: Optional[parsing.Span],
ctx: context.ContextLevel) -> irast.Set:

assert isinstance(ir_set.expr, irast.Array)

orig_typeref = typegen.type_to_typeref(orig_stype, env=ctx.env)
new_typeref = typegen.type_to_typeref(new_stype, env=ctx.env)
direct_cast = _find_cast(orig_stype, new_stype, srcctx=srcctx, ctx=ctx)
direct_cast = _find_cast(orig_stype, new_stype, span=span, ctx=ctx)

if direct_cast is None:
if not new_stype.is_array():
raise errors.QueryError(
f'cannot cast {orig_stype.get_displayname(ctx.env.schema)!r} '
f'to {new_stype.get_displayname(ctx.env.schema)!r}',
span=srcctx) from None
span=span) from None
assert isinstance(new_stype, s_types.Array)
el_type = new_stype.get_subtypes(ctx.env.schema)[0]
intermediate_stype = orig_stype
Expand All @@ -1185,7 +1185,7 @@ def _cast_array_literal(
for el in ir_set.expr.elements:
el = compile_cast(el, el_type,
cardinality_mod=qlast.CardinalityModifier.Required,
ctx=ctx, span=srcctx)
ctx=ctx, span=span)
casted_els.append(el)

new_array = setgen.ensure_set(
Expand Down
4 changes: 2 additions & 2 deletions edb/edgeql/compiler/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ def compile_TypeCast(
def _infer_type_introspection(
typeref: irast.TypeRef,
env: context.Environment,
srcctx: Optional[parsing.Span]=None,
span: Optional[parsing.Span]=None,
) -> s_types.Type:
if irtyputils.is_scalar(typeref):
return cast(s_objtypes.ObjectType,
Expand All @@ -792,7 +792,7 @@ def _infer_type_introspection(
env.schema.get('schema::MultiRange'))
else:
raise errors.QueryError(
'unexpected type in INTROSPECT', span=srcctx)
'unexpected type in INTROSPECT', span=span)


@dispatch.compile.register(qlast.Introspect)
Expand Down
2 changes: 1 addition & 1 deletion edb/edgeql/compiler/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ def get_globals(
and not ctx.env.options.json_parameters
):
glob_set = setgen.get_globals_as_json(
tuple(globs), ctx=ctx, srcctx=expr.span)
tuple(globs), ctx=ctx, span=expr.span)
else:
if ctx.env.options.func_params is not None:
# Make sure that we properly track the globals we use in functions
Expand Down
Loading

0 comments on commit 1a7cd4a

Please sign in to comment.