summary refs log tree commit diff stats
Commit message (Collapse)AuthorAgeFilesLines
...
* fixes rst parsing Markdown CodeblockFields blocking the loop (#24128)ringabout2024-09-182-1/+13
| | | | | | | | | ```nim import packages/docutils/[rst, rstgen] let message = """```llvm-profdata""" echo rstgen.rstToHtml(message, {roSupportMarkdown}, nil) ```
* revert second argument of `inc` not being generic (#24129)metagn2024-09-173-5/+11
| | | | refs #22328, fixes regression in https://forum.nim-lang.org/t/12465#76998
* fix segfault in effect tracking for sym node with nil type (#24114)metagn2024-09-172-1/+20
| | | | | | | | | | | | | | | | | | | | | | | | | fixes #24112 Sym nodes in templates that could be open are [given `nil` type](https://github.com/nim-lang/Nim/blob/22d2cf217597468ace8ba540d6990b1f6d8a816a/compiler/semtempl.nim#L274) when `--experimentalOpenSym` is disabled so that they can be semchecked to give a warning since #24007. The first nodes of object constructors (in this case) and in type conversions don't replace their first node (the symbol) with a typechecked one, they only call `semTypeNode` on it and leave it as is. Effect tracking checks if the type of a sym node has a destructor to check if the node type should be replaced with the sym type. But this causes a segfault when the type of the node is nil. To fix this, we always set the node type to the sym type if the node type is nil. Alternatively `semObjConstr` and `semConv` could be changed to set the type of their first node to the found type but I'm not sure if this would break anything. They could call `semExprWithType` on the first node but `semTypeNode` would still have to be called (maybe call it before?). This isn't a problem if the sym node has a type but is just nested in `nkOpenSym` or `nkOpenSymChoice` which have nil type instead (i.e. with openSym enabled), so maybe this still is the "most general" solution, I don't know.
* remove nimfrs and varslot (#24126)ringabout2024-09-172-18/+4
| | | | | | | was introduced for debugger https://github.com/nim-lang/Nim/commit/b63f322a466351bc57f8a4593009f0520c348527#diff-abd3a10386cf1ae32bfd3ffae82335a1938cc6c6d92be0ee492fcb44b9f2b552 https://github.com/nim-lang/Nim/blob/b63f322a466351bc57f8a4593009f0520c348527/lib/system/debugger.nim
* make distinct conversions addressable in VM (#24124)metagn2024-09-172-10/+65
| | | | | | | | | | | | | | | | fixes #24097 For `nkConv` addresses where the conversion is between 2 types that are equal between backends, treat assignments the same as assignments to the argument of the conversion. In the VM this seems to be in `genAsgn` and `genAsgnPatch`, as evidenced by the special logic for `nkDerefExpr` etc. This doesn't handle ranges after #24037 because `sameBackendType` is used and not `sameBackendTypeIgnoreRange`. This is so this is backportable without #24037 and another PR can be opened that implements it for ranges and adds tests as well. We can also merge `sameBackendTypeIgnoreRange` with `sameBackendType` since it doesn't seem like anything that uses it would be affected (only cycle checks and the VM), but then we still have to add tests.
* don't match arguments with typeclass type in generics (#24123)metagn2024-09-173-0/+25
| | | | | | | | | | | | | | fixes #24121 Proc arguments can have typeclass type like `Foo | Bar` that `sigmatch` handles specially before matching them to the param type, because they wouldn't match otherwise. Not exactly sure why this existed but matching any typeclass or unresolved type in generic contexts now fails the match so typing the call is delayed until instantiation. Also it turns out default values with `tyFromExpr` type depending on other parameters was never tested, this also needs a patch to make the `tyFromExpr` type `tfNonConstExpr` so it doesn't try to evaluate the other parameter at compile time.
* test case haul before 2.2 (#24119)metagn2024-09-1716-0/+281
| | | | | closes #4774, closes #7385, closes #10019, closes #12405, closes #12732, closes #13270, closes #13799, closes #15247, closes #16128, closes #16175, closes #16774, closes #17527, closes #20880, closes #21346
* Fixes #23624 "nim check crash" (#23625)Juan M Gómez2024-09-163-38/+54
|
* minor improvement (#24113)ringabout2024-09-161-2/+1
|
* disable closure iterator changes in #23787 unless `-d:nimOptIters` is ↵metagn2024-09-165-36/+150
| | | | | | | | | | | | | | enabled (#24108) refs #24094, soft reverts #23787 #23787 turned out to cause issues as described in #24094, but the changes are still positive, so it is now only enabled if compiling with `-d:nimOptIters`. Unfortunately the changes are really interwoven with each other so the checks for this switch in the code are a bit messy, but searching for `nimOptIters` should give the necessary clues to remove the switch properly later on. Locally tested that nimlangserver works but others can also check.
* fixes #24109; gdb.SYMBOL_FUNCTION_DOMAIN (#24110)ringabout2024-09-161-5/+5
| | | fixes #24109
* bumps nimble to `0.16.1` (#24102)Juan M Gómez2024-09-151-1/+1
|
* minor: export dllOverrides (#24106)ringabout2024-09-141-1/+1
|
* fix regression with uint constant losing abstract type (#24105)metagn2024-09-142-1/+7
| | | | | | | | fixes #24104, refs #23955 The line `result.typ = dstTyp` added in #23955 changes the type of `result`, which was the type of `n` due to the argument passed to `newIntNodeT`, to the abstract type skipped `dstTyp`. The line is removed to just keep the type as abstract.
* fix calls to untyped arbitrary expressions in generics (#24100)metagn2024-09-134-5/+50
| | | | | | | | | | | | | | | | | | | | fixes #24099 If an arbitrary expression without a proc type (in this case `tyFromExpr`) is called, the compiler [passes it to overload resolution](https://github.com/nim-lang/Nim/blob/793cee4de1934fd1f6271cf5fed46f01c5abb19b/compiler/semexprs.nim#L1223). But overload resolution also can't handle arbitrary expressions and treats them as not participating at all, matching with the state `csEmpty`. The compiler checks for this and gives an "identifier expected" error. Instead, now if we are in a generic context and an arbitrary expression call matched with `csEmpty`, we now return `csNoMatch` so that `semResolvedCall` can leave it untyped as appropriate. The expression flag `efNoDiagnostics` is replaced with this check. It's not checked anywhere else and the only place that uses it is `handleCaseStmtMacro`. Replacing it with `efNoUndeclared`, we just get `csEmpty` instead of `csNoMatch`, which is handled the same way here. So `efNoDiagnostics` is now removed and `efNoUndeclared` is used instead.
* treat generic body type as atomic in iterOverType (#24096)metagn2024-09-112-1/+15
| | | | | | | | | | | | | | | | | follows up #24095 In #24095 a check was added that used `iterOverType` to check if a type contained unresolved types, with the aim of always treating `tyGenericBody` as resolved. But the body of the `tyGenericBody` is also iterated over in `iterOverType`, so if the body of the type actually used generic parameters (which isn't the case in the test added in #24095, but is now), the check would still count the type as unresolved. This is handled by not iterating over the children of `tyGenericBody`, the only users of `iterOverType` are `containsGenericType` and `containsUnresolvedType`, the first one always returns true for `tyGenericBody` and the second one aims to always return false. Unfortunately this means `iterOverType` isn't as generic of an API anymore but maybe it shouldn't be used anymore for these procs.
* make sigmatch use prepareNode for tyFromExpr (#24095)metagn2024-09-115-5/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fixes regression remaining after #24092 In #24092 `prepareNode` was updated so it wouldn't try to instantiate generic type symbols (like `Generic` when `type Generic[T] = object`, and `prepareNode` is what `tyFromExpr` uses in most of the compiler. An exception is in sigmatch, which is now changed to use `prepareNode` to make generic type symbols work in the same way as usual. However this requires another change to work: Dot fields and matches to `typedesc` on generic types generate `tyFromExpr` in generic contexts since #24005, including generic type symbols. But this means when we try to instantiate the `tyFromExpr` in sigmatch, which increases `c.inGenericContext` for potentially remaining unresolved expressions, dotcalls stay as `tyFromExpr` and so never match. To fix this, we change the "generic type" check in dot fields and `typedesc` matching to an "unresolved type" check which excludes generic body types; and for generic body types, we only generate `tyFromExpr` if the dot field is a generic parameter of the generic type (so that it gets resolved only at instantiation). Notes for the future: * Sigmatch shouldn't have to `inc c.inGenericContext`, if a `tyFromExpr` can't instantiate it's fine if we just fail the match (i.e. redirect the instantiation errors from `semtypinst` to a match failure). Then again maybe this is the best way to check for inability to instantiate. * The `elif c.inGenericContext > 0 and t.containsUnresolvedType` check in dotfields could maybe be simplified to just checking for `tyFromExpr` and `tyGenericParam`, but I don't know if this is an exhaustive list.
* implement template default values using other params (#24073)metagn2024-09-115-1/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | fixes #23506 #24065 broke compilation of template parameter default values that depended on other template parameters. But this was never implemented anyway, actually attempting to use those default values breaks the compiler as in #23506. So these are now implemented as well as fixing the regression. First, if a default value expression uses any unresolved arguments (generic or normal template parameters) in a template header, we leave it untyped, instead of applying the generic typechecking (fixing the regression). Then, just before the body of the template is about to be explored, the default value expressions are handled in the same manner as the body as well. This captures symbols including the parameters, so the expression is checked again if it contains a parameter symbol, and marked with `nfDefaultRefsParam` if it does (as an optimization to not check it later). Then when the template is being evaluated, when substituting a parameter, if we try to substitute with a node marked `nfDefaultRefsParam`, we also evaluate it as we would the template body instead of passing it as just a copy (the reason why it never worked before). This way we save time if a default value doesn't refer to another parameter and could just be copied regardless.
* don't instantiate generic body type symbols in generic expressions (#24092)metagn2024-09-102-0/+31
| | | | | | | | | | | | | | | fixes #24090 Generic body types are normally a sign of an uninstantiated type, and so give errors when trying to instantiate them. However when instantiating free user expressions like the nodes of `tyFromExpr`, generic default params, static values etc, they can be used as arguments to macros or templates etc (as in the issue). So, we don't try to instantiate generic body type symbols at all in free expressions such as these (but not in for example type nodes), and avoid the error. In the future there should be a "concrete type" check for generic body types different from the check in type instantiation to deal with things like #24091, if we do want to allow this use of them.
* add posix uint changes to changelog + fix Nlink, Dev on FreeBSD (#24088)metagn2024-09-094-4/+27
| | | | | | | refs #24078, refs #24076 Since these changes are potentially breaking, add them to changelog, also add Nlink as mentioned in https://github.com/nim-lang/Nim/issues/24076#issuecomment-2337666555.
* enable closures tests for JS & implement `finished` for JS (#23521)ringabout2024-09-0913-29/+80
|
* Adds an example of using ident to name procedures to the macros tutorial ↵CharlesEnding2024-09-091-0/+30
| | | | | | | | | (#22973) As discussed here: https://forum.nim-lang.org/t/10653 --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* fix: InotifyEvent.name should be UncheckedArray[char] (#23413)Tobias Dély2024-09-091-1/+1
|
* + show the effectsOf pragma (if present) of procs in nimsuggest hints… ↵Nikolay Nikolov2024-09-091-0/+10
| | | | | (#23305) … and compiler messages
* open new scope for const values (#24084)metagn2024-09-095-0/+31
| | | | | | | | | | | | | fixes #5395 Previously values of `const` statements used the same scope as the `const` statement itself, meaning variables could be declared inside them and referred to in other statements in the same block. Now each `const` value opens its own scope, so any variable declared in the value of a constant can only be accessed for that constant. We could change this to open a new scope for the `const` *section* rather than each constant, so the variables can be used in other constants, but I'm not sure if this is sound.
* fixes #21353; fixes default closure in the VM (#24070)ringabout2024-09-093-23/+27
| | | | | | | | | | | | | fixes #21353 ```nim result = newNodeIT(nkTupleConstr, info, t) result.add(newNodeIT(nkNilLit, info, t)) result.add(newNodeIT(nkNilLit, info, t)) ``` The old implementation uses `t` which is the type of the closure function as its type. It is not correct and generates ((nil, nil), (nil, nil)) for `default(closures)`. This PR creates `(tyPointer, tyPointer)` for fake closure types just like what cctypes do.
* fix regression with generic params in static type (#24075)metagn2024-09-092-0/+13
| | | | | | | | | | | | | | | | | | | | | | | Caught in https://github.com/metagn/applicates, I'm not sure which commit causes this but it's also in the 2.0 branch (but not 2.0.2), so it's not any recent PRs. If a proc has a static parameter with type `static Foo[T]`, then another parameter with type `static Bar[T, U]`, the generic instantiation for `Bar` doesn't match `U` which has type `tyGenericParam`, but matches `T` since it has type `tyTypeDesc`. The reason is that `concreteType` returns the type itself for `tyTypeDesc` if `c.isNoCall` (i.e. matching a generic invocation), but returns `nil` for `tyGenericParam`. I'm guessing `tyGenericParam` is received here because of #22618, but that doesn't explain why `T` is still `tyTypeDesc`. I'm not sure. Regardless, we can just copy the behavior for `tyTypeDesc` to `tyGenericParam` and also return the type itself when `c.isNoCall`. This feels like it defeats the purpose of `concreteType` but the way it's used doesn't make sense without it (generic param can't match another generic param?). Alternatively we could loosen the `if concrete == nil: return isNone` checks in some places for specific conditions, whether `c.isNoCall` or `c.inGenericContext == 0` (though this would need #24005).
* show symchoices as ambiguous in overload type mismatches (#24077)metagn2024-09-099-13/+97
| | | | | | | | fixes #23397 All ambiguous symbols generate symchoices for call arguments since #23123. So, if a type mismatch receives a symchoice node for an argument, we now treat it as an ambiguous identifier and list the ambiguous symbols in the error message.
* fix int32's that should be uint32 on BSD & OSX (#24078)metagn2024-09-093-10/+18
| | | | | | | | | fixes #24076 As described in #24076, misannotating these types causes codegen errors. Sources for the types are https://github.com/openbsd/src/blob/master/sys for BSD and https://opensource.apple.com/source/Libinfo/Libinfo-391/ and [_types.h](https://opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/_types.h.auto.html) for OSX.
* Fix CSS for `number-lines` code blocks (#24081)Jake Leahy2024-09-093-8/+14
| | | | | | | | | | | | Adds a few fixes for when using code blocks with lines numbered - Use CSS variables for the colours so that it works in dark mode - Don't turn on normal table effects like hover and smaller font when its a line number table - With dochack.nim, don't add a clipboard copy button for the line numbers at the side [Example page showing the changes](https://66dcde6e4a655efb70771d9a--dazzling-kitten-6c3419.netlify.app/)
* fix CI, sem whole `when` stmts as generic stmt (#24072)metagn2024-09-082-3/+17
| | | | | | | | | | | | | | fixes CI, refs #24066, refs #24065 The combination of #24065 and #24066 caused a CI failure where a `when` branch that was never compiled gave an undeclared identifier error. This is because the `when` branch was being semchecked with `semGenericStmt` without `withinMixin`, which is the flag `semgnrc` normally gives to `when` branch bodies. To fix this, just pass the whole `when` stmt to `semGenericStmt` rather than the individual blocks. The alternative would be to just replace the calls to `semGenericStmt` with a new proc that does the same thing, just with the flags `{withinMixin}`.
* Fix ioselectors_kqueue raising wrong exceptions (#24079)bptato2024-09-082-3/+26
| | | | | | | | | | | | | | | | | kqueue will remove pipes automatically if their read end is closed. Unfortunately this means that trying to unregister it (which is necessary to clean up resources & for consistency with other ioselectors implementations) will set an ENOENT error, which currently raises an exception. (ETA: in other words, it is currently impossible to call unregister on a pipe fd without potentially getting the selector into an invalid state on platforms with kqueue.) Avoid this issue by ignoring ENOENT errors returned from kqueue. (Tested on FreeBSD. I added a test case to the tioselectors file; the seemingly unrelated change is to fix a race condition that doesn't appear on Linux, so that it would run my code too.)
* fix subscript in generics, typeof, `lent` with bracket (#24067)metagn2024-09-083-0/+41
| | | | | | | | | fixes #15959 Another followup of #22029 and #24005, subscript expressions now recognize when their parameters are generic types, then generating tyFromExpr. `typeof` also now properly sets `tfNonConstExpr` to make it usable in proc signatures. `lent` with brackets like `lent[T]` is also now allowed.
* improve compiler performance on dot fields after #24005 (#24074)metagn2024-09-081-6/+3
| | | | | | | | | | | | | | | | | | | | | | | I noticed after #24005 the auto-reported boot time in PRs increased from around 8 seconds to 8.8 seconds, but I wasn't sure what could cause a performance problem that made the compiler itself compile slower, most of the changes were related to `static` which the compiler code doesn't use too often. So I figured it was unrelated. However there is still a performance problem with the changes to `tryReadingGenericParam`. If an expression like `a.b` doesn't match any of the default dot field behavior (for example, is actually a call `b(a)`), the compiler does a final check to see if `b` is a generic parameter of `a`. Since #24005, if the type of `a` is not `tyGenericInst` or an old concept type, the compiler does a full traversal of the type of `a` to see if it contains a generic type, only then checking for `c.inGenericContext > 0` to not return `nil`. This happens on *every* dot call. Instead, we now check for `c.inGenericContext > 0` first, only then checking if it contains a generic type, saving performance by virtue of `c.inGenericContext > 0` being both cheap and less commonly true. The `containsGenericType` could also be swapped out for more generic type kind checks, but I think this is incorrect even if it might pass CI.
* fix string literal assignment with different lengths on ARC (#24083)metagn2024-09-082-1/+18
| | | fixes #24080
* generate tyFromExpr for `when` in generics (#24066)metagn2024-09-064-4/+65
| | | | | | | | fixes #22342, fixes #22607 Another followup of #22029, `when` expressions in general in generic type bodies now behave like `nkRecWhen` does since #24042, leaving them as `tyFromExpr` if a condition is uncertain. The tests for the issues were originally added but left disabled in #24005.
* adapt generic default parameters to recent generics changes (#24065)metagn2024-09-069-28/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fixes #16700, fixes #20916, refs #24010 Fixes the instantiation issues for proc param default values encountered in #24010 by: 1. semchecking generic default param values with `inGenericContext` for #22029 and followups to apply (the bigger change in semtypes), 2. rejecting explicit generic instantiations with unresolved generic types inside `inGenericContext` (sigmatch change), 3. instantiating the default param values using `prepareNode` rather than an insufficient manual method (the bigger change in seminst). This had an important side effect of references to other parameters not working since they would be resolved as a symbol belonging to the uninstantiated original generic proc rather than the later instantiated proc. There is a more radical way to fix this which is generating ident nodes with `tyFromExpr` in specifically this context, but instead we just count them as belonging to the same proc in `hoistParamsUsedInDefault`. Other minor bugfixes: * To make the error message in t20883 make sense, we now give a "cannot instantiate" error when trying to instantiate a proc generic param with `tyFromExpr`. * Object constructors as default param values generated default values of private fields going through `evalConstExpr` more than once, but the VM doesn't mark the object fields as `nfSkipFieldChecking` which gives a "cannot access field" error. So the VM now marks object fields it generates as `nfSkipFieldChecking`. Not sure if this affects VM performance, don't see why it would. * The nkRecWhen changes in #24042 didn't cover the case where all conditions are constantly false correctly, this is fixed with a minor change. This isn't needed for this PR now but I encountered it after forgetting to `dec c.inGenericContext`.
* fixes #24053; fixes #18288; relax reorder with push/pop pragmas ↵ringabout2024-09-062-11/+19
| | | | | | | | | restrictions; no crossing push/pop barriers (#24061) fixes #24053; fixes #18288 makes push pragmas depend on each node before it and nodes after it depend on it
* proper errors for subscript overloads (#24068)metagn2024-09-067-52/+128
| | | | | | | | | | The magic `mArrGet`/`mArrPut` subscript overloads always match, so if a subscript doesn't match any other subscript overloads and isn't a regular language-handled subscript, it creates a fake overload mismatch error in `semArrGet` that doesn't have any information (gives stuff like "first mismatch at index: 0" for every single mismatch). Instead of generating the fake mismatches, we only generate the fake mismatch for `mArrGet`/`mArrPut`, and process every overload except them as a real call and get the errors from there.
* expose `rangeBase` typetrait, fix enum conversion warning (#24056)metagn2024-09-066-3/+74
| | | | | | | | | | | | | | | | refs #21682, refs #24038 The `rangeBase` typetrait added in #21682 which gives the base type of a range type is now added publicly to `typetraits`. Previously it was only privately used in `repr_v2` and in `enumutils` since #24052 (coincidentally I didn't see this until now). This is part of an effort to make range types easier to work with in generics, as mentioned in #24038. Its use combined with #24037 is also tested. The condition for the "enum to enum conversion" warning is now also restricted to conversions between different enum base types, i.e. conversion between an enum type and a range type of itself doesn't give a warning. I put this in this PR since the test gave the warning and so works as a regression test.
* fix undeclared identifier in templates in generics (#24069)metagn2024-09-062-1/+11
| | | | | | | fixes #13979 Fixes templates in generics that use identifiers that aren't defined yet, giving an early `undeclared identifier` error, by just marking template bodies as in a mixin context in `semgnrc`.
* remove unused config field: keepComments (#24063)ringabout2024-09-051-2/+0
|
* fixes #23897; Useless empty C files with arc/orc (#24064)ringabout2024-09-051-3/+0
| | | | | | | | | fixes #23897 follow up https://github.com/nim-lang/Nim/pull/21288 follow up https://github.com/nim-lang/Nim/pull/22472 Since #22472 triggers `nimTestErrorFlag` in every module that isn't empty, this PR removes unnecessary logic
* Make math.isNaN,copySign,etc available on objc (#24025)lit2024-09-051-1/+1
| | | | | | | fixes #23922 --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* remove unused nimStdlibVersion (#24060)ringabout2024-09-042-19/+1
|
* Make `$` on 0-length `MemSlice` produce Nim "" as per DMisener idea (#24015)c-blake2024-09-041-1/+1
| | | | | | | | in https://forum.nim-lang.org/t/12463 which seems reasonable enough to me. stdlib has several dozens of places doing result.setLen now, but if `experimental:strictDefs` move sot on by default and there is no easy way to locally suppress the warning we can revisit this.
* streams: implement readStr for VM, document VM limitations (#24058)metagn2024-09-043-4/+17
| | | | | | | | | | | fixes #24054 `readData` is not implemented for the VM as mentioned in the issue, but `readDataStr` is, so that is used for `readStr` instead on the VM. We could also just use it in general since it falls back to `readData` anyway but it's kept the same otherwise for now. Also where and why streams in general don't work in VM is now documented on the top level `streams` module documentation.
* document partial generics breaking changes (#24055)metagn2024-09-041-0/+13
| | | refs #24010, split from #24051
* proper error for calling nil closure in VM (#24059)metagn2024-09-043-0/+35
| | | | | | fixes #24057 Instead of crashing the compiler, the VM now gives a stacktrace if a nil closure is attempted to be called.
* fixes symbolName for range enums (#24052)ringabout2024-09-032-1/+17
|