Promote FunctionType to a standard instruction. (#3931)

This removes the builtin FunctionType, replacing it with a FunctionType
instruction. The constant for a FunctionDecl is now a StructValue with
type of FunctionType.

Note this means a function declaration produces _both_ a type, and a
value of the type. This has some consequences in terms of circularity,
and makes the importing of function declarations a little more complex.

It'll get particularly peculiar for imports because of the behavior of
the reference, but that's a known issue due to other things such as
`alias`. The impact will hopefully be contained to
ResolvePrevInstForMerge (and ImportRefs).

To note a small formatting change in diagnostics:

```
-  // CHECK:STDERR: fail_member_lookup.carbon:[[@LINE+4]]:3: ERROR: Value of type `<associated <function> in Interface>` is not callable.
+  // CHECK:STDERR: fail_member_lookup.carbon:[[@LINE+4]]:3: ERROR: Value of type `<associated F in Interface>` is not callable.

-  // CHECK:STDERR: fail_todo_facet_lookup.carbon:[[@LINE+4]]:3: ERROR: Value of type `<associated <function> in Interface>` is not callable.
+  // CHECK:STDERR: fail_todo_facet_lookup.carbon:[[@LINE+4]]:3: ERROR: Value of type `<associated F in Interface>` is not callable.
```

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Jon Ross-Perkins
2024-05-03 15:18:04 +00:00
committed by GitHub
co-authored by Richard Smith
parent e6061f6910
commit 76ed3c73cb
405 changed files with 9799 additions and 6579 deletions
+9 -1
View File
@@ -814,7 +814,6 @@ class TypeCompleter {
case SemIR::BuiltinKind::IntType:
case SemIR::BuiltinKind::FloatType:
case SemIR::BuiltinKind::NamespaceType:
case SemIR::BuiltinKind::FunctionType:
case SemIR::BuiltinKind::BoundMethodType:
case SemIR::BuiltinKind::WitnessType:
return MakeCopyValueRepr(type_id);
@@ -956,6 +955,7 @@ class TypeCompleter {
SemIR::ValueRepr::ObjectAggregate);
}
case SemIR::AssociatedEntityType::Kind:
case SemIR::FunctionType::Kind:
case SemIR::InterfaceType::Kind:
case SemIR::UnboundElementType::Kind: {
// These types have no runtime operations, so we use an empty value
@@ -1065,6 +1065,14 @@ auto Context::GetBuiltinType(SemIR::BuiltinKind kind) -> SemIR::TypeId {
return type_id;
}
auto Context::GetFunctionType(SemIR::FunctionId fn_id) -> SemIR::TypeId {
auto type_id = GetTypeImpl<SemIR::FunctionType>(*this, fn_id);
// To keep client code simpler, complete function types before returning them.
bool complete = TryToCompleteType(type_id);
CARBON_CHECK(complete) << "Failed to complete function type";
return type_id;
}
auto Context::GetPointerType(SemIR::TypeId pointee_type_id) -> SemIR::TypeId {
return GetTypeImpl<SemIR::PointerType>(*this, pointee_type_id);
}