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

generics caching buggy and order-sensitive #13572

Open
timotheecour opened this issue Mar 3, 2020 · 0 comments
Open

generics caching buggy and order-sensitive #13572

timotheecour opened this issue Mar 3, 2020 · 0 comments
Labels

Comments

@timotheecour
Copy link
Member

timotheecour commented Mar 3, 2020

  • generics caching is buggy and order-sensitive
  • import order affects which generic instantiation gets cached, resulting in surprising behavior when unrelated code changes
  • there's no way to "recover" from a generic instantiation, see example below; note that the "first-arrived" instantiation deepDownHidden1 could be hidden really deep inside some code and it'd be hard to find where or why proc $(a: FileIndex): string = "FOO" in main.nim isn't picked up in a more complex example

Example

#t10297_types.nim:
type
  FileIndex* = distinct int32
  TLineInfo* = object
    line*: uint16
    col*: int16
    fileIndex*: FileIndex

# t10297c.nim
import t10297_types
proc deepDownHidden1() = discard $TLineInfo.default

# t10297d.nim
import t10297_types
proc `$`*(a: FileIndex): string = $a.int32
proc deepDownHidden2() = discard $TLineInfo.default

#main.nim
import t10297_types
import t10297c
import t10297d

proc `$`(a: FileIndex): string = "FOO"
echo TLineInfo.default

Current Output

# as is it shows:
(line: 0, col: 0, fileIndex: ...)
# flip order of import t10297c vs import t10297d in main:
(line: 0, col: 0, fileIndex: 0)
# comment both import t10297c and import t10297d
(line: 0, col: 0, fileIndex: FOO)

Expected Output

(line: 0, col: 0, fileIndex: FOO)

Additional Information

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

2 participants