Skip to content

Commit b61559a

Browse files
author
dwightguth
authored
Fixes for anywhere rules and strategies (runtimeverification#216)
* remove StrategyApply and StrategyApplied sorts * support anywhere rules * fix parse error
1 parent 9718a99 commit b61559a

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

k-distribution/include/builtin/domains.k

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,11 +1299,9 @@ module STRATEGY
12991299
13001300
syntax Strategy ::= #STUCK() [symbol]
13011301
1302-
syntax StrategyApply ::= "^" #RuleTag [klabel(#applyRule), symbol]
1302+
syntax Strategy ::= "^" #RuleTag [klabel(#applyRule), symbol]
13031303
1304-
syntax StrategyApplied ::= "~" #RuleTag [klabel(#appliedRule), symbol]
1305-
1306-
syntax Strategy ::= StrategyApply | StrategyApplied
1304+
syntax Strategy ::= "~" #RuleTag [klabel(#appliedRule), symbol]
13071305
13081306
configuration <s> $STRATEGY:K </s>
13091307
endmodule
@@ -1360,8 +1358,8 @@ module BASIC-STRATEGY
13601358
13611359
rule <s> true ~> #FROZEN(CONFIGURATION:K) => true ...</s>
13621360
1363-
// rule <s> #STUCK ~> X:StrategyApply => false ...</s>
1364-
rule <s> X:StrategyApplied => true ...</s>
1361+
// rule <s> #STUCK ~> #applyRule(_) => false ...</s>
1362+
rule <s> #appliedRule(_) => true ...</s>
13651363
13661364
rule <s> A:Strategy ; B:Strategy => A ~> #SHOLE ; B ...</s> when notBool(isBool(A))
13671365
@@ -1372,7 +1370,7 @@ module BASIC-STRATEGY
13721370
rule <s> false ; B:Strategy => false ...</s>
13731371
13741372
// the second rule is stupid -- just made to sidestep what is likely a KSEQ normalization bug
1375-
rule <s> #STUCK() ~> A:StrategyApply => false ...</s>
1373+
rule <s> #STUCK() ~> #applyRule(_) => false ...</s>
13761374
rule <s> #STUCK() ~> false => false ...</s>
13771375
13781376
endmodule

kernel/src/main/java/org/kframework/backend/kore/ModuleToKORE.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public String convert(boolean heatCoolEq) {
141141
if (left instanceof KApply) {
142142
KApply kapp = (KApply) left;
143143
Production prod = production(kapp);
144-
if (prod.att().contains(Attribute.FUNCTION_KEY)) {
144+
if (prod.att().contains(Attribute.FUNCTION_KEY) || rule.att().contains(Attribute.ANYWHERE_KEY)) {
145145
functionRules.put(kapp.klabel(), rule);
146146
}
147147
}
@@ -571,7 +571,7 @@ private void convertRule(Rule rule, boolean heatCoolEq, Sort topCellSort, Map<St
571571
.map(i -> (NonTerminal) i)
572572
.map(NonTerminal::sort).collect(Collectors.toList());
573573
productionLabel = production.klabel().get();
574-
if (isFunction(prod)) {
574+
if (isFunction(prod) || rule.att().contains(Attribute.ANYWHERE_KEY)) {
575575
leftChildren = ((KApply) left).items();
576576
equation = true;
577577
} else if ((rule.att().contains("heat") || rule.att().contains("cool")) && heatCoolEq) {
@@ -673,7 +673,7 @@ private void convertRule(Rule rule, boolean heatCoolEq, Sort topCellSort, Map<St
673673
convert(consideredAttributes, rule.att());
674674
sb.append("\n\n");
675675
}
676-
} else if (!rule.att().contains(Attribute.MACRO_KEY) && !rule.att().contains(Attribute.ALIAS_KEY) && !rule.att().contains(Attribute.ANYWHERE_KEY)) {
676+
} else if (!rule.att().contains(Attribute.MACRO_KEY) && !rule.att().contains(Attribute.ALIAS_KEY)) {
677677
if (rulesAsClaims) {
678678
sb.append(" claim{} ");
679679
} else {
@@ -876,9 +876,15 @@ private Att addKoreAttributes(Production prod, SetMultimap<KLabel, Rule> functio
876876
(prod.att().contains(Attribute.FUNCTION_KEY) && prod.att().contains(Attribute.UNIT_KEY))) {
877877
isConstructor = false;
878878
}
879+
boolean isAnywhere = false;
880+
if (overloads.contains(prod)) {
881+
isConstructor = false;
882+
isAnywhere = true;
883+
}
879884
for (Rule r : functionRules.get(prod.klabel().get())) {
880885
if (r.att().contains(Attribute.ANYWHERE_KEY)) {
881886
isConstructor = false;
887+
isAnywhere = true;
882888
}
883889
}
884890
Att att = prod.att().remove("constructor");
@@ -891,7 +897,7 @@ private Att addKoreAttributes(Production prod, SetMultimap<KLabel, Rule> functio
891897
if (isFunctional) {
892898
att = att.add("functional");
893899
}
894-
if (overloads.contains(prod)) {
900+
if (isAnywhere) {
895901
att = att.add("anywhere");
896902
}
897903
return att;

0 commit comments

Comments
 (0)