Commit Graph

21643 Commits

Author SHA1 Message Date
Juan M Gómez
ca577dbab1 C++: ptr fields now pulls the whole type if it's a member in nkDotExpr (#22855) 2023-10-23 08:59:14 +02:00
SirOlaf
c13c48500b Fix #22826: Don't skip generic instances in type comparison (#22828)
Close #22826

I am not sure why this code skips generic insts, so letting CI tell me.
Update: It has told me nothing. Maybe someone knows during review.

Issue itself seems to be that the generic instance is skipped thus it
ends up being just `float` which makes it use the wrong generic instance
of the proc because it matches the one in cache

---------

Co-authored-by: SirOlaf <>
2023-10-21 22:00:16 +02:00
Vindaar
2b1a671f1c explicitly import using std/ in tempfiles.nim (#22851)
At least on modern Nim `tempfiles` is not usable if the user has
https://github.com/oprypin/nim-random installed, because the compiler
picks the nimble path over the stdlib path (apparently).
2023-10-20 19:04:01 +02:00
ringabout
e10878085e fixes #22844; uses arrays to store holeyenums for iterations; much more efficient than sets and reasonable for holeyenums (#22845)
fixes #22844
2023-10-20 18:38:42 +02:00
rockcavera
27deacecaa fix #22834 (#22843)
fix #22834

Edit: also fixes `result.addrList` when IPv6, which previously only
performed a `result.addrList = cstringArrayToSeq(s.h_addr_list)` which
does not provide the textual representation of an IPv6
2023-10-20 09:43:53 +02:00
Juan Carlos
05a7c0fdd0 Bisect default Linux (#22840)
- Bisect default to Linux only. Tiny diff, YAML only.

| OS | How to? |
|----|---------|
| Linux | `-d:linux` |
| Windows | `-d:windows` |
| OS X | `-d:osx` |

If no `-d:linux` nor `-d:windows` nor `-d:osx` is used then defaults to
Linux.
2023-10-18 20:12:50 -04:00
ringabout
0d4b3ed18e fixes #22836; Unnecessary warning on 'options.none' with 'strictDefs'… (#22837)
… enabled

fixes #22836
2023-10-18 22:44:13 +08:00
Andreas Rumpf
3c48af7ebe NIR: temporary ID generation bugfix (#22830) 2023-10-16 15:47:13 +02:00
Juan M Gómez
a9bc6779e1 the compiler can be compiled with vcc (#22832) 2023-10-16 15:36:39 +02:00
ringabout
078495c793 closes #16919; followup #16820, test tsugar on all backends (#22829)
closes #16919
followup #16820
2023-10-16 12:44:55 +08:00
Andreas Rumpf
10c3ab6269 NIR: store sizes, alignments and offsets in the type graph; beginning… (#22822)
…s of a patent-pending new VM
2023-10-16 00:01:33 +02:00
Himaj Patil
5f400983d5 Update readme.md (#22827)
Added table view in Compiling section of documentation
2023-10-15 21:29:16 +02:00
ringabout
f5d70e7fa7 fixes #19250; fixes #22259; ORC AssertionDefect not containsManagedMemory(n.typ) (#22823)
fixes #19250
fixes #22259

The strings, seqs, refs types all have this flag, why should closures be
treated differently?

follow up https://github.com/nim-lang/Nim/pull/14336
2023-10-13 21:34:13 +02:00
ringabout
61145b1d4b fixes #22354; Wrong C++ codegen for default parameter values in ORC (#22819)
fixes #22354

It skips `nkHiddenAddr`. No need to hoist `var parameters` without side
effects. Besides, it saves lots of temporary variables in ORC.
2023-10-13 10:58:43 +02:00
Andreas Rumpf
8990626ca9 NIR: progress (#22817)
Done:

- [x] Implement conversions to openArray/varargs.
- [x] Implement index/range checking.
2023-10-12 23:33:38 +02:00
ringabout
d790112ea4 update nimble (#22814)
Issues like https://github.com/nim-lang/nimble/issues/1149 keep popping
up. One way or another, we should alleviate the pain.

Finally, we should consider
https://github.com/nim-lang/nimble/pull/1141#discussion_r1316829521 as
an option using some kind of cron script to update
https://nim-lang.org/nimble/packages.json. It's turning into a really
annoying problem.
2023-10-11 21:06:25 +02:00
SirOlaf
68ba45cc04 Import std/stackframes in ast2ir.nim (#22815)
Ref https://github.com/nim-lang/Nim/pull/22777#issuecomment-1758090410

Co-authored-by: SirOlaf <>
2023-10-11 21:05:51 +02: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
ecaccafa6c fixes #22790; use cast suppress AnyEnumConv warnings for enums withou… (#22813)
…t holes

fixes #22790
2023-10-11 17:18:54 +02:00
ringabout
9d7acd001f use lent for the return value of index accesses of tables (#22812)
ref https://forum.nim-lang.org/t/10525
2023-10-11 15:14:12 +02:00
ringabout
14d25eedfd suppress incorrect var T destructor warnings for newFinalizer in stdlib (#22810)
in `std/nre`
```nim
proc initRegex(pattern: string, flags: int, study = true): Regex =
  new(result, destroyRegex)
```
gives incorrect warnings like

```
C:\Users\blue\Documents\Nim\lib\impure\nre.nim(252, 6) Error: A custom '=destroy' hook which takes a 'var T' parameter is deprecated; it should take a 'T' parameter [Deprecated
```
2023-10-11 13:27:22 +02:00
ringabout
2cf214d6d4 allows cast int to bool/enum in VM (#22809)
Since they are integer types, by mean of allowing cast integer to enums
in VM, we can suppress some enum warnings in the stdlib in the unified
form, namely using a cast expression.
2023-10-11 12:06:42 +02:00
Juan M Gómez
bf72d87f24 adds support for noDecl in constructor (#22811)
Notice the test wouldnt link before
2023-10-11 08:28:00 +02:00
ringabout
81b2ae747e fixes #8893; guard against array access in renderer (#22807)
fixes #8893
2023-10-09 15:36:56 +02:00
Juan M Gómez
8ac466980f marking a field with noInit allows to skip constructor initialiser (#22802)
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-10-08 23:51:44 +02:00
Juan M Gómez
c3774c8821 fixes nimsuggest false error on lifetime tracking hook fixes #22794 (#22805)
fixes #22794

Not sure if it's too much.
2023-10-08 20:22:35 +02:00
Matt Rixman
5bcea05caf Add getCursorPos() to std/terminal (#22749)
This would be handy for making terminal apps which display content below
the prompt (e.g. `fzf` does this).

Need to test it on windows before I remove "draft" status.

---------

Co-authored-by: Matt Rixman <MatrixManAtYrService@users.noreply.github.com>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-10-08 18:56:18 +02:00
ringabout
efa64aa49b fixes #22787; marks var section in the loop as reassign preventing cursor (#22800)
fixes #22787

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-10-07 07:43:39 +02:00
Levi Notik
f111009e5d Fix typo/grammar in exception tracking section (#22801)
I came across this sentence in the Nim Manual and couldn't make sense of
it. I believe this is the correct fix for the sentence.

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2023-10-07 07:43:17 +02:00
ringabout
476492583b remove the O(n*n) addUnique one from std (#22799)
It's not used in the compiler, besides, it doesn't seem to be a common
operation. Follows the discussion on the Discord.
2023-10-06 22:39:32 +02:00
ringabout
f2f0b3e25d fixes #22711; Check atomicArc for atomic destroy race condition (#22788)
fixes #22711

Per @elcritch's awesome solution
2023-10-04 19:41:39 +02:00
ringabout
f4a623dadf document atomicInc and atomicDec (#22789) 2023-10-04 16:00:41 +02:00
ringabout
1a6ca0c604 arraymancer switches to the offical URL (#22782) 2023-10-03 18:46:41 +08:00
Pylgos
db36765afd nimsuggest: Clear generic inst cache before partial recompilation (#22783)
fixes #19371
fixes #21093
fixes #22119
2023-10-03 10:22:31 +02:00
ringabout
5d5c39e745 fixes #22778 regression: contentLength implementation type mismatched (#22780)
fixes #22778
follow up https://github.com/nim-lang/Nim/pull/19835
2023-10-03 11:00:24 +08:00
ringabout
642ac0c1c3 fixes #22753; Nimsuggest segfault with invalid assignment to table (#22781)
fixes #22753

## Future work
We should turn all the error nodes into nodes of a nkError kind, which
could be a industrious task. But perhaps we can add a special treatment
for error nodes to make the transition smooth.
2023-10-02 14:45:04 -04:00
CMD
49df69334e Fix IndexDefect in asyncfile.readLine (#22774)
`readLine` proc in asyncfile module caused IndexDefect when it reached
EoF. Now it returns empty string instead.
2023-10-01 07:20:43 +02:00
Juan Carlos
b60f15e0dc copyFile with POSIX_FADV_SEQUENTIAL (#22776)
- Continuation of https://github.com/nim-lang/Nim/pull/22769
- See
https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fadvise.html
- The code was already there in `std/posix` since years ago. 3 line
diff.

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-10-01 07:19:37 +02:00
daylin
c3b95cbd2c docs: add another switch example for nimscript (#22772)
I couldn't find any documentation on the syntax for --hint:X:on|off with
`nimscript` except in [this old forum
post](https://forum.nim-lang.org/t/8526#55236).
2023-09-30 14:53:09 +02:00
Ryan McConnell
b2ca6bedae Make typeRel behave to spec (#22261)
The goal of this PR is to make `typeRel` accurate to it's definition for
generics:
```
# 3) When used with two type classes, it will check whether the types
# matching the first type class (aOrig) are a strict subset of the types matching
# the other (f). This allows us to compare the signatures of generic procs in
# order to give preferrence to the most specific one:
```

I don't want this PR to break any code, and I want to preserve all of
Nims current behaviors. I think that making this more accurate will help
serve as ground work for the future. It may not be possible to not break
anything but this is my attempt.

So that it is understood, this code was part of another PR (#22143) but
that problem statement only needed this change by extension. It's more
organized to split two problems into two PRs and this issue, being
non-breaking, should be a more immediate improvement.

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-09-30 06:34:14 +02:00
ringabout
7146307823 fixes #22554; makes newSeqWith use newSeqUninit (#22771)
fixes #22554
2023-09-30 06:32:27 +02:00
Juan Carlos
a38e3dcb1f copyFile with bufferSize instead of hardcoded value (#22769)
- `copyFile` allows to specify `bufferSize` instead of hardcoded wrong
value. Tiny diff.


# Performance

- 1200% Performance improvement.


# Check it yourself

Execute:

```bash
for i in $(seq 0 10); do
  bs=$((1024*2**$i))
  printf "%7s Kb\t" $bs
  timeout --foreground -sINT 2 dd bs=$bs if=/dev/zero of=/dev/null 2>&1 | sed -n 's/.* \([0-9.,]* [GM]B\/s\)/\1/p'
done
```

(This script can be ported to PowerShell for Windows I guess, it works
in Windows MinGW Bash anyways).


# Stats

- Hardcoded `8192` or `8000` Kb bufferSize gives `5` GB/s.
- Setting `262144` Kb bufferSize gives `65` GB/s (script suggestion).

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-09-30 06:31:28 +02:00
ringabout
5eeafbf550 fixes #22696; func strutils.join for non-strings uses proc $ which can have side effects (#22770)
fixes #22696
partially revert https://github.com/nim-lang/Nim/pull/16281

`join` calls `$` interally, which might introduce a sideeffect call.
2023-09-30 06:27:27 +02:00
Juan M Gómez
0c179db657 case macro now can be used inside generic. Fixes #20435 (#22752)
fixes #20435

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
Co-authored-by: Jake Leahy <jake@leahy.dev>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-09-30 06:27:02 +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
ringabout
8761599aad fixes #22763; nimcache in nim.cfg uses the relative path to the config file (#22764)
fixes #22763
2023-09-28 18:09:58 +02:00
Juan M Gómez
4fffa0960f C++ Adds support for default arg using object construction syntax. Fixes a compiler crash (#22768)
`Foo()` below makes the compiler crash. 
```nim

proc makeBoo(a:cint = 10, b:cstring = "hello", foo: Foo = Foo()): Boo {.importcpp, constructor.}

```
2023-09-28 18:08:42 +02:00
ringabout
285cbcb6aa ref #19727; implement setLenUninit for seqsv2 (#22767)
ref #19727
2023-09-28 18:08:31 +02:00
Thiago
4bf0f846df Removed localStorage.hasKey binding (#22766)
Doesn't exists anymore.

Use `window.localStorage.getItem("key").isNil` instead

![Screenshot from 2023-09-28
07-22-41](https://github.com/nim-lang/Nim/assets/74574275/65d58921-58c7-4a81-9f3b-5faa3a79c4f2)
2023-09-28 11:30:04 +02:00
Juan Carlos
f0865fa696 Fix #21407 (#22759)
- Fix #21407

---------

Co-authored-by: Amjad Ben Hedhili <amjadhedhili@outlook.com>
2023-09-28 07:37:09 +02:00