mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:21:19 +01:00
Refactor WhereExpr evaluation into smaller helper functions (#7006)
This splits off the functionality to handle the base facet type, rewrites, and impls constraints into separate functions. We use the Context instead of EvalContext throughout, as the goal is to move this code to EvalConstantInst in time. That means we do not apply specifics to the functions in the requirements inst block. That is fine because WhereExpr never evaluates to an WhereExpr, so this instruction never survives as a constant value long enough to be re-evaluated with a specific applied to it.
This commit is contained in:
+71
-2
@@ -10,7 +10,8 @@
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/eval/unexpected_runtime.carbon
|
||||
|
||||
// --- fail_unexpected_runtime.carbon
|
||||
// --- fail_unexpected_runtime_base.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
var x: type;
|
||||
|
||||
@@ -19,9 +20,77 @@ interface Z {
|
||||
}
|
||||
|
||||
class D {
|
||||
// CHECK:STDERR: fail_unexpected_runtime.carbon:[[@LINE+4]]:31: error: expression is runtime; expected constant [EvalRequiresConstantValue]
|
||||
// CHECK:STDERR: fail_unexpected_runtime_base.carbon:[[@LINE+4]]:18: error: cannot evaluate type expression [TypeExprEvaluationFailure]
|
||||
// CHECK:STDERR: extend impl as x where .T = () {}
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
extend impl as x where .T = () {}
|
||||
}
|
||||
|
||||
// --- fail_unexpected_runtime_rewrite_lhs.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
var x: type;
|
||||
|
||||
interface Z {
|
||||
let T:! type;
|
||||
}
|
||||
|
||||
class D {
|
||||
// CHECK:STDERR: fail_unexpected_runtime_rewrite_lhs.carbon:[[@LINE+8]]:18: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
||||
// CHECK:STDERR: extend impl as Z where x = () {}
|
||||
// CHECK:STDERR: ^~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_unexpected_runtime_rewrite_lhs.carbon:[[@LINE+4]]:28: error: requirement can only use `=` after `.member` designator [RequirementEqualAfterNonDesignator]
|
||||
// CHECK:STDERR: extend impl as Z where x = () {}
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
extend impl as Z where x = () {}
|
||||
}
|
||||
|
||||
// --- fail_unexpected_runtime_rewrite_rhs.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
var x: type;
|
||||
|
||||
interface Z {
|
||||
let T:! type;
|
||||
}
|
||||
|
||||
class D {
|
||||
// CHECK:STDERR: fail_unexpected_runtime_rewrite_rhs.carbon:[[@LINE+4]]:31: error: expression is runtime; expected constant [EvalRequiresConstantValue]
|
||||
// CHECK:STDERR: extend impl as Z where .T = x {}
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
extend impl as Z where .T = x {}
|
||||
}
|
||||
|
||||
// --- fail_unexpected_runtime_impls_lhs.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
var x: type;
|
||||
|
||||
interface Z {}
|
||||
|
||||
class D {
|
||||
// CHECK:STDERR: fail_unexpected_runtime_impls_lhs.carbon:[[@LINE+4]]:29: error: cannot evaluate type expression [TypeExprEvaluationFailure]
|
||||
// CHECK:STDERR: extend impl as type where x impls Z {}
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
extend impl as type where x impls Z {}
|
||||
}
|
||||
|
||||
// --- fail_unexpected_runtime_impls_rhs.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
var x: type;
|
||||
|
||||
interface Z {}
|
||||
|
||||
class D {
|
||||
// CHECK:STDERR: fail_unexpected_runtime_impls_rhs.carbon:[[@LINE+4]]:41: error: cannot evaluate type expression [TypeExprEvaluationFailure]
|
||||
// CHECK:STDERR: extend impl as type where .Self impls x {}
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
extend impl as type where .Self impls x {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user