Skip to content

Commit 9c95819

Browse files
committed
Fix polymorphization for coroutines
Fixes rust-lang/rustc_codegen_cranelift#1429
1 parent 430ab4e commit 9c95819

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

build_system/tests.rs

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
9999
TestCase::build_bin_and_run("aot.mod_bench", "example/mod_bench.rs", &[]),
100100
TestCase::build_bin_and_run("aot.issue-72793", "example/issue-72793.rs", &[]),
101101
TestCase::build_bin("aot.issue-59326", "example/issue-59326.rs"),
102+
TestCase::custom("aot.polymorphize_coroutine", &|runner| {
103+
runner.run_rustc(&["example/polymorphize_coroutine.rs", "-Zpolymorphize"]);
104+
runner.run_out_command("polymorphize_coroutine", &[]);
105+
}),
102106
TestCase::build_bin_and_run("aot.neon", "example/neon.rs", &[]),
103107
];
104108

config.txt

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ aot.float-minmax-pass
4242
aot.mod_bench
4343
aot.issue-72793
4444
aot.issue-59326
45+
aot.polymorphize_coroutine
4546
aot.neon
4647

4748
testsuite.extended_sysroot

example/polymorphize_coroutine.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(coroutines, coroutine_trait)]
2+
3+
use std::ops::Coroutine;
4+
use std::pin::Pin;
5+
6+
fn main() {
7+
run_coroutine::<i32>();
8+
}
9+
10+
fn run_coroutine<T>() {
11+
let mut coroutine = || {
12+
yield;
13+
return;
14+
};
15+
Pin::new(&mut coroutine).resume(());
16+
}

src/value_and_place.rs

+26
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,32 @@ pub(crate) fn assert_assignable<'tcx>(
977977
}
978978
}
979979
}
980+
(&ty::Coroutine(def_id_a, args_a, mov_a), &ty::Coroutine(def_id_b, args_b, mov_b))
981+
if def_id_a == def_id_b && mov_a == mov_b =>
982+
{
983+
let mut types_a = args_a.types();
984+
let mut types_b = args_b.types();
985+
loop {
986+
match (types_a.next(), types_b.next()) {
987+
(Some(a), Some(b)) => assert_assignable(fx, a, b, limit - 1),
988+
(None, None) => return,
989+
(Some(_), None) | (None, Some(_)) => panic!("{:#?}/{:#?}", from_ty, to_ty),
990+
}
991+
}
992+
}
993+
(&ty::CoroutineWitness(def_id_a, args_a), &ty::CoroutineWitness(def_id_b, args_b))
994+
if def_id_a == def_id_b =>
995+
{
996+
let mut types_a = args_a.types();
997+
let mut types_b = args_b.types();
998+
loop {
999+
match (types_a.next(), types_b.next()) {
1000+
(Some(a), Some(b)) => assert_assignable(fx, a, b, limit - 1),
1001+
(None, None) => return,
1002+
(Some(_), None) | (None, Some(_)) => panic!("{:#?}/{:#?}", from_ty, to_ty),
1003+
}
1004+
}
1005+
}
9801006
(ty::Param(_), _) | (_, ty::Param(_)) if fx.tcx.sess.opts.unstable_opts.polymorphize => {
9811007
// No way to check if it is correct or not with polymorphization enabled
9821008
}

0 commit comments

Comments
 (0)