9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] Nim lang, C alignment support
@ 2021-08-06 10:52 Emery
  2021-08-06 11:11 ` Adrian Siekierka
  0 siblings, 1 reply; 5+ messages in thread
From: Emery @ 2021-08-06 10:52 UTC (permalink / raw)
  To: 9front

Hi,

I've been try to port the Nim language to Plan 9 and so far it works with
one exception. Most pure Nim code can be compiled to a C form that can be
built by the native compilers (no APE), but the Nim garbage collector
uses the alignment features of GCC/LLVM/VCC. Programs run until the first
garbage collection and then things go to shit.

Are there C compilers with alignment control (C11?) available for 9Front?
Is there any interest in backporting alignas or alignof to 6c?
An alternative would be to port Nim to C99.

There might not be any interest in Nim within the Plan 9 community but
I would prefer to be writing and testing my projects on 9Front.


Cheers,
Emery


https://nim-lang.org/

The alignment macros:
https://github.com/nim-lang/Nim/blob/v1.4.8/lib/nimbase.h#L548

Expected behavior:
https://raw.githubusercontent.com/nim-lang/Nim/devel/tests/align/talign.nim

Useless Plan 9 port:
https://github.com/nim-lang/Nim/compare/v1.4.8...ehmry:plan9


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9front] Nim lang, C alignment support
  2021-08-06 10:52 [9front] Nim lang, C alignment support Emery
@ 2021-08-06 11:11 ` Adrian Siekierka
  2021-08-06 13:37   ` Emery Hemingway
  0 siblings, 1 reply; 5+ messages in thread
From: Adrian Siekierka @ 2021-08-06 11:11 UTC (permalink / raw)
  To: 9front

Hello,

The Nim garbage collector? I hope you're opting into ARC/ORC instead - 
that's the one the Nim development team is pushing for (the former is 
reference counting with RAII elements; the latter is that combined with 
a dedicated garbage collector just for resolving references which may 
contain cycles).

I think Araq might be interested in patches which improve the 
portability of the C code they output, but you'd have to ask.

Adrian "asie" Siekierka

On 8/6/21 12:52 PM, Emery wrote:
> Hi,
>
> I've been try to port the Nim language to Plan 9 and so far it works with
> one exception. Most pure Nim code can be compiled to a C form that can be
> built by the native compilers (no APE), but the Nim garbage collector
> uses the alignment features of GCC/LLVM/VCC. Programs run until the first
> garbage collection and then things go to shit.
>
> Are there C compilers with alignment control (C11?) available for 9Front?
> Is there any interest in backporting alignas or alignof to 6c?
> An alternative would be to port Nim to C99.
>
> There might not be any interest in Nim within the Plan 9 community but
> I would prefer to be writing and testing my projects on 9Front.
>
>
> Cheers,
> Emery
>
>
> https://nim-lang.org/
>
> The alignment macros:
> https://github.com/nim-lang/Nim/blob/v1.4.8/lib/nimbase.h#L548
>
> Expected behavior:
> https://raw.githubusercontent.com/nim-lang/Nim/devel/tests/align/talign.nim 
>
>
> Useless Plan 9 port:
> https://github.com/nim-lang/Nim/compare/v1.4.8...ehmry:plan9
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9front] Nim lang, C alignment support
  2021-08-06 11:11 ` Adrian Siekierka
@ 2021-08-06 13:37   ` Emery Hemingway
  2021-08-06 22:25     ` Xiao-Yong Jin
  0 siblings, 1 reply; 5+ messages in thread
From: Emery Hemingway @ 2021-08-06 13:37 UTC (permalink / raw)
  To: Adrian Siekierka; +Cc: 9front

When I say garbage collector I should say memory manager, ARC and ORC
don't work either. If you look at the generated source all Nim types
have some alignment info attach to them, so I'd say its an unavoidable
problem.

On Friday 6 August 2021 13:11:31 CEST, Adrian Siekierka wrote:
> Hello,
>
> The Nim garbage collector? I hope you're opting into ARC/ORC 
> instead - that's the one the Nim development team is pushing for 
> (the former is reference counting with RAII elements; the latter 
> is that combined with a dedicated garbage collector just for 
> resolving references which may contain cycles).


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9front] Nim lang, C alignment support
  2021-08-06 13:37   ` Emery Hemingway
@ 2021-08-06 22:25     ` Xiao-Yong Jin
  2021-08-08 14:54       ` Emery Hemingway
  0 siblings, 1 reply; 5+ messages in thread
From: Xiao-Yong Jin @ 2021-08-06 22:25 UTC (permalink / raw)
  To: 9front; +Cc: Adrian Siekierka


> On Aug 6, 2021, at 8:37 AM, Emery Hemingway <ehmry@posteo.net> wrote:
> 
> When I say garbage collector I should say memory manager, ARC and ORC
> don't work either. If you look at the generated source all Nim types
> have some alignment info attach to them, so I'd say its an unavoidable
> problem.

What exactly happens when the executables run?  Do you have the Nim
compiler bootstrapped on 9front?  Or do you just try to compile the
C code generated from other host OS?  Did you try to turn off all
the extra checks and just use malloc, like,

	-d:danger --panics:on --gc:arc -d:useMalloc

If I understand correctly, the only place that relies on the alignment
is Nim's allocator, for whatever reason, and it did not appear until
late 2019 as an optimization and safety guarantees for dynamic libraries.
If you can figure out where it actually "goes to shit", you might be
able to avoid using alignment at all.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9front] Nim lang, C alignment support
  2021-08-06 22:25     ` Xiao-Yong Jin
@ 2021-08-08 14:54       ` Emery Hemingway
  0 siblings, 0 replies; 5+ messages in thread
From: Emery Hemingway @ 2021-08-08 14:54 UTC (permalink / raw)
  To: Xiao-Yong Jin; +Cc: 9front, Adrian Siekierka

Hello Jin,

On Saturday 7 August 2021 00:25:58 CEST, Xiao-Yong Jin wrote:
> What exactly happens when the executables run?  Do you have the Nim
> compiler bootstrapped on 9front?  Or do you just try to compile the
> C code generated from other host OS?

Nim executables seem to run until memory starts being freed. It's a
double-free panic in pool.c or else I get a stack-trace leading to
gc.nim. Simple programs are usable, I have the compiler bootstrapped
enough to print it's version and usage message to stdout, but with any
load it will dealloc and break.

> Did you try to turn off all the extra checks and just use malloc, like,
>
> 	-d:danger --panics:on --gc:arc -d:useMalloc

I've tried these and --gc:orc but things seem to break in the same way.

> If I understand correctly, the only place that relies on the alignment
> is Nim's allocator, for whatever reason, and it did not appear until
> late 2019 as an optimization and safety guarantees for dynamic libraries.
> If you can figure out where it actually "goes to shit", you might be
> able to avoid using alignment at all.

I think you are right, it may be possible to disable some optimizations,
I'll see what I can do. If anyone is curious I've documented the
bootstrapping process.

https://github.com/ehmry/Nim/tree/plan9#readme


Thanks for the encouragement,
Emery

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-09  9:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-06 10:52 [9front] Nim lang, C alignment support Emery
2021-08-06 11:11 ` Adrian Siekierka
2021-08-06 13:37   ` Emery Hemingway
2021-08-06 22:25     ` Xiao-Yong Jin
2021-08-08 14:54       ` Emery Hemingway

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).