Commit Graph

21916 Commits

Author SHA1 Message Date
ringabout
e4522dc87f remove internalNew from system (#23475) 2024-04-04 12:53:30 +02:00
ringabout
14e79b79bc remove BountySource which doesn't exist anymore (#23474)
ref https://github.com/nim-lang/website/issues/391


https://news.ycombinator.com/item?id=38419134
2024-04-04 12:53:09 +02:00
ringabout
9e1b170a09 fixes #16771; lower swap for JS backend (#23473)
fixes #16771

follow up https://github.com/nim-lang/Nim/pull/16536

Ideally it should be handled in the IR part in the future

I have also checked the double evaluation of `swap` in the JS runtime
https://github.com/nim-lang/Nim/issues/16779, that might be solved by a
copy flag or something. Well, it should be best solved in the IR so that
it doesn't bother backends anymore.
2024-04-03 16:59:35 +02:00
lit
dee55f587f Update syncio.nim, fixes "open by FileHandle" doesn't work on Windows (#23456)
## Reprodution
if on Windows:
```Nim
when defined(windows):
  var file: File
  let succ = file.open(<aFileHandle>)
``` 
then `succ` will be false.

If tested, it can be found to fail with errno `22` and message: `Invalid
argument`

## Problem
After some investigations and tests,
I found it's due to the `mode` argument for `fdopen`.


Currently `NoInheritFlag`(`'N'` in Windows) is added to `mode` arg
passed to `_fdopen`, but if referring to
[Windows `_fdopen`
doc](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fdopen-wfdopen?view=msvc-170),
you'll find there is no `'N'` describled. That's `'N'` is not accepted
by `_fdopen`.

Therefore, the demo above will fail.

## In Addition
To begin with, technologically speaking, when opening with a
`fileHandle`(or called `fd`), there is no concept of fd-inheritable as
`fd` is opened already.

In POSIX, `NoInheritFlag` is defined as `e`.

It's pointed out in [POSIX `open`
man-doc](https://www.man7.org/linux/man-pages/man3/fopen.3.html) that
`e` in mode is ignored for fdopen(),

which means `e` for `fdopen()` is not wanted, just allowed.

Therefore, better to also not pass `e` to `fdopen`

---

In all, that's this PR.
2024-04-03 09:32:26 +02:00
ringabout
3bdb531f90 fixes testament targets field (#23472) 2024-04-03 11:33:56 +08:00
ringabout
9ad4309ca4 bump nimble version (#23467) 2024-04-02 18:18:57 +02:00
ringabout
a1602b0d85 dynlib keeps exported functions alive in emscripten (#23469)
ref https://forum.nim-lang.org/t/11338

ref https://github.com/beef331/wasm3/blob/master/src/wasm3/exporter.nim

ref https://github.com/emscripten-core/emscripten/issues/6233

ref
https://github.com/emscripten-core/emscripten/blob/3.1.56/system/include/emscripten/em_macros.h#L10

`EMSCRIPTEN_KEEPALIVE` is a macro that is used to prevent unused
functions from being deadcode eliminated in emscripten, which is a
simple wrapper around `__attribute__((used))`. This PR follows suits and
expects dynlib is supposed to keep these functions alive. In the future,
`exportwasm` might be introduced.

After this PR, a function with `{.dynlib, exportc.}` can be reused from
other wasm programs reliably.
2024-04-02 18:18:03 +02:00
ringabout
32fa7e2871 fixes #9550; Concept related crash only when compiling to JS (#23470)
fixes #9550
2024-04-02 18:09:10 +02:00
Juan M Gómez
cf00b2fd9e adds ccMember CC fixes #23434 (#23457) 2024-03-29 22:09:00 +01:00
ringabout
4b6a9e4add fixes #23422; card regression (#23437)
fixes #23422

ref https://github.com/nim-lang/Nim/issues/20997
https://github.com/nim-lang/Nim/pull/21165

The function `cardSet` is used for large sets that are stored in the
form of arrays. It shouldn't be passed as a pointer
2024-03-28 11:04:47 +01:00
ringabout
a24990bd8c fixes #23429; rework --verbosity with warnings/hints (#23441)
fixes #23429
2024-03-28 11:04:12 +01:00
Gianmarco
afc30a3b93 Fix compile time errors when using tables on 8/16-bits systems. (#23450)
Refer to the discussion in #23439.
2024-03-28 10:54:29 +01:00
Nikolay Nikolov
c934d5986d Converted the 'invalid kind for firstOrd/lastOrd(XXX)' messages from internal errors to fatal errors. (#23443)
This fixes a nimsuggest crash when opening:
    beacon_chain/consensus_object_pools/blockchain_dag.nim
from the nimbus-eth2 project and many other .nim files (44 files, to be
precise) in the same project.

Replaces: https://github.com/nim-lang/Nim/pull/23402
2024-03-27 10:51:44 +01:00
Gianmarco
4c38569229 Change unicode lookup tables to have int32 elements to support platforms where sizeof(int) < 4 (#23433)
Fixes an issue that comes up when using strutils.`%` or any other
strutils/strformat feature that uses the unicode lookup tables behind
the scenes, on systems where ints are than 32-bit wide.

Tested with:

```bash
./koch test cat lib
```

Refer to the discussion in #23125.
2024-03-25 10:59:48 +01:00
Jaremy Creechley
280f877145 fix atomicarc increment (#23427)
The fix to the atomicArc looks to use `-1` as the check value from the
`SharedPtr` solution. However, it should be `-rcIncrement` since the
refcount is bit shifted in ARC/ORC.

I discovered this playing around doing atomic updates of refcounts in a
user library.

Related to https://github.com/nim-lang/Nim/issues/22711 

@ringabout I believe you ported the sharedptr fix?
2024-03-25 10:59:18 +01:00
Juan M Gómez
33902d9dbb [Cpp] Fixes an issue when mixing hooks and calls (#23428) 2024-03-21 08:48:14 +01:00
Igor Sirotin
50c1e93a74 fix: use ErrorColor for hints marked as errors (#23430)
# Description

When using `--hintAsError`, we want some red color to appear in the
logs.
Same is already done for `warningAsError`.

# Cherry-picking to Nim 1.6

Would be nice to cherry-pick this and the `warningAsError` log highlight
to 1.6 branch, as it's used in status-desktop.
2024-03-21 08:26:26 +01:00
Andreas Rumpf
6c4c60eade Adds support for custom ASTs in the Nim parser (#23417) 2024-03-18 20:27:00 +01:00
arkanoid87
cbf48a253f Update manual.md (#23393)
adding link to generic == for tuples in Open and Closed symbols example
2024-03-16 06:23:44 +01:00
ringabout
f639cf063f fixes #23401; prevents nrvo for cdecl procs (#23409)
fixes #23401
2024-03-16 06:23:15 +01:00
soonsouth
b387bc49b5 chore: fix some typos (#23412)
Signed-off-by: soonsouth <cuibuwei@163.com>
2024-03-16 08:35:18 +08:00
Nikolay Nikolov
899ba01ccf + added nimsuggest support for exception inlay hints (#23202)
This adds nimsuggest support for displaying inlay hints for exceptions.
An inlay hint is displayed around function calls, that can raise an
exception, which isn't handled in the current subroutine (in other
words, exceptions that can propagate back to the caller). On mouse hover
on top of the hint, a list of exceptions that could propagate is shown.

The changes, required to support this are already commited to
nimlangserver and the VS code extension. The extension and the server
allow configuration for whether these new exception hints are enabled
(they can be enabled or disabled independently from the type hints), as
well as the inlay strings that are inserted before and after the name of
the function, around the function call. Potentially, one of these
strings can be empty, for example, the user can choose to add an inlay
hint only before the name of the function, or only after the name of the
function.
2024-03-15 18:20:10 +01:00
Chancy K
c2c00776e3 fix BigInt conversion, xOffset/yOffset to int from int64 (#23404)
Problem described here: https://github.com/karaxnim/karax/issues/284

Co-authored-by: Chancy Kennedy <chancy@conciergecloset.com>
2024-03-15 10:13:40 +08:00
Andreas Rumpf
7657a637b8 refactoring: no inheritance for PType/PSym (#23403) 2024-03-14 19:23:18 +01:00
握猫猫
51837e8127 Fix #23381, Use sink and lent to avoid Future[object] making a copy (#23389)
fix #23381

As for the read function, the original plan was to use lent for
annotation, but after my experiments, it still produced copies, so I had
to move it out.

Now the `read` function cannot be called repeatedly
2024-03-14 11:24:39 +01:00
metagn
fb6c805568 propagate efWantStmt in semWhen (#23400)
fixes #23399

The new case introduced in #21657 is triggered by `efWantStmt` but the
`when` statement doesn't normally propagate this flag, so propagate it
when the `semCheck` param in `semWhen` is true which happens when the
`when` statement is `efWhenStmt` anyway.
2024-03-14 11:23:09 +01:00
ringabout
7c11da3f22 fixes #23382; gives compiler errors for closure iterators in JS (#23398)
fixes #23382
follow up https://github.com/nim-lang/Nim/pull/15823
2024-03-14 11:12:29 +01:00
Juan M Gómez
78c834dd76 Fixes an issue where exported types werent being cgen with the exportc pragma (#23369) 2024-03-11 13:57:55 +01:00
Juan M Gómez
93399776c4 [C++] Allow member to define static funcs (#23387) 2024-03-11 12:10:43 +01:00
lit
94c5996877 Update tests/js/tos.nim, make isAbsolute tested on nodejs under Windows. (#23377)
Windows's nodejs `isAbsolute` issue has been resolved by [this
PR](https://github.com/nim-lang/Nim/pull/23365).

So we can improve the coverage for Windows.
2024-03-09 11:43:27 +01:00
ringabout
1e20165a15 fixes #22166; adds sideeffects for close and setFilePos (#23380)
fixes #22166
2024-03-09 11:43:00 +01:00
ringabout
320311182c fixes #22284; fixes #22282; don't override original parameters of inferred lambdas (#23368)
fixes #22284
fixes #22282


```
Error: j(uRef, proc (config: F; sources: auto) {.raises: [].} = discard ) can raise an unlisted exception: Exception
```


The problem is that `n.typ.n` contains the effectList which shouldn't
appear in the parameter of a function defintion. We could not simply use
`n.typ.n` as `n[paramsPos]`. The effect lists should be stripped away
anyway.
2024-03-09 11:42:15 +01:00
ringabout
f80a5a30b4 fixes #23378; fixes js abs negative int64 (#23379)
fixes #23378
2024-03-09 11:41:39 +01:00
ringabout
6ebad30e7a closes #22846; adds a test case (#23374)
closes #22846
2024-03-08 14:06:04 +08:00
ringabout
c2d2b6344d remove mention of GC_ref and GC_unref for strings (#23373) 2024-03-06 21:24:55 +01:00
ringabout
a2584c779b closes #15751; adds a test case (#23372)
closes #15751
2024-03-06 16:25:20 +08:00
ringabout
7cd3d60683 fixes #12703; nim cpp rejects valid code would lose const qualifier for cstring to string via cstrToNimstr (#23371)
fixes #12703
ref #19588
2024-03-05 18:06:58 +01:00
ringabout
d373d304ff closes #10219; adds a test case (#23370)
closes #10219
2024-03-05 16:39:20 +08:00
ringabout
e217bb24a1 fixes #20945; fixes #18262; provides C API NimDestroyGlobals for static/dynlib libraries (#23357)
fixes #20945
fixes #18262

todo
- [ ] perhaps export with lib prefix when the option is enabled
2024-03-04 10:14:25 +01:00
litlighilit
6e875cd7c2 fix isAbsolute broken when nodejs on Windows (#23365)
When target is nodejs, 
`isAbsolute` used to only check in the POSIX flavor,

i.e.  for js backend on Windows, 
```nim
isAbsolute(r"C:\Windows") == false
```

This fixes it.
2024-03-04 09:58:33 +01:00
Juan M Gómez
2081da3207 makes nimsuggest listen on localhost by default (#23351) 2024-03-04 09:58:06 +01:00
ringabout
a619434904 remove obselete doc with nimrtl (#23358)
since nimrtl.dll is created with `--threads:on`
2024-03-04 09:57:40 +01:00
ringabout
248850a0ce ref #23333; fixes AF_INET6 value on Linux (#23334)
ref #23333
2024-03-03 17:52:56 +01:00
Juan M Gómez
90fe1b340f Dont mangle when targeting cpp (#23335)
Unfortunately we cant trick the debugger when targeting C++ so this one
also needs to wait for our own debugger adapter.
2024-03-03 17:37:29 +01:00
litlighilit
79bd6fe084 Update browsers.nim, deprecate unimplemented openDefaultBrowser() (#23332)
For this
[proc](773c066634/lib/pure/browsers.nim (L83))
`proc openDefaultBrowser*() {.since: (1, 1).}`:

though it's documented to open default browser with `about:blank` page,
it behaves differently:

- On Windows, it failed and open no window
- On Linux(Debian with Kde), it opens not default browser but
`Konqueror`

I have paid much effort to implement this variant, but even the
implementation on Windows is considerably complex.

In short, it's not only hard but unworthy to fix this.

Just as Araq
[said](https://github.com/nim-lang/Nim/issues/22250#issuecomment-1631360617),

we shall remove the `proc openDefaultBrowser*() {.since: (1, 1).}`
variant

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2024-03-03 17:27:27 +01:00
autumngray
15577043e8 Fix nimsuggest highlight for import statements (#23263)
Currently, I don't have syntax highlighting (+ no/wrong
jump-to-definition) for some import statement forms, namely:

- `import module/name/with/(slashes)`
- `import (mod) as alias`
- `import basemod/[ (sub1), (sub2) ]`

With this patch, highlight/def will work for the regions indicated by
parentheses.
2024-03-03 16:05:11 +01:00
ringabout
aa30233ea7 fixes #23273; forbids methods having importc pragmas (#23324)
fixes #23273
2024-03-03 16:04:24 +01:00
ringabout
572b0b67ff fixes sink regression for ORC; ref #23354 (#23359)
ref #23354

The new move analyzer requires types that have the tfAsgn flag
(otherwise `lastRead` will return true); tfAsgn is included when the
destructor is not trival. But it should consider the assignement for
objects in this case because objects might have a trival destructors but
it's the assignement that matters when it is passed to sink parameters.
2024-03-03 16:03:53 +01:00
ringabout
31d7554524 fixes #13481; fixes #22708; disable using union objects in VM (#23362)
fixes #13481;
fixes #22708

Otherwise it gives implicit results or bad codegen
2024-03-03 15:56:06 +01:00
heterodoxic
f4fe3af42a make use of C++11's auto type deduction for temporary variables (#23327)
This is just one of those tiny steps towards the goal of an "optimized"
C and C++ codegen I raised elsewhere before - what does me babbling
"optimized" mainly entail?

(not mutually-exclusive ascertainment proposals following:)

- less and simplified resulting code: easier to pick up/grasp for the
C/C++ compiler for to do its own optimization heuristics, less parsing
effort for us mere humans trying to debug, especially in the case of
interop
- build time reduction: less code emission I/O, runtime string
formatting for output...
- easier access for fresh contributors and better maintainability
- interop improvements
- further runtime optimizations

I am eagerly looking forward to the results of the LLVM-based
undertakings, but I also think we can do a bit better (as outlined
above) with our current C/C++ backends till those come to fruition.

**Long story short**: this PR here focuses on the C++ backend,
augmenting the current codegen method of establishing "temporary"
variables by using C++11's auto type deduction. The reasons for adopting
an "Almost Always Auto" style have been collected [here
](https://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/)
for the C++ world. For those hopping between C++'s and Nim's realms,
this change also results in a bit less code and less work for the
codegen part (no redundant `getTypeDesc`s): no need to tell the C++
compiler the type it already knows of (in most cases).
2024-03-03 15:53:23 +01:00