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

All symbols in concepts should be open by default #7222

Closed
zah opened this issue Feb 15, 2018 · 1 comment
Closed

All symbols in concepts should be open by default #7222

zah opened this issue Feb 15, 2018 · 1 comment
Assignees
Labels

Comments

@zah
Copy link
Member

zah commented Feb 15, 2018

Consider the following concept:

trie_database.nim:

type
  KeccakHash* = object
    data*: string

  BytesRange* = object
    bytes*: string

  TrieDatabase* = concept db
    mixin put, get, del

    put(var db, KeccakHash, string) is bool
    del(var db, KeccakHash) is bool
    get(db, KeccakHash) is string

With the following usage:

import
  hashes, tables, trie_database

type
  MemDBTable = Table[KeccakHash, string]

  MemDB* = object
    tbl: MemDBTable

proc hash*(key: KeccakHash): int =
  hashes.hash(key.data)

proc get*(db: MemDB, key: KeccakHash): string =
  db.tbl[key]

proc del*(db: var MemDB, key: KeccakHash): bool =
  if db.tbl.hasKey(key):
    db.tbl.del(key)
    return true
  else:
    return false

proc put*(db: var MemDB, key: KeccakHash, value: string): bool =
  db.tbl[key] = value
  return true

proc takeDb(d: TrieDatabase) = discard
var mdb: MemDB

takeDb(mdb) {.explain.}

It won't be matched unless mixin is used in the concept body, because the del symbol from the system module will be closed in the generic pre-pass of the concept body. We should resolve the issue by considering all symbols within concepts open (mixed in) by default.

@zah zah added the Concepts label Feb 15, 2018
@zah zah self-assigned this Feb 15, 2018
@Araq
Copy link
Member

Araq commented Feb 16, 2018

Supported by #7114, I think. So yes, I agree.

zah added a commit that referenced this issue Jun 12, 2018
* late instantiation for the generic procs' default param values
* automatic mixin behaviour in concepts

Other fixes:

* don't render the automatically inserted default params in calls
* better rendering of tyFromExpr
zah added a commit that referenced this issue Jun 16, 2018
* late instantiation for the generic procs' default param values
* automatic mixin behaviour in concepts

Other fixes:

* don't render the automatically inserted default params in calls
* better rendering of tyFromExpr
zah added a commit that referenced this issue Jun 16, 2018
* late instantiation for the generic procs' default param values
* automatic mixin behaviour in concepts

Other fixes:

* don't render the automatically inserted default params in calls
* better rendering of tyFromExpr
@Araq Araq closed this as completed in 5bcf8bc Jun 26, 2018
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