public inbox for gcc-rust@gcc.gnu.org
 help / color / mirror / Atom feed
* union support
@ 2021-07-22 23:19 Mark Wielaard
  2021-07-22 23:19 ` [PATCH 1/2] Better union support in the parser Mark Wielaard
  2021-07-22 23:19 ` [PATCH 2/2] WIP union hir-lowering and type support Mark Wielaard
  0 siblings, 2 replies; 9+ messages in thread
From: Mark Wielaard @ 2021-07-22 23:19 UTC (permalink / raw)
  To: gcc-rust

Hi,

I have been playing with union support which was mostly missing. union
is slightly odd because it is a weak keyword, so it can be used as a
"normal" identifier and is only special when defining a union
type. Which means you can have programs like:

union union { union: u32, funion: f32 }
pub fn main ()
{
  let union = union { union: 1 };
  let _u = unsafe { union.union };
  let _f = unsafe { union.funion; };
}

Here are two patches to support the above (partially).
Also on https://code.wildebeest.org/git/user/mjw/gccrs/log/?h=union

The first fixes up the parser and should be good to go.
[PATCH 1/2] Better union support in the parser

The second provides lowering to HIR and type checking support.  This
is mostly cargo culting existing code for structs and tuple struct. It
seems to work, but I cannot say I fully understand what I am doing.
[PATCH 2/2] WIP union hir-lowering and type support

Currently this will eventually crash when trying to generate code in
Gcc_backend::constructor_expression because we try to emit code for a
struct with multiple fields, but the union doesn't have real fields,
just multiple variants.

Hopefully this is somewhat useful. Feedback on how to proceed and/or
how to get a better design (it seems a good idea to treat a union as
much as possible as a struct/tuple variant, but maybe there is a
better way) is very welcome.

Thanks,

Mark

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-08-04 21:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-22 23:19 union support Mark Wielaard
2021-07-22 23:19 ` [PATCH 1/2] Better union support in the parser Mark Wielaard
2021-07-23 11:19   ` Philip Herron
2021-07-22 23:19 ` [PATCH 2/2] WIP union hir-lowering and type support Mark Wielaard
2021-07-23 11:19   ` Philip Herron
2021-08-01 11:29     ` Mark Wielaard
2021-08-01 22:37       ` Mark Wielaard
2021-08-02 12:33         ` Thomas Schwinge
2021-08-04 21:04       ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).