Files
carbon-lang/toolchain/sem_ir/builtin_function_kind.h
T
Jon Ross-PerkinsandRichard Smith 76ed3c73cb 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>
2024-05-03 15:18:04 +00:00

47 lines
1.5 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_TOOLCHAIN_SEM_IR_BUILTIN_FUNCTION_KIND_H_
#define CARBON_TOOLCHAIN_SEM_IR_BUILTIN_FUNCTION_KIND_H_
#include <cstdint>
#include "common/enum_base.h"
#include "toolchain/sem_ir/ids.h"
namespace Carbon::SemIR {
class File;
CARBON_DEFINE_RAW_ENUM_CLASS(BuiltinFunctionKind, std::uint8_t) {
#define CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(Name) \
CARBON_RAW_ENUM_ENUMERATOR(Name)
#include "toolchain/sem_ir/builtin_function_kind.def"
};
// A kind of builtin function.
class BuiltinFunctionKind : public CARBON_ENUM_BASE(BuiltinFunctionKind) {
public:
#define CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(Name) \
CARBON_ENUM_CONSTANT_DECL(Name)
#include "toolchain/sem_ir/builtin_function_kind.def"
// Returns the builtin function kind with the given name, or None if the name
// is unknown.
static auto ForBuiltinName(llvm::StringRef name) -> BuiltinFunctionKind;
// Determines whether this builtin function kind can have the specified
// function type.
auto IsValidType(const File& sem_ir, llvm::ArrayRef<TypeId> arg_types,
TypeId return_type) const -> bool;
};
#define CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(Name) \
CARBON_ENUM_CONSTANT_DEFINITION(BuiltinFunctionKind, Name)
#include "toolchain/sem_ir/builtin_function_kind.def"
} // namespace Carbon::SemIR
#endif // CARBON_TOOLCHAIN_SEM_IR_BUILTIN_FUNCTION_KIND_H_