Skip to content

Commit

Permalink
cumulative updates from flat_alloc branch (#382)
Browse files Browse the repository at this point in the history
* disabling the pager in my pretty printing run script

* change the elaboration of `new` and non-local Invocations to match the flat yul object style (#367)

* making a change to double check work flow

* adding a stub for computing the size of a contract; that'll be its own PR entirely one day fairly soon, but for now, we assume that we just need 32 bytes

* using hex values for some boilerplate so that it matches the docs

* reworking constructors to just allocate memory

* adding some helper functions in util. one is a renaming for transactions from child contracts; the other is basically a type-checked comment pointing out uses of some pretty substantian technical debt

* temporarily removing the code to translate child contracts. rewriting the translation of Invocations to remap everything to local invocations instead, into the names that will be created in the flat yul object

* removing an assertion and adding translation of string literals

* whitespace, scala style

* utility function for undoing the transaction renaming

* generate flat yul object from child contracts (#369)

* rename, add boolean for main-ness in translate decl

* changing signature of translateDeclaration to remove a return that doesn't do anything

* whitespace, scala style

* comments

* scraps; adding an assert

* changing how child contracts are processed

* rewrite of translateTransaction

* chainging signature of translateStatement

* more threading through inMain

* whitespace, scala style

* adding some docs

* removing the nicer output for typed names in favor of a bland one, per solc's current limitations. adding a comment about why.

* adding a temporary fix to the top of the dispatch table pending talking with MC"

* removing a stale comment

* comments

* adding missing declarations to invocations

* cleaning up comments and some messy logic around temporary variables

* removing comment

* more hacks for specific tests in advance of type info

* changing hardcoded value in the mustache file for this to be the current contract address

* adding a couple of args to get this to typecheck

* use type annotations in Yul codegen (#377)

* removing a util function to rename functions in the dispatch table; that no longer makes sense with the solution for flattening that we've settled on for now

* adding comments; expanding getcontractname

* ripping out some code, adding comments

* adding a comment that may help to locate a bug later

* moving comment closer to the source and updating it

* comments

* scraps; this change seemed likely but breaks a bunch of tests

* quick function to traverse over an expression and check a given predicate on all the annotations

* fixing some import dependencies

* traversal of a program rather than just an expression; i sure hope i don't have to come back and make this the fully polymorphic map reduce but i bet i will

* adding updates to the expression returned in the checker from just the ReferenceIdentifier cases, after some debugging with @mcoblenz

* adding additional ParserUtil.updateExprType uses as seems right. bunch of tests fail, some of which i expected some i didn't, and i don't know how to fix a lot of them

* updating width calculation to actually inspect the type, now that we know it

* removing an assert that caused a bunch of false negatives.

* small changes per PR comments

* copying a slightly cut down version of linked lists, but this needs to be edited down even more to be the right goal for a demo.

* compute the sizes of contracts for allocation (#378)

* copying a slightly cut down version of linked lists, but this needs to be edited down even more to be the right goal for a demo.

* computing sizes of types recursively

* adding some simple hard coded unit tests

* copying over a helper from type checker tests to test on actual contracts in files

* adding more general tests; it doesn't work but i think i know why

* scraps and printlines from trying to debug sizes

* changing the type of the size computation function so it has enough information, per MC. reworking tests

* renaming size function; fixing the main test

* adding some comments and a variable for pointer sizes

* formatting, reworking base test

* removing the two simpler unit tests. it is hard and somewhat pointless to be the parser and create a contract table by hand, the existing test is informative enough

* fixing type checker errors (#380)

* debugging scraps

* copying a slightly cut down version of linked lists, but this needs to be edited down even more to be the right goal for a demo.

* commenting out spammy prints

* patch from MC

* updating override syntax to not introduce a new field

* updating expr type update to set the location and use the one field rather than build new ones

* removing printlines

* updating logged errors in a few places; this fixes some but not all of #379

* error in resourcesTest was in the test itself; it was incorrectly looking for m to be at int

* formatting, whitespace

* fixed permission passing test; also errors in the definition of the test, not the checker

* fixing all permowned error

* scala style, whitespace

* scraps

* adding a comment, removing a comment, removing an assert
  • Loading branch information
ivoysey committed Nov 1, 2021
1 parent 924ebf9 commit 726805a
Show file tree
Hide file tree
Showing 13 changed files with 821 additions and 349 deletions.
5 changes: 3 additions & 2 deletions Obsidian_Runtime/src/main/yul_templates/object.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ object "{{creationObject}}" {
if iszero(lt(calldatasize(), 4)) {
{{#dispatch}}
{{! TODO 224 is a magic number offset to shift to follow the spec above; check that it's right }}
let this := address()
let selector := shr(224, calldataload(0))
{{dispatchCase}}
{{/dispatch}}
Expand All @@ -63,14 +64,14 @@ object "{{creationObject}}" {
}
function allocate_unbounded() -> memPtr {
memPtr := mload(64)
memPtr := mload(0x40)
}
function finalize_allocation(memPtr, size) {
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
// protect against overflow
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
mstore(64, newFreePtr)
mstore(0x40, newFreePtr)
}
function panic_error_0x41() {
Expand Down
2 changes: 1 addition & 1 deletion bin/run_any_yul.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TOP=$(echo "$output" | grep -n "Pretty printed source:" | cut -f1 -d:)
BOT=$(echo "$output" | grep -n "Binary representation:" | cut -f1 -d:)
TOP=$((TOP+1)) # drop the line with the name
BOT=$((BOT-2)) # drop the empty line after the binary
echo -ne "$output" | sed -n $TOP','$BOT'p' | bat -l javascript --style=plain
echo -ne "$output" | sed -n $TOP','$BOT'p' | bat -l javascript --style=plain -P

TOP=$(echo "$output" | grep -n "Binary representation" | cut -f1 -d:)
BOT=$(echo "$output" | grep -n "Text representation" | cut -f1 -d:)
Expand Down
110 changes: 110 additions & 0 deletions resources/tests/GanacheTests/LinkedList.obs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
asset contract NodeMaybe {
state NodeNone {}
state NodeSome {
IntNode@Shared node;
}

NodeMaybe@NodeSome(IntNode@Shared node) {
->NodeSome(node = node);
}

NodeMaybe@NodeNone() {
->NodeNone;
}


transaction getNode(NodeMaybe@NodeSome this) returns IntNode@Unowned
{
return node;
}

transaction getValue(NodeMaybe@NodeSome this) returns int {
return node.getValue();
}
}


asset contract IntNode {
int elem;
NodeMaybe@Owned next;

IntNode@Owned(int elem, NodeMaybe@Owned next) {
this.elem = elem;
this.next = next;
}

transaction length(IntNode@Unowned this) returns int {
int i = 1;
switch next {
case NodeSome {
i = i + next.getNode().length();
}
}
return i;
}

transaction append(int new_elem) {
switch next {
case NodeSome {
next.getNode().append(new_elem);
}

case NodeNone {
next = new NodeMaybe(new IntNode(new_elem, new NodeMaybe()));
}
}
}
}

asset contract IntList {

NodeMaybe first;

IntList() {
first = new NodeMaybe();
}

transaction length() returns int {
int i = 0;
switch first {
case NodeSome {
i = first.getNode().length();
}
}
return i;
}

transaction append(int elem) {
switch first {
case NodeSome {
first.getNode().append(elem);
}
case NodeNone {
first = new NodeMaybe(new IntNode(elem, new NodeMaybe()));
}
}
}


/* assume that elements appear at most once */
transaction delete(int target) {
return; // TODO
}
}


main contract UsesLinkedList {

IntList ll;

transaction main() returns int {
ll = new IntList();
ll.append(1);
ll.append(2);
ll.append(3);
ll.append(4);
ll.append(5);
ll.delete(3);
return(ll.length());
}
}
3 changes: 1 addition & 2 deletions src/main/scala/edu/cmu/cs/obsidian/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package edu.cmu.cs.obsidian
import java.io.{File, FileInputStream}
import java.nio.file.{Files, Path, Paths, StandardCopyOption}
import java.util.Scanner

import org.apache.commons.io.FileUtils

import scala.collection.mutable.HashSet
Expand Down Expand Up @@ -252,7 +251,7 @@ object Main {

val checker = new Checker(transformedTable, options.typeCheckerDebug)
val (typecheckingErrors, checkedTable) = checker.checkProgram()

val allSortedErrors = (duplicateErrors ++ importErrors ++ transformErrors ++ typecheckingErrors).sorted

if (!allSortedErrors.isEmpty) {
Expand Down

0 comments on commit 726805a

Please sign in to comment.