-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[MIR] Initial implementation for translating calls. #30364
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_mir] | ||
fn test1(a: isize, b: (i32, i32), c: &[i32]) -> (isize, (i32, i32), &[i32]) { | ||
// Test passing a number of arguments including a fat pointer. | ||
// Also returning via an out pointer | ||
fn callee(a: isize, b: (i32, i32), c: &[i32]) -> (isize, (i32, i32), &[i32]) { | ||
(a, b, c) | ||
} | ||
callee(a, b, c) | ||
} | ||
|
||
#[rustc_mir] | ||
fn test2(a: isize) -> isize { | ||
// Test passing a single argument. | ||
// Not using out pointer. | ||
fn callee(a: isize) -> isize { | ||
a | ||
} | ||
callee(a) | ||
} | ||
|
||
struct Foo; | ||
impl Foo { | ||
fn inherent_method(&self, a: isize) -> isize { a } | ||
} | ||
|
||
#[rustc_mir] | ||
fn test3(x: &Foo, a: isize) -> isize { | ||
// Test calling inherent method | ||
x.inherent_method(a) | ||
} | ||
|
||
trait Bar { | ||
fn extension_method(&self, a: isize) -> isize { a } | ||
} | ||
impl Bar for Foo {} | ||
|
||
#[rustc_mir] | ||
fn test4(x: &Foo, a: isize) -> isize { | ||
// Test calling extension method | ||
x.extension_method(a) | ||
} | ||
|
||
#[rustc_mir] | ||
fn test5(x: &Bar, a: isize) -> isize { | ||
// Test calling method on trait object | ||
x.extension_method(a) | ||
} | ||
|
||
#[rustc_mir] | ||
fn test6<T: Bar>(x: &T, a: isize) -> isize { | ||
// Test calling extension method on generic callee | ||
x.extension_method(a) | ||
} | ||
|
||
trait One<T = Self> { | ||
fn one() -> T; | ||
} | ||
impl One for isize { | ||
fn one() -> isize { 1 } | ||
} | ||
|
||
#[rustc_mir] | ||
fn test7() -> isize { | ||
// Test calling trait static method | ||
<isize as One>::one() | ||
} | ||
|
||
struct Two; | ||
impl Two { | ||
fn two() -> isize { 2 } | ||
} | ||
|
||
#[rustc_mir] | ||
fn test8() -> isize { | ||
// Test calling impl static method | ||
Two::two() | ||
} | ||
|
||
fn main() { | ||
assert_eq!(test1(1, (2, 3), &[4, 5, 6]), (1, (2, 3), &[4, 5, 6][..])); | ||
assert_eq!(test2(98), 98); | ||
assert_eq!(test3(&Foo, 42), 42); | ||
assert_eq!(test4(&Foo, 970), 970); | ||
assert_eq!(test5(&Foo, 8576), 8576); | ||
assert_eq!(test6(&Foo, 12367), 12367); | ||
assert_eq!(test7(), 1); | ||
assert_eq!(test8(), 2); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add some tests using trait dispatch? (or does that not work yet)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some more tests for calling methods in different ways. #29907 + this pull also allow calling trait static methods which i've also included a test for.