Stream: compiler development

Topic: everything implements inspect


view this post on Zulip Brendan Hansknecht (Dec 11 2024 at 19:30):

Is there an easy way for me to tell the compiler that everything implements inspect. I want to add a debug statement inDict code, but can't easily do so due to the compiler thinking that k and v don't implement inspect. Clearly k and v have to implement inspect cause everything in roc implements inspect. It would be nice to just stop all type checking when it comes to inspect and never have to write where x implements Inspect.

view this post on Zulip Sam Mohr (Dec 11 2024 at 19:34):

I don't know if it would work, but you could try making a Vis a : a where a implements Inspect type alias and wrap stuff in it

view this post on Zulip Sam Mohr (Dec 11 2024 at 19:34):

You can also write stuff using dbg, and add type annotations afterwards

view this post on Zulip Sam Mohr (Dec 11 2024 at 19:34):

Otherwise, not a thing AFAICT

view this post on Zulip Richard Feldman (Dec 11 2024 at 19:35):

we discussed this originally but if I remember right @Ayaz Hafiz preferred having the constraint. I don't remember the exact discission anymore :big_smile:

view this post on Zulip Brendan Hansknecht (Dec 11 2024 at 19:40):

This issue is that there are a ton of function in dict. So either I need to add the constraint or comment out the type for every single function (turns out I also need to comment out all the types in set for this to work)

view this post on Zulip Brendan Hansknecht (Dec 11 2024 at 19:41):

I can't do it to a single function cause they are all linked by dict

view this post on Zulip Brendan Hansknecht (Dec 11 2024 at 19:41):

And by interconnected tests and calls

view this post on Zulip Brendan Hansknecht (Dec 11 2024 at 19:41):

So I would really like to remove the constraint in general. It is a pain in practice and would be worse for larger libraries

view this post on Zulip Brendan Hansknecht (Dec 11 2024 at 19:45):

Being able to drop in a dbg without changing an entire call stack is pretty fundamental

view this post on Zulip Ayaz Hafiz (Dec 11 2024 at 19:50):

yes, it should be sufficient to add the exception to the Rigid* cases here
https://github.com/roc-lang/roc/blob/0be7b3f7501501f6ced1648f9c2644560d338505/crates/compiler/solve/src/ability.rs#L681-L703

view this post on Zulip Ayaz Hafiz (Dec 11 2024 at 19:50):

Note that you'll need to promote the var to include the ability in the same way is done for FlexVar

view this post on Zulip Ayaz Hafiz (Dec 11 2024 at 19:50):

otherwise the derived impl will never be created (I think)


Last updated: Jul 06 2025 at 12:14 UTC