Skip to content

borrow checking #15282

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

Merged
merged 17 commits into from
Sep 9, 2020
Merged

borrow checking #15282

merged 17 commits into from
Sep 9, 2020

Conversation

Araq
Copy link
Member

@Araq Araq commented Sep 7, 2020

Todo:

  • wiring of Nim's borrow checker to types containing a view-type.
  • backend extensions in order to map openArray to structs.
  • documentation and tests.

Copy link
Collaborator

@mratsim mratsim left a comment

Choose a reason for hiding this comment

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

I can't comment on the implementation but we'll likely want to have an easy to approach API and story.

I should probably write a RFC on that.

echo a.len

proc main(s: seq[int]) =
var x: openArray[int] = s # 'x' is a view into 's'
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a var x = s.view() or var x = s.borrow() would be nicer but I guess we can discuss API once the low-level primitive work.

echo x[i]
take(x)

take(x.toOpenArray(0, 1)) # slicing remains possible
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly [] on sequences should now return openArray by default unless this is assigned to a returned value that escapes and maybe we need a StringView type?

@Araq
Copy link
Member Author

Araq commented Sep 8, 2020

Well I won't rename or introduce new APIs, I'm following nim-lang/RFCs#178

If you want new names or APIs please write an RFC and see how the community reacts. ;-)

@RSDuck
Copy link
Contributor

RSDuck commented Sep 8, 2020

this is so cool and pretty much the only thing I felt was missing from Nim!

While this is going to be experimental at first, I think it deprecates multiple things which were more or less workarounds using pointers:

@Araq
Copy link
Member Author

Araq commented Sep 8, 2020

While this is going to be experimental at first, I think it deprecates multiple things which were more or less workarounds using pointers

Agreed. Also the special casing for evalOnce (you cannot store an openArray in a variable) should be removable with this.

@Araq
Copy link
Member Author

Araq commented Sep 9, 2020

Merging this as the dangers of merge conflicts become serious. But it's hardly usable in this state and will see follow-up PRs.

@Araq Araq merged commit 10988d4 into devel Sep 9, 2020
@Araq Araq deleted the araq-borrow-checking branch September 9, 2020 05:32
mildred pushed a commit to mildred/Nim that referenced this pull request Jan 11, 2021
* refactoring: move procs to typeallowed.nim
* frontend preparations for first class openArray support
* prepare the code generator for first class openArray
* code generation for first class openArray; WIP
* code generation for open arrays, progress
* added isViewType proc
* preparations for borrow checking
* added borrow checking to the front end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants