serokell / universum

:milky_way: Prelude written in @Serokell
MIT License
174 stars 26 forks source link

[#222] `CallStack` attach #261

Open DK318 opened 2 years ago

DK318 commented 2 years ago

Description

Problem

Functions from Universum.Unsafe don't carry CallStack. Sometimes it is hard to debug when you don't have stack trace.

Solution

Attached CallStack to all functions from Universum.Unsafe by copying them from base and replacing errorWithoutStackTrace with error function.

Related issues(s)

✓ Checklist for your Pull Request

Ideally a PR has all of the checkmarks set.

If something in this list is irrelevant to your PR, you should still set this checkmark indicating that you are sure it is dealt with (be that by irrelevance).

Related changes (conditional)

Stylistic guide (mandatory)

DK318 commented 2 years ago

I've looked through Prelude sources and figured out that all these unsafe functions use errorWithoutStackTrace

gromakovsky commented 2 years ago

Ah, ok, I get it. Well, looks sad, it's something that wasn't considered in the issue description, I mean the fact of copy-paste wasn't mentioned in "Cons".

dcastro commented 2 years ago

I mean the fact of copy-paste wasn't mentioned in "Cons".

That's a good point :/ Would you still say this is worth pursuing, despite the cons? Or do you think we shouldn't do this?

gromakovsky commented 2 years ago

I personally don't remember much suffering from lack of CallStack in Unsafe functions. And I quite heavily don't like copy-paste. So I would refraing from making this change, but it's highly opinionated and if there are enough people who need call stacks I won't reject it. cc @Martoon-00 maybe

Martoon-00 commented 2 years ago

Fair, I didn't mention that this issue will require copy-paste.

And the fact that we have to copy stuff like INLINE pragmas is pretty annoying (fortunately not the rewrite rules, but who knows, maybe they will appear in the future :see_no_evil:).


Though nevertheless, I think this change is important. Not having a callstack seems innocent until the moment when it actually fires, and then it would be extremely hard to debug given a large project. Imagine, I used Unsafe.head 10 times in different parts of the project - that would be sad to investigate.

Coming to think about it, I would consider 3 alternatives:

  1. Add callstacks
  2. Don't have callstacks, leave everything as-is
  3. Remove the Unsafe module altogether

And 2nd option seems the worst here, because having an unsafe function without a callstack, if I understand it correctly, can be treated as an anti-pattern. We better enforce the user to use a safe function + explicit fromMaybe (error ...) (3rd option) than allow using Unsafe.head in its current form.