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

[WIP] Look for string.GetPinnableReference when pinning a string first #9252

Closed
wants to merge 2 commits into from

Conversation

cartermp
Copy link
Contributor

@cartermp cartermp commented May 20, 2020

This tries to address #9251

I couldn't actually run these tests on my machine with VS for some weird reason, so I'll let CI tell me what I did wrong instead

@cartermp cartermp marked this pull request as ready for review May 21, 2020 17:43
@cartermp cartermp requested a review from TIHan May 21, 2020 17:43
@cartermp cartermp requested a review from KevinRansom May 21, 2020 17:45
KevinRansom
KevinRansom previously approved these changes May 21, 2020
@GrabYourPitchforks
Copy link
Member

Thanks kindly for getting to this so quickly! :)

//
// let ptr: nativeptr<char> =
// let pinned s = str
// (nativeptr)s + GetPinnableReference()
Copy link
Member

@GrabYourPitchforks GrabYourPitchforks May 22, 2020

Choose a reason for hiding this comment

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

Just to clarify, the compiler shouldn't perform any arithmetic here. The result of GetPinnableReference is a readonly char&, and that char& should be pinned. The string instance itself should not be pinned.

If you take a look at the "expected IL" example in #9251, the result of GetPinnableReference is immediately assigned to the pinned char& local. There's no add instruction in the expected IL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm. @dsyme wrote this originally, I assume he had a good reason for doing this, but yes it shouldn't need to do that.

Copy link
Member

Choose a reason for hiding this comment

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

Clarification to my comments: the GetOffsetToStringData pattern works by having the caller pin the string instance, then compute addrof(string) + GetOffsetToStringData, then expose the resulting sum as a char*. So the addition is expected there.

The GetPinnableReference pattern works by providing the char& directly, which the caller then pins.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, I'll take another look at this

@KevinRansom KevinRansom dismissed their stale review May 22, 2020 17:23

reasons

ptr
"""
let il = """
char& modreq([System.Runtime]System.Runtime.InteropServices.InAttribute) [System.Runtime]System.String::GetPinnableReference()
Copy link
Contributor

Choose a reason for hiding this comment

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

We should check to make sure the local char is pinned as well from locals init.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, thinking about it more this is a bad test. I'll revisit this one

@cartermp cartermp changed the title Look for string.GetPinnableReference when pinning a string first [WIP] Look for string.GetPinnableReference when pinning a string first Jun 27, 2020
@cartermp
Copy link
Contributor Author

The fix here isn't right and will require a bit more work in the typechecker to do the right thing. I'm going to close this one out, at least until some of the test refactoring is completed, so that I don't have to baby the PR along without a proper fix.

@cartermp cartermp closed this Jun 27, 2020
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.

4 participants