unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: "Mattias Engdegård" <mattiase@acm.org>
Cc: emacs-devel@gnu.org, Andrea Corallo <akrl@sdf.org>
Subject: Re: master 0cbcc62: 'assoc' is not side-effect-free; constprop its pure subset
Date: Sun, 01 Nov 2020 09:07:46 -0500	[thread overview]
Message-ID: <jwvh7q941za.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <823589BC-6CB4-4140-A442-10B5FF5870AC@acm.org> ("Mattias Engdegård"'s message of "Sun, 1 Nov 2020 13:56:50 +0100")

> It wasn't really meant seriously, but a simple system may look like
>
> EFFECT ::=
>    nil        ; no effect (subset of all effects)
>  | *          ; any effect (superset of all effects)
>  | signal     ; signal any condition (error etc)
>  | read-env   ; read from the global environment
>  | N          ; effect of function passed as argument N, N≥1
>  | (union EFFECT...)  ; union of effects

Side note: this sounds good (I've been thinking along very similar lines
recently to try and improve the docs of `pure` and `side-effect-free`),
but note that nil has to me "any effect" since most functions will come
with no annotation at all (which most is most naturally mapped to nil).

Also, there are a few functions which we're willing to constant-fold
even though they can have "minor" side-effects (the cases I can think of
seem to be mostly about clobbering the match-data, so maybe all it means
is that we need is an additional `clobbers-match-data`, which means that
the contents of the match-data can't be relied upon after the call).

> More fine-grained effects could be added, such as throws, mutation of
> arguments, reading data referenced by arguments, etc.

If we ever want to be able to detect match-data errors via static
analysis, we'd need to know which functions set the match data, which
functions are guaranteed not to affect the match-data, and which
functions read the match data (then we can warn any time you read the
match data even though you called a function not known to preserve the
match-data since the last call to a match-data-setting function).
Now admittedly, "preserve the match-data" is not really an effect ;-)

> It all depends on what is useful for the compiler(s) and related tools.

Indeed, we should keep things as simple as possible.  For me the main
benefit is that it seems easier to explain those effects than to explain
what it means to be "pure" or "side-effect-free", probably because both
of those terms already exist in computer-English but with not 100%
precise meanings and that our use doesn't match 100% either.


        Stefan




  reply	other threads:[~2020-11-01 14:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20201031133156.28415.87445@vcs0.savannah.gnu.org>
     [not found] ` <20201031133158.04C1220A1C@vcs0.savannah.gnu.org>
2020-10-31 15:06   ` master 0cbcc62: 'assoc' is not side-effect-free; constprop its pure subset Stefan Monnier
2020-11-01  9:39     ` Mattias Engdegård
2020-11-01  9:47       ` Andrea Corallo via Emacs development discussions.
2020-11-01 12:56         ` Mattias Engdegård
2020-11-01 14:07           ` Stefan Monnier [this message]
2020-11-02  5:40             ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvh7q941za.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=akrl@sdf.org \
    --cc=emacs-devel@gnu.org \
    --cc=mattiase@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).