-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
add default field support for object in ARC/ORC #20480
Conversation
In the following up PRs, there are few improvements which can be applied:
|
compiler/semstmts.nim
Outdated
@@ -680,6 +689,9 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode = | |||
addToVarSection(c, result, n, a) | |||
continue | |||
var v = semIdentDef(c, a[j], symkind, false) | |||
if {sfThread, sfNoInit} * v.flags != {}: | |||
a[^1] = c.graph.emptyNode | |||
def = c.graph.emptyNode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be a bad idea, what about var x {.noInit.} = f()
? You turn this into var x {.noInit.} = <default>
? Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I forget to consider that situation. Now I use a node flag to distinguish whether the node is from default field initialization or from explicit initialization ee53173
nfUseDefaultField
is originally used for object fields and the two usages don't overlap.
compiler/semstmts.nim
Outdated
@@ -1639,6 +1651,20 @@ proc addResult(c: PContext, n: PNode, t: PType, owner: TSymKind) = | |||
n.add newSymNode(c.p.resultSym) | |||
addParamOrResult(c, c.p.resultSym, owner) | |||
|
|||
proc addDefaultFieldForResult(c: PContext, n: PNode, t: PType) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addDefaultFieldForResult
adds default values for implicit variables within procs:
transform
proc foo(): Object =
discard
into
proc foo(): Object =
result = Object()
discard
So that default values are applied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary if we do nim-lang/RFCs#378 and I think we should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will undo the default fields for results.
let field = defaultNodeField(c, a[^2]) | ||
if field != nil: | ||
a[^1] = field | ||
let m = copyTree(a[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need a copyTree
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is an old change and has been removed since ee53173. And it didn't work since semIdentDef(c, m, symkind, false)
affected the ic tests.
Thanks for your hard work on this PR! Hint: mm: orc; opt: speed; options: -d:release |
Was this documented? Not in changelog either |
It will be documented after bugs are fixed. |
* fresh start * add cpp target * add result support * add nimPreviewRangeDefault * reduce * use orc * refactor common parts * add tuple support * add testcase for tuple * cleanup; fixes nimsuggest tests * there is something wrong with cpp * remove * add support for seqs * fixes style * addd initial distinct support * remove links * typo * fixes tuple defaults * add rangedefault * add cpp support * fixes one more bugs * add more hasDefaults * fixes ordinal types * add testcase for nim-lang#16744 * add testcase for nim-lang#3608 * fixes docgen * small fix * recursive * fixes * cleanup and remove tuple support * fixes nimsuggest * fixes generics procs * refactor * increases timeout * refactor hasDefault * zero default; disable i386 * add tuples back * fixes bugs * fixes tuple * add more tests * fix one more bug regarding tuples * more tests and cleanup * remove messy distinct types which must be initialized by original types * add tests * fixes zero default * fixes grammar * fixes tests * fixes tests * fixes tests * fixes comments * fixes and add testcase * undo default values for results Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
* fresh start * add cpp target * add result support * add nimPreviewRangeDefault * reduce * use orc * refactor common parts * add tuple support * add testcase for tuple * cleanup; fixes nimsuggest tests * there is something wrong with cpp * remove * add support for seqs * fixes style * addd initial distinct support * remove links * typo * fixes tuple defaults * add rangedefault * add cpp support * fixes one more bugs * add more hasDefaults * fixes ordinal types * add testcase for #16744 * add testcase for #3608 * fixes docgen * small fix * recursive * fixes * cleanup and remove tuple support * fixes nimsuggest * fixes generics procs * refactor * increases timeout * refactor hasDefault * zero default; disable i386 * add tuples back * fixes bugs * fixes tuple * add more tests * fix one more bug regarding tuples * more tests and cleanup * remove messy distinct types which must be initialized by original types * add tests * fixes zero default * fixes grammar * fixes tests * fixes tests * fixes tests * fixes comments * fixes and add testcase * undo default values for results Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com> (cherry picked from commit f89ba2c)
closes nim-lang/RFCs#126
closes nim-lang/RFCs#48
closes nim-lang/RFCs#233
closes nim-lang/RFCs#252
closes #12378
fixes #19763
fixes #16744
fixes #3608
ref nim-lang/RFCs#437
inspired by #12378
default fields for object
the addition compared to #12378
notes for me only
abstractInst vs {tyGenericInst, tyAlias, tySink}