Current section
Files
Jump to
Current section
Files
src/graded@internal@types.erl
-module(graded@internal@types).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/graded/internal/types.gleam").
-export([is_upper_initial/1, is_subset/2, union/2, empty/0, from_labels/1, has_variables/1]).
-export_type([qualified_name/0, effect_set/0, effect_term/0, annotation_kind/0, param_bound/0, effect_annotation/0, returns_annotation/0, type_field_annotation/0, type_field_effect/0, external_target/0, external_annotation/0, graded_line/0, graded_file/0, resolved_call/0, argument_value/0, return_provenance/0, field_provenance/0, call_argument/0, local_call/0, field_call/0, factory_signature/0, direct_operator_call/0, direct_closure_call/0, direct_pipe_op/0, violation/0, warning/0, check_result/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-type qualified_name() :: {qualified_name, binary(), binary()}.
-type effect_set() :: wildcard |
{specific, gleam@set:set(binary())} |
{polymorphic, gleam@set:set(binary()), gleam@set:set(binary())}.
-type effect_term() :: {t_labels, gleam@set:set(binary())} |
t_top |
{t_var, binary()} |
{t_app, effect_term(), effect_term()} |
{t_abs, binary(), effect_term()} |
{t_union, list(effect_term())}.
-type annotation_kind() :: effects | check.
-type param_bound() :: {param_bound, binary(), effect_term()}.
-type effect_annotation() :: {effect_annotation,
annotation_kind(),
binary(),
list(param_bound()),
effect_term()}.
-type returns_annotation() :: {returns_annotation, binary(), effect_term()}.
-type type_field_annotation() :: {type_field_annotation,
gleam@option:option(binary()),
binary(),
binary(),
effect_term()}.
-type type_field_effect() :: {type_field_effect,
effect_term(),
list(param_bound()),
gleam@option:option(qualified_name())}.
-type external_target() :: module_external | {function_external, binary()}.
-type external_annotation() :: {external_annotation,
binary(),
external_target(),
effect_set()}.
-type graded_line() :: {annotation_line, effect_annotation()} |
{type_field_line, type_field_annotation()} |
{external_line, external_annotation()} |
{returns_line, returns_annotation()} |
{comment_line, binary()} |
blank_line.
-type graded_file() :: {graded_file, list(graded_line())}.
-type resolved_call() :: {resolved_call, qualified_name(), glance:span()}.
-type argument_value() :: {function_ref, qualified_name()} |
{local_ref, binary()} |
constructor_ref |
{closure,
list(binary()),
list({binary(), argument_value()}),
list(glance:statement())} |
{choice, list(argument_value())} |
{returned_operator, qualified_name(), list(call_argument())} |
{receiver_path, binary()} |
{constructed, gleam@dict:dict(binary(), argument_value())} |
{call_result, qualified_name(), list(call_argument())} |
other_expression.
-type return_provenance() :: {passthrough, integer()} |
{path, integer(), binary()} |
{build, gleam@dict:dict(binary(), field_provenance())} |
{join, list(return_provenance())} |
opaque.
-type field_provenance() :: {field_param, integer()} |
{field_path, integer(), binary()} |
field_opaque.
-type call_argument() :: {call_argument,
integer(),
gleam@option:option(binary()),
argument_value()}.
-type local_call() :: {local_call, binary(), glance:span()}.
-type field_call() :: {field_call,
binary(),
binary(),
glance:span(),
glance:span()}.
-type factory_signature() :: {factory_signature,
gleam@dict:dict(binary(), integer()),
gleam@dict:dict(binary(), integer())}.
-type direct_operator_call() :: {direct_operator_call,
qualified_name(),
list(call_argument()),
glance:span()}.
-type direct_closure_call() :: {direct_closure_call,
argument_value(),
glance:span()}.
-type direct_pipe_op() :: {direct_pipe_op, argument_value(), glance:span()}.
-type violation() :: {violation,
binary(),
qualified_name(),
glance:span(),
effect_set(),
effect_set()}.
-type warning() :: {untracked_effect_warning,
binary(),
qualified_name(),
glance:span(),
effect_set()} |
{unmatched_field_bound_warning, binary(), binary(), boolean()} |
{unmatched_param_bound_warning, binary(), binary()} |
{unmatched_check_warning, binary()} |
{unmatched_type_field_warning, binary()}.
-type check_result() :: {check_result,
binary(),
list(violation()),
list(warning())}.
-file("src/graded/internal/types.gleam", 22).
?DOC(false).
-spec is_upper_initial(binary()) -> boolean().
is_upper_initial(Name) ->
case gleam@string:first(Name) of
{ok, First} ->
(First =:= string:uppercase(First)) andalso (First /= string:lowercase(
First
));
{error, nil} ->
false
end.
-file("src/graded/internal/types.gleam", 59).
?DOC(false).
-spec is_subset(effect_set(), effect_set()) -> boolean().
is_subset(Actual, Declared) ->
case {Declared, Actual} of
{wildcard, _} ->
true;
{_, wildcard} ->
false;
{{polymorphic, D_labels, _}, {specific, A}} ->
gleam@set:is_subset(A, D_labels);
{{polymorphic, D_labels@1, D_vars}, {polymorphic, A_labels, A_vars}} ->
gleam@set:is_subset(A_labels, D_labels@1) andalso gleam@set:is_subset(
A_vars,
D_vars
);
{{specific, D}, {specific, A@1}} ->
gleam@set:is_subset(A@1, D);
{{specific, _}, {polymorphic, _, _}} ->
false
end.
-file("src/graded/internal/types.gleam", 75).
?DOC(false).
-spec union(effect_set(), effect_set()) -> effect_set().
union(A, B) ->
case {A, B} of
{wildcard, _} ->
wildcard;
{_, wildcard} ->
wildcard;
{{specific, X}, {specific, Y}} ->
{specific, gleam@set:union(X, Y)};
{{polymorphic, L1, V1}, {polymorphic, L2, V2}} ->
{polymorphic, gleam@set:union(L1, L2), gleam@set:union(V1, V2)};
{{specific, X@1}, {polymorphic, L, V}} ->
{polymorphic, gleam@set:union(X@1, L), V};
{{polymorphic, L@1, V@1}, {specific, X@2}} ->
{polymorphic, gleam@set:union(L@1, X@2), V@1}
end.
-file("src/graded/internal/types.gleam", 88).
?DOC(false).
-spec empty() -> effect_set().
empty() ->
{specific, gleam@set:new()}.
-file("src/graded/internal/types.gleam", 93).
?DOC(false).
-spec from_labels(list(binary())) -> effect_set().
from_labels(Labels) ->
{specific, gleam@set:from_list(Labels)}.
-file("src/graded/internal/types.gleam", 98).
?DOC(false).
-spec has_variables(effect_set()) -> boolean().
has_variables(Effect_set) ->
case Effect_set of
{polymorphic, _, Variables} ->
not gleam@set:is_empty(Variables);
_ ->
false
end.