Skip to content

Ref scoping#5240

Merged
TIHan merged 28 commits intodotnet:masterfrom
TIHan:ref-scopes2
Jul 2, 2018
Merged

Ref scoping#5240
TIHan merged 28 commits intodotnet:masterfrom
TIHan:ref-scopes2

Conversation

@TIHan
Copy link
Copy Markdown
Contributor

@TIHan TIHan commented Jun 27, 2018

This adds byref scoping.

Before, you could compile code like this:

let test () =
  let x =
    let mutable y = 1
    &y
  ()

As you can see, we can return the address of y from the expression, out of the scope of where it was defined. Technically, this is valid and will run. However, we suspect that no one is doing this as doing such a thing has the potential to cause bugs, as shown here: #5235

This change will restrict returning the address of values from where it was defined in an expression, effectively its visibility.

@cartermp
Copy link
Copy Markdown
Contributor

@TIHan can you track the scoping rules in the RFC as well? We want the RFC to be the canonical source for these sorts of things.

@TIHan
Copy link
Copy Markdown
Contributor Author

TIHan commented Jun 27, 2018

@cartermp, I will update the rules to the RFC. Spoke with @dsyme and we agreed on rules. Just need to make sure everything is passing.

Copy link
Copy Markdown
Contributor

@KevinRansom KevinRansom left a comment

Choose a reason for hiding this comment

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

Nice

@TIHan
Copy link
Copy Markdown
Contributor Author

TIHan commented Jun 28, 2018

test Windows_NT Release_ci_part4 Build please

@TIHan
Copy link
Copy Markdown
Contributor Author

TIHan commented Jun 29, 2018

I found a bug last night and will need to fix it today.

@TIHan
Copy link
Copy Markdown
Contributor Author

TIHan commented Jul 1, 2018

I believe this is now fully ready.

One thing to note, I disallowed "implicit address of" for member methods with inref<'T> params because it doesn't make sense for scopes; I think it's ok that we do this. For one it makes it consistent with let-bound functions, and two we don't think about scoping for them.

@TIHan TIHan requested a review from dsyme July 2, 2018 05:55
@TIHan TIHan merged commit 32a93aa into dotnet:master Jul 2, 2018
TIHan added a commit to TIHan/visualfsharp that referenced this pull request Jul 2, 2018
* Added Limit

* Trying to get basic scopes

* Basic scope checks

* Some more checks

* Handling another ref scope case

* Using env instead of cenv

* Partially scoped

* Almost figuring out scoping

* Scopes are working

* Check returnable

* Current tests passing

* Removed compiler generated rhs

* Minor cleanup

* Added scoping tests

* Adding tests again

* Scoping now determines what is local

* Updated tests/baseline for byrefs. Simplified compiler generated check

* Trivial change for scope check

* Fixed bug with stack referring span-likes returning by-refs in scopes other than the method/function level

* Quick fix

* Preventing taking address of expression that isn't a let-bound value

* Updated baseline

* Updated baseline

* Added better way to disable address of

* Finishing up. Updating baselines

* Updating neg106 baseline

* Updated baselines again

* Removing compiler generated check by fixing GetLimitVal
TIHan added a commit that referenced this pull request Jul 2, 2018
* Enable negative byref tests (#5237)

* Checking negative tests for byrefs

* Added byref test baseline

* Ref scoping (#5240)

* Added Limit

* Trying to get basic scopes

* Basic scope checks

* Some more checks

* Handling another ref scope case

* Using env instead of cenv

* Partially scoped

* Almost figuring out scoping

* Scopes are working

* Check returnable

* Current tests passing

* Removed compiler generated rhs

* Minor cleanup

* Added scoping tests

* Adding tests again

* Scoping now determines what is local

* Updated tests/baseline for byrefs. Simplified compiler generated check

* Trivial change for scope check

* Fixed bug with stack referring span-likes returning by-refs in scopes other than the method/function level

* Quick fix

* Preventing taking address of expression that isn't a let-bound value

* Updated baseline

* Updated baseline

* Added better way to disable address of

* Finishing up. Updating baselines

* Updating neg106 baseline

* Updated baselines again

* Removing compiler generated check by fixing GetLimitVal
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