Make GHCi load a source file in any state, and just throw errors at runtime [duplicate] - haskell

I swear I saw a new feature in a recent set of GHC release notes - but now I can find no reference to it. Am I delusional, or does this feature actually exist?
It was to do with loading incomplete modules. As best as I can remember, it allows you to turn off compilation errors due to undefined variables. (Naturally, at run-time this causes an exception to be thrown if you try to actually use the undefined variables for anything.) Does that sound familiar? Or is my mind making this up?

You are looking for a compile time option, vs a language extension, of "defer errors to runtime". That is, compile with -fdefer-type-errors.

Related

Recordwildcards crashes at runtime in yesod app

I ran into the following error which is quite surprising. I added a field to the AppSettings in a Yesod app (using the Yesod scaffholding) and to my surprise, everything compiled even though I didn't do anything else (I was expecting to have to add somewhere a default value to the construction of AppSettings, but not). I got a runtime error instead telling me that a field was missing.
It appears that the only construction to AppSetting uses the RecordWildCards extension and looks like AppSettings{..}. Not defining the new field didn't generate an error but a warning (I didn't see it, because I was running test in continuous mode using stack test --file-watch). How is that possible ?
I try to reproduce the problem in a simple file and I get an error not a warning. So why do I get a warning for Yesod ? Is it a compilation flag or something ?
Edit
This is not specific to Yesod. I've made the test again with a simple file and it generates a warning not an error.
According to changelog in GHC, "that not a bug, it's a feature": https://ghc.haskell.org/trac/ghc/ticket/5334
You can change this behavior by changing type of your fields to strict (prepend a ! to type name - like !Int) - however, then you lose laziness (more about effects of strict types: Advantages of strict fields in data types)
Of course, you can also make it an error by slamming in -Werror compilation option, but then you need to be very strict about your code (no unused imports, no unused variables, even when unpacking a record etc.), or get rid of -Wall and turn on only warnings you perceive as important.

Getting a strange error from winnt.h?

I'm trying to write an x2 camera driver for a Hamamatsu camera in Visual Studio 2015. The X2 driver template already has windows.h included as an external dependency, but when trying to include a necessary header file, it throws an error that windows.h is not included (along with 80 or so errors of function calls that therefore don't exist). But when I include windows.h, I think it's causing a double include and is throwing this error:
Severity: Error (active)
Code: none
Description: expected an identifier Project :x2camera
File: c:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um\winnt.h
Line: 524
I'm really new to working with Visual Studio projects - how can I include windows.h into the file so it can get the functions and declarations it needs without actually including it and causing a double inclusion? Like I said, it's in the "project dependencies" list, and I think it's being included in another file (but I'm having a hard time finding that).
Or is that not even my problem?
Any help is appreciated.
​No idea what the problem was but I somehow managed to get it to compile. I think it needed to be included elsewhere first, then built, then included where it needed to be... which doesn't make sense honestly but maybe it was an error with how the inclusion was functioning.
Either way, my question is now resolved, though the questions that now arise such as "why the heck did this work" are baffling.

Visual Studio 2012 undocumented warning C4447

dllmain.cpp(16): warning C4447: 'main' signature found without threading mode
l. Consider using 'int main(Platform::Array<Platform::String^>^ args)'.
Above is a warning I got from building a Windows Store App DLL project. I didn't change anything in that default dllmain.cpp file except for including my own version of pch.
The documentation for this warning (along with many VS2012 errors/warnings) is nowhere to be found on MSDN and here is the only relevant link I can find:
http://social.msdn.microsoft.com/Forums/en-US/vssetup/thread/6daa9587-fe54-4e84-a8b9-0e5c52c2f6e8/
and the op there didn't get an answer.
If anyone knows what it means and how to fix it, it would be great!
As far as I can tell, you can safely ignore the warning. The compiler cribs when it sees a Win32-style DllMain being compiled using the /ZW flag (Consume Windows Runtime Extensions). However, the function gets called as you'd normally expect.
Alternatively, you can work around the warning by compiling dllmain.cpp without /ZW. You might need to adjust the PCH settings for this to properly work. This is the path taken by the DLL (Windows Store apps) C++/CX project template in Visual Studio.
Incidentally, the reason you do not get the warning when you're trying to build a Windows Runtime Component project (which builds everything using /ZW) is that a Windows Runtime Component doesn't declare a DllMain. This is not to say that it can't; it just picks up the dummy DllMain that the CRT defines (which basically turns off per-thread initialization and reports success).

Android: Cannot load library

I am facing a situation of which I have no idea. I am tried to test one method that I have implemented in C++ and I used swig to generate the wrapper. After compilation, when I tried to run the application, I got an error java.lang.UnsatisfiedLinkError.
It further states that
cannot load library:reloc_library[1311]:33
cannot locate '_Z13recognizeFacePKcS0_'
...
and suddenly throw exception.
I tried using adb shell to debug and found library in the right location (data/data/com/mesh/faceAuth/lib/libfaceAuth.so) but it gives the same error. I also read from this site, that it has to do with wrong STL implementation which I don't have any clue of. I will highly appreciate your candid suggestion.
Regards,
Mohammed.
Best guess with what information you have provided, The library you are trying to load needs some dependencies to be loaded before it.
For example:
System.loadLibrary("bullet");
System.loadLibrary("irrlicht");
System.loadLibrary("gamescript");
gamescript library needs other 2 library to be loaded before it. Otherwise, it gives me the same error you have mentioned. I can dig further on this issue if you can post some part of your .mk file for building the library here.
Your error has nothing to do with STL.
You probably reference a global function ::recognizeFace(char const*, char const*) in your code. Maybe, you have another function defined, for example recognizeFace(char*, char*).

How can I switch off exception handling in MSVC?

Does anybody know how to switch off exception handling option in MSVC? I tried to set the option 'Enable C++ exceptions' to 'NO' and I got warning:
warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc.
I would like to switch off the exception handler, too, but I don't know how.
In my application I basically need more speed than stability, therefore I chose switching off the exception handling. I do not have any try/catch blocks, but I do use STL. When I switch the option 'Enable C++ exceptions' to 'NO' is there any way how to get rid of those warnings?
Most likely you're including one or more standard C++ headers that contain try/catch. The most typical case would be <iostream> - you will get this error on a file which consists of a single line that just includes that. Any other stream header will also do, as will locales.
If you look closely at the error message, it should reference two filenames, not one - your file, and the included file with the error. E.g. in my sample case of #include <iostream>, I get this:
except.cpp
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\xlocale(342) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
If you really don't want exceptions in the STL that will be linked to your program, define _HAS_EXCEPTIONS=0 in your whole project. Better than compiling your code with /EHsc if you don't plan on adding exception handling.
That warning means that you told the compiler you're not going to use exceptions yet you have a try {} catch() {} block in the code. It informs you that although you have that block, if an exception is thrown no desctructors are going to be executed. Turning exceptions off means exactly that - the compiler doesn't produce code for automatic destruction when the stack is unwound in the event of an exceptions.
In Visual Studio, /EH is found at Configuration Properties âž” C/C++ âž” Code Generation âž” Enable C++ Exceptions.
Switching off exceptions is quite hard, as you're dealing with C++ here. It's really in the same category as switching off NULL pointers - how are you going to handle memory allocation failure, for instance?
That said, /EH specifies which exception handling model you want, and "none" is not an option. You can pick /EHa, /EHs, /EHac and /EHsc - [a]ynchronous with or without support for throwing extern "C" functions.
Do you still have try/catch block(s) in your code?
The first thing to do when you get stuck is look up the error on MSDN and/or Google for it. That usually helps. This is what MSDN says:
When the /EHsc option has not been enabled, an object with automatic storage in the frame, between the function doing the throw and the function catching the throw, will not be destroyed. However, an object with automatic storage created in a try or catch block will be destroyed. [...]
Using MSVC aka CL one can simply use the /kernel switch or not have any /EH switch. Windows C/C++ MSVC builds always have SEH. SEH is inbuilt in Windows.
If #if _HAS_EXCEPTIONS == 0 , MS STL will simply switch to SEH.
Is that standard C++? No it is not. Three keywords will be missing: try, throw and catch. And you need to learn about SEH.
So is that a "good thing"? Well for Windows low level C++, SEH is a good thing.
ps: It is not advisable to use /kernel switch, outside of kernel developments.

Resources