[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/2] pkl: Disallow pinned unions
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH 1/2] pkl: Disallow pinned unions |
Date: |
Tue, 18 Jan 2022 13:36:37 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Hi Mohammad.
> 2022-01-18 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
>
> * libpoke/pkl-typify.c (pkl_typify1_ps_type_struct): Disallow
> pinned unions.
> * doc/poke.texi (Unions): Update.
> * testsuite/poke.pkl/pinned-union-1.pk: New test.
We conventionally use the -diag suffix in the names of tests that check
for compilation errors. So I would name that test
`pinned-union-diag-1.pk' instead.
Other than that, this is OK for master.
Thanks for the patch.
> * testsuite/Makefile.am (EXTRA_DIST): Update.
> ---
> ChangeLog | 8 ++++++++
> doc/poke.texi | 2 ++
> libpoke/pkl-typify.c | 11 +++++++++++
> testsuite/Makefile.am | 1 +
> testsuite/poke.pkl/pinned-union-1.pk | 8 ++++++++
> 5 files changed, 30 insertions(+)
> create mode 100644 testsuite/poke.pkl/pinned-union-1.pk
>
> diff --git a/ChangeLog b/ChangeLog
> index 7b8d8be2..1778c324 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,11 @@
> +2022-01-18 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
> +
> + * libpoke/pkl-typify.c (pkl_typify1_ps_type_struct): Disallow
> + pinned unions.
> + * doc/poke.texi (Unions): Update.
> + * testsuite/poke.pkl/pinned-union-1.pk: New test.
> + * testsuite/Makefile.am (EXTRA_DIST): Update.
> +
> 2022-01-17 Jose E. Marchesi <jemarch@gnu.org>
>
> * poke/pk-scrabble.pk (scrabble): Move variable declaration up to
> diff --git a/doc/poke.texi b/doc/poke.texi
> index ee9bbb57..6e221f03 100644
> --- a/doc/poke.texi
> +++ b/doc/poke.texi
> @@ -11182,6 +11182,8 @@ means. Alternatives are considered in turn, in
> written order, and the
> first alternative that can be used without triggering a constraint
> violation exception is selected.
>
> +Note that, unlike structs, unions cannot be pinned.
> +
> @node Union Constructors
> @subsection Union Constructors
>
> diff --git a/libpoke/pkl-typify.c b/libpoke/pkl-typify.c
> index 1b9fad18..b9609cec 100644
> --- a/libpoke/pkl-typify.c
> +++ b/libpoke/pkl-typify.c
> @@ -1784,6 +1784,8 @@ PKL_PHASE_END_HANDLER
> The total size declared in the integral struct should exactly match
> the size of all the contained fields.
>
> + Pinned unions are not allowed.
> +
> Labels are not allowed in integral structs.
> Optional fields are not allowed in integral structs. */
>
> @@ -1865,6 +1867,15 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_type_struct)
> PKL_PASS_ERROR;
> }
> }
> +
> + if (PKL_AST_TYPE_S_PINNED_P (struct_type)
> + && PKL_AST_TYPE_S_UNION_P (struct_type))
> + {
> + PKL_ERROR (PKL_AST_LOC (struct_type),
> + "unions are not allowed to be pinned");
> + PKL_TYPIFY_PAYLOAD->errors++;
> + PKL_PASS_ERROR;
> + }
> }
> PKL_PHASE_END_HANDLER
>
> diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
> index 4a0b632d..357897ba 100644
> --- a/testsuite/Makefile.am
> +++ b/testsuite/Makefile.am
> @@ -1532,6 +1532,7 @@ EXTRA_DIST = \
> poke.pkl/or-int-struct-2.pk \
> poke.pkl/or-int-struct-3.pk \
> poke.pkl/pinned-int-struct-1.pk \
> + poke.pkl/pinned-union-1.pk \
> poke.pkl/pos-diag-1.pk \
> poke.pkl/pos-integers-1.pk \
> poke.pkl/pos-integers-2.pk \
> diff --git a/testsuite/poke.pkl/pinned-union-1.pk
> b/testsuite/poke.pkl/pinned-union-1.pk
> new file mode 100644
> index 00000000..008f4bf8
> --- /dev/null
> +++ b/testsuite/poke.pkl/pinned-union-1.pk
> @@ -0,0 +1,8 @@
> +/* { dg-do compile } */
> +
> +type Foo =
> + pinned union /* { dg-error "pinned" } */
> + {
> + int<16> hi;
> + uint<16> lo;
> + };