Skip to content

Commit

Permalink
Merge pull request #968 from nikodemus/cps-can-convert-unknown-method…
Browse files Browse the repository at this point in the history
…-with-constant-args

cps: can convert unknown method with constant arguments
  • Loading branch information
nikodemus authored Jun 17, 2023
2 parents 8db54fb + 30b1174 commit 2fd281c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ jobs:
- name: Install Emacs
run: |
sudo add-apt-repository -y ppa:kelleyk/emacs
sudo apt-get install -y emacs26-nox
sudo apt-get install -y emacs28-nox
- name: Test foolang-mode
run: bash tests/test-elisp.sh
32 changes: 29 additions & 3 deletions foo/impl/cps.foo
Original file line number Diff line number Diff line change
Expand Up @@ -1418,8 +1418,11 @@ interface OperationKind
(op args allSatisfy: #isConstant)
ifTrue: { let argVals = op args collect: #value.
let value = op kind apply: argVals.
let constant = graph ensureConstant: value.
op replaceUsesWith: constant in: worklist }!
-- apply will return False instead of a CpsValue if it fails,
-- in which case we can't simplify.
value is False
ifFalse: { let constant = graph ensureConstant: value.
op replaceUsesWith: constant in: worklist } }!
end
Expand Down Expand Up @@ -2471,7 +2474,7 @@ class CpsConverter { graph var next classMap namespace }
let instance = Instance
class: classDef
datum: value.
let const = graph ensureConstant: instance.
let const = graph ensureConstant: instance::Instance.
graph continuation: "$const_ref"
params: []
target: target
Expand Down Expand Up @@ -2740,6 +2743,7 @@ class CpsCopier { graph copied }
method visitConstant: aConstant
-- Log println: "visitConstant: {aConstant}".
copied
at: aConstant
ifNonePut: { graph ensureConstant: aConstant value }!
Expand Down Expand Up @@ -4933,6 +4937,28 @@ end"
equals: 123!


method test_flush_unused_known_expression
let cps = self convertExpr: "1 + 2. 42"
with: [IntegerClassDefinition].
assert that: { CpsPrinter printToString: cps }
equals: "
$entry:2($return:3):
$return:3(42)
"!


method test_keep_unused_unknown_expression
let cps = self convertExpr: "1 unknownMethod: 2. 42"
with: [IntegerClassDefinition].
assert that: { CpsPrinter printToString: cps }
equals: "
$entry:2($return:3):
apply:14($seq:8, findMethod:13(Integer, #unknownMethod:))(1, 2)
$seq:8($ignore:7):
$return:3(42)
"!


method test_optimize_datumOf_makeInstance_pairs_eliminated
let cps = self convertExpr: "let a = X a :: Integer.
let b = X b :: Integer. a + b + a + b"
Expand Down

0 comments on commit 2fd281c

Please sign in to comment.