Commit Graph

6315 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
3bdb531f90 fixes testament targets field (#23472) 2024-04-03 11:33:56 +08: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
Juan M Gómez
33902d9dbb [Cpp] Fixes an issue when mixing hooks and calls (#23428) 2024-03-21 08:48:14 +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
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
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
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
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
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
Jacek Sieka
a1e41930f8 strformat: detect format string errors at compile-time (#23356)
This also prevents unwanted `raises: [ValueError]` effects from bubbling
up from correct format strings which makes `fmt` broadly unusable with
`raises`.

The old runtime-based `formatValue` overloads are kept for
backwards-compatibility, should anyone be using runtime format strings.

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2024-03-03 15:40:53 +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
ringabout
6ce6cd4bb8 fixes #22723; skips tyUserTypeClasses in injectdestructors (#23341)
fixes #22723
2024-02-24 07:39:56 +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
ringabout
39f2df1972 fixes #23295; don't expand constants for complex structures (#23297)
fixes #23295
2024-02-20 07:31:58 +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
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
Tomohiro
befb383ac8 fixes #23275; Add == for Deque (#23276) 2024-02-08 22:18:52 +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
3550c907de closes #14710; adds a test case (#23277)
closes #14710
2024-02-05 22:46:51 +08: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
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
ringabout
d44b0b1869 fixes #22597; avoid side effects for call returning openArray types (#23257)
fixes #22597

```nim
proc autoToOpenArray*[T](s: Slice[T]): openArray[T] =
  echo "here twice"
  result = toOpenArray(s.p, s.first, s.last)
```
For functions returning openarray types, `fixupCall` creates a temporary
variable to store the return value: `let tmp = autoToOpenArray()`. But
`genOpenArrayConv` cannot handle openarray assignements with side
effects. It should have stored the right part of the assignment first
instead of calling the right part twice.
2024-01-26 06:06:08 +01:00
Jake Leahy
06b9e603bc Show error when trying to run in folder that doesn't exist instead of assertion (#23242)
Closes #23240

Fixes regression caused by #23017
2024-01-23 22:35:52 +01:00
metagn
ee984f8836 account for nil return type in tyProc sumGeneric (#23250)
fixes #23249
2024-01-23 22:00:34 +01:00
ringabout
720021908d fixes #23233; Regression when using generic type with Table/OrderedTable (#23235)
fixes #23233
2024-01-19 20:37:16 +01:00
Bung
01097fc1fc fix mime types data (#23226)
generated via https://github.com/bung87/mimetypes_gen

source data:
http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=co
2024-01-19 13:11:01 +01:00
ringabout
b2f79df81c fixes #22218; avoids cursor when copy is disabled (#23209)
fixes #22218
2024-01-18 21:47:13 +01:00
ringabout
3fb46fac32 fixes #12334; keeps nkHiddenStdConv for cstring conversions (#23216)
fixes #12334

`nkHiddenStdConv` shouldn't be removed if the sources aren't literals,
viz. constant symbols.
2024-01-18 21:31:49 +01:00
metagn
cfd69bad1a fix wrong subtype relation in tuples & infer some conversions (#23228)
fixes #18125

Previously a tuple type like `(T, int)` would match an expected tuple
type `(U, int)` if `T` is a subtype of `U`. This is wrong since the
codegen does not handle type conversions of individual tuple elements in
a type conversion of an entire tuple. For this reason the compiler
already does not accept `(float, int)` for a matched type `(int, int)`,
however the code that checked for which relations are unacceptable
checked for `< isSubtype` rather than `<= isSubtype`, so subtypes were
not included in the unacceptable relations.

Update: Now only considered unacceptable when inheritance is used, as in
[`paramTypesMatch`](3379d26629/compiler/sigmatch.nim (L2252-L2254)).
Ideally subtype relations that don't need conversions, like `nil`,
`seq[empty]`, `range[0..5]` etc would be their own relation
`isConcreteSubtype` (which would also allow us to differentiate with
`openArray[T]`), but this is too big of a refactor for now.

To compensate for this making things like `let x: (Parent, int) =
(Child(), 0)` not compile (they would crash codegen before anyway but
should still work in principle), type inference for tuple constructors
is updated such that they call `fitNode` on the fields and their
expected types, so a type conversion is generated for the individual
subtype element.
2024-01-18 21:19:29 +01:00
metagn
3ab8b6b2cf error on large integer types as array index range (#23229)
fixes #17163, refs #23204

Types that aren't `tyRange` and are bigger than 16 bits, so `int32`,
`uint64`, `int` etc, are disallowed as array index range types.
`tyRange` is excluded because the max array size is backend independent
(except for the specific size of `high(uint64)` which crashes the
compiler) and so there should still be an escape hatch for people who
want bigger arrays.
2024-01-18 21:14:27 +01:00
metagn
3224337550 give typedesc param nodes type T not typedesc[T] [backport:2.0] (#23115)
fixes https://github.com/nim-lang/Nim/issues/23112, fixes a mistake in
https://github.com/nim-lang/Nim/pull/22581

This makes `getType(t)` where `t` is a typedesc param with value `T`
equal to `getType(T)`.
2024-01-18 14:50:36 +01:00
Giuliano Mega
473f259268 Fix reset code gen for range types (#22462, #23214) (#23215)
This PR modifies `specializeResetT` so that it generates the proper
reset code for range types. I've tested it in the examples for issues
#23214 and #22462 as well as our codebase, and it seems to fix the
issues I had been experiencing.
2024-01-18 14:40:22 +01:00
ringabout
3379d26629 fixes #23223; prevents insert self-assignment (#23225)
fixes #23223
2024-01-18 14:20:54 +01:00
metagn
f46f26e79a don't use previous bindings of auto for routine return types (#23207)
fixes #23200, fixes #18866

#21065 made it so `auto` proc return types remained as `tyAnything` and
not turned to `tyUntyped`. This had the side effect that anything
previously bound to `tyAnything` in the proc type match was then bound
to the proc return type, which is wrong since we don't know the proc
return type even if we know the expected parameter types (`tyUntyped`
also [does not care about its previous bindings in
`typeRel`](ab4278d217/compiler/sigmatch.nim (L1059-L1061))
maybe for this reason).

Now we mark `tyAnything` return types for routines as `tfRetType` [as
done for other meta return
types](18b5fb256d/compiler/semtypes.nim (L1451)),
and ignore bindings to `tyAnything` + `tfRetType` types in `semtypinst`.
On top of this, we reset the type relation in `paramTypesMatch` only
after creating the instantiation (instead of trusting
`isInferred`/`isInferredConvertible` before creating the instantiation),
using the same mechanism that `isBothMetaConvertible` uses.

This fixes the issues as well as making the disabled t15386_2 test
introduced in #21065 work. As seen in the changes for the other tests,
the error messages give an obscure `proc (a: GenericParam): auto` now,
but it does give the correct error that the overload doesn't match
instead of matching the overload pre-emptively and expecting a specific
return type.

tsugar had to be changed due to #16906, which is the problem where
`void` is not inferred in the case where `result` was never touched.
2024-01-17 11:59:54 +01:00
ringabout
ab4278d217 fixes #23180; fixes #19805; prohibits invalid tuple unpacking code in for loop (#23185)
fixes #23180
fixes #19805
2024-01-13 14:09:34 +01:00
ringabout
8484abc2e4 fixes #15924; Tuple destructuring is broken with closure iterators (#23205)
fixes #15924
2024-01-13 12:00:55 +01:00
metagn
6650b41777 document the new ambiguous identifier resolution (#23166)
refs #23123

Not sure if detailed enough.
2024-01-11 12:39:51 +01:00
ringabout
29ac3c9986 fixes #22923; fixes =dup issues (#23182)
fixes #22923
2024-01-11 11:23:42 +01:00
ringabout
62c5b8b287 fixes #23129; fixes generated hooks raise unlisted Exception, which never raise (#23195)
fixes #23129
2024-01-11 07:47:33 +01:00