gren-lang / gren-lang/compiler
Compiler optimizing out unreferenced ports causes unexpected errors
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 503
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Description
I encountered an error similar to this one when testing an application I am currently developing:
Uncaught Error: NAME_OF_PORT_FUNCTION isn't defined as a task-based port in Gren code.
The error is visible in the browser's console and prevents the application from starting.
I do have NAME_OF_PORT_FUNCTION defined as a port in a port module of my project, but it is not currently called anywhere in the project (haven't reached that far in my project yet), so I suspect the compiler removed it for optimization purposes. I don't think the compiler is wrong to do so, but the relation between that and the error message is unintuitive.
If possible, I think this would warrant a warning instead of an error (at least in the case of an actually optimized out port instead of one truly undefined). In any case, I think the error message would benefit from indicating that the cause can be optimization (e.g. NAME_OF_PORT_FUNCTION isn't defined as a task-based port or isn't referenced in the Gren code.).
I created a small example to show the issue: https://github.com/nsensfel/gren-port-issue.
Check src/Module/Update.gren for a modification that will trigger the error (command = (Module.Port.test)) or remove it (command = (Module.Port.any_test model.nothing)). The difference between the two is the former only calls one of the port functions and the latter can branch to any of them.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer in https://github.com/nsensfel/gren-port-issue and inspect src/Module/Update.gren. Compare the command = (Module.Port.test) case with command = (Module.Port.any_test model.nothing), then trace the compiler's handling of the referenced and optimized-out ports. Done means the resulting diagnostic or behavior clearly distinguishes an optimized-out port from an undefined task-based port.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100