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

fix #15958 #15970

Merged
merged 9 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ proc ccgIntroducedPtr(conf: ConfigRef; s: PSym, retType: PType): bool =
result = false
# first parameter and return type is 'lent T'? --> use pass by pointer
if s.position == 0 and retType != nil and retType.kind == tyLent:
result = pt.kind != tyVar
result = pt.kind notin {tyVar, tyArray}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But C arrays are pointers already, why would the C code generator introduce another indirection in this case?

Copy link
Member Author

@cooldome cooldome Nov 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix actually removes double pointer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then what about tyOpenArray, tyVarargs (and maybe tySequence)?

Copy link
Member Author

@cooldome cooldome Nov 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right tyOpenArray, tyVarargs also need this fix. Seq is fine.
Added tests to cover tyOpenArray, tyVarargs to PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, big sets are mapped to C arrays... :-)

Copy link
Member Author

@cooldome cooldome Nov 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they are and they need the fix. Added big sets as well :)


proc fillResult(conf: ConfigRef; param: PNode) =
fillLoc(param.sym.loc, locParam, param, ~"Result",
Expand Down
11 changes: 11 additions & 0 deletions tests/lent/tbasic_lent_check.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
discard """
targets: "c cpp"
timotheecour marked this conversation as resolved.
Show resolved Hide resolved
output: "1"
"""

Expand All @@ -14,3 +15,13 @@ proc main =
doAssert(not compiles(passToVar(viewInto(x))))

main()

timotheecour marked this conversation as resolved.
Show resolved Hide resolved

#------------------------------------------------------------------------------
# issue #15958

block:
proc byLent[T](a: T): lent T = a
let a = [11,12]
doAssert byLent(a) == [11,12]
doAssert byLent(a).unsafeAddr == a.unsafeAddr