Re: Phobos in BetterC

2019-03-10 Thread Seb via Digitalmars-d-learn

On Friday, 8 March 2019 at 09:24:25 UTC, Vasyl Teliman wrote:
I've tried to use Mallocator in BetterC but it seems it's not 
available there:


https://run.dlang.io/is/pp3HDq

This produces a linker error.

I'm wondering why Mallocator is not available in this mode (it 
would be intuitive to assume that it's working). Also I would 
like to know what parts of Phobos are available there (e.g. 
std.traits, std.typecons...).


Thanks in advance.


Just for reference there's also a few number of tests in Phobos 
annotated with @betterC. As expected, they are tested with 
-betterC. However, at the moment this annotated subset is pretty 
small and not exposed to the documentation. Though it shouldn't 
be too hard to increase the subset and mark the annotated 
function in the documentation.


Re: Phobos in BetterC

2019-03-09 Thread 9il via Digitalmars-d-learn

On Saturday, 9 March 2019 at 19:40:27 UTC, Sebastiaan Koppe wrote:

On Saturday, 9 March 2019 at 17:14:37 UTC, 9il wrote:
It was fixed to be used in BetterC. If it still does not work 
you can open an issue and ping me (@9il).


That is awesome. I suppose support for betterC is only from v3 
upwards?


Yes. However, it is hard to test. Also, BetterC works better in 
LDC. I have never seen a real production betterC program compiled 
with DMD.


Re: Phobos in BetterC

2019-03-09 Thread Sebastiaan Koppe via Digitalmars-d-learn

On Saturday, 9 March 2019 at 17:14:37 UTC, 9il wrote:
It was fixed to be used in BetterC. If it still does not work 
you can open an issue and ping me (@9il).


That is awesome. I suppose support for betterC is only from v3 
upwards?


Re: Phobos in BetterC

2019-03-09 Thread 9il via Digitalmars-d-learn

On Friday, 8 March 2019 at 09:24:25 UTC, Vasyl Teliman wrote:
I've tried to use Mallocator in BetterC but it seems it's not 
available there:


https://run.dlang.io/is/pp3HDq

This produces a linker error.

I'm wondering why Mallocator is not available in this mode (it 
would be intuitive to assume that it's working). Also I would 
like to know what parts of Phobos are available there (e.g. 
std.traits, std.typecons...).


Thanks in advance.


Try this package
https://github.com/dlang-community/stdx-allocator

(v3.0.2)

It was fixed to be used in BetterC. If it still does not work you 
can open an issue and ping me (@9il).


Best,
Ilya


Re: Phobos in BetterC

2019-03-09 Thread Nicholas Wilson via Digitalmars-d-learn

On Saturday, 9 March 2019 at 12:42:34 UTC, Sebastiaan Koppe wrote:
There might also be the option to use @nogc exceptions (dip 
1008), but I am not sure.


That won't work as the implementation on DIP1008 cheats the type 
system but doesn't actually work, i.e. the exceptions are still 
CG allocated.




Re: Phobos in BetterC

2019-03-09 Thread Sebastiaan Koppe via Digitalmars-d-learn

On Friday, 8 March 2019 at 09:24:25 UTC, Vasyl Teliman wrote:

Also I would to know what parts of Phobos are available there
(e.g. std.traits, std.typecons...).


There is no clear rule on which phobos packages work and which 
don't. It all depends on what underlying features the phobos 
package uses. Here is the list of what's not allowed in betterC:


- Garbage Collection
- TypeInfo and ModuleInfo
- Classes
- Built-in threading (e.g. core.thread)
- Dynamic arrays (though slices of static arrays work) and 
associative arrays

- Exceptions
- synchronized and core.sync
- Static module constructors or destructors

Generally anything meta/compile-time works. Packages like 
std.traits / std.meta / std.range / std.algorithm are not an 
issue. You would expect std.typecons.tuple to work as well, but 
it doesn't.


If you are doing ctfe, then you are in for a bummer. Because the 
same restrictions apply there as well. There is supposed to be a 
workaround by including the ctfe file in question via -I on the 
command line, but I could never make it work in dub.


If you encounter something that doesn't work, there are a couple 
of options. Sometimes the function you are trying to use is 
betterC compatible but is inside a package that isn't. Just 
extract it into a separate file. At other times it is because the 
struct has a toString method, or throws an exception. Again, copy 
the relevant part, rip out the toString method and/or replace the 
exception with an assert (of course, after you make sure the 
assert doesn't get triggered). There might also be the option to 
use @nogc exceptions (dip 1008), but I am not sure.


If all that isn't possible, you will have to rewrite the thing in 
question.


Re: Phobos in BetterC

2019-03-09 Thread Nicholas Wilson via Digitalmars-d-learn

On Friday, 8 March 2019 at 09:24:25 UTC, Vasyl Teliman wrote:
I've tried to use Mallocator in BetterC but it seems it's not 
available there:


https://run.dlang.io/is/pp3HDq

This produces a linker error.

I'm wondering why Mallocator is not available in this mode (it 
would be intuitive to assume that it's working). Also I would 
like to know what parts of Phobos are available there (e.g. 
std.traits, std.typecons...).


Thanks in advance.


This is really a linker problem, because -betterC doesn't link 
druntime, and pbobos links druntime. to get around this pass 
-i=std.experimental.allocator to dmd along with the rest of you 
usual arguments.


Re: Phobos in BetterC

2019-03-09 Thread Laeeth Isharc via Digitalmars-d-learn

On Friday, 8 March 2019 at 09:24:25 UTC, Vasyl Teliman wrote:
I've tried to use Mallocator in BetterC but it seems it's not 
available there:


https://run.dlang.io/is/pp3HDq

This produces a linker error.

I'm wondering why Mallocator is not available in this mode (it 
would be intuitive to assume that it's working). Also I would 
like to know what parts of Phobos are available there (e.g. 
std.traits, std.typecons...).


Thanks in advance.


I would guess it's not available because it was written before 
betterC mode was a thing and nobody has yet updated it.


If you look at spasm on code.dlang.org there is a version you can 
copy paste that should work in betterC mode if I remember 
correctly.




Re: Phobos in BetterC

2019-03-09 Thread Bastiaan Veelo via Digitalmars-d-learn

On Friday, 8 March 2019 at 09:24:25 UTC, Vasyl Teliman wrote:
I've tried to use Mallocator in BetterC but it seems it's not 
available there:


https://run.dlang.io/is/pp3HDq

This produces a linker error.

I'm wondering why Mallocator is not available in this mode (it 
would be intuitive to assume that it's working). Also I would 
like to know what parts of Phobos are available there (e.g. 
std.traits, std.typecons...).


Thanks in advance.


I can’t answer that but you can use C’s malloc directly: 
https://run.dlang.io/is/fnRFIr


Bastiaan.


Phobos in BetterC

2019-03-08 Thread Vasyl Teliman via Digitalmars-d-learn
I've tried to use Mallocator in BetterC but it seems it's not 
available there:


https://run.dlang.io/is/pp3HDq

This produces a linker error.

I'm wondering why Mallocator is not available in this mode (it 
would be intuitive to assume that it's working). Also I would 
like to know what parts of Phobos are available there (e.g. 
std.traits, std.typecons...).


Thanks in advance.