Commit Graph

8103 Commits

Author SHA1 Message Date
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
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
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
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
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
Andreas Rumpf
7657a637b8 refactoring: no inheritance for PType/PSym (#23403) 2024-03-14 19:23:18 +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
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
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
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
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
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
Andreas Rumpf
24fbacc63f fixes an issue with string to 'var openArray' at compile-time; [backp… (#23363)
…ort]
2024-03-03 15:40:08 +01:00
ringabout
1e7ca2dc78 improve error messages [backport] (#23345)
ref https://forum.nim-lang.org/t/11052


![image](https://github.com/nim-lang/Nim/assets/43030857/1df87691-32d9-46b5-b61b-6b9f7cc94862)
2024-02-26 17:24:16 +01:00
Juan M Gómez
93a8b85a91 fixes #23306 nim cpp -r invalid code generation regression with closure iterators and try/catch-like constructions (#23317) 2024-02-26 11:21:03 +01:00
Nikolay Nikolov
37ed8c8480 * fixed nimsuggest crash with 'Something = concept' put (erroneously) outside of a 'type' block (#23331) 2024-02-24 07:55:23 +01:00
ringabout
6ce6cd4bb8 fixes #22723; skips tyUserTypeClasses in injectdestructors (#23341)
fixes #22723
2024-02-24 07:39:56 +01:00
litlighilit
248bdb276a compiler/ast.nim: fix a typo (#23340)
constains -> constrains

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2024-02-23 20:11:27 +08:00
Juan M Gómez
09580eeec9 Fixes #23337; When NimScript errors prevents NimSuggest from Init (#23338) 2024-02-22 14:56:45 +01:00
Nikolay Nikolov
773c066634 * fixed nimsuggest crash when opening a .nim file, that contain a {.fatal: "msg".} pragma. (#23325) 2024-02-20 08:11:08 +01:00
Ryan McConnell
ca77423ffc varargs[typed] should behave more like typed (#23303)
This fixes an oversight with a change that I made a while ago.

Basically, these two snippets should both compile. Currently the
`varargs` version will fail.

```nim
template s(d: typed)=discard
proc something()=discard
proc something(x:int)=discard

s(something)
```

```nim
template s(d: varargs[typed])=discard
proc something()=discard
proc something(x:int)=discard

s(something)
```

Potentially unrelated, but this works currently for some reason:
```nim
template s(a: varargs[typed])=discard
proc something()=discard
proc something(x:int)=discard

s:
  something
```

also, this works:
```nim
template s(b:untyped, a: varargs[typed])=discard
proc something()=discard
proc something(x:int)=discard

s (g: int):
  something
```
but this doesn't, and the error message is not what I would expect:
```nim
template s(b:untyped, a: varargs[typed])=discard
proc something()=discard
proc something(x:int)=discard

s (g: int), something
```

So far as I can tell, none of these issues persist for me after the code
changes in this PR.
2024-02-20 08:08:16 +01:00
Juan M Gómez
7bf8cd3f86 Fixes a nimsuggest crash when using chronos (#23293)
The following would crash nimsuggest on init:
```nim
import chronos
type
  HistoryQuery = object
    start: int
    limit: int

  HistoryResult = object
    messages: string

type HistoryQueryHandler* = proc(req: HistoryQuery): Future[HistoryResult] {.async, gcsafe.}
```
2024-02-20 07:36:50 +01:00
ringabout
39f2df1972 fixes #23295; don't expand constants for complex structures (#23297)
fixes #23295
2024-02-20 07:31:58 +01:00
heterodoxic
9a46230335 assume a module's usage if it contains a passC/passL/compile pragma w… (#23323)
…hich conveys effects beyond its module scope for C/C++
codegen(suppresses current UnusedImport warning)

Just a minor inconvenience working in the area of C/C++ integration I
guess, but here we go:

I noticed receiving ```UnusedImport``` warnings for modules having only
```passC```/```passL```/```compile``` pragmas around. I gather the
compiler cannot actually infer those modules being unused as they *may*
have consequences for the whole build process (as they did in my simple
case).

Thus, I hereby suggest adding the `sfUsed` flag to the respective module
in order to suppress the compiler's warning.

I reckon other pragmas should be put into consideration as well: I will
keep up the investigation with PR followups.
2024-02-19 20:59:14 +01:00
ringabout
35ec9c31bd fixes refc with non-var destructor; cancel warnings (#23156)
fixes https://forum.nim-lang.org/t/10807
2024-02-13 08:11:49 +01:00
ringabout
1e9a3c438b fixes #18104; tranform one liner var decl before templates expansion (#23294)
fixes #18104
2024-02-13 08:10:28 +01:00
Juan M Gómez
a8c168c168 fixes a nimsuggest crash on init (#23300) 2024-02-11 07:54:36 +01:00
Juan M Gómez
ae2cdcebc2 nimsuggest --ic:on compiles (#23298) 2024-02-09 18:45:01 +01:00
Juan M Gómez
a45f43da34 MangleProcs following the Itanium spec so they are demangled in the debugger call stack (#23260)
![image](https://github.com/nim-lang/Nim/assets/1496571/0d796c5b-0bbf-4bb4-8c95-c3e3cce22f15)

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2024-02-09 13:23:36 +01:00
ringabout
4b67cccf50 fixes regression #23280; Operations on inline toOpenArray len return a wrong result (#23285)
fixes #23280
2024-02-06 06:24:02 +01:00
ringabout
7d9721007c fixes regression #22909; don't optimize result init if statements can raise which corrupts the compiler (#23271)
fixes #22909
required by https://github.com/nim-lang/Nim/pull/23267

```nim
proc foo: string =
  assert false
  result = ""
```

In the function `foo`, `assert false` raises an exception, which can
cause `result` to be uninitialized if the default result initialization
is optimized out
2024-02-01 16:51:07 +01:00
ringabout
519d976f62 compute checksum of nim files early in the pipelines (#23268)
related https://github.com/nim-lang/Nim/issues/21717 configs will be
resolved later
2024-01-31 21:36:59 +01:00
ringabout
98b083d750 minor fixes for std prefix in the compiler (#23269) 2024-01-30 17:03:02 +01:00
ringabout
f7c6e04cfb fixes #19977; rework inlining of 'var openarray' iterators for C++ (#23258)
fixes #19977
2024-01-26 12:46:39 +01:00
ringabout
24a606902a fixes #23247; don't destroy openarray since it doesn't own the data (#23254)
fixes #23247
closes #23251 (which accounts for why the openarray type is lifted
because ops are lifted for openarray conversions)

related: https://github.com/nim-lang/Nim/pull/18713

It seems to me that openarray doesn't own the data, so it cannot destroy
itself. The same case should be applied to
https://github.com/nim-lang/Nim/issues/19435. It shouldn't be destroyed
even openarray can have a destructor. A cleanup will be followed for
https://github.com/nim-lang/Nim/pull/19723 if it makes sense.

According to https://github.com/nim-lang/Nim/pull/12073, it lifts
destructor for openarray when openarray is sunk into the function, when
means `sink openarray` owns the data and needs to destroy it. In other
cases, destructor shouldn't be lifted for `openarray` in the first place
and it shouldn't destroy the data if it doesn't own it.

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2024-01-26 08:04:16 +01:00