Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrapnils: allows optional chaining of field access and indexing when LHS i snil #13023

Merged
merged 16 commits into from
Jan 18, 2020

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented Jan 3, 2020

(supersedes #13014)
This PR introduces a proc maybe for optional chaining, which has similar counterparts in other languages (eg, it's ubiquitous in swift, see https://docs.swift.org/swift-book/LanguageGuide/OptionalChaining.html)

very often, when debugging (or other cases), we need to special case field access to make sure a ref/ptr object is not nil, leading to clumsy code, eg:

type PSym = ref TSym
proc fun(s: PSym, iter: int) =
  var msg: string
  if s != nil:
    msg.add "name:", s.name.s & "kind: " s.kind
  else:
    msg.add "s is nil"
  echo msg & "iter:" & $iter

this PR allows much simpler code instead, that allows intermediate LHS values to be nil (in which case it returns default for the field) in field access and indexing:

type PSym = ref TSym
proc fun(s: PSym, iter: int) =
  echo (isnil: s == nil, name: s.maybe.foo[12].bar.name[], kind: s.maybe.kind[], iter: iter)

EDIT: example showing behavior on procs

/cc @Araq IMO this is the desired, common case, behavior

# this works even if n.typ == nil; in which case `typeToString` is NOT called
echo (dest.kind, n.typ == nil, n.typ.maybe.typeToString[])

note1:

supersedes #13014 ; advantages:

  • requires no parser change (whereas .? and ?. had issues with foo.?bar.baz etc, which would require parser/lexer changes)
  • works with [] indexing (hard to do with .?; any of these ?[], [?], []? would require parser/lexer changes)

note2:

I designed it to be recursive (in the sense that operations on a Maybe return a Maybe, and at the end of the chain you can add [] to get back the value); IMO it's the most commonly useful behavior; we could introduce a non-recursive variant (which hence wouldn't need [] at the end) in further PR and it's trivial to do so (that was in fact my original version, but new version is better)

Eg for long chains, maybe is needed only once, at the 1st place where some value can be nil:

# say foo isn't nil but foo.bar is maybe nil:
foo.bar.maybe.x1.x2.x3[] # everything after foo.bar can be nil

# the non-recursive variant would've been:
foo.bar.maybe.x1.maybe.x2.maybe.x3

obviously user has full control eg to terminate chain early:

echo foo.maybe.x1[].x2

note3:

  • despite superficial similarities, this is different from std/options; std/options just can't be used for this use case
  • I chose to put it in a new module instead of std/sugar (no real harm to having more modules especially bc of lack of cyclic imports it's actually better)

future work

@timotheecour timotheecour changed the title maybe: allows optional chaining maybe: allows optional chaining of field access and indexing when LHS i snil Jan 3, 2020
@Araq
Copy link
Member

Araq commented Jan 3, 2020

Now that's a work of genius (no irony!). We can bikeshed about the name though... :-)

lib/std/maybes.nim Outdated Show resolved Hide resolved
@timotheecour
Copy link
Member Author

PTAL

@Araq
Copy link
Member

Araq commented Jan 4, 2020

.maybe is not the best name for this IMO, how about:

  • nilToDef
  • nocrash
  • nildef
  • notnil

@timotheecour
Copy link
Member Author

timotheecour commented Jan 4, 2020

how about:
nilwrap? (note: not nilWrap; it's easier to type all small case)
and then i replace all occurrences of maybe by nilwrap

also see note I added above regarding example showing behavior on procs

(notnil already has some kind of meaning; nocrash is a misnomer since it can still crash for other reasons (eg function calls that crash for unrelated reasons); nildef/nilToDef sounds like definition, not default)

if not nilwrap, I'd be ok with: nilsafe

@juancarlospaco
Copy link
Collaborator

notnil 👍

@disruptek
Copy link
Contributor

defuse

@timotheecour
Copy link
Member Author

notnil is not a good name, there's a different concept already called NotNil: see nimNotNil, tfNotNil etc; we shouldn't conflate these

@Araq
Copy link
Member

Araq commented Jan 4, 2020

I like nilwrap (don't forget to change the module's name to nilwraps and the changelog entry).

@timotheecour
Copy link
Member Author

done PTAL

@timotheecour timotheecour reopened this Jan 5, 2020
@Araq
Copy link
Member

Araq commented Jan 5, 2020

Wait a sec ... why nilwrap? Shouldn't this be wrapnil?

@disruptek
Copy link
Contributor

denil

@timotheecour
Copy link
Member Author

Wait a sec ... why nilwrap? Shouldn't this be wrapnil?

done; hopefully ends the bikeshed ;-)

@Araq
Copy link
Member

Araq commented Jan 5, 2020

auto return type is bad for documentation generator, speaking of which docgen (kochdocs) is not updated and this need a big doc comment saying this module is experimental and also relying on experimental Nim features.

Slightly offtopic, the rule we are following now is that new std modules start as experimental and are only in std so that we don't have a silly "deprecation" period should they turn out to be good enough...

@timotheecour
Copy link
Member Author

PTAL

  • auto return type is bad for documentation generator
    done (question: since nim doc runs nim, can't it infer it?)

  • speaking of which docgen (kochdocs) is not updated
    done (IMO there should be a CI test (that runs as early as possible in CI) to make sure all modules are covered; instead of relying on such kind of knowledge

  • and this need a big doc comment as being experimental and also relying on experimental Nim features.
    done

Slightly offtopic, the rule we are following now is that new std modules start as experimental and are only in std so that we don't have a silly "deprecation" period should they turn out to be good enough...

for future PR's how about the following fool-proof rule:
new module mymod requires a experimental flag: --experimental:std:mymod
then when we figure out the module is good enough we just make that flag default.
This avoids any shuffling around of files, and avoids any renames in user code (unlike what we have with lib/experimental/diff.nim and import experimental/diff)

@Araq
Copy link
Member

Araq commented Jan 5, 2020

question: since nim doc runs nim, can't it infer it?

In theory it could but for Nim's semi-broken generics it's even harder.

done (IMO there should be a CI test (that runs as early as possible in CI) to make sure all modules are covered; instead of relying on such kind of knowledge

kochdocs should use some globs. (I know you had such a PR and krux02 closed it, without my consent.)

new module mymod requires a experimental flag: --experimental:std:mymod
then when we figure out the module is good enough we just make that flag default.

I think that's not necessary and only more annoying. Instead we should document that std is mostly about namespacing modules and that both "standard" modules end up there and also experimental ones. The experimental ones will always have a comment saying that (and obviously they are candidates for the stdlib).

lib/std/wrapnils.nim Outdated Show resolved Hide resolved
@timotheecour
Copy link
Member Author

timotheecour commented Jan 6, 2020

PTAL
I had to add a field validImpl to distinguish valid from invalid values: the wrapnil object becomes invalid (and stays invalid) as soon as a nil is found on the chain.
Without this, some tests in test suite would fail.
The test suite reflects the most useful semantics IMO.

@Araq
Copy link
Member

Araq commented Jan 6, 2020

Please bare with me but here are more remarks to be discussed, they don't imply actions on the PR itself:

  • There is a weird asymetry between wrapnil and [] (deref to get out of the wrapnil context?). what if we use a wrap(x) instead. Needs the () though then.
  • The primary use case is "safe access in testing for equality". So should this perhaps be a class of operators like ==?, <?, <=??

For example:

doAssert a.x2.x2.x3[1] ==? default(char)

Or maybe just

doAssert ?!a.x2.x2.x3[1] == default(char)

If you want to end the nil oblivious evaluation rules earlier, use ():

doAssert ?!(a.x2).x2.x3[1] == default(char)

I like ?! best because it sticks out and is unlikely to clash with any existing usages.

@timotheecour
Copy link
Member Author

timotheecour commented Jan 6, 2020

  • I added deref for the uncommon case where a system.[] is needed: it's uncommon because field access don't require to first deref, but there is 1 case where it is needed: proc call that expects a deref'd input, see new test in ce296cb

  • There is a weird asymetry between wrapnil and [] (deref to get out of the wrapnil context?)
    it's the exact same as in typeinfo: toAny / [].

I'm optimizing for the common case (usually you'll want to unwrap at end of chain), hence used a familiar (existing) operator
We can however add get to make it more flexible, as in options.get:

template `[]`*(a: Wrapnil): untyped = a.valueImpl
template get*(a: Wrapnil): untyped = a.valueImpl  # but also throws if not a.validImpl (as in `options.get`)
template get*(a: Wrapnil, b: defaultVal): untyped = a.valueImpl

The primary use case is "safe access in testing for equality"

# 1: safe echo / msgs / debug
echo (x1.wrapnil.x2[], ...)
# 2: safe testing: will assert with desired msg instead of segfault
doAssert x1.wrapnil.x2[] == val, additionalContext
# 3: safe delayed testing, using unittest.check: will allow testing to continue (keeping the err checkpoint) instead of segfault
check x1.wrapnil.x2[] == val
# 4: safe branching
if x1.wrapnil.x2[] == val: foo

what if we use a wrap(x) instead. Needs the () though then

not clear; how would u translate: x1.x2.wrapnil.x3.x4[].baz using wrap?
It suffers from same issues as $ which violates the natural left-to-right evaluation chains, making it awkward to use when what you're stringifying is not "the whole expression" (and would additionally require quoting).
Wheres with x1.x2.wrapnil.x3.x4[].baz it's clear where the wrapping/unwrapping happens

in any case I bet wrap can be written on top of primitives from this PR (via a macro), but I don't think it's simpler to use.

==?, <?, <=?

why are these needed? this works:

check x1.wrapnil.x2[] == val
check x1.wrapnil.x2[] > val

@Araq
Copy link
Member

Araq commented Jan 8, 2020

Ok, let me try again:

What downside does a unary operator have? It sticks out as "here is something fishy going on" and it's clear what it applies to without the need for deref.

Some examples from your tests, rewritten with ?! (which is what I'm proposing):

  doAssert ?!a.x2.x2.x1 == 0.0
  doAssert ?!a3.x2.x2.x5.len == 0
  doAssert ?!a.x2.x2.x3[1] == default(char)
  echo ?!a.b.c.d

@timotheecour
Copy link
Member Author

timotheecour commented Jan 18, 2020

compromise: I've un-exported wrapnil, isValid, unwrap for now to unblock this PR but kept them as private procs so I don't loose the work and this can be debated later;

As I tried to explain in #13023 (comment), ?. does not distinguish between

  • invalid value (ie, had intermediate nils)
  • default value that happens to be default (which is perfectly valid, eg an int that's 0)

This is the same rationale as in std/options which has an API to distinguish invalid from valid (even if valid-but-default):

import std/options

let x1 = some(0)
echo x1.isSome # true even if valid but default
echo x1.get(0)

let x2 = none(int)
echo x2.isSome # false
echo x2.get(0)

the example use is

let z = x1.wrapnil.x2.x3.level
if z.isValid:
  echo z.unwrap
else: # do smthg else, maybe throw with a useful context, or handle differently

@Araq Araq merged commit f6ba4e8 into nim-lang:devel Jan 18, 2020
@timotheecour timotheecour changed the title maybe: allows optional chaining of field access and indexing when LHS i snil [TODO] maybe: allows optional chaining of field access and indexing when LHS i snil Jan 19, 2020
@timotheecour timotheecour deleted the pr_maybe branch January 19, 2020 04:35
dom96 pushed a commit that referenced this pull request Feb 15, 2020
* Add osOpen alias for the operating system specific open command

* Add `--git.devel` option to the documentation
remove unused import (#12900)

fix json regression D20191212T144944 (#12902) [backport]

Peer Review Feedback #12901 (comment)

Merge branch 'devel' of https://github.com/nim-lang/Nim into osopen

Peer Review Feedback #12901 (comment)

Update lib/pure/browsers.nim

Co-Authored-By: Dominik Picheta <dominikpicheta@googlemail.com>
Peer Review Feedback #12901 (comment)

allow typed/untyped in magic procs (#12911)

NaN floatFormat with clang_cl  (#12910)

* clang_cl nan floatFormat

* format

add $nimeq for gdb (#12909)

ARC: cycle detector (#12823)

* first implementation of the =trace and =dispose hooks for the cycle collector
* a cycle collector for ARC: progress
* manual: the .acyclic pragma is a thing once again
* gcbench: adaptations for --gc:arc
* enable valgrind tests for the strutils tests
* testament: better valgrind support
* ARC refactoring: growable jumpstacks
* ARC cycle detector: non-recursive algorithm
* moved and renamed core/ files back to system/
* refactoring: --gc:arc vs --gc:orc since 'orc' is even more experimental and we want to ship --gc:arc soonish

Cleanup leftovers of #12911(#12916)

Fix single match output (#12920)

fixes #12899 (#12921)

* fixes #12899

* fixes regression: destroy global variables in reverse declaration order, closureleak test relies on it

Implement NixOS distro check (#12914)

Better case coverage error message for alias and range enum (#12913)

fix error in assertions document (#12925) [backport]

fix cmdline bugs affecting nimBetterRun correctness (#12933) [backport]

fix #12919 tasyncclosestall flaky: Address already in use (#12934)

system.reset is no longer magic (#12937)

It has now means setting x to default for new and old runtime alike
Fix #12785 (#12943)

* Fix #12785 and add test

* better variable name

update documentation for `closureScope` and `capture` (#12886)

fixes #12735 on osx, call dsymutil for debug builds (#12931)

* fix #12735 osx: dsymutil needs to be called for debug builds
* also write dsymutil command to extraCmds in json build file

Auto-initialize deques (#12879)

case coverage error message for `char` (#12948)

lenVarargs: number of varargs elements (#12907)

docs: tiny style improvements

added guidelines for evolving Nim's stdlib

fixes a bug that kept sugar.collect from working with for loop macros [backport]

fixes #12826

fixes a regression

a better bugfix

fixes a test case

fixes a silly regression

fixes the distros.nim regression

ported channels to ARC

ported osproc.nim to ARC

ported re.nim to ARC

ARC: default to a shared heap with --threads:on

osproc: fixes regression

fixes another regression

fixes #12945 (#12959)

minor refactorings

Fixes stackoverflow links in readme (#12963) [backport]

Allow customize Host header
[ci skip] docfix .. < => ..< (#12981) [backport]

parsecfg: retain CRLF line breaks, fixes #12970 (#12971)

generic stack trace overriding mechanism (#12922)

* libbacktrace support

* switch to a generic stack trace overriding mechanism

When "nimStackTraceOverride" is defined, once of the imported modules
can register its own procedure to replace the default stack trace
generation by calling `registerStackTraceOverride(myOwnProc)`.

Tested with `./koch boot -d:release --debugger:native -d:nimStackTraceOverride --import:libbacktrace`
for the compiler itself and `./bin/nim c -r -f --stacktrace:off --debugger:native -d:nimStackTraceOverride --import:libbacktrace foo.nim`
for an external program.

* make the StackTraceOverrideProc {.noinline.}

Added fix for handling TaintedStrings in streams and httpclient (#12969)

* Added fix for taint mode in streams and httpclient

* Removed taintMode export from system.nim

Check pqntuples > 0 in getValue. Fixes #12973 (#12974)

c_fflush() the rawWrite() buffer (#12987)

Stack traces on an unbuffered stderr get out of sync with line-buffered
stdout - usually on Windows terminals or CI logs. This fixes it by
calling C's fflush() on the output buffer in the procedure used for
printing stack traces.
fixes #12989

Revert "fixes #12989"

This reverts commit 928c2fe.

fixes #12965 (#12991)

fixes #12989 (#12992)

* fixes #12989
* Revert "remove unwanted changes"

This reverts commit 5018297.

fixes disruptek/nimph#102 multi-level nim.cfg use (#13001) [backport]

--exception:goto switch for deterministic exception handling (#12977)

This implements "deterministic" exception handling for Nim based on goto instead of setjmp. This means raising an exception is much cheaper than in C++'s table based implementations. Supports hard realtime systems. Default for --gc:arc and the C target because it's generally a good idea and arc is all about deterministic behavior.

Note: This implies that fatal runtime traps are not catchable anymore! This needs to be documented.
fix #12985 {.push.} now does not apply to generic instantiations (#12986)

Sink to MemMove optimization in injectdestructors (#13002)

remove default argument for readLines (#12807) [backport]

fixes #12978 (#13012)

Fix typo (#13015) [backport]

fixes #12961 (#13019)

fixes #12956 (#13020)

fix #12988 (#13022)

fix #12988
Fixes #13026 (#13028)

fixes #12964 (#13027)

fixes #13032

VM: support importc var, ptr/pointer types, cast int <=> ptr/pointer (#12877)

* VM: allow certain hardcoded special var variables at CT
* VM: allow all importc var, cast[int](ptr)
* fix tests tests/vm/tstaticprintseq.nim, tests/cpp/t8241.nim
* VM: == works for ptr/pointer nodes
* bugfix: ==, cast now also works for pointer, not just ptr
* VM supports cast PtrLikeKinds <=> PtrLikeKinds / int
* improve cname handling
* fixup + bug fix
* VM: support cast from ref to int
* address comment: opcLdGlobalDeref => opcLdGlobalDerefFFI
* defensive check against typ == nil

fix enumtostr crash for enum-range (#13035)

fixes #13013, reverts previous changes to readLines() (#13036) [backport]

* Revert "remove default argument for readLines (#12807) [backport]"

This reverts commit c949b81.

reprjs: style changes

fixes #12996

Rst parser respect `:start-after:` and `:end-before:` in `include` directive (#12972)

* [FEATURE] rst parser respect :start-after: in include

Rst parser now respects `:start-after:` and `:end-before:` attributes
for `include` directive.

* [DOC] include directive parsing proc update

* [TEST] Added unit tests for include rst directive in `rst` module

Allow `-o` option for `buildIndex` (#13037) [backport]

Addressing #12771

This is also included in the docgen documentation [here](https://nim-lang.org/docs/docgen.html) but its not respected as reported in the issue.
[cleanup] remove disabled (and obsolete) ttypetraits; rename ttypetraits2 => ttypetraits (#13041)

* remove disabled (and obsolete) ttypetraits; rename ttypetraits2 => ttypetraits

* D20200105T085828 fix super strange bug that causes CI to fail: builds.sr.ht with: `Error: Settle timed out after 120 attempts`

Continue #13002 (#13021)

testament/important_packages dont run hts (#13052)

Modify the test command for nimly (nimble-package) (#13053)

clean up deprecated stuff and unused imports in tests (#13059)

--styleCheck:hint now works (#13055)

[easy] --hint:link:on now shows link cmd instead of nothing (#13056)

* --hint:link:on now shows link cmd instead of nothing

* update doc for --listCmd

add pqserverVersion,pqconnectionNeedsPassword,pqconnectionUsedPassword (#13060)

basename supports pragmaexpr (#13045)

* basename supports pragmaexpr

* update changelog

distinctBase type trait for distinct types (#13031)

make SuccessX show project file + output file (#13043)

* make SuccessX show project file + output file
* address comments
* fix test and add `result.err = reNimcCrash` otherwise hard to see where reNimcCrash used
* address comments

move entries from the wrong changelog file [ci skip]

fix crash due to errant symbols in nim.cfg (#13073) [backport]

Deleted misplaced separator (#13085) [backport]

Misplaced separator, which was constantly breaking compilation on Haiku OS, was deleted.
take the one good idea from --os:standalone and enable it via -d:StandaloneHeapSize (#13077)

remove all remaining warnings when build nim (with -d:nimHasLibFFI) (#13084)

* cleanup deprecations in evalffi + elsewhere

* remove dead code getOrdValue64

Use '__noinline' instead of 'noinline' for N_NOINLINE gcc attribute, this prevents clashes with systems where 'noinline' might be already defined (#13089)

Fix error check code in osproc (#13090) [backport]

fixes #13072; no test case because it will be added later with more exception handling related bugfixes

fixes #13070

typetraits: fixes #6454; genericParams; added lenTuple; added tuple type get (#13064)

[backport] system/io.nim fix wrong documentation comment [ci skip]

fixes an asyncftpclient bug; refs #13096 [backport]

System cleanup, part 1 (#13069)

* system.nim: mark what every .pop does

* system.nim: un-nest when statements

[backport] fix #12813, fix #13079 (#13099)

Correctly remove a key from CountTable when it is set to zero.
more arc features (#13098)

* config update
* ARC now supports 'repr' and 'new' with finalizers is supported

Remove some unused/disabled OpenSSL functions (#13106)

Add link to posix_utils.html in posix.nim (#13111)

VM FFI: write(stderr, msg) and fprintf(cstderr, msg) now work at CT (#13083)

fix the ftp store function read the local file bug (#13108) [backport]

* Update asyncftpclient.nim

When use newStringOfCap function not have assign memory for the string data,so if use this address the fault is rasise.

* complelete the bugfix

fix rtti sizeof for varargs in global scope (#13125) [backport]

fixes #13122 (#13126)

* fixes #13122

* moved tests to where they belong

fixes #13112 (#13127)

* improve line error information

* fixes #13112

Expose more openSSL methods. (#13131)

fixes #13100 nim doc now treats `export localSymbol` correctly (#13123) [backport]

* fix #13100 nim doc now treats `export localSymbol` correctly
* use owner instead

fixes #13119 (#13128)

* fixes #13119
* fixes a regression

fixes #13105 (#13138)

fixes #10665 (#13141) [backport]

pass platform argument only if vccexe is used (#13078)

* pass platform only if vccexe is used
* fixes #12297

fixes #13104 [backport] (#13142)

fixes #9674 [backport] (#13143)

Fix typo in doc/destructors.rst (#13148)

Added 'ansic' os support for minimal (embedded) targets (#13088)

* os:any implementation
* os:asny: omit flock/funlock calls in echoBinSafe
* Disabled default "unhandled expection" reporting for `--os:any` to reduce
code size. Added unhandledExceptionHook instead which can be used to get
a notification from Nim and handle it from the application.

System cleanup, part 2 (#13155)

* create basic_types, arithmetics, exceptions, comparisons
* create setops.nim
* create memalloc.nim
* create gc_interface.nim
* create iterators_1.nim

export normalizePathEnd (#13152)

successX now correctly shows html output for `nim doc`, `nim jsondoc`; fix #13121 (#13116)

* successX now correctly shows html output for nim doc
* fixes #13121
* fixup hintSuccessX to be less weird

ARC: misc bugfixes (#13156)

* fixes #13102
* closes #13149
* ARC: fixes a move optimizer bug (there are more left regarding array and tuple indexing)
* proper fix; fixes #12957
* fixes yet another case object '=' code generation problem

CI fix timeout error (#13134)

Remove obsolete code from osalloc (#13158)

style fix: change 'JS' to 'js' to make it consistent (#13168)

Working towards arc codegen (#13153)

fixes #13029
fixes #12998 nim doc regression (#13117)

fix tsizeof3 for aarch64 (#13169)

Cleanup DFA (#13173)

Fix docs (#13176)

fixes #13095 (#13181)

* fixes #13095

* fix typo

make case-object transitions explicit, make unknownLineInfo a const, replace a few magic numbers with consts (#13170)

ARC works for async on Windows (#13179)

make sink operator optional (#13068)

* make sink operator optional

* bug fix, add changelog entry

* Trigger build

* fix one regression

* fix test

* Trigger build

* fix typos

Fix docs for subdirs too (#13180)

* Fix doc subdirs
* Extract to helper proc, and fix on windows

followup on #10435 : should be diff, not show (#13162)

fixes #13157

refs #13054 correctly handle {.exportc,dynlib.} and {.exportcpp,dynlib.}  (#13136)

* refs #13054 correctly handle {.exportc,dynlib.} and {.exportcpp,dynlib.}
* put back NIM_EXTERNC for N_LIB_EXPORT; causes issues with compilerproc

fixes #13144 (#13145)

* fixup: genscript now does not copy nimbase.h but uses -I$nim/lib

times: toUnixFloat, fromUnixFloat (#13044)

maybe: allows optional chaining of field access and indexing when LHS i snil (#13023)

* maybe: allows optional chaining
* fix tools/kochdocs.nim
* improve semantics to distinguish valid from invalid values
* for now, wrapnil, isValid, unwrap are not exported

fix docs + API for fieldPairs, fields (#13189)

more on arc codegen (#13178)

* arc codegen for union type

* add more tests

* fix offsetof

* fix tsizeof test

* fix style

Add link to packaging.html (#13194)

Fixes #13186 (#13188)

fixes #13195

revert last commit

Merge branch 'devel' of https://github.com/nim-lang/Nim into devel

Revert "fixes #13195"

This reverts commit cd7904f.

fixes #13110 (#13197)

fixes #13195 (#13198)

* fixes #13195

* extra fix

* fix typo

compiler/ccgtypes: hide exportc proc unless it has dynlib (#13199)

This hides most of stdlib's internal functions from resulting
binaries/libraries, where they aren't needed on *nix. Static libraries
are not affected by this change (visibility doesn't apply to them).
fix range[enum] type conversion (#13204) [backport]

Idxmin & idxmax, continuation (#13208)

* Add idxmin() which returns the index of the minimum value

* Add idxmax() which returns the index of the maximum value

* Add tests for idxmin()

* Add tests for idxmax()

* Remove initialization of result = 0

* Adds overloading for arrays (no enums indexed arrays yet)

* Add support for enum index arrays

* Fix tests with enum

* Fix tests for idxmax

* Change names of the procedures to minIndex and maxIndex

* address Araq's comments:

- remove 'array' versions
- add .since pragma
- return 'int' instead of 'Natural'
- add changelog entry

Co-authored-by: Federico A. Corazza <20555025+Imperator26@users.noreply.github.com>

fix #13211 relativePath("foo", ".") (#13213)

fixes a critical times.nim bug reported on IRC [backport] (#13216)

httpclient, maxredirects to Natural, newHttpClient/newAsyncHttpClient add headers argument instead of hardcoded empty (#13207)

added note to re constructor regarding performance (#13224)

Since I was new to regex I did not know that there is a compilation going on with ``re"[abc]"`` constructor and so I followed the other examples in the docs blindly, that is I just put the constructor directly in the arguments of match, find, etc., which was inside a loop and then wondered why my performance was so bad. Of course putting it outside the loop made it vastly more performant. People like me would benefit from the small note I added I would think :)
[backport] Documentation Fix #12251 (#13226) [ci skip]

[backport] times/getClockStr(): fix mistake in doc (#13229) [ci skip]

new os.isRelativeTo (#13212)

[backport] Fix typo and improve in code-block of 'lib/pure/parseutils.nim' (#13231) [ci skip]

[backport] fix #11440, add docs to isNil for seq types needing nilseq (#13234) [ci skip]

VM: allow overriding MaxLoopIterations without rebuilding nim (#13233)

kochdocs: use a glob instead of hardcoded list; generate docs for compiler/; bugfixes (#13221)

* kochdocs: use a glob instead of hardcoded list; generate docs for compiler/; bugfixes
* fixup after #13212 isRelativeTo got merged

fix lots of bugs with parentDir, refs #8734 (#13236)

Unexport even more symbols (#13214)

* system/gc: don't export markStackAndRegisters

* compiler/cgen: unexport internal symbols

As these functions are Nim-specific walkaround against C's optimization
schemes, they don't serve any purpose being exported.

* compiler/cgen: don't export global var unless marked

* compiler/ccgthreadvars: don't export threadvar unless marked

* tests/dll/visibility: also check for exports

This ensure that these changes don't break manual exports.

* compiler/cgen: hide all variables created for constants

* compiler/ccgtypes: don't export RTTI variables

* compiler/ccgexprs: make all complex const static

* nimbase.h: fix export for windows

* compiler/cgen, ccgthreadvars: export variables correctly

For C/C++ variables, `extern` means that the variable is defined in an
another unit. Added a new N_LIB_EXPORT_VAR to correctly export
variables.

Removed lib/system/allocators.nim. seqs_v2 and strs_v2 now uses allocShared0. (#13190)

* Cleanup, remove lib/system/allocators.nim. seqs_v2 and strs_v2 now use
allocShared0 by default.

* Fixed -d:useMalloc allocShared / reallocShared / deallocShared. These now use the alloc/dealloc/realloc implementation that also takes care of zeroing memory at realloc.

* Removed debug printfs

* Removed unpairedEnvAllocs() from tests/destructor/tnewruntime_misc

* More mmdisp cleanups. The shared allocators do not need to zero memory or throw since the regular ones already do that

* Introduced realloc0 and reallocShared0, these procs are now used by
strs_v2 and seqs_v2. This also allowed the -d:useMalloc allocator to
drop the extra header with allocation length.

* Moved strs_v2/seqs_v2 'allocated' flag into 'cap' field

* Added 'getAllocStats()' to get low level alloc/dealloc counters. Enable with -d:allocStats

* *allocShared implementations for boehm and go allocators now depend on the proper *allocImpl procs

[backport] documentation: Add channels examples (#13202) [ci skip]

[backport] Make all parseutils examples auto-checking (#13238)

- Also fix one example's output (ikString -> ikStr, ikVar instead of ikExpr)
Updated 'nim for embedded systems' section to use --os:any and --gc:arc (#13237)

* Updated 'nim for embedded systems' section to use --os:any and --gc:arc

* Added section about size optimization to embedded systems

Remove name attribute from docutils.nimble (#13239)

Fixes asyncftpclient multiline reading, fixes #4684 (#13242)

Previously, the 4th character of `result` was checked for `'-'` every time, instead of each new line.

Also made it work for taint mode.
Fix typo for literal `[` (#13243)

The literal value for the `tkBracketLe` token was incorrectly set to `]` rather than `[`. I've had a quick glance at the code and it doesn't look like this change will affect anything at all, but I haven't tested yet - let's see if the CI explodes...
Add "origin" to window.location (#13251)

Add "origin" to window location: https://www.w3schools.com/jsref/prop_loc_origin.asp
nim dump: add libpath (#13249)

contributing docs: symbols need package prefix; changed allocStats to nimAllocStats (#13247)

testament/azure: major rewrite (#13246)

This commit features a major rewrite of Azure Pipelines integration,
turning the spaghetti it originally was into something maintainable.

Key changes:
- No longer requires a ton of hooks into testament.
- Results are now cached then bulk-uploaded to prevent throttling from
  Azure Pipelines, avoiding costly timeouts.
- A low timeout is also employed to avoid inflated test time.
- The integration is now documented.
Cleaned up mmdisp.nim, moved implementations into lib/system/mm/ (#13254)

make goto based exceptions available for 'nim cpp' (#13244)

* make goto based exceptions available for 'nim cpp'
* optimize seq.add to be comparable to C++'s emplace_back

ARC: remove unnecessary code

ARC: optimize complete object constructors to use nimNewObjUninit

make nre compile with --gc:arc

Rename isNilOrWhitespace to isEmptyOrWhitespace and make it use allCharsInSet (#13258)

* Rename isNilOrWhitespace to isEmptyOrWhitespace

* Make isEmptyOrWhitespace use allCharsInSet(Whitespace)

Clearer final objects error; fixes #13256 (#13257)

scrollTop must be settable (#13263)

* scrollTop must be assignable

Make scrollTop settable

* add missing export

fixes #13219 (#13272)

fixes #13281 (#13282)

* fixes ##13281

* add comment to test

unittest add resetOutputFormatters proc (#13267)

* add resetOutputFormatters

* remove space

* resolve comments

TlSF Alloctor: use less memory for --gc:arc (#13280)

Tiny since cleanup (#13286)

nimv2 widestring indexing (#13279)

Repr v2 progress (#13268)

* progress on repr_v2

* repr progress

* add ref objects with distrinct

* fix failing tests

refactor htmldocs; gitignore it

removed unused import

fix stdout(etc) for emscripten

csize => csize_t for sysctl

Thread attributes should be destroyed using the pthread_attr_destroy() (#13293)

On some OSes (such as FreeBSD or Solaris), pthread_attr_init allocate
memory. So it is necessary to deallocate that memory by using
pthread_attr_destroy.
fix critical bug discovered by #11591 (#13290) [backport]

miscellaneous bug fixes (#13291)

* fix for emscripten etc

* add testcase for #13290

* replace deprecated isNilOrWhitespace

CT FFI: fix for windows; fix case transition; error msg shows more useful context (#13292)

* evalffi: fix case transition
* evalffi: fix for windows
* evallffi: `cannot import` errmsg now also shows which library it tried to import symbol from

refs #8391 std/os now shows runtime context for raiseOSError exceptions (#13294)

* refs #8391: fix errmsg for setCurrentDir

* raiseOSError calls for copyFile

* refs #8391 std/os now shows runtime context for raiseOSError exceptions

build_all.sh: building csources 5X faster thanks to make -j (#13300)

* build_all.sh: building csources 5X faster thanks to make -j
* fix for freebsd
* use OS-dependent formula to get number of logical cores
* make is an optional dependency

Fix capture for object types (#13315)

* Fix capture for object|tuple|... types

* Add test case

Quote nim executable before executing. (#13316) [backport]

In case nim executable is located in PATH containing spaces.

fixes #13311
ReSync with devel

Make build_all.sh more portable and a bit simpler (#13308)

koch: enable checks in the compiler when running CI (#13323)

fix #13132 tnetdial (#13318)

enable testing -d:nimHasLibFFI mode (#13091)

Fix #10717, fix #13284 (#13307)

Fixed codegen for constant cstring with --gc:arc (#13326)

* Fixed codegen for constant cstring with --gc:arc, fixes  #13321

* Added test for #13321

Option to allow the request body to be processed outside the asynchttpserver library. (#13147)

Allow the request body to be processed outside the asynchttpserver library to break big files into chunks of data. This change does not break anything.

build_all.sh update (#13320)

* Don't overload the system, don't crash when you can't determine the CPU count and don't rely on bash

* Extract to variable

* Limit number of spawned jobs for systems with weak IO

* Use proper arithmetic braces

contributing.rst: Add a special rule for 'outplace'-like features

[backport] -d:danger should imply -d:release (#13336)

nim secret: support linenoise when available (#13328)

fix #13150 `nim doc --project` now works reliably (#13223)

* fix #13150 `nim doc --project` works with duplicate names and with imports below main project file

* add to help; fixup after #13212 isRelativeTo got merged
* fix test tests/compilerapi/tcompilerapi.nim
* remove nimblePkg field; compute on the fly instead
* kochdocs: compiler docs now under compiler/
* --docRoot now has smart default: best among @pkg, @path

make monotimes have zero overhead if you don't use it (#13338) [backport]

fix #13349 regression: isNamedTuple now works with generic tuples (#13350)

fixes #13269 (#13344)

adding sqlite3 backup functions (#13346)

* adding sqlite3 backup functions

* changing sleep to sqlite3_sleep to prevent clashes

Added a basic example how to handle a Post request. (#13339)

* Added a basic example how to handle a Post request.

They were also made minor cosmetic changes.

* Minor fixes suggested by Yardanico

* Fixed a wrong value in chunkSize constant.

* Re-added the request.body for compatibility!

replace old problematic isNamedTuple implementation by TypeTrait isNamedTuple in dollars.nim (#13347)

* replace old problematic isNamedTuple implementation by TypeTrait isNamedTuple

* fix for bootstrap

fix #13182: `proc fun(a: varargs[Foo, conv])` now can be overloaded (#13345) [backport]

miscellaneous bug fixes (part 3) (#13304)

* fix deprecation; fix indentation

* git clone: use -q

* fix Warning: pragma before generic parameter list is deprecated; fix typo

* bugfix: sysTypeFromName("float64") was never cached

testament: introduce 'matrix' for testing multiple options (#13343)

printing float values will have one more digit. (#13276) [backport]

* printing float values will have one more digit. Fixes #13196

[backport] fix #13352

[backport] remove 'CountTable.mget' (#13355)

It didn't work, and it was an oversight to be included in v1.0.
fix #6736: templates in unittest now show actual value (#13354)

Revert "printing float values will have one more digit. (#13276) [backport]" (#13363)

This reverts commit b2c6db9.
Add sideEffect pragma to importC procs in posix, winlean and time module (#13370)

* Add sideEffect pragma to procs in winlean
* Add sideEffect pragma to procs in posix
* Add test for #13306
* Add sideEffect pragma to procs in times
* Fixes #13306
fixes #3339 by documenting the limitations of case-statement (#13366)

fixes #13314 (#13372)

testament: this now works: "testament r /abspath/to/test.nim" (#13358)

fix `is` with generic types; fix `genericHead(Foo[T])` (#13303)

* fix #9855, fix #9855, fix genericHead
* render TTypeKind via toHumanStr

fix #13255 (#13275) [backport]

remove outplace version of 'merge' for CountTables (#13377)

* remove outplace version of 'merge' for CountTables

* remove 'merge' tests

fix #13374 `nim c -r -` now generates $nimcache/stdinfile (#13380) [backport]

fix #9634 don't crash on execCmdEx/readLine when inside gdb/lldb (#13232)

* fix #9634 debugging a program using execCmdEx now works

* only apply EINTR to c_gets for now

This reverts commit c0f5305.

lib.rst: add a link for jsconsole [backport] (#13383)

Make vccexe parse response files (#13329)

expectLen now shows the length that we got (#13387)

fix several bugs with `repr`  (#13386)

fixes #13378 [backport] (#13392)

remove dead code test_nimhcr_integration.(bat,sh) (#13388)

* enable test for osx: import tests/dll/nimhcr_integration

* re-disable osx test

fix linenoise regression (#13395)

* fix nightlies linenoise regression

* fix other installers

Revert "remove dead code test_nimhcr_integration.(bat,sh) (#13388)" (#13396)

This reverts commit 90491ea.
fixes #13368 (#13397)

fix bug in int128 (#13403)

isolate the build process from external config files (#13411)

add ggplotnim to important_packages (#13206)

Fix to asynchttpserver form data/body broken with #13147 (#13394)

* Fix to asynchttpserver form data/body broken with #13147
* New implementation that use a interator instance of future streams
* asynchttpserver now can handle chunks of data.

Merge branch 'devel' of https://github.com/nim-lang/Nim into osopen

Squash Commits; Peer review feedbacks #12901 (comment)
narimiran pushed a commit to narimiran/Nim that referenced this pull request Feb 19, 2020
* Add osOpen alias for the operating system specific open command

* Add `--git.devel` option to the documentation
remove unused import (nim-lang#12900)

fix json regression D20191212T144944 (nim-lang#12902) [backport]

Peer Review Feedback nim-lang#12901 (comment)

Merge branch 'devel' of https://github.com/nim-lang/Nim into osopen

Peer Review Feedback nim-lang#12901 (comment)

Update lib/pure/browsers.nim

Co-Authored-By: Dominik Picheta <dominikpicheta@googlemail.com>
Peer Review Feedback nim-lang#12901 (comment)

allow typed/untyped in magic procs (nim-lang#12911)

NaN floatFormat with clang_cl  (nim-lang#12910)

* clang_cl nan floatFormat

* format

add $nimeq for gdb (nim-lang#12909)

ARC: cycle detector (nim-lang#12823)

* first implementation of the =trace and =dispose hooks for the cycle collector
* a cycle collector for ARC: progress
* manual: the .acyclic pragma is a thing once again
* gcbench: adaptations for --gc:arc
* enable valgrind tests for the strutils tests
* testament: better valgrind support
* ARC refactoring: growable jumpstacks
* ARC cycle detector: non-recursive algorithm
* moved and renamed core/ files back to system/
* refactoring: --gc:arc vs --gc:orc since 'orc' is even more experimental and we want to ship --gc:arc soonish

Cleanup leftovers of nim-lang#12911(nim-lang#12916)

Fix single match output (nim-lang#12920)

fixes nim-lang#12899 (nim-lang#12921)

* fixes nim-lang#12899

* fixes regression: destroy global variables in reverse declaration order, closureleak test relies on it

Implement NixOS distro check (nim-lang#12914)

Better case coverage error message for alias and range enum (nim-lang#12913)

fix error in assertions document (nim-lang#12925) [backport]

fix cmdline bugs affecting nimBetterRun correctness (nim-lang#12933) [backport]

fix nim-lang#12919 tasyncclosestall flaky: Address already in use (nim-lang#12934)

system.reset is no longer magic (nim-lang#12937)

It has now means setting x to default for new and old runtime alike
Fix nim-lang#12785 (nim-lang#12943)

* Fix nim-lang#12785 and add test

* better variable name

update documentation for `closureScope` and `capture` (nim-lang#12886)

fixes nim-lang#12735 on osx, call dsymutil for debug builds (nim-lang#12931)

* fix nim-lang#12735 osx: dsymutil needs to be called for debug builds
* also write dsymutil command to extraCmds in json build file

Auto-initialize deques (nim-lang#12879)

case coverage error message for `char` (nim-lang#12948)

lenVarargs: number of varargs elements (nim-lang#12907)

docs: tiny style improvements

added guidelines for evolving Nim's stdlib

fixes a bug that kept sugar.collect from working with for loop macros [backport]

fixes nim-lang#12826

fixes a regression

a better bugfix

fixes a test case

fixes a silly regression

fixes the distros.nim regression

ported channels to ARC

ported osproc.nim to ARC

ported re.nim to ARC

ARC: default to a shared heap with --threads:on

osproc: fixes regression

fixes another regression

fixes nim-lang#12945 (nim-lang#12959)

minor refactorings

Fixes stackoverflow links in readme (nim-lang#12963) [backport]

Allow customize Host header
[ci skip] docfix .. < => ..< (nim-lang#12981) [backport]

parsecfg: retain CRLF line breaks, fixes nim-lang#12970 (nim-lang#12971)

generic stack trace overriding mechanism (nim-lang#12922)

* libbacktrace support

* switch to a generic stack trace overriding mechanism

When "nimStackTraceOverride" is defined, once of the imported modules
can register its own procedure to replace the default stack trace
generation by calling `registerStackTraceOverride(myOwnProc)`.

Tested with `./koch boot -d:release --debugger:native -d:nimStackTraceOverride --import:libbacktrace`
for the compiler itself and `./bin/nim c -r -f --stacktrace:off --debugger:native -d:nimStackTraceOverride --import:libbacktrace foo.nim`
for an external program.

* make the StackTraceOverrideProc {.noinline.}

Added fix for handling TaintedStrings in streams and httpclient (nim-lang#12969)

* Added fix for taint mode in streams and httpclient

* Removed taintMode export from system.nim

Check pqntuples > 0 in getValue. Fixes nim-lang#12973 (nim-lang#12974)

c_fflush() the rawWrite() buffer (nim-lang#12987)

Stack traces on an unbuffered stderr get out of sync with line-buffered
stdout - usually on Windows terminals or CI logs. This fixes it by
calling C's fflush() on the output buffer in the procedure used for
printing stack traces.
fixes nim-lang#12989

Revert "fixes nim-lang#12989"

This reverts commit 928c2fe.

fixes nim-lang#12965 (nim-lang#12991)

fixes nim-lang#12989 (nim-lang#12992)

* fixes nim-lang#12989
* Revert "remove unwanted changes"

This reverts commit 5018297.

fixes disruptek/nimph#102 multi-level nim.cfg use (nim-lang#13001) [backport]

--exception:goto switch for deterministic exception handling (nim-lang#12977)

This implements "deterministic" exception handling for Nim based on goto instead of setjmp. This means raising an exception is much cheaper than in C++'s table based implementations. Supports hard realtime systems. Default for --gc:arc and the C target because it's generally a good idea and arc is all about deterministic behavior.

Note: This implies that fatal runtime traps are not catchable anymore! This needs to be documented.
fix nim-lang#12985 {.push.} now does not apply to generic instantiations (nim-lang#12986)

Sink to MemMove optimization in injectdestructors (nim-lang#13002)

remove default argument for readLines (nim-lang#12807) [backport]

fixes nim-lang#12978 (nim-lang#13012)

Fix typo (nim-lang#13015) [backport]

fixes nim-lang#12961 (nim-lang#13019)

fixes nim-lang#12956 (nim-lang#13020)

fix nim-lang#12988 (nim-lang#13022)

fix nim-lang#12988
Fixes nim-lang#13026 (nim-lang#13028)

fixes nim-lang#12964 (nim-lang#13027)

fixes nim-lang#13032

VM: support importc var, ptr/pointer types, cast int <=> ptr/pointer (nim-lang#12877)

* VM: allow certain hardcoded special var variables at CT
* VM: allow all importc var, cast[int](ptr)
* fix tests tests/vm/tstaticprintseq.nim, tests/cpp/t8241.nim
* VM: == works for ptr/pointer nodes
* bugfix: ==, cast now also works for pointer, not just ptr
* VM supports cast PtrLikeKinds <=> PtrLikeKinds / int
* improve cname handling
* fixup + bug fix
* VM: support cast from ref to int
* address comment: opcLdGlobalDeref => opcLdGlobalDerefFFI
* defensive check against typ == nil

fix enumtostr crash for enum-range (nim-lang#13035)

fixes nim-lang#13013, reverts previous changes to readLines() (nim-lang#13036) [backport]

* Revert "remove default argument for readLines (nim-lang#12807) [backport]"

This reverts commit c949b81.

reprjs: style changes

fixes nim-lang#12996

Rst parser respect `:start-after:` and `:end-before:` in `include` directive (nim-lang#12972)

* [FEATURE] rst parser respect :start-after: in include

Rst parser now respects `:start-after:` and `:end-before:` attributes
for `include` directive.

* [DOC] include directive parsing proc update

* [TEST] Added unit tests for include rst directive in `rst` module

Allow `-o` option for `buildIndex` (nim-lang#13037) [backport]

Addressing nim-lang#12771

This is also included in the docgen documentation [here](https://nim-lang.org/docs/docgen.html) but its not respected as reported in the issue.
[cleanup] remove disabled (and obsolete) ttypetraits; rename ttypetraits2 => ttypetraits (nim-lang#13041)

* remove disabled (and obsolete) ttypetraits; rename ttypetraits2 => ttypetraits

* D20200105T085828 fix super strange bug that causes CI to fail: builds.sr.ht with: `Error: Settle timed out after 120 attempts`

Continue nim-lang#13002 (nim-lang#13021)

testament/important_packages dont run hts (nim-lang#13052)

Modify the test command for nimly (nimble-package) (nim-lang#13053)

clean up deprecated stuff and unused imports in tests (nim-lang#13059)

--styleCheck:hint now works (nim-lang#13055)

[easy] --hint:link:on now shows link cmd instead of nothing (nim-lang#13056)

* --hint:link:on now shows link cmd instead of nothing

* update doc for --listCmd

add pqserverVersion,pqconnectionNeedsPassword,pqconnectionUsedPassword (nim-lang#13060)

basename supports pragmaexpr (nim-lang#13045)

* basename supports pragmaexpr

* update changelog

distinctBase type trait for distinct types (nim-lang#13031)

make SuccessX show project file + output file (nim-lang#13043)

* make SuccessX show project file + output file
* address comments
* fix test and add `result.err = reNimcCrash` otherwise hard to see where reNimcCrash used
* address comments

move entries from the wrong changelog file [ci skip]

fix crash due to errant symbols in nim.cfg (nim-lang#13073) [backport]

Deleted misplaced separator (nim-lang#13085) [backport]

Misplaced separator, which was constantly breaking compilation on Haiku OS, was deleted.
take the one good idea from --os:standalone and enable it via -d:StandaloneHeapSize (nim-lang#13077)

remove all remaining warnings when build nim (with -d:nimHasLibFFI) (nim-lang#13084)

* cleanup deprecations in evalffi + elsewhere

* remove dead code getOrdValue64

Use '__noinline' instead of 'noinline' for N_NOINLINE gcc attribute, this prevents clashes with systems where 'noinline' might be already defined (nim-lang#13089)

Fix error check code in osproc (nim-lang#13090) [backport]

fixes nim-lang#13072; no test case because it will be added later with more exception handling related bugfixes

fixes nim-lang#13070

typetraits: fixes nim-lang#6454; genericParams; added lenTuple; added tuple type get (nim-lang#13064)

[backport] system/io.nim fix wrong documentation comment [ci skip]

fixes an asyncftpclient bug; refs nim-lang#13096 [backport]

System cleanup, part 1 (nim-lang#13069)

* system.nim: mark what every .pop does

* system.nim: un-nest when statements

[backport] fix nim-lang#12813, fix nim-lang#13079 (nim-lang#13099)

Correctly remove a key from CountTable when it is set to zero.
more arc features (nim-lang#13098)

* config update
* ARC now supports 'repr' and 'new' with finalizers is supported

Remove some unused/disabled OpenSSL functions (nim-lang#13106)

Add link to posix_utils.html in posix.nim (nim-lang#13111)

VM FFI: write(stderr, msg) and fprintf(cstderr, msg) now work at CT (nim-lang#13083)

fix the ftp store function read the local file bug (nim-lang#13108) [backport]

* Update asyncftpclient.nim

When use newStringOfCap function not have assign memory for the string data,so if use this address the fault is rasise.

* complelete the bugfix

fix rtti sizeof for varargs in global scope (nim-lang#13125) [backport]

fixes nim-lang#13122 (nim-lang#13126)

* fixes nim-lang#13122

* moved tests to where they belong

fixes nim-lang#13112 (nim-lang#13127)

* improve line error information

* fixes nim-lang#13112

Expose more openSSL methods. (nim-lang#13131)

fixes nim-lang#13100 nim doc now treats `export localSymbol` correctly (nim-lang#13123) [backport]

* fix nim-lang#13100 nim doc now treats `export localSymbol` correctly
* use owner instead

fixes nim-lang#13119 (nim-lang#13128)

* fixes nim-lang#13119
* fixes a regression

fixes nim-lang#13105 (nim-lang#13138)

fixes nim-lang#10665 (nim-lang#13141) [backport]

pass platform argument only if vccexe is used (nim-lang#13078)

* pass platform only if vccexe is used
* fixes nim-lang#12297

fixes nim-lang#13104 [backport] (nim-lang#13142)

fixes nim-lang#9674 [backport] (nim-lang#13143)

Fix typo in doc/destructors.rst (nim-lang#13148)

Added 'ansic' os support for minimal (embedded) targets (nim-lang#13088)

* os:any implementation
* os:asny: omit flock/funlock calls in echoBinSafe
* Disabled default "unhandled expection" reporting for `--os:any` to reduce
code size. Added unhandledExceptionHook instead which can be used to get
a notification from Nim and handle it from the application.

System cleanup, part 2 (nim-lang#13155)

* create basic_types, arithmetics, exceptions, comparisons
* create setops.nim
* create memalloc.nim
* create gc_interface.nim
* create iterators_1.nim

export normalizePathEnd (nim-lang#13152)

successX now correctly shows html output for `nim doc`, `nim jsondoc`; fix nim-lang#13121 (nim-lang#13116)

* successX now correctly shows html output for nim doc
* fixes nim-lang#13121
* fixup hintSuccessX to be less weird

ARC: misc bugfixes (nim-lang#13156)

* fixes nim-lang#13102
* closes nim-lang#13149
* ARC: fixes a move optimizer bug (there are more left regarding array and tuple indexing)
* proper fix; fixes nim-lang#12957
* fixes yet another case object '=' code generation problem

CI fix timeout error (nim-lang#13134)

Remove obsolete code from osalloc (nim-lang#13158)

style fix: change 'JS' to 'js' to make it consistent (nim-lang#13168)

Working towards arc codegen (nim-lang#13153)

fixes nim-lang#13029
fixes nim-lang#12998 nim doc regression (nim-lang#13117)

fix tsizeof3 for aarch64 (nim-lang#13169)

Cleanup DFA (nim-lang#13173)

Fix docs (nim-lang#13176)

fixes nim-lang#13095 (nim-lang#13181)

* fixes nim-lang#13095

* fix typo

make case-object transitions explicit, make unknownLineInfo a const, replace a few magic numbers with consts (nim-lang#13170)

ARC works for async on Windows (nim-lang#13179)

make sink operator optional (nim-lang#13068)

* make sink operator optional

* bug fix, add changelog entry

* Trigger build

* fix one regression

* fix test

* Trigger build

* fix typos

Fix docs for subdirs too (nim-lang#13180)

* Fix doc subdirs
* Extract to helper proc, and fix on windows

followup on nim-lang#10435 : should be diff, not show (nim-lang#13162)

fixes nim-lang#13157

refs nim-lang#13054 correctly handle {.exportc,dynlib.} and {.exportcpp,dynlib.}  (nim-lang#13136)

* refs nim-lang#13054 correctly handle {.exportc,dynlib.} and {.exportcpp,dynlib.}
* put back NIM_EXTERNC for N_LIB_EXPORT; causes issues with compilerproc

fixes nim-lang#13144 (nim-lang#13145)

* fixup: genscript now does not copy nimbase.h but uses -I$nim/lib

times: toUnixFloat, fromUnixFloat (nim-lang#13044)

maybe: allows optional chaining of field access and indexing when LHS i snil (nim-lang#13023)

* maybe: allows optional chaining
* fix tools/kochdocs.nim
* improve semantics to distinguish valid from invalid values
* for now, wrapnil, isValid, unwrap are not exported

fix docs + API for fieldPairs, fields (nim-lang#13189)

more on arc codegen (nim-lang#13178)

* arc codegen for union type

* add more tests

* fix offsetof

* fix tsizeof test

* fix style

Add link to packaging.html (nim-lang#13194)

Fixes nim-lang#13186 (nim-lang#13188)

fixes nim-lang#13195

revert last commit

Merge branch 'devel' of https://github.com/nim-lang/Nim into devel

Revert "fixes nim-lang#13195"

This reverts commit cd7904f.

fixes nim-lang#13110 (nim-lang#13197)

fixes nim-lang#13195 (nim-lang#13198)

* fixes nim-lang#13195

* extra fix

* fix typo

compiler/ccgtypes: hide exportc proc unless it has dynlib (nim-lang#13199)

This hides most of stdlib's internal functions from resulting
binaries/libraries, where they aren't needed on *nix. Static libraries
are not affected by this change (visibility doesn't apply to them).
fix range[enum] type conversion (nim-lang#13204) [backport]

Idxmin & idxmax, continuation (nim-lang#13208)

* Add idxmin() which returns the index of the minimum value

* Add idxmax() which returns the index of the maximum value

* Add tests for idxmin()

* Add tests for idxmax()

* Remove initialization of result = 0

* Adds overloading for arrays (no enums indexed arrays yet)

* Add support for enum index arrays

* Fix tests with enum

* Fix tests for idxmax

* Change names of the procedures to minIndex and maxIndex

* address Araq's comments:

- remove 'array' versions
- add .since pragma
- return 'int' instead of 'Natural'
- add changelog entry

Co-authored-by: Federico A. Corazza <20555025+Imperator26@users.noreply.github.com>

fix nim-lang#13211 relativePath("foo", ".") (nim-lang#13213)

fixes a critical times.nim bug reported on IRC [backport] (nim-lang#13216)

httpclient, maxredirects to Natural, newHttpClient/newAsyncHttpClient add headers argument instead of hardcoded empty (nim-lang#13207)

added note to re constructor regarding performance (nim-lang#13224)

Since I was new to regex I did not know that there is a compilation going on with ``re"[abc]"`` constructor and so I followed the other examples in the docs blindly, that is I just put the constructor directly in the arguments of match, find, etc., which was inside a loop and then wondered why my performance was so bad. Of course putting it outside the loop made it vastly more performant. People like me would benefit from the small note I added I would think :)
[backport] Documentation Fix nim-lang#12251 (nim-lang#13226) [ci skip]

[backport] times/getClockStr(): fix mistake in doc (nim-lang#13229) [ci skip]

new os.isRelativeTo (nim-lang#13212)

[backport] Fix typo and improve in code-block of 'lib/pure/parseutils.nim' (nim-lang#13231) [ci skip]

[backport] fix nim-lang#11440, add docs to isNil for seq types needing nilseq (nim-lang#13234) [ci skip]

VM: allow overriding MaxLoopIterations without rebuilding nim (nim-lang#13233)

kochdocs: use a glob instead of hardcoded list; generate docs for compiler/; bugfixes (nim-lang#13221)

* kochdocs: use a glob instead of hardcoded list; generate docs for compiler/; bugfixes
* fixup after nim-lang#13212 isRelativeTo got merged

fix lots of bugs with parentDir, refs nim-lang#8734 (nim-lang#13236)

Unexport even more symbols (nim-lang#13214)

* system/gc: don't export markStackAndRegisters

* compiler/cgen: unexport internal symbols

As these functions are Nim-specific walkaround against C's optimization
schemes, they don't serve any purpose being exported.

* compiler/cgen: don't export global var unless marked

* compiler/ccgthreadvars: don't export threadvar unless marked

* tests/dll/visibility: also check for exports

This ensure that these changes don't break manual exports.

* compiler/cgen: hide all variables created for constants

* compiler/ccgtypes: don't export RTTI variables

* compiler/ccgexprs: make all complex const static

* nimbase.h: fix export for windows

* compiler/cgen, ccgthreadvars: export variables correctly

For C/C++ variables, `extern` means that the variable is defined in an
another unit. Added a new N_LIB_EXPORT_VAR to correctly export
variables.

Removed lib/system/allocators.nim. seqs_v2 and strs_v2 now uses allocShared0. (nim-lang#13190)

* Cleanup, remove lib/system/allocators.nim. seqs_v2 and strs_v2 now use
allocShared0 by default.

* Fixed -d:useMalloc allocShared / reallocShared / deallocShared. These now use the alloc/dealloc/realloc implementation that also takes care of zeroing memory at realloc.

* Removed debug printfs

* Removed unpairedEnvAllocs() from tests/destructor/tnewruntime_misc

* More mmdisp cleanups. The shared allocators do not need to zero memory or throw since the regular ones already do that

* Introduced realloc0 and reallocShared0, these procs are now used by
strs_v2 and seqs_v2. This also allowed the -d:useMalloc allocator to
drop the extra header with allocation length.

* Moved strs_v2/seqs_v2 'allocated' flag into 'cap' field

* Added 'getAllocStats()' to get low level alloc/dealloc counters. Enable with -d:allocStats

* *allocShared implementations for boehm and go allocators now depend on the proper *allocImpl procs

[backport] documentation: Add channels examples (nim-lang#13202) [ci skip]

[backport] Make all parseutils examples auto-checking (nim-lang#13238)

- Also fix one example's output (ikString -> ikStr, ikVar instead of ikExpr)
Updated 'nim for embedded systems' section to use --os:any and --gc:arc (nim-lang#13237)

* Updated 'nim for embedded systems' section to use --os:any and --gc:arc

* Added section about size optimization to embedded systems

Remove name attribute from docutils.nimble (nim-lang#13239)

Fixes asyncftpclient multiline reading, fixes nim-lang#4684 (nim-lang#13242)

Previously, the 4th character of `result` was checked for `'-'` every time, instead of each new line.

Also made it work for taint mode.
Fix typo for literal `[` (nim-lang#13243)

The literal value for the `tkBracketLe` token was incorrectly set to `]` rather than `[`. I've had a quick glance at the code and it doesn't look like this change will affect anything at all, but I haven't tested yet - let's see if the CI explodes...
Add "origin" to window.location (nim-lang#13251)

Add "origin" to window location: https://www.w3schools.com/jsref/prop_loc_origin.asp
nim dump: add libpath (nim-lang#13249)

contributing docs: symbols need package prefix; changed allocStats to nimAllocStats (nim-lang#13247)

testament/azure: major rewrite (nim-lang#13246)

This commit features a major rewrite of Azure Pipelines integration,
turning the spaghetti it originally was into something maintainable.

Key changes:
- No longer requires a ton of hooks into testament.
- Results are now cached then bulk-uploaded to prevent throttling from
  Azure Pipelines, avoiding costly timeouts.
- A low timeout is also employed to avoid inflated test time.
- The integration is now documented.
Cleaned up mmdisp.nim, moved implementations into lib/system/mm/ (nim-lang#13254)

make goto based exceptions available for 'nim cpp' (nim-lang#13244)

* make goto based exceptions available for 'nim cpp'
* optimize seq.add to be comparable to C++'s emplace_back

ARC: remove unnecessary code

ARC: optimize complete object constructors to use nimNewObjUninit

make nre compile with --gc:arc

Rename isNilOrWhitespace to isEmptyOrWhitespace and make it use allCharsInSet (nim-lang#13258)

* Rename isNilOrWhitespace to isEmptyOrWhitespace

* Make isEmptyOrWhitespace use allCharsInSet(Whitespace)

Clearer final objects error; fixes nim-lang#13256 (nim-lang#13257)

scrollTop must be settable (nim-lang#13263)

* scrollTop must be assignable

Make scrollTop settable

* add missing export

fixes nim-lang#13219 (nim-lang#13272)

fixes nim-lang#13281 (nim-lang#13282)

* fixes #nim-lang#13281

* add comment to test

unittest add resetOutputFormatters proc (nim-lang#13267)

* add resetOutputFormatters

* remove space

* resolve comments

TlSF Alloctor: use less memory for --gc:arc (nim-lang#13280)

Tiny since cleanup (nim-lang#13286)

nimv2 widestring indexing (nim-lang#13279)

Repr v2 progress (nim-lang#13268)

* progress on repr_v2

* repr progress

* add ref objects with distrinct

* fix failing tests

refactor htmldocs; gitignore it

removed unused import

fix stdout(etc) for emscripten

csize => csize_t for sysctl

Thread attributes should be destroyed using the pthread_attr_destroy() (nim-lang#13293)

On some OSes (such as FreeBSD or Solaris), pthread_attr_init allocate
memory. So it is necessary to deallocate that memory by using
pthread_attr_destroy.
fix critical bug discovered by nim-lang#11591 (nim-lang#13290) [backport]

miscellaneous bug fixes (nim-lang#13291)

* fix for emscripten etc

* add testcase for nim-lang#13290

* replace deprecated isNilOrWhitespace

CT FFI: fix for windows; fix case transition; error msg shows more useful context (nim-lang#13292)

* evalffi: fix case transition
* evalffi: fix for windows
* evallffi: `cannot import` errmsg now also shows which library it tried to import symbol from

refs nim-lang#8391 std/os now shows runtime context for raiseOSError exceptions (nim-lang#13294)

* refs nim-lang#8391: fix errmsg for setCurrentDir

* raiseOSError calls for copyFile

* refs nim-lang#8391 std/os now shows runtime context for raiseOSError exceptions

build_all.sh: building csources 5X faster thanks to make -j (nim-lang#13300)

* build_all.sh: building csources 5X faster thanks to make -j
* fix for freebsd
* use OS-dependent formula to get number of logical cores
* make is an optional dependency

Fix capture for object types (nim-lang#13315)

* Fix capture for object|tuple|... types

* Add test case

Quote nim executable before executing. (nim-lang#13316) [backport]

In case nim executable is located in PATH containing spaces.

fixes nim-lang#13311
ReSync with devel

Make build_all.sh more portable and a bit simpler (nim-lang#13308)

koch: enable checks in the compiler when running CI (nim-lang#13323)

fix nim-lang#13132 tnetdial (nim-lang#13318)

enable testing -d:nimHasLibFFI mode (nim-lang#13091)

Fix nim-lang#10717, fix nim-lang#13284 (nim-lang#13307)

Fixed codegen for constant cstring with --gc:arc (nim-lang#13326)

* Fixed codegen for constant cstring with --gc:arc, fixes  nim-lang#13321

* Added test for nim-lang#13321

Option to allow the request body to be processed outside the asynchttpserver library. (nim-lang#13147)

Allow the request body to be processed outside the asynchttpserver library to break big files into chunks of data. This change does not break anything.

build_all.sh update (nim-lang#13320)

* Don't overload the system, don't crash when you can't determine the CPU count and don't rely on bash

* Extract to variable

* Limit number of spawned jobs for systems with weak IO

* Use proper arithmetic braces

contributing.rst: Add a special rule for 'outplace'-like features

[backport] -d:danger should imply -d:release (nim-lang#13336)

nim secret: support linenoise when available (nim-lang#13328)

fix nim-lang#13150 `nim doc --project` now works reliably (nim-lang#13223)

* fix nim-lang#13150 `nim doc --project` works with duplicate names and with imports below main project file

* add to help; fixup after nim-lang#13212 isRelativeTo got merged
* fix test tests/compilerapi/tcompilerapi.nim
* remove nimblePkg field; compute on the fly instead
* kochdocs: compiler docs now under compiler/
* --docRoot now has smart default: best among @pkg, @path

make monotimes have zero overhead if you don't use it (nim-lang#13338) [backport]

fix nim-lang#13349 regression: isNamedTuple now works with generic tuples (nim-lang#13350)

fixes nim-lang#13269 (nim-lang#13344)

adding sqlite3 backup functions (nim-lang#13346)

* adding sqlite3 backup functions

* changing sleep to sqlite3_sleep to prevent clashes

Added a basic example how to handle a Post request. (nim-lang#13339)

* Added a basic example how to handle a Post request.

They were also made minor cosmetic changes.

* Minor fixes suggested by Yardanico

* Fixed a wrong value in chunkSize constant.

* Re-added the request.body for compatibility!

replace old problematic isNamedTuple implementation by TypeTrait isNamedTuple in dollars.nim (nim-lang#13347)

* replace old problematic isNamedTuple implementation by TypeTrait isNamedTuple

* fix for bootstrap

fix nim-lang#13182: `proc fun(a: varargs[Foo, conv])` now can be overloaded (nim-lang#13345) [backport]

miscellaneous bug fixes (part 3) (nim-lang#13304)

* fix deprecation; fix indentation

* git clone: use -q

* fix Warning: pragma before generic parameter list is deprecated; fix typo

* bugfix: sysTypeFromName("float64") was never cached

testament: introduce 'matrix' for testing multiple options (nim-lang#13343)

printing float values will have one more digit. (nim-lang#13276) [backport]

* printing float values will have one more digit. Fixes nim-lang#13196

[backport] fix nim-lang#13352

[backport] remove 'CountTable.mget' (nim-lang#13355)

It didn't work, and it was an oversight to be included in v1.0.
fix nim-lang#6736: templates in unittest now show actual value (nim-lang#13354)

Revert "printing float values will have one more digit. (nim-lang#13276) [backport]" (nim-lang#13363)

This reverts commit b2c6db9.
Add sideEffect pragma to importC procs in posix, winlean and time module (nim-lang#13370)

* Add sideEffect pragma to procs in winlean
* Add sideEffect pragma to procs in posix
* Add test for nim-lang#13306
* Add sideEffect pragma to procs in times
* Fixes nim-lang#13306
fixes nim-lang#3339 by documenting the limitations of case-statement (nim-lang#13366)

fixes nim-lang#13314 (nim-lang#13372)

testament: this now works: "testament r /abspath/to/test.nim" (nim-lang#13358)

fix `is` with generic types; fix `genericHead(Foo[T])` (nim-lang#13303)

* fix nim-lang#9855, fix nim-lang#9855, fix genericHead
* render TTypeKind via toHumanStr

fix nim-lang#13255 (nim-lang#13275) [backport]

remove outplace version of 'merge' for CountTables (nim-lang#13377)

* remove outplace version of 'merge' for CountTables

* remove 'merge' tests

fix nim-lang#13374 `nim c -r -` now generates $nimcache/stdinfile (nim-lang#13380) [backport]

fix nim-lang#9634 don't crash on execCmdEx/readLine when inside gdb/lldb (nim-lang#13232)

* fix nim-lang#9634 debugging a program using execCmdEx now works

* only apply EINTR to c_gets for now

This reverts commit c0f5305.

lib.rst: add a link for jsconsole [backport] (nim-lang#13383)

Make vccexe parse response files (nim-lang#13329)

expectLen now shows the length that we got (nim-lang#13387)

fix several bugs with `repr`  (nim-lang#13386)

fixes nim-lang#13378 [backport] (nim-lang#13392)

remove dead code test_nimhcr_integration.(bat,sh) (nim-lang#13388)

* enable test for osx: import tests/dll/nimhcr_integration

* re-disable osx test

fix linenoise regression (nim-lang#13395)

* fix nightlies linenoise regression

* fix other installers

Revert "remove dead code test_nimhcr_integration.(bat,sh) (nim-lang#13388)" (nim-lang#13396)

This reverts commit 90491ea.
fixes nim-lang#13368 (nim-lang#13397)

fix bug in int128 (nim-lang#13403)

isolate the build process from external config files (nim-lang#13411)

add ggplotnim to important_packages (nim-lang#13206)

Fix to asynchttpserver form data/body broken with nim-lang#13147 (nim-lang#13394)

* Fix to asynchttpserver form data/body broken with nim-lang#13147
* New implementation that use a interator instance of future streams
* asynchttpserver now can handle chunks of data.

Merge branch 'devel' of https://github.com/nim-lang/Nim into osopen

Squash Commits; Peer review feedbacks nim-lang#12901 (comment)

(cherry picked from commit ba25f84)
@timotheecour timotheecour changed the title [TODO] maybe: allows optional chaining of field access and indexing when LHS i snil [TODO] wrapnils: allows optional chaining of field access and indexing when LHS i snil May 1, 2020
@doongjohn
Copy link

doongjohn commented Aug 8, 2020

# nim v1.2.6
# Windows 10 x64

type Person = ref object
  name: string
  age: int

var person: Person = nil

echo ?.person.name != "" # false
echo ?.person.name != "no name" # true
echo ?.person.age != 0 # false

echo ?.person.name != "no name" # true Is this intended?

@timotheecour
Copy link
Member Author

Yes, why is it surprising? There is a nil in the chain, so it returns default(string) (string is the type of the expression)

@doongjohn
Copy link

Oh, I thought if it's null then the result will always be false.

@doongjohn
Copy link

What do you think about adding ??. for returning Option[T]?

# wrapnils.nim
# ...

# this returns Option[T] instead of default value.
macro `??.`*(a: untyped): untyped =
  result = replace(a)
  result = quote do:
    if `result`.validImpl:
      some(`result`.valueImpl)
    else:
      none(`result`.valueImpl.type)
# Option helper
# just to make things simpler :)

proc `==`*[T](a: Option[T], b: T): bool {.inline.} =
  if a.isNone: return false
  return a.get() == b

proc `!=`*[T](a: Option[T], b: T): bool {.inline.} =
  if a.isNone: return true
  return a.get() != b
type Person = ref object
  name: string
  age: int

var john = Person(name: "John", age: 20)
echo ??.john.name == "John" # true
echo ??.john.age != 20 # false
john = nil
echo ??.john.name == "" # false
echo ??.john.age != 0 # true

@timotheecour
Copy link
Member Author

@doongjohn see #16931 which should solve your problem; note that == and != as you described are IMO not a good idea so I didn't do that.

@timotheecour timotheecour changed the title [TODO] wrapnils: allows optional chaining of field access and indexing when LHS i snil wrapnils: allows optional chaining of field access and indexing when LHS i snil Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants