Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial constant evaluation to blocks
BlockExpressions are usually evaluated by create a temporary variable to hold the result of the tail expression in the correctly. Const expressions do not have a context of a block so we must fold the value to store it correctly without the need for temporary variables or a stack. To do this we can leverage the fact that our constexpr code can fold simple CallExpr's so in this patch we actually generate an implicit artifical function for the block but do not add it to the translation unit and we then generate an artifical CallExpr and pass it to the constant folder system, and then assign the ConstDecl to this folded value thus reusing all of our existing BlockExpression code instead of a seperate system. Fixes #799
- Loading branch information
Showing
5 changed files
with
102 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// { dg-additional-options "-w" } | ||
const A: i32 = 1; | ||
const B: i32 = { A + 2 }; | ||
|
||
const fn test() -> i32 { | ||
B | ||
} | ||
|
||
const C: i32 = { | ||
const a: i32 = 4; | ||
test() + a | ||
}; | ||
|
||
fn main() -> i32 { | ||
C - 7 | ||
} |