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

has_definition_started accessor for entities #4730

Merged
merged 8 commits into from
Dec 21, 2024
2 changes: 1 addition & 1 deletion toolchain/check/handle_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ auto HandleParseNode(Context& context, Parse::ImplDefinitionStartId node_id)
BuildImplDecl(context, node_id, /*is_definition=*/true);
auto& impl_info = context.impls().Get(impl_id);

if (impl_info.is_defined()) {
if (impl_info.has_definition_started()) {
CARBON_DIAGNOSTIC(ImplRedefinition, Error,
"redefinition of `impl {0} as {1}`", InstIdAsRawType,
InstIdAsRawType);
Expand Down
8 changes: 7 additions & 1 deletion toolchain/sem_ir/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ struct Impl : public EntityWithParamsBase,
out << "{self: " << self_id << ", constraint: " << constraint_id << "}";
}

// Determines whether the definition of this impl has begun. This is false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to move this onto EntityWithParamsBase?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

// until we reach the `{` of the impl definition.
auto has_definition_started() const -> bool {
return definition_id.is_valid();
}

// Determines whether this impl has been fully defined. This is false until we
// reach the `}` of the impl definition.
auto is_defined() const -> bool { return defined; }

// Determines whether this impl's definition has begun but not yet ended.
auto is_being_defined() const -> bool {
return definition_id.is_valid() && !is_defined();
return has_definition_started() && !is_defined();
}
};

Expand Down
Loading