ideas-computer-jasper-jasperNotes6

https://www.semipublic.comp-arch.net/wiki/Bad,_Good,_and_Middling_Ideas_in_Computer_Architecture

https://www.semipublic.comp-arch.net/wiki/Design_Principles_and_Rules_of_Thumb

--

my notes on katherine coons's notes on tim sweeney's talk

Three Kinds of Code

game simulation (shared state concurrency): software transactional memory numeric computation: implicit thread parallelism (purely functional) shading: implicit data parallelism (SIMD)

  --

Vertex[] Transform (Vertex[] Vertices, int[] Indices, Matrix m) { Vertex[] Result = new Vertex[Indices.length]; for(int i=0; i<Indices.length; i++) Result[i] = Transform(m,Vertices[Indices[i]]); return Result; };

problems: each input may be NULL, Indices May contain indices outside of the range of the Vertex array, so Indices.length could dereference a NULL pointer, Vertices[Indices[i]] might be out of bounds., transform may hang

Dynamic failure in mainstream languages

Solved problems: Random memory overwrites Memory leaks (?)

Solvable: Accessing arrays out of bounds Dereferencing null pointers Integer overflow Accessing uninitialized variables

50% of the bugs in Unreal can be traced to these problems!

Transform{n:nat}(Vertices:[n]Vertex, Indices:[]nat<n, m:Matrix):[]Vertex= for each(i in Indices) Transform(m,Vertices[i])

the only problem left: transform may hang

how might this work?

  --

Dependent types

int nat nat<n

Dependent functions

Sum(n:nat,xs:[n]int)=.. a=Sum(3,[7,8,9])

Universal quantification

Sum{n:nat}(xs:[n]int)=.. a=Sum([7,8,9])

  --

(maybe/option types): Separating the “pointer to t” concept from the “optional value of t” concept

xp:^int xo:?int xpo:?^int

Advantages: You can’t dereference a NULL pointer The compiler can force you to do the appropriate error checks

?int x = lookup(t, k) FOUND(x) -> { use x … } NOTHING(x) -> { display error message of your choice

  --

Comprehensions (a la Haskell), for safely traversing and generating collections

Successors(xs:[]int):[]int= foreach(x in xs) x+1

Now we can’t have an index out of bounds error!

But this ties the Collections object and Iterator interface directly to the language - sacrifice abstraction

A guarded casting mechanism for cases where need a safe “escape”:

GetElement?(as:[]string, i:int):string= if(n:nat<as.length=i) as[n] else “Index Out of Bounds”

  --

Exceptions impose sequencing constraints on concurrent execution.

Dependent types and concurrency must evolve simultaneously

  --

Analysis of Unreal code

Usage of integer variables in Unreal: 90% of integer variables in Unreal exist to index into arrays 80% could be dependently-typed explicitly, guaranteeing safe array access without casting. 10% would require casts upon array access. The other 10% are used for: Computing summary statistics Encoding bit flags Various forms of low-level hackery

How true are these observations for other types of code?

“For” loops in Unreal: 40% are functional comprehensions 50% are functional folds Functional comprehensions (foreach) Functional folds: Operator to encapsulate simple patterns of recursion for processing lists

  --

Accessing uninitialized variables

class MyClass? { const int a=c+1; const int b=7; const int c=b+1; } MyClass?