mudasobwa
Creator of Cure
I need to get specs for the function which may be located in the external module, like Process or :math.
Dialyzer source code does roughly this:
{:ok, core} = Process |> :code.which() |> :dialyzer_utils.get_core_from_beam([])
{:ok, rec_dict} = :dialyzer_utils.get_record_and_type_info(core)
:dialyzer_utils.get_spec_info(Process, core, rec_dict)
and it kinda works. Is there any better documented and/or less hacky way to get the spec? Is there any reason specs are not there in beam chunks? Should not Code.fetch_docs/2 (or maybe another not yet existing Code.fetch_specs/2) retrieve specs? What am I missing?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
D4no0
Should they be there? If you think about it,
@specis nothing more than a specialized module attribute.mudasobwa
Same as
@docis, btw.Specs are there in generated documentation for a reason.
LostKobrakai
Code.fetch_docsis about fetching the “Docs” chunk of a beam file (as proposed initially here: Eep 0048 - Erlang/OTP), which specifically includes only documentation text. There is no chunk for types though. E.g. ex_doc seems to parse them from the abstract code provided in the debug_info (“Dbgi”) chunk. Dialyzer also fetches the what seems like core erlang code from the debug_info chunk. I’m wondering if there’s also some history around where and how that data is fetched (seems like there is). So the answer might be that there’s multiple ways to skin the cat and nobody bothered normalizing one of them within the elixir core codebase.mudasobwa
For the record, I used this code to fetch the spec as a string.
The first naïve attempt was to use
:erl_types.t_form_to_string/1from:dialyzerand it worked to some extent, returning somewhat alongsideI struggled to find an elixir helper to parse this into an elixir format and reached for
Code.Typespec.spec_to_quoted/2which kinda worked but not without glitches.The type it returned for
Process.send_after/4did not recornize thewhen option: {:abs, boolean()}guard and gave mewhen option: varwhich resulted in compile error. I will probably file a bug to the core.Another glitch I found is function spec syntax. While
(binary() -> boolean())is translated to the expected erlang~c"fun((binary()) -> boolean())", the any-arity notation lacks parentheses around the fun as~c"fun(...) -> integer()". That I am not sure whether it’s expected or not.Anyway.
LostKobrakai
Seems like ex_doc also reaches into the private API of
Code.Typespec. Sounds like there could be an effort made to lift functionality into proper public APIs.mudasobwa
I am positive that specs should be optionally added to “Docs” chunks.
Now when Erlang uses
ex_docto generate docs, at least two different toolings reach for two different private APIs to retrieve what is de facto a part of docs.Or, alternatively, the new “Spec” chunk should be added to unify the representation of specs in the chunks.