Skip to content

Commit

Permalink
Fix visibility of imported things
Browse files Browse the repository at this point in the history
Fixes #111
Previously, if a module B imports a module A, then a module C imports B,
the public names in A would also be visible to C (i.e. B would
automatically reexport everything from A). This seems to be a bad
default.

This patch changes the default behaviour so that the only names exported
from a module are those defined in that module. If B imports A and wants
to reexport everything in A, then A should be imported with the "public"
modifier (i.e. "import public A").

Several changes have been made to the prelude, since several prelude
modules were taking advantage of the old broken behaviour.

This may cause lots of things to break. Sorry. The fix is typically just
to import the module you should have imported anyway :).
  • Loading branch information
edwinb committed Dec 13, 2014
1 parent b9e5895 commit 7b5f4aa
Show file tree
Hide file tree
Showing 29 changed files with 162 additions and 90 deletions.
1 change: 1 addition & 0 deletions libs/base/Decidable/Decidable.idr
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Decidable.Decidable

import Data.Rel
import Data.Fun

%access public

Expand Down
2 changes: 2 additions & 0 deletions libs/base/Decidable/Order.idr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Decidable.Order

import Decidable.Decidable
import Decidable.Equality
import Data.Fun
import Data.Rel

%access public

Expand Down
2 changes: 0 additions & 2 deletions libs/base/System.idr
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module System

import Prelude

%include C "unistd.h"
%default partial
%access public
Expand Down
3 changes: 1 addition & 2 deletions libs/effects/Effects.idr
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module Effects

import Language.Reflection
import Control.Catchable
import Effect.Default
import public Effect.Default

--- Effectful computations are described as algebraic data types that
--- explain how an effect is interpreted in some underlying context.
Expand Down
3 changes: 3 additions & 0 deletions libs/prelude/Decidable/Equality.idr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ module Decidable.Equality

import Builtins
import Prelude.Basics
import Prelude.Bool
import Prelude.Classes
import Prelude.Either
import Prelude.List
import Prelude.Vect
import Prelude.Nat
import Prelude.Fin
import Prelude.Maybe

Expand Down
1 change: 1 addition & 0 deletions libs/prelude/IO.idr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
%unqualified

import Builtins
import Prelude.List

%access public
Expand Down
51 changes: 27 additions & 24 deletions libs/prelude/Prelude.idr
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
module Prelude

import Builtins
import IO

import Prelude.Bool
import Prelude.Classes
import Prelude.Cast
import Prelude.Nat
import Prelude.Fin
import Prelude.List
import Prelude.Maybe
import Prelude.Monad
import Prelude.Applicative
import Prelude.Functor
import Prelude.Either
import Prelude.Vect
import Prelude.Strings
import Prelude.Chars
import Prelude.Traversable
import Prelude.Bits
import Prelude.Stream
import Prelude.Uninhabited
import Prelude.Pairs

import Decidable.Equality
import public Builtins
import public IO

import public Prelude.Algebra
import public Prelude.Basics
import public Prelude.Bool
import public Prelude.Classes
import public Prelude.Cast
import public Prelude.Nat
import public Prelude.Fin
import public Prelude.List
import public Prelude.Maybe
import public Prelude.Monad
import public Prelude.Applicative
import public Prelude.Foldable
import public Prelude.Functor
import public Prelude.Either
import public Prelude.Vect
import public Prelude.Strings
import public Prelude.Chars
import public Prelude.Traversable
import public Prelude.Bits
import public Prelude.Stream
import public Prelude.Uninhabited
import public Prelude.Pairs

import public Decidable.Equality

%access public
%default total
Expand Down
2 changes: 2 additions & 0 deletions libs/prelude/Prelude/Applicative.idr
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module Prelude.Applicative

import Builtins

import Prelude.Basics
import Prelude.Bool
import Prelude.Classes
import Prelude.Functor

Expand Down
9 changes: 8 additions & 1 deletion libs/prelude/Prelude/Bits.idr
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
module Prelude.Bits

import Builtins

import Prelude.Basics
import Prelude.Bool
import Prelude.Cast
import Prelude.Classes
import Prelude.Foldable
import Prelude.Nat
import Prelude.Strings
import Prelude.Vect
import Prelude.Bool

%access public
%default total
Expand Down
3 changes: 3 additions & 0 deletions libs/prelude/Prelude/Either.idr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import Builtins

import Prelude.Basics
import Prelude.Bool
import Prelude.Classes
import Prelude.Maybe
import Prelude.List

Expand Down
7 changes: 7 additions & 0 deletions libs/prelude/Prelude/Fin.idr
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
module Prelude.Fin

import Builtins

import Prelude.Basics
import Prelude.Bool
import Prelude.Cast
import Prelude.Classes
import Prelude.Maybe
import Prelude.Nat
import Prelude.Either
import Prelude.Uninhabited
Expand Down
1 change: 1 addition & 0 deletions libs/prelude/Prelude/Foldable.idr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Prelude.Foldable

import Builtins
import Prelude.Bool
import Prelude.Basics
import Prelude.Classes
import Prelude.Algebra

Expand Down
2 changes: 2 additions & 0 deletions libs/prelude/Prelude/List.idr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Builtins

import Prelude.Algebra
import Prelude.Basics
import Prelude.Bool
import Prelude.Classes
import Prelude.Foldable
import Prelude.Functor
import Prelude.Maybe
Expand Down
3 changes: 3 additions & 0 deletions libs/prelude/Prelude/Maybe.idr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module Prelude.Maybe

import Builtins
import Prelude.Algebra
import Prelude.Basics
import Prelude.Bool
import Prelude.Cast
import Prelude.Classes
import Prelude.Foldable

%access public
Expand Down
1 change: 1 addition & 0 deletions libs/prelude/Prelude/Nat.idr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Prelude.Nat
import Builtins

import Prelude.Algebra
import Prelude.Basics
import Prelude.Bool
import Prelude.Cast
import Prelude.Classes
Expand Down
4 changes: 4 additions & 0 deletions libs/prelude/Prelude/Stream.idr
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module Prelude.Stream

import Builtins

import Prelude.Basics
import Prelude.Functor
import Prelude.Nat
import Prelude.Vect

%access public
Expand Down
9 changes: 8 additions & 1 deletion libs/prelude/Prelude/Strings.idr
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
module Prelude.Strings

import Builtins
import Prelude.List

import Prelude.Algebra
import Prelude.Basics
import Prelude.Bool
import Prelude.Chars
import Prelude.Cast
import Prelude.Classes
import Prelude.Either
import Prelude.Foldable
import Prelude.Functor
import Prelude.List
import Prelude.Nat

||| Appends two strings together.
|||
Expand Down
4 changes: 4 additions & 0 deletions libs/prelude/Prelude/Traversable.idr
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
module Prelude.Traversable

import Builtins

import Prelude.Basics
import Prelude.Applicative
import Prelude.Foldable
import Prelude.Functor

traverse_ : (Foldable t, Applicative f) => (a -> f b) -> t a -> f ()
traverse_ f = foldr (($>) . f) (pure ())
Expand Down
6 changes: 5 additions & 1 deletion libs/prelude/Prelude/Vect.idr
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
module Prelude.Vect

import Builtins

import Prelude.Basics
import Prelude.Bool
import Prelude.Fin
import Prelude.Foldable
import Prelude.Functor
import Prelude.Maybe
import Prelude.List
import Prelude.Classes
import Prelude.Nat
import Prelude.Bool
import Prelude.Uninhabited

%access public
Expand Down
13 changes: 7 additions & 6 deletions src/Idris/AbsSyntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ addAutoImport fp = do i <- getIState
addHdr :: Codegen -> String -> Idris ()
addHdr tgt f = do i <- getIState; putIState $ i { idris_hdrs = nub $ (tgt, f) : idris_hdrs i }

addImported :: FilePath -> Idris ()
addImported f = do i <- getIState
putIState $ i { idris_imported = nub $ f : idris_imported i }
addImported :: Bool -> FilePath -> Idris ()
addImported pub f
= do i <- getIState
putIState $ i { idris_imported = nub $ (f, pub) : idris_imported i }

addLangExt :: LanguageExt -> Idris ()
addLangExt TypeProviders = do i <- getIState
Expand Down Expand Up @@ -382,7 +383,7 @@ addNameIdx' i n
getHdrs :: Codegen -> Idris [String]
getHdrs tgt = do i <- getIState; return (forCodegen tgt $ idris_hdrs i)

getImported :: Idris [FilePath]
getImported :: Idris [(FilePath, Bool)]
getImported = do i <- getIState; return (idris_imported i)

setErrSpan :: FC -> Idris ()
Expand Down Expand Up @@ -1576,8 +1577,8 @@ aiFn inpat expat qq ist fc f ds as
_ -> True

getAccessibility n
= case lookupDefAcc n False (tt_ctxt ist) of
[(n,t)] -> t
= case lookupDefAccExact n False (tt_ctxt ist) of
Just (n,t) -> t
_ -> Public

insertImpl :: [PArg] -> [PArg] -> [PArg]
Expand Down
4 changes: 2 additions & 2 deletions src/Idris/AbsSyntaxTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ data IState = IState {
idris_libs :: [(Codegen, String)],
idris_cgflags :: [(Codegen, String)],
idris_hdrs :: [(Codegen, String)],
idris_imported :: [FilePath], -- ^ Imported ibc file names
idris_imported :: [(FilePath, Bool)], -- ^ Imported ibc file names, whether public
proof_list :: [(Name, [String])],
errSpan :: Maybe FC,
parserWarnings :: [(FC, Err)],
Expand Down Expand Up @@ -259,7 +259,7 @@ data IBCWrite = IBCFix FixDecl
| IBCMetavar Name
| IBCSyntax Syntax
| IBCKeyword String
| IBCImport FilePath
| IBCImport (Bool, FilePath) -- True = import public
| IBCImportDir FilePath
| IBCObj Codegen FilePath
| IBCLib Codegen String
Expand Down
2 changes: 1 addition & 1 deletion src/Idris/Chaser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ buildTree built fp = btree [] fp
(_, modules, _) <- parseImports f file
-- The chaser should never report warnings from sub-modules
clearParserWarnings
ms <- mapM (btree done) [realName | (realName, alias, fc) <- modules]
ms <- mapM (btree done) [realName | (_, realName, alias, fc) <- modules]
return (concat ms)
else return [] -- IBC with no source available
-- (\c -> return []) -- error, can't chase modules here
2 changes: 1 addition & 1 deletion src/Idris/Core/Evaluate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ isTCDict n ctxt

lookupP :: Name -> Context -> [Term]
lookupP n ctxt
= do def <- lookupCtxt n (definitions ctxt)
= do def <- lookupCtxt n (definitions ctxt)
p <- case def of
(Function ty tm, a, _, _) -> return (P Ref n ty, a)
(TyDecl nt ty, a, _, _) -> return (P nt n ty, a)
Expand Down
Loading

0 comments on commit 7b5f4aa

Please # to comment.