-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify language and add notes what types of allocation patterns are acceptable. #2
base: main
Are you sure you want to change the base?
Conversation
|
||
Enormous troubles and inefficiencies stem from general purpose library code allocating memory as the library sees fit. This makes the library code far less usable. Memory allocation strategies should be decided upon by the user of the library, not the library. | ||
|
||
The easiest way to achieve this is to design the library to not use memory allocation at all. For example, std.path assembles paths from parts without doing allocations - it returns Voldemort ranges that the user can then use to emit the result into a buffer of the user's choosing. | ||
|
||
Library routines may allocate memory internally, but not in a way that affects the user. | ||
In cases where allocation is necessary, Library routines may allocate memory internally, in such a way that it does not effect the user. Additionally, allocation patterns that use internal allocations, such as Dependency Injection, may be used to allocate. Note that this may require compiler support to fully implement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/effect/affect/.
What requires compiler support?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am just leaving the door open to potential future cases.
|
||
Exceptions are inefficient and use the GC. Of course, they cannot be used in `nothrow` code. Examine each use of an Exception to see if it can be designed out of existence, like the Replacement Character method above. Design the return value such that an error is not necessary - for example, a string search function can return an empty string if not found rather than throw an Exception. | ||
Investigate the use of Option types for error returns. | ||
|
||
Investigate the use of "Option" or "Sum" types for error returns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this is that bubbling up errors becomes a pain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, value type exceptions aka zero cost exceptions would be the option here as it'll bubble up.
Waiting on sumtypes before continuing that DIP work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this is that bubbling up errors becomes a pain.
How about polymorphic variants? That's a good idea from OCaml. See: https://keleshev.com/composable-error-handling-in-ocaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to wait for built-in sum types to address this. Ideally, any solution we come up with for the error-bubbling problem would apply equally well to built-in types and library types (like how Rust's ?
operator can be overloaded by implementing the Try
trait).
Value type exceptions like I've designed them will automatically combine
between different sets. That is the only advantage I can see from that
link.
…On Sat, Feb 3, 2024, 12:15 Mengu Kagan ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In Design.md
<#2 (comment)>
:
>
Exceptions are inefficient and use the GC. Of course, they cannot be used in `nothrow` code. Examine each use of an Exception to see if it can be designed out of existence, like the Replacement Character method above. Design the return value such that an error is not necessary - for example, a string search function can return an empty string if not found rather than throw an Exception.
-Investigate the use of Option types for error returns.
+
+Investigate the use of "Option" or "Sum" types for error returns.
The problem with this is that bubbling up errors becomes a pain.
How about polymorphic variants? That's a good idea from OCaml. See:
https://keleshev.com/composable-error-handling-in-ocaml
—
Reply to this email directly, view it on GitHub
<#2 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHSL45M7ZCN7UUJG6LGXQDYRVXQDAVCNFSM6AAAAAA76RJ7HCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTQNRQGYYTANRQGE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
@WalterBright This does not include my thoughts on relaxing allocation rules for non "Core" packages as that would be dependent on going with my proposed split-root design (which I am still working on).