Skip to content

Commit

Permalink
Merged from upstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardgeek committed Jun 22, 2022
1 parent f3fd2b9 commit 62f5a00
Show file tree
Hide file tree
Showing 15 changed files with 254 additions and 204 deletions.
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ This is not an officially supported Google product.
cool new security and efficiency features of Rune, but, for now, it is not
recommended for any production use case.**

Rune is a systems programming language designed for security-sensitive
applications. Rune can help you avoid common security flaws that often arise
when using traditional systems languages such as C and C++. Its primary goal is
providing safety features for hardware-enforced private computation such as
[sealed computation](https://arxiv.org/abs/1906.07841) or [secure
enclaves](https://www.infosecurity-magazine.com/opinions/enclaves-security-world/).
Rune's most notable security feature is constant-time processing of secrets.
Rune also aims to be faster than C++ for most memory-intensive applications,
due to its Structure-of-Array
Rune is a Python-inspired efficient systems programming language designed to
interact easily with C and C++ libraries. Rune's most notable security feature
is constant-time processing of secrets. Rune aims to be faster than C++ for
most memory-intensive applications, due to its Structure-of-Array
\([SoA](https://en.wikipedia.org/wiki/AoS_and_SoA#:~:text=AoS%20vs.,AoS%20case%20easier%20to%20handle.)\)
memory management.

Additional documentation:

* [Rune Overview](docs/index.md)
* [Rune for Python programmers](docs/rune4python.md)

Consider the following example for treatment of secrets:

```
Expand Down Expand Up @@ -161,9 +161,6 @@ we can create/destroy Node objects arbitrarily, unlike the C++ benchmark based
on `MemoryPool`. When completed, we expect Rune to win most memory-intensive
benchmarks.

For more information about Rune, see additional documentation in
[g3doc](g3doc/index.md).

## Compiling the Rune compiler:

You'll need 6 dependencies installed to compile Rune:
Expand Down
35 changes: 19 additions & 16 deletions builtin/arraylist.rn
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,30 @@
// limitations under the License.

generator ArrayList(A: Class, B: Class, cascadeDelete:bool = false,
labelA: string = "", labelB: string = "") {
labelA: string = "", labelB: string = "", pluralB = "") {
if pluralB == "" {
pluralB = "$B_s"
}
prependcode A {
self.$labelB$B_s = arrayof(B)
self.$labelB$pluralB = arrayof(B)

func resize$labelB$B_s(self, num$labelB$B_s: Uint) {
length = self.$labelB$B_s.length()
func resize$labelB$pluralB(self, num$labelB$pluralB: Uint) {
length = self.$labelB$pluralB.length()
if num$labelB$B < length {
// Remove children that fall off the end.
for i in range(num$labelB$B_s, length) {
child = self.$labelB$B_s[i]
for i in range(num$labelB$pluralB, length) {
child = self.$labelB$pluralB[i]
if !isnull(child) {
self.remove$labelB$B(child)
}
}
} else {
// Initialize the new values to null.
for i in range(length, num$labelB$B_s) {
self.$labelB$B_s[i] = null(B)
for i in range(length, num$labelB$pluralB) {
self.$labelB$pluralB[i] = null(B)
}
}
self.$labelB$B_s.resize(num$labelB$B_s)
self.$labelB$pluralB.resize(num$labelB$pluralB)
}

func append$labelB$B(self, child: B) {
Expand All @@ -42,8 +45,8 @@ generator ArrayList(A: Class, B: Class, cascadeDelete:bool = false,
throw "append$labelB$B: Object is already in a relation"
}
}
child.$labelA$A_Index = <u32>self.$labelB$B_s.length()
self.$labelB$B_s.append(child)
child.$labelA$A_Index = <u32>self.$labelB$pluralB.length()
self.$labelB$pluralB.append(child)
child.$labelA$A = self
ref child
}
Expand All @@ -54,7 +57,7 @@ generator ArrayList(A: Class, B: Class, cascadeDelete:bool = false,
throw "remove$labelB$B: Object not owned by me"
}
}
self.$labelB$B_s[child.$labelA$A_Index] = null(child)
self.$labelB$pluralB[child.$labelA$A_Index] = null(child)
child.$labelA$A_Index = 0xffffffffu32
child.$labelA$A = null(self)
unref child
Expand All @@ -64,8 +67,8 @@ generator ArrayList(A: Class, B: Class, cascadeDelete:bool = false,
if cascadeDelete {
// If this is a cascade-delete relationship, destroy children in the destructor.
appendcode A.destroy {
for i in range(self.$labelB$B_s.length()) {
child$labelB$B = self.$labelB$B_s[i]
for i in range(self.$labelB$pluralB.length()) {
child$labelB$B = self.$labelB$pluralB[i]
if !isnull(child$labelB$B) {
child$labelB$B.destroy()
}
Expand All @@ -74,8 +77,8 @@ generator ArrayList(A: Class, B: Class, cascadeDelete:bool = false,
} else {
// Remove all children.
prependcode A.destroy {
for i in range(self.$labelB$B_s.length()) {
child$labelB$B = self.$labelB$B_s[i]
for i in range(self.$labelB$pluralB.length()) {
child$labelB$B = self.$labelB$pluralB[i]
if !isnull(child$labelB$B) {
self.remove$labelB$B(child$labelB$B)
}
Expand Down
20 changes: 9 additions & 11 deletions builtin/doublylinked.rn
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@

generator DoublyLinked(A: Class, B: Class, cascadeDelete:bool = false,
labelA: string = "", labelB: string = "", pluralB: string = "") {
/*
if pluralB == "" {
pluralB = labelB + B + "s"
pluralB = "$B_s"
}
*/
prependcode A {
self.first$labelB$B = null(B)
self.last$labelB$B = null(B)
Expand Down Expand Up @@ -106,17 +104,17 @@ generator DoublyLinked(A: Class, B: Class, cascadeDelete:bool = false,
unref child
}

func count$labelB$B_s(self) {
func count$labelB$pluralB(self) {
count = 0
for child in self.$labelB$B_s() {
for child in self.$labelB$pluralB() {
count += 1
}
return count
}

func index$labelB$B(self, index) {
count = 0
for child in self.$labelB$B_s() {
for child in self.$labelB$pluralB() {
if count == index {
return child
}
Expand All @@ -125,19 +123,19 @@ generator DoublyLinked(A: Class, B: Class, cascadeDelete:bool = false,
return null(child)
}

iterator $labelB$B_s(self) {
iterator $labelB$pluralB(self) {
for child = self.first$labelB$B, !isnull(child), child = child.next$A$labelB$B {
yield child
}
}

iterator reverse$labelB$B_s(self) {
iterator reverse$labelB$pluralB(self) {
for child = self.last$labelB$B, !isnull(child), child = child.prev$A$labelB$B {
yield child
}
}

iterator safe$labelB$B_s(self) {
iterator safe$labelB$pluralB(self) {
child = self.first$labelB$B
while !isnull(child) {
next$A$labelB$B = child.next$A$labelB$B
Expand All @@ -146,7 +144,7 @@ generator DoublyLinked(A: Class, B: Class, cascadeDelete:bool = false,
}
}

iterator safeReverse$labelB$B_s(self) {
iterator safeReverse$labelB$pluralB(self) {
child = self.last$labelB$B
while !isnull(child) {
prevA$labelB$B = child.prev$A$labelB$B
Expand All @@ -171,7 +169,7 @@ generator DoublyLinked(A: Class, B: Class, cascadeDelete:bool = false,
do {
child$labelB$B = self.first$labelB$B
} while !isnull(child$labelB$B) {
self.remove(child$labelB$B)
self.remove$labelB$B(child$labelB$B)
}
}
}
Expand Down
69 changes: 41 additions & 28 deletions builtin/hashed.rn
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ func hashValue(value) -> u64 {
generator Hashed(A: Class, B: Class, cascadeDelete: bool = false,
labelA: string = "", labelB: string = "", keyField: string = "hash", pluralB: string = "") {
if pluralB == "" {
pluralB = labelB + "s";
pluralB = "$B_s";
}
prependcode A {
self.table = arrayof(B)
self.numEntries = 0
self.$labelB$B_Table = arrayof(B)
self.num$labelB$pluralB = 0

func find$labelB$B(self, key) {
if self.table.length() == 0 {
return null(self.table[u64])
if self.$labelB$B_Table.length() == 0 {
return null(self.$labelB$B_Table[u64])
}
hash = hashValue(key) & <u64>(self.table.length() - 1)
entry = self.table[hash]
hash = hashValue(key) & <u64>(self.$labelB$B_Table.length() - 1)
entry = self.$labelB$B_Table[hash]
while !isnull(entry) {
if key == entry.$keyField {
return entry
Expand All @@ -97,37 +97,39 @@ generator Hashed(A: Class, B: Class, cascadeDelete: bool = false,
}

func insert$labelB$B(self, entry) {
if self.numEntries == self.table.length() {
if self.table.length() == 0 {
self.table.resize(1)
if self.num$labelB$pluralB == self.$labelB$B_Table.length() {
if self.$labelB$B_Table.length() == 0 {
self.$labelB$B_Table.resize(1)
} else {
// Double the size of the hash table.
self.table.resize(self.table.length() << 1)
self.$labelB$B_Table.resize(self.$labelB$B_Table.length() << 1)
}
for i in range(self.numEntries, self.table.length()) {
self.table[i] = null(entry)
for i in range(self.num$labelB$pluralB, self.$labelB$B_Table.length()) {
self.$labelB$B_Table[i] = null(entry)
}
}
hash = hashValue(entry.$keyField) & <u64>(self.table.length() - 1)
prevEntry = self.table[hash]
hash = hashValue(entry.$keyField) & <u64>(self.$labelB$B_Table.length() - 1)
prevEntry = self.$labelB$B_Table[hash]
entry.nextHashed$A$labelB$B = prevEntry
self.table[hash] = entry
self.numEntries += 1
self.$labelB$B_Table[hash] = entry
self.num$labelB$pluralB += 1
entry.$labelA$A = self
ref entry
}

func remove$labelB$B(self, child) {
hash = hashValue(child.$keyField) & <u64>(self.table.length() - 1)
entry = self.table[hash]
hash = hashValue(child.$keyField) & <u64>(self.$labelB$B_Table.length() - 1)
entry = self.$labelB$B_Table[hash]
prev = null(entry)
while !isnull(entry) {
if entry == child {
if isnull(prev) {
self.table[hash] = child.nextHashed$A$labelB$B
self.$labelB$B_Table[hash] = child.nextHashed$A$labelB$B
} else {
prev.nextHashed$A$labelB$B = child.nextHashed$A$labelB$B
}
child.nextHashed$A$labelB$B = null(child)
child.$labelA$A = null(self)
unref child
return
}
Expand All @@ -138,43 +140,54 @@ generator Hashed(A: Class, B: Class, cascadeDelete: bool = false,
}

iterator $labelB$pluralB(self) {
for i in range(self.table.length()) {
entry = self.table[i]
for i in range(self.$labelB$B_Table.length()) {
entry = self.$labelB$B_Table[i]
while !isnull(entry) {
yield entry
entry = entry.nextHashed$A$labelB$B
}
}
}

iterator safe$labelB$pluralB(self) {
for i in range(self.$labelB$B_Table.length()) {
entry = self.$labelB$B_Table[i]
while !isnull(entry) {
nextEntry = entry.nextHashed$A$labelB$B
yield entry
entry = nextEntry
}
}
}
}

if cascadeDelete {
// If this is a cascade-delete relationship, destroy children in
// the destructor.
appendcode A.destroy {
for x$labelB$B in range(self.table.length()) {
$labelB$B_Entry = self.table[x$labelB$B]
for x$labelB$B in range(self.$labelB$B_Table.length()) {
$labelB$B_Entry = self.$labelB$B_Table[x$labelB$B]
while !isnull($labelB$B_Entry) {
next$labelB$B_Entry = $labelB$B_Entry.nextHashed$A$labelB$B
$labelB$B_Entry.nextHashed$A$labelB$B = null($labelB$B_Entry)
$labelB$B_Entry.$labelA$A = null(self)
$labelB$B_Entry.destroy()
$labelB$B_Entry = next$labelB$B_Entry
}
self.table[x$labelB$B] = null($labelB$B_Entry)
self.$labelB$B_Table[x$labelB$B] = null($labelB$B_Entry)
}
}
} else {
appendcode A.destroy {
for x$labelB$B in range(self.table.length()) {
$labelB$B_Entry = self.table[x$labelB$B]
for x$labelB$B in range(self.$labelB$B_Table.length()) {
$labelB$B_Entry = self.$labelB$B_Table[x$labelB$B]
while !isnull($labelB$B_Entry) {
next$labelB$B_Entry = $labelB$B_Entry.nextHashed$A$labelB$B
$labelB$B_Entry.nextHashed$A$labelB$B = null($labelB$B_Entry)
$labelB$B_Entry.$labelA$A = null(self)
$labelB$B_Entry = next$labelB$B_Entry
}
self.table[x$labelB$B] = null($labelB$B_Entry)
self.$labelB$B_Table[x$labelB$B] = null($labelB$B_Entry)
}
}
}
Expand Down
Loading

0 comments on commit 62f5a00

Please sign in to comment.