1 // Test where we change a type definition by adding a field. Fns with
2 // this type in their signature are recompiled, as are their callers.
3 // Fns with that type used only in their body are also recompiled, but
4 // their callers are not.
6 // revisions:cfail1 cfail2
7 // compile-flags: -Z query-dep-graph
10 #![feature(rustc_attrs)]
11 #![feature(stmt_expr_attributes)]
13 #![crate_type = "rlib"]
15 // These are expected to require codegen.
16 #![rustc_partition_codegened(module="struct_point-point", cfg="cfail2")]
17 #![rustc_partition_codegened(module="struct_point-fn_with_type_in_sig", cfg="cfail2")]
18 #![rustc_partition_codegened(module="struct_point-call_fn_with_type_in_sig", cfg="cfail2")]
19 #![rustc_partition_codegened(module="struct_point-fn_with_type_in_body", cfg="cfail2")]
20 #![rustc_partition_codegened(module="struct_point-fn_make_struct", cfg="cfail2")]
21 #![rustc_partition_codegened(module="struct_point-fn_read_field", cfg="cfail2")]
22 #![rustc_partition_codegened(module="struct_point-fn_write_field", cfg="cfail2")]
24 #![rustc_partition_reused(module="struct_point-call_fn_with_type_in_body", cfg="cfail2")]
41 pub fn origin() -> Point {
43 return Point { x: 0.0, y: 0.0 };
46 return Point { x: 0.0, y: 0.0, z: 0.0 };
49 pub fn total(&self) -> f32 {
51 return self.x + self.y;
54 return self.x + self.y + self.z;
57 pub fn x(&self) -> f32 {
63 /// A function that has the changed type in its signature; must currently be
66 /// You could imagine that, in the future, if the change were
67 /// sufficiently "private", we might not need to type-check again.
68 /// Rebuilding is probably always necessary since the layout may be
70 pub mod fn_with_type_in_sig {
73 #[rustc_clean(except="typeck,fn_sig,optimized_mir", cfg="cfail2")]
74 pub fn boop(p: Option<&Point>) -> f32 {
75 p.map(|p| p.total()).unwrap_or(0.0)
79 /// Call a function that has the changed type in its signature; this
80 /// currently must also be rebuilt.
82 /// You could imagine that, in the future, if the change were
83 /// sufficiently "private", we might not need to type-check again.
84 /// Rebuilding is probably always necessary since the layout may be
86 pub mod call_fn_with_type_in_sig {
87 use fn_with_type_in_sig;
89 #[rustc_clean(except="typeck,optimized_mir", cfg="cfail2")]
91 fn_with_type_in_sig::boop(None)
95 /// A function that uses the changed type, but only in its body, not its
98 /// You could imagine that, in the future, if the change were
99 /// sufficiently "private", we might not need to type-check again.
100 /// Rebuilding is probably always necessary since the layout may be
102 pub mod fn_with_type_in_body {
105 #[rustc_clean(except="typeck,optimized_mir", cfg="cfail2")]
106 pub fn boop() -> f32 {
107 Point::origin().total()
111 /// A function `X` that calls a function `Y`, where `Y` uses the changed type in its
112 /// body. In this case, the effects of the change should be contained
113 /// to `Y`; `X` should not have to be rebuilt, nor should it need to be
114 /// type-checked again.
115 pub mod call_fn_with_type_in_body {
116 use fn_with_type_in_body;
118 #[rustc_clean(cfg="cfail2")]
119 pub fn bip() -> f32 {
120 fn_with_type_in_body::boop()
124 /// A function item that makes an instance of `Point` but does not invoke methods.
125 pub mod fn_make_struct {
128 #[rustc_clean(except="typeck,fn_sig,optimized_mir", cfg="cfail2")]
129 pub fn make_origin(p: Point) -> Point {
134 /// A function item that reads fields from `Point` but does not invoke methods.
135 pub mod fn_read_field {
138 #[rustc_clean(except="typeck,fn_sig,optimized_mir", cfg="cfail2")]
139 pub fn get_x(p: Point) -> f32 {
144 /// A function item that writes to a field of `Point` but does not invoke methods.
145 pub mod fn_write_field {
148 #[rustc_clean(except="typeck,fn_sig,optimized_mir", cfg="cfail2")]
149 pub fn inc_x(p: &mut Point) {