Skip to content

Commit

Permalink
Merge branch 'dev' into rasi_generator
Browse files Browse the repository at this point in the history
  • Loading branch information
pieter-bos authored May 27, 2024
2 parents 0520db3 + de1dcdb commit 0aca156
Show file tree
Hide file tree
Showing 413 changed files with 11,039 additions and 6,453 deletions.
Empty file added .git-blame-ignore-revs
Empty file.
2 changes: 1 addition & 1 deletion .mill-jvm-opts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-Xss32m
-Xss128m
-Xmx2G
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.6
0.11.7
30 changes: 30 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version = 3.8.1
runner.dialect = scala213

maxColumn = 80

# always add trailing commas in expressions with more than one argument
# do allow removing the trailing comma if the expression fits on one line
rewrite.trailingCommas.style = "multiple"
rewrite.trailingCommas.allowFolding = true

# regardless of the input, try to compact expressions into one line
# the readability of this option is guarded by the fact that maxColumn = 80
newlines.source = fold
# never keep a part of the expression on the same line of a case/if/def/val if
# it is already multiple lines.
newlines.beforeMultiline = unfold
newlines.forceBeforeMultilineAssign = def
# try not to break strings by breaking them at interpolation points
# e.g. "longText ${x} moreLongText"
# should not be:
# "longText ${
# x} moreLongText"
# and instead should just overflow the line.
newlines.inInterpolation = avoid
# prefer to place a newline *before* the "implicit" keyword; not after.
newlines.implicitParamListModifierPrefer = before

# default: align the => arrows in cases
# here: do not align them, typically doesn't help readability.
align.preset = none
100 changes: 68 additions & 32 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import mill.{util => _, _}
import scalalib.{JavaModule => _, ScalaModule => _, _}
import contrib.buildinfo.BuildInfo
import me.pieterbos.mill.cpp.options.implicits._
import me.pieterbos.mill.cpp.options.CppExecutableOptions
import me.pieterbos.mill.cpp.options.{CppCompileOptions, CppExecutableOptions}
import me.pieterbos.mill.cpp.{CMakeModule, LinkableModule}
import me.pieterbos.mill.cpp.toolchain.GccCompatible
import mill.util.Jvm
Expand Down Expand Up @@ -687,7 +687,7 @@ object vercors extends Module {
}

object origin extends CppModule {
def moduleDeps = Seq(llvm, json, proto, proto.protobuf.libprotobuf)
def moduleDeps = Seq(llvm, json, proto, protobuf.libprotobuf)

def sources = T.sources(vcllvm.root() / "lib" / "origin")

Expand All @@ -698,7 +698,7 @@ object vercors extends Module {
}

object passes extends CppModule {
def moduleDeps = Seq(llvm, proto, proto.protobuf.libprotobuf)
def moduleDeps = Seq(llvm, proto, protobuf.libprotobuf)

def sources = T.sources(vcllvm.root() / "lib" / "passes")

Expand All @@ -709,7 +709,7 @@ object vercors extends Module {
}

object transform extends CppModule {
def moduleDeps = Seq(llvm, proto, proto.protobuf.libprotobuf)
def moduleDeps = Seq(llvm, proto, protobuf.libprotobuf)

def sources = T.sources(vcllvm.root() / "lib" / "transform")

Expand All @@ -720,7 +720,7 @@ object vercors extends Module {
}

object util extends CppModule {
def moduleDeps = Seq(llvm, proto, proto.protobuf.libprotobuf)
def moduleDeps = Seq(llvm, proto, protobuf.libprotobuf)

def sources = T.sources(vcllvm.root() / "lib" / "util")

Expand All @@ -732,48 +732,47 @@ object vercors extends Module {

override def unixToolchain = GccCompatible("g++", "ar")

def moduleDeps = Seq(origin, passes, transform, util, llvm, proto, proto.protobuf.libprotobuf)
def moduleDeps = Seq(origin, passes, transform, util, llvm, proto, protobuf.libprotobuf)

def sources = T.sources(vcllvm.root() / "tools" / "vcllvm")

def includePaths = T.sources(vcllvm.root() / "include")

object protobuf extends CMakeModule {
object protobufGit extends GitModule {
override def url: T[String] = "https://github.com/protocolbuffers/protobuf"

object proto extends CppModule {
object protobuf extends CMakeModule {
object protobufGit extends GitModule {
override def url: T[String] = "https://github.com/protocolbuffers/protobuf"

override def commitish: T[String] = "v25.2"
override def commitish: T[String] = "v25.2"

override def fetchSubmodulesRecursively = true
}
override def fetchSubmodulesRecursively = true
}

override def root = T.source(protobufGit.repo())
override def root = T.source(protobufGit.repo())

override def jobs = T {
2
}
override def jobs = T {
2
}

override def cMakeBuild: T[PathRef] = T {
os.proc("cmake", "-B", T.dest, "-Dprotobuf_BUILD_TESTS=OFF", "-DABSL_PROPAGATE_CXX_STD=ON", "-S", root().path).call(cwd = T.dest)
os.proc("make", "-j", jobs(), "all").call(cwd = T.dest)
PathRef(T.dest)
}
override def cMakeBuild: T[PathRef] = T {
os.proc("cmake", "-B", T.dest, "-Dprotobuf_BUILD_TESTS=OFF", "-DABSL_PROPAGATE_CXX_STD=ON", "-S", root().path).call(cwd = T.dest)
os.proc("make", "-j", jobs(), "all").call(cwd = T.dest)
PathRef(T.dest)
}

object libprotobuf extends CMakeLibrary {
def target = T {
"libprotobuf"
}
object libprotobuf extends CMakeLibrary {
def target = T {
"libprotobuf"
}
}

object protoc extends CMakeExecutable {
def target = T {
"protoc"
}
object protoc extends CMakeExecutable {
def target = T {
"protoc"
}
}
}

object proto extends CppModule {
def protoPath = T.sources(
vercors.col.helpers.megacol().path / os.up / os.up / os.up / os.up,
settings.src / "serialize",
Expand Down Expand Up @@ -801,8 +800,45 @@ object vercors extends Module {
Seq(PathRef(generate()))
}

override def unixToolchain = GccCompatible("g++", "ar")
def precompileHeaders: T[PathRef] = T {
def isHiddenFile(path: os.Path): Boolean = path.last.startsWith(".")

val headers = for {
root <- allSources()
if os.exists(root.path)
path <- if(os.isDir(root.path)) os.walk(root.path) else Seq(root.path)
if os.isFile(path)
if !isHiddenFile(path)
if Seq("h", "hpp").contains(path.ext.toLowerCase)
} yield (root.path, path.relativeTo(root.path))

val options = CppCompileOptions(
allIncludePaths().map(_.path),
defines(),
includes().map(_.path),
standard(),
optimization(),
compileOptions(),
compileEarlyOptions(),
)

for((base, header) <- headers) {
val compileOut = toolchain.compile(base / header, T.dest, options)
val outDir = T.dest / header / os.up
val out = outDir / (header.last + ".gch")
os.makeDir.all(outDir)
os.move(compileOut, out)
os.copy(base / header, T.dest / header)
}

PathRef(T.dest)
}

override def exportIncludePaths: T[Seq[PathRef]] = T {
Seq(precompileHeaders())
}

override def unixToolchain = GccCompatible("g++", "ar")
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/archive/known-problems/791/zero_mixed_array_2.pvl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ZeroMixedArray {
context_everywhere ar.length == M * N;
context (\forall* int i;0 <= i && i < M*N ; Perm(ar[i],write));
ensures (\forall int i;0 <= i && i < M*N ; ar[i]==0);
void vector(int M, int N, int[M*N] ar) {
void vectorZero(int M, int N, int[M*N] ar) {
par outer (int i = 0 .. M)
context (\forall* int k; N*i <= k && k < N*(i+1) ; Perm(ar[k],write));
ensures (\forall int k; N*i <= k && k < N*(i+1) ; ar[k]==0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ pure boolean property2(seq<int> xs, seq<int> ys) =
class OddPhase {
////////////////////////////////////////////////////////////////////////////////////////Lemmas
requires |xs| == |ys|;
requires (\forall int i; i>=0 && i<|xs|/2 && 2*i+1<|xs|; xs[2*i] <= xs[2*i+1]);
requires (\forall int i; i>=0 && i<|ys|/2 && 2*i+2<|ys|; ys[2*i+1] <= ys[2*i+2]);
requires (\forall int i; i>=0 && i<|xs|; xs[i] == ys[i]);
ensures (\forall int i; i>=0 && i<|ys|/2 && 2*i+2<|ys|; ys[2*i] <= ys[2*i+1] && ys[2*i+1] <= ys[2*i+2]);
requires (\forall int i; i>=0 && i < |xs|/2 && 2*i+1 < |xs|; xs[2*i] <= xs[2*i+1]);
requires (\forall int i; i>=0 && i < |ys|/2 && 2*i+2 < |ys|; ys[2*i+1] <= ys[2*i+2]);
requires (\forall int i; i>=0 && i < |xs|; xs[i] == {: ys[i] :});
ensures (\forall int i; i>=0 && i < |ys|/2 && 2*i+2 < |ys|; ys[2*i] <= ys[2*i+1] && ys[2*i+1] <= ys[2*i+2]);
void lemma_concat(seq<int> xs, seq<int> ys){

}
Expand Down Expand Up @@ -147,7 +147,7 @@ class OddPhase {
int k = 0;

loop_invariant 0 <= k && k <= |xs|;
loop_invariant (\forall int l; l>=0 && l<k; counter(xs + ys, xs[l]) == counter(xs, xs[l]) + counter(ys, xs[l]));
loop_invariant (\forall int l; l>=0 && l<k; {: counter(xs + ys, xs[l]) :} == counter(xs, xs[l]) + counter(ys, xs[l]));
while(k < |xs|)
{
lemma_count_app(xs, ys, xs[k]);
Expand Down Expand Up @@ -215,7 +215,7 @@ class OddPhase {
int k = 0;

loop_invariant 0 <= k && k <= |xs|;
loop_invariant (\forall int l; l>=0 && l<k; counter(xs, xs[l]) == counter(ys, xs[l]));
loop_invariant (\forall int l; l>=0 && l<k; {: counter(xs, xs[l]) :} == counter(ys, xs[l]));
while(k < |xs|)
{
lemma_swap_permutation(xs, ys, i, j, xs[k]);
Expand Down Expand Up @@ -282,9 +282,11 @@ class OddPhase {
requires isSorted[0] ==> (\forall int j; j >= 0 && j < |inp_seq_cur|; inp_seq_all[loopCounter[0]][j] == inp_seq_cur[j]);
context isApermutation(inp_seq_all[0], inp_seq_cur);
ensures (\forall int i; 0 <= i && i < contrib.length/2 && 2*i+1 < contrib.length; contrib[2*i+1] == 1);
ensures (\forall int i; 0 <= i && i < |inp_seq_all[loopCounter[0]+1]|/2 && 2*i+2 < |inp_seq_all[loopCounter[0]+1]|;
inp_seq_all[loopCounter[0]+1][2*i+1] <= inp_seq_all[loopCounter[0]+1][2*i+2]) ==>
(\forall int i; 0 <= i && i < |inp_seq_all[loopCounter[0]+1]|; inp_seq_cur[i] == inp_seq_all[loopCounter[0]+1][i]);
ensures (\let int loopCounter0succ = loopCounter[0] + 1;
(\forall int i; 0 <= i && i < |inp_seq_all[loopCounter[0]+1]|/2 && 2*i+2 < |inp_seq_all[loopCounter[0]+1]|;
inp_seq_all[loopCounter0succ][2*i+1] <= inp_seq_all[loopCounter[0]+1][2*i+2]) ==>
(\forall int i; 0 <= i && i < |inp_seq_all[loopCounter[0]+1]|; inp_seq_cur[i] == inp_seq_all[loopCounter0succ][i])
);
ensures (\forall int i; 0 <= i && i < input.length/2 && 2*i+2 < input.length; input[2*i+1] <= input[2*i+2]);
ensures (\forall int i; 0 <= i && i < |inp_seq_all[loopCounter[0]+1]|/2 && 2*i+2 < |inp_seq_all[loopCounter[0]+1]|;
((inp_seq_all[loopCounter[0]+1][2*i+1] > inp_seq_all[loopCounter[0]+1][2*i+2]) ==>
Expand All @@ -306,12 +308,13 @@ class OddPhase {
(\forall int i; 0 <= i && i < loopCounter[0]+2; input.length == |inp_seq_all[i]|) **
(\forall* int i; 0 <= i && i < contrib.length; Perm(contrib[i], 1\2)) **
(\forall* int i; 0 <= i && i < input.length; Perm(input[i], write)) **
(\forall int i; 0 <= i && i < input.length; {: input[i] :} == {: inp_seq_cur[i] :}) **
(\forall int i; 0 <= i && i < input.length; input[i] == inp_seq_cur[i]) **

isApermutation(inp_seq_all[0], inp_seq_cur) **

((\forall int i; 0 <= i && i < (contrib.length); {: contrib[i] :} == 0) ==>
(\forall int j; j >= 0 && j < |inp_seq_cur|; inp_seq_all[loopCounter[0]+1][j] == {: inp_seq_cur[j] :})) **
((\forall int i; 0 <= i && i < (contrib.length); contrib[i] == 0) ==>
(\let int loopCounter0succ = loopCounter[0] + 1;
(\forall int j; j >= 0 && j < |inp_seq_cur|; inp_seq_all[loopCounter0succ][j] == inp_seq_cur[j]))) **

property2(inp_seq_cur, inp_seq_all[loopCounter[0]+1]) **

Expand All @@ -321,9 +324,11 @@ class OddPhase {
((inp_seq_all[loopCounter[0]+1][2*i+1] > inp_seq_all[loopCounter[0]+1][2*i+2] && contrib[2*i+1] == 0) ==>
(inp_seq_cur[2*i+1] == inp_seq_all[loopCounter[0]+1][2*i+1] && inp_seq_cur[2*i+2] == inp_seq_all[loopCounter[0]+1][2*i+2]))) **

(\forall int i; 0 <= i && i < |inp_seq_all[loopCounter[0]+1]|/2 && 2*i+2 < |inp_seq_all[loopCounter[0]+1]|;
((inp_seq_all[loopCounter[0]+1][2*i+1] > inp_seq_all[loopCounter[0]+1][2*i+2] && contrib[2*i+1] == 1) ==>
(inp_seq_cur[2*i+1] == inp_seq_all[loopCounter[0]+1][2*i+2] && inp_seq_cur[2*i+2] == inp_seq_all[loopCounter[0]+1][2*i+1]))) **
(\let int loopCounter0succ = loopCounter[0] + 1;
(\forall int i; 0 <= i && i < |inp_seq_all[loopCounter[0]+1]|/2 && 2*i+2 < |inp_seq_all[loopCounter[0]+1]|;
((inp_seq_all[loopCounter[0]+1][2*i+1] > inp_seq_all[loopCounter[0]+1][2*i+2] && contrib[2*i+1] == 1) ==>
(inp_seq_cur[2*i+1] == inp_seq_all[loopCounter0succ][2*i+2] && inp_seq_cur[2*i+2] == inp_seq_all[loopCounter0succ][2*i+1])))
) **

property1(inp_seq_cur, inp_seq_all[loopCounter[0]+1]) **

Expand Down
69 changes: 69 additions & 0 deletions examples/concepts/c/vector_add.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Compile with
// gcc -mavx -o vector_add vector_add.c

#include <assert.h>
#include <immintrin.h>
#include <stdbool.h>

/*@
context_everywhere n >= 0 && n % 4 == 0;
context_everywhere a != NULL && \pointer_length(a) >= n;
context_everywhere b != NULL && \pointer_length(b) >= n;
context_everywhere c != NULL && \pointer_length(c) >= n;
context_everywhere (\forall* int i; 0<=i && i<n; Perm(&a[i], 1\2));
context_everywhere (\forall* int i; 0<=i && i<n; Perm(&b[i], 1\2));
context_everywhere (\forall* int i; 0<=i && i<n; Perm(&c[i], write));
ensures (\forall int j; 0 <= j && j<n; {:c[j]:} == a[j] + b[j]);
@*/
void vector_add(int *a, int *b, int *c, int n){
/*@
loop_invariant 0<=i && i<=n && i%4 == 0;
loop_invariant (\forall int j; 0 <= j && j<i; {:c[j]:} == a[j] + b[j]);
@*/
for(int i = 0; i < n; i+=4){
// Normally this should be:
// a4 = _mm_load_si128((__m128i*)(a + i));
// _mm_load_si128
// But then we need good support for casting between pointers.
__v4si a4 = {a[i], a[i+1], a[i+2], a[i+3]};
__v4si b4 = {b[i], b[i+1], b[i+2], b[i+3]};
__v4si c4 = a4 + b4;
__v4si d4 = a4 == b4;
// _mm_store_si128(c+i, c4);
c[i] = c4[0];
c[i+1] = c4[1];
c[i+2] = c4[2];
c[i+3] = c4[3];
}
}


int main(){

int a[4*100];
int b[4*100];
/*@
loop_invariant 0<=i && i<=4*100;
loop_invariant (\forall* int j; 0 <= j && j<4*100; Perm(&a[j],write));
loop_invariant (\forall* int j; 0 <= j && j<4*100; Perm(&b[j],write));
loop_invariant (\forall int j; 0 <= j && j<i; a[j] == j);
loop_invariant (\forall int j; 0 <= j && j<i; b[j] == 400-j);
@*/
for(int i = 0; i < 4*100; i++){
a[i] = i;
b[i] = 400-i;
}
int c[4*100];
vector_add(a, b, c, 4*100);
//@ assert((\forall int j; 0 <= j && j<4*100; c[j] == 400));
/*@
loop_invariant 0<=i && i<=4*100;
loop_invariant (\forall* int j; 0 <= j && j<4*100; Perm(&c[j],write));
loop_invariant (\forall int j; 0 <= j && j<4*100; c[j] == 400);
@*/
for(int i=0; i<4*100; i++){
assert(c[i] == 400);
}

return 0;
}
Loading

0 comments on commit 0aca156

Please sign in to comment.