-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tail recursion #254
Open
vidsinghal
wants to merge
39
commits into
main
Choose a base branch
from
tail_recursion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+20,215
−383
Open
Tail recursion #254
Changes from 12 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
76a4486
mono tree c
vidsinghal 68a8876
mono tree c
vidsinghal ed4baad
add some motivating examples
vidsinghal 9341090
Merge branch 'tail_recursion' of github.com:iu-parfunc/gibbon into ta…
vidsinghal 23cd2eb
edits
vidsinghal a34dc9f
Add Manual tail recursion for Map, .c and .exe files
vidsinghal 7085cdd
Add insertion sort tail and non tail .c,.s,.exe examples
vidsinghal 47b5c65
add data for a Map on Vector
vidsinghal 2d83d67
Add example for Map on a Vector
vidsinghal 2b95a5a
Merge branch 'tail_recursion' of github.com:iu-parfunc/gibbon into ta…
vidsinghal 1e19aeb
Tail recursive length on cons list
vidsinghal 908e6c6
Merge branch 'tail_recursion' of github.com:iu-parfunc/gibbon into ta…
vidsinghal c57d980
add a pass to infer functions that are TMC or TC
vidsinghal b3998bb
Add pass to figure functions with tail calls
vidsinghal 9198a0e
Merge branch 'tail_recursion' of github.com:iu-parfunc/gibbon into ta…
vidsinghal e5a2a2b
Ensure ArrowTy Ty2 is printed in debug mode -v4
vidsinghal e913977
fix bug
vidsinghal cf620df
edits
vidsinghal 463a2f0
edits
vidsinghal 0951a9e
LREM -> add a field to signify it its a mutable location, AppE -> add…
vidsinghal d335d0b
marktailCalls: marks calls and output locations
vidsinghal cef8b0d
edit
vidsinghal 336a05f
edits
vidsinghal dfa92fb
edits
vidsinghal 6b202bb
edits
vidsinghal a9257b1
edits
vidsinghal ee07117
edits
vidsinghal 0fdeb23
edits
vidsinghal 85640cd
edits
vidsinghal 52898f5
edits
vidsinghal b7c20de
format file with fourmalu
vidsinghal 87693a1
Merge branch 'tail_recursion' of github.com:iu-parfunc/gibbon into ta…
vidsinghal e7eab10
Change LocVar to loc in L2 IR for LetLocE, addtag and allocate scalar…
vidsinghal 91e8c98
MarkTailCalls: handle alloc tag and scalars
vidsinghal adfb1ac
edits
vidsinghal b474e86
Revert "edits", Remove unnecessary abstraction of L3Variable
vidsinghal c681a83
Add Deref Mut cursor in L3 IR
vidsinghal d0a5974
add more mutable IR instructions
vidsinghal c566596
writeup
vidsinghal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
packages: gibbon-compiler | ||
|
||
program-options | ||
ghc-options: -Werror | ||
ghc-options: | ||
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,27 @@ | ||
module ConsListLength where | ||
|
||
|
||
data ConsIntList = Cons Int (ConsIntList) | Nil | ||
|
||
|
||
|
||
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have one empty line between definitions? (Same below.) |
||
mkConsIntList :: Int -> ConsIntList | ||
mkConsIntList len = if len <= 0 | ||
then Nil | ||
else let | ||
rst = mkConsIntList (len-1) | ||
in Cons len rst | ||
|
||
|
||
length :: ConsIntList -> Int -> Int | ||
length lst accum = case lst of | ||
Nil -> accum | ||
Cons x rst -> length rst (accum+1) | ||
|
||
|
||
|
||
gibbon_main = | ||
let n = sizeParam | ||
lst = mkConsIntList n | ||
len = iterate (length lst 0) | ||
in len |
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,71 @@ | ||
module Insertion where | ||
|
||
import Gibbon.Vector | ||
|
||
isort2 :: (a -> a -> Int) -> Vector a -> Vector a | ||
isort2 cmp xs = | ||
let n = length xs | ||
in go 1 n cmp (copy xs) | ||
|
||
go :: Int -> Int -> (a -> a -> Int) -> Vector a -> Vector a | ||
go i n cmp ys = | ||
if i == n | ||
then ys | ||
else let ys' = shift i cmp ys | ||
in go (i+1) n cmp ys' | ||
|
||
|
||
shift :: Int -> (a -> a -> Int) -> Vector a -> Vector a | ||
shift j cmp ys = | ||
if j == 0 | ||
then ys | ||
else let a = nth ys j | ||
b = nth ys (j-1) | ||
in if (cmp a b) > 0 | ||
then ys | ||
else let ys' = inplaceUpdate j b ys | ||
ys'' = inplaceUpdate (j-1) a ys' | ||
in shift (j-1) cmp ys'' | ||
|
||
-------------------------------------------------------------------------------- | ||
|
||
insert :: (a -> a -> Int) -> Vector a -> a -> Int -> Vector a | ||
insert cmp xs x n = | ||
if n == 0 | ||
then inplaceUpdate 0 x xs | ||
else let y = nth xs (n-1) | ||
in if (cmp x y) < 0 | ||
then let xs' = inplaceUpdate n y xs | ||
in insert cmp xs' x (n-1) | ||
else inplaceUpdate n x xs | ||
|
||
isort :: (a -> a -> Int) -> Vector a -> Vector a -> Int -> Vector a | ||
isort cmp xs b n = | ||
let len = length xs | ||
in if len <= 1 | ||
then xs | ||
else if n == 0 | ||
then b | ||
else let xs' = isort cmp xs b (n-1) | ||
in insert cmp xs' (nth xs n) n | ||
|
||
isort1 :: (a -> a -> Int) -> Vector a -> Vector a | ||
isort1 cmp xs = | ||
let n = length xs | ||
hd = nth xs 0 | ||
b :: Vector a | ||
b = generate n (\i -> hd) | ||
in isort cmp xs b ((length xs) - 1) | ||
|
||
-------------------------------------------------------------------------------- | ||
|
||
gibbon_main = | ||
let n = sizeParam | ||
ls :: Vector Int | ||
ls = generate sizeParam (\i -> n-i) | ||
|
||
ls1 = isort1 compare_int ls | ||
ls2 = isort2 compare_int ls | ||
|
||
_ = printVec (\i -> printint i) ls1 | ||
in (ls1,ls2) |
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,43 @@ | ||
module Map where | ||
|
||
|
||
data ConsIntList = Cons Int (ConsIntList) | Nil | ||
|
||
|
||
mkConsIntList :: Int -> ConsIntList | ||
mkConsIntList len = if len <= 0 | ||
then Nil | ||
else let | ||
rst = mkConsIntList (len-1) | ||
in Cons len rst | ||
|
||
|
||
map :: (Int -> Int) -> ConsIntList -> ConsIntList | ||
map f lst = case lst of | ||
Nil -> Nil | ||
Cons x rst -> Cons (f x) (map f rst) | ||
|
||
|
||
|
||
|
||
add1 :: Int -> Int | ||
add1 x = x + 1 | ||
|
||
checkMapAdd1 :: ConsIntList -> ConsIntList -> Bool | ||
checkMapAdd1 lst lst' = case lst of | ||
Nil -> case lst' of | ||
Nil -> True | ||
_ -> False | ||
Cons x rst -> case lst' of | ||
Nil -> False | ||
Cons x' rst' -> if (x' == x + 1) | ||
then True && checkMapAdd1 rst rst' | ||
else False | ||
|
||
gibbon_main = | ||
let len = 10000000 | ||
lst = mkConsIntList len | ||
lst' = iterate (map add1 lst) | ||
in checkMapAdd1 lst lst' | ||
|
||
|
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 @@ | ||
module MapOnVector where | ||
|
||
import Gibbon.Vector | ||
|
||
add1 :: Int -> Int | ||
add1 x = x + 1 | ||
|
||
|
||
gibbon_main = | ||
let n = sizeParam | ||
ls :: Vector Int | ||
ls = generate sizeParam (\i -> n-i) | ||
-- generate_loop is the recursive function to look at, if it is tail_recursive or not. | ||
ls' = iterate (map add1 ls) | ||
--_ = printVec (\i -> printint i) ls' | ||
in (ls,ls') |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a temporary change to see how far CI advances, or do you intend it to stay that way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just temporary