Skip to content

Conversation

@danakj
Copy link
Contributor

@danakj danakj commented Oct 10, 2025

SymbolicBindingType evaluates to the type component of a symbolic facet value (a type/witnesses pair), and that symbolic facet value has its constant value replaced by a specific. That specific can provide a FacetValue, in which case it just evaluates to that FacetValue's type component. It can provide a BindSymbolicName of another binding, in which case it points to that entity instead and awaits a further specific. Currently the code only handles these two cases, and they match the behaviour of the evaluation of FacetAccessType itself.

However FacetAccessType evaluation also handles cases beyond these, as there are other instructions that occur as facet values, such as ImplWitnessAccess, when accessing an associated constant of an interface that has a facet type as its type.

Currently eval then crashes in this scenario. Instead of furthering to reproduce the contents of FacetAccessType's evaluation, defer to calling the EvalConstantInst() overload for it when evaluating SymbolicBindingType against a new value from a specific. This means SymbolicBindingType can evaluate back into a FacetAccessType, when it was originally a FacetAccessType(BindSymbolicName) and becomes FacetAccessType(ImplWitnessAccess) through a specific.

This comes with a test that crashed in eval before this change.

@danakj danakj requested a review from a team as a code owner October 10, 2025 20:34
@danakj danakj requested review from jonmeow and removed request for a team October 10, 2025 20:34
Comment on lines 2215 to 2216
// Copy the updated constant field values into `bind`.
bind = inst.As<SemIR::SymbolicBindingType>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this copy the value into bind? It looks it's not an output parameter; whereas before there was conditional assignment, you've made that unconditional. Can you elaborate here, or declare a separate variable to make it clearer that updating bind has no real effect?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest removing bind and calling Is in the two places it's used. Each time we convert it, we use it exactly once, and keeping it around as a duplicate of inst seems error-prone. (We should pass inst directly to MakeConstantResult rather than converting back from SymbolicBindingType.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, yeah. Done.

return ConvertEvalResultToConstantId(
eval_context.context(),
EvalConstantInst(eval_context.context(), access),
ComputeInstPhase(eval_context.context(), access));
Copy link
Contributor

Choose a reason for hiding this comment

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

Could shortcut this a little:

Suggested change
ComputeInstPhase(eval_context.context(), access));
GetPhase(eval_context.constant_values(), value));

... though either way seems OK to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true... though I decided to leave it, since it will not break this way, if we change FacetAccessType someday.

Comment on lines 2215 to 2216
// Copy the updated constant field values into `bind`.
bind = inst.As<SemIR::SymbolicBindingType>();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest removing bind and calling Is in the two places it's used. Each time we convert it, we use it exactly once, and keeping it around as a duplicate of inst seems error-prone. (We should pass inst directly to MakeConstantResult rather than converting back from SymbolicBindingType.)

zygoloid added a commit to zygoloid/carbon-lang that referenced this pull request Oct 13, 2025
@danakj danakj enabled auto-merge October 14, 2025 15:13
@danakj danakj added this pull request to the merge queue Oct 14, 2025
Merged via the queue into carbon-language:trunk with commit e12d1b6 Oct 14, 2025
8 checks passed
@danakj danakj deleted the symbolic-binding-type-of-assoc-const branch October 14, 2025 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants