Skip to content

Conversation

@cebernardi
Copy link
Contributor

PR for #1062


var (
validGCOptions = []string{"none", "leaking", "extalloc", "conservative"}
validSchedulerOptions = []string{"tasks", "coroutines"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"none" is also a valid scheduler option

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaddr2line oh I see.. so I think I should also modify this line https://github.com/tinygo-org/tinygo/blob/master/main.go#L713 and this line: https://github.com/tinygo-org/tinygo/blob/master/compileopts/config.go#L132

can you please confirm?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes those should be updated. You could add it to this PR: even though it's somewhat separate it's a small and obvious fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaddr2line @aykevl done!

// ErrSchedulerInvalidOption is an error raised if scheduler option is not valid
ErrSchedulerInvalidOption = fmt.Errorf(`invalid scheduler option: valid values are %s`,
strings.Join(validSchedulerOptions, ", "))
//ErrPrintSizeInvalidOption is an error raised if size option is not valid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need a space before the first word in a doc comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

main.go Outdated
Programmer: *programmer,
}

err := options.Verify()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure whether this is the right place to put this, as we continue modifying the options after this.

What do you think @aykevl ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had this doubt as well, I put it here because it looked to me that after this line nothing was setting GC, Scheduler or PrintSize.. very curious to see what's you thoughts are..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it should be done when the options object is finished building and won't be modified anymore.

Looking down below I see that there is also a custom check for panicStrategy. I think it would make sense to move that one to the common Verify function too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aykevl I moved panicStrategy check under options as well, and removed it from main.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aykevl @jaddr2line I've also moved options.Validate call later in the code..
I'm still unsure about it, because a few lines later, in the "build" case of the switch, options.Target is modified.

Another option could be moving the option check into builder.NewConfig...
what do you guys think?

Copy link
Contributor Author

@cebernardi cebernardi May 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aykevl @jaddr2line what do you think about moving the options.Verify block into builder.NewConfig?
The more I think about it, the more it looks to me the right place 🤔

@niaow
Copy link
Member

niaow commented Apr 26, 2020

The macos build failure appears to have been caused by a partial CircleCI outage, which has since been fixed.

@niaow niaow changed the title 1062 flag error reporting compileopts: improve error reporting of unsupported flags Apr 26, 2020
@cebernardi cebernardi requested a review from niaow April 26, 2020 16:11
@cebernardi cebernardi requested a review from aykevl May 1, 2020 21:36
@aykevl
Copy link
Member

aykevl commented May 11, 2020

I think the current Verify call is fine. You could make a NewOptions, but I think a NewX function is mainly useful for initializing private fields or when complicated logic is required. In this case the contents of Options is public, and is intended to be public. The struct fields are the public API.

I think this PR is fine as it is right now and could be squashed/merged. If I were to suggest any changes, it would be the following:

  • Do not export the errors as globals, in my view they are an implementation detail (the errors are intended to be shown directly to the user, and not intended to be interpreted by the API consume).
  • In fact, I think it's better to generate error values on the fly so that you can include the invalid flag. For example, if you use -panic=foo, you get error: invalid panic option foo: valid values are print, trap. This improvs the user experience.
  • With this, the current tests become a lot harder. Honestly I don't see the value in testing here. Testing is important in many parts of the code (especially in complicated algorithms), but in this case there are no complicated APIs to test. The tests also get in the way of adding/removing options.

@cebernardi
Copy link
Contributor Author

@aykevl probably I didn't explain myself, I apologies for this.
My question was:
Do we want to call options.Verify() in main.go, or do we prefer to call options.Verify() as a first thing in builder.NewConfig method?

builder.NewConfig takes an Option parameter, so I thought it was a good spot.

Regarding your other suggestions, no problem, I'll change the error generation to include the offending value 👍

@cebernardi
Copy link
Contributor Author

@aykevl I've unexported the errors (actually, I got rid of them at all) and included the incorrect option value in the message.

Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you for the updates!

@aykevl aykevl merged commit aff260f into tinygo-org:master May 16, 2020
@aykevl
Copy link
Member

aykevl commented May 16, 2020

Oops I didn't pay attention and I accidentally merged this into master. It should be fixed now.

@niaow niaow added this to the v0.14 milestone Jun 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants