[ragel-users] "declared but not used" errors with v7 Go backend

Damian Gryski dgryski at gmail.com
Wed Dec 5 12:11:10 UTC 2018


You can prefix the underscore assignments with var also.  That will work
both at the function and global scopes.

var _scanner_trans_cond_spaces [] int8  = [] int8  { ... }
var _ =  _scanner_trans_cond_space

On Wed, Dec 5, 2018 at 6:31 AM Adrian Thurston <thurston at colm.net> wrote:

> Hi Damian,
>
> I just altered the codegen so that unused arrays are not generated. This
> eliminates the need to assign to _ for the static arrays. The need is still
> there for static variables, for example:
>
>     _ = scanner_first_final
>     _ = scanner_error
>     _ = scanner_en_main
>
> I've noticed though that the _ assignment trick isn't valid for arrays
> that are not in a function scope, which means we can't use it right after
> declaration. It could go into the write exec block or the write init block
> though. To do that I'll have to create a dedicated reference statement for
> the intermediate language since the go code generator does not understand
> the state machine. It's just a language translation. The reference
> statement can have no effect in other languages.
>
> For the time being I'll need to revert the _ assignment since it breaks
> ragel programs where the data is not function scoped.
>
> Adrian
>
> On 2018-11-01 09:12, Damian Gryski wrote:
>
> This is with ragel 7.0.0.11 and colm 0.13.0.6.  I was unable to get ragel
> to build from git.
>
> With the example grammar at github.com/dgryski/ragel-examples/regexp1, I
> get the following error:
>
> $ ragel-go sshd.rl
> $ go build
> # github.com/dgryski/ragel-examples/regexp1
> ./sshd.go:11:6: _scanner_trans_cond_spaces declared and not used
> ./sshd.go:12:6: _scanner_trans_offsets declared and not used
> ./sshd.go:13:6: _scanner_trans_lengths declared and not used
> ./sshd.go:14:6: _scanner_cond_keys declared and not used
> ./sshd.go:17:6: _scanner_eof_cond_spaces declared and not used
> ./sshd.go:18:6: _scanner_eof_cond_key_offs declared and not used
> ./sshd.go:19:6: _scanner_eof_cond_key_lens declared and not used
> ./sshd.go:20:6: _scanner_eof_cond_keys declared and not used
> ./sshd.go:21:6: _scanner_nfa_targs declared and not used
> ./sshd.go:22:6: _scanner_nfa_offsets declared and not used
> ./sshd.go:22:6: too many errors
>
> The usual solution to this in autogenerated code is to assign them to `_`,
> the underscore "blank variable".  This satisfies the compiler and the
> entire array will be eliminated as a dead-store if it ends up not being
> used.
>
> Thus, each declaration for variables which may or may not be used will
> look like:
> var _scanner_trans_cond_spaces [] int8  = [] int8  { ... }
> _ = _scanner_trans_cond_space
>
> Note also the first `[] int8` is redundant -- the compiler will infer the
> type from the type of the array on the right hand side of the `=`.
>
> Fixing these issues in the Go template in the src/host-go directory and
> rebuilding fixed these errors (although I had to copy files from the git
> checkout for the template changes to recompile successfully).
>
> Damian
>
> _______________________________________________
> ragel-users mailing listragel-users at colm.nethttp://www.colm.net/cgi-bin/mailman/listinfo/ragel-users
>
> _______________________________________________
> ragel-users mailing list
> ragel-users at colm.net
> http://www.colm.net/cgi-bin/mailman/listinfo/ragel-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.colm.net/pipermail/ragel-users/attachments/20181205/630e1a05/attachment.html>


More information about the ragel-users mailing list