fix: Add comptime to trait impls and structs#5511
Merged
jfecher merged 5 commits intojf/trait-constraintfrom Jul 16, 2024
Merged
fix: Add comptime to trait impls and structs#5511jfecher merged 5 commits intojf/trait-constraintfrom
comptime to trait impls and structs#5511jfecher merged 5 commits intojf/trait-constraintfrom
Conversation
5 tasks
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jul 17, 2024
# Description ## Problem\* Resolves an issue mentioned in this PR: #5511 And in @asterite's comptime prefix operators PR. ## Summary\* Previously, if a function was every (erroneously) allowed to be called in a comptime context before it had been elaborated, we'd see just an empty block as its body. I've changed this so we don't default function bodies to an empty block anymore. Using an option we can now properly error in this case as well. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --------- Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem*
Resolves
Summary*
This is somewhat of a quick fix to the issue in the trait constraint PR and in @asterite's comptime prefix operator PR.
The issue was that the comptime functions/blocks were using other functions which weren't elaborated yet. So they saw an empty function body. Just adding
comptimeto a function in an impl wasn't sufficient since the compiler didn't look in every function within an impl to know whether to add the impl to the list of comptime items. Moreover, it wouldn't be possible to only add thiscomptimeto a subset of functions within an impl so I decided to allowcomptimeas a keyword on an entire impl as well - and this is what decides whether or not to add it to the comptime items.I'm not really satisfied with this solution since it overloads
comptimeto mean both "run this at compile-time (always)" and "able to be run at compile-time" but I don't have a better solution right now. To some degree the separation is necessary since we need to separate runtime functions that can be modified by comptime functions from comptime functions that cannot be modified (because we've already run them).Additional Context
Requires #5517 to work
Documentation*
Check one:
PR Checklist*
cargo fmton default settings.