Skip to content

troubleshooting a non-deterministic outcome #13

@maverickwoo

Description

@maverickwoo

I recently started noticing gorewrite has a non-deterministic behavior: in one project, it fails to generate the correct output often, with a failure rate of about 80% in that project; however, it will eventually succeed in generating the correct output if I run it enough number of times (and so I have a script to check after each run and repeat if necessary).

The project is somewhat big and so I am still finding time to pare it down to a toy example to show the problem. Plus, since I can manage to get the correct output by repeating runs until success, it is not super high priority to me due to delivery deadlines.

With some preliminary investigations, I notice all the failures has to do with extra line breaks after return. Examples of bad output:

Example 1. (bad)

	return

	sb.String()

Example 2. (bad)

			return
			i - 1

In general, I am noticing a lot of extra line breaks in the generated code. Most of them are survivable in Go's syntax, but some like the above are not.

Example 3. (survivable)

			rv = append(
				rv,
				a)

Since I think this may hit some other users and maybe you have insights into this issue, may I ask if you have any advice on where such non-determinism can creep in and how I would troubleshoot this? I realize it could totally be a bug in go/ast, but I thought I could check with you first since I first encounter it in gorewrite.

Thanks!

P.S. A bit of information for repro in the future:

$ go version
go version go1.10 darwin/amd64

My genericis at git cd81575 and golang.org/x/tools is at 96caea4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions