Skip to content

Compiler optimizing out unreferenced ports causes unexpected errors #381

Description

@nsensfel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions