@@ -9,8 +9,11 @@ them completely via simple [constant propagation](https://en.wikipedia.org/wiki/
99Afterwards I developed two languages which are directly designed to do all
1010their type-checking via constant propagation:
1111[ Simple] ( https://github.com/SeaOfNodes/Simple ) and [ AA] ( https://github.com/cliffclick/aa ) . Both languages are statically typed
12- and type-safe; Simple uses constant propagation exclusively while AA uses a
13- blend of extended Hindley-Milner and constant propagation.
12+ and type-safe; AA uses a blend of extended Hindley-Milner and constant propagation.
13+
14+ [ Simple] ( https://github.com/SeaOfNodes/Simple ) uses constant propagation exclusively to do type analysis (and the
15+ generate any resulting semantic errors), and has a working implementation
16+ so you can view it in action!
1417
1518In both languages, after the first round of * pessimistic* constant propagation
1619(and extensive peephole optimizations) completes, every program point (node in
@@ -48,8 +51,11 @@ IR graph* or sometimes simply *nodes*.
4851* [ Nomative Typing and Traits and Interfaces] ( #nomative-typing-and-traits-and-interfaces )
4952* Conditional Conformance
5053* Call Graph Discovery
54+ * Parametric Polymorphism
5155* Separate compilation
5256* Performance Concerns
57+ * A Self Type
58+ * Overloading
5359* Typing other simple properties: mutable-or-not, [ initialized/destructed] -or-not
5460* Arrays
5561
@@ -326,6 +332,19 @@ if( ptr ) // null-check
326332 ptr.makeSound() // Legal, because ptr cannot be null
327333```
328334
335+ The same code with a "possibly null pointer" error:
336+
337+ ```
338+ val ptr = rand() ? null : Cat("Whiskers"); // Inferred type: *[name:"Whiskers", makeSound=#1{}]?
339+ ptr.makeSound() // Illegal, because ptr might be null
340+ ```
341+
342+ Here the load to fetch the ` makeSound ` method fails during error reporting; in
343+ Simple this is just a ` LoadNode ` which has an error check against its pointer
344+ input being possibly ` null ` .
345+
346+
347+
329348### Equivalence Class Aliasing
330349
331350The Sea-of-Nodes IR design uses the * equivalence class* model of aliasing,
@@ -395,7 +414,9 @@ large program with many 1000's of functions. The most common case is a single
395414function, i.e., just calling a function by name.
396415
397416A * function index* is simply a unique small integer that refers to a function
398- (perhaps via array lookup), and can be efficiently tracked.
417+ (perhaps via array lookup), and can be efficiently tracked. We print them as
418+ ` [#fidxs]{signature -> return} ` The above ` fcn ` is typed ` [#2,3]{u8 -> u16} ` ,
419+ indicating both function #2 and function #3 are included here.
399420
400421The type system will track function collections * in general* , so the general
401422case is that the function type has a set of allowed functions, and might
@@ -434,21 +455,21 @@ In this typing formulation, methods will be struct **fields** that happen to be
434455function-typed, or basically as type sugar over the existing types already
435456mentioned above.
436457
437- The ` toUpperCase ` field here is ** finally** assigned a function constant - and, as
438- with all final constant fields, the field value is the same for all instances
439- of ` String ` so does not need to be implemented as actually in the ` String `
440- instances. As an implementation detail, these final field constants can be moved over to some
441- collection of such fields, e.g. a ` class String ` instance.
458+ The ` toUpperCase ` field here is ** finally** assigned a function constant - and,
459+ as with all final constant fields, the field value is the same for all
460+ instances of ` String ` so does not need to be implemented as actually in the
461+ ` String ` instances. As an implementation detail, these final field constants
462+ can be moved over to some collection of such fields, e.g. a ` class String `
463+ instance.
442464
443465From the typing systems point-of-view, the field is a full-fledged
444466member of the ` String ` type. E.g. some pseudo-definition of ` String ` :
445467
446468``` java
447- String = : [ // String is a struct type...
448- toUpperCase // with a field called toUpperCase...
449- : { String - > String } // typed as a function from self/String to String
450- = { body },
451- ... // And probably has many more fields, elided here
469+ String = : [ // String is a struct type...
470+ toUpperCase // with a field called toUpperCase...
471+ : [#1 ]{ String - > String }, // typed as a function from String to String
472+ ... // And probably has many more fields, elided here
452473];
453474```
454475
0 commit comments