Commit Graph

1228 Commits

Author SHA1 Message Date
Yuriy Glukhov
2c83f94544 Check for nil in cstringArrayToSeq (#23747)
This fixes crashes in some specific network configurations (as
`cstringArrayToSeq` is used extensively in `nativesockets`).

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2024-06-24 09:35:05 +02:00
lit
b3b26b2e56 doc(format): system.nim: doc of hostCPU for loongarch64 (#23621)
In doc, `loongarch64` used to be written as `'"loongarch64"'`

since it's [supported](https://github.com/nim-lang/Nim/pull/19223)
2024-05-17 20:35:02 +08:00
ringabout
cd3cf3a20e fixes #23524; global variables cannot be analysed when injecting move (#23529)
fixes #23524

```nim
proc isAnalysableFieldAccess*(orig: PNode; owner: PSym): bool =
  ...
  result = n.kind == nkSym and n.sym.owner == owner and
    {sfGlobal, sfThread, sfCursor} * n.sym.flags == {} and
    (n.sym.kind != skParam or isSinkParam(n.sym))
```
In `isAnalysableFieldAccess`, globals, cursors are already rejected
2024-04-24 12:47:05 +02:00
ringabout
e4522dc87f remove internalNew from system (#23475) 2024-04-04 12:53:30 +02:00
Andreas Rumpf
59c65009a5 ORC: added -d:nimOrcStats switch and related API (#23272) 2024-02-21 16:58:30 +01:00
ringabout
e3350cbe6f clean up goto exceptions; remove the setjmp.h dep (#23259) 2024-01-27 07:57:07 +01:00
ringabout
8a38880ef7 workaround arrayWith issues (#23230)
I'm working on it, but it's quite tricky. I will fix it soon
2024-01-18 21:13:39 +01:00
ringabout
3379d26629 fixes #23223; prevents insert self-assignment (#23225)
fixes #23223
2024-01-18 14:20:54 +01:00
ringabout
bd72c4c729 remove unnecessary workaround from arrayWith (#23208)
The problem was fixed by https://github.com/nim-lang/Nim/pull/23195
2024-01-15 17:06:43 +08:00
ringabout
30cb6826c0 patches for #23129 (#23198)
fixes it in the normal situation
2024-01-11 15:38:23 +01:00
ringabout
29ac3c9986 fixes #22923; fixes =dup issues (#23182)
fixes #22923
2024-01-11 11:23:42 +01:00
ASVIEST
20d79c9fb0 Deprecate asm stmt for js target (#23149)
why ?

- We already have an emit that does the same thing
- The name asm itself is a bit confusing, you might think it's an alias
for asm.js or something else.
- The asm keyword is used differently on different compiler targets (it
makes it inexpressive).
- Does anyone (other than some compiler libraries) use asm instead of
emit ? If yes, it's a bit strange to use asm somewhere and emit
somewhere. By making the asm keyword for js target deprecated, there
would be even less use of the asm keyword for js target, reducing the
amount of confusion.
- New users might accidentally use a non-universal approach via the asm
keyword instead of emit, and then when they learn about asm, try to
figure out what the differences are.

see https://forum.nim-lang.org/t/10821

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2024-01-02 07:49:54 +01:00
ringabout
bc24340d55 fixes #23006; newSeqUninit -> CT Error; imitate newStringUninit (#23007)
fixes #23006
2023-11-30 14:08:49 +01:00
ringabout
b5f5b74fc8 enable vtable implementation for C++ and make it an experimental feature (#23004)
follow up https://github.com/nim-lang/Nim/pull/22991

- [x] turning it into an experimental feature

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-11-30 14:05:45 +01:00
ringabout
30cf33f04d rework the vtable implementation embedding the vtable array directly with new strictions on methods (#22991)
**TODO**
- [x] fixes changelog
With the new option `nimPreviewVtables`, `methods` are confined in the
same module where the type of the first parameter is defined

- [x] make it opt in after CI checks its feasibility

## In the following-up PRs

- [ ] in the following PRs, refactor code into a more efficient one

- [ ] cpp needs special treatments since it cannot embed array in light
of the preceding limits: ref
https://github.com/nim-lang/Nim/pull/20977#discussion_r1035528927; we
can support cpp backends with vtable implementations later on the
comprise that uses indirect vtable access

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-11-28 15:11:43 +01:00
ringabout
379299a5ac fixes #22286; enforce Non-var T destructors by nimPreviewNonVarDestructor (#22975)
fixes #22286
ref https://forum.nim-lang.org/t/10642

For backwards compatibilities, we might need to keep the changes under a
preview compiler flag. Let's see how many packags it break.

**TODO** in the following PRs

- [ ] Turn the `var T` destructors warning into an error with
`nimPreviewNonVarDestructor`

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-11-25 18:27:27 +01:00
Jacek Sieka
58c44312af reserve sysFatal for Defect (#22158)
Per manual, `panics:on` affects _only_ `Defect`:s - thus `sysFatal`
should not redirect any other exceptions.

Also, when `sysFatal` is used in `nimPanics` mode, it should use regular
exception handling pipeline to ensure exception hooks are called
consistently for all raised defects.
2023-11-06 07:57:29 +01:00
ringabout
f0e5bdd7d8 fixes #22898; fix #22883 differently (#22900)
fixes #22898
In these cases, the tables/sets are clears or elements are deleted from
them. It's reasonable to suppress warnings because the value is not
accessed anymore, which means it's safe to ignore the warnings.
2023-11-05 09:12:53 +01:00
ringabout
92141e82ed fixes #22883; replace default(typeof( with reset; suppress `Unsaf… (#22895)
fixes #22883

…eDefault` warnings

avoid issues mentioned by https://forum.nim-lang.org namely, it
allocated unnecessary stack objects in the loop

```c
while (1)
{
tyObject_N__8DSNqSGSHBKOhI8CqSgAow T5_;
nimZeroMem((void *)(&T5_), sizeof(tyObject_N__8DSNqSGSHBKOhI8CqSgAow));
eqsink___test4954_u450((&(*t_p0).data.p->data[i].Field1), T5_);
}
```

It might be more efficient in some cases

follow up https://github.com/nim-lang/Nim/pull/21821
2023-11-01 07:54:47 +01:00
ringabout
3fd4e68433 fixes #22856; enables -d:nimStrictDelete (#22858)
fixes #22856

`-d:nimStrictDelete` is introduced in 1.6.0, which promised to be
enabled in the coming versions. To keep backwards incompatibilities, it
also extends the feature of `-d:nimAuditDelete`, which now mimics the
old behaviors.
2023-10-24 05:13:14 +02:00
ringabout
3095048d67 fixes system.delete that raises defects (#22857) 2023-10-23 22:56:52 +08:00
Andreas Rumpf
816589b667 NIR: Nim intermediate representation (#22777)
Theoretical Benefits / Plans: 

- Typed assembler-like language.
- Allows for a CPS transformation.
- Can replace the existing C backend by a new C backend.
- Can replace the VM.
- Can do more effective "not nil" checking and static array bounds
checking.
- Can be used instead of the DFA.
- Easily translatable to LLVM.
- Reasonably easy to produce native code from.
- Tiny memory consumption. No pointers, no cry.

**In very early stages of development.**

Todo:
- [x] Map Nim types to IR types.
- [ ] Map Nim AST to IR instructions:
  - [x] Map bitsets to bitops.
  - [ ] Implement string cases.
  - [ ] Implement range and index checks.
  - [x] Implement `default(T)` builtin.
  - [x] Implement multi string concat.
- [ ] Write some analysis passes.
- [ ] Write a backend.
- [x] Integrate into the compilation pipeline.
2023-10-11 17:44:14 +02:00
ringabout
7146307823 fixes #22554; makes newSeqWith use newSeqUninit (#22771)
fixes #22554
2023-09-30 06:32:27 +02:00
ringabout
a8d55fdec7 deprecates newSeqUninitialized replaced by newSeqUninit (#22739)
ref #19727
closes #22586

https://github.com/nim-lang/Nim/issues/22554 needs it to move on.
`newSeqUnsafe` can be introduced later.
2023-09-29 09:38:51 +02:00
Amjad Ben Hedhili
f0bf94e531 Make newStringUninit available in the VM [backport] (#22748)
It's equivalent to `newString`.
2023-09-25 07:19:09 +02:00
SirOlaf
1b0447c208 Add magic toOpenArrayChar (#22751)
Should help with stuff like the checksums package which only takes
`openArray[char]`

Co-authored-by: SirOlaf <>
2023-09-24 20:47:56 +02:00
Amjad Ben Hedhili
a6c281bd1d Fix newStringUninit not setting the '\0' terminator [backport] (#22746)
Causes problems when working with `cstring`s.
2023-09-23 17:08:24 +02:00
Amjad Ben Hedhili
b10a809274 Make newStringUninit available on the js backend [backport] (#22743) 2023-09-23 11:39:11 +02:00
Amjad Ben Hedhili
b542be1e7d Fix capacity for const and shallow [backport] (#22705) 2023-09-18 22:57:30 +02:00
sls1005
dba9000609 Add descriptions and examples for rawProc and rawEnv (#22710)
Add descriptions for `rawProc` and `rawEnv`. See
<https://forum.nim-lang.org/t/10485> for more informations.

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-09-18 16:42:43 +02:00
ringabout
63c2ea5566 fixes incorrect cint overflow in system (#22718)
fixes #22700
2023-09-18 10:00:46 +02:00
Amjad Ben Hedhili
8853fb0775 Make newSeqOfCap not initialize memory. (#21842)
It's used in `newSeqUninitialized`.

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2023-09-09 21:11:45 +02:00
ringabout
e53c66ef39 fixes #22555; implements newStringUninit (#22572)
* fixes newStringUninitialized; implement `newStringUninitialized`

* add a simple test case

* adds a changelog

* Update lib/system.nim

* Apply suggestions from code review

rename to newStringUninit
2023-08-29 13:29:42 +02:00
Amjad Ben Hedhili
d77ada5bdf Markdown code blocks migration part 9 (#22506)
* Markdown code blocks migration part 9

* fix [skip ci]
2023-08-19 15:14:56 +02:00
Andrey Makarov
a660c17d30 Markdown code blocks migration part 8 (#22478) 2023-08-15 06:27:36 +02:00
ringabout
3f7e1d7daa replace doAssert false with raiseAssert in lib, which works better with strictdefs (#22458) 2023-08-11 18:24:46 +02:00
ringabout
10a6e4c236 clean up gc:arc or gc:orc in docs and in error messages (#22408)
* clean up gc:arc/orc in docs

* in error messages
2023-08-08 05:55:18 -04:00
konsumlamm
d37b620757 Make repr(HSlice) always available (#22332)
Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2023-08-04 05:29:48 +02:00
ringabout
f0f3904ff0 implement ensureMove (#22339)
* implement `ensureMove`

* use an additional flag

* improve some logics

* progress: fixes discard ensureMove

* forbids nested expressions

* improve error messages

* checkpoint

* fixes cursor

* ADD MORE TESTS

* fixes cursorinference again

* tiny cleanup

* improve error messages

* fixes docs

* implement comments add more tests

* fixes js
2023-07-29 10:57:03 +02:00
ringabout
11c8dfc9b3 fixes docs (#22331) 2023-07-26 10:04:34 +08:00
ringabout
7d9fe106ec fixes #22268; fixes move codegen (#22288) 2023-07-19 12:57:58 +02:00
Juan Carlos
db1ce4ff12 Fix #22273 (#22275)
* Fix #22273
2023-07-14 12:40:57 +02:00
ringabout
1ad618d96c clean up the documentation (#22196) 2023-07-02 22:36:05 +02:00
ringabout
e422b3c860 adds =destroy T support for strings and seqs (#22167)
* adds =destroy T support for strings and seqs

* fixes system

* fixes tests
2023-06-27 13:07:29 +02:00
ringabout
4546f5dfe5 adds T destructor for refs (#22147)
* adds T destructor for refs

* add `newRefdestructor`

* adds ref overload for destructors

* fixes config
2023-06-26 15:10:06 +02:00
ringabout
f524d60fa1 fixes #22123; Compiler bug with default initializer values and arrays (#22128) 2023-06-20 08:02:06 +02:00
ringabout
64b27edd3a make move use =wasMoved internally (#22032)
* make `move` use `=wasMoved` internally

* fixes tests

* fixes spawn finally

* fixes views

* rename to internalMove

* add a test case
2023-06-09 15:53:12 +02:00
ringabout
0f3d6b5a52 small fixes for atomicArc (#22017)
* small fixes for atomicArc

* Update lib/system/arc.nim
2023-06-06 21:22:07 +02:00
ringabout
1133f20fe2 lift the =dup hook (#21903)
* fixes tests again
* remove helper functions
* fixes closures, owned refs
* final cleanup
2023-06-02 16:03:32 +02:00
ringabout
ddce555998 improve wasMoved hooks; allow reset to use the overridden wasMoved hook (#21831)
* improve `wasMoved` hooks

* Because `wasMoved` is lifted
2023-05-12 15:24:14 +02:00