Skip to content

Commit

Permalink
Merge branch 'develop' into nailgun-location
Browse files Browse the repository at this point in the history
  • Loading branch information
rv-jenkins authored Nov 29, 2023
2 parents ab46e70 + 4d8cbf9 commit 8efffb2
Show file tree
Hide file tree
Showing 17 changed files with 164 additions and 82 deletions.
2 changes: 1 addition & 1 deletion deps/hs-backend-booster_release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ac35589bb31831b346e143bfa98c51e670237b8e
c289a1a29575f9e5156fae75fb34e1c97cfffd02
22 changes: 11 additions & 11 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
description = "K Framework";
inputs = {
haskell-backend.url = "github:runtimeverification/haskell-backend/eebe4e9fd9dd6c606b37a384dbbfecca85943a38";
haskell-backend.url = "github:runtimeverification/haskell-backend/b2bade8ce62e5f3add32d87e98244ceb31790f9f";
booster-backend = {
url = "github:runtimeverification/hs-backend-booster/ac35589bb31831b346e143bfa98c51e670237b8e";
url = "github:runtimeverification/hs-backend-booster/c289a1a29575f9e5156fae75fb34e1c97cfffd02";
inputs.nixpkgs.follows = "haskell-backend/nixpkgs";
inputs.haskell-backend.follows = "haskell-backend";
inputs.stacklock2nix.follows = "haskell-backend/stacklock2nix";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,12 @@ private RewriterResult executeKoreCommands(
public RewriterResult prove(Module rules, Boolean reuseDef) {
Module kompiledModule = KoreBackend.getKompiledModule(module, true);
ModuleToKORE converter =
new ModuleToKORE(kompiledModule, def.topCellInitializer, kompileOptions, kem);
new ModuleToKORE(
kompiledModule,
def.topCellInitializer,
kompileOptions,
kem,
kProveOptions.allowFuncClaims);
String defPath =
reuseDef
? files.resolveKompiled("definition.kore").getAbsolutePath()
Expand Down
2 changes: 1 addition & 1 deletion haskell-backend/src/main/native/haskell-backend
Submodule haskell-backend updated 28 files
+19 −1 docs/2022-07-18-JSON-RPC-Server-API.md
+1 −0 kore-rpc-types/src/Kore/JsonRpc/Types.hs
+24 −7 kore/src/Kore/JsonRpc.hs
+2 −22 kore/src/Kore/Log/DecidePredicateUnknown.hs
+6 −3 kore/src/Kore/Rewrite/SMT/Lemma.hs
+16 −0 kore/src/SMT.hs
+90 −71 scripts/generate-regression-tests.sh
+23,713 −12,316 test/regression-evm/test-dsvalue-peek-pass-rough-definition.kore
+6 −6 test/regression-evm/test-dsvalue-peek-pass-rough-spec.kore
+5 −2 test/regression-evm/test-dsvalue-peek-pass-rough.sh
+23,713 −12,316 test/regression-evm/test-flipper-addu48u48-fail-rough-definition.kore
+7 −7 test/regression-evm/test-flipper-addu48u48-fail-rough-spec.kore
+5 −2 test/regression-evm/test-flipper-addu48u48-fail-rough.sh
+23,583 −12,019 test/regression-evm/test-functional-definition.kore
+134 −111 test/regression-evm/test-functional-spec.kore
+5 −2 test/regression-evm/test-functional.sh
+23,394 −11,854 test/regression-evm/test-lemmas-definition.kore
+1,293 −721 test/regression-evm/test-lemmas-spec.kore
+5 −2 test/regression-evm/test-lemmas.sh
+23,580 −12,016 test/regression-evm/test-storagevar03-definition.kore
+6 −6 test/regression-evm/test-storagevar03-spec.kore
+5 −2 test/regression-evm/test-storagevar03.sh
+8,338 −6,722 test/regression-evm/test-sum-to-n-definition.kore
+12 −10 test/regression-evm/test-sum-to-n-spec.kore
+5 −2 test/regression-evm/test-sum-to-n.sh
+23,390 −11,850 test/regression-evm/test-totalSupply-definition.kore
+6 −6 test/regression-evm/test-totalSupply-spec.kore
+5 −2 test/regression-evm/test-totalSupply.sh
2 changes: 1 addition & 1 deletion hs-backend-booster/src/main/native/hs-backend-booster
Submodule hs-backend-booster updated 44 files
+2 −1 .gitignore
+1 −1 cabal.project
+1 −1 deps/haskell-backend_release
+1 −1 deps/k_release
+4 −4 flake.lock
+15 −2 flake.nix
+1 −13 library/Booster/Definition/Base.hs
+0 −8 library/Booster/Definition/Util.hs
+58 −33 library/Booster/JsonRpc.hs
+18 −18 library/Booster/JsonRpc/Utils.hs
+82 −44 library/Booster/Pattern/ApplyEquations.hs
+58 −80 library/Booster/Pattern/Base.hs
+20 −46 library/Booster/Pattern/Binary.hs
+133 −0 library/Booster/Pattern/Bool.hs
+1 −14 library/Booster/Pattern/Index.hs
+7 −86 library/Booster/Pattern/Match.hs
+9 −7 library/Booster/Pattern/Rewrite.hs
+0 −21 library/Booster/Pattern/Simplify.hs
+21 −29 library/Booster/Pattern/Util.hs
+39 −70 library/Booster/Syntax/Json/Externalise.hs
+60 −56 library/Booster/Syntax/Json/Internalise.hs
+119 −131 library/Booster/Syntax/ParsedKore/Internalise.hs
+3 −0 package.yaml
+21 −8 scripts/compare.py
+13 −7 scripts/performance-tests-kevm.sh
+18 −10 scripts/performance-tests-kontrol.sh
+1 −1 stack.yaml
+6 −6 stack.yaml.lock
+12 −0 stacklock2nix.patch
+0 −10 test/internalisation/bool.kore.report
+0 −2 test/internalisation/does-not-preserve-definedness.kore.report
+0 −2 test/internalisation/existentials.kore.report
+0 −33 test/internalisation/imp.kore.report
+0 −2 test/internalisation/preserves-definedness-total-function.kore.report
+0 −2 test/internalisation/preserves-definedness.kore.report
+0 −11 test/internalisation/subsorts.kore.report
+0 −44 test/internalisation/test-totalSupply-definition.kore.report
+57 −3 test/llvm-integration/LLVM.hs
+43 −0 test/llvm-integration/definition/llvm.k
+2 −2 tools/booster/Proxy.hs
+12 −5 unit-tests/Test/Booster/Fixture.hs
+44 −14 unit-tests/Test/Booster/Pattern/ApplyEquations.hs
+4 −16 unit-tests/Test/Booster/Pattern/Binary.hs
+19 −22 unit-tests/Test/Booster/Pattern/Rewrite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module A4-SPEC
import TEST
imports ML-SYNTAX

claim c => 2 #And {3 #Equals n}
claim <k> c => 2 #And {3 #Equals n} </k>
rule {n #Equals 3} => #Top [simplification, comm] // the comm attribute is stripped because it has a different meaning in the backend
// rule {3 #Equals n} => #Top [simplification] // should be generated by the above
endmodule
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module A5-SPEC
import TEST
imports ML-SYNTAX

claim c => 2 #And n +Int n
claim <k> c => 2 #And n +Int n </k>
rule n +Int n => #Top [simplification, comm]
// the comm attribute is stripped because it has a different meaning in the backend
// even if comm, the body is identical so we don't generate anything extra
Expand Down
34 changes: 22 additions & 12 deletions kernel/src/main/java/org/kframework/backend/kore/ModuleToKORE.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,22 @@ public enum SentenceType {
private final Set<String> mlBinders = new HashSet<>();
private final KompileOptions options;

// for now these two variables are coupled to enable the functional claim check
private final KExceptionManager kem;
private final boolean allowFuncClaims;

public ModuleToKORE(Module module, KLabel topCellInitializer, KompileOptions options) {
this(module, topCellInitializer, options, null);
this(module, topCellInitializer, options, null, false);
}

public ModuleToKORE(
Module module, KLabel topCellInitializer, KompileOptions options, KExceptionManager kem) {
Module module,
KLabel topCellInitializer,
KompileOptions options,
KExceptionManager kem,
boolean allowFuncClaims) {
this.kem = kem;
this.allowFuncClaims = allowFuncClaims;
this.module = module;
this.addSortInjections = new AddSortInjections(module);
this.topCellInitializer = topCellInitializer;
Expand Down Expand Up @@ -1057,6 +1064,9 @@ private RuleInfo getRuleInfo(RuleOrClaim rule, boolean heatCoolEq, String topCel
productionSortStr = topCellSortStr;
}
owise = rule.att().contains(Att.OWISE());
} else if (leftPattern instanceof KToken kt) {
productionSort = kt.sort();
productionSortStr = getSortStr(productionSort);
}

return new RuleInfo(
Expand Down Expand Up @@ -1107,7 +1117,7 @@ private void convertRule(
assertNoExistentials(rule, existentials);
if (rule instanceof Claim) {
sb.append(" claim{R");
if (kem != null) // TODO: remove once
if (!allowFuncClaims) // TODO: remove once
// https://github.com/runtimeverification/haskell-backend/issues/3010 is
// implemented
kem.registerCompilerWarning(
Expand Down Expand Up @@ -1348,38 +1358,38 @@ private void convertRule(
} else {
// LHS for claims
sb.append(" claim{} ");
sb.append(String.format("\\implies{%s} (\n ", topCellSortStr));
sb.append(String.format(" \\and{%s} (\n ", topCellSortStr));
convertSideCondition(requires, topCellSortStr, sb);
sb.append(String.format("\\implies{%s} (\n ", ruleInfo.productionSortStr));
sb.append(String.format(" \\and{%s} (\n ", ruleInfo.productionSortStr));
convertSideCondition(requires, ruleInfo.productionSortStr, sb);
sb.append(", ");
convert(left, sb);
sb.append("), ");
}

// generate rule RHS
if (sentenceType == SentenceType.ALL_PATH) {
sb.append(String.format("%s{%s} (\n ", ALL_PATH_OP, topCellSortStr));
sb.append(String.format("%s{%s} (\n ", ALL_PATH_OP, ruleInfo.productionSortStr));
} else if (sentenceType == SentenceType.ONE_PATH) {
sb.append(String.format("%s{%s} (\n ", ONE_PATH_OP, topCellSortStr));
sb.append(String.format("%s{%s} (\n ", ONE_PATH_OP, ruleInfo.productionSortStr));
}
if (!existentials.isEmpty()) {
for (KVariable exists : existentials) {
sb.append(String.format(" \\exists{%s} (", topCellSortStr));
sb.append(String.format(" \\exists{%s} (", ruleInfo.productionSortStr));
convert((K) exists, sb);
sb.append(", ");
}
sb.append("\n ");
}
sb.append(String.format("\\and{%s} (\n ", topCellSortStr));
sb.append(String.format("\\and{%s} (\n ", ruleInfo.productionSortStr));

if (options.enableKoreAntileft) {
convertSideCondition(ensures, topCellSortStr, sb);
convertSideCondition(ensures, ruleInfo.productionSortStr, sb);
sb.append(", ");
convert(right, sb);
} else {
convert(right, sb);
sb.append(", ");
convertSideCondition(ensures, topCellSortStr, sb);
convertSideCondition(ensures, ruleInfo.productionSortStr, sb);
}

sb.append(')');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private boolean skipSentence(Sentence s) {
// cell mentioned is the automatically-added <generatedCounter> cell.
private boolean shouldConsider(List<K> items, boolean isClaim) {
if (items.size() == 1) {
return true;
return !isClaim;
} else if (items.size() == 2 && isClaim) {
K second = items.get(1);
if (second instanceof KApply app) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ public AddImplicitCounterCell() {}

public Sentence apply(Module m, Sentence s) {
if (s instanceof Claim claim) {
Set<KVariable> freshVars = new HashSet<>();
VisitK visitor =
new VisitK() {
@Override
public void apply(KVariable var) {
if (ResolveFreshConstants.isFreshVar(var)) freshVars.add(var);
}
};
visitor.apply(claim.body());
visitor.apply(claim.requires());
visitor.apply(claim.ensures());
// do not add <generatedCounter> if the claim doesn't contain cells or fresh vars
if (!ConcretizeCells.hasCells(claim.body()) && freshVars.isEmpty()) {
return s;
}
return claim.newInstance(
apply(claim.body(), m), claim.requires(), claim.ensures(), claim.att());
}
Expand Down
23 changes: 23 additions & 0 deletions kernel/src/main/java/org/kframework/compile/ConcretizeCells.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// Copyright (c) K Team. All Rights Reserved.
package org.kframework.compile;

import java.util.stream.Stream;
import org.kframework.attributes.Att;
import org.kframework.definition.*;
import org.kframework.definition.Module;
import org.kframework.kore.K;
import org.kframework.kore.KRewrite;

/**
* Apply the configuration concretization process. The implicit {@code <k>} cell is added by another
Expand Down Expand Up @@ -60,6 +64,9 @@ public ConcretizeCells(
}

public Sentence concretize(Module m, Sentence s) {
if (s instanceof Claim c && !hasCells(c.body())) {
return s;
}
s = addRootCell.addImplicitCells(s, m);
s = addParentCells.concretize(s);
s = closeCells.close(s);
Expand All @@ -69,4 +76,20 @@ public Sentence concretize(Module m, Sentence s) {
s = sortCells.postprocess(s);
return s;
}

public static boolean hasCells(K item) {
if (IncompleteCellUtils.flattenCells(item).stream()
.anyMatch(k -> k.att().get(Production.class).att().contains(Att.CELL()))) {
return true;
}

if (item instanceof KRewrite rew) {
return Stream.concat(
IncompleteCellUtils.flattenCells(rew.left()).stream(),
IncompleteCellUtils.flattenCells(rew.right()).stream())
.anyMatch(ConcretizeCells::hasCells);
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,15 @@ private Rule resolve(Rule rule) {
return withFresh;
}

public static boolean isFreshVar(KVariable kvar) {
return kvar.name().startsWith("!");
}

private void analyze(K term) {
new VisitK() {
@Override
public void apply(KVariable k) {
if (k.name().startsWith("!")) {
if (isFreshVar(k)) {
freshVars.add(k);
}
super.apply(k);
Expand Down
6 changes: 6 additions & 0 deletions kernel/src/main/java/org/kframework/kprove/KProveOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@ public synchronized File specFile(FileUtil files) {
descriptionKey = "file",
description = "If set, emit the JSON serialization of the spec module to the specified file.")
public String emitJsonSpec = null;

@Parameter(
names = "--allow-func-claims",
description = "Allow functional claims to be printed in kore format. Use with --dry-run.",
hidden = true)
public boolean allowFuncClaims = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public enum Status {
private final boolean debug;
private final Module mod;
private final java.util.Set<SortHead> sorts;
private final Map<ProductionReference, Integer> prIds = new IdentityHashMap<>();

// logic QF_DT is best if it exists as it will be faster than ALL. However, some z3 versions do
// not have this logic.
Expand Down Expand Up @@ -593,15 +594,15 @@ public String apply(Term t) {
boolean isTopSort =
expectedSort.equals(Sorts.RuleContent()) || expectedSort.name().equals("#RuleBody");
int id = nextId;
boolean shared = pr.id().isPresent() && variablesById.size() > pr.id().get();
boolean shared = prIds.containsKey(pr) && variablesById.size() > prIds.get(pr);
if (!shared) {
// if this is the first time reaching this term, initialize data structures with the
// variables associated with
// this term.
nextId++;
variablesById.add(new ArrayList<>());
cacheById.add(new HashSet<>());
pr.setId(Optional.of(id));
prIds.put(pr, id);
for (Sort param : iterable(pr.production().params())) {
String name = "FreshVar" + param.name() + locStr(pr);
if (!variables.contains(name)) {
Expand All @@ -612,7 +613,7 @@ public String apply(Term t) {
}
} else {
// get cached id
id = pr.id().get();
id = prIds.get(pr);
}
if (pr instanceof TermCons tc) {
boolean wasStrict = isStrictEquality;
Expand Down Expand Up @@ -682,7 +683,7 @@ public String apply(Term t) {
nextId++;
variablesById.add(new ArrayList<>());
cacheById.add(new HashSet<>());
pr.setId(Optional.of(id));
prIds.put(pr, id);
if (isAnonVar(c)) {
name = "Var" + c.value() + locStr(c);
isStrictEquality = true;
Expand Down Expand Up @@ -799,7 +800,7 @@ private String printSort(Sort s, Optional<ProductionReference> t, boolean isIncr
Map<Sort, String> params = new HashMap<>();
if (t.isPresent()) {
if (t.get().production().params().nonEmpty()) {
int id = t.get().id().get();
int id = prIds.get(t.get());
List<String> names = variablesById.get(id);
Seq<Sort> formalParams = t.get().production().params();
assert (names.size() == formalParams.size());
Expand Down Expand Up @@ -945,8 +946,8 @@ void pushNotModel() {
}

public Seq<Sort> getArgs(ProductionReference pr) {
if (pr.id().isPresent()) {
int id = pr.id().get();
if (prIds.containsKey(pr)) {
int id = prIds.get(pr);
List<String> names = variablesById.get(id);
return names.stream().map(this::getValue).collect(Collections.toList());
} else {
Expand Down Expand Up @@ -1023,7 +1024,7 @@ private void reset() {
}
}

private static String locStr(ProductionReference pr) {
private String locStr(ProductionReference pr) {
String suffix = "";
if (pr.production().klabel().isDefined()) {
suffix = "_" + pr.production().klabel().get().name().replace("|", "");
Expand All @@ -1040,7 +1041,7 @@ private static String locStr(ProductionReference pr) {
+ l.endColumn()
+ suffix;
}
return pr.id().get() + suffix;
return prIds.get(pr) + suffix;
}

private StringBuilder sb = new StringBuilder();
Expand Down
Loading

0 comments on commit 8efffb2

Please sign in to comment.