Skip to content

Commit 307e256

Browse files
Take result attributes directly from the production when resolving contexts (#4685)
A declaration like ```syntax KItem ::= thing(Stuff, Stuff) [seqstrict, result(Evaluated)]``` should consider tems that are `Evaluated` as evaluated. Right now, this happens only for the argument being heated/cooled, while the previous arguments are checked for being `KResult`. As an example, when heating the second argument above, the heating rule looks something like this: ``` rule thing(A, B) => B ~> thingFreezer(A) requires isKResult(A) andBool notBool isEvaluated(B) ``` With this PR, the rule becomes ``` rule thing(A, B) => B ~> thingFreezer(A) requires isEvaluated(A) andBool notBool isEvaluated(B) ``` Fixes #4683 --------- Co-authored-by: Tamás Tóth <tothtamas28@users.noreply.github.com>
1 parent c15d153 commit 307e256

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
thing(a, b)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<k>
2+
.K
3+
</k>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
DEF=test
2+
EXT=test
3+
TESTDIR=.
4+
KOMPILE_FLAGS+=--syntax-module TEST
5+
6+
include ../../../include/kframework/ktest.mak
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module TEST
2+
imports BOOL
3+
4+
syntax KResult
5+
6+
syntax Stuff ::= "a" | "b" | "c"
7+
syntax KItem ::= thing(Stuff, Stuff) [seqstrict, result(MyResult)]
8+
9+
rule thing(c, c) => .K
10+
11+
rule b => c
12+
rule a => c
13+
14+
syntax Bool ::= isMyResult(K) [function, total, symbol(isMyResult)]
15+
rule isMyResult(_) => false [owise]
16+
rule isMyResult(c) => true
17+
endmodule

k-frontend/src/main/java/org/kframework/compile/ResolveStrict.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,14 @@ private void setAliases(String attribute, Set<ContextAlias> aliases, Production
116116
}
117117
}
118118

119-
private static final ContextAlias DEFAULT_ALIAS =
120-
ContextAlias(KVariable("HERE"), BooleanUtils.TRUE, Att.empty());
119+
private static final ContextAlias defaultAliasFor(Production production) {
120+
Att att = production.att();
121+
if (!att.contains(Att.RESULT())) {
122+
return ContextAlias(KVariable("HERE"), BooleanUtils.TRUE, Att.empty());
123+
}
124+
return ContextAlias(
125+
KVariable("HERE"), BooleanUtils.TRUE, Att.empty().add(Att.RESULT(), att.get(Att.RESULT())));
126+
}
121127

122128
private void resolve(
123129
boolean sequential,
@@ -202,14 +208,14 @@ public Set<Sentence> resolve(Production production, boolean sequential) {
202208
for (int i = 1; i <= arity; i++) {
203209
strictnessPositions.add(i);
204210
}
205-
aliases.add(DEFAULT_ALIAS);
211+
aliases.add(defaultAliasFor(production));
206212
resolve(sequential, sentences, arity, strictnessPositions, allPositions, aliases, production);
207213
allPositions.addAll(strictnessPositions);
208214
} else {
209215
String[] components = attribute.split(";");
210216
if (components.length == 1) {
211217
if (Character.isDigit(components[0].trim().charAt(0))) {
212-
aliases.add(DEFAULT_ALIAS);
218+
aliases.add(defaultAliasFor(production));
213219
setPositions(components[0].trim(), strictnessPositions, arity, production);
214220
} else {
215221
for (int i = 1; i <= arity; i++) {

0 commit comments

Comments
 (0)