Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requires in haskell is LHS #2690

Merged
merged 2 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions k-distribution/tests/regression-new/checkWarns/checkRHSHaskell.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This should kompile just fine for the haskell backend, variables
// in the requires clause should be considered as part of LHS for haskell backend.
// https://github.com/runtimeverification/k/issues/2687

module CHECKRHSHASKELL-SYNTAX

endmodule

module CHECKRHSHASKELL
imports CHECKRHSHASKELL-SYNTAX
imports MAP
imports INT
imports BOOL

syntax Pgm ::= "a" | "b"

rule <k> a => b </k>

syntax Int ::= f ( Int ) [function, functional, no-evaluators]

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

rule <k> a => b </k> requires f(_X) ==Int 3

endmodule
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

import com.google.common.collect.Sets;
import org.kframework.attributes.Att;
import org.kframework.backend.Backends;
import org.kframework.compile.GatherVarsVisitor;
import org.kframework.definition.Claim;
import org.kframework.definition.Context;
import org.kframework.definition.ContextAlias;
import org.kframework.definition.Rule;
import org.kframework.definition.RuleOrClaim;
import org.kframework.definition.Sentence;
import org.kframework.kore.K;
Expand All @@ -31,18 +33,20 @@
public class CheckRHSVariables {
private final Set<KEMException> errors;
private final boolean errorExistential;
private final String backend;

public CheckRHSVariables(Set<KEMException> errors, boolean errorExistential) {
public CheckRHSVariables(Set<KEMException> errors, boolean errorExistential, String backend) {
this.errors = errors;
this.errorExistential = errorExistential;
this.backend = backend;
}
private void check(RuleOrClaim rule) {
resetVars();
Set<String> unboundVariableNames = getUnboundVarNames(rule);
boolean errorExistential = this.errorExistential && !(rule.att().contains(Att.LABEL()) && rule.att().get(Att.LABEL()).equals("STDIN-STREAM.stdinUnblock"));
gatherVars(true, rule.body(), errorExistential);
gatherVars(false, rule.ensures(), errorExistential);
if (rule instanceof Claim) {
if (rule instanceof Claim || (rule instanceof Rule && backend.equals(Backends.HASKELL))) {
gatherVars(true, rule.requires(), errorExistential);
check(rule.body(), true, false, unboundVariableNames);
check(rule.requires(), true, false, unboundVariableNames);
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/main/java/org/kframework/kompile/Kompile.java
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public void proverChecksX(Module specModule, Module mainDefModule) {
public void structuralChecks(scala.collection.Set<Module> modules, Module mainModule, Option<Module> kModule, Set<String> excludedModuleTags) {
boolean isSymbolic = excludedModuleTags.contains(Att.CONCRETE());
boolean isKast = excludedModuleTags.contains(Att.KORE());
CheckRHSVariables checkRHSVariables = new CheckRHSVariables(errors, !isSymbolic);
CheckRHSVariables checkRHSVariables = new CheckRHSVariables(errors, !isSymbolic, kompileOptions.backend);
stream(modules).forEach(m -> stream(m.localSentences()).forEach(checkRHSVariables::check));

stream(modules).forEach(m -> stream(m.localSentences()).forEach(new CheckAtt(errors, kem, mainModule, isSymbolic && isKast)::check));
Expand Down