Repository: JuliaLang/julia
File: JuliaLowering/src/linear_ir.jl (Julia)

Code before:
            kind(rhs) in KSet"new splatnew cfunction isdefined call foreigncall gc_preserve_begin foreigncall new_opaque_closure")
end

function check_no_local_bindings(ctx, ex, msg)
    contains_nonglobal_binding = contains_unquoted(ex) do e
        kind(e) == K"BindingId" && get_binding(ctx, e).kind !== :global
    end
    if contains_nonglobal_binding
        throw(LoweringError(ex, msg))
    end
end

# evaluate the arguments of a call, creating temporary locations as needed
function compile_args(ctx, args)
    # First check if all the arguments are simple (and therefore side-effect free).
    # Otherwise, we need to use ssa values for all arguments to ensure proper
    # left-to-right evaluation semantics.
    all_simple = all(a->is_simple_arg(ctx, a), args)
    args_out = SyntaxList(ctx)
    for arg in args
        arg_val = compile(ctx, arg, true, false)
        if isnothing(arg_val)
            # arguments that don't return a value, e.g. `f(return)`
            push!(args_out, nothing_(ctx, arg))
        elseif (all_simple || is_const_read_arg(ctx, arg_val)) &&
            is_valid_body_ir_argument(ctx, arg_val)
            push!(args_out, arg_val)
        else
            push!(args_out, emit_assign_tmp(ctx, arg_val))
        end
    end
    return args_out
end

function emit(ctx::LinearIRContext, ex)
    push!(ctx.code, ex)
    return ex
end

# Emit computation of ex, assigning the result to an ssavar and returning that
function emit_assign_tmp(ctx::LinearIRContext, ex, name="tmp")
    tmp = ssavar(ctx, ex, name)
    emit(ctx, @ast ctx ex [K"=" tmp ex])
    return tmp
end

function compile_pop_exception(ctx, srcref, src_tokens, dest_tokens)
    # It's valid to leave the context of src_tokens for the context of
    # dest_tokens when src_tokens is the same or nested within dest_tokens.
    # It's enough to check the token on the top of the dest stack.
    n = length(dest_tokens)

Review comment (suggestion):
```suggestion
        elseif ((all_simple || is_const_read_arg(ctx, arg_val)) &&
                is_valid_body_ir_argument(ctx, arg_val))
```

Aligning to the inner block is confusing IMO.

Although I actually don't think we have a great style for breaking conditions on multiple lines like this.

Code after:
            kind(rhs) in KSet"new splatnew cfunction isdefined call foreigncall gc_preserve_begin foreigncall new_opaque_closure")
end

function check_no_local_bindings(ctx, ex, msg)
    contains_nonglobal_binding = contains_unquoted(ex) do e
        kind(e) == K"BindingId" && get_binding(ctx, e).kind !== :global
    end
    if contains_nonglobal_binding
        throw(LoweringError(ex, msg))
    end
end

# evaluate the arguments of a call, creating temporary locations as needed
function compile_args(ctx, args)
    # First check if all the arguments are simple (and therefore side-effect free).
    # Otherwise, we need to use ssa values for all arguments to ensure proper
    # left-to-right evaluation semantics.
    all_simple = all(a->is_simple_arg(ctx, a), args)
    args_out = SyntaxList(ctx)
    for arg in args
        arg_val = compile(ctx, arg, true, false)
        if isnothing(arg_val)
            # arguments that don't return a value, e.g. `f(return)`
            push!(args_out, nothing_(ctx, arg))
        elseif ((all_simple || is_const_read_arg(ctx, arg_val)) &&
                is_valid_body_ir_argument(ctx, arg_val))
            push!(args_out, arg_val)
        else
            push!(args_out, emit_assign_tmp(ctx, arg_val))
        end
    end
    return args_out
end

function emit(ctx::LinearIRContext, ex)
    push!(ctx.code, ex)
    return ex
end

# Emit computation of ex, assigning the result to an ssavar and returning that
function emit_assign_tmp(ctx::LinearIRContext, ex, name="tmp")
    tmp = ssavar(ctx, ex, name)
    emit(ctx, @ast ctx ex [K"=" tmp ex])
    return tmp
end

function compile_pop_exception(ctx, srcref, src_tokens, dest_tokens)
    # It's valid to leave the context of src_tokens for the context of
    # dest_tokens when src_tokens is the same or nested within dest_tokens.
    # It's enough to check the token on the top of the dest stack.
    n = length(dest_tokens)