a_iscompiled v2a082+ Topic is solved

Discuss the future of the AutoHotkey language
coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

a_iscompiled v2a082+

19 Jan 2018, 22:25

I'm gonna risk the bite and post this here.
Can't find any changes relating to this, not sure if it extends to other a_ variables.

For an uncompiled script containing

Code: Select all

if (a_iscompiled)
	msgbox("is compiled")
else
	msgbox("not compiled")
and
A_IsCompiled — Contains 1 if the script is running as a compiled EXE and an empty string (which is considered false) if it is not.
In v2a081-cad307c "not compiled" is displayed.
In v2a commit 343fbb9, date 17-11-26, "not compiled" is displayed.

In v2a082-fffc60d and beyond "is compiled" is displayed.


Can someone else try to test this to confirm it's happening and is not some weird crap going on in my setup.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: a_iscompiled v2a082+

20 Jan 2018, 01:34

2.0-a083-97803ae

Code: Select all

msgbox(a_iscompiled == a_traymenu) ; 1
cheers ☕
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: a_iscompiled v2a082+

20 Jan 2018, 02:30

I think you're right. This returns true: MsgBox(IsObject(A_IsCompiled)).

Code: Select all

;results where obtained with an *uncompiled* script
;tested on AHK v2a082-fffc60d
MsgBox(a_iscompiled) ;blank
MsgBox(A_IsCompiled) ;blank
MsgBox(StrLen(a_iscompiled)) ;0
MsgBox(StrLen(A_IsCompiled)) ;0
MsgBox(a_iscompiled ? "y" : "n") ;y
MsgBox(A_IsCompiled ? "y" : "n") ;y
vText := ""
MsgBox(vText ? "y" : "n") ;n
MsgBox(vText ? "y" : "n") ;n
MsgBox(IsObject(a_iscompiled)) ;1 ;could this be the problem?
MsgBox(IsObject(A_IsCompiled)) ;1 ;could this be the problem?
if (a_iscompiled)
	msgbox("is compiled") ;(this triggered)
else
	msgbox("not compiled") ;(not this)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: a_iscompiled v2a082+  Topic is solved

20 Jan 2018, 20:36

This issue is caused by a compiler optimization called "COMDAT folding".

On non-compiled builds, BIV_IsCompiled and BIV_TrayMenu have the same implementation: just return an empty string. This is because the BIV interface only supports strings, and all objects are treated as "" when used in that context. The actual implementation of A_TrayMenu is in the expression evaluator, and is dependent on mBIV == &BIV_TrayMenu.

With COMDAT folding, identical functions (that is, functions with the exact same machine code implementation) are "folded", such that you're actually calling the same address. So in this case, mBIV == &BIV_TrayMenu and mBIV == &BIV_IsCompiled are both true.

An interesting side note is that since True, False, A_PtrSize and A_IsUnicode are optimized by comparing the address in mBIV and replacing them with the corresponding constant value at load time, any BIV functions identical with those will be optimized as well. So for instance, if v2 had an ANSI build, A_IsCompiled would automatically be resolved to "" at load time, because its compiled form would be identical to A_IsUnicode (but only in ANSI builds). I didn't optimize A_IsCompiled this way because it isn't used in (performance-critical) expressions much, and there is a small cost to code size.

There seems to be some disagreement about whether the change in behaviour caused by this optimization complies with or violates the C++ standard.

Either way, I'll work around it (to fix the bug).

Edit: Fixed by v2.0-a084.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: a_iscompiled v2a082+

21 Jan 2018, 09:50

That doesn't sound like an easy catch, well done and thanks for the explaination. :shock:

Cheers.

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 67 guests