Skip to content

Commit

Permalink
Merge branch 'develop' into connected
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltoli authored Mar 25, 2024
2 parents 84e574d + 9b12fe8 commit d4f0490
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 14 deletions.
2 changes: 1 addition & 1 deletion deps/hs-backend-booster_release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
36d54e028bd6c5720063ae562758bd7e4848f00d
88ffab54a7266d8c98d5c039ef81143d1d24f3f0
8 changes: 4 additions & 4 deletions flake.lock

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

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
inputs = {
haskell-backend.url = "github:runtimeverification/haskell-backend/093af3153a5e07626d9b2e628d7ad4fc77c5a723";
booster-backend = {
url = "github:runtimeverification/hs-backend-booster/36d54e028bd6c5720063ae562758bd7e4848f00d";
url = "github:runtimeverification/hs-backend-booster/88ffab54a7266d8c98d5c039ef81143d1d24f3f0";
inputs.nixpkgs.follows = "haskell-backend/nixpkgs";
inputs.haskell-backend.follows = "haskell-backend";
inputs.stacklock2nix.follows = "haskell-backend/stacklock2nix";
Expand Down
1 change: 1 addition & 0 deletions k-distribution/tests/regression-new/total-proj/1.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo()
3 changes: 3 additions & 0 deletions k-distribution/tests/regression-new/total-proj/1.test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<k>
false ~> .K
</k>
6 changes: 6 additions & 0 deletions k-distribution/tests/regression-new/total-proj/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DEF=test
EXT=test
TESTDIR=.
KOMPILE_BACKEND=haskell

include ../../../include/kframework/ktest.mak
15 changes: 15 additions & 0 deletions k-distribution/tests/regression-new/total-proj/test.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module TEST
imports INT
imports BOOL
imports LIST

configuration <k> $PGM:Pgm </k>

syntax Pgm ::= foo() | Pgm2
syntax Pgm2 ::= bar(baz: Int)

rule foo() => ?X:Pgm2
rule X:Pgm2 => baz(X)
rule I:Int => false

endmodule
16 changes: 11 additions & 5 deletions kernel/src/main/java/org/kframework/backend/kore/KoreBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,12 @@ public Function<Definition, Definition> steps() {
DefinitionTransformer generateSortPredicateRules =
DefinitionTransformer.from(
new GenerateSortPredicateRules()::gen, "adding sort predicate rules");
DefinitionTransformer generateSortProjections =
DefinitionTransformer.from(
new GenerateSortProjections(kompileOptions.coverage)::gen, "adding sort projections");
Function1<Definition, Definition> generateSortProjections =
d ->
DefinitionTransformer.from(
new GenerateSortProjections(kompileOptions.coverage, d.mainModule())::gen,
"adding sort projections")
.apply(d);
DefinitionTransformer subsortKItem =
DefinitionTransformer.from(Kompile::subsortKItem, "subsort all sorts to KItem");
Function1<Definition, Definition> addCoolLikeAtt =
Expand Down Expand Up @@ -377,8 +380,11 @@ public Function<Module, Module> specificationSteps(Definition def) {
ModuleTransformer.fromSentenceTransformer(
new ConcretizeCells(configInfo, labelInfo, sortInfo, mod)::concretize,
"concretizing configuration");
ModuleTransformer generateSortProjections =
ModuleTransformer.from(new GenerateSortProjections(false)::gen, "adding sort projections");
Function1<Module, Module> generateSortProjections =
m ->
ModuleTransformer.from(
new GenerateSortProjections(false, m)::gen, "adding sort projections")
.apply(m);

return m ->
resolveComm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
public class GenerateSortProjections {

private Module mod;
private final Module mainMod;
private final boolean cover;

public GenerateSortProjections(boolean cover) {
public GenerateSortProjections(boolean cover, Module mainMod) {
this.mainMod = mainMod;
this.cover = cover;
}

public GenerateSortProjections(Module mod) {
this.mainMod = null;
this.mod = mod;
this.cover = false;
}
Expand Down Expand Up @@ -133,13 +136,30 @@ public Stream<? extends Sentence> gen(Production prod) {
if (!hasName) {
return Stream.empty();
}
boolean total = false;
if (mainMod != null) {
if (stream(
mainMod
.productionsForSort()
.get(prod.sort().head())
.getOrElse(() -> Collections.<Production>Set()))
.filter(p -> !p.att().contains(Att.FUNCTION()))
.count()
== 1) {
total = true;
}
}
i = 0;
for (NonTerminal nt : iterable(prod.nonterminals())) {
if (nt.name().isDefined()) {
KLabel lbl = getProjectLbl(prod.klabel().get().name(), nt.name().get());
if (mod.definedKLabels().contains(lbl)) {
return Stream.empty();
}
Att att = Att.empty().add(Att.FUNCTION());
if (total) {
att = att.add(Att.TOTAL());
}
sentences.add(
Production(
lbl,
Expand All @@ -149,7 +169,7 @@ public Stream<? extends Sentence> gen(Production prod) {
Terminal("("),
NonTerminal(prod.sort()),
Terminal(")")),
Att.empty().add(Att.FUNCTION())));
att));
sentences.add(
Rule(
KRewrite(KApply(lbl, KApply(prod.klabel().get(), KList(vars))), vars.get(i)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
import org.kframework.definition.Sentence;
import org.kframework.kore.*;

/**
* MinimizeTermConstruction.
*
* <p>Looks for places where #as patterns can be used to reduce the number of constructors in
* rewrites:
*
* <p>`P1 => P2[P1]` -> `P1 #as X => P2[X]`
*/
public class MinimizeTermConstruction {

private final Set<KVariable> vars = new HashSet<>();
Expand Down

0 comments on commit d4f0490

Please sign in to comment.