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

Include guards missing - can't import same bundle twice in a dependency tree #329

Closed
Bearmarshal opened this issue Feb 9, 2016 · 13 comments · Fixed by #443
Closed

Include guards missing - can't import same bundle twice in a dependency tree #329

Bearmarshal opened this issue Feb 9, 2016 · 13 comments · Fixed by #443
Assignees

Comments

@Bearmarshal
Copy link

There seem to be no include guards in any of the generated C files, leading to problems with a nestled dependency tree, such as the following:

  Foo
  / \
Bar Frob
  \ /
  Main

The error is trivial to trigger, just import the same bunde twice in a file:

bundle Foo where

passive class Foo {}
import Foo
import Foo

class Main {
  def main() : void {
    print(42);
  }
}

This also causes a circular dependency to throw the compiler into an infinite loop:

bundle InfiniteImport where
import InfiniteImport

class Main {
  def main() : void {
    print(42);
  }
}
@supercooldave
Copy link

I do mean to address this as a part of the module system, but development is (too) slow.
If you can think of a quick hack to deal with this, we'd be happy to #linclude it.

@Bearmarshal
Copy link
Author

Would inserting #pragma once into each generated .h file work?

@supercooldave
Copy link

Perhaps .. maybe you could try on the generated C.
This would be an easy fix – I'm sure one of us could quickly implement it.

@Bearmarshal
Copy link
Author

The duplication is caught during typechecking, though, so you would have to turn that off before getting any generated C...

@supercooldave
Copy link

Argh!

@EliasC
Copy link
Contributor

EliasC commented Feb 9, 2016

@Bearmarshal: I'm pretty sure there is only ever a single .h file generated, even when including modules.

@Bearmarshal
Copy link
Author

You are right. I guess that makes stuff less trivial then...

Perhaps surrounding all declarations made by a single bundle with

#ifndef BUNDLE_BundleName
#define BUNDLE_BundleName
...
#endif

I assume this would require some additional work, though, like keeping a separate list of declarations per bundle keyword, or so...

@Bearmarshal
Copy link
Author

What are the arguments for not using multiple .h files?

@EliasC
Copy link
Contributor

EliasC commented Feb 9, 2016

One way forward could be to check for duplicate classes when merging the class tables of different modules, and if they are from the same file, only keep one of them (and in the other case, rightfully give an error message and wait for @supercooldave's module system to provide namespaces). This information should be available in the SourcePos meta-information of the AST nodes.

@EliasC
Copy link
Contributor

EliasC commented Feb 9, 2016

@Bearmarshal: As far as I can see, your problem is not at the C-level (yet) but rather on the Encore level. The simplest solution would be one that only required changes to one of them.

@Bearmarshal
Copy link
Author

I've actually promised myself to not dig into the compiler source code (I would probably disappear from the face of Earth for a month if I did), so I'll wait.

@EliasC
Copy link
Contributor

EliasC commented Feb 9, 2016

@Bearmarshal: But you want to get rid of the "Duplicate definition of ..." from encorec, right? You are not getting clang errors?

@Bearmarshal
Copy link
Author

Yes, I want. And no, I'm not.

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 a pull request may close this issue.

4 participants