Skip to content

Commit

Permalink
Merge pull request #3217 from michaellilltokiwa/issue/1875
Browse files Browse the repository at this point in the history
fuir: remove manual stack cleanup
  • Loading branch information
michaellilltokiwa committed Sep 13, 2024
2 parents 96ed830 + c25a8d4 commit 3c046a5
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 24 deletions.
5 changes: 2 additions & 3 deletions src/dev/flang/be/interpreter/Interpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static void setField(int thiz, int staticClazz, Value curValue, Value v)
);

int fclazz = clazzForField(thiz);
LValue slot = fieldSlot(thiz, staticClazz, fclazz, curValue);
LValue slot = fieldSlot(thiz, staticClazz, fclazz, curValue);
setFieldSlot(thiz, fclazz, slot, v);
}

Expand Down Expand Up @@ -435,7 +435,6 @@ private static void setChoiceField(int thiz,
*/
private static LValue fieldSlot(int thiz, int staticClazz, int fclazz, Value curValue)
{
int off;
var clazz = staticClazz;
if (fuir().clazzIsRef(staticClazz))
{
Expand All @@ -448,7 +447,7 @@ private static LValue fieldSlot(int thiz, int staticClazz, int fclazz, Value cur
clazz = ((Boxed)curValue)._valueClazz;
curValue = ((Boxed)curValue)._contents;
}
off = Layout.get(clazz).offset(thiz);
int off = Layout.get(clazz).offset(thiz);

// NYI: check if this is a can be enabled or removed:
//
Expand Down
34 changes: 14 additions & 20 deletions src/dev/flang/fuir/analysis/AbstractInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Stack;

import dev.flang.fuir.FUIR;
import dev.flang.ir.IR.ExprKind;

import static dev.flang.ir.IR.NO_SITE;

Expand Down Expand Up @@ -521,27 +522,20 @@ public Pair<VALUE,RESULT> processCode(int s0)
l.add(_processor.reportErrorInCode("Severe compiler bug! This code should be unreachable."));
}

if (!containsVoid(stack) && stack.size() > 0)
{ // NYI: #1875: Manual stack cleanup. This should not be needed since the
// FUIR has the (so far undocumented) invariant that the stack must be
// empty at the end of a basic block. There were some cases
// (tests/reg_issue1294) where this is not the case that need to be
// fixed, the FUIR code should contain a POP instructions to avoid this
// special handling here!
//
var e = _fuir.codeAt(last_s);
switch (e)
// FUIR has the (so far undocumented) invariant that the stack must be
// empty at the end of a basic block.
if (CHECKS) check
(containsVoid(stack) || stack.isEmpty() || _fuir.alwaysResultsInVoid(last_s));

if (!containsVoid(stack) && !stack.isEmpty() && _fuir.alwaysResultsInVoid(last_s))
{
if (CHECKS) check
(_fuir.codeAt(last_s) == ExprKind.Call);
var cc0 = _fuir.accessedClazz(last_s);
var rt = _fuir.clazzResultClazz(cc0);
if (!clazzHasUnitValue(rt))
{
case Call:
var cc0 = _fuir.accessedClazz(last_s);
var rt = _fuir.clazzResultClazz(cc0);
if (!clazzHasUnitValue(rt))
{
l.add(_processor.drop(stack.pop(), rt));
}
break;
default:
break; // NYI: ignore this case for now, this occurs infrequently, one example is tests/reg_issue1294.
l.add(_processor.drop(stack.pop(), rt));
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/reg_issue1294/issue1294.fz
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ scenario1 =>
fs(F type : a F) =>
_ := F.zero

scenario1
# NYI: BUG: #3649 scenario1



Expand Down
25 changes: 25 additions & 0 deletions tests/reg_issue2345/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion test Makefile
#
# -----------------------------------------------------------------------

override NAME = reg_issue2345.fz
include ../compile.mk
25 changes: 25 additions & 0 deletions tests/reg_issue2345/reg_issue2345.fz
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion test reg_issue2345
#
# -----------------------------------------------------------------------

_ := n
n => if true then n else panic "n"
25 changes: 25 additions & 0 deletions tests/reg_issue2345_1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion test Makefile
#
# -----------------------------------------------------------------------

override NAME = reg_issue2345_1
include ../compile.mk
26 changes: 26 additions & 0 deletions tests/reg_issue2345_1/reg_issue2345_1.fz
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion test reg_issue2345_1
#
# -----------------------------------------------------------------------

reg_issue2345_1 is
n2 => if true then n2 else panic "n"
n2
25 changes: 25 additions & 0 deletions tests/reg_issue3521/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion test Makefile
#
# -----------------------------------------------------------------------

override NAME = reg_issue3521
include ../simple.mk
25 changes: 25 additions & 0 deletions tests/reg_issue3521/reg_issue3521.fz
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion test reg_issue3521
#
# -----------------------------------------------------------------------

a => if false then _ := "$unit"

Empty file.
Empty file.

0 comments on commit 3c046a5

Please sign in to comment.