Skip to content

Commit e5ed0a5

Browse files
authored
Auto merge of #37842 - nikomatsakis:incremental-test, r=mw
Add tests for incremental reuse scenarios These are microbenchmarks checking that we achieve the expected reuse in the scenarios covered by incremental beta. r? @michaelwoerister
2 parents 7c535c6 + 36f2af1 commit e5ed0a5

File tree

3 files changed

+382
-0
lines changed

3 files changed

+382
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test where we change a type definition by adding a field. Fns with
12+
// this type in their signature are recompiled, as are their callers.
13+
// Fns with that type used only in their body are also recompiled, but
14+
// their callers are not.
15+
16+
// revisions:rpass1 rpass2
17+
// compile-flags: -Z query-dep-graph
18+
19+
#![feature(rustc_attrs)]
20+
#![feature(stmt_expr_attributes)]
21+
#![feature(static_in_const)]
22+
#![allow(dead_code)]
23+
24+
// These are expected to require translation.
25+
#![rustc_partition_translated(module="struct_point-point", cfg="rpass2")]
26+
#![rustc_partition_translated(module="struct_point-fn_with_type_in_sig", cfg="rpass2")]
27+
#![rustc_partition_translated(module="struct_point-call_fn_with_type_in_sig", cfg="rpass2")]
28+
#![rustc_partition_translated(module="struct_point-fn_with_type_in_body", cfg="rpass2")]
29+
#![rustc_partition_translated(module="struct_point-fn_make_struct", cfg="rpass2")]
30+
#![rustc_partition_translated(module="struct_point-fn_read_field", cfg="rpass2")]
31+
#![rustc_partition_translated(module="struct_point-fn_write_field", cfg="rpass2")]
32+
33+
#![rustc_partition_reused(module="struct_point-call_fn_with_type_in_body", cfg="rpass2")]
34+
35+
mod point {
36+
#[cfg(rpass1)]
37+
pub struct Point {
38+
pub x: f32,
39+
pub y: f32,
40+
}
41+
42+
#[cfg(rpass2)]
43+
pub struct Point {
44+
pub x: f32,
45+
pub y: f32,
46+
pub z: f32,
47+
}
48+
49+
impl Point {
50+
pub fn origin() -> Point {
51+
#[cfg(rpass1)]
52+
return Point { x: 0.0, y: 0.0 };
53+
54+
#[cfg(rpass2)]
55+
return Point { x: 0.0, y: 0.0, z: 0.0 };
56+
}
57+
58+
pub fn total(&self) -> f32 {
59+
#[cfg(rpass1)]
60+
return self.x + self.y;
61+
62+
#[cfg(rpass2)]
63+
return self.x + self.y + self.z;
64+
}
65+
66+
pub fn x(&self) -> f32 {
67+
self.x
68+
}
69+
}
70+
}
71+
72+
/// A fn that has the changed type in its signature; must currently be
73+
/// rebuilt.
74+
///
75+
/// You could imagine that, in the future, if the change were
76+
/// sufficiently "private", we might not need to type-check again.
77+
/// Rebuilding is probably always necessary since the layout may be
78+
/// affected.
79+
mod fn_with_type_in_sig {
80+
use point::Point;
81+
82+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
83+
pub fn boop(p: Option<&Point>) -> f32 {
84+
p.map(|p| p.total()).unwrap_or(0.0)
85+
}
86+
}
87+
88+
/// Call a fn that has the changed type in its signature; this
89+
/// currently must also be rebuilt.
90+
///
91+
/// You could imagine that, in the future, if the change were
92+
/// sufficiently "private", we might not need to type-check again.
93+
/// Rebuilding is probably always necessary since the layout may be
94+
/// affected.
95+
mod call_fn_with_type_in_sig {
96+
use fn_with_type_in_sig;
97+
98+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
99+
pub fn bip() -> f32 {
100+
fn_with_type_in_sig::boop(None)
101+
}
102+
}
103+
104+
/// A fn that uses the changed type, but only in its body, not its
105+
/// signature.
106+
///
107+
/// You could imagine that, in the future, if the change were
108+
/// sufficiently "private", we might not need to type-check again.
109+
/// Rebuilding is probably always necessary since the layout may be
110+
/// affected.
111+
mod fn_with_type_in_body {
112+
use point::Point;
113+
114+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
115+
pub fn boop() -> f32 {
116+
Point::origin().total()
117+
}
118+
}
119+
120+
/// A fn X that calls a fn Y, where Y uses the changed type in its
121+
/// body. In this case, the effects of the change should be contained
122+
/// to Y; X should not have to be rebuilt, nor should it need to be
123+
/// typechecked again.
124+
mod call_fn_with_type_in_body {
125+
use fn_with_type_in_body;
126+
127+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
128+
pub fn bip() -> f32 {
129+
fn_with_type_in_body::boop()
130+
}
131+
}
132+
133+
/// A fn item that makes an instance of `Point` but does not invoke methods
134+
mod fn_make_struct {
135+
use point::Point;
136+
137+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
138+
pub fn make_origin(p: Point) -> Point {
139+
Point { ..p }
140+
}
141+
}
142+
143+
/// A fn item that reads fields from `Point` but does not invoke methods
144+
mod fn_read_field {
145+
use point::Point;
146+
147+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
148+
pub fn get_x(p: Point) -> f32 {
149+
p.x
150+
}
151+
}
152+
153+
/// A fn item that writes to a field of `Point` but does not invoke methods
154+
mod fn_write_field {
155+
use point::Point;
156+
157+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
158+
pub fn inc_x(p: &mut Point) {
159+
p.x += 1.0;
160+
}
161+
}
162+
163+
fn main() {
164+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test where we change the body of a public, inherent method.
12+
13+
// revisions:rpass1 rpass2
14+
// compile-flags: -Z query-dep-graph
15+
16+
#![feature(rustc_attrs)]
17+
#![feature(stmt_expr_attributes)]
18+
#![allow(dead_code)]
19+
20+
#![rustc_partition_translated(module="struct_point-point", cfg="rpass2")]
21+
22+
// FIXME(#35078) -- this gets recompiled because we don't separate sig from body
23+
#![rustc_partition_translated(module="struct_point-fn_calls_changed_method", cfg="rpass2")]
24+
25+
#![rustc_partition_reused(module="struct_point-fn_calls_another_method", cfg="rpass2")]
26+
#![rustc_partition_reused(module="struct_point-fn_make_struct", cfg="rpass2")]
27+
#![rustc_partition_reused(module="struct_point-fn_read_field", cfg="rpass2")]
28+
#![rustc_partition_reused(module="struct_point-fn_write_field", cfg="rpass2")]
29+
30+
mod point {
31+
pub struct Point {
32+
pub x: f32,
33+
pub y: f32,
34+
}
35+
36+
impl Point {
37+
pub fn distance_from_origin(&self) -> f32 {
38+
#[cfg(rpass1)]
39+
return self.x * self.x + self.y * self.y;
40+
41+
#[cfg(rpass2)]
42+
return (self.x * self.x + self.y * self.y).sqrt();
43+
}
44+
45+
pub fn x(&self) -> f32 {
46+
self.x
47+
}
48+
}
49+
}
50+
51+
/// A fn item that calls the method on `Point` which changed
52+
mod fn_calls_changed_method {
53+
use point::Point;
54+
55+
// FIXME(#35078) -- this gets recompiled because we don't separate sig from body
56+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
57+
pub fn check() {
58+
let p = Point { x: 2.0, y: 2.0 };
59+
p.distance_from_origin();
60+
}
61+
}
62+
63+
/// A fn item that calls a method on `Point` which did not change
64+
mod fn_calls_another_method {
65+
use point::Point;
66+
67+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
68+
pub fn check() {
69+
let p = Point { x: 2.0, y: 2.0 };
70+
p.x();
71+
}
72+
}
73+
74+
/// A fn item that makes an instance of `Point` but does not invoke methods
75+
mod fn_make_struct {
76+
use point::Point;
77+
78+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
79+
pub fn make_origin() -> Point {
80+
Point { x: 2.0, y: 2.0 }
81+
}
82+
}
83+
84+
/// A fn item that reads fields from `Point` but does not invoke methods
85+
mod fn_read_field {
86+
use point::Point;
87+
88+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
89+
pub fn get_x(p: Point) -> f32 {
90+
p.x
91+
}
92+
}
93+
94+
/// A fn item that writes to a field of `Point` but does not invoke methods
95+
mod fn_write_field {
96+
use point::Point;
97+
98+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
99+
pub fn inc_x(p: &mut Point) {
100+
p.x += 1.0;
101+
}
102+
}
103+
104+
fn main() {
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test where we change the *signature* of a public, inherent method.
12+
13+
// revisions:rpass1 rpass2
14+
// compile-flags: -Z query-dep-graph
15+
16+
#![feature(rustc_attrs)]
17+
#![feature(stmt_expr_attributes)]
18+
#![feature(static_in_const)]
19+
#![allow(dead_code)]
20+
21+
// These are expected to require translation.
22+
#![rustc_partition_translated(module="struct_point-point", cfg="rpass2")]
23+
#![rustc_partition_translated(module="struct_point-fn_calls_changed_method", cfg="rpass2")]
24+
25+
#![rustc_partition_reused(module="struct_point-fn_calls_another_method", cfg="rpass2")]
26+
#![rustc_partition_reused(module="struct_point-fn_make_struct", cfg="rpass2")]
27+
#![rustc_partition_reused(module="struct_point-fn_read_field", cfg="rpass2")]
28+
#![rustc_partition_reused(module="struct_point-fn_write_field", cfg="rpass2")]
29+
30+
mod point {
31+
pub struct Point {
32+
pub x: f32,
33+
pub y: f32,
34+
}
35+
36+
impl Point {
37+
#[cfg(rpass1)]
38+
pub fn distance_from_point(&self, p: Option<Point>) -> f32 {
39+
let p = p.unwrap_or(Point { x: 0.0, y: 0.0 });
40+
let x_diff = self.x - p.x;
41+
let y_diff = self.y - p.y;
42+
return x_diff * x_diff + y_diff * y_diff;
43+
}
44+
45+
#[cfg(rpass2)]
46+
pub fn distance_from_point(&self, p: Option<&Point>) -> f32 {
47+
const ORIGIN: &Point = &Point { x: 0.0, y: 0.0 };
48+
let p = p.unwrap_or(ORIGIN);
49+
let x_diff = self.x - p.x;
50+
let y_diff = self.y - p.y;
51+
return x_diff * x_diff + y_diff * y_diff;
52+
}
53+
54+
pub fn x(&self) -> f32 {
55+
self.x
56+
}
57+
}
58+
}
59+
60+
/// A fn item that calls the method that was changed
61+
mod fn_calls_changed_method {
62+
use point::Point;
63+
64+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
65+
pub fn check() {
66+
let p = Point { x: 2.0, y: 2.0 };
67+
p.distance_from_point(None);
68+
}
69+
}
70+
71+
/// A fn item that calls a method that was not changed
72+
mod fn_calls_another_method {
73+
use point::Point;
74+
75+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
76+
pub fn check() {
77+
let p = Point { x: 2.0, y: 2.0 };
78+
p.x();
79+
}
80+
}
81+
82+
/// A fn item that makes an instance of `Point` but does not invoke methods
83+
mod fn_make_struct {
84+
use point::Point;
85+
86+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
87+
pub fn make_origin() -> Point {
88+
Point { x: 2.0, y: 2.0 }
89+
}
90+
}
91+
92+
/// A fn item that reads fields from `Point` but does not invoke methods
93+
mod fn_read_field {
94+
use point::Point;
95+
96+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
97+
pub fn get_x(p: Point) -> f32 {
98+
p.x
99+
}
100+
}
101+
102+
/// A fn item that writes to a field of `Point` but does not invoke methods
103+
mod fn_write_field {
104+
use point::Point;
105+
106+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
107+
pub fn inc_x(p: &mut Point) {
108+
p.x += 1.0;
109+
}
110+
}
111+
112+
fn main() {
113+
}

0 commit comments

Comments
 (0)