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

misc feature requests #86

Open
1 task
timotheecour opened this issue Apr 4, 2020 · 42 comments
Open
1 task

misc feature requests #86

timotheecour opened this issue Apr 4, 2020 · 42 comments
Labels

Comments

@timotheecour
Copy link
Owner

timotheecour commented Apr 4, 2020

  • int128_t
  • the compiler's implementation of Int128 could just use __int128 or int128_t for compilers that support it (most compilers nowadays; TODO: what about MSVC?); should be faster
  • that type could be exposed in stdlib (but then maybe we also need Int256? maybe only in certain cases?)
  • the compiler's implementation of Int128 could have tests against int128_t (to be run on platforms that support it)
@timotheecour
Copy link
Owner Author

timotheecour commented Apr 4, 2020

=> #127

@timotheecour
Copy link
Owner Author

toMsgFilename:
use "$nim/lib/system.nim"
insted of things like "/../../Nim_prs/lib/system.nim"
when we have optListFullPaths off

@timotheecour
Copy link
Owner Author

thispkg

avoid ambiguities by allowing to refer to current nimble package

import thispkg/foo # restrict search to current package (don't resolve using other nimble packages nor stdlib)
const dir = getCurrentNimblePath() # resolves to path of enclosing nimble file in a parent dir

links

@timotheecour
Copy link
Owner Author

--warningAsError:on (see nim-lang@9c46927#commitcomment-38288400)

@timotheecour
Copy link
Owner Author

instead of introducing all those nimHasX (eg nimHasInvariant from nim-lang@2b3b24a) bootstrap flags, why not simply bump NimPatch after each such feature is introduced? (and check with since (1,3,5) instead of when defined(nimHasInvariant) )

if feature is later removed, we can just do between (1,3,5), (1,3,7)

@timotheecour
Copy link
Owner Author

localize define pragma
nim-lang@a890aa7#commitcomment-38288755

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 5, 2020

dispatchStrings

goal:
replace this:

case mystr
of "foo1": fun1
of "foo2": fun2

(commonly used pattern, and has a lot of drawbacks) with something easier to use, more efficient:
note: could also use the caseStmtMacros syntax

dispatchStrings(a: seq[string], b: string):

benefits:

  • no need to normalize and give ugly (requiring -i to search) normalized case keys hiding the fooBar
  • uses most efficient algo possible (eg binary search)
  • DRY: allows access to set of keys at CT

note

compiler could also optimize case of for strings, it right now generates suboptimal code eg:

        if (eqStrings(a, ((NimStringDesc*) &TM__5AYZFnjJ9ao1QQmyuowdBNw_2))) goto LA1_;
        if (eqStrings(a, ((NimStringDesc*) &TM__5AYZFnjJ9ao1QQmyuowdBNw_3))) goto LA2_;
        if (eqStrings(a, ((NimStringDesc*) &TM__5AYZFnjJ9ao1QQmyuowdBNw_4))) goto LA3_;
        if (eqStrings(a, ((NimStringDesc*) &TM__5AYZFnjJ9ao1QQmyuowdBNw_5))) goto LA4_;
        goto LA5_;
        LA1_: ;
        {
                nimln_(23, "/Users/timothee/git_clone/nim/timn/tests/nim/all/t10501.nim");
                echoBinSafe(TM__5AYZFnjJ9ao1QQmyuowdBNw_6, 1);
        }

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 5, 2020

goto D20200405T000014

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 5, 2020

caseStmtMacros should be like everything else, w a function call eg:

case mymatch(key) # instead of case key
of ok1: bar1
of ok2: bar2
else: discard

D20200405T033816

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 5, 2020

type T = typeof(block: x = 0) should compile (and resolve to T is void) D20200405T063825

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 5, 2020

astGet

analog to astToStr but to retrieve the ith element of an AST node (avoid macros when we don't want to write a macro and can't import macros etc)

template fun(a): untyped =
  let astGet(a,0): astGet(a, 1) = astGet(a, 2)

same as:

macro fun(a): untyped =
  let a0 = astGet(a,0)
  let a1 = astGet(a,1)
  let a2 = astGet(a,2)
  quote do:
    let `a0`: `a1` = `a2`

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 5, 2020

--msgpaths:full/rel/var

  • works "always" even after nim was built wo that option; idea maybe could be to check an ENV VAR to decide how to format output paths
  • allows shortening paths using $nim/ $pkg etc, eg $cligen/foo/bar.nim
  • customize whether it's foo:line:col or foo(line, col)
  • maybe simplest is via a fmt string eg:
--msgpaths:$full:$line:$col # posix way file.nim:12:13
--msgpaths:$full($line, $col)
--msgpaths:$rel($line) # relative to cwd
--msgpaths:$projectpath # like with current --listfullpaths:off
--msgpaths:$blue$rel($line)$normal # color
--msgpaths:$vars # shortens /pathto/Nim/lib/foo.nim to $nim/lib/system.nim

can any of this be done w a shared library dlopened' by nim to defer it to custom logic?

@timotheecour
Copy link
Owner Author

  • custom nim plugin loaded via dlopen to customize certain callbacks

@timotheecour
Copy link
Owner Author

should user defined pragmas or builtin pragmas require special syntax to avoid clashes (eg when new pragmas are added)?
at least we shd error if a name clashes and provide way to disambiguate eg using fqname or {.@foo.}

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 6, 2020

  • getAppFilename should get a resolveSymlinks option

eg use case: the exe is in a path w spaces, and a symlink hides the spaces => i want the symlink, not resoved path

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 6, 2020

=> #182

@timotheecour
Copy link
Owner Author

option to show how to process output file, eg:
nim c --process:"lldb $cmd" main.nim
which will run under a debugger in this example:
lldb outfile args

other options include: running dsymutil etc

@timotheecour
Copy link
Owner Author

runtime localized checks

@timotheecour
Copy link
Owner Author

this should be supported in some way
c_printf("s1=%"PRIu64"\n", s.uint64);

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 9, 2020

for i,a in somjson: discard shd work for JArray

Error: unhandled exception: /Users/timothee/git_clone/nim/Nim_devel/lib/pure/json.nim(764, 10) node.kind == JObject : pairs() can not iterate a JsonNode of kind JArray

EDIT:
or maybe more generally, instead we need to be explicit eg enumerate, eg:
for i,a in somejson.enumerate

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 10, 2020

this really should be specified in https://nim-lang.org/docs/nep1.html. Here are sane conventions:

  • always use single quotes eg 'foo'
  • pragmas should always use a dot, eg: '.importc'

rationale:

  • backtick is not good because some symbols (eg operators) already require a backtick and docgen needs backtick too.
  • '.importc' is less verbose than {.importc.} and equally unambiguous
  • as done in D and other compilers, nim compiler could automatically color-code/highlight single quoted symbols it sees in error messages eg 'foo' (with --colors:on).

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 10, 2020

EDIT: see tsizeof.c_sizeof => expose it

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 10, 2020

we need to be able to {.emit:"/*HERE*/ int `ret` = 1;".} because emit goes otherwise in different section, eg BUG:

macro c_sizeof(a: typed): int32 =
  ## Bullet proof implementation that works using the sizeof operator
  ## in the c backend. Assuming of course this implementation is
  ## correct.
  result = quote do:
    var res: int32
    {.emit: [res, " = sizeof(", `a`, ");"] .}
    res

appears correct but in fact compiling wo -w gives:

/Users/timothee/git_clone/nim/timn/build/nimcache/@mt10524.nim.c:62:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
resX60gensym16836048___UNSWjIfCauW7KQ8SZW8T6A = sizeof(struct dirent);
^
/Users/timothee/git_clone/nim/timn/build/nimcache/@mt10524.nim.c:104:1: warning: attribute declaration must precede definition [-Wignored-attributes]
N_LIB_PRIVATE NI32 resX60gensym16836048___UNSWjIfCauW7KQ8SZW8T6A;

edit: works inside proc but not at module block scope; is that a bug?

EDIT:
sounds easy to implement:

proc determineSection(n: PNode): TCFileSection =
  result = cfsEmits # WAS: cfsProcHeaders
  if n.len >= 1 and n[0].kind in {nkStrLit..nkTripleStrLit}:
    let sec = n[0].strVal
    if sec.startsWith("/*TYPESECTION*/"): result = cfsTypes
    elif sec.startsWith("/*VARSECTION*/"): result = cfsVars
    elif sec.startsWith("/*INCLUDESECTION*/"): result = cfsHeaders

proc genEmit(p: BProc, t: PNode) =
  var s = genAsmOrEmitStmt(p, t[1])
  if p.prc == nil:
    # top level emit pragma?
    let section = determineSection(t[1])
    genCLineDir(p.module.s[section], t.info, p.config)
    p.module.s[section].add(s)
  else:
    genLineDir(p, t)
    line(p, cpsStmts, s)

note: other name could be INLINE but that's overloaded

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 10, 2020

  • could we simplify pragma with:
    {.foo, bar.} => {foo, bar}
    would that cause any ambiguity ever (with sets)?

  • other option:
    {.foo, bar.} => @foo, bar
    eg:

var a: {.noinit.}: int
proc fun(): int {.async, inline.} = discard
{.push experimental: foo.}
=>
var a @noinit: int
proc fun(): int @async, inline = discard
@(push experimental: foo)

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 10, 2020

we need a way to distinguish user defined pragmas and builtin pragmas otherwise introduction of new builtins (or user defined) could clash
maybe:

proc fun(): int {.!newbuiltin.}

alternative: with 1st class pragma (eg nim-lang#13016) maybe all builtins can be exported from system (and therefore, still be technically overridable, which is sane)

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 16, 2020

  • VM cast
  • Error: VM does not support 'cast' from tyInt to tyCString
    eg for tests/vm/mevalffi.nim

  • Error: VM does not support 'cast' from tyPtr to tyCString

  • Error: deref unsupported ptr type: ("ptr cstring", tyPtr)
    var buffer1b = castptr cstring[]

links

D20200416T133904

@timotheecour
Copy link
Owner Author

allow passing a path for cc eg:
nim c --cc:zig --cc.path:/pathto/zig_temp main
(is it possible now?)

@timotheecour
Copy link
Owner Author

nim should have a way to show and update progress on same line without creating large terminal output, like zig (eg: zig c++ -o /tmp/z01 /Users/timothee/git_clone//nim//timn/src/timn/examples/thellocpp.cpp), probably using ncurses

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 18, 2020

@timotheecour
Copy link
Owner Author

resumable iterator (eg if throws)

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 19, 2020

  • recursive {.push overflowChecks: off.} that would apply to called functions without RT overhead; probably requires nim logic to duplicate such code if needed;
  • recursive {.push overflowChecks: off.} that would apply to called functions; with a small runtime overhead that checks whether to check for overloads; much simpler to implement and might be more efficient due to less cgen code duplication; the bool flag should be easy for branch predictors

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 22, 2020

  • approxEqual

@timotheecour
Copy link
Owner Author

  • getCompilerVersion to get the nim version the compiler was compiled with
    so that works w bootstrapping (or when nim --lib:lib compiler/nim) and reduces need for all those define symbols

the way to do it is via extending querySetting to support arbitrary type, eg tuple
either by making it magic, or by getting type as typedesc

should we use distinct string or tuple?

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 22, 2020

utility to make it easier to deal w compiler version, eg ctVersion or NimVer:
when nimver < "1.2.1"
where nimver is a distinct string

see also: nim-lang#14648

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 22, 2020

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 25, 2020

  • --hint:SuccessX should work and mean --hint:SuccessX:on

=> nim-lang#14271

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 25, 2020

  • extend nimCompilerStackraceHints scope

@timotheecour timotheecour added enhancement New feature or request feature and removed enhancement New feature or request labels Apr 29, 2020
@timotheecour
Copy link
Owner Author

timotheecour commented Apr 29, 2020

KEY panic exceptions
--panic:OutOfMemError:on --panic:AssertionError:on

--panics:on # Defects terminate (can't be caught)
--panics:list # will list all selected panics (eg from cmdline + cfg files)
--panic:OutOfMemError:on  --panic:AssertionError:on # these 2 Defects will become non-catchable
which is more flexible for users who care about maximizing performance but still want to allow one specific type of defect to be catchable, depending on their applicatin.

links

nim-lang#13908 (comment)

@timotheecour
Copy link
Owner Author

  • getProjectPath() is useless; we need: getProjectFile (returning absolute path)
    EDIT: maybe it's projectFull in compilersettings

  • also, maybe be useful to be able to report path to currently executing nims file

@timotheecour
Copy link
Owner Author

  • expose typeToString from ttypetraits

@timotheecour
Copy link
Owner Author

timotheecour commented May 18, 2020

=> #479

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant