fireproofsocks
I often get into trouble with Elixir and compile-time values. I’m wondering if there are any IDE plugins that highlight areas of code that are evaluated at compile time. E.g. module attributes and macros. Sometimes I’m not always 100% sure what is a macro and what might be some interesting new feature that some clever developer has deployed. So it would be a helpful reminder that some stuff is evaluated at compile time, and that may affect how I structure certain code.
Trending in Discussions
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Hi there! :wave:
@frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
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
- #ai
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Nicd
The problem is that until you do compile, you can’t know which part will be evaluated, since the compilation stage runs any code at top/module level and that code can do anything.
NobbZ
As a rule of thumb, if its not within a
def(p) or if is a macro then it is evaluated at compile time.LostKobrakai
The only code, which goes into the compiled .beam files are functions for modules. So runtime code must be code of a function. Therefore @NobbZ’s rule of thumb works quite well.
It get’s tricky for macros, as when using macros you cannot be sure if the AST input to the macro and the AST generated by the macro is actually used at runtime or not without looking at both the macro definition and the place it’s used in.
Within
defmacroonly places wrapped byquote doare the ones in question. Everything else is run at compile time.NobbZ
But only if that macro gets called… Thats why I said “macros get evaluated at compile time”.
fireproofsocks
How exactly are calls to
System.get_env/2handled? Are ENV vars read at compile time? Or does this change depending on where exactly the calls toSystem.get_env/2get called?Here’s an example from a recent Phoenix project that uses a simple “shared secret” authentication for some routes:
The corresponding config reads from an ENV variable:
Because
plugis a macro, that gets evaluated at compile time… but does that mean that it evaluates all the way down through the config down to the ENV value at compilation time? Or does it store more of a reference like{MyApp.MyModule, :function, [1, "foo"]}?NobbZ
System.get_envis a function so it gets called when it’s called.If this is compiletime or runtime depends on the context.
fireproofsocks
Thanks, but that doesn’t entirely answer my question. How “deep” does the evaluation go when a function is called? In my case, when the
plugmacro referencesApplication.get_envwhich in turn referencesSystem.get_env, does that mean that the plug gets passed the ENV that was present at compile time?NobbZ
The config is evaluated at
mixtime. If you don’t deal with releases, you can consider it as “boottime” of your application, if you run releases, it’s compiletime. With the notable exception ofconfig/release.exswhich is only evaluated at boottime of the release.Though as plug is a macro, it takes its arguments as AST.
The macro decides when those are evaluated.
A good macro does contain this in the documentation.
If it’s not noted in the documentation, I’d expect everything not in a
do/endto be compiletime evaluated.