Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: Go 2: Permit running code at compile-time using "comptime" keyword #39216

Closed
donutloop opened this issue May 22, 2020 · 4 comments
Closed

Comments

@donutloop
Copy link
Contributor

@donutloop donutloop commented May 22, 2020

Problem

I want to read in the content of files while compiling time to simplify the shipping of template files with a binary.

Solution

using the comptime keyword to run arbitrary code at compilation-time.

Ref: https://ziglang.org/documentation/master/#Introducing-the-Compile-Time-Concept

Design idea

func main() {
    content := comptime os.Open("./code.json")
   ....
}
@gopherbot gopherbot added this to the Proposal milestone May 22, 2020
@gopherbot gopherbot added the Proposal label May 22, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 22, 2020

We aren't going to permit arbitrary code to run at compile time.

The specific topic of embedding files in a compiled binary is #35950.

@beoran
Copy link

@beoran beoran commented May 23, 2020

Also there is go generate which should be used instead for code generation.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 26, 2020

For the reasons mentioned above, this is a likely decline. Leaving open for four weeks for final comments.

@griesemer griesemer changed the title proposal: Go 2: Comptime proposal: Go 2: Permit running code at compile-time using `comptime` keyword May 26, 2020
@griesemer griesemer changed the title proposal: Go 2: Permit running code at compile-time using `comptime` keyword proposal: Go 2: Permit running code at compile-time using comptime keyword May 26, 2020
@griesemer griesemer changed the title proposal: Go 2: Permit running code at compile-time using comptime keyword proposal: Go 2: Permit running code at compile-time using "comptime" keyword May 26, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 23, 2020

No further comments.

@marniks7 marniks7 mentioned this issue Oct 30, 2020
3 of 3 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.