Skip to content

Commit 4787116

Browse files
committed
Pass args as explicit argument to Apply.remote
1 parent 4f0b0d9 commit 4787116

File tree

3 files changed

+23
-37
lines changed

3 files changed

+23
-37
lines changed

lib/elixir/lib/module/types/apply.ex

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,11 @@ defmodule Module.Types.Apply do
276276
@doc """
277277
Applies a function in a given module.
278278
"""
279-
def remote(_module, _fun, _args_types, _expr, %{mode: :traversal}, context) do
279+
def remote(_module, _fun, _args, _args_types, _expr, %{mode: :traversal}, context) do
280280
{dynamic(), context}
281281
end
282282

283-
def remote(:erlang, :element, [_, tuple], {_, meta, [index, _]} = expr, stack, context)
283+
def remote(:erlang, :element, [index, _], [_, tuple], expr, stack, context)
284284
when is_integer(index) do
285285
case tuple_fetch(tuple, index - 1) do
286286
{_optional?, value_type} ->
@@ -294,18 +294,11 @@ defmodule Module.Types.Apply do
294294
mfac = mfac(expr, :erlang, :element, 2)
295295

296296
{error_type(),
297-
error({:badindex, mfac, expr, tuple, index - 1, context}, meta, stack, context)}
297+
error({:badindex, mfac, expr, tuple, index - 1, context}, elem(expr, 1), stack, context)}
298298
end
299299
end
300300

301-
def remote(
302-
:erlang,
303-
:insert_element,
304-
[_, tuple, value],
305-
{_, meta, [index, _, _]} = expr,
306-
stack,
307-
context
308-
)
301+
def remote(:erlang, :insert_element, [index, _, _], [_, tuple, value], expr, stack, context)
309302
when is_integer(index) do
310303
case tuple_insert_at(tuple, index - 1, value) do
311304
value_type when is_descr(value_type) ->
@@ -321,11 +314,11 @@ defmodule Module.Types.Apply do
321314
mfac = mfac(expr, :erlang, :insert_element, 3)
322315

323316
{error_type(),
324-
error({:badindex, mfac, expr, tuple, index - 2, context}, meta, stack, context)}
317+
error({:badindex, mfac, expr, tuple, index - 2, context}, elem(expr, 1), stack, context)}
325318
end
326319
end
327320

328-
def remote(:erlang, :delete_element, [_, tuple], {_, meta, [index, _]} = expr, stack, context)
321+
def remote(:erlang, :delete_element, [index, _], [_, tuple], expr, stack, context)
329322
when is_integer(index) do
330323
case tuple_delete_at(tuple, index - 1) do
331324
value_type when is_descr(value_type) ->
@@ -341,16 +334,16 @@ defmodule Module.Types.Apply do
341334
mfac = mfac(expr, :erlang, :delete_element, 2)
342335

343336
{error_type(),
344-
error({:badindex, mfac, expr, tuple, index - 1, context}, meta, stack, context)}
337+
error({:badindex, mfac, expr, tuple, index - 1, context}, elem(expr, 1), stack, context)}
345338
end
346339
end
347340

348-
def remote(:erlang, :make_tuple, [_, elem], {_, _meta, [size, _]}, _stack, context)
341+
def remote(:erlang, :make_tuple, [size, _], [_, elem], _expr, _stack, context)
349342
when is_integer(size) and size >= 0 do
350343
{tuple(List.duplicate(elem, size)), context}
351344
end
352345

353-
def remote(:erlang, :hd, [list], expr, stack, context) do
346+
def remote(:erlang, :hd, _args, [list], expr, stack, context) do
354347
case list_hd(list) do
355348
{_, value_type} ->
356349
{value_type, context}
@@ -360,7 +353,7 @@ defmodule Module.Types.Apply do
360353
end
361354
end
362355

363-
def remote(:erlang, :tl, [list], expr, stack, context) do
356+
def remote(:erlang, :tl, _args, [list], expr, stack, context) do
364357
case list_tl(list) do
365358
{_, value_type} ->
366359
{value_type, context}
@@ -370,7 +363,7 @@ defmodule Module.Types.Apply do
370363
end
371364
end
372365

373-
def remote(:erlang, name, [left, right] = args_types, expr, stack, context)
366+
def remote(:erlang, name, _args, [left, right], expr, stack, context)
374367
when name in [:>=, :"=<", :>, :<, :min, :max] do
375368
context =
376369
cond do
@@ -396,18 +389,11 @@ defmodule Module.Types.Apply do
396389
if name in [:min, :max] do
397390
{union(left, right), context}
398391
else
399-
{return(boolean(), args_types, stack), context}
392+
{return(boolean(), [left, right], stack), context}
400393
end
401394
end
402395

403-
def remote(
404-
:erlang,
405-
name,
406-
[left, right] = args_types,
407-
{_, _, args} = expr,
408-
stack,
409-
context
410-
)
396+
def remote(:erlang, name, args, [left, right] = args_types, expr, stack, context)
411397
when name in [:==, :"/=", :"=:=", :"=/="] do
412398
context =
413399
cond do
@@ -429,13 +415,13 @@ defmodule Module.Types.Apply do
429415
{return(boolean(), args_types, stack), context}
430416
end
431417

432-
def remote(mod, fun, args_types, expr, stack, context) do
418+
def remote(mod, fun, args, args_types, expr, stack, context) do
433419
arity = length(args_types)
434420

435421
case :elixir_rewrite.inline(mod, fun, arity) do
436422
{new_mod, new_fun} ->
437423
expr = inline_meta(expr, mod, fun)
438-
remote(new_mod, new_fun, args_types, expr, stack, context)
424+
remote(new_mod, new_fun, args, args_types, expr, stack, context)
439425

440426
false ->
441427
{info, context} = signature(mod, fun, arity, elem(expr, 1), stack, context)

lib/elixir/lib/module/types/expr.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,15 @@ defmodule Module.Types.Expr do
383383
Of.map_fetch(expr, type, key_or_fun, stack, context)
384384
else
385385
{mods, context} = Of.modules(type, key_or_fun, 0, [:dot], expr, meta, stack, context)
386-
apply_many(mods, key_or_fun, [], expr, stack, context)
386+
apply_many(mods, key_or_fun, [], [], expr, stack, context)
387387
end
388388
end
389389

390390
def of_expr({{:., _, [remote, name]}, meta, args} = expr, stack, context) do
391391
{remote_type, context} = of_expr(remote, stack, context)
392392
{args_types, context} = Enum.map_reduce(args, context, &of_expr(&1, stack, &2))
393393
{mods, context} = Of.modules(remote_type, name, length(args), expr, meta, stack, context)
394-
apply_many(mods, name, args_types, expr, stack, context)
394+
apply_many(mods, name, args, args_types, expr, stack, context)
395395
end
396396

397397
# TODO: &Foo.bar/1
@@ -540,18 +540,18 @@ defmodule Module.Types.Expr do
540540

541541
## General helpers
542542

543-
defp apply_many([], function, args_types, expr, stack, context) do
543+
defp apply_many([], function, _args, args_types, expr, stack, context) do
544544
Apply.remote(function, args_types, expr, stack, context)
545545
end
546546

547-
defp apply_many([mod], function, args_types, expr, stack, context) do
548-
Apply.remote(mod, function, args_types, expr, stack, context)
547+
defp apply_many([mod], function, args, args_types, expr, stack, context) do
548+
Apply.remote(mod, function, args, args_types, expr, stack, context)
549549
end
550550

551-
defp apply_many(mods, function, args_types, expr, stack, context) do
551+
defp apply_many(mods, function, args, args_types, expr, stack, context) do
552552
{returns, context} =
553553
Enum.map_reduce(mods, context, fn mod, context ->
554-
Apply.remote(mod, function, args_types, expr, stack, context)
554+
Apply.remote(mod, function, args, args_types, expr, stack, context)
555555
end)
556556

557557
{Enum.reduce(returns, &union/2), context}

lib/elixir/lib/module/types/pattern.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ defmodule Module.Types.Pattern do
718718
{args_type, context} =
719719
Enum.map_reduce(args, context, &of_guard(&1, dynamic(), expr, stack, &2))
720720

721-
Module.Types.Apply.remote(:erlang, function, args_type, call, stack, context)
721+
Module.Types.Apply.remote(:erlang, function, args, args_type, call, stack, context)
722722
end
723723

724724
# var

0 commit comments

Comments
 (0)