News for hackers. Stuff that matters.
Re:Deadcode: Finding unreachable functions in Go by vbezhenar on Tuesday January 23, 2024 @02:28PM (#39108392)
IMO tree-shaking and similar stuff must be not an afterthought, but instead built into language and tooling from the day one.
Re:Deadcode: Finding unreachable functions in Go by icholy on Tuesday January 23, 2024 @02:53PM (#39108802)
Seems like you're conflating two separate things here. The Go compiler has a DCE pass which prevents unused code from ending up in the binary. The linked blog-post describes a tool for identifying unused code in your codebase. Two completely separate use-cases.
Re:Deadcode: Finding unreachable functions in Go by BoppreH on Tuesday January 23, 2024 @02:58PM (#39108884)
I agree that "changes the generated binary" and "displays information to the user" are separate use cases, but the compiler already does both. There's even a compiler error for unused imports and variables.

Doesn't seem far-fetched to ask for the compiler to warn on unused types/functions too.

Re:Deadcode: Finding unreachable functions in Go by icholy on Tuesday January 23, 2024 @03:14PM (#39109102)
It's not that simple. The Go compiler uses a main package as its entry point when compiling a binary. A module can have a many main packages each using different subsets of the library packages.

So there are two choices here:

    1. The Go compiler complains about code which is unused by the current main package.
    2. The Go compiler tries to find/compile all main packages every-time.
Both of these options suck.
Re:Deadcode: Finding unreachable functions in Go by kyrra on Tuesday January 23, 2024 @02:41PM (#39108614)
One nice thing about go is that it ships with an AST package for parsing go code. It allows building of tooling really easily.

https://pkg.go.dev/go/ast

Re:Deadcode: Finding unreachable functions in Go by fransje26 on Tuesday January 23, 2024 @02:41PM (#39108609)
Do you happen to know languages that implement that? I vaguely remember remember some Zig post on the topic, but I don't remember if it was an idea exploration, or an implemented feature.
Re:Deadcode: Finding unreachable functions in Go by marcosdumay on Tuesday January 23, 2024 @02:42PM (#39108627)
I can't name any language that was born with it.

Most have it on the standard tools, but I don't think any language was born with it.

Re:Deadcode: Finding unreachable functions in Go by rootext on Tuesday January 23, 2024 @02:45PM (#39108677)
Dart compiler does it, as I know.
Re:Deadcode: Finding unreachable functions in Go by mschuster91 on Tuesday January 23, 2024 @03:10PM (#39109057)
And then, people start using reflection (Java), vtables/dynamic lookups (C, C++), eval (JS, PHP) and similar constructs (a lot of languages have them), and suddenly tree-shaking falls apart.

Tree shaking shouldn't be necessary in 2024 anyway.

Re:Deadcode: Finding unreachable functions in Go by icholy on Tuesday January 23, 2024 @04:56PM (#39110503)
Calling vtables "reflection" is a stretch.
Re:Deadcode: Finding unreachable functions in Go by mschuster91 on Tuesday January 23, 2024 @05:04PM (#39110595)
I was merely listing stuff that can break or severely restrict tree-shaking.
Re:Deadcode: Finding unreachable functions in Go by icholy on Tuesday January 23, 2024 @07:18PM (#39111907)
Apologies, I misread your comment. But can you elaborate on your statement that tree-shaking (more commonly referred to as dead-code-elimination) is no longer required?
Re:Deadcode: Finding unreachable functions in Go by mschuster91 on Wednesday January 24, 2024 @03:46AM (#39115120)
Tree shaking was mostly a thing invented in the NodeJS ecosystem for websites to save transfer traffic and thus lead to faster page loads, as well as save a bit of RAM.

Even budget phones routinely have more than 4GB of RAM, and high-speed Internet access is the norm, so you can get away with a lot more inefficiency than just a few years ago.