Open rfratto opened 2 years ago
This issue has not had any activity in the past 30 days, so the needs-attention
label has been added to it.
If the opened issue is a bug, check to see if a newer release fixed your issue. If it is no longer relevant, please feel free to close this issue.
The needs-attention
label signals to maintainers that something has fallen through the cracks. No action is needed by you; your issue will be kept open and you do not have to respond to this comment. The label will be removed the next time this job runs if there is new activity.
Thank you for your contributions!
Today, a Go value maps to a Alloy syntax capsule when any of the following are true:
interface{}
These rules were intended to make capsules feel "magical," have historically caused bugs (#2361, grafana/agent#2362) and are generally confusing to remember (I even had to look up the rules again just when writing this). The biggest issue with capsules is that capsule information can get lost if a type is casted to an
interface{}
, which can happen in many situations, including storing a capsule value in a*vm.Scope
as a variable.About a month ago I suggested changing these rules, and this issue is a more formal proposal of that suggestion.
Proposal
I propose that:
This proposal only affects developers building components on top of Alloy. Users of Alloy are not impacted.
The new API looks like this:
Example usage
Using the new proposed API above, the exports for
prometheus.remote_write
change to:The arguments type for types which accept capsules would also change:
Discussion
This proposal does come at a cost: developing against Alloy becomes slightly more tedious for capsule values, as it removes the magic introduced in the initial implementation.
However, the new rules are much easier to remember, and the new API should offload most of the tedium introduced by the new rules. This proposal even potentially makes Alloy easier to understand for developers reading the code, as it now must be explicit when something is being encapsulated.