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

add back noalias to &mut T pointer parameters #13935

Merged
merged 1 commit into from
May 5, 2014
Merged

add back noalias to &mut T pointer parameters #13935

merged 1 commit into from
May 5, 2014

Conversation

thestinger
Copy link
Contributor

This was removed because these could alias with &const T or @mut T
and those are now gone from the language. There are still aliasing
issues within local scopes, but this is correct for function parameters.

This also removes the no-op noalias marker on proc (not a pointer) and
leaves out the mention of #6750 because real type-based alias analysis
is not within the scope of best effort usage of the noalias attribute.

Test case:

pub fn foo(x: &mut &mut u32) {
    **x = 5;
    **x = 5;
}

Before:

define void @_ZN3foo20h0ce94c9671b0150bdaa4v0.0E(i32** nocapture readonly) unnamed_addr #0 {
entry-block:
  %1 = load i32** %0, align 8
  store i32 5, i32* %1, align 4
  %2 = load i32** %0, align 8
  store i32 5, i32* %2, align 4
  ret void
}

After:

define void @_ZN3foo20h0ce94c9671b0150bdaa4v0.0E(i32** noalias nocapture readonly) unnamed_addr #0 {
entry-block:
  %1 = load i32** %0, align 8
  store i32 5, i32* %1, align 4
  ret void
}

Closes #12436

This was removed because these could alias with `&const T` or `@mut T`
and those are now gone from the language. There are still aliasing
issues within local scopes, but this is correct for function parameters.

This also removes the no-op `noalias` marker on proc (not a pointer) and
leaves out the mention of #6750 because real type-based alias analysis
is not within the scope of best effort usage of the `noalias` attribute.

Test case:

    pub fn foo(x: &mut &mut u32) {
        **x = 5;
        **x = 5;
    }

Before:

    define void @_ZN3foo20h0ce94c9671b0150bdaa4v0.0E(i32** nocapture readonly) unnamed_addr #0 {
    entry-block:
      %1 = load i32** %0, align 8
      store i32 5, i32* %1, align 4
      %2 = load i32** %0, align 8
      store i32 5, i32* %2, align 4
      ret void
    }

After:

    define void @_ZN3foo20h0ce94c9671b0150bdaa4v0.0E(i32** noalias nocapture readonly) unnamed_addr #0 {
    entry-block:
      %1 = load i32** %0, align 8
      store i32 5, i32* %1, align 4
      ret void
    }

Closes #12436
@alexcrichton
Copy link
Member

Can't &mut T still alias *U and *mut U? Does a check need to be done of the other argument types to make sure none of them are pointers as well?

@thestinger
Copy link
Contributor Author

It can't alias in safe code or valid unsafe code. The noalias attribute guarantees that the parameter can not be used to observe writes through other pointers not based (created from) on it and it can't cause writes observable through other pointers. It's about memory dependencies rather than pointer equality.

@thestinger
Copy link
Contributor Author

cc @nikomatsakis

bors added a commit that referenced this pull request May 5, 2014
This was removed because these could alias with `&const T` or `@mut T`
and those are now gone from the language. There are still aliasing
issues within local scopes, but this is correct for function parameters.

This also removes the no-op `noalias` marker on proc (not a pointer) and
leaves out the mention of #6750 because real type-based alias analysis
is not within the scope of best effort usage of the `noalias` attribute.

Test case:

    pub fn foo(x: &mut &mut u32) {
        **x = 5;
        **x = 5;
    }

Before:

    define void @_ZN3foo20h0ce94c9671b0150bdaa4v0.0E(i32** nocapture readonly) unnamed_addr #0 {
    entry-block:
      %1 = load i32** %0, align 8
      store i32 5, i32* %1, align 4
      %2 = load i32** %0, align 8
      store i32 5, i32* %2, align 4
      ret void
    }

After:

    define void @_ZN3foo20h0ce94c9671b0150bdaa4v0.0E(i32** noalias nocapture readonly) unnamed_addr #0 {
    entry-block:
      %1 = load i32** %0, align 8
      store i32 5, i32* %1, align 4
      ret void
    }

Closes #12436
@bors bors closed this May 5, 2014
@bors bors merged commit f62c753 into rust-lang:master May 5, 2014
@thestinger thestinger deleted the noalias branch May 5, 2014 17:15
@nikomatsakis
Copy link
Contributor

I am not sure if I agree (nor sure if I disagree...) regarding potential aliasing of &mut T and *mut T. That is, I don't think we've strictly defined this.

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2023
…=Veykril

Assist: desugar doc-comment

My need for this arose due to wanting to do feature dependent documentation and therefor convert parts of my doc-comments to attributes.

Not sure about the pub-making of the other handlers functions, but I didn't think it made much sense to reimplement them.
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.

add back noalias to &mut parameters
4 participants