[m-rev.] for (possibly post-commit) review: simplify the creation of .int files

Julien Fischer jfischer at opturion.com
Mon Feb 18 21:31:26 AEDT 2019


On Mon, 18 Feb 2019, Zoltan Somogyi wrote:

> On Mon, 18 Feb 2019 18:23:04 +1100, Peter Wang <novalazy at gmail.com> wrote:
>> What will happen if the programmer forgets to add the attribute on a
>> foreign type that is larger than one word? Because programmers WILL
>> forget, precisely because such types are rare.
>
> That is a valid point. Maybe we want the opposite assertion:
> something that says "definitely not bigger than a word".
> That way, if you forget the assertion when it would be valid,
> you lose some performance, but preserve correctness.

Which is the situation we already have with the
"can_pass_as_mercury_type" attribute.  That attribute already means
word sized or less.

> In theory, this is still vulnerable to users adding a new platform
> with a smaller word size that would make such assertions invalid.
> We could guard against that by making the assertion "definitely
> not bigger than an N-bit word,  for N = 32 or 64. Then we
> apply the assertion on platforms with N or more bits in a word,
> and ignore it otherwise.

That's essentially what I was suggesting.

> I can't think of a plausible way for a platform change to invalidate
> such an assertion *without* a word size change, but then again,
> I am not as familiar with the C#/Java platform scene as you guys.

C# and Java are not relevant in the context of this discussion.
(Almost all the types in those languages are reference types and we
already have special support for those that are not.)

> What is your opinion?

There are three annotations you can reasonably have concerning
the size of a foreign_type (in C):

   1. definitely word sized or less (i.e. can_pass_as_mercury_type).
   2. definite fixed size, which may exceed the word size.
   3. definitely greater than a word in size.

Almost every foreign type I have ever seen falls into the first
category.

    :- pragma foreign_type("C", foo, "int64_t").

is an example of where the second category could be used.
(At least it was until I added 64-bit integers to the language itself.)

I don't think I have ever seen an instance of the third category.

In C, there is also a subset of types where you simply are not
going to know the size (in a portable fashion), due to things
like structure padding and alike.

Julien.


More information about the reviews mailing list