www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - usable nogc Exceptions with Mir Runtime

reply 9il <ilyayaroshenko gmail.com> writes:
Hello

Mir Runtime [1] is Dlang  nogc runtime infrastructure for a 
simple, slim, and fast code. It is based on Mir Core [2] and 
compatible with Mir Algorithm [3] >=v3.0.0-alpha-dev.

Mir Runtime should be used with flags -dip1000, -dip1008 and 
optionally -dip25.

Release v0.0.5 comes with

  - mir.exception -  nogc MirException
  - mir.format -  nogc formatting

Mir Runtime uses a combination of DIP1000 [4] and DIP1008 [5].

Example
=======================
///
 safe pure nothrow  nogc
unittest
{
     import mir.exception;
     import mir.format;
     try throw new MirException(stringBuf() << "Hi D" << 2 << "!" 
<< getData);
     catch(Exception e) assert(e.msg == "Hi D2!");
}

=======================

If the message is non-scope string MirException constructor uses 
the message data itself (zero-copy).
If the message is scope const array of char with the size no 
greater then 447 bytes, MirException constructor uses local 
buffer preallocated by DRuntime, otherwise, MirException 
allocates memory using C's malloc.

Knows Issues:
  - DRuntime Issue 19317 [6] cause memory leaks for messages that 
have a size greater than 447 bytes.

This work has been sponsored by Symmetry Investments [7] and 
Kaleidic Associates [8].

1. https://github.com/libmir/mir-runtime
2. https://github.com/libmir/mir-core
3. https://github.com/libmir/mir-algorithm
4. https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md
5. https://github.com/dlang/DIPs/blob/master/DIPs/DIP1008.md
6. https://issues.dlang.org/show_bug.cgi?id=19317
7. http://symmetryinvestments.com/
8. http://github.com/kaleidicassociates

Best regards,
Ilya Yaroshenko
Oct 24 2018
next sibling parent jmh530 <john.michael.hall gmail.com> writes:
On Wednesday, 24 October 2018 at 10:57:27 UTC, 9il wrote:
 Hello

 Mir Runtime [1] is Dlang  nogc runtime infrastructure for a 
 simple, slim, and fast code. It is based on Mir Core [2] and 
 compatible with Mir Algorithm [3] >=v3.0.0-alpha-dev.

 Mir Runtime should be used with flags -dip1000, -dip1008 and 
 optionally -dip25.

 Release v0.0.5 comes with

  - mir.exception -  nogc MirException
  - mir.format -  nogc formatting

 [snip]
Cool. Keep up the good work.
Oct 24 2018
prev sibling next sibling parent reply Oleg <code.viator gmail.com> writes:
Thanks for your work!

 Example
 =======================
 ///
  safe pure nothrow  nogc
 unittest
 {
     import mir.exception;
     import mir.format;
     try throw new MirException(stringBuf() << "Hi D" << 2 << 
 "!" << getData);
     catch(Exception e) assert(e.msg == "Hi D2!");
 }

 =======================
I don't understand why you choose C++ format style instead of D-style format?
Oct 30 2018
next sibling parent reply 9il <ilyayaroshenko gmail.com> writes:
On Tuesday, 30 October 2018 at 16:25:12 UTC, Oleg wrote:
 Thanks for your work!

 Example
 =======================
 ///
  safe pure nothrow  nogc
 unittest
 {
     import mir.exception;
     import mir.format;
     try throw new MirException(stringBuf() << "Hi D" << 2 << 
 "!" << getData);
     catch(Exception e) assert(e.msg == "Hi D2!");
 }

 =======================
I don't understand why you choose C++ format style instead of D-style format?
The C++ format style is simpler to implement and it is much faster to run. D's style came from C and Boost's format. Also, the C++ style is more low level then format strings, so they can be built on top of it.
Oct 31 2018
parent reply Uknown <sireeshkodali1 gmail.com> writes:
On Wednesday, 31 October 2018 at 08:34:08 UTC, 9il wrote:
 The C++ format style is simpler to implement and it is much 
 faster to run.
 D's style came from C and Boost's format. Also, the C++ style 
 is more low level then format strings, so they can be built on 
 top of it.
I think they meant why use the `<<` operator instead of the `~` operator?
Oct 31 2018
next sibling parent bauss <jj_1337 live.dk> writes:
On Wednesday, 31 October 2018 at 09:13:14 UTC, Uknown wrote:
 On Wednesday, 31 October 2018 at 08:34:08 UTC, 9il wrote:
 The C++ format style is simpler to implement and it is much 
 faster to run.
 D's style came from C and Boost's format. Also, the C++ style 
 is more low level then format strings, so they can be built on 
 top of it.
I think they meant why use the `<<` operator instead of the `~` operator?
This. Please don't do that.
Oct 31 2018
prev sibling parent reply 9il <ilyayaroshenko gmail.com> writes:
On Wednesday, 31 October 2018 at 09:13:14 UTC, Uknown wrote:
 On Wednesday, 31 October 2018 at 08:34:08 UTC, 9il wrote:
 The C++ format style is simpler to implement and it is much 
 faster to run.
 D's style came from C and Boost's format. Also, the C++ style 
 is more low level then format strings, so they can be built on 
 top of it.
I think they meant why use the `<<` operator instead of the `~` operator?
~ is used for string concatenation in D including string compile time constant concatenation. It is better not to override it because both << and ~ can be used in the same expression.
Oct 31 2018
parent reply bauss <jj_1337 live.dk> writes:
On Wednesday, 31 October 2018 at 13:56:56 UTC, 9il wrote:
 ~ is used for string concatenation in D including string 
 compile time constant concatenation.   It is better not to 
 override it because both << and ~ can be used in the same 
 expression.
I see what your argument is now for it, BUT I would still have left it out because it's not idiomatic D and an alternative would have been better if you absolutely had to rely on ~ being used within the expression to combine both. Ex. try throw new MirException(stringBuf().append("Hi D", 2, "!", getData); Would have been a much better approach similar to how write/writeln etc. work from std.stdio.
Nov 01 2018
next sibling parent Atila Neves <atila.neves gmail.com> writes:
On Thursday, 1 November 2018 at 10:17:25 UTC, bauss wrote:
 On Wednesday, 31 October 2018 at 13:56:56 UTC, 9il wrote:
 ~ is used for string concatenation in D including string 
 compile time constant concatenation.   It is better not to 
 override it because both << and ~ can be used in the same 
 expression.
I see what your argument is now for it, BUT I would still have left it out because it's not idiomatic D and an alternative would have been better if you absolutely had to rely on ~ being used within the expression to combine both. Ex. try throw new MirException(stringBuf().append("Hi D", 2, "!", getData); Would have been a much better approach similar to how write/writeln etc. work from std.stdio.
https://github.com/atilaneves/nogc/blob/ed4663558ceea1f5dc2634d6f01cc6ce6967adc1/tests/ut/exception.d#L49
Nov 01 2018
prev sibling parent reply 9il <ilyayaroshenko gmail.com> writes:
On Thursday, 1 November 2018 at 10:17:25 UTC, bauss wrote:
 On Wednesday, 31 October 2018 at 13:56:56 UTC, 9il wrote:
 ~ is used for string concatenation in D including string 
 compile time constant concatenation.   It is better not to 
 override it because both << and ~ can be used in the same 
 expression.
I see what your argument is now for it, BUT I would still have left it out because it's not idiomatic D and an alternative would have been better if you absolutely had to rely on ~ being used within the expression to combine both. Ex. try throw new MirException(stringBuf().append("Hi D", 2, "!", getData); Would have been a much better approach similar to how write/writeln etc. work from std.stdio.
Well, added at v0.0.8 [1]. Mir Runtime formatting and exceptions are CTFE-able if a msg fits into a local buffer and support user-defined types formatting. Note, that toString function must be scope const. mir.parse was added in v0.0.7. Currently, only integer types are supported. 1. https://github.com/libmir/mir-runtime/pull/2
Nov 01 2018
parent bauss <jj_1337 live.dk> writes:
On Friday, 2 November 2018 at 05:21:07 UTC, 9il wrote:
 On Thursday, 1 November 2018 at 10:17:25 UTC, bauss wrote:
 [...]
Well, added at v0.0.8 [1]. Mir Runtime formatting and exceptions are CTFE-able if a msg fits into a local buffer and support user-defined types formatting. Note, that toString function must be scope const. mir.parse was added in v0.0.7. Currently, only integer types are supported. 1. https://github.com/libmir/mir-runtime/pull/2
Thanks!
Nov 01 2018
prev sibling parent reply Manu <turkeyman gmail.com> writes:
On Tue, Oct 30, 2018 at 9:30 AM Oleg via Digitalmars-d-announce
<digitalmars-d-announce puremagic.com> wrote:
 Thanks for your work!

 Example
 =======================
 ///
  safe pure nothrow  nogc
 unittest
 {
     import mir.exception;
     import mir.format;
     try throw new MirException(stringBuf() << "Hi D" << 2 <<
 "!" << getData);
     catch(Exception e) assert(e.msg == "Hi D2!");
 }

 =======================
I don't understand why you choose C++ format style instead of D-style format?
Perhaps this is a stupid question... but there's clearly `new MirException` right there in that code. How is this nogc?
Nov 02 2018
parent 9il <ilyayaroshenko gmail.com> writes:
On Friday, 2 November 2018 at 07:00:49 UTC, Manu wrote:
 On Tue, Oct 30, 2018 at 9:30 AM Oleg via Digitalmars-d-announce 
 <digitalmars-d-announce puremagic.com> wrote:
 Thanks for your work!

 Example
 =======================
 ///
  safe pure nothrow  nogc
 unittest
 {
     import mir.exception;
     import mir.format;
     try throw new MirException(stringBuf() << "Hi D" << 2 <<
 "!" << getData);
     catch(Exception e) assert(e.msg == "Hi D2!");
 }

 =======================
I don't understand why you choose C++ format style instead of D-style format?
Perhaps this is a stupid question... but there's clearly `new MirException` right there in that code. How is this nogc?
The code requires -dip1008 flag. Take a look into the DIP https://github.com/dlang/DIPs/blob/master/DIPs/DIP1008.md
Nov 02 2018
prev sibling parent Nathan S. <no.public.email example.com> writes:
On Wednesday, 24 October 2018 at 10:57:27 UTC, 9il wrote:
 Release v0.0.5 comes with

  - mir.exception -  nogc MirException
  - mir.format -  nogc formatting
Fantastic!
Oct 31 2018