1. Phix : is not used
- Posted by ChrisB (moderator) Apr 01, 2018
- 1091 views
Hi Pete,
While converting an eu library to Phix, I got the following error
type is_integer(object s) ^ is not used.
Having worked out that is_ was not the issue (!), I narrowed it to (much clipped)
type is_integer(object s) --code end type ifdef WINDOWS then --code else ifdef LINUX then --code some functions in one of the functions if is_integer(....) then end if end ifdef
Running on windows the Linux ifdef is never used, so Phix halted.
Adding
ifdef Linux then type is_integer(object s) --code end type end ifdef
solved the issue, but does this fall in the category of bug (should Phix stop if a type isn't used), poor coding on the lib authors part (no disrespect intended), or a tip when using Phix (if you define a type, always use it at least once)
Cheers Chris
Ps
type is_integer(object s) --code end type if is_integer(1) then end if
also works
PPS
I also note that t_digit, a predefined type in Eu isn't defined in Phix, which doesn't necessarily need to be phixed, but worthwhile noting that there are several predifined types not included by Phix. Could add types.e to Phix programs on an adhoc basis as the user needed them (although I haven't checked this for compatability)
Cheers Chris
2. Re: Phix : is not used
- Posted by petelomax Apr 01, 2018
- 1030 views
type is_integer(object s) ^ is not used.
does this fall in the category of bug (should Phix stop if a type isn't used)
Yes, that is a looong-standing issue.
or a tip when using Phix (if you define a type, always use it at least once)
if is_integer(1) then end if
Yes, that's exactly the sort of thing I end up doing.
Technical details: pEmit2.e scans the IL, performing type propagation and marking routines as used/not used, so it can omit them when not needed. However, to cope with the slightly implicit way that type routines are called it collects all types up front. Problem is, if they are not actually used, the parameter type(s) never get set, and that can cause all manner of trouble when emitting code - since it now "knows" it is not an integer, not a float, not a string, and not a sequence, so it ends up doing things like not emitting any code, but then trying to backpatch some jump that it never emitted - and like 200 other weird variants of that sort of thing.
There is a similar gotcha: when all calls to a routine (ie type or function or procedure) get optimised away. Most times that's fine, but some times it ain't. If you ever see
if "abc"="def" then <call some routine> end if
that is now my standard way of working around this persistent little nasty beast. (It forces the compiler to emit code that will be analyzed, but won't actually ever execute.)
Another possible little "trick" is to declare a routine_id("whatever") which causes the compiler to mark the routine as a possible target of call_proc/func, which forces all the parameters to be treated as if they were passed in values of the "object" type, however that can sometimes cause sub-optimal code to be emitted.
I really should do something about this... but don't hold your breath, I've known about this for at least five years already.
Pete
3. Re: Phix : is not used
- Posted by ChrisB (moderator) Apr 01, 2018
- 1013 views
Good to know,
Cheers Chris