Category Theory
Zulip Server
Archive

You're reading the public-facing archive of the Category Theory Zulip server.
To join the server you need an invite. Anybody can get an invite by contacting Matteo Capucci at name dot surname at gmail dot com.
For all things related to this archive refer to the same person.


Stream: learning: questions

Topic: aliasing


view this post on Zulip Joe Moeller (Apr 06 2020 at 16:46):

I've programmed in C++ a fair amount. What's aliasing? @sarahzrf

view this post on Zulip Jules Hedges (Apr 06 2020 at 16:48):

That would be references, I guess (and potentially also pointers)

view this post on Zulip Joe Moeller (Apr 06 2020 at 16:53):

There was some discussion on it in another stream since it has to do with Sarah's talk. There she said it had to do with pointers, and I guess something about having two distinct pointers point to the same thing.

view this post on Zulip Reid Barton (Apr 06 2020 at 16:57):

Yeah, basically it refers to when two pointers point to the same thing or overlapping things, particularly when you didn't expect them to.

view this post on Zulip Joe Moeller (Apr 06 2020 at 16:58):

What's the deal with these? What sorts of issues make people say "oh what about aliasing?"

view this post on Zulip Jules Hedges (Apr 06 2020 at 16:59):

(the underlying language-independent concept can also be called names, ie. having multiple names for the same thing)

view this post on Zulip Jules Hedges (Apr 06 2020 at 17:00):

Aliasing + destructive updates = headache. Somebody can do something to xx, and suddenly yy has changed. It means you can't reason lexically

view this post on Zulip Reid Barton (Apr 06 2020 at 17:02):

For example if you want to optimize a for loop, you might want to know that updates you make in the body of the for loop don't affect the value of the upper bound of the loop.

view this post on Zulip James Wood (Apr 06 2020 at 17:08):

IIRC, copying an array is a classic thing that can be hit by aliasing. If source and target arrays overlap, the naïve algorithm will at some point start copying the start of the source array again, into the end of the target array (because it starts reading from the start of the target array, which has written over values from the source array).

view this post on Zulip Reid Barton (Apr 06 2020 at 17:08):

Or imagine you are implementing a function that takes pointers to three matrices AA, BB, CC and updates CC according to the rule C:=C+ABC := C + A B.

view this post on Zulip Reid Barton (Apr 06 2020 at 17:10):

The obvious implementation won't work as claimed if the reference CC is the same as either AA or BB (but it's fine if AA and BB are the same reference). A variant of James's example.

view this post on Zulip Joe Moeller (Apr 06 2020 at 17:10):

Great, this is all making sense.

view this post on Zulip Joe Moeller (Apr 06 2020 at 17:10):

I had the sense that it should be a thing I encountered but just never saw a name put to it, and that's exactly what it was!

view this post on Zulip Paolo Capriotti (Apr 06 2020 at 21:06):

the standard issue with aliasing is that if the compiler cannot prove that pointers point to different things, it might have to reload a value from memory even when not necessary, because it cannot be sure that it hasn't been written by previous instructions

view this post on Zulip Paolo Capriotti (Apr 06 2020 at 21:07):

so C for example has a keyword (restrict IIRC) to instruct the compiler that it is allowed to assume that two pointers point to non-overlapping areas, so that certain optimisations can be applied

view this post on Zulip sarahzrf (Apr 06 2020 at 23:06):

reid's example ties in great with the kind of thing i would want to illustrate, actually

view this post on Zulip sarahzrf (Apr 06 2020 at 23:07):

the kind of place you use separation logic in practice is generally for writing down specifications of the behavior of programs, such as saying "this program really does add matrices"

view this post on Zulip sarahzrf (Apr 06 2020 at 23:07):

but of course, if you wrote the obvious implementation, that specification just isn't true—what if the matrices you pass in alias?

view this post on Zulip sarahzrf (Apr 06 2020 at 23:08):

except that in separation logic, you can use "separating conjunction" instead of ordinary conjunction when necessary, and when you do so, you implicitly rule out such cases in your premise

view this post on Zulip sarahzrf (Apr 06 2020 at 23:09):

so that the case you naïvely had in mind now really is what you're saying with your specification

view this post on Zulip sarahzrf (Apr 06 2020 at 23:10):

the "separation" is as in "separation of the resources underlying the matrices from one another"