Project Fortress

27
Alex Miller Project Fortress http://www.flickr.com/photos/micbaun/1216608114/ Wednesday, July 1, 2009

description

An overview of Project Fortress, a research language being developed at Sun, focusing on scientific and large-scale computing.

Transcript of Project Fortress

Page 1: Project Fortress

Alex MillerProject Fortress

http://www.flickr.com/photos/micbaun/1216608114/Wednesday, July 1, 2009

Page 2: Project Fortress

Dude, isn’t Fortress like FORTRAN or something?

http://www.flickr.com/photos/finkle/3111290180/Wednesday, July 1, 2009

Page 3: Project Fortress

Um, no.

Wednesday, July 1, 2009

Page 4: Project Fortress

Modern language design

+

Scientific computing

Wednesday, July 1, 2009

Page 5: Project Fortress

Features of interest

Mathematical rendering

Parallelism

Software transactional memory

Operator and function overloading

Objects / traits

Contracts

Components / apis

Wednesday, July 1, 2009

Page 6: Project Fortress

Let’s build some basics

Wednesday, July 1, 2009

Page 7: Project Fortress

Types

ZZ32, ZZ64 - signed integer types

RR32, RR64 - floating point types

String

Boolean

Wednesday, July 1, 2009

Page 8: Project Fortress

juxtaposition

3 4 evaluates to 12

“a” “b” evaluates to “ab”

log 1 evaluates to 0

Wednesday, July 1, 2009

Page 9: Project Fortress

Ranges

5:9 evaluates to [5,6,7,8,9]

5:9:2 evaluates to [5,7,9]

5#2 evaluates to [5,6]

Wednesday, July 1, 2009

Page 10: Project Fortress

Variables

Immutable: name[:type] = value

zero = 0

zero:ZZ32 = 0

Mutable: var name[:type] = value OR name[:type] := value

var sum = 0

sum := 0

Wednesday, July 1, 2009

Page 11: Project Fortress

Now you’re dangerous.

Wednesday, July 1, 2009

Page 12: Project Fortress

A simple examplecomponent factexport Executable

fact(n:ZZ32): ZZ32 = if n = 0 then 1 else n fact(n-1) end

run():()=do for k<-seq(1:10) do println " fact(" k ") = " fact(k) endend

end

Executable - a trait defining run()

Rendering: ZZ32, <-, fonts

juxtaposition as operator

Parallelism - in terms, in for

seq() - force sequential

Wednesday, July 1, 2009

Page 13: Project Fortress

BIG ideas

But factorial is just a big multiply...use aggregate PROD operator ∏ instead.

This is known as a BIG operator.

Wednesday, July 1, 2009

Page 14: Project Fortress

component factp export Executable

factp(n:ZZ32): ZZ32 = PROD [i <- 1:n] i

run():()=do for k<-seq(1:10) do println " factp(" k ") = " factp(k) endend

end

More direct implementation

PROD = aggregate product

SUM = summation

Known as “BIG” operators

You can make your own!

Wednesday, July 1, 2009

Page 15: Project Fortress

Operator overloading

Would be nice to actually use the right mathematical operator ! instead of a function, wouldn’t it?

Wednesday, July 1, 2009

Page 16: Project Fortress

component factoexport Executable

opr(n:ZZ32)! = PROD [i <- 1:n] i

run():()=do for k<-seq(1:10) do println k "! = " k! endend

end

Let’s make it an operator

opr() used to define a postfix operator here

Also can do prefix, infix, nofix, multifix, or enclosing!

Wednesday, July 1, 2009

Page 17: Project Fortress

Lists

evens = <|[\ZZ32\] 2,4,6,8,10|> println "evens: " evens

evens2 = <|[\ZZ32\] 2 x | x <- 1:5|>println "evens2: " evens2

odds = <|[\ZZ32\] e - 1 | e <- evens |>println "odds: " odds

evens: <|2, 4, 6, 8, 10|>

evens2: <|2, 4, 6, 8, 10|>

odds: <|1, 3, 5, 7, 9|>

Wednesday, July 1, 2009

Page 18: Project Fortress

Another example

What’s the bug? (Hint: think parallelism)

component sosimport List.{...}export Executable

sumOfSquares(n:List[\ZZ32\]): ZZ64 = do sum:ZZ64 := 0 for i<-0#|n| do sum += (n[i])^2 end sumend

run():()=do theList = <|[\ZZ32\] x | x<-1#100|> println "sumOfSquares = " sumOfSquares(theList)end

end

Wednesday, July 1, 2009

Page 19: Project Fortress

Implicit parallelism

Many things implicitly parallel

for loops

parameters to a function call

do ... also ... end construct

Here, for loop is parallel, so sum += is a data race

Use atomic to fix

Wednesday, July 1, 2009

Page 20: Project Fortress

Atomic punkcomponent sosimport List.{...}export Executable

sumOfSquares(n:List[\ZZ32\]): ZZ64 = do sum:ZZ64 := 0 for i<-0#|n| do atomic sum += (n[i])^2 end sumend

run():()=do theList = <|[\ZZ32\] x | x<-1#100|> println "sumOfSquares = " sumOfSquares(theList)end

end

Fortress uses Software Transactional Memory

atomic blocks executed all or nothing

Retry on collision

Transactions may nest

tryatomic

Wednesday, July 1, 2009

Page 21: Project Fortress

Traits

trait - like Java interface

methods - abstract or concrete

object - like Java final class

fields, methods

constructors

multiple inheritance

getter / setter - metadata

component traitexampleexport Executable

trait Animal talk():Stringend

trait Fuzzy howFuzzy():Stringend

trait Cat extends Animal getter name():String talk() = "meow"end

object Whiskers extends {Cat, Fuzzy} name() = "Whiskers" howFuzzy() = "real fuzzy"end

run():() = do w:Whiskers = Whiskers println w.name() " is " w.howFuzzy()endend

Wednesday, July 1, 2009

Page 22: Project Fortress

Function contracts

Documentation of semantic constraints beyond the type system.

requires - specifies pre-conditions on incoming arguments

ensures - specifies post-condition on “outcome”

component factcexport Executable

factorial(n:ZZ32):ZZ32 requires { n >= 0 } ensures { outcome >= 0 } = PROD [i <- 1:n] i

run():() = do for k<-seq(1:10) do println k "! = " factorial(k) endendend

Wednesday, July 1, 2009

Page 23: Project Fortress

Components and APIs

Components modularize your program

Components export and import APIs (NEVER other components, just APIs)

APIs are explicitly defined in their own file type

Repository for components

Wednesday, July 1, 2009

Page 24: Project Fortress

And more...Literal arrays, multi-dimensional arrays

Maps, sets, skip lists, trees, heaps, sparse vectors and matrices, quick sort, etc in library

Explicit thread spawn, memory region tree

Function overloading

Tuples

Tests

Functions as first class objects

Exceptions

Wednesday, July 1, 2009

Page 25: Project Fortress

Whither next?

Currently working on compiler

Goal is to have it working in 6 months for a real bioinformatics project

Wednesday, July 1, 2009

Page 27: Project Fortress

Alex Miller

Twitter: http://twitter.com/puredanger

Blog: http://tech.puredanger.com

Presentations: http://slideshare.net/alexmiller

Wednesday, July 1, 2009