-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'issue-6043' into remove-functionHeight
- Loading branch information
Showing
35 changed files
with
182 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Source/DafnyCore/Resolver/DetectUnsoundFunctionReferencesVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Diagnostics.Contracts; | ||
|
||
namespace Microsoft.Dafny; | ||
|
||
class DetectUnsoundFunctionReferencesVisitor : ResolverBottomUpVisitor { | ||
private readonly ICallable context; | ||
private bool doDecreasesChecks; | ||
private DetectUnsoundFunctionReferencesVisitor(ModuleResolver resolver, ICallable context) | ||
: base(resolver) { | ||
Contract.Requires(resolver != null); | ||
Contract.Requires(context != null); | ||
this.context = context; | ||
} | ||
|
||
public static void Check(Function function, ModuleResolver resolver) { | ||
var visitor = new DetectUnsoundFunctionReferencesVisitor(resolver, function); | ||
visitor.doDecreasesChecks = false; | ||
visitor.Visit(function); | ||
visitor.doDecreasesChecks = true; | ||
visitor.Visit(function.Decreases.Expressions); | ||
} | ||
|
||
protected override void VisitOneExpr(Expression expr) { | ||
if (!doDecreasesChecks && expr is MemberSelectExpr { Member: Function fn } && ModuleDefinition.InSameSCC(context, fn)) { | ||
resolver.reporter.Error(MessageSource.Resolver, expr.Origin, | ||
"cannot use naked function in recursive setting. Possible solution: eta expansion."); | ||
} | ||
|
||
if (doDecreasesChecks && expr is FunctionCallExpr callExpr && ModuleDefinition.InSameSCC(context, callExpr.Function)) { | ||
string msg; | ||
if (context == callExpr.Function) { | ||
msg = "a decreases clause is not allowed to call the enclosing function"; | ||
} else { | ||
msg = $"the decreases clause of {context.WhatKind} '{context.NameRelativeToModule}' is not allowed to call '{callExpr.Function}', " + | ||
"because they are mutually recursive"; | ||
} | ||
|
||
resolver.reporter.Error(MessageSource.Resolver, callExpr.Origin, msg); | ||
} | ||
} | ||
} |
37 changes: 0 additions & 37 deletions
37
Source/DafnyCore/Resolver/DetectUnsoundFunctionReferences_Visitor.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.