Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NF] Enforce function purity rules better.
- Give a warning if any pure function contains calls to impure functions, and mark such functions as impure themselves to make sure they're not constant evaluated.
- Loading branch information
Showing
5 changed files
with
109 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// name: ImpureCall1 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
impure function f | ||
input Real x; | ||
output Real y = x; | ||
end f; | ||
|
||
function f2 | ||
input Real x; | ||
output Real y; | ||
algorithm | ||
y := f(x); | ||
end f2; | ||
|
||
model ImpureCall1 | ||
Real x = f2(1.0); | ||
end ImpureCall1; | ||
|
||
// Result: | ||
// impure function f | ||
// input Real x; | ||
// output Real y = x; | ||
// end f; | ||
// | ||
// impure function f2 | ||
// input Real x; | ||
// output Real y; | ||
// algorithm | ||
// y := f(x); | ||
// end f2; | ||
// | ||
// class ImpureCall1 | ||
// Real x = f2(1.0); | ||
// end ImpureCall1; | ||
// [flattening/modelica/scodeinst/ImpureCall1.mo:13:1-18:7:writable] Warning: Pure function ‘f2‘ contains a call to impure function ‘f‘. | ||
// | ||
// endResult |
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