Skip to content

Conversation

danakj
Copy link
Contributor

@danakj danakj commented Jun 25, 2025

AddImportedInstruction was turning errors in an instruction into a Runtime constant value instead of an Error, which led to crashes when importing an instruction that had an error inside it somewhere.

Fixes #5726

@danakj danakj force-pushed the error-in-import branch from ec00a51 to 74e38c1 Compare June 25, 2025 19:09
Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

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

LG, just one suggestion to make the error observable in the test

Comment on lines 146 to 148
fn F() {
//@dump-sem-ir-begin
WithError(());
Copy link
Contributor

@jonmeow jonmeow Jun 25, 2025

Choose a reason for hiding this comment

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

Noting that the generated IR doesn't include any errors (but I do note the absence of a call), I'd wonder if something like a let might show the transmission:

Suggested change
fn F() {
//@dump-sem-ir-begin
WithError(());
fn F() {
//@dump-sem-ir-begin
let x: () = WithError(());

I think that'll yield:

+// CHECK:STDOUT:   %x: %empty_tuple.type = bind_name x, <error> [concrete = <error>]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, yep it does, exactly.

@danakj danakj enabled auto-merge June 25, 2025 20:22
@danakj danakj added this pull request to the merge queue Jun 25, 2025
Merged via the queue into carbon-language:trunk with commit fa6322d Jun 25, 2025
8 checks passed
@danakj danakj deleted the error-in-import branch June 25, 2025 20:53
github-merge-queue bot pushed a commit that referenced this pull request Jul 2, 2025
…5729)

Currently if the first operand contains an error, we will return error,
even though the second operands contains a runtime, and it has a
stronger priority (the phase always goes up if possible).

Import is only allowed on instructions with compile-time values, so we
crash if we ever try to import a runtime value. Importable instructions
must diagnose unexpected runtime values and produce errors in the semir
from which they would be imported so that runtime values are never
imported by another semir.

If we had an instruction where you had an error value from the first
operand, and runtime from the second, and we imported it:
- Before #5728 we
would crash in import, but only because we treated errors as runtime
- After #5728 we
would import ErrorInst because we propagate errors. This is desirable
for cases with compile-time values and errors present only.
- After this PR, we would crash again, cuz you're importing a runtime
thing.

This change means that instructions containing an
`InstConstantKind::Never` instruction like`ValueParam` will consistently
evaluate to a runtime value, even if there are errors present. This is
visible in the `BindName` instructions changing in the semir, where they
became constant `ErrorInst` values previously but no longer do.
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.

Crash if error in imported where
2 participants