Skip to content
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

Import module collisions #235

Open
wants to merge 74 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
e1ec3aa
collision example
0xtimmy Oct 25, 2023
4e81af3
repeatable module import collisions
0xtimmy Oct 27, 2023
a2deafb
declaration renaming works
0xtimmy Nov 6, 2023
7ff377a
module rename can modify function callsites and function decalrations…
0xtimmy Nov 8, 2023
1b2cfaf
finished basic module import resolution
0xtimmy Nov 10, 2023
f05cbdd
parses modules in defs and main as well
0xtimmy Nov 11, 2023
2776226
added a pass to resolve imports in desugarModule
0xtimmy Nov 21, 2023
3d80c84
minor cleanup of README and gibbon-compiler/gibbon.cabal
ulysses4ever Nov 22, 2023
6145e02
aliases work
0xtimmy Nov 22, 2023
434712c
qualified imports
0xtimmy Nov 22, 2023
34e6618
spec imports
0xtimmy Nov 23, 2023
c8bb2d1
finished test cases
0xtimmy Nov 30, 2023
eca7cdd
Merge pull request #233 from ulysses4ever/ap-minor-cleanup
rrnewton Dec 6, 2023
97b9c39
fix? handling local identifier
0xtimmy Dec 7, 2023
2659da7
some testing
0xtimmy Dec 7, 2023
c3e9aca
fixed interp
0xtimmy Dec 10, 2023
22cc526
fixing a test (did not specify the sum function)
0xtimmy Dec 10, 2023
ddbae71
added ext parsing
0xtimmy Dec 11, 2023
cd2ec79
fixed an issue with LetE
0xtimmy Dec 11, 2023
b114741
some oddness
0xtimmy Dec 11, 2023
2f4992c
more bug fixing
0xtimmy Jan 11, 2024
19d4a65
add fixed linear ext handling
0xtimmy Jan 11, 2024
9bc6837
let _default contructors pass through
0xtimmy Jan 11, 2024
09c85cb
collision example
0xtimmy Oct 25, 2023
6020508
repeatable module import collisions
0xtimmy Oct 27, 2023
33f7d48
declaration renaming works
0xtimmy Nov 6, 2023
2a2c42a
module rename can modify function callsites and function decalrations…
0xtimmy Nov 8, 2023
c5f48c6
finished basic module import resolution
0xtimmy Nov 10, 2023
826eb0c
parses modules in defs and main as well
0xtimmy Nov 11, 2023
5acadd1
added a pass to resolve imports in desugarModule
0xtimmy Nov 21, 2023
27269e6
aliases work
0xtimmy Nov 22, 2023
7d61d81
qualified imports
0xtimmy Nov 22, 2023
0aa6bb3
spec imports
0xtimmy Nov 23, 2023
d42d258
finished test cases
0xtimmy Nov 30, 2023
a430af3
fix? handling local identifier
0xtimmy Dec 7, 2023
375baae
some testing
0xtimmy Dec 7, 2023
6847ca9
fixed interp
0xtimmy Dec 10, 2023
0350baf
fixing a test (did not specify the sum function)
0xtimmy Dec 10, 2023
da753a5
added ext parsing
0xtimmy Dec 11, 2023
f886311
fixed an issue with LetE
0xtimmy Dec 11, 2023
fc54de8
some oddness
0xtimmy Dec 11, 2023
fbeca95
more bug fixing
0xtimmy Jan 11, 2024
c3232d4
add fixed linear ext handling
0xtimmy Jan 11, 2024
8ce0e24
let _default contructors pass through
0xtimmy Jan 11, 2024
f20862f
notes from artem
0xtimmy Jan 31, 2024
ecc51cd
built bundler & added bundle flow to the parser and compiler
0xtimmy Jan 31, 2024
2e2e322
passes some tests
0xtimmy Feb 14, 2024
d5cf3f2
Merge branch 'import-module-collisions' into module-bundler
0xtimmy Feb 14, 2024
c3e1d6d
Merge pull request #255 from iu-parfunc/module-bundler
0xtimmy Feb 14, 2024
0df2511
fixing merge issue
0xtimmy Feb 14, 2024
9824c51
removed qualification from unique name (gets rid of the ugly {package…
0xtimmy Feb 14, 2024
ba66015
fixed .gib extension
0xtimmy Feb 15, 2024
237b0e5
fixed verbodity issue
0xtimmy Feb 17, 2024
e10b206
adding the fix to the interpreter
0xtimmy Feb 17, 2024
9662f04
PR cleanup
0xtimmy Feb 20, 2024
f66afdc
cleaning up build file
0xtimmy Feb 20, 2024
41d3b82
reverting common.hs
0xtimmy Feb 20, 2024
1349a7c
some more test fixes
0xtimmy Feb 21, 2024
86c50d6
some more test changes
0xtimmy Feb 21, 2024
6062341
alternatives for showing internal type names
0xtimmy Feb 21, 2024
d1ff39b
Merge branch 'main' of github.com:iu-parfunc/gibbon
0xtimmy Feb 21, 2024
c6b38d2
changed layout benches to print the blogs in a way that's independent…
0xtimmy Feb 21, 2024
24b33ba
removing interp changes
0xtimmy Feb 21, 2024
55373d2
handling _default in freshBundle CaseE
0xtimmy Feb 21, 2024
1387304
fixed more test cases
0xtimmy Feb 21, 2024
1d9fed9
fixing manyFuncs
0xtimmy Feb 21, 2024
4330552
solve layout constrs error
0xtimmy Feb 21, 2024
0d17d3a
test cases pass
0xtimmy Feb 21, 2024
65ab88c
Merge pull request #256 from iu-parfunc/test-case-changes
0xtimmy Feb 21, 2024
bbaa2d7
removed some tests missing from main
0xtimmy Feb 21, 2024
97eff1d
adressed comments and added more robust descriptions to all new modules
0xtimmy Feb 28, 2024
a335c8f
added a pass to resolve imports in desugarModule
0xtimmy Mar 8, 2024
ecac589
merged in main
0xtimmy Mar 8, 2024
6756e1d
removing extra files from diff
0xtimmy Jun 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gibbon-compiler/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ demo/*.c
demo/*.exe
gibbon-compiler/examples/parallel/data/*.txt
*.log.hs
*.log
7 changes: 4 additions & 3 deletions gibbon-compiler/examples/add1.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module Add where
data Tree = Leaf Int | Node Tree Tree

add1 :: Tree -> Tree
add1 t = case t of
Leaf x -> Leaf (x + 1)
Node x1 x2 -> Node (add1 x1) (add1 x2)
Node x1 x2 -> Node (Add.add1 x1) (Add.add1 x2)

main :: Tree
main = add1 (Node (Leaf 1) (Leaf 2))
gibbon_main :: Tree
gibbon_main = Add.add1 (Node (Leaf 1) (Leaf 2))
Comment on lines -8 to +10
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was annoyed that this example doesn't compile too. But does this change fix it? I seem to remember that gibbon_main can only return scalar types, I think (Int, etc.). Maybe adding a summation over the resulting tree could make it work?

8 changes: 8 additions & 0 deletions gibbon-compiler/examples/imports/AddTree.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module AddTree where
data Tree = Node Tree Tree | Leaf Int

sum :: Tree -> Int
sum t =
case t of
Leaf v -> v
Node l r -> (sum l) + (sum r)
15 changes: 15 additions & 0 deletions gibbon-compiler/examples/imports/Addone.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Addone where
import AddTree

add :: Tree -> Tree
add t = case t of
Leaf x -> Leaf (x + 1)
Node x1 x2 -> Node (add x1) (add x2)

sub :: Tree -> Tree
sub t = case t of
Leaf x -> Leaf (x - 1)
Node x1 x2 -> Node (sub x1) (sub x2)

gibbon_main :: Tree
gibbon_main = add (Node (Leaf 1) (Leaf 2))
15 changes: 15 additions & 0 deletions gibbon-compiler/examples/imports/Addtwo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Addtwo where
import AddTree

add :: Tree -> Tree
add t = case t of
Leaf x -> Leaf (x + 2)
Node x1 x2 -> Node (add x1) (add x2)

sub :: Tree -> Tree
sub t = case t of
Leaf x -> Leaf (x - 2)
Node x1 x2 -> Node (sub x1) (sub x2)

gibbon_main :: Tree
gibbon_main = add (Node (Leaf 1) (Leaf 2))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module AllThreeImportModifications where
import qualified Addtwo as T (add)
import qualified Addone as O (add)
import AddTree as Tree (sum, Node, Leaf)

gibbon_main = sum (T.add (O.add (Tree.Node (Tree.Leaf 1) (Tree.Leaf 2))))
1 change: 1 addition & 0 deletions gibbon-compiler/examples/imports/ImportAliased.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9
6 changes: 6 additions & 0 deletions gibbon-compiler/examples/imports/ImportAliased.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module ImportAliased where
import qualified Addtwo as T
import qualified Addone as O
import AddTree as Tree

gibbon_main = sum (T.add (O.add (Tree.Node (Tree.Leaf 1) (Tree.Leaf 2))))
1 change: 1 addition & 0 deletions gibbon-compiler/examples/imports/ImportQualified.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9
6 changes: 6 additions & 0 deletions gibbon-compiler/examples/imports/ImportQualified.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module ImportQualified where
import qualified Addtwo
import qualified Addone
import AddTree

gibbon_main = sum (Addtwo.add (Addone.add (Node (Leaf 1) (Leaf 2))))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module ImportQualifiedAndSpecified where
import qualified Addtwo (add)
import qualified Addone (sub)
import AddTree

gibbon_main = sum (Addtwo.add (Addone.sub (Node (Leaf 1) (Leaf 2))))
1 change: 1 addition & 0 deletions gibbon-compiler/examples/imports/ImportSpecified.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5
6 changes: 6 additions & 0 deletions gibbon-compiler/examples/imports/ImportSpecified.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module ImportSpecified where
import Addtwo (add)
import Addone (sub)
import AddTree

gibbon_main = sum (add (sub (Node (Leaf 1) (Leaf 2))))
61 changes: 61 additions & 0 deletions gibbon-compiler/examples/imports/failing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Poly
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is also a layout-patch leftover?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was leftover notes for myself, good to remove from the diff

### `/poly/Poly1.hs`

Problem seems to be with the type names, numbers and Nothing, Cons, Nil, Right all match

```
< '#(10 #t 11 #f 2 4 (Poly1_Nothing_77_v_323) (Poly1_Right_76_v_342 20) (Poly1_Right_76_v_334 1) 12 #f 0 3 (Poly1_Cons_74_v_329 1 (Poly1_Cons_74_v_329 2 (Poly1_Nil_73_v_329))) (Poly1_Cons_74_v_329 1 (Poly1_Cons_74_v_329 2 (Poly1_Nil_73_v_329))) (Poly1_Right_76_v_334 1) (Poly1_Cons_74_v_329 11 (Poly1_Cons_74_v_329 12 (Poly1_Nil_73_v_329))))
---
> '#(10 #t 11 #f 2 4 (Nothing_v_295 ) (Right_v_315 20) (Right_v_306 1) 12 #f 0 3 (Cons_v_301 1(Cons_v_301 2(Nil_v_301 ))) (Cons_v_301 1(Cons_v_301 2(Nil_v_301 ))) (Right_v_306 1) (Cons_v_301 11(Cons_v_301 12(Nil_v_301 ))))
\ No newline at end of file
```

# Eval l/r
### `eval_l.hs`

### `eval_r.hs`

these are failing to properly import a module in interp mode this seems to stem from the fact the the imported file does not have a module declaration,,, so internally it renames with "Main" but the true Main module expects "Eval" b/c that's the name in the import statement.

solving this by having the Main module tell each imported module how to name themselves ... this I think could get convoluted b/c a module decalred internally as A could be imported as B ... perhaps a subjective design decision but this seems to work

# ArrowTy
### `layout1ContentSearch.hs`
```
Couldn't match type 'ArrowTy [VectorTy (MetaTv $839)]
IntTy' with 'IntTy'
Expected type: IntTy
Actual type: ArrowTy [VectorTy (MetaTv $839)] IntTy
In the expression:
VarE "Gibbon_Vector_length_132" in Var "GenerateLayout1_mkBlogs_layout1_107"
```

This all seems to come from a similair pattern but it looks like the bug doesn't have anything to do with the error. The issue is scope: `Gibbon_Vector_length_132` is some global name but there is a `length` that is one of the function arguements. The rename pass matches length to the global function, causing the error. My solution was to force the global name to be qualified within the scope where `length` exists. So the global `Gibbon.Vector.length` can be accessed if qualified, but simple reference to `length` will use the function arguement `length`

### `layout1ContentSearchRunPipeline.hs`

### `layout1FilterBlogs.hs`

### `layout1TagSearch.hs`

### `layout2ContentSearch.hs`

### `layout2FilterBlogs.hs`

### `layout2TagSearch.hs`

### `layout3ContentSearch.hs`

### `layout3FilterBlogs.hs`

### `layout3TagSearch.hs`

### `layout4ContentSearch.hs`

### `layout4FilterBlogs.hs`

### `layout4TagSearch.hs`

### `layout5ContentSearch.hs`

### `layout5FilterBlogs.hs`
9 changes: 9 additions & 0 deletions gibbon-compiler/examples/imports/import_tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Import Features
- no modifiers
- qualified
- specified
- aliased
- qualified & specified
- qualified & aliased
- specified & aliased
- qualified & specified & aliased
2 changes: 1 addition & 1 deletion gibbon-compiler/examples/poly/Poly1.ans
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'#(10 #t 11 #f 2 4 (Nothing_v_406) (Right_v_426 20) (Right_v_417 1) 12 #f 0 3 (Cons_v_412 1 (Cons_v_412 2 (Nil_v_412))) (Cons_v_412 1 (Cons_v_412 2 (Nil_v_412))) (Right_v_417 1) (Cons_v_412 11 (Cons_v_412 12 (Nil_v_412))))
'#(10 #t 11 #f 2 4 (Nothing99_v434) (Right98_v453 20) (Right98_v445 1) 12 #f 0 3 (Cons96_v440 1 (Cons96_v440 2 (Nil95_v440))) (Cons96_v440 1 (Cons96_v440 2 (Nil95_v440))) (Right98_v445 1) (Cons96_v440 11 (Cons96_v440 12 (Nil95_v440))))
2 changes: 1 addition & 1 deletion gibbon-compiler/examples/test_153.ans
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'#('#(2 3) (B_v_13 4 5))
'#('#(2 3) (B5_v17 4 5))
2 changes: 1 addition & 1 deletion gibbon-compiler/examples/test_164.ans
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(Cons_v_64 3 (Cons_v_64 5 (Cons_v_64 7 (Nil_v_64))))
(Cons19_v68 3 (Cons19_v68 5 (Cons19_v68 7 (Nil18_v68))))
2 changes: 1 addition & 1 deletion gibbon-compiler/examples/test_166.ans
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(Node_v_79 10 10 10 10 10 10 10 10 (Cell_v_79 5 5 5 5 5 5 5 5) (Cell_v_79 2 2 2 2 2 2 2 2))
(Node16_v86 10 10 10 10 10 10 10 10 (Cell15_v86 5 5 5 5 5 5 5 5) (Cell15_v86 2 2 2 2 2 2 2 2))
2 changes: 1 addition & 1 deletion gibbon-compiler/examples/test_191.ans
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(Cons 12 ->i (I 2) (Cons 12 ->i (I 1) (Nil)))'#()
(Cons26 12 ->i (I28 2) (Cons26 12 ->i (I28 1) (Nil27)))'#()
4 changes: 2 additions & 2 deletions gibbon-compiler/examples/test_printpacked.ans
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(Node (Node (Leaf 1)(Leaf 1))(Node (Leaf 1)(Leaf 1)))
->i (Node (Node (Leaf 1)(Leaf 1))(Node (Leaf 1)(Leaf 1)))
(Node32 (Node32 (Leaf31 1)(Leaf31 1))(Node32 (Leaf31 1)(Leaf31 1)))
->i (Node32 (Node32 (Leaf31 1)(Leaf31 1))(Node32 (Leaf31 1)(Leaf31 1)))
1
'#()
2 changes: 2 additions & 0 deletions gibbon-compiler/gibbon.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ flag LLVM_ENABLED
library
exposed-modules: Gibbon.Common
Gibbon.Compiler
Gibbon.Bundler
Gibbon.DynFlags
Gibbon.Pretty
Gibbon.SExpFrontend
Expand Down Expand Up @@ -60,6 +61,7 @@ library
Gibbon.NewL2.FromOldL2

-- compiler passes, roughly in the order they're run
Gibbon.Passes.FreshBundle
Gibbon.Passes.Freshen
Gibbon.Passes.Flatten
Gibbon.Passes.InlineTriv
Expand Down
54 changes: 54 additions & 0 deletions gibbon-compiler/src/Gibbon/Bundler.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- | Union all the modules in a program bundle in to a single program
module Gibbon.Bundler (bundleModules) where
import qualified Data.Foldable as F
import qualified Data.Set as S
import Gibbon.L0.Syntax as L0
import Gibbon.Common
import Data.Map as M



-- | Main bundler, runs all imported modules through a union that combines
-- their function defintions and data definitions with main's
-- Names should be globally unique at this point
bundleModules :: ProgBundle0 -> PassM Prog0
bundleModules bundle = do
let (ProgBundle modules main) = bundle
let (ProgModule _ (Prog main_defs main_funs main_exp) _) = main
let (defs, funs) = F.foldr _bundleModule (main_defs, main_funs) modules
return $ Prog defs funs main_exp

-- | Bundle fold function
-- builds the full program by folding definitons and functions into the main
_bundleModule :: ProgModule0 -> (DDefs0, FunDefs0) -> (DDefs0, FunDefs0)
_bundleModule (ProgModule mod_name (Prog {ddefs, fundefs}) _) (defs1, funs1) =
-- conflict checking,,, extract definition and function names
let ddef_names1 = M.keysSet defs1
ddef_names2 = M.keysSet ddefs
fn_names1 = M.keysSet funs1
fn_names2 = M.keysSet fundefs
em1 = S.intersection ddef_names1 ddef_names2
em2 = S.intersection fn_names1 fn_names2
conflicts1 = F.foldr (\d acc ->
if (ddefs M.! d) /= (defs1 M.! d)
then d : acc
else acc)
[] em1
conflicts2 = F.foldr (\f acc ->
if (fundefs M.! f) /= (funs1 M.! f)
then dbgTraceIt
(sdoc ((fundefs M.! f), (funs1 M.! f)))
(f : acc)
else acc)
[] em2
in case (conflicts1, conflicts2) of
([], []) ->
(M.union ddefs defs1, M.union fundefs funs1)
(_x:_xs, _) ->
error $
"Conflicting definitions of " ++
show conflicts1 ++ " found in " ++ mod_name
(_, _x:_xs) ->
error $
"Conflicting definitions of " ++
show (S.toList em2) ++ " found in " ++ mod_name
7 changes: 4 additions & 3 deletions gibbon-compiler/src/Gibbon/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ newUniq = state (\x -> (x, x+1))

-- | Generate a unique symbol by attaching a numeric suffix.
gensym :: MonadState Int m => Var -> m Var
gensym v = state (\n -> (cleanFunName v `varAppend` "_" `varAppend` toVar (show n), n + 1))
gensym v = state (\n -> (cleanFunName v `varAppend` toVar (show n), n + 1))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why this underscore was removed? Preferably with examples.


gensym_tag :: MonadState Int m => Var -> String -> m Var
gensym_tag v str = state (\n -> (cleanFunName v `varAppend` toVar (show n ++ str) , n + 1))
Expand Down Expand Up @@ -356,10 +356,11 @@ abbrv n x =
then str
else L.take (n-3) str ++ "..."

lookup3 :: (Eq k, Show k, Show a, Show b) => k -> [(k,a,b)] -> (k,a,b)
lookup3 :: HasCallStack => (Eq k, Show k, Show a, Show b) => k -> [(k,a,b)] -> (k,a,b)
lookup3 k ls = go ls
where
go [] = error$ "lookup3: key "++show k++" not found in list:\n "++L.take 80 (show ls)
--go [] = error$ "lookup3: key "++show k++" not found in list:\n "++L.take 80 (show ls)
go [] = error$ "lookup3: key "++show k++" not found in list:\n "++ (show ls)
go ((k1,a1,b1):r)
| k1 == k = (k1,a1,b1)
| otherwise = go r
Expand Down
Loading
Loading