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

Internal error typechecking non-terminating function on case-insensitive filesystem #5508

Closed
james-smith-69781 opened this issue Aug 12, 2021 · 12 comments · Fixed by #5510
Closed
Assignees
Labels
file system Interactions between Agda's module system and the actual OS file system internal-error Concerning internal errors of Agda platform:macOS Any issue specific to macOS platform: windows Any issue specific to Microsoft Windows regression in 2.6.2 Regression that first appeared in Agda 2.6.2 type: bug Issues and pull requests about actual bugs ux: error reporting Issues to do with how Agda reports errors
Milestone

Comments

@james-smith-69781
Copy link

james-smith-69781 commented Aug 12, 2021

Working through the tutorial at http://www.cse.chalmers.se/~ulfn/papers/afp08/tutorial.pdf , I wanted to see the error given by 'fold'. Here is the somewhat-minimized code:

module Universesbug where

data Functor : Set₁ where

[_] : Functor  (Set  Set)

map : (F : Functor){X Y : Set}  (X  Y)  [ F ] X  [ F ] Y

data μ_ (F : Functor) : Set where
  <_> : [ F ] (μ F)  μ F

fold : (F : Functor){A : Set}  ([ F ] A  A)  μ F  A
fold F φ < x > = φ (map F (fold F φ) x)

An internal error has occurred. Please report this as a bug. Location of the error: __IMPOSSIBLE__, called at src/full/Agda/TypeChecking/Errors.hs:296:\ 18 in Agd-2.6.2-d8dfa68e:Agda.TypeChecking.Errors

Agda installed from Homebrew:

% agda --version
Agda version 2.6.2
@gallais gallais added the internal-error Concerning internal errors of Agda label Aug 12, 2021
@gallais
Copy link
Member

gallais commented Aug 12, 2021

Strange, I can't reproduce this in either 2.6.1.3 or 2.6.2

in Agd-2.6.2-d8dfa68e

I can't find this Agda commit in the git history. 🤨

Edit: I have just compiled & installed HEAD and I'm not able to reproduce the internal error either.

@gallais gallais added the status: info-needed More information is needed from the bug reporter to confirm the issue. label Aug 12, 2021
@james-smith-69781
Copy link
Author

Is there additional info I could share that would be useful?

I updated to Homebrew's HEAD version of Agda and it still reproes for me:

An internal error has occurred. Please report this as a bug.
Location of the error: __IMPOSSIBLE__, called at src/full/Agda/TypeChecking/Errors.hs:296:18 in Agd-2.6.3-1fd9406f:Agda.TypeChecking.Errors

@andreasabel
Copy link
Member

I cannot reproduce this with any of 2.6.1, 2.6.2, or 2.6.3 (dev version).

@andreasabel andreasabel added the status: invalid Not a bug (not in changelog) label Aug 13, 2021
@andreasabel
Copy link
Member

andreasabel commented Aug 13, 2021

Actually, looking at the error location, this could be a problem with case-insensitive/ignoring file systems (wild guess).

m <- fromMaybe __IMPOSSIBLE__ <$> lookupModuleFromSource f

Is the filename exactly Universesbug.agda or is it a case-variant of it?

@andreasabel andreasabel reopened this Aug 13, 2021
@james-smith-69781
Copy link
Author

james-smith-69781 commented Aug 13, 2021

@andreasabel

The file name is universesbug.agda not Universesbug.agda. My filesystem is APFS (encrypted), which is case insensitive.

agda universesbug.agda reproduces the bug, while agda Universesbug.agda results in correct behavior.

New shrunk repro is any non-termination error in a module where the case of the module name does not match the case in the invocation of agda.

casebug.agda or Casebug.agda (irrelevant):

module Casebug where

nt :  {A : Set}  A  A
nt i = nt i

% agda casebug.agda

...and...

module casebug where

nt :  {A : Set}  A  A
nt i = nt i

% agda Casebug.agda

@james-smith-69781 james-smith-69781 changed the title Internal error typechecking unterminating fold Internal error typechecking non-terminating function on case-insensitive filesystem Aug 15, 2021
@andreasabel andreasabel added ux: error reporting Issues to do with how Agda reports errors file system Interactions between Agda's module system and the actual OS file system type: bug Issues and pull requests about actual bugs and removed status: info-needed More information is needed from the bug reporter to confirm the issue. status: invalid Not a bug (not in changelog) labels Aug 17, 2021
@andreasabel
Copy link
Member

andreasabel commented Aug 17, 2021

This bug is likely caused by my work on #4828 (commit be5cafa, amended by 0eaf439, see also the repercussions it had on #4671).

@andreasabel andreasabel added this to the 2.6.3 milestone Aug 17, 2021
@andreasabel
Copy link
Member

andreasabel commented Aug 17, 2021

I can reproduce this on a FAT32-formatted USB stick, when I call agda with the case-variant of the file. (Everything works if I use the case-variant of the module.)

UPDATE (5 hrs later): Actually, this bug also exists on macOS, I could have saved myself many hours trying to get a dev env on Windows running...

@andreasabel
Copy link
Member

The moduleToSource map contains apparently the wrong AbsolutePath: rather than the original file name, one that has been constructed from the module name:

( TopLevelModuleName 
  { moduleNameRange = Range (Just (AbsolutePath {textPath = "/Volumes/FAT32/iSSue5508.agda"})) (...)
  , moduleNameParts = "Issue5508" :| []
  }
, AbsolutePath {textPath = "/Volumes/FAT32/Issue5508.agda"}
)

@andreasabel andreasabel self-assigned this Aug 17, 2021
@andreasabel andreasabel mentioned this issue Aug 17, 2021
@andreasabel andreasabel added the regression in 2.6.2 Regression that first appeared in Agda 2.6.2 label Aug 17, 2021
@andreasabel andreasabel added platform:macOS Any issue specific to macOS platform: windows Any issue specific to Microsoft Windows labels Aug 17, 2021
@andreasabel
Copy link
Member

Fixed by proactively putting the correct entry into the ModuleToSource map. Thanks for reporting, @james-smith-69781 !

@andreasabel
Copy link
Member

andreasabel commented Oct 14, 2021

The test fails in the cabal-test CI under Windows, see https://github.com/agda/agda/runs/3888327883?check_suite_focus=true.

--- "a/C:\\Users\\runneradmin\\AppData\\Local\\Temp\\iSS3936.golden"
+++ "b/C:\\Users\\runneradmin\\AppData\\Local\\Temp\\iSS3947.actual"
@@ -1,9 +1,7 @@
-customised/iSSue5508.agda:10,1-11,6
-Termination checking failed for the following functions:
-  A
-Problematic calls:
-  A (at customised/iSSue5508.agda:11,5-6)
-customised/iSSue5508.agda:29,6-8
-Cannot eliminate type  R  with projection  S.g
-when checking the clause left hand side
-test .g
+customised/iSSue5508.agda:6,8-17
+The name of the top level module does not match the file name. The
+module Issue5508 should be defined in one of the following files:
+  customised/Issue5508.agda
+  customised/Issue5508.lagda
+  agda-default-include-path/Issue5508.agda
+  agda-default-include-path/Issue5508.lagda

The golden value is the one for a case-insensitive file system, but Agda produces the error for a case-sensitive file system.

The module name is Issue5508

module Issue5508 where -- case variant intended!

but Agda is called with file name iSSue5508.agda. The error isn't surprising even for a case-insensitive FS, the question is more why it is not triggered on macOS, but only on Windows.

UPDATE: Ah, the explanation is that Agda does something OS-specific for Windows rather than doing something filesystem-specific. Hence the difference to macOS:

doesFileExistCaseSensitive :: FilePath -> IO Bool
#ifdef mingw32_HOST_OS
doesFileExistCaseSensitive f = do
doesFileExist f `and2M` do
bracket (findFirstFile f) (findClose . fst) $
fmap (takeFileName f ==) . getFindDataFileName . snd
#else
doesFileExistCaseSensitive = doesFileExist
#endif

This twist was added by Makoto (we miss you in the team!) in e46f6bf.

andreasabel added a commit that referenced this issue Oct 14, 2021
Try to entirely leave it to the filesystem whether a module name
matches a file name; do not enforce same capitalization.
andreasabel added a commit that referenced this issue Oct 14, 2021
Try to entirely leave it to the filesystem whether a module name
matches a file name; do not enforce same capitalization.
andreasabel added a commit that referenced this issue Oct 15, 2021
Try to entirely leave it to the filesystem whether a module name
matches a file name; do not enforce same capitalization.
@andreasabel andreasabel modified the milestones: 2.6.3, 2.6.2.1 Nov 19, 2021
@andreasabel
Copy link
Member

Cherry-picked onto maint-2.6.2, scheduled for 2.6.2.1.

@andreasabel andreasabel reopened this Jan 27, 2022
@andreasabel andreasabel linked a pull request Jan 27, 2022 that will close this issue
@andreasabel
Copy link
Member

(Had to reopen the issue just to link it to #5510.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
file system Interactions between Agda's module system and the actual OS file system internal-error Concerning internal errors of Agda platform:macOS Any issue specific to macOS platform: windows Any issue specific to Microsoft Windows regression in 2.6.2 Regression that first appeared in Agda 2.6.2 type: bug Issues and pull requests about actual bugs ux: error reporting Issues to do with how Agda reports errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants