Skip to content

Commit 0b16260

Browse files
fw-immunantkkysen
authored andcommitted
transpile: use built-in SIMD items from stdlib, not via reexports
these will have `use`s added unconditionally with the stdlib path if the main module uses them directly, so in order to allow deduplication without tracing through reexports, we should have the main module import these from their original (stdlib) location, not the reexported one
1 parent 3756bc6 commit 0b16260

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

c2rust-transpile/src/translator/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,8 +1084,25 @@ fn make_submodule(
10841084
match use_idents(tree) {
10851085
IdentsOrGlob::Idents(idents) => {
10861086
for ident in idents {
1087-
// Add a `use` for `self::this_module::exported_name`.
1088-
use_item_store.add_use(false, use_path(), &ident.to_string());
1087+
fn is_simd_type_name(name: &str) -> bool {
1088+
const SIMD_TYPE_NAMES: &[&str] = &[
1089+
"__m128i", "__m128", "__m128d", "__m64", "__m256", "__m256d",
1090+
"__m256i",
1091+
];
1092+
SIMD_TYPE_NAMES.contains(&name) || name.starts_with("_mm_")
1093+
}
1094+
let name = &*ident.to_string();
1095+
if is_simd_type_name(name) {
1096+
// Import vector type/operation names from the stdlib, as we also generate
1097+
// other uses for them from that location and can't easily reason about
1098+
// the ultimate target of reexported names when avoiding duplicate imports
1099+
// (which are verboten).
1100+
simd::add_arch_use(use_item_store, "x86", name);
1101+
simd::add_arch_use(use_item_store, "x86_64", name);
1102+
} else {
1103+
// Add a `use` for `self::this_module::exported_name`.
1104+
use_item_store.add_use(false, use_path(), name);
1105+
}
10891106
}
10901107
}
10911108
IdentsOrGlob::Glob => {}

c2rust-transpile/src/translator/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static SIMD_X86_64_ONLY: &[&str] = &[
6767
"_mm_crc32_u64",
6868
];
6969

70-
fn add_arch_use(store: &mut ItemStore, arch_name: &str, item_name: &str) {
70+
pub fn add_arch_use(store: &mut ItemStore, arch_name: &str, item_name: &str) {
7171
store.add_use_with_attr(
7272
true,
7373
vec!["core".into(), "arch".into(), arch_name.into()],

0 commit comments

Comments
 (0)