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

Added module system support for diamond and repeated imports, and to prevent recursive imports. #443

Merged
merged 22 commits into from
May 30, 2016

Conversation

supercooldave
Copy link

Added module system to support diamond and repeated imports, and prevent recursive imports.
Involved a significant reworking of the way modules were included in the code, and hence touched quite a few places in the code.

Fixes #329 and #233.

This PR lays the foundation for proper module support, including namespaces and all the other things you would expect.

Several new test cases provided. Failing tests are not yet integrated into the test build, awaiting @kaeluka's new test scripts.

No new documentation provided, as these changes make the modules behave closer to what is expected.

@supercooldave supercooldave changed the title Added module system to support diamond and repeated imports, and prevent recursive imports Added module system support for diamond and repeated imports, and to prevent recursive imports. May 24, 2016
@supercooldave supercooldave added this to the May'16 Sprint milestone May 24, 2016
importAndCheckModules :: (Environment -> Program -> IO (Environment, Program)) ->
[FilePath] -> Program -> IO ModuleMap
importAndCheckModules checker importDirs p = do
(modules, env) <- importAndCheckProgram [] Map.empty emptyEnv [] p -- [] is QName of top-level module.
Copy link
Contributor

Choose a reason for hiding this comment

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

env variable is never used

@kikofernandez
Copy link
Contributor

rebase this branch on top of development, solve conflicts and I'll continue with the review (possibly Monday)

@supercooldave
Copy link
Author

@kikofernandez I've addressed your changes and rebased.

importAndCheckProgram seen importTable env target impl

importOne :: [FilePath] -> ImportDecl -> IO Program
importOne importDirs (Import _ target) = do
Copy link
Contributor

Choose a reason for hiding this comment

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

I am looking at this function but, somehow, it's not clear to me. My understanding:

  1. importOne takes always the same input for importDirs (which comes from the importDirs from importAndCheckModules checker importDirs p)
  2. Append to the dirs the target
  3. Filter out the ones that do not exist
  4. If there is more than one, e.g. libA/B/MapInt and libC/D/MapInt, the compiler throws a warning. If libA and libC are the includes (-I libA:libC), the compiler can still distinguish which module we want to access to, eitherB/MapInt or C/MapInt, and the warning could be avoided. Does this make sense?

However, I can understand the warning if we include -I libA:libB and we have libA/B/MapInt.enc and libB/B/MapInt.enc and the user imports the module import B.MapInt. There is no way of telling which of the two we are accessing. In this case, an error is better (I think).

Does this make sense or am I mistaken somewhere along the road?

Copy link
Author

Choose a reason for hiding this comment

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

You understand correctly.
I'll see what the impact of converting the warning into an error is.

Copy link
Author

Choose a reason for hiding this comment

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

Converting it to an error means I can convert a succeeding test into a failing test – which is how it should be.
Good catch.

@kikofernandez
Copy link
Contributor

test suite seems to complain that there is a missing clean target in the Makefile:

Found Makefile in ./encore/modules. Running!
make[3]: *** No rule to make target `clean'.  Stop.
           make | ../../../../release/encorec DeepImporter.enc -I lib:otherlib
           make | ../../../../release/encorec FarImporter.enc -I lib:otherlib
           make | ../../../../release/encorec DupImporter.enc -I lib:otherlib
           make | Warning: Module DupLib found in multiple places:
           make | -- lib/DupLib.enc
           make | -- otherlib/DupLib.enc
           make | ../../../../release/encorec Qualified.enc -I lib:otherlib



compressModules :: ModuleMap -> Program
compressModules = foldl1 joinTwo
Copy link
Contributor

Choose a reason for hiding this comment

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

does this work (in the sense that you are guaranteed to have at least 2 Programs) because you are always adding the String module? (in the future, you will add stds)

Copy link
Author

Choose a reason for hiding this comment

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

Are you referring to fold1? It requires only one element in the list.

Copy link
Contributor

Choose a reason for hiding this comment

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

you are right, sorry. I thought it requires two arguments by default.

@supercooldave
Copy link
Author

supercooldave commented May 27, 2016

Regarding Makefile problem. I blame Stephan!
In any case, it's now fixed.

(Left err, warnings) -> (Left err, warnings)

-- addEnvironment :: (Either TCError Program, [TCWarning]) -> (Either TCError (Environment, Program), [TCWarning])
Copy link
Contributor

Choose a reason for hiding this comment

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

remove unless you are planning on using this in the next iteration of the module system

Copy link
Author

Choose a reason for hiding this comment

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

Gone.

@kikofernandez
Copy link
Contributor

kikofernandez commented May 27, 2016

I have finished with the PR and will check only the incremental changes. After that, this PR has my blessing and will be merged (probably Monday, I am taking the weekend off)

@supercooldave
Copy link
Author

@kikofernandez I addressed your comment about commented out debugging code in a better way (in last push).

@kikofernandez
Copy link
Contributor

Merging in 1h

@kikofernandez kikofernandez merged commit 4ba922e into parapluu:development May 30, 2016
@kikofernandez kikofernandez deleted the modules branch May 30, 2016 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include guards missing - can't import same bundle twice in a dependency tree
2 participants