diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-05-23 14:57:55 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-23 14:57:55 +0000 |
commit | bf6d540b1043bb944450dfe9da4c91124cdf31d3 (patch) | |
tree | 6edb9359d5ac9d9b63938019e0fd9b336c1dd43e /gcc/rust/backend/rust-compile-context.h | |
parent | 63762cc243c643c10aca7e07dfd6abe9b78748f8 (diff) | |
parent | cd39861da5e1113207193bb8b3e6fb3dde92895f (diff) | |
download | gcc-bf6d540b1043bb944450dfe9da4c91124cdf31d3.zip gcc-bf6d540b1043bb944450dfe9da4c91124cdf31d3.tar.gz gcc-bf6d540b1043bb944450dfe9da4c91124cdf31d3.tar.bz2 |
Merge #1268
1268: Fix Slice Type Layout r=philberty a=philberty
Slices in Rust are represented by TypePaths such as '[i32]'. Though if you
actually try to use this explicit type-path you will hit errors such as
this type has an unknown size at compile time. This is because this is
actually what Rust calls a dynamically sized type. This means when you use
types such as: '&[i32]' it is not actually a reference type to a slice. Its
a slice in its entirety this means for lack of a better word when you use
'*const [i32]' or '&mut [i32]' we end up actually passing around a struct
by value _not_ at pointer/reference to it.
This patch changes the type-layout so that we handle this layout change
properly. This patch will also need to be applied to str types which I
believe have a similar layout for safety.
The patch also sets up TYPE_MAIN_VARIANT so that we can avoid unnessecary
view_convert_expressions between *const [i32] and &mut [i32] which will
have the same layout.
Reference:
https://doc.rust-lang.org/reference/dynamically-sized-types.html
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=672adac002939a2dab43b8d231adc1dc
Fixes #1232
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-context.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-context.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 8378554..096b65f 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -67,6 +67,17 @@ public: return type; } + tree insert_main_variant (tree type) + { + hashval_t h = type_hasher (type); + auto it = main_variants.find (h); + if (it != main_variants.end ()) + return it->second; + + main_variants.insert ({h, type}); + return type; + } + ::Backend *get_backend () { return backend; } Resolver::Resolver *get_resolver () { return resolver; } Resolver::TypeCheckContext *get_tyctx () { return tyctx; } @@ -314,6 +325,7 @@ private: std::map<DefId, std::vector<std::pair<const TyTy::BaseType *, tree>>> mono_fns; std::map<HirId, tree> implicit_pattern_bindings; + std::map<hashval_t, tree> main_variants; // To GCC middle-end std::vector<tree> type_decls; |