tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] enforced immutability - proposed research project


From: Bruno Haible
Subject: Re: [Tinycc-devel] enforced immutability - proposed research project
Date: Mon, 18 Jan 2021 10:59:10 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-197-generic; KDE/5.18.0; x86_64; ; )

Hello Christian,

> Silly question, putting immutable objects in a read only section is not
> enough?

I'm mainly concerned about objects in the heap.

Typically, immutable objects are still mutable while they are being
constructed. Typical code looks like this:

        struct data *wp;
        struct data const *p;

        wp = (struct data *) malloc (sizeof (struct data));
        wp->x = 7;
        wp->y = 42;
        p = wp;
        assert (p->x == 7);
        assert (p->y == 42);
        ((struct data *) p)->x = 9; // Violation of immutability, no crash
        ...
        free (p);

To enforce immutability, it would be transformed to

        struct data *wp;
        struct data const *p;

        wp = (struct data *) immmalloc (sizeof (struct data));
        wp->x = 7;
        wp->y = 42;
        p = immfreeze (wp);
        assert (p->x == 7);
        assert (p->y == 42);
        ((struct data *) p)->x = 9; // Violation of immutability, crashes
        ...
        immfree (p);

> If accepted, it should have no impact on compilation speed which is one of
> the most important aspect of tcc (after correctness of course and execution
> speed which comes second). Changes must also apply to all current supported
> platforms.

That is one possible outcome.

Another possible outcome is a research paper.

Another possible outcome is a prototype that serves to guide an implementation
in GCC.

Another possibility is to use the idea for a GSoC student project.

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]